source: trunk/condmag_cond_sed_on_orca.pro @ 5

Last change on this file since 5 was 5, checked in by pinsard, 17 years ago

add svn:keyword property Id and remove svn:executable to condmag_cond_sed_on_orca.pro

  • Property svn:keyword set to Id
File size: 10.8 KB
Line 
1;+
2;
3; @file_comments
4; interpolate condmag.nc file (sediment and magnetic fields) on ORCA grid
5; and produce one file cond_sed_<orcares>.nc
6;
7; @categories
8; interpolation, orca grid
9;
10; @param orcares {in}{required}{type=string}
11; code of ORCA grid to use for output results
12; must be 'ORCA2'
13;
14; @param method {in}{required}{type=string}
15; code for interpolation method
16; must be 'bilinear' or 'imoms3'
17; in fact bilinear is used in this geomag project
18; ++ est-ce que ce sera tjs vrai ?
19;
20; @param gridtype {in}{required}{type=string}
21; to specify on which grid we do the interpolation T, U, V
22; must belong to T,U,V
23;
24; @restrictions
25;  - Requires SAXO tools
26;  - must have condmag.nc in ${GEOMAG_ID}/
27;  - must have meshmask in ${GEOMAG_ID}/
28;  - must not have cond_sed_*.nc in ${GEOMAG_OD}/
29;
30; @todo
31; add ORCA025
32; provide tools to plot output file
33; produce a NetCDF GDT or CF compliant
34;
35; @pre
36; be sure to have datafile condmag.nc in the directory defined in
37; ${GEOMAG_ID}/ see geomag_env.sh
38; be sure to have meshmask of ORCA grid you choos in the directory defined in
39; ${GEOMAG_ID}/
40; for ORCA2 filename is meshmask_bab.nc
41;
42; @post
43; cond_sed_<I>orcasres</I>.nc is now present in ${GEOMAG_OD}/
44; see geomag_env.sh
45;
46; @examples
47; IDL> .run condmag_cond_sed_on_orca
48; IDL> condmag_cond_sed_on_orca, 'ORCA2', 'bilinear','T'
49;
50; @history
51; fplod 2006-11-20T10:32:02Z aedon.locean-ipsl.upmc.fr (Darwin)
52; cleaning before introduction into svn repository
53; fplod 2006-03-23T13:05:39Z aedon.lodyc.jussieu.fr (Darwin)
54; cond_sed_ORCA2 presque ok manque attributes min/max de cond_sed
55; fplod 2006-03-22T09:35:42Z aedon.lodyc.jussieu.fr (Darwin)
56; created from
57; /Users/fplod/incas/seb/DORAEMON/wind/idl/quikscat_to_orca_scalar.pro written
58; by Sebastien Masson
59; to reproduce  /usr/work/sur/fvi/OPA/geomag/cond_sed_ORCA2.nc
60; main differences : no yyyy parameter, no time loop , no mask and no missing
61; values (++ to be checked ) in data input (condmag.nc), no scale factor,
62; no OFFSET, no save of weight and addresses
63;
64; @version
65; $Id$
66;
67;-
68PRO condmag_cond_sed_on_orca, orcares, method, gridtype
69;
70  compile_opt idl2, strictarrsubs
71;
72;----
73; check input parameters
74;----
75;
76; check orcares definition
77;
78  CASE orcares OF
79     'ORCA2': BEGIN
80                 filename_oce = 'meshmask_bab.nc'
81                 PRINT, 'valid orcares parameter'
82              END
83      ELSE  : BEGIN
84                 msg = 'orcares must be ORCA2'
85                 PRINT, msg
86                 RETURN
87              END
88  ENDCASE
89;
90; check method definition
91  CASE method OF
92     'bilinear': BEGIN
93                    PRINT, 'valid method parameter'
94                 END
95     'imoms3'  : BEGIN
96                    PRINT, 'valid method parameter'
97                 END
98     ELSE      : BEGIN
99                    msg = 'method must be bilinear or imoms3'
100                    PRINT, msg
101                    RETURN
102                 END
103  ENDCASE
104;
105; check gridtype definition
106  gridtype = strupcase(gridtype)
107  CASE gridtype OF
108     'T' : BEGIN
109              PRINT, 'valid gridtype parameter'
110           END
111     'U' : BEGIN
112              PRINT, 'valid gridtype parameter'
113           END
114     'V' : BEGIN
115              PRINT, 'valid gridtype parameter'
116           END
117     ELSE: BEGIN
118              msg = 'gridtype must be T, U or V'
119              PRINT, msg
120              RETURN
121           END
122  ENDCASE
123;
124; check for input files
125;
126; test if ${GEOMAG_ID} defined
127  geomag_id_env=GETENV('GEOMAG_ID')
128  CASE geomag_id_env OF
129     ''  :  BEGIN
130              msg = '${GEOMAG_ID} is not defined'
131              PRINT, msg
132              RETURN
133            END
134     ELSE: BEGIN
135             msg = '${GEOMAG_ID} is ' + geomag_id_env
136             PRINT, msg
137           END
138  ENDCASE
139;
140  iodirin = isadirectory(geomag_id_env)
141;
142; existence and protection of ${GEOMAG_ID}
143  IF (FILE_TEST(iodirin, /DIRECTORY,/EXECUTABLE , /READ) EQ 0) THEN BEGIN
144     msg = 'the directory' + iodirin  + ' is not accessible.'
145     PRINT, msg
146     RETURN
147  ENDIF
148;
149; conductivity and magnetic field
150  filename_condmag = 'condmag.nc'
151;
152; check if this file exists
153  fullfilename_condmag = isafile(iodirin + filename_condmag)
154  IF fullfilename_condmag[0] EQ '' THEN BEGIN
155     msg = 'the file ' + fullfilename_condmag + ' was not found.'
156     PRINT, msg
157     RETURN
158  ENDIF
159;
160; protection
161  IF (FILE_TEST(fullfilename_condmag[0], /READ) EQ 0) THEN BEGIN
162     msg = 'the file ' + fullfilename_condmag[0] + ' is not readable.'
163     PRINT, msg
164     RETURN
165  ENDIF
166;
167; mesh mask
168; check if this file exists
169  fullfilename_oce = isafile(iodirin + filename_oce)
170  IF fullfilename_oce[0] EQ '' THEN BEGIN
171     msg = 'the file ' + fullfilename_oce + ' was not found.'
172     PRINT, msg
173     RETURN
174  ENDIF
175;
176; protection
177  IF (FILE_TEST(fullfilename_oce[0], /READ) EQ 0) THEN BEGIN
178     msg = 'the file ' + fullfileoce_condmag[0] + ' is not readable.'
179     PRINT, msg
180     RETURN
181  ENDIF
182;
183; test if ${GEOMAG_OD} defined
184  geomag_od_env=GETENV('GEOMAG_OD')
185  CASE geomag_od_env OF
186     '' : BEGIN
187             msg = '${GEOMAG_OD} is not defined'
188             PRINT, msg
189             RETURN
190          END
191     ELSE: BEGIN
192             msg = '${GEOMAG_OD} is ' + geomag_od_env
193             PRINT, msg
194           END
195  ENDCASE
196;
197; check if output data will be possible
198  iodirout = isadirectory(geomag_od_env)
199;
200; existence and protection
201  IF (FILE_TEST(iodirout, /DIRECTORY,/WRITE) EQ 0) THEN BEGIN
202     msg = 'the directory' + iodirout  + ' was not found.'
203     PRINT, msg
204     RETURN
205  ENDIF
206;
207; build output filename
208  filename_cond_sed = 'cond_sed' + '_' + orcares +'.nc'
209  fullfilename_cond_sed = iodirout + filename_cond_sed
210;
211; in order to avoid unexpected overwritten
212  IF (FILE_TEST(fullfilename_cond_sed) EQ 1) THEN BEGIN
213     msg = 'the file ' + fullfilename_cond_sed  + ' already exists.'
214     PRINT, msg
215     RETURN
216  ENDIF
217;
218; d'après ncdump -h /usr/work/sur/fvi/OPA/geomag/condmag.nc
219  condmaglonname = 'lo'
220  condmaglatname = 'la'
221  varname_cond_sed = 'cond_sed'
222;
223;----
224; conductivity and magnetic field grid parameters
225;----
226;
227  get_gridparams, fullfilename_condmag[0], $
228     condmaglonname, condmaglatname, $
229     condmaglon, condmaglat, jpia, jpja, 1,/DOUBLE
230;
231;----
232; Oceanic grid parameters
233;----
234;
235  olonname = 'glam' + STRLOWCASE(gridtype)
236  olatname = 'gphi' + STRLOWCASE(gridtype)
237  get_gridparams, fullfilename_oce[0], $
238     olonname, olatname, $
239     olon, olat, jpio, jpjo, 2,/DOUBLE
240;
241;---------------
242; Compute weight and address
243;---------------
244;
245  CASE method OF
246     'bilinear': compute_fromreg_bilinear_weigaddr, $
247                    condmaglon, condmaglat, olon, olat, weig, addr
248     'imoms3'  : compute_fromreg_imoms3_weigaddr, $
249                    condmaglon, condmaglat, olon, olat, weig, addr
250  ENDCASE
251;
252; reading condmag file
253  netcdf_id_condmag = NCDF_OPEN(fullfilename_condmag[0])
254  varinq_cond_sed = NCDF_VARINQ(netcdf_id_condmag, varname_cond_sed)
255;
256;---------------------------
257; Creation of the NetCdf file for cond_sed
258;---------------------------
259;
260  netcdf_id_cond_sed = NCDF_CREATE(fullfilename_cond_sed, /clobber)
261  NCDF_CONTROL, netcdf_id_cond_sed, /NOFILL
262; dimension
263  dimidx = NCDF_DIMDEF(netcdf_id_cond_sed, 'x' ,  jpio)
264  dimidy = NCDF_DIMDEF(netcdf_id_cond_sed, 'y' ,  jpjo)
265  dimidt = NCDF_DIMDEF(netcdf_id_cond_sed, 'lo', /UNLIMITED)
266;
267; global attributes
268  NCDF_ATTPUT, netcdf_id_cond_sed, 'Conventions', 'GDT 1.2', /GLOBAL
269  NCDF_ATTPUT, netcdf_id_cond_sed, 'file_name'  , filename_cond_sed, /GLOBAL
270  NCDF_ATTPUT, netcdf_id_cond_sed, 'Title'      , 'Monthly Levitus Sea Salinity corrected', /GLOBAL
271;
272; declaration of variables
273; 4 common variables for the two files to produce
274  varid = lonarr(3)
275;
276  varid[0] = NCDF_VARDEF(netcdf_id_cond_sed, 'nav_lon'  , [dimidx, dimidy], /FLOAT)
277  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'units'    , 'degrees_east'
278  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'valid_min', min(olon, max = omax),/FLOAT
279  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'valid_max', omax,/FLOAT
280  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'long_name', 'Longitude at t-point'
281;
282  varid[1] = NCDF_VARDEF(netcdf_id_cond_sed, 'nav_lat'  , [dimidx, dimidy], /FLOAT)
283  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'units'    , 'degrees_north'
284  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'valid_min', min(olat, max = omax),/FLOAT
285  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'valid_max', omax,/FLOAT
286  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'long_name', 'Latitude at t-point'
287;
288  varid[2] = NCDF_VARDEF(netcdf_id_cond_sed, 'time'     , [dimidt], /FLOAT)
289;
290; each of the the two files to produce contains a specific variable
291  varid_cond_sed = lonarr(1)
292  varid_cond_sed[0] = NCDF_VARDEF(netcdf_id_cond_sed, varname_cond_sed, [dimidx, dimidy, dimidt], /FLOAT)
293;
294; variable 3
295  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'long_name', 'Salinity' ; ++ faux et non cf
296  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'units', 'siemens'
297; pour min  et max, il faut avoir lu la variable ... cf. plus bas ++
298; donc pour l'instant on les met à valeur manquante
299  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_min', !VALUES.F_NAN ,/FLOAT
300  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_max', !VALUES.F_NAN ,/FLOAT
301;---------------------------
302; end of header definition, writing of the NetCdf file
303;---------------------------
304  NCDF_CONTROL, netcdf_id_cond_sed, /ENDEF
305  NCDF_CLOSE, netcdf_id_condmag ; ++ si le close n'est pa ici ça merde mais je ne sais pas pourquoi
306; grid
307;---------------------------
308  NCDF_VARPUT, netcdf_id_cond_sed, 'nav_lon', TEMPORARY(olon)
309  NCDF_VARPUT, netcdf_id_cond_sed, 'nav_lat', TEMPORARY(olat)
310  NCDF_VARPUT, netcdf_id_cond_sed, varid[2], FLOAT(0.5) ; ++ c'est quoi cette valeur
311;---------------------------
312; data
313;---------------------------
314; réouverture du fichier ... mais pourquoi on le relit !!++
315      netcdf_id_condmag = NCDF_OPEN(fullfilename_condmag[0])
316;
317      NCDF_VARGET, netcdf_id_condmag, varname_cond_sed, varin_cond_sed ; , COUNT = [jpia, jpja, 1], OFFSET = [0, 0, 0]
318;
319; do the interpolation
320      varin_cond_sed = TOTAL(weig*varin_cond_sed[addr], 1)
321      varin_cond_sed = REFORM(varin_cond_sed, jpio, jpjo, /OVER)
322;
323      NCDF_CLOSE, netcdf_id_condmag
324      varout_cond_sed = TEMPORARY(varin_cond_sed)
325; compute min max
326      minarr = min(varout_cond_sed, max = maxarr)
327;
328; put back the masked value
329;++      IF bad[0] NE -1 THEN varout_cond_sed[TEMPORARY(bad)] = 32767
330;
331; write the data
332      NCDF_VARPUT, netcdf_id_cond_sed, varname_cond_sed, varout_cond_sed, COUNT = [jpio, jpjo, 1], OFFSET = [0, 0, 0]
333;
334; update min max attributes
335  NCDF_CONTROL, netcdf_id_cond_sed, /REDEF
336  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_min', minarr,/FLOAT
337  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_max', maxarr,/FLOAT
338  NCDF_CONTROL, netcdf_id_cond_sed, /ENDEF
339;
340;---------------------------
341; close the netcdf file
342  NCDF_CLOSE, netcdf_id_cond_sed
343  msg =' done'
344  PRINT, msg
345;
346END
Note: See TracBrowser for help on using the repository browser.