Example Conversion [ HP FORTRAN 77/iX Migration Guide ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Migration Guide
Example Conversion
Here is an example that shows the steps in converting a FORTRAN 66/V
source program to an HP FORTRAN 77/V source program.
This is the program as originally written in FORTRAN 66/V:
$control uslinit
program test
system intrinsic dateline, calendar
parameter prompt = "today is ...."
character cctrl,datebuf*27
character*12 string
integer today,age,daym(12)
integer dbirth, mbirth, ybirth
integer dtoday, mtoday, ytoday
C calendar jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
data daym/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/
call dateline(datebuf)
display prompt,datebuf[1:17]
cctrl=%320C
write(6,1100) cctrl
read(5,1200) string
write(6,1300)
read(5,1400) ybirth,mbirth,dbirth
today=int(calender)
ytoday=today[0:7]
dtoday=today[7:9]
mtoday=0
do 50 i=1,12
mtoday=mtoday + 1
if (dtoday .le. daym(mtoday)) goto 60
dtoday=dtoday - daym(mtoday)
50 continue
60 age=ytoday - ybirth
if (mtoday - mbirth) 100,80,200
80 if (dtoday - ybirth) 100,200,200
100 age=ytoday - ybirth - 1
200 write(6,1500) string,age
stop
1100 format(1a1,'. May I have your name? ')
1200 format(a12)
1300 format(%320C,"and your birthday (yymmdd):")
1400 format(3I2)
1500 format(" ",a12,", I believe your age is ",I2)
end
Running the Migration Aid on the Example Program
The following command runs the migration aid on the FORTRAN 66/V source
file INPUT66 and produces the HP FORTRAN 77/V source file OUTPUT77:
:CONVERT INPUT66,OUTPUT77,FTNCMDS.PUB.SYS
While the migration aid runs, it sends the following information to the
terminal (user responses are highlighted):
FORTRAN MIGRATION AID (C) 1987/A.00.02
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FORTRAN/V TO FORTRAN 77/V MIGRATION AID
+ ======================================
+ This migration aid reads commands from the COMMAND file and asks
+ you whether to apply them or not in the conversion process. For
+ each command, the migration aid asks:
+
+ Apply the corresponding commands? (expected Y,N,A)
+
+ Answer Y to apply them automatically.
+ N to not apply them. (Carriage return assumes this option).
+ A to be asked before the changes are done.
+ E to exit the program (no conversion will be done).
+
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Free format allows you to start your source code anywhere on the
line; this is no longer allowed in FORTRAN 77. The next changes
convert free format to fixed format;
WARNING! if the text is already in FIXED format, answer "N" to the
question otherwise wrong modifications will result.
If you plan to convert many files that already are in FIXED format,
you might find it convenient to delete this set of commands from the
file FTNCMDS (or better, you create your own copy of the file
FTNCMDS without them) in order to avoid being asked to apply these
commands and answering "YES" accidentally.
apply these commands? expected (Y,N,A) N
The next changes will affect the $INCLUDE and $CONTROL compiler
directives. Changes are
enclose include file with quotes.
- from CHECK=n to CHECK_FORMAL_PARM n
- from SEGMENT=sname to SEGMENT "sname"
- from LIST/NOLIST to LIST on/off
- from CODE/NOCODE to LIST_CODE on/off
- from MAP/NOMAP to TABLES on/off
- from BOUNDS to RANGE on
- from WARN/NOWARN to WARNINGS on/off
- from LOCATION/NOLOCATION to CODE_OFFSETS on/off
- from INIT to INIT ON
apply these commands? expected (Y,N,A) Y
The next changes will delete any compiler directive in FORTRAN/V that
has no equivalent in FORTRAN 77.
They are $EDIT
$TRACE
$CONTROL STAT/NOSTAT
$CONTROL SOURCE/NOSOURCE
$CONTROL LABEL/NOLABEL
$CONTROL FIXED
$CONTROL FREE
$CONTROL FILE=n-m
$CONTROL FILE=n
$CONTROL ERRORS=n
$CONTROL CROSSREF
$CONTROL CROSSREF ALL
If after deletion of these options the control line is left empty
the line will be removed.
apply these commands? expected (Y,N,A) Y
The next changes will affect the directive $SET. They will change
strings of the form $SET Xn ON / OFF to $SET (Xn=.TRUE. / .FALSE.)
They will also change conditional compile expressions of the form
$IF Xn=ON/OFF to $IF (Xn/.not.Xn)
apply these commands? expected (Y,N,A) Y
The next changes will affect octal constants of the form %nn
followed by a J or L or alone. They will be converted to nnB. Note
that numbers of the form %nnC, %nnR, %nnD won't be changed.
apply these commands? expected (Y,N,A) Y
The next changes will convert numerical ascii expressions to its
Hollerith equivalent, for example,
%"c"L ----> 1Hc
%"cc"L ---> 2Hcc
%"ccc"L---> 3Hccc
%"cccc"L--> 4Hcccc
apply these commands? expected (Y,N,A) Y
The next changes will affect character constants of the form %nnC.
They will be converted to CHAR(nn) except if they are found in the
same line as a FORMAT statement. Note that numbers of the form
%nn,%nnJ,%nnL,%nnR,%nnD won't be changed.
apply these commands? expected (Y,N,A) Y
The next changes will affect the condition code intrinsic,
alternative return locations, and parameters passed by value in the
following way,
-Occurrences of .CC. will be converted to CCODE().
-Alternative return locations '$nn' will be converted to '*nn'
locations.
-The backslash (\) of parameters passed by value will be deleted.
CAUTION: in FORTRAN 77/V, the actual mode of passing variables
should be specified through the ALIAS statement.
apply these commands? expected (Y,N,A) Y
The next changes will convert ACCEPT and DISPLAY statements
to READ * and PRINT * respectively.
apply these commands? expected (Y,N,A) Y
The next commands will affect default INTEGER and LOGICAL variables.
INTEGER and LOGICAL variables will be converted to INTEGER*2 and
LOGICAL*2, respectively.
Note that this command is intended to preserve the 16-bit length
variables since in MPE/iX the default is 32-bit (or INTEGER*4). If
you use the directive $SHORT, you might not want to apply this
command. Note as well that in MPE/iX, the 32-bit variables are
handled more efficiently than the 16-bit ones.
apply these commands? expected (Y,N,A) Y
The next commands will change CHARACTER declarations to the new
syntax. They will also enclose the object of PARAMETER statements
between parentheses Note that the changed lines may still need
manual changes.
apply these commands? expected (Y,N,A) Y
The next commands will put parentheses after the parameterless
intrinsics. For example,
100 C=CLOCK will be changed to
100 C=CLOCL()
The intrinsics affected are
-CALENDAR CAUSEBREAK CLOCK
-DEBUG FATHER FREELOCRIN
-GETJCW GETORIGIN GETPRIVMODE
-GETUSERMODE PROCTIME RESETDUMP
-TERMINATE TIMER
apply these commands? expected (Y,N,A) Y
The next commands will change all the following intrinsic functions
to their corresponding name in FORTRAN 77.
IABS....HABS JABS....IABS JINT....INT JDINT...IDINT
JMOD....MOD MOD.....HMOD AJMAXO..AMAXO JMAXO...MAXO
JMAX1...MAX1 AJMINO..AMINO JMINO...MINO JMIN1...MIN1
JFIX....IFIX ISIGN...HSIGN JSIGN...ISIGN IDIM....HDIM
JDIM....IDIM FLOATJ..FLOAT
apply these commands? expected (Y,N,A) Y
The next two sets of commands affect substrings and partial-word
designators which have the same syntax in FORTRAN/V but differ in
FORTRAN 77. Don't answer "Y" to both of them but alternatively, if
you answer "Y" to one of them, answer "N" to the other or use Ask
mode ("A").
Please refer to the Migration Guide for further explanations.
EXPRESSIONS OF THE FORM VAR[e1:e2]. Part 1.
===========================================
The next commands will treat strings of the form VAR[m:n] as
substrings, and will change them to VAR(m:m+n-1) (note that n does
not represent the number of characters anymore but rather the last).
If the expression does not contain n (i.e. VAR[m]), it will be
changed to the corresponding VAR(m:) in FORTRAN 77.
apply these commands? expected (Y,N,A) A
EXPRESSIONS OF THE FORM VAR[e1:e2]. Part 2.
===========================================
The next changes will convert constructs of the form
VARi[e1:e2]=VARj[e3:e4] to a call to the bit intrinsic MVBITS (move
bits), and expressions of the form VARi=VARj[e3:e4] to a call to
IBITS (extract bits).
apply these commands? expected (Y,N,A) A
The next commands will change some cumbersome math generated by the
preceding commands, such as 15-15, 16-0, and 1-1.
apply these commands? expected (Y,N,A) Y
The next change will replace the STR function with an internal WRITE
VAR1 = STR(VAR2, num) --> WRITE (VAR1, Inum) VAR2
apply these commands? expected (Y,N,A) Y
Deletion of END=label in WRITE statements
apply these commands? expected (Y,N,A) Y
NOW THE CONVERSION WILL START.
old line:
$control uslinit
new line:
$OPTION uslinit MIGF77
C$control uslinit MIGF66
$OPTION uslinit MIGF77
program test
system intrinsic dateline,calendar
old line:
parameter prompt = "today is...."
new line:
PARAMETER ( prompt = "today is....") MIGF77
C parameter prompt = "today is...." MIGF66
PARAMETER ( prompt = "today is....") MIGF77
character cctrl,datebuf*27
character*12 string
old line:
integer today,age,daym(12)
new line:
INTEGER*2 today,age,daym(12) MIGF77
C integer today,age,daym(12) MIGF66
INTEGER*2 today,age,daym(12) MIGF77
old line:
integer dbirth, mbirth, ybirth
new line:
INTEGER*2 dbirth, mbirth, ybirth MIGF77
C integer dbirth, mbirth, ybirth MIGF66
INTEGER*2 dbirth, mbirth, ybirth MIGF77
old line:
integer dtoday, mtoday, ytoday
new line:
INTEGER*2 dtoday, mtoday, ytoday MIGF77
C integer dtoday, mtoday, ytoday MIGF66
INTEGER*2 dtoday, mtoday, ytoday MIGF77
C calendar jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
data daym/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/
call dateline(datebuf)
old line:
PRINT *, prompt,datebuf[1:17]
ASK option was requested
PRINT *, prompt,datebuf(1:1+17-1)
apply it? expected (Y,N) Y
old line:
display prompt,datebuf[1:17]
new line:
PRINT *, prompt,datebuf(1:17) MIGF77
C display prompt,datebuf[1:17] MIGF66
PRINT *, prompt,datebuf(1:17) MIGF77
old line:
cctrl=%320C
new line:
cctrl=CHAR(320B) MIGF77
C cctrl=%320C MIGF66
cctrl=CHAR(320B) MIGF77
write(6,1100) cctrl
read(5,1200) string
write(6,1300)
read(5,1400) ybirth,mbirth,dbirth
old line:
today=int(calendar)
new line:
today=int(CALENDAR()) MIGF77
C today=int(calendar) MIGF66
today=int(CALENDAR()) MIGF77
old line:
ytoday=today[0:7]
ASK option was requested
ytoday=today(0:0+7-1)
apply it? expected (Y,N) N
old line:
ytoday=today[0:7]
ASK option was requested
ytoday=IBITS(today,-0+15-7+1,7)
apply it? expected (Y,N) Y
old line:
ytoday=today[0:7]
new line:
ytoday=IBITS(today,+15-7+1,7) MIGF77
C ytoday=today[0:7] MIGF66
ytoday=IBITS(today,+15-7+1,7) MIGF77
old line:
dtoday=today[7:9]
ASK option was requested
dtoday=today(7:7+9-1)
apply it? expected (Y,N) N
old line:
dtoday=today[7:9]
ASK option was requested
dtoday=IBITS(today,-7+15-9+1,9)
apply it? expected (Y,N) Y
old line:
dtoday=today[7:9]
new line:
dtoday=IBITS(today,+8-9+1,9) MIGF77
C dtoday=today[7:9] MIGF66
dtoday=IBITS(today,+8-9+1,9) MIGF77
mtoday=0
do 50 i=1,12
mtoday=mtoday+1
if ( dtoday .le. daym(mtoday)) go to 60
dtoday=dtoday-daym(mtoday)
50 continue
60 age=ytoday-ybirth
if ( mtoday-mbirth) 100,80,200
80 if ( dtoday-dbirth) 100,200,200
100 age=ytoday-ybirth-1
200 write(6,1500) string,age
stop
1100 format(1a1,'. May I have your name? ')
1200 format(a12)
1300 format(%320C,"and your birthday (yymmdd):")
1400 format(3I2)
1500 format(" ",a12,", I believe your age is ",I2)
end
10 lines have been changed.(21)
38 lines of code found
1 comment lines found
The Converted Program
Here is the converted program, OUTPUT77:
C$control uslinit
$OPTION uslinit
program test
system intrinsic dateline,calendar
C parameter prompt = "today is...."
PARAMETER ( prompt = "today is....")
character cctrl,datebuf*27
character*12 string
C integer today,age,daym(12)
INTEGER*2 today,age,daym(12)
C integer dbirth, mbirth, ybirth
INTEGER*2 dbirth, mbirth, ybirth
C integer dtoday, mtoday, ytoday
INTEGER*2 dtoday, mtoday, ytoday
C calendar jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
data daym/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/
call dateline(datebuf)
C display prompt,datebuf[1:17]
PRINT *, prompt,datebuf(1:17)
C cctrl=%320C
cctrl=CHAR(320B)
write(6,1100) cctrl
read(5,1200) string
write(6,1300)
read(5,1400) ybirth,mbirth,dbirth
C today=int(calendar)
today=int(CALENDAR())
C ytoday=today[0:7]
ytoday=IBITS(today,+15-7+1,7)
C dtoday=today[7:9]
dtoday=IBITS(today,+8-9+1,9)
mtoday=0
do 50 i=1,12
mtoday=mtoday+1
if ( dtoday .le. daym(mtoday)) go to 60
dtoday=dtoday-daym(mtoday)
50 continue
60 age=ytoday-ybirth
if ( mtoday-mbirth) 100,80,200
80 if ( dtoday-dbirth) 100,200,200
100 age=ytoday-ybirth-1
200 write(6,1500) string,age
stop
1100 format(1a1,'. May I have your name? ')
1200 format(a12)
1300 format(%320C,"and your birthday (yymmdd):")
1400 format(3I2)
1500 format(" ",a12,", I believe your age is ",I2)
end
Compilation of the Converted Program
When OUTPUT77 is compiled by the HP FORTRAN 77/V compiler, it produces
the following listing:
PAGE 1 HEWLETT-PACKARD HP32116A.00.08
HP FORTRAN 77 (C) HEWLETT-PACKARD CO. 1987 MON, MAY 18, 1987, 12:55 PM
0 1 C$control uslinit
0 2 $OPTION uslinit
1 3 program test
2 4 system intrinsic dateline,calendar
2 5 C parameter prompt = "today is...."
^
**** WARNING # 1 WARNING: THIS SYSTEM-SPECIFIC FEATURE IS NOT PART
OF HP STANDARD FORTRAN 77 (830)
3 6 PARAMETER ( prompt = "today is....")
^
**** ERROR # 1 INCONSISTENT PARAMETER TYPE (153)
4 7 character cctrl,datebuf*27
5 8 character*10 string(10)
5 9 C integer today,age,daym(12)
6 10 INTEGER*2 today,age,daym(12)
6 11 C integer dbirth, mbirth, ybirth
7 12 INTEGER*2 dbirth, mbirth, ybirth
7 13 C integer dtoday, mtoday, ytoday
8 14 INTEGER*2 dtoday, mtoday, ytoday
8 15 C calendar jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
9 16 data daym/31,28,31,30,31,30,31,31,30,31,30,31/
10 17 call dateline(datebuf)
10 18 C display prompt,datebuf[1:17]
^
**** WARNING # 2 WARNING: THIS SYSTEM-SPECIFIC FEATURE IS NOT
PART OF HP STANDARD FORTRAN 77 (830)
11 19 PRINT *, prompt,datebuf(1:17)
11 20 C cctrl=%320C
12 21 cctrl=CHAR(320B)
13 22 write(6,1100) cctrl
14 23 read(5,1200) string
15 24 write(6,1300)
16 25 read(5,1400) ybirth,mbirth,dbirth
16 26 C today=int(calendar)
17 27 today=int(CALENDAR())
17 28 C ytoday=today[0:7]
^
**** WARNING # 3 WARNING: THIS SYSTEM-SPECIFIC FEATURE IS NOT PART OF
HP STANDARD FORTRAN 77 (830)
18 29 ytoday=IBITS(today,+15-7+1,7)
18 30 C dtoday=today[7:9]
19 31 dtoday=IBITS(today,+8-9+1,9)
20 32 mtoday=0
21 33 do 50 i=1,12
22 34 1 mtoday=mtoday+1
23 35 1 if ( dtoday .le. daym(mtoday)) go to 60
24 36 1 dtoday=dtoday-daym(mtoday
25 37 1 50 continue
26 38 60 age=ytoday-ybirth
27 39 if ( mtoday-mbirth) 100,80,200
28 40 80 if ( dtoday-dbirth) 100,200,200
29 41 100 age=ytoday-ybirth-1
30 42 200 write(6,1500) string,age
31 43 stop
32 44 1100 format(1a1,'. May I have your name? ')
33 45 1200 format(a12)
PAGE 2
34 46 1300 format(%320C,"and your birthday (yymmdd)
35 47 1400 format(3I2)
36 48 1500 format(" ",a12,", I believe your age is ",I2)
37 49 end
NUMBER OF ERRORS = 1 NUMBER OF WARNINGS = 3
PROCESSOR TIME 0: 0: 2 ELAPSED TIME 0: 0:11
NUMBER OF LINES = 49
Recompilation of the Converted Program
An error occurred because the migration aid could not explicitly type the
constant in the PARAMETER statement. We can correct the problem by
editing the converted program to do the explicit typing. Next we delete
the lines containing MIGF66 and add the $STANDARD_LEVEL SYSTEM compiler
directive to eliminate the warnings. Here is the result of recompiling
with these corrections. A sample run of the program follows.
PAGE 1 HEWLETT-PACKARD HP32116A.00.08
HP FORTRAN 77 (C) HEWLETT-PACKARD CO. 1987 MON, MAY 18, 1987, 12:58 PM
0 1 $standard_level system
0 2 $OPTION uslinit
1 3 program test
2 4 system intrinsic dateline,calendar
3 5 Character*12 prompt
4 6 PARAMETER ( prompt = "today is)
5 7 character cctrl,datebuf*27
6 8 character*12 string
7 9 INTEGER*2 today,age,daym(12)
8 10 INTEGER*2 dbirth, mbirth, ybirth
9 11 INTEGER*2 dtoday, mtoday, ytoday
9 12 C calendar jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
10 13 data daym/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/
11 14 call dateline(datebuf)
12 15 PRINT *, prompt,datebuf(1:17)
13 16 cctrl=CHAR(320B)
14 17 write(6,1100) cctrl
15 18 read(5,1200) string
16 19 write(6,1300)
17 20 read(5,1400) ybirth,mbirth,dbirth
18 21 today=int(CALENDAR())
19 22 ytoday=IBITS(today,+15-7+1,7)
20 23 dtoday=IBITS(today,+8-9+1,9)
21 24 mtoday=0
22 25 do 50 i=1,12
23 26 1 mtoday=mtoday+1
24 27 1 if ( dtoday .le. daym(mtoday)) go to 60
25 28 1 dtoday=dtoday-daym(mtoday)
26 29 1 50 continue
27 30 60 age=ytoday-ybirth
28 31 if ( mtoday-mbirth) 100,80,200
29 32 80 if ( dtoday-dbirth) 100,200,200
30 33 100 age=ytoday-ybirth-1
31 34 200 write(6,1500) string,age
32 35 stop
33 36 1100 format(1a1,'. May I have your name? ')
34 37 1200 format(a12)
35 38 1300 format(%320C,"and your birthday (yymmdd) ")
36 39 1400 format(3I2)
37 40 1500 format(" ",a12,", I believe your age is ",I2)
38 41 end
NUMBER OF ERRORS = 0 NUMBER OF WARNINGS = 0
PROCESSOR TIME 0: 0: 3 ELAPSED TIME 0: 0:14
NUMBER OF LINES = 41
END OF PROGRAM
END OF PREPARE
today is....MON, MAY 18, 1987. May I have your name? Wendy Carlos
and your birthday (yymmdd):540806
Wendy Carlos, I believe your age is 32
END OF PROGRAM
MPE/iX 5.0 Documentation