Difference between revisions of "General GAMAP usage"
(→Using 0.5 x 0.667 grids with GAMAP) |
(→Note for Windows users) |
||
Line 66: | Line 66: | ||
--[[User:Bmy|Bob Y.]] 13:49, 7 July 2008 (EDT) | --[[User:Bmy|Bob Y.]] 13:49, 7 July 2008 (EDT) | ||
+ | |||
+ | === Note for Mac users=== | ||
+ | |||
+ | If you experience a problem starting up GAMAP on a Mac, make sure to place the <tt>gamap2</tt> directory into your home directory. If you place it into your <tt>Applications/itt</tt> directory you may encounter path problems. | ||
+ | |||
+ | --[[User:Bmy|Bob Y.]] 09:46, 18 February 2011 (EST) | ||
== Using CTM_GET_DATA with the STATUS keyword == | == Using CTM_GET_DATA with the STATUS keyword == |
Revision as of 14:46, 18 February 2011
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
- Color and graphics with GAMAP
- Regridding with GAMAP
- Date and time computations with GAMAP
- Text manipulation with GAMAP
--Bob Y. 16:05, 26 November 2008 (EST)
Contents
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
Note for Windows users
one user reported that replacing
Sep = Path_Sep( /Search_Path ) PREF_SET, 'IDL_PATH', $ EXPAND_PATH('+~/IDL/gamap2/', /ALL_DIRS ) + Sep + $ '<IDL_DEFAULT>', /COMMIT
with
IdlPath = Expand_Path( '+' + !PATH, /All_Dirs ) Sep = Path_Sep( /Search_Path ) PREF_SET, 'IDL_PATH', $ EXPAND_PATH('+~/IDL/gamap2/', /ALL_DIRS ) + Sep + $ idlpath, /COMMIT
in idl_startup.pro solved the following problem under Windows: !path would not contain directories without a *.pro file.
NOTES:
- The PREF_SET command was introduced in IDL 6.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.
- 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.
- 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.
- 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.
- 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.)
- 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:\).
- 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 10:52, 30 March 2009 (EDT)
--Bob Y. 13:49, 7 July 2008 (EDT)
Note for Mac users
If you experience a problem starting up GAMAP on a Mac, make sure to place the gamap2 directory into your home directory. If you place it into your Applications/itt directory you may encounter path problems.
--Bob Y. 09:46, 18 February 2011 (EST)
Using CTM_GET_DATA with the STATUS keyword
Here I document an advanced usage of CTM_GET_DATA. Sometimes CTM_GET_DATA (or a routine that calls it) crashes with the following message:
% CTM_RETRIEVE_DATA: *** SERIOUS: More than 1 item found!
This message indicates more than one datablock with the same metadata has been found, when only one was expected. If you call CTM_GET_DATA with the (non documented...) STATUS keyword, then the message disappears. Only the metadata are read, and the data pointers in the datainfo structures are null pointers. You cannot dereference them. To access the data, you must call CTM_READ_DATA instead:
; read metadata only ctm_get_data, di, ....., status=2 ; then find the index you want in the array of structure di ... ; then get the data ( wanted_array = *di[ wanted_index ] is not valid since pointer is null) ctm_read_data, wanted_array, di[ wanted_index ], result=r
This method has been used for example in gc_combine_nd48.pro of GAMAP v2.13.
--phs 17:48, 8 October 2009 (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:
- start your IDL session in your run directory
- start your IDL anywhere, and then: cd, 'your_run_directory', before using GAMAP
- copy your diag/tracerinfo.dat from your run dir to your ../gamap2/input_files/ (i.e., overwrite default ones), before using GAMAP
- Advanced 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 (1) : 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 refer 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 others objects and/or pointers alive in your code (i.e., you do not want to call heap_gc or you want to call ctm_cleanup with /no_gc), you need to free only the "no global" 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(..., /No_Global), 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
Memory management (2) : UNDEFINE
The UNDEFINE (as of GAMAP v2.13) routine is used to free memory. When called on a DataInfo structure, it just undefines the datainfo variable, but not the data pointer inside it, at the risk of memory leak if the datainfo.data pointer points to some data. This is opposite to the expected effect! Note that CTM_CLEANUP is doing a fine job at unallocating gamap pointers when needed, as long as the datainfo structure have not been undefined. In GAMAP, most calls to UNDEFINE, if not all, are probably not needed.
Note that an updated UNDEFINE routine is available at D. Fanning site. This update does free pointers within a structure, thus avoiding memory leak. Its usage in GAMAP is being tested, but not part of GAMAP v2.13.
--phs 17:03, 8 October 2009 (EDT)
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)
Using 0.5 x 0.667 grids with GAMAP
Win Trivitayanurak wrote:
- I'm looking for IDL code (i.e. codes in GAMAP package) that works for 0.5x0.667 resolution but apparently didn't find one in my gamap2 package.
- Specifically i have to regrid the restart file from 4x5 to 0.5x0.66 resolution China nested-grid domain (for GEOS-5 47L vertical res.). But it seems to me that other utility codes like ctm_type.pro does not have any info about the 0.5 x 0.66 resolution too.
Bob Yantosca wrote:
- You can specify the 0.5 x 0.667 grid with
InType = CTM_TYPE( MODELNAME='GEOS5_47L', RES=[2D/3D, 1D/2D] ... ) InGrid = CTM_GRID( InType )
- etc. The trick is that you need to pass the resolution string as fractions of double precision #'s to get the lats & lons specified correctly.
- You will probably have to define a global 0.5 x 0.666 grid for the regridding (i.e. pass that to REGRIDH_RESTART) and then cut the global file down to size with the CREATE_NESTED etc. routines (located in the gamap2/regridding subdirectories).
--Bob Y. 13:33, 24 April 2009 (EDT)