source: trunk/src/interp_olr_30n30s.pro @ 203

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

fix thanks to coding rules

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