Re: interpreting a piece of code



On Thu, 17 Aug 2006 17:02:35 +0200, Darius Blaszijk <dhkblaszyk@xxxxxxxxxxxxx>
wrote in <FLWdnVNxfPuMGHnZRVnyrw@xxxxxxxxxxxxx>:

I'm porting a fortran library to pascal, but I came a cross a piece of code
which I have no clue how to interpret. I put the code below. My question is
not if someone wants to translate it for me (although I wouldn't mind
ofcourse!), but rather how to interpret this. I appologise for just pasting
a big chunk in this mail, but I really don't even have a clue how to make a
simple example to show my problem. The problem I'm facing are the lines that
are numbered 1 to 18 before the instructions. Do I need to interpret them as
being labels or some kind of goto statements? What is the index variable?

do 1 i=1,12
if (ctrl(i).lt.0.) ctrl(i)=DFAULT(i)
1 continue

That's a loop with I running from 1 to 12, manipulating the
corresponding element of the array ctrl. "DO 1" means loop over statements
up to and including the one labelled 1.

np = ctrl(1)
ngen = ctrl(2)
nd = ctrl(3)
pcross = ctrl(4)
imut = ctrl(5)
pmut = ctrl(6)
pmutmn = ctrl(7)
pmutmx = ctrl(8)
fdif = ctrl(9)
irep = ctrl(10)
ielite = ctrl(11)
ivrb = ctrl(12)
status = 0
c
c Print a header
if (ivrb.gt.0) then

write(*,2) ngen,np,n,nd,pcross,pmut,pmutmn,pmutmx,fdif

2 format(/1x,60('*'),/,
+ ' *',13x,'PIKAIA Genetic Algorithm Report ',13x,'*',/,
+ 1x,60('*'),//,
+ ' Number of Generations evolving: ',i4,/,
+ ' Individuals per generation: ',i4,/,
+ ' Number of Chromosome segments: ',i4,/,
+ ' Length of Chromosome segments: ',i4,/,
+ ' Crossover probability: ',f9.4,/,
+ ' Initial mutation rate: ',f9.4,/,
+ ' Minimum mutation rate: ',f9.4,/,
+ ' Maximum mutation rate: ',f9.4,/,
+ ' Relative fitness differential: ',f9.4)

That's the format for the write statement to console (unit=*);
the non-blank character in column 5 signifies a continuation of the statement
above.

if (imut.eq.1) write(*,3) 'Uniform, Constant Rate'
if (imut.eq.2) write(*,3) 'Uniform, Variable Rate (F)'
if (imut.eq.3) write(*,3) 'Uniform, Variable Rate (D)'
if (imut.eq.4) write(*,3) 'Uniform+Creep, Constant Rate'
if (imut.eq.5) write(*,3) 'Uniform+Creep, Variable Rate (F)'
if (imut.eq.6) write(*,3) 'Uniform+Creep, Variable Rate (D)'
3 format(
+ ' Mutation Mode: ',A)
if (irep.eq.1) write(*,4) 'Full generational replacement'
if (irep.eq.2) write(*,4) 'Steady-state-replace-random'
if (irep.eq.3) write(*,4) 'Steady-state-replace-worst'
4 format(
+ ' Reproduction Plan: ',A)
endif

Again, 3 & 4 are format statements for the write. In fact all the
labels except 1 are for format statements; 1 is the terminal statement
of a do-loop.


--
Ivan Reid, Electronic & Computer Engineering, ___ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
.