home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1995
/
ARCHIVE95.iso
/
discs
/
shareware
/
share_44
/
bas2f77
< prev
next >
Wrap
Text File
|
1991-11-16
|
3KB
|
66 lines
CONVERTING PROGRAMS FROM BASIC TO FORTRAN
(excluding file handling operations)
Some differences between BASIC and Fortran
1. BASIC can have several commands on a line; Fortran can only have one.
2. BASIC lines are all numbered; Fortran lines may be, but most are not.
3. BASIC comments begin REM, Fortran ones begin with C or *
4. BASIC files are 'tokenised', to speed up the interpretation process.
Fortran files are ASCII text files, and must be compiled before execution.
5. BASIC variable names ending in % are integers. Fortran names beginning
with letters I-N are integer by default.
6. BASIC variable names ending in $ are character variables of undefined
length. Fortan character variables need tohave their length explicitly
defined.
7. In BASIC all variables are known to all procedures unless defined as LOCAL
but in Fortran all variables are local to the subroutine unless they are
stored in COMMON BLOCKS
8. BASIC commands are 'case-sensitive' but Fortran ones are not.
9. BASIC commands start immediately after the line number, Fortran commands
normally start in the 7th position in the line.
Instructions
Note: Although following these instructions may produce a working Fortran
program, it will not necessarily be good Fortran code because there are many
Fortran concepts which are not in BASIC. Similarly, BASIC V concepts which
are not in FORTRAN77 can usually be circumvented. Better code can usually be
made by starting again and rewriting the program from the beginning in
Fortran.
1. Load BASIC and the program to be converted
2. type the following to change the BASIC 'tokens' into an ASCII file:
*SPOOL TEMP
LIST
*SPOOL
3. Then use !Edit to edit the file 'TEMP' as follows:
a)make one command per line, e.g. by replacing ':' by '\n '
delete the 1st line '>LIST'
and the last line '>*SPOOL'
b)remove the line numbers and the [0d] by:
(i)select the whole file
(ii) press Menu button and choose the 'Select' option, and the Indent
sub-option asking for -6
(iii)press Menu again, choose 'Select' and 'Indent' but ask for +6
(iv) deselect the whole file using CTRL and Z
c)replace REM by C search for ' REM' and replace with 'C'
d)replace DIM by DIMENSION, note that by default BASIC arrays begin at 0
while FORTRAN ones begin at 1, although they can be made to begin at 0
by explicitly entering the 0. Character variables must be declared in
DIMENSION statements in Fortran, but need not be in BASIC.
e)remove the %, changing the variable names to begin with one of the
letters I-N.
f)put () into the IF statements
g)replace logical expressions < by .LT. > by .GT. etc
h)replace 'ENDPROC' by 'RETURN\n END'
i)replace DEFPROC by SUBROUTINE
j)replace PROC by CALL
k)replace DEFFN by FUNCTION and change the return statement.
l)replace FOR I% = 1 TO N STEP M by DO 10 I=1,N,M
NEXT 10 CONTINUE
m)replace any graphics commands. MODE, CLS etc by corresponding routines
from the Graphics library, remember that () can be left out in BASIC but are mandatory in FORTRAN.
n) Dimension any character constants and remove the $ front the names,
change all " to '.
o) replace INSTR by INDEX, and ASC by ICHAR
p) change PRINT statements to PRINT *, and " to '