source: trunk/src/interp_olr_30n30s.pro

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

fix thanks to coding rules; typo

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