source: trunk/src/interp_olr_30n30s.pro @ 178

Last change on this file since 178 was 174, checked in by pinsard, 12 years ago

bunch of new functions

  • Property svn:keywords set to URL
File size: 8.6 KB
Line 
1;+
2;
3; =====================
4; interp_olr_30n30s.pro
5; =====================
6;
7; .. function:: interp_olr_30n30s(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Interpolation of OLR to OAFLUX grid
13;
14; :file:`${PROJECT_ID}/olr.day.mean.nc`
15; have been produced by
16; :ref:`get_olr.sh`
17;
18; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` containing OAFLUX grid
19; have been produced by
20; :func:`oaflux_mask_30n30s`.
21;
22; Interpolated OLR is written in
23; :file:`${PROJECT_OD}/${PROJECT_OD}/olr_oafluxgrid_30n30s_{yyyymmdd}_{yyyymmdd}.nc`
24; if this file not already exists.
25;
26; This output file will be used by
27; :func:`tropflux_swr_nrt`.
28;
29;     .. graphviz::
30;
31;        digraph interp_olr_30n30s{
32;
33;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/olr.day.mean_new.nc"];
34;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
35;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/olr_oafluxgrid_30n30s_{yyyymmdd}_{yyyymmdd}.nc"];
36;
37;           interp_olr_30n30s [shape=box,
38;           fontname=Courier,
39;           color=blue,
40;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_olr_30n30s.pro",
41;           label="${PROJECT}/src/interp_olr_30n30s.pro"];
42;
43;           {file_in mask} -> {interp_olr_30n30s} -> {file_out}
44;
45;        }
46;
47; SEE ALSO
48; ========
49;
50; :ref:`interpolate_data`
51;
52; Used by :ref:`tropflux.sh`
53;
54; :ref:`project_profile.sh`
55;
56; :ref:`data_in_olr`, :ref:`get_olr.sh`
57;
58; :func:`report <saxo:report>`
59; :func:`isadirectory <saxo:isadirectory>`
60; :func:`isafile <saxo:isafile>`
61; :func:`initncdf <saxo:initncdf>`
62; :func:`read_ncdf <saxo:read_ncdf>`
63; :func:`domdef <saxo:domdef>`
64; :func:`call_interp2d <saxo:call_interp2d>`
65; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
66;
67; EXAMPLES
68; ========
69;
70; ::
71;
72;  IDL> .compile file_interp
73;  IDL> yyyymmddb = 20000101L
74;  IDL> yyyymmdde = 20001231L
75;  IDL> result = interp_olr_30n30s(yyyymmddb, yyyymmdde)
76;  IDL> print, result
77;
78; TODO
79; ====
80;
81; hard coded attributes for time origine
82;
83; how can we avoid this message ::
84;
85;   % initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you want to find one...
86;
87; I think we do not need any zaxis
88;
89; strange second value [1] in the file produced on cratos idl 7 20110812::
90;
91;   $ ncdump $PROJECT_OD/olr_oafluxgrid_30n30s_19890101_20091231.nc
92;     olr =
93;     1e+20, 1, 258.15, 264.882, 271.614, 273.8116, 271.4748, 269.138, 266.6868,
94;
95; coding rules
96;
97; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
98;
99; pb with mixing interpolated and uninterpolated OLR data
100; check if the input file is the right one (interpolated with get_olr.sh vs non interpolated with get_olr_int.sh)
101;
102; uninterpolated OLR is more timely
103;
104; cf. pk and jv to solve this issue
105;
106; KNOWN ISSUES
107; ============
108;
109; test of existence of fullfilename_msk not very efficient because
110; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
111;
112; EVOLUTIONS
113; ==========
114;
115; $Id: interp_olr_30n30s.pro 88 2011-08-19 15:40:14Z pinsard $
116;
117; $URL$
118;
119; - fplod 20120321
120;
121;   * add timerange in global attributes
122;   * change time origne 1950 -> 1957 to homogenize wih others fields
123;
124; - fplod 20120320
125;
126;   * taking project_overwite into account
127;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
128;   * pro -> function
129;
130; - fplod 20110812T084449Z aedon.locean-ipsl.upmc.fr (Darwin)
131;
132;   * remove new from filename
133;   * usage of $PROJECT_ID and $PROJECT_OD
134;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
135;   * complete description
136;
137; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
138;
139;   * remove hard coded directory for mask_oaflux_30N30S.nc
140;
141; - fplod 20101215T113118Z aedon.locean-ipsl.upmc.fr (Darwin)
142;
143;   * add graph in header
144;
145; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
146;
147;   * minimal header
148;
149; - pbk 2008
150;
151;   * creation
152;
153;-
154function interp_olr_30n30s $
155         , yyyymmddb $
156         , yyyymmdde
157;
158;++compile_opt idl2, strictarrsubs, logical_predicate
159;
160@cm_4cal
161@cm_4data
162@cm_4mesh
163@cm_4data
164@cm_project
165;
166; Return to caller if errors
167ON_ERROR, 2
168;
169result = -1
170;
171usage = 'result = interp_olr_30n30s(yyyymmddb, yyyymmdde)'
172nparam = N_PARAMS()
173IF (nparam NE 2) THEN BEGIN
174   ras = report(['Incorrect number of arguments.' $
175         + '!C' $
176         + 'Usage : ' + usage])
177   return, result
178ENDIF
179;
180; check for input directory
181;
182; test if ${PROJECT_ID} defined
183CASE project_id_env OF
184    ''  :  BEGIN
185     msg = 'eee : ${PROJECT_ID} is not defined'
186     ras = report(msg)
187     return, result
188           END
189 ELSE: BEGIN
190     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
191     ras = report(msg)
192       END
193ENDCASE
194;
195iodirin = isadirectory(project_id_env)
196;
197; existence and protection of ${PROJECT_ID}
198IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
199   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
200   ras = report(msg)
201   return, result
202ENDIF
203;
204; build mask filename
205filename_msk='mask_oaflux_30N30S.nc'
206;
207; check if this file exists
208msg='iii : looking for ' + filename_msk
209ras = report(msg)
210fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
211IF fullfilename_msk[0] EQ '' THEN BEGIN
212   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
213   ras = report(msg)
214   return, result
215ENDIF
216;
217; build data filename
218filename='olr.day.mean.nc'
219;
220; check if this file exists
221msg='iii : looking for ' + filename
222ras = report(msg)
223fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
224IF fullfilename[0] EQ '' THEN BEGIN
225   msg = 'eee : the file ' + fullfilename + ' was not found.'
226   ras = report(msg)
227   return, result
228ENDIF
229;
230; test if ${PROJECT_OD} defined
231CASE project_od_env OF
232  '' : BEGIN
233         msg = 'eee : ${PROJECT_OD} is not defined'
234         ras = report(msg)
235       return, result
236       END
237  ELSE: BEGIN
238          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
239          ras = report(msg)
240        END
241 ENDCASE
242;
243; check if output data will be possible
244iodirout = isadirectory(project_od_env)
245;
246; existence and protection
247IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
248    msg = 'eee : the directory' + iodirout  + ' was not found.'
249    ras = report(msg)
250    return, result
251ENDIF
252;
253; build output filename
254filename_out = 'olr_oafluxgrid_30n30s_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') +'.nc'
255fullfilename_out = iodirout + filename_out
256; in order to avoid unexpected overwritten
257IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
258   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
259   ras = report(msg)
260   return, result
261ENDIF
262;
263initncdf, fullfilename
264domdef
265latin=reform(gphit[0,*])
266lonin=reform(glamt[*,0])
267print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
268print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
269olrin=read_ncdf("olr",yyyymmddb-.5d,yyyymmdde, file=fullfilename,/nostr)
270;
271timein=24.d*(time-julday(1,1,1957,0,0,0))
272jptin=n_elements(timein)
273da=jul2date(time[0])
274cda0=string(da,format='(i8.8)')
275da=jul2date(time[jptin-1])
276cda1=string(da,format='(i8.8)')
277print, 'olr first date ', cda0
278print, 'olr last date ' , cda1
279
280mskin=glamt*0.+1.
281;
282initncdf, fullfilename_msk
283domdef
284latout=reform(gphit[0,*])
285lonout=reform(glamt[*,0])
286print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
287print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
288mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
289;
290help, olrin,lonin,latin,mskin,lonout,latout,mskout
291;
292olrout=fltarr(jpi,jpj,jptin)
293;
294for jt=0,jptin-1 do begin
295;
296  print, 'Interpolation jt=',jt,' / ',jptin-1
297  tab_olr=reform(olrin[*,*,jt])
298;
299  olrout[*,*,jt]=call_interp2d(tab_olr,lonin,latin,mskin $
300      , lonout,latout,method='bilinear'  $
301      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
302  olrout[*,*,jt]=olrout[*,*,jt]*mskout+(1.-mskout)*1.e20
303;
304endfor
305;
306lat=latout
307lon=lonout
308ncfile='!' + fullfilename_out
309lon_attr={units:'degrees_east',long_name:'Longitude'}
310lat_attr={units:'degrees_north',long_name:'Latitude'}
311time_attr={units:'days since 1957-01-01 00:00:00',long_name:'Time axis',time_origin:'1957-JAN-01 00:00:00'}
312globattr={source:'NOAA OLR, cf http://www.cdc.noaa.gov/cdc/data.interp_OLR.html, interpolated to 1x1 degree grid and with oaflux mask', timerange:cda0+' - '+cda1}
313olr_attr={units:'w/m^2',missing_value:1e20,long_name:'Outgoing Longwave Radiation',short_name:'olr',axis:'TYX'}
314;
315ncfields = 'olr[longitude,latitude,time]=olrout:olr_attr; ' $
316                      + 'longitude[]=lon:lon_attr; ' $
317                      + 'latitude[]=lat:lat_attr; ' $
318                      + 'time[*time]=timein:time_attr ' $
319                      + ' @ globattr'
320;
321@ncdf_quickwrite
322;
323result = 0
324return, result
325;
326end
Note: See TracBrowser for help on using the repository browser.