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 | ;- |
---|
168 | function 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 |
---|
181 | ON_ERROR, 2 |
---|
182 | ; |
---|
183 | result = -1 |
---|
184 | ; |
---|
185 | usage = 'result = interp_olr_30n30s(yyyymmddb, yyyymmdde)' |
---|
186 | nparam = N_PARAMS() |
---|
187 | IF (nparam NE 2) THEN BEGIN |
---|
188 | ras = report(['Incorrect number of arguments.' $ |
---|
189 | + '!C' $ |
---|
190 | + 'Usage : ' + usage]) |
---|
191 | return, result |
---|
192 | ENDIF |
---|
193 | ; |
---|
194 | ; check for input directory |
---|
195 | ; |
---|
196 | ; test if ${PROJECT_ID} defined |
---|
197 | CASE 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 |
---|
207 | ENDCASE |
---|
208 | ; |
---|
209 | iodirin = isadirectory(project_id_env) |
---|
210 | ; |
---|
211 | ; existence and protection of ${PROJECT_ID} |
---|
212 | IF (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 |
---|
216 | ENDIF |
---|
217 | ; |
---|
218 | ; build mask filename |
---|
219 | filename_msk='mask_oaflux_30N30S.nc' |
---|
220 | ; |
---|
221 | ; check if this file exists |
---|
222 | msg='iii : looking for ' + filename_msk |
---|
223 | ras = report(msg) |
---|
224 | fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST) |
---|
225 | IF fullfilename_msk[0] EQ '' THEN BEGIN |
---|
226 | msg = 'eee : the file ' + fullfilename_msk + ' was not found.' |
---|
227 | ras = report(msg) |
---|
228 | return, result |
---|
229 | ENDIF |
---|
230 | ; |
---|
231 | ; build data filename |
---|
232 | filename='olr.day.mean.nc' |
---|
233 | ; |
---|
234 | ; check if this file exists |
---|
235 | msg='iii : looking for ' + filename |
---|
236 | ras = report(msg) |
---|
237 | fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST) |
---|
238 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
239 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
240 | ras = report(msg) |
---|
241 | return, result |
---|
242 | ENDIF |
---|
243 | ; |
---|
244 | ; test if ${PROJECT_OD} defined |
---|
245 | CASE 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 |
---|
255 | ENDCASE |
---|
256 | ; |
---|
257 | ; check if output data will be possible |
---|
258 | iodirout = isadirectory(project_od_env) |
---|
259 | ; |
---|
260 | ; existence and protection |
---|
261 | IF (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 |
---|
265 | ENDIF |
---|
266 | ; |
---|
267 | ; build output filename |
---|
268 | filename_out = 'olr_oafluxgrid_30n30s_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') +'.nc' |
---|
269 | fullfilename_out = iodirout + filename_out |
---|
270 | ; in order to avoid unexpected overwritten |
---|
271 | IF ((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 |
---|
275 | ENDIF |
---|
276 | ; |
---|
277 | initncdf, fullfilename |
---|
278 | domdef |
---|
279 | latin=reform(gphit[0,*]) |
---|
280 | lonin=reform(glamt[*,0]) |
---|
281 | print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0] |
---|
282 | print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0] |
---|
283 | olrin=read_ncdf("olr",yyyymmddb-.5d,yyyymmdde, file=fullfilename,/nostr) |
---|
284 | ; |
---|
285 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
286 | jptin=n_elements(timein) |
---|
287 | da=jul2date(time[0]) |
---|
288 | cda0=string(da,format='(i8.8)') |
---|
289 | da=jul2date(time[jptin-1]) |
---|
290 | cda1=string(da,format='(i8.8)') |
---|
291 | print, 'olr first date ', cda0 |
---|
292 | print, 'olr last date ' , cda1 |
---|
293 | |
---|
294 | mskin=glamt*0.+1. |
---|
295 | ; |
---|
296 | initncdf, fullfilename_msk |
---|
297 | domdef |
---|
298 | latout=reform(gphit[0,*]) |
---|
299 | lonout=reform(glamt[*,0]) |
---|
300 | print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0] |
---|
301 | print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0] |
---|
302 | mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) |
---|
303 | ; |
---|
304 | help, olrin,lonin,latin,mskin,lonout,latout,mskout |
---|
305 | ; |
---|
306 | olrout=fltarr(jpi,jpj,jptin) |
---|
307 | ; |
---|
308 | for 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 | ; |
---|
318 | endfor |
---|
319 | ; |
---|
320 | lat=latout |
---|
321 | lon=lonout |
---|
322 | ncfile='!' + fullfilename_out |
---|
323 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
324 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
325 | time_attr={units:'days since 1957-01-01 00:00:00',long_name:'Time axis',time_origin:'1957-JAN-01 00:00:00'} |
---|
326 | globattr={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} |
---|
327 | olr_attr={units:'w/m^2',missing_value:1e20,long_name:'Outgoing Longwave Radiation',short_name:'olr',axis:'TYX'} |
---|
328 | ; |
---|
329 | ncfields = '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 | ; |
---|
337 | result = 0 |
---|
338 | return, result |
---|
339 | ; |
---|
340 | end |
---|