Re: You are my hope. Please
- From: "e p chandler" <epc8@xxxxxxxx>
- Date: 7 Jun 2005 19:52:44 -0700
Ciobin wrote:
> "Steven G. Kargl" <kargl@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> ha scritto nel
> messaggio news:d8557u$umi$2@xxxxxxxxxxxxxxxxxxxxxxxxxx
> > In article <xoope.138787$IN.2398096@xxxxxxxxxxxxxxxxxx>,
> > "Ciobin" <lingo74@xxxxxxxxxxxxxxxxxxxxxx> 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.
> >
> 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
.
- References:
- You are my hope. Please
- From: Ciobin
- Re: You are my hope. Please
- From: Steven G. Kargl
- Re: You are my hope. Please
- From: Ciobin
- You are my hope. Please
- Prev by Date: Re: Fortran functions
- Next by Date: Re: gains from vectorization
- Previous by thread: Re: You are my hope. Please
- Next by thread: Re: You are my hope. Please
- Index(es):
Relevant Pages
|
Loading