MODULE M3UTILIO Fortran-90 styleMODULE M3UTILIOdoes the "proper F90 way" of encapsulating the Models-3 I/O API parameter, data structure, and function-declarations, in a way that nested FortranUSE <module>constructs do not interact with older FortranINCLUDEstatements to generate multiple-declaration errors at compile time.The issue is that when one has two or more Fortran-90
MODULEs, sayMODULE AthatUSEsMODULE B, where both of these need access to facilities provded by the standard I/O APIINCLUDEfilesPARMS3.EXT,FDESC3.EXT, and/orIODECL3.EXT, there is a problem: ifMODULE BINCLUDEs these, it introduces an artificial dependency ofMODULE AuponMODULE B: where should theINCLUDEstatements be placed (if they appear in bothMODULEs, the compiler will complain that variables and functions have repeated declarations, which is illegal. The problem is even worse ifMODULE AUSEs a thirdMODULE C, independent ofB, that also needs I/O APIINCLUDEfiles: one can't necessarily makeC USE B, or vice versa.However, the Fortran-90
USEconstruct does not have this problem:MODULEsA,B, andCcan all have statementsUSE M3UTILIOwithout causing multiple-declaration problems: the recognition that these statements provide one common set of declarations is now built into the Fortran-90 (and later) language, in a way not possible at all for Fortran-77 (and that must be managed manually by the programmer with #ifdefs for the corresponding C #include construct).
MODULE M3UTILIOMODULE M3UTILIOitself includes, and therefore replaces theINCLUDEof the following Models-3 I/O APIINCLUDEfiles:It further provides Fortran-90 style
PARMS3.EXTFDESC3.EXTIODECL3.EXTINTERFACEblocks for the following list of routines (basically, all of the public routines in the I/O API whose usage does not require "void pointer" arguments -- note that theBUFFERargument for WRITE3() does not have a single specified type; it may beINTEGER, REAL,orDOUBLE PRECISION, and may have an arbitrary number of dimensions, instead of being restricted (as anINTERFACEwould require) to one single possibility like a 3-DREAL BUFFER(:,:,:), or requiring over three thousand lines of "wrapper" code to support the implied polymorphism. (IODECL3.EXTis invoked from thisMODULEto provide theEXTERNALdeclarations for these polymorphic routines, but not full interface blocks.)It also provides four cleanly-coded public parsing-utility routines that replace various less-well-conceived SMOKE 1.x library-routines,and new utility routines for grid-description checking and for integer unsorted-table lookup:
BILINBMATVECCURRECCURSTEPDAYMONDMATVECDSCGRID and DSCOORDDT2STRENVDBLEENVINTENVREALENVSTRENVYNFINDCFIND1FIND2FIND3FIND4FINDR1FINDR2FINDR3FINDR4GCDGETDATEGETDBLEGETDFILEGETEFILEGETFFILEGETMENUGETNUMGETREALGETSTRGETYNGRDCHK3HHMMSSINDEX1INDEXINT1INTLISTISDSTJSTEP3JULIANJUNITLAMBERTand related routinesLBLANKLOCAT1LOCAT2LOCAT3LOCAT4LOCATCLOCATR1LOCATR2LOCATR3LOCATR4LUSTRM3EXITM3FLUSHM3MESGM3MSG2M3PARAGM3PROMPTM3WARNMMDDYYNEXTIMEPCOEFPMATVECPOLYPROMPTDFILEPROMPTFFILEPROMPTMFILEPROMPTGRID()REALISTSCANINT()SEC2TIMESECSDIFFSETENVVARSORTICSORTI1SORTI2SORTI3SORTI4SORTR1SORTR2SORTR3SORTR4STR2DBLESTR2INTSTR2REALSTRLISTTIME2SECUNGRIDBUNGRIDIUPCASE()WKDAYYEAR4YR2DAY- and more...
SUBROUTINE SPLITLINE( LINE, NMAX, N, FIELD, EFLAG )
CHARACTER(LEN=*), INTENT( IN ):: LINE
INTEGER, INTENT( IN ):: NMAX
INTEGER, INTENT( OUT ):: N
CHARACTER(LEN=*), INTENT( OUT ):: FIELD( NMAX )
LOGICAL, INTENT( OUT ):: EFLAG- split a line into fields, ignoring comments
SUBROUTINE FIXFIELDCHARACTER(LEN=*), INTENT( INOUT ):: FIELD- fixup, replacing blanks and "missing"s in character-string fields by zeros
REAL FUNCTION KEYVALCHARACTER(LEN=*), INTENT( IN ) :: KEY- search for
REALkey-value in I/O API file descriptive headerFDESC3Darray.
KEYSTR- search for REAL key-value in I/O API file descriptive header
FDESC3Darray.
Note that in retro-fitting
MODULE M3UTILIOinto existing codes, one must not only remove all of theINCLUDEstatements associated with the standard I/O APIPARMS3.EXT,FDESC3.EXT, and/orIODECL3.EXT, one must also remove any (now extra) declarations of the functions with explicitINTERFACEs from the list given above.
Send comments to
Carlie J. Coats, Jr.
carlie.coats@baronams.com