source: trunk/SRC/ReadWrite/idl-NetCDF/ncdf_quickwrite/README_ncdf_quickwrite.txt @ 163

Last change on this file since 163 was 70, checked in by pinsard, 18 years ago

update according to idl-NetCDF-v04.tar.gz available via http://www.ittvis.com/codebank/search.asp?FID=418; side effects are not tested

  • Property svn:executable set to *
File size: 7.7 KB
Line 
1
2NAME:
3
4   ncdf_quickwrite
5
6
7SYNOPSIS:
8
9   This is a routine for writing variables from an IDL session to a
10   NetCDF file, in just a very few commands.
11
12   It is designed to be quick to *use*, once you are familiar with the syntax.
13
14   It may possibly also be slightly quicker to *learn* than writing NetCDF
15   files the standard way, but this is not particularly the objective.
16
17
18DESCRIPTION:
19
201) Ensure that the supplied routines are installed in your IDL_PATH.
21
22         ncdf_quickwrite.pro
23         ncdf_quickwrite_helper1.pro
24         ncdf_quickwrite_helper2.pro
25         ncdf_quickwrite_helper3.pro
26
272) Set the string variable NCFILE to the NetCDF filename you wish to write,
28   For example:
29
30         ncfile='myfile.nc'
31
32   The file should not already exist.  If you wish to permit overwriting, put
33   "!" before the filename.  For example:
34
35         ncfile='!myfile.nc'
36
373) Set the string variable NCFIELDS as follows.
38   NB there are a number of options but you do not need to use them all!
39   Skip down to "USAGE EXAMPLE" below for a simple example.
40
41   a) For each variable, construct the VARIABLE SPECIFICATION as follows:
42
43        => For an array, use the name of array, with the names of the
44           dimensions in square brackets ([]) and separated by commas.
45           For example:
46
47                 pressure[longitude,latitude]
48
49        => For a 1-dimensional array, whose dimension name is the same
50           as the array name, you can omit the dimension name if you want.
51           For example:
52
53                 longitude[]
54
55        => For each scalar, do not use square brackets, e.g.:
56
57                 g
58
59        => If any of variables you want to use in the NetCDF file is not held
60           in a variable of the same name in your IDL session, then put
61           follow the variable specification with "=expression".
62
63           Examples:
64
65               1) if pressure is in IDL variable "p", you have:
66
67                       pressure[longitude,latitude]=p
68
69               2) if g is not stored in a variable but should
70                  have value 9.8, you have:
71
72                       g=9.8
73
74        => If any of the variables have attributes to be stored, follow
75           the specification with a colon (:) followed by the name of
76           a variable containing a structure of attributes.  For example:
77
78               pressure[longitude,latitude]=p:patts
79
80               where "patts" is a structure containing:
81                         {units:'pascal',missing_value:1e10}
82
83   b) Join up all the variables with semicolons (;) to make the NCFIELDS
84      string.  For example:
85
86      NCFIELDS = $
87       'pressure[longitude,latitude]=p:patts;longitude[];latitude[];g=9.8'
88
89   c) If there is a dimension, which you want to be of UNLIMITED size, then
90      precede its name with "*" somewhere where it is mentioned (or where
91      you omit the dimension name because it matches the variable name,
92      nonetheless still include the "*" in the square brackets).  For example
93      the "time" dimension in any of the following:
94
95        NCFIELDS = $
96         'pressure[longitude,latitude,*time];longitude[];latitude[];time[]'
97
98        NCFIELDS = $
99         'pressure[longitude,latitude,time];longitude[];latitude[];time[*time]'
100
101        NCFIELDS = $
102         'pressure[longitude,latitude,time];longitude[];latitude[];time[*]'
103
104      (Note that if you put "*" before the same dimension name more than once,
105      that is accepted.  But if you put "*" before more than one dimension
106      name, that is an error, because only one dimension can be UNLIMITED.)
107
108   d) If there are global attributes, follow the specification with an
109      at sign (@) followed by the name of a variable containing a structure
110      of attributes.  For example:
111       
112        NCFIELDS = $
113          'pressure[longitude,latitude];longitude[];latitude[]@globatts'
114
115        where "globatts" is a structure containing:
116                         {source:'my program',version:2}
117
118   e) You may insert whitespace in NCFIELDS for readability.
119
1204) Type:  @ncdf_quickwrite
121
122
123USAGE EXAMPLES:
124
1251) SIMPLE EXAMPLE.
126
127      =>  You have the following variables:
128
129           LATITUDE        FLOAT     = Array[73]
130           LONGITUDE       FLOAT     = Array[96]
131           PRESSURE        DOUBLE    = Array[96, 73]
132
133      =>  You issue the following commands:
134
135           ncfile='my.nc'
136           ncfields='latitude[];longitude[];pressure[longitude,latitude]'
137           @ncdf_quickwrite
138
139      =>  This makes "my.nc". "ncdump -h my.nc" reports the following:
140
141           netcdf my {
142           dimensions:
143                   latitude = 73 ;
144                   longitude = 96 ;
145           variables:
146                   float latitude(latitude) ;
147                   float longitude(longitude) ;
148                   double pressure(latitude, longitude) ;
149           }
150
1512) MORE COMPLEX EXAMPLE.
152
153      =>  You have the following variables:
154
155           LATS            FLOAT     = Array[73]
156           LONS            FLOAT     = Array[96]
157           P               DOUBLE    = Array[96, 73, 100]
158           UBAR            DOUBLE    = Array[73, 100]
159           YR              LONG      = Array[100]
160
161      =>  You issue the following commands.
162          (NB The NCFIELDS assignment can be typed as one long line, but is
163          split below for readability.)
164
165             ncfile='!my.nc'
166             angle_attr={units:'degrees'}
167             wind_attr={units:'m s-1'}
168             press_attr={units:'pascals',missing_value:1e10}
169             g_attr={units:'m s-2'}
170             globattr={source:'My program',version:2}
171             
172             ncfields = 'pressure[longitude,latitude,time]=p:press_attr; ' $
173                      + 'longitude[]=lons:angle_attr; ' $
174                      + 'latitude[]=lats:angle_attr; ' $
175                      + 'ubar[latitude,time]:wind_attr; ' $
176                      + 'year[*time]=yr; ' $
177                      + 'g=9.8:g_attr @ globattr'
178             
179             @ncdf_quickwrite
180
181      =>  This makes "my.nc", overwriting any existing my.nc.
182          "ncdump -h my.nc" reports the following:
183
184           netcdf my {
185           dimensions:
186                   longitude = 96 ;
187                   latitude = 73 ;
188                   time = UNLIMITED ; // (100 currently)
189           variables:
190                   double pressure(time, latitude, longitude) ;
191                           pressure:units = "pascals" ;
192                           pressure:missing_value = 1.e+10f ;
193                   float longitude(longitude) ;
194                           longitude:units = "degrees" ;
195                   float latitude(latitude) ;
196                           latitude:units = "degrees" ;
197                   double ubar(time, latitude) ;
198                           ubar:units = "m s-1" ;
199                   int year(time) ;
200                   float g ;
201                           g:units = "m s-2" ;
202           
203           // global attributes:
204                           :source = "My program" ;
205                           :version = 2s ;
206           }
207     
208           (Note that in this example you have created a NetCDF file
209            with verbose variable names even though the IDL variables
210            have terse names.)
211
212BUGS:
213
214  => Writing string variables may fail.
215
216
217LIMITATIONS:
218
219  => An expression following an "=" sign should not contain ":" or ";" signs
220     because these will be treated as separators.
221
222  => An expression following an "=" sign gets evaluated twice.  If this is
223     computationally expensive, store it in a variable and reference the
224     variable instead.
225
226  => Attribute names are case-insensitive because they are structure tags.
227     In fact, they are stored as lower case.
228
229
230AUTHOR:
231
232   Alan Iwi <A.M.Iwi@rl.ac.uk>
233
234
235COPYRIGHT:
236
237   I am putting these routines in the public domain.
238
239   But the IDL program itself is subject to copyright restrictions.
240
Note: See TracBrowser for help on using the repository browser.