MITGCM recipee for building a package
June 11, 2015 at 03:13 PM | categories: mitgcm | View Comments
It is not easy to include a new functionality in a huge computer simulation such as MITgcm , even if it is very modular and written with extensions in mind (and it is). So here is my experience with it. In the following, some of the replacements could be done on your local "code" directory, rather than on the root. The name of the example package is mypack.
1 prepare an empty package that does nothing
the minimal list of files (which can be coppied, with necessary name changes of files/variables/parameters/functions, from MYPACKAGE) is:
mypack_calc.F mypack_diagnostics_init.F MYPACK_OPTIONS.h MYPACK_PARAMS.h MYPACK.h mypack_output.F mypack_routines.F mypack_check.F mypack_init_varia.F mypack_readparms.F
their description :
file | description |
---|---|
headers | |
MYPACK.h | define pkg variables, and their common blocks |
MYPACK_OPTIONS.h | package specific MACRO option defs |
MYPACK_PARAMS.h | package parameters and their common block (read from data.mypack) |
code | |
mypack_calc.F | interface for mitgcnuv (this is what the model's core calls) |
mypack_check.F | check dependencies/conflicts with other packages |
mypack_diagnostics_init.F | define diagnostics related to the package |
mypack_init_varia.F | initialize MYPACK parameters and variables |
mypack_output.F | create diagnostic outputs |
mypack_readparms.F | parse data.mypack |
mypack_routines.F | routines that implement double diffusion parametrization schemes |
they should be under a new directory of the rootdir (in mypack case ~/MITgcm/model/pkg/mypack )
the input file data.pkg should include the new entry "useMypack=.TRUE.," under the namelist "&PACKAGES"
this parameter should be declared (with the type LOGICAL
), and included in the common block PARM_PACKAGES under ~/MITgcm/model/inc/PARAMS.h
. it should also be included under the namelist "PACKAGES" in ~/MITgcm/model/src/packages_boot.F
, and its default value should usually be declared in this file to be .FALSE.
.
2 parse user parameters
in mypack_readparms
- create a separate NAMELIST for each namelist that should appear in data.mypack
.
then give the parameters default values. (e.g. mypack_scheme = 'kunze' )
then try to read them (e.g. "READ(UNIT=iUnit,NML=MYPACK_SCHEME,IOSTAT=errIO)" ) and monitor events where errIO<0 :
1: READ(UNIT=iUnit,NML=MYPACK_SCHEME,IOSTAT=errIO) 2: IF ( errIO .LT. 0 ) THEN 3: WRITE(msgBuf,'(A)') 4: & 'S/R INI_PARMS' 5: CALL PRINT_ERROR( msgBuf , 1) 6: WRITE(msgBuf,'(A)') 7: & 'Error reading numerical model ' 8: CALL PRINT_ERROR( msgBuf , 1) 9: WRITE(msgBuf,'(A)') 10: & 'parameter file "data.mypack"' 11: CALL PRINT_ERROR( msgBuf , 1) 12: WRITE(msgBuf,'(A)') 13: & 'Problem in namelist MYPACK_SCHEME' 14: CALL PRINT_ERROR( msgBuf , 1) 15: STOP 'ABNORMAL END: S/R MYPACK_INIT' 16: ENDIF 17: 18: CLOSE(iUnit)
finally tell STDOUT.*
that you're finished
1: WRITE(msgBuf,'(A)') ' MYPACK_INIT: finished reading data.mypack'
declare these variables in MYPACK_PARAMS.h
these subroutines are run from the model file packages_readparms.F
. these are the needed lines in packages_readparms.F
:
1: C-- Initialize Mypack parameters 2: IF (useMypack) CALL MYPACK_READPARMS( myThid ) 3: #endif
Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.