For Programmers: Free Programming Magazines  


Home > Archive > Fortran > June 2005 > You are my hope. Please









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author You are my hope. Please
Ciobin

2005-06-07, 8:58 pm

I'm working on my thesis and I'm porting a software from fortran to C.

Now I've a great problem. I don't know how change this code lines.

Could you help me?


c -----------------------------------------------------------------

c Set up the relationship list xx.

c -----------------------------------------------------------------

l=0

do 130 i=1, n

l=l+1

xx(l)=i

xptr(i)=l

neg=0

ptr=headp(i)

70 if (ptr.eq.0) goto 110

80 do 100 k=headc(clause(ptr)), headc(clause(ptr)+1)-1

index=iabs(lit(k))

do 90 j=xptr(i), l

if (index.eq.xx(j)) goto 100

90 continue

l=l+1

xx(l)=index

100 continue

if (neg.eq.1) then

ptr=nextm(ptr)

goto 120

endif

ptr=nextp(ptr)

goto 70

110 continue

ptr=headm(i)

neg=1

120 if (ptr.eq.0) goto 130

goto 80

130 continue

xptr(n+1)=l+1



Steven G. Kargl

2005-06-07, 8:58 pm

In article <xoope.138787$IN.2398096@twister2.libero.it>,
"Ciobin" <lingo74@forzaferrari-libero.it> writes:
>
> I'm working on my thesis and I'm porting a software from fortran to C.
>


Why? Wouldn't it be easier to download a free Fortran compiler or
purchase a commercial compiler than re-invent the wheel?

> Now I've a great problem. I don't know how change this code lines.
>
> Could you help me?
>


(code snipped)

This is only a small chuck of code that is incomplete. In particular,
there are no declarations of the variables, which makes it difficult
to give guidance.


--
Steve
http://troutmask.apl.washington.edu/~kargl/
Ciobin

2005-06-07, 8:58 pm


"Steven G. Kargl" <kargl@troutmask.apl.washington.edu> ha scritto nel
messaggio news:d8557u$umi$2@gnus01.u.washington.edu...
> In article <xoope.138787$IN.2398096@twister2.libero.it>,
> "Ciobin" <lingo74@forzaferrari-libero.it> writes:
>
> Why? Wouldn't it be easier to download a free Fortran compiler or
> purchase a commercial compiler than re-invent the wheel?
>
>
> (code snipped)
>
> This is only a small chuck of code that is incomplete. In particular,
> there are no declarations of the variables, which makes it difficult
> to give guidance.
>

I'd like to know how transform the cicle and inconditionate jump in a
structrured language.
It is not important the variable declaration.

So, I hope to help me. PLEASE !!!!!!


Steven G. Kargl

2005-06-08, 4:00 am

In article <lxppe.48699$795.1499660@twister1.libero.it>,
"Ciobin" <lingo74@forzaferrari-libero.it> writes:
>
> "Steven G. Kargl" <kargl@troutmask.apl.washington.edu> ha scritto nel
> I'd like to know how transform the cicle and inconditionate jump in a
> structrured language.
> It is not important the variable declaration.


The declaration are important! For example,
is the following an array reference or function call

ptr = nextm(ptr)

We have no way to know!

--
Steve
http://troutmask.apl.washington.edu/~kargl/
e p chandler

2005-06-08, 4:00 am


Ciobin wrote:
> "Steven G. Kargl" <kargl@troutmask.apl.washington.edu> ha scritto nel
> messaggio news:d8557u$umi$2@gnus01.u.washington.edu...
> I'd like to know how transform the cicle and inconditionate jump in a
> structrured language.
> It is not important the variable declaration.
>
> So, I hope to help me. PLEASE !!!!!!


Before thinking about translating this into C, why not try and clean it
up in Fortran first? Then at least you will have cleaner code to work
with which may suggest some structured programming constructs.

When faced with this type of task where I am required to work on
existing code such as this, I usually:

1. upper case it
2. print out a listing
3. bracket the start and end of DO loops
4. run an arrow from GOTOs to their targets
5. draw arrows that indicate other transfers of control

In this case it is "spaghetti" code. Various loops cross each other and
some code jumps out of a DO loop. I won't address the DO 100 loop
except to pretty print it a bit. Perhaps someone else might make
suggestions.

In untangling code like this, it is sometimes helpful to replace GOTOs
by the code that they GO TO. In this case duplicate code is a good
thing. Keeping in mind where the flow of control goes, the code after
the DO 100 loop simplifies quite a bit giving what would be a do while
loop.

I believe that this is equivalent code, but use at your own risk.

C --------------------------------
C SET UP THE RELATIONSHIP LIST XX.
C --------------------------------
L=0
DO 130 I=1,N
L=L+1
XX(L)=I
XPTR(I)=L
NEG=0
PTR=HEADP(I)
IF (PTR.EQ.0) THEN
PTR=HEADM(I)
NEG=1
ENDIF
IF (PTR.NE.0) THEN
80 DO 100 K=HEADC(CLAUSE(PTR)),HEADC(CLAUSE(PTR)+1
)-1
INDEX=IABS(LIT(K))
DO 90 J=XPTR(I),L
IF (INDEX.EQ.XX(J)) GOTO 100
90 CONTINUE
L=L+1
XX(L)=INDEX
100 CONTINUE
IF (NEG.EQ.1) THEN
PTR=NEXTM(PTR)
ELSE
PTR=NEXTP(PTR)
IF (PTR.EQ.0) THEN
PTR=HEADM(I)
NEG=1
ENDIF
ENDIF
IF (PTR.NE.0) GOTO 80
ENDIF
130 CONTINUE
XPTR(N+1)=L+1

Ryo

2005-06-08, 8:58 am

> I'd like to know how transform the cicle and inconditionate jump in a
> structrured language.


You seem to me to be mixing up two things. Exactly what is your goal?
1) Do you want to translate the code into more "structured" one? Or
2) Do you want to translate the code into C?

You can translate the code into more structured one in Fortran.
Fortran has at least as many facilities to write structured code
as C does. If you call C a "structure language", then you should call
Fortran so, too.

You can also translate the code in question into C keeping the same
structure. The resultant C code will be as poorly structured as the
original Fortran code.

Ryo

beliavsky@aol.com

2005-06-08, 4:00 pm

Ciobin wrote:

<snip>

> I'd like to know how transform the cicle and inconditionate jump in a
> structrured language.
> It is not important the variable declaration.
>
> So, I hope to help me. PLEASE !!!!!!


Please learn how to post intelligent messages on Usenet:
(1) Use an informative subject line, such as "translate Fortran code to
C", rather than "You are my hope".
(2) Don't beg, SHOUT or use needless punctuation. "Please" is better
than "PLEASE !!!!!!".
(3) If you have trouble with spelling English words, use a
spell-checker. Above, "cicle" should be "cycle", "structrured" should
be "structured", and "inconditionate" should be "unconditional" (I
think).

Eric Raymond's good advice on using Usenet is at
http://www.catb.org/~esr/faqs/smart-questions.html .

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com