Difference between revisions of "General GAMAP usage"

From Geos-chem
Jump to: navigation, search
Line 1: Line 1:
On this page we list some general GAMAP tips & tricks.  Please also see the following pages:
+
On this page we list some general GAMAP tips & tricks.  Please also see the following pages for more tips & tricks:
 
+
 
* [[File I/O with GAMAP]]
 
* [[File I/O with GAMAP]]
 
* [[Color and graphics with GAMAP]]
 
* [[Color and graphics with GAMAP]]
Line 6: Line 5:
 
* [[Date and time computations with GAMAP]]
 
* [[Date and time computations with GAMAP]]
 
* [[Text manipulation with GAMAP ]]
 
* [[Text manipulation with GAMAP ]]
 +
--[[User:Bmy|Bob Y.]] 16:05, 26 November 2008 (EST)
  
 
== GAMAP and IDL 7 ==
 
== GAMAP and IDL 7 ==
Line 73: Line 73:
 
  print, file_which('tracerinfo.dat')
 
  print, file_which('tracerinfo.dat')
 
--[[User:Plesager|phs]] 15:52, 4 April 2008 (EDT)
 
--[[User:Plesager|phs]] 15:52, 4 April 2008 (EDT)
 
== Date and time ==
 
 
This section has been split off into its own wiki page, [[Date and time computations with GAMAP|''Date and Time Computations with GAMAP'']].
 
 
== Text manipulation with GAMAP ==
 
 
This section has been split off into its own wiki page, [[Text manipulation with GAMAP|''Text manipulation with GAMAP'']].
 
  
 
== Memory management and CTM_MAKE_DATAINFO ==
 
== Memory management and CTM_MAKE_DATAINFO ==

Revision as of 21:05, 26 November 2008

On this page we list some general GAMAP tips & tricks. Please also see the following pages for more tips & tricks:

--Bob Y. 16:05, 26 November 2008 (EST)

GAMAP and IDL 7

Version 7 of IDL comes with a new development environment (called Workbench) based on Eclipse. If you are not using the IDL Workbench, you will not notice any change. But if you do, you will see a major upgrade, ... and may soon have a problem with the !PATH definition. For GAMAP to work properly, we provide an idl_startup.pro template file for you to modify for your system. In this routine, you used to see the !PATH defined like that:

IdlPath = Expand_Path( '+' + !PATH,  /All_Dirs ) 

!PATH       = EXPAND_PATH('+~/IDL/gamap2/', /ALL_DIRS) + ':' + $
              EXPAND_PATH('+~/IDL/idlpro/')            + ':' + $
              EXPAND_PATH('+~/IDL/jhuapl/')            + ':' + $
              IdlPath

Now, for GAMAP to work with the new IDL Workbench, you must use the following syntax instead:

; Call the IDL routine PATH_SEP to get the path separator token 
; (i.e. the character that you need to separate directories in !PATH). 
; This token is different depending on which OS you are using.
Sep     = Path_Sep( /Search_Path )

; Use the PREF_SET command to append your directories into the default
; IDL search path.  This approach is necessary if you want to use the 
; IDL Workbench in IDL 7.0 and later versions. (phs, bmy, 4/15/08)
PREF_SET, 'IDL_PATH',                                        $
           EXPAND_PATH('+~/IDL/gamap2/', /ALL_DIRS ) + Sep + $
           EXPAND_PATH('+~/IDL/idlpro/'            ) + Sep + $
           EXPAND_PATH('+~/IDL/jhuapl/'            ) + Sep + $
           '<IDL_DEFAULT>', /COMMIT

NOTES:

  1. The PREF_SET command was introduced in IDL 6.2.
  2. This syntax can be added to your idl_startup.pro file even if you do not use the IDL Workbench. More about that issue can be found here.
  3. You can add/delete directories to the IDL_PATH corresponding to the particular directory structure in your space. In this particular example we are adding the gamap2, idlpro, and jhuapl directories to IDL_PATH. If, for example, you don't have an idlpro directory, you can of course omit that.
  4. The EXPAND_PATH function should expand a relative file path (i.e. with a ~) to a full file path. However, there may be some flavors of Linux for which ~ might be problematic.
  5. Adding a + before the directory name in the call to EXPAND_PATH will make IDL search the directory and all of its subdirectories for files of the appropriate type (*.pro, *.sav) for the given path.
  6. Using the /ALL_DIRS keyword in the call to EXPAND_PATH, such as EXPAND_PATH( '+~/IDL/gamap2/', /ALL_DIRS ), will cause IDL to return the full path names of all of the subdirectories under ~/IDL/gamap2, regardless of whether or not they contain *.pro or *.sav files. (IDL's default behavior is to only return path names for those directories containing *.pro or *.sav files.)
  7. If the EXPAND_PATH function for some reason does not expand the filepaths, then you can specify them manually. Windows users might need to start the string with the drive letter (e.g. C:\).
  8. It is best to create the <IDL_DEFAULT> string with PREF_SET. Do not attempt to add the file paths directly to the IDLDE or IDL Workbench GUI.

--phs 16:42, 14 April 2008 (EDT)

--Bob Y. 13:49, 7 July 2008 (EDT)

Usage of TRACERINFO.DAT and DIAGINFO.DAT

User A said he keeps getting this message:

% UPDATE_TRACER_DATAINFO: WARNING: Use_DataInfo appears independent from global array!

User B said:

My ctm.bpch files have duplicate data blocks for some parameters. Something's wrong!

Answer:

These are symptoms of diaginfo.dat or/and tracerinfo.dat that do not match the binary punch file (user B), or that the bpch file was created with inadequate diag/tracerinfo.dat files and end up with duplicate 999 tracers without tracername for example (user B). The solution is to use correct diag/tracerinfo.dat when reading and creating bpch files. GEOS-Chem now writes those files for each runs in your run directory. If you use them when reading run outputs, you will not have a problem.

The first time a GAMAP routine is used, it will look for and read these files. First, in the current directory, then in the !path variable (which means it will used the default ones in ../gamap2/input_files/). So, to read those corresponding to your run you can:

  1. start your IDL session in your run directory
  2. start your IDL anywhere, and then: cd, 'your_run_directory', before using GAMAP
  3. copy your diag/tracerinfo.dat from your run dir to your ../gamap2/input_files/ (i.e., overwrite default ones), before using GAMAP
  4. Advance users can also, at anytime in their session, force GAMAP to read specific diag/tracerinfo.dat:
ctm_diaginfo, /all, /force_reading, filename='your_diaginfo.dat'
ctm_tracerinfo, /all, /force_reading, filename='your_tracerinfo.dat'

If you are using a default location, double check that it is really used with the following query:

print, file_which('tracerinfo.dat')

--phs 15:52, 4 April 2008 (EDT)

Memory management and CTM_MAKE_DATAINFO

When using CTM_MAKE_DATAINFO, you create few pointers and allocate memory to pointed data. Three scenarios to free that memory are possible.

(1) By default, GAMAP keeps track of the pointers in a global structure, and you can clean up the memory by calling CTM_CLEANUP (with or without the keyword /NO_GC):

    ctm_make_datainfo(data, ...)
    CTM_WriteBpch, DataInfo, FileInfo, FileName=file
    ctm_cleanup

(2) If you use the keyword /NO_GLOBAL when calling CTM_MAKE_DATAINFO, the story is a little bit more subtle. Now, GAMAP has no idea of the created pointers. If you use CTM_CLEANUP without the keyword /NO_GC, everything is clean up because there is a call to heap_gc. But you are also loosing **all other** pointers and objects.

    ctm_make_datainfo(data, ..., /No_global)
    CTM_WriteBpch, DataInfo, FileInfo, FileName=file
    ctm_cleanup

Note if you do not call ctm_cleanup or call it with /No_GC, then the memory allocated by CTM_MAKE_DATAINFO is still allocated and the pointers that refers to it are alive... until you exit the routine (unless they are passed back). Once you are out of the routine, this memory remains allocated but is useless since unaccessible, in other words you have memory leak.

(3) So, if you want to keep some objects and/or pointers alive in your code (i.e., you do not want to call heap_gc or ctm_cleanup,/no_gc), you need to free only the created pointers as follows:

    ctm_make_datainfo(data, datainfo, fileinfo, ..., /No_global)
    CTM_WriteBpch, DataInfo, FileInfo, FileName=file
    ptr_free, DataInfo.data
    ptr_free, fileinfo.gridinfo

To free only the heap memory created by multiple calls to CTM_MAKE_DATAINFO, the procedure is:

  for D=0L, NTracers-1L do begin
     
     Success = CTM_Make_DataInfo( Data[*,*,D], DataInfo, FileInfo, ..., /No_Global )
     
     ArrDataInfo = D eq 0l ? [ DataInfo ] : [ ArrDataInfo, DataInfo ]
     
     if D ne Ntracers-1l then ptr_free, Fileinfo.gridinfo
     
  endfor
     
  CTM_WriteBpch, ArrDataInfo, FileInfo, FileName=OutFileName
     
  for d=0, n_elements(ArrDataInfo)-1l do ptr_free, ArrDataInfo[d].data
  ptr_free, fileinfo.gridinfo

--phs 10:28, 13 February 2008

GAMAP routines for statistical analysis

GAMAP ships with several routins for computing various statistical quantities:

CUM_TOTAL
Computes the cumulative total of an array.
MEAN
Computes the mean value of an array of any # of dimensions.
ORG_CORR
Calculates the reduced major-axis.
PERCENTILES
Computes percentiles of an array
QQNORM
Sorts a data array, assigns assign actual "probability" and calculates the expected deviation from the mean.
RUN_AV
Computes the running average or running total of a data vector.

Also, the IDL routine MOMENT computes the 4 statistical moments of a data set: mean, variance, skewness, and kurtosis.

--Bob Y. 09:42, 8 July 2008 (EDT)