Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29439 Discussions

help in fortran conditional structures

bmoumen
Beginner
980 Views

what theselines do:
1- DATA HPOL/6HLINEAR ,5HRIGHT ,4HLEFT/
2- DATA PNET/6H ,2H ,6HSTRAIG,2HHT,6HCROSSE,1HD/
3- WRITE(3,146)
4- READ(2,125)AIN,(COM(I,KCOM),I=1,19) ???!!!there were files opened for read and write!!!???
####################################################
what means UNIT 8 in:
OPEN (UNIT=8,FILE='PLTDAT.DAT',STATUS='UNKNOWN',ERR=14)
####################################################
howthis codecan be written using while, for and standard branch structures???
remarque that there is no THEN or END IF in the previous IF structure
and no END DO in the DO structure

2 KCOM=KCOM+1
IF (KCOM.GT.5) KCOM=5
READ(2,125)AIN,(COM(I,KCOM),I=1,19)
IF(KCOM.GT.1)GO TO 3

WRITE(3,126)

3 WRITE(3,129) (COM(I,KCOM),I=1,19)
IF (AIN.EQ.ATST(11)) GO TO 2
IF (AIN.EQ.ATST(1)) GO TO 4

WRITE(3,130)
STOP

4 CONTINUE
DO 5 I=1,LD
5 ZARRAY(I)=(0.,0.)
MPCNT=0
IMAT=0
##############################################################

0 Kudos
1 Reply
TimP
Honored Contributor III
980 Views
DATA initializes static (SAVEd, since 1990) variables. 6HLINEAR is pre-1977 syntax for 'LINEAR' (a string of characters). Although you haven't showed it, there seems a good chance that your code uses non-portable syntax (as there was no good alternative prior to 1977).
WRITE(3,146) is still standard syntax, should be explained in any Fortan summary of any era. Appends text to the file opened on unit 3, in accordance with a line 146 FORMAT (no variable content here).
For consistency with pre-1977 syntax, many compilers opened files automatically, with a default name containing the unit number, such as fort02 for unit 2. Others depended on shell facilities like assign, specifically meant for Fortran. You would want to add an OPEN.
Changing to block IF looks straightforward

Opinions vary on whether one should attemp to use DO WHILE. A literal translation of what you show:
DO
KCOM = KCOM +1
....
if(ain /= atst(11)exit
END DO
if(ain == atst(11)then
write(3,130)
stop
endif

0 Kudos
Reply