Re: You are my hope. Please




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

.



Relevant Pages

  • Re: question about thread scheduling
    ... still have problems with rescheduling. ... In essential, it is a control problem, and I must send a voltage to the ... If the NN run in a different thread as the control loop ...
    (microsoft.public.windowsce.platbuilder)
  • Re: About alternatives to Matlab
    ... But whether a single loop is faster than several BLAS calls does not ... Bad Fortran 95 can easily be 25% lower than well-tuned C99. ... NumPy can be slower than equivalent C by an order of magnitude. ... manipulated within Python, not the speed of python code using NumPy ...
    (comp.lang.python)
  • Re: should every thing be zero indexed?
    ... Jim Rogers wrote: ... >> This for loop would have the structure of a quantification: ... >> as, arrays. ... > I acknowledge that the concept of arrays was used heavily in Fortran, ...
    (comp.programming)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... >> both less efficient and less safe than the Fortran and Basic standard. ... >> The C for loop is actually trying to do what a do loop does. ... sloppy thinking that results from confusing a programming language ... > I do not believe that you are capable of writing a conforming C compiler. ...
    (comp.programming)
  • Re: OT: The Most Unexpected AND Interesting Discovery about QBasic
    ... writing code with subtle changes in loop counters (in Fortran IV)... ... I'd put a call to a subroutine... ... course all about rockets and rocket engines. ...
    (sci.stat.math)

Loading