#] #] ********************* #] loaddefs link d_Qndfs 'port GREP_Fortran_to_QNial.ndf' # www.BillHowell.ca 13Feb07, 08Feb2021 - think this was incomplete? (very old optrs!!) # Operation priorities - because Q'Nial is a 'fair and level playing field', these MUST be explicitly put in by parenthesis WATCH OUT! f_portGrepFortrantoQNial := 'port GREP_Fortran_to_QNial.ndf' ; loaddefs_start f_portGrepFortrantoQNial ; #**************************** # List of operators, generated with : # $ cat "$d_Qndfs""port GREP_Fortran_to_QNial.ndf" | grep "^#]" | sed 's/^#\]/ /' # ********************* loaddefs link d_Qndfs 'port GREP_Fortran_to_QNial.ndf' GREP_Fortran_to_QNial IS OP filename_in filename_out - #*********************************** IF flag_debug THEN write 'loading GREP_Fortran_to_QNial' ; ENDIF ; #] GREP_Fortran_to_QNial IS OP filename_in filename_out - GREP_Fortran_to_QNial IS OP filename_in filename_out { fin := open Filename_in "r ; fout := open Filename_out "w ; WHILE ((w := readfile fin) ~= ??eof) DO % first clear out "decorative" items that will cause problems later ; w := regexp_substitute 'c\*\*\*' '#***' w ; w := regexp_substitute '\*\*\*\**' '' w ; w := regexp_substitute '----*' '' w ; % separate operators from surrounding text ; % it's easier to correct the few logical comparisons later, as the majority are assignments ; w := regexp_substitute '\+' ' + ' w "g ; % CAUTION: '+' wipes out the line!!! ; w := regexp_substitute '-' ' - ' w "g ; w := regexp_substitute '\*\*' ' power ' w "g ; w := regexp_substitute '\*' ' * ' w "g ; w := regexp_substitute '/' ' / ' w "g ; w := regexp_substitute '=' ' := ' w "g ; % QNial automatically supports double precision (I think), but it has up to ~16 digit precision? ; w := regexp_substitute '\.D0' '' w "g ; w := regexp_substitute 'acos' ' arccos ' w "g ; w := regexp_substitute 'asin' ' arcsin ' w "g ; w := regexp_substitute 'atan' ' arctan ' w "g ; w := regexp_substitute '\.eq\.' ' = ' w "g ; w := regexp_substitute '\.ne\.' ' ~= ' w "g ; w := regexp_substitute '\.gt\.' ' > ' w "g ; w := regexp_substitute '\.ge\.' ' >= ' w "g ; w := regexp_substitute '\.lt\.' ' < ' w "g ; w := regexp_substitute '\.le\.' ' <= ' w "g ; w := regexp_substitute '\.and\.' ' and ' w "g ; w := regexp_substitute '\.or\.' ' or ' w "g ; w := regexp_substitute ' if ' ' IF ' w ; w := regexp_substitute ' then ' ' THEN ' w ; w := regexp_substitute ' else ' ' ELSE ' w ; w := regexp_substitute ' endif ' ' ENDIF ' w ; w := regexp_substitute ' do ' ' FOR ' w ; w := regexp_substitute ' end do ' ' ENDFOR ' w ; w := regexp_substitute ' case ' ' CASE ' w ; w := regexp_substitute ' end case ' ' ENDCASE ' w ; % special situations ; % arrangement, indented right across the page ; w := regexp_substitute '^c' '% ' w ; w := regexp_substitute 'write *(\*,\*)' 'writescreen ' w ; % actually, combine writescreen & read into single Q'Nial expression where values called for ; w := regexp_substitute 'read *(\*.\*)' 'readfile ' w ; w := regexp_substitute 'int(' ' floor ' w ; % put back "pretty stuff" ; w := regexp_substitute '' '*************************************************' w ; w := regexp_substitute '' '-------------------------------------------------' w ; % final work on each line ; w := w link ' ; ' ; % add semi-colon to the end of each code line ; % THEN remove it from lines that aren't supposed to have it (eg empty lines) ; writefile fout w ; ENDWHILE ; close fin ; close fout ; } # Example filename_in := 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Laskar - Milankovic insolation program\2004 program\prepsub.f' ; filename_out := 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Laskar - Milankovic insolation program\2004 Howell\Laskar - prepsub test2.ndf' ; #************************************ # Todo later # for comment lines starting with 'c' - put 'subroutine' statement: - into comments - copy to beginning of function defn - replace '(' by ' IS OP ' - replace ',' by ' ' - remove last ')' - follow by '\n{\n' (on next line...) # replace ' return\n end\n' with '}' # grep - convert x(y) to x@y for array X, must distinguish from functions!!! grep - convert 'XA(I + M)' to 'XA@[I + M]' for array XA, must distinguish from functions!!! # will need to handle multi-line features like the "return-end" thing # The backslash character, \ , which is used to continue a line of a definition in immediate mode, must not be inserted at the end of lines in a definition file. loaddefs_ended f_portGrepFortrantoQNial ; # enddoc