source: trunk/condmag_output.pro

Last change on this file was 48, checked in by pinsard, 10 years ago

fix thanks to coding rules

  • Property svn:keyword set to Id
File size: 11.9 KB
Line 
1;+
2;
3; @file_comments
4; produce cond_sed_<orcares>.nc or Br_<orcares>.nc
5; dependent on orcares and variable parameters
6;
7; @categories
8; output, netcdf
9;
10; @param orcares {in}{required}{type=string}
11; code of ORCA grid to use for output results
12; must be 'ORCA2' or 'ORCA025'
13;
14; @param variable {in}{required}{type=structure return by NCDF_VARINQ}
15; { NAME:"", DATATYPE:"", NDIMS:0L, NATTS:0L, DIM:LONARR(NDIMS) }
16; variable of condmag.nc to be written
17; variable.NAME must be 'cond_sed' or 'Br'
18;
19; @param title {in}{required}{type=string}
20; title must belong_name 'Conductance' or 'Magnetic_field' ++
21;
22; @param long_name {in}{required}{type=string}
23; long_name must be 'Conductance' or 'magnetic_field' ++
24;
25; @param units {in}{required}{type=string}
26; units must be 'siemens' or 'tesla'
27;
28; @param jpio {in}{required}{type=integer}
29; x dimension of the 3d array to be written
30; must be greater than 1
31;
32; @param jpjo {in}{required}{type=integer}
33; y dimension of the 3d array to be written
34; must be greater than 1
35;
36; @param olon {in}{required}{type=1d array of floats}
37; x++ longitude values
38; must be ++
39;
40; @param olat {in}{required}{type=1d array of floats}
41; x++ latitude values
42; must be ++
43;
44; @param values {in}{required}{type=nd array of variable.DATATYPE}
45; values of the variable to be written
46; ++ must be
47;
48; @restrictions
49;  - Requires SAXO tools
50;
51; @todo
52; produce a NetCDF GDT or CF compliant
53; check if jpio and jpjo are not present in some "common" after getgridparam
54; in order to remove them from parameters
55;
56; @pre
57; reading of condmag.nc
58; see condmag_on_orca.pro
59;
60; @post
61; cond_sed_<I>orcasres</I>.nc is now present in ${GEOMAG_OD}/
62; or
63; Br_<I>orcasres</I>.nc is now present in ${GEOMAG_OD}/
64; see geomag_env.sh
65;
66; @examples
67; IDL> .run condmag_on_orca
68; IDL> condmag_output, 'ORCA2', 'cond_sed', 'Conductance', 'Conductance', 'siemens', jpio, jpjo, olon, olat, values
69;
70; @history
71; reee522 2006-12-13T11:44:19Z rhodes (IRIX64)
72; add attributes in parameters list
73; reee522 2006-11-28T14:07:32Z rhodes (IRIX64)
74; written from current release of condmag_on_orca.pro
75;
76; @version
77; $Id$
78;
79;-
80PRO condmag_output, orcares, variable, title, long_name, units, jpio, jpjo, olon, olat, values
81    ;
82    compile_opt idl2, strictarrsubs
83    ;
84    ;----
85    ; check input parameters
86    ;----
87    ;
88    ; check orcares definition
89    ;
90    CASE orcares OF
91        'ORCA2': BEGIN
92                 msg = 'iii : valid orcares parameter = ' +  orcares
93                 ras = report(msg)
94         END
95        'ORCA025': BEGIN
96                 msg = 'iii : valid orcares parameter = ' +  orcares
97                 ras = report(msg)
98         END
99         ELSE : BEGIN
100                 msg = 'eee : invalid orcares parameter = ' + orcares
101                 ras = report(msg)
102                 msg = 'eee : orcares must be ORCA2 or ORCA025'
103                 ras = report(msg)
104                 RETURN
105         END
106    ENDCASE
107    ;
108    ; check variable definition
109    ; ++ dimension etc.
110    CASE variable.NAME OF
111        'cond_sed': BEGIN
112             msg = 'iii : valid variable.NAME parameter = ' + variable.NAME
113             ras = report(msg)
114             CASE title OF
115                 'Conductance': BEGIN
116                      msg = 'iii : valid title parameter = ' + title
117                      ras = report(msg)
118                 END
119                 ELSE      : BEGIN
120                     msg = 'eee : invalid title parameter = ' + title
121                     ras = report(msg)
122                     msg = 'eee : title must be Conductance'
123                     ras = report(msg)
124                     RETURN
125                 END
126             ENDCASE
127             CASE long_name OF
128                 'Conductance': BEGIN
129                     msg = 'iii : valid long_name parameter = ' + long_name
130                     ras = report(msg)
131                 END
132                 ELSE      : BEGIN
133                     msg = 'eee : invalid long_name parameter = ' + long_name
134                     ras = report(msg)
135                     msg = 'eee : long_name must be Conductance'
136                     ras = report(msg)
137                     RETURN
138                 END
139             ENDCASE
140             CASE units OF
141                 'siemens': BEGIN
142                                     msg = 'iii : valid units parameter = ' + units
143                                     ras = report(msg)
144                 END
145                 ELSE      : BEGIN
146                                      msg = 'eee : invalid units parameter = ' + units
147                                      ras = report(msg)
148                                      msg = 'eee : units must be siemens'
149                                      ras = report(msg)
150                                      RETURN
151                 END
152             ENDCASE
153         END
154         'Br'  : BEGIN
155             msg = 'iii : valid variable.NAME parameter = ' + variable.NAME
156             ras = report(msg)
157             CASE title OF
158                 'Magnetic field': BEGIN
159                     msg = 'iii : valid title parameter = ' + title
160                     ras = report(msg)
161                 END
162                 ELSE      : BEGIN
163                    msg = 'eee : invalid title parameter = ' + title
164                    ras = report(msg)
165                    msg = 'eee : title must be Magnetic field'
166                    ras = report(msg)
167                    RETURN
168                 END
169             ENDCASE
170             CASE long_name OF
171                 'magnetic field': BEGIN
172                     msg = 'iii : valid long_name parameter = ' + long_name
173                     ras = report(msg)
174                 END
175             ELSE      : BEGIN
176                 msg = 'eee : invalid long_name parameter = ' + long_name
177                 ras = report(msg)
178                 msg = 'eee : long_name must be magnetic field'
179                 ras = report(msg)
180                 RETURN
181             END
182         ENDCASE
183         CASE units OF
184             'tesla': BEGIN
185                 msg = 'iii : valid units parameter = ' + units
186                 ras = report(msg)
187             END
188             ELSE      : BEGIN
189                 msg = 'eee : invalid units parameter = ' + units
190                 ras = report(msg)
191                 msg = 'eee : units must be tesla'
192                 ras = report(msg)
193                 RETURN
194             END
195         ENDCASE
196     END
197     ELSE      : BEGIN
198         msg = 'eee : invalid variable.NAME parameter = ' + variable.NAME
199         ras = report(msg)
200         msg = 'eee : variable.NAME must be cond_sed or Br'
201         ras = report(msg)
202         RETURN
203     END
204ENDCASE
205    ;
206    ; check jpio
207    IF (jpio LT 1) THEN BEGIN
208       msg = ' eee : invalid jpio parameter = ' + STRING(jpio)
209       ras = report(msg)
210       msg = ' eee : jpio must be greater or equal to 1'
211       ras = report(msg)
212       RETURN
213    ENDIF ELSE BEGIN
214       msg = 'iii : valid jpio parameter = ' + STRING(jpio)
215       ras = report(msg)
216    ENDELSE
217    ;
218    ; check jpjo
219    IF (jpjo LT 1) THEN BEGIN
220       msg = ' eee : invalid jpjo parameter = ' + STRING(jpjo)
221       ras = report(msg)
222       msg = ' eee : jpjo must be greater or equal to 1'
223       ras = report(msg)
224       RETURN
225    ENDIF ELSE BEGIN
226       msg = 'iii : valid jpjo parameter = ' + STRING(jpjo)
227       ras = report(msg)
228    ENDELSE
229    ;
230    ; check olon ++ what to check
231    ; when decided reproduce with olat ++
232    IF (N_ELEMENTS(olon) NE jpio*jpjo) THEN BEGIN
233       msg = ' eee : invalid nb of elements of olon parameter = ' + STRING(N_ELEMENTS(olon))
234       ras = report(msg)
235       msg = ' eee : nb of elements of olon must be equal to jpio*jpjo = ' + STRING(jpio*jpjo)
236       ras = report(msg)
237       RETURN
238    ENDIF ELSE BEGIN
239       msg = 'iii : valid nb of elements olon parameter'
240       ras = report(msg)
241    ENDELSE
242    ;
243    ; check values ++
244    ; test if ${GEOMAG_OD} defined
245    geomag_od_env=GETENV('GEOMAG_OD')
246    CASE geomag_od_env OF
247        '' : BEGIN
248               msg = 'eee : ${GEOMAG_OD} is not defined'
249               ras = report(msg)
250               RETURN
251        END
252        ELSE : BEGIN
253             msg = 'iii : ${GEOMAG_OD} is ' + geomag_od_env
254             ras = report(msg)
255        END
256    ENDCASE
257    ;
258    ; check if output data will be possible
259    iodirout = isadirectory(geomag_od_env)
260    ;
261    ; existence and protection
262    IF (FILE_TEST(iodirout, /DIRECTORY,/WRITE) EQ 0) THEN BEGIN
263       msg = 'eee : the directory' + iodirout  + ' was not found.'
264       ras = report(msg)
265       RETURN
266    ENDIF
267    ;
268    ; build output filenames
269    filename = variable.NAME + '_' + orcares +'.nc'
270    fullfilename = iodirout + filename
271    ;
272    ; in order to avoid unexpected overwritten
273    IF (FILE_TEST(fullfilename) EQ 1) THEN BEGIN
274       msg = 'eee : the file ' + fullfilename  + ' already exists.'
275       ras = report(msg)
276       RETURN
277    ENDIF
278    ;
279    ; d'aprÚs ncdump -h /usr/work/sur/fvi/OPA/geomag/condmag.nc
280    ; ces lignes n'ont rien a faire la ++ ces information devrait etre en parameter
281    condmaglonname = 'lo'
282    condmaglatname = 'la'
283    varname = variable.NAME
284    ;
285    ;---------------------------
286    ; Creation of the NetCdf output file
287    ;---------------------------
288    ;
289    netcdf_id = NCDF_CREATE(fullfilename, /clobber)
290    NCDF_CONTROL, netcdf_id, /NOFILL
291    ;
292    ; dimension
293    dimidx = NCDF_DIMDEF(netcdf_id, 'x' ,  jpio)
294    dimidy = NCDF_DIMDEF(netcdf_id, 'y' ,  jpjo)
295    dimidt = NCDF_DIMDEF(netcdf_id, 'lo', /UNLIMITED)
296    ;
297    ; global attributes
298    NCDF_ATTPUT, netcdf_id, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformite
299    NCDF_ATTPUT, netcdf_id, 'file_name'  , filename, /GLOBAL
300    NCDF_ATTPUT, netcdf_id, 'Title'      , title, /GLOBAL
301    ;
302    ; declaration of variables
303    ; 4 common variables for the two files to produce
304    varid = lonarr(4)
305    ;
306    varid[0] = NCDF_VARDEF(netcdf_id, 'nav_lon'  , [dimidx, dimidy], /FLOAT)
307    NCDF_ATTPUT, netcdf_id, varid[0], 'units'    , 'degrees_east'
308    NCDF_ATTPUT, netcdf_id, varid[0], 'valid_min', min(olon, max = omax), /FLOAT
309    NCDF_ATTPUT, netcdf_id, varid[0], 'valid_max', omax, /FLOAT
310    NCDF_ATTPUT, netcdf_id, varid[0], 'long_name', 'Longitude at t-point'
311    ;
312    varid[1] = NCDF_VARDEF(netcdf_id, 'nav_lat'  , [dimidx, dimidy], /FLOAT)
313    NCDF_ATTPUT, netcdf_id, varid[1], 'units'    , 'degrees_north'
314    NCDF_ATTPUT, netcdf_id, varid[1], 'valid_min', min(olat, max = omax), /FLOAT
315    NCDF_ATTPUT, netcdf_id, varid[1], 'valid_max', omax, /FLOAT
316    NCDF_ATTPUT, netcdf_id, varid[1], 'long_name', 'Latitude at t-point'
317    ;
318    varid[2] = NCDF_VARDEF(netcdf_id, 'time'     , [dimidt], /FLOAT)
319    ;
320    varid[3] =  NCDF_VARDEF(netcdf_id, varname, [dimidx, dimidy, dimidt], /FLOAT)
321    NCDF_ATTPUT, netcdf_id, varid[3], 'long_name', long_name
322    NCDF_ATTPUT, netcdf_id, varid[3], 'units', units
323    ; pour min et max, il faut avoir lu la variable ... cf. plus bas ++
324    ; donc pour l'instant on les met à valeur manquante
325    NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', !VALUES.F_NAN, /FLOAT
326    NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', !VALUES.F_NAN, /FLOAT
327    ;
328    ;---------------------------
329    ; end of header definition, writing of the NetCdf files
330    ;---------------------------
331    ;
332    NCDF_CONTROL, netcdf_id, /ENDEF
333    ;
334    NCDF_VARPUT, netcdf_id, 'nav_lon', olon
335    NCDF_VARPUT, netcdf_id, 'nav_lat', olat
336    NCDF_VARPUT, netcdf_id, varid[2], FLOAT(0.5) ; ++ c'est quoi cette valeur
337    ;
338    ; compute min max
339    minarr = min(values, max = maxarr)
340    ;
341    ; put back the masked value
342    ;++      IF bad[0] NE -1 THEN values[TEMPORARY(bad)] = 32767
343    ;
344    ; write the data
345    NCDF_VARPUT, netcdf_id, varname, values, COUNT = [jpio, jpjo, 1], OFFSET = [0, 0, 0]
346    ;
347    ; update min max attributes
348    NCDF_CONTROL, netcdf_id, /REDEF
349    NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', minarr, /FLOAT
350    NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', maxarr, /FLOAT
351    NCDF_CONTROL, netcdf_id, /ENDEF
352    ;
353    ; close the netcdf files
354    NCDF_CLOSE, netcdf_id
355    ;
356    msg = 'iii : ' + fullfilename + ' created'
357    ras = report(msg)
358END
Note: See TracBrowser for help on using the repository browser.