MEGMS logo - go to the home page
  1. Home

    1. MEGS_Log

    2. CoalLog tools

    3. Fortran Tools

      1. FF08Depends

      2. FF08Diff

      3. FF08FixedFormForEver

      4. FF08Obfuscate

      5. Internal test utilities

      6. aniso_varying_string

      7. Direct2D API bindings

      8. Fortran shared pointers

    4. Contact Us

  2. Site map

"Let's model me a mine"

M.E.G.M.S.


Mining & Exploration Geological Modelling Services

Previous topic Parent topic Home topic Next topic

FF08FixedFormForEver

FF08FixedFormForEver is a command line tool for rendering Fortran 2008 source in a number of horrible ways.

One day, a practical use for this tool may be found.

The tool itself is written in Fortran 2003. A zip archive of the latest source release (revision 2960 from 2020-04-17), available under an Apache 2.0 licence, can be found at www.megms.com.au/download/FF08FixedFormForEver.zip.

How to use

The command line has the following syntax:

FF08FixedFormForEver [options] source-file-specs...

Command line options:

-? or --help
Display command line and program usage help, then exit.
--version
Display program version information, then exit.
--list[:] file
Specify a list file - each record from the given file will be added (in addition to any source file specifications provided on the command line) to the list of source file specifications for the prevailing set (as indicated by --left and --right) to be processed. May be specified multiple times.
--free
Emits a compact free form variant instead,
--console-free
Reads free form input source from the console, after any other files. May not be used with a file specification of - or the --console-fixed option.
--console-fixed
Reads fixed form input source from the console, after any other files. May not be used with a file specification of - or the --console-free option.
@response-file
Nominates a response file with additional arguments and options. Each argument or option in a response file place should be in its own record. Options and arguments in response files are expanded as they are encountered into the total set of options and arguments for the program. Multiple response files may be specified, and response files may reference other response files, but a response file reference may not be recursive.

source-file-specs is a list of the names of the Fortran source files to parse.

A source-file-spec of - directs that source file specifications will also be read from the console, one file per record. A line that is zero length or all blanks terminates the input. - may only be specified once on the command line. This feature is useful with operating system shell provided pipes between programs.

Source files with an extension (part of the filename following the last dot) of for or f are taken to be fixed source form files. Source files with an extension of f90, f95, f03 or f08 are taken to be free source form. Other extensions result in an error. The comparison with the file extension is not case sensitive.

The resulting source code is written to the console.

Examples

Applying the tool to the source code for its own main program:

FF08FixedFormForEver FF08FixedFormForEver.f90

results in...

      PROGRAMFF08FIXEDFORMFOREVER;USECMDLINE;USEERRORS;USEFILEUTILITIES;
     1USEFIXEDFORMFOREVERIMPLEMENTATION;USESTRINGS;USE,INTRINSIC::ISO_FO
     2RTRAN_ENV,ONLY:OUTPUT_UNIT,ERROR_UNIT;IMPLICITNONE;CHARACTER(*),PA
     ORAMETER::PROGRAM_VERSION='FF08FixedFormForEver version 1.0';TYPE(C
     ]MDLINEOPTION)::CMD_LINE_OPTIONS(6);TYPE(STRING),ALLOCATABLE::ARGUM
     $ENTS(:);TYPE(STRING),ALLOCATABLE::FILE_SPECS(:);CHARACTER(:),ALLOC
     ~ATABLE::MSG;INTEGER::STAT;INTEGER::STOP_CODE;INTEGER::I;LOGICAL::O
     NUTPUT_FREE;LOGICAL::CONSOLE_FIXED;LOGICAL::CONSOLE_FREE;CHARACTER(
     `5)::CONSOLE_READ;LOGICAL::GOT_DASH;CMD_LINE_OPTIONS(1)=CMDLINEOPTI
     "ON('help',CHAR_NAME='?',DESCRIPTION='Display command line and prog
     &ram usage help, then exit.');CMD_LINE_OPTIONS(2)=CMDLINEOPTION('ve
     Nrsion',DESCRIPTION='Display program version information, then exit
     >.');CMD_LINE_OPTIONS(3)=CMDLINEOPTION('list',DESCRIPTION='Specify
     6a list file - each line from the given file will be added (in addi
     ?tion to any source file specifications provided on the command lin
     }e) to the list of source file specifications to be processed.  May
     . be specified multiple times.',OPTION_TYPE=IOPTARG,CAN_REPEAT=.TRU
     KE.);CMD_LINE_OPTIONS(4)=CMDLINEOPTION('free',DESCRIPTION='Emits a
     4compact free form variant instead.');CMD_LINE_OPTIONS(5)=CMDLINEOP
     'TION('console-free',DESCRIPTION='Reads free form input source from
     7 the console, after any other files.  May not be used with a file
     3specification of "-" or the --console-fixed option.');CMD_LINE_OPT
     6IONS(6)=CMDLINEOPTION('console-fixed',DESCRIPTION='Reads fixed for
     +m input source from the console, after any other files.  May not b
     ^e used with a file specification of "-" or the --console-free opti
     5on.');CALLPARSECMDLINE(CMD_LINE_OPTIONS,ARGUMENTS,STAT,MSG);IF(STA
     `T/=0)THEN;PRINT"('Error parsing command line:',A)",MSG;CALLUSAGE_M
     7ESSAGE(OUTPUT_UNIT,CMD_LINE_OPTIONS);STOP3;ENDIF;IF((CMD_LINE_OPTI
     )ONS(1)%PRESENTCOUNT>0).OR.(COMMAND_ARGUMENT_COUNT()==0))THEN;CALLU
     <SAGE_MESSAGE(OUTPUT_UNIT,CMD_LINE_OPTIONS);STOP;ENDIF;IF(CMD_LINE_
     8OPTIONS(2)%PRESENTCOUNT>0)THEN;PRINT"(A)",PROGRAM_VERSION;STOP
      ENDIF;OUTPUT_FREE=CMD_LINE_OPTIONS(4)%PRESENTCOUNT/=0;CONSOLE_FREE
     @=CMD_LINE_OPTIONS(5)%PRESENTCOUNT/=0;CONSOLE_FIXED=CMD_LINE_OPTION
     !S(6)%PRESENTCOUNT/=0;GOT_DASH=.FALSE.;DOI=1,SIZE(ARGUMENTS);IF(ARG
     2UMENTS(I)%ITEM=='-')THEN;IF(GOT_DASH)THEN;WRITE(ERROR_UNIT,"('''-'
     C' appears more than once on the command line.')");STOP3;ENDIF;GOT_
     @DASH=.TRUE.;IF(CONSOLE_FREE.OR.CONSOLE_FIXED)THEN;WRITE(ERROR_UNIT
     :,"('A file specification of ""-"" cannot be used if the --console-
     Ffree or --console-fixed options are present.')");STOP3;ENDIF;CALLA
     [DDFROMCONSOLE(FILE_SPECS,ERROR_UNIT,STOP_CODE);IF(STOP_CODE/=0)CAL
     =LDO_STOP;ELSE;CALLAPPEND(FILE_SPECS,ARGUMENTS(I)%ITEM);ENDIF;ENDDO
      DOI=1,CMD_LINE_OPTIONS(3)%PRESENTCOUNT;CALLADDLISTFILE(FILE_SPECS,
     WCMD_LINE_OPTIONS(3)%ARGUMENT(I)%ITEM,ERROR_UNIT,STOP_CODE);IF(STOP
     ~_CODE/=0)CALLDO_STOP;ENDDO;IF(CONSOLE_FREE.AND.CONSOLE_FIXED)THEN;
     2WRITE(ERROR_UNIT,"('The --console-free and --console-fixed options
     @ cannot both be present.')");STOP3;ELSEIF(CONSOLE_FREE)THEN;CONSOL
     *E_READ='FREE';ELSEIF(CONSOLE_FIXED)THEN;CONSOLE_READ='FIXED';ELSE;
     ;CONSOLE_READ='';ENDIF;CALLEXECUTE(FILE_SPECS,CONSOLE_READ,OUTPUT_F
     UREE,OUTPUT_UNIT,ERROR_UNIT,STOP_CODE);CALLDO_STOP;CONTAINS;SUBROUT
     }INEDO_STOP;SELECTCASE(STOP_CODE);CASE(0);CASE(1);STOP1;CASE(2);STO
     "P2;CASEDEFAULT;STOP3;ENDSELECT;ENDSUBROUTINEDO_STOP;SUBROUTINEUSAG
     TE_MESSAGE(OUT_UNIT,CMD_LINE_OPTIONS);USECMDLINE;INTEGER,INTENT(IN)
     E::OUT_UNIT;TYPE(CMDLINEOPTION),INTENT(IN)::CMD_LINE_OPTIONS(:);CHA
     .RACTER(*),PARAMETER::FMT_A="(A)";CHARACTER(:),ALLOCATABLE::PROGRAM
     [_NAME;INTEGER::STAT;WRITE(OUT_UNIT,FMT_A)'Format your fortran sour
     ,ce in ...rather compact... fixed or free form.';WRITE(OUT_UNIT,"()
     E");CALLGETCMDLINEARGUMENT(0,PROGRAM_NAME,STAT);IF(STAT/=0)PROGRAM_
     LNAME='FF08FixedFormForEver';WRITE(OUT_UNIT,FMT_A)'Usage: '//PROGRA
     IM_NAME//' [options] source-file-specs...';WRITE(OUT_UNIT,"()");WRI
     :TE(OUT_UNIT,FMT_A)'Valid options are:';WRITE(OUT_UNIT,"()");CALLWR
     +ITEUSAGEMESSAGE(CMD_LINE_OPTIONS,OUT_UNIT);WRITE(OUT_UNIT,FMT_A)'s
     )ource-file-specs is a list of the names of the Fortran source file
     (s to ','parse.  If there is a file named - then additional file na
     Xmes will be read ','from the console (one per line).';WRITE(OUT_UN
     WIT,FMT_A)'','The resulting source code is written to the console.'
      ENDSUBROUTINEUSAGE_MESSAGE;ENDPROGRAMFF08FIXEDFORMFOREVER  
      

Beautiful.

Building from source

The source code should be compilable by a Fortran 2003 compiler.

Intel Visual Fortran 15.0 was the compiler used for development. With that compiler, the /standard-semantics switch (or its equivalent on non-Windows platforms) is required.

The file compile-order.txt in the source archive specifies the order in which the included source files may be compiled.

Note that gfortran current trunk (at the time of writing r238060) cannot be used due to PR 44265, PR 71796 and PR 71807.

Feedback

Questions, queries and quibbles can be sent to ff08@megms.com.au.