home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / shareware / share_44 / bas2f77 < prev    next >
Text File  |  1991-11-16  |  3KB  |  66 lines

  1.               CONVERTING PROGRAMS FROM BASIC TO FORTRAN
  2.                  (excluding file handling operations)
  3.  
  4.                Some differences between BASIC and Fortran
  5.  
  6. 1. BASIC can have several commands on a line; Fortran can only have one.
  7. 2. BASIC lines are all numbered; Fortran lines may be, but most are not.
  8. 3. BASIC comments begin REM, Fortran ones begin with C or *
  9. 4. BASIC files are 'tokenised', to speed up the interpretation process.
  10.    Fortran files are ASCII text files, and must be compiled before execution.
  11. 5. BASIC variable names ending in % are integers. Fortran names beginning
  12.    with letters I-N are integer by default.
  13. 6. BASIC variable names ending in $ are character variables of undefined
  14.    length. Fortan character variables need tohave their length explicitly
  15.    defined.
  16. 7. In BASIC all variables are known to all procedures unless defined as LOCAL
  17.    but in Fortran all variables are local to the subroutine unless they are
  18.    stored in COMMON BLOCKS           
  19. 8. BASIC commands are 'case-sensitive' but Fortran ones are not.
  20. 9. BASIC commands start immediately after the line number, Fortran commands
  21.    normally start in the 7th position in the line.
  22.  
  23.                            Instructions
  24.   Note: Although following these instructions may produce a working Fortran
  25. program, it will not necessarily be good Fortran code because there are many
  26. Fortran concepts which are not in BASIC. Similarly, BASIC V concepts which
  27. are not in FORTRAN77 can usually be circumvented. Better code can usually be
  28. made by starting again and rewriting the program from the beginning in
  29. Fortran. 
  30.  
  31. 1. Load BASIC and the program to be converted
  32. 2. type the following to change the BASIC 'tokens' into an ASCII file:
  33.    *SPOOL TEMP
  34.    LIST
  35.    *SPOOL
  36. 3. Then use !Edit to edit the file 'TEMP' as follows:
  37.   a)make one command per line, e.g. by replacing ':' by '\n      ' 
  38.     delete the 1st line '>LIST'
  39.     and the last line '>*SPOOL'
  40.   b)remove the line numbers and the [0d] by:
  41.     (i)select the whole file
  42.     (ii) press Menu button and choose the 'Select' option, and the Indent
  43.         sub-option asking for -6
  44.     (iii)press Menu again, choose 'Select' and 'Indent' but ask for +6
  45.      (iv) deselect the whole file using CTRL and Z
  46.   c)replace REM by C search for '      REM' and replace with 'C'
  47.   d)replace DIM by DIMENSION, note that by default BASIC arrays begin at 0
  48.     while FORTRAN ones begin at 1, although they can be made to begin at 0 
  49.     by explicitly entering the 0. Character variables must be declared in
  50.     DIMENSION statements in Fortran, but need not be in BASIC.
  51.   e)remove the %, changing the variable names to begin with one of the 
  52.    letters I-N.
  53.   f)put () into the IF statements
  54.   g)replace logical expressions < by .LT. > by .GT.  etc
  55.   h)replace 'ENDPROC' by   'RETURN\n      END'
  56.   i)replace DEFPROC by SUBROUTINE
  57.   j)replace PROC by CALL
  58.   k)replace DEFFN by FUNCTION and change the return statement.
  59.   l)replace FOR I% = 1 TO N STEP M  by    DO 10 I=1,N,M
  60.             NEXT                       10 CONTINUE
  61.   m)replace any graphics commands. MODE, CLS etc by corresponding routines
  62.     from the Graphics library, remember that () can be left out in BASIC but     are mandatory in FORTRAN.
  63.   n) Dimension any character constants and remove the $ front the names,
  64.      change all " to '.
  65.   o) replace INSTR by INDEX, and ASC by ICHAR
  66.   p) change PRINT statements to PRINT *, and " to '