MITGCM recipee for building a package

| 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.

org-mode source

Read and Post Comments

Alternative to keyword substitution in git, using org-mode

| categories: orgmode, max, git, linux | View Comments

Linus Torvalds thinks that cvs-style keyword substitution (like having the string \(Log\) substituted by actual cvs logs in text file) is idiotic. He's got some points, like avoiding mess in binary files. I think that seeing a log in my org-files is not that bad, and it gives me a notion of the gradual advances that were made. I found the following lines to be non-intrusive enough to make them an almost keyword-substitution-substitution.

# git logging 
#+BEGIN_SRC sh :exports results :results raw drawer
git log | sed -e "s/^/# /g"
\#+END_SRC

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

Backups on OS X

| categories: mac, linux | View Comments

Back to backing up (no pun intended), OS X uses a launchd system rather than "cron.daily". If you are like me, you probably don't want to know why and you don't care. You just want a cron.daily approach, and a way to know whether it worked or not.

So put your bash script from here somewhere on your system, and put the following script in your ~/Library/LaunchAgents/ , with a name like me.bckup.daily.plist (though the name should not matter, or so they tell) :

 1: <?xml version="1.0" encoding="UTF-8"?>
 2: <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/
 3: DTDs/PropertyList-1.0.dtd">
 4: <plist version="1.0">
 5: <dict>
 6: <key>Label</key>
 7: <string>me.bckup.daily</string>
 8: <key>LowPriorityIO</key>
 9: <true/>
10: <key>Nice</key>
11: <integer>12</integer>
12: <key>Program</key>
13: <string>/path/to/your/script/bckup_to_hd</string>
14: <key>StartCalendarInterval</key>
15: <dict>
16: <key>Hour</key>
17: <integer>16</integer>
18: <key>Minute</key>
19: <integer>49</integer>
20: </dict>
21: <key>StandardErrorPath</key>
22: <string>/path/to/log_err_file.txt</string>
23: <key>StandardOutPath</key>
24: <string>/path/to/log_out_file.txt</string>
25: </dict>
26: </plist>

with the obvious ammendments of the exact time you want it to be launched every day, and your exact absolute paths.

To begin its action for the first time, either logout and login or :

1: launchctl load me.bckup.daily.plist

If something went wrong, you could use launchctl unload instead of load , get things straight and load again.

Now, how do you know if something went wrong ?

first, you have your log files /path/to/log_*_file.txt . Second, you could search for clues in /private/var/log/system.log in the time you designated.

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

Backups

| categories: mac, linux | View Comments

Backuping should be - routine,automatic, and simple. I'm using the following:

1: rsync --force --ignore-errors --delete \
2:  --exclude /path/to/*excluded_files* \
3:  --backup-dir=`date +%Y-%m` -avb /home/yourname/ \
4:  /path/to/your/BCK/hd

Each month you get a new directory YYYYmm (year+month) on your backup hard drive, for files that have been changed/deleted during this month. You should probably delete it after a few months, but sometimes you will want to recover some data which was mistakenly deleted. Otherwise, all other files (which weren't deleted or modified) are just duplicated to the backup hd.

If you are using linux, you should probably put this script in your /etc/cron.daily/ directory. And give it the correct permissions.

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

GMT pen attributes

| categories: gmt | View Comments

A lot of GMT programs have flags with "pen" attributes. It is not very easy to find in the man pages or the pdf documentation what is a pen. So…

A pen is a comma separated triple parameter :

width,color,style

where :

  • width = faint default thinnest thinner thin thick thicker thickest fat fatter fattest obese it can also be indicated in numbers in the range [0 18p]
  • color = a gray shade in the range 0–255 (linearly going from black (0) to white (255)). or RGB, by specifying r/g/b, each ranging from 0–255. Here 0/0/0 is black, 255/255/255 is white, 255/0/0 is red, etc. or color Name. There are 663 valid color names. Use man gmtcolors to list all valid names. A very small yet versatile subset consists of the 29 choices white, black, and [light:|dark]{red, orange, yellow, green, cyan, blue, magenta, gray|grey, brown}. The color names are case-insensitive, so mixed upper and lower case can be used (like DarkGreen).
  • style = solid, dashed, etc.

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

Next Page »