1 | ;+ |
---|
2 | ; |
---|
3 | ; |
---|
4 | ; =================== |
---|
5 | ; interp_erai_lwr.pro |
---|
6 | ; =================== |
---|
7 | ; |
---|
8 | ; .. function:: interp_erai_lwr(yyyymmddb,yyyymmdde) |
---|
9 | ; |
---|
10 | ; DESCRIPTION |
---|
11 | ; =========== |
---|
12 | ; |
---|
13 | ; Interpolation of str from ERA-I grid to OAFLUX grid |
---|
14 | ; |
---|
15 | ; :file:`${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc` |
---|
16 | ; containing str from ERA-I |
---|
17 | ; has been produced by |
---|
18 | ; :ref:`compute_erai_daily_region_2d.sh`. |
---|
19 | ; |
---|
20 | ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` |
---|
21 | ; containing OAFLUX mask |
---|
22 | ; has been produced by |
---|
23 | ; :func:`oaflux_mask_30n30s`. |
---|
24 | ; |
---|
25 | ; Interpolated str |
---|
26 | ; is written in |
---|
27 | ; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` |
---|
28 | ; if this file not already exists. |
---|
29 | ; |
---|
30 | ; This output file |
---|
31 | ; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` |
---|
32 | ; must be processed after by |
---|
33 | ; :ref:`add_19890101.sh`. |
---|
34 | ; |
---|
35 | ; .. only:: man |
---|
36 | ; |
---|
37 | ; Figure is visible on PDF and HTML documents only. |
---|
38 | ; |
---|
39 | ; .. only:: html or latex |
---|
40 | ; |
---|
41 | ; .. graphviz:: |
---|
42 | ; |
---|
43 | ; digraph interp_erai_lwr { |
---|
44 | ; |
---|
45 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc"]; |
---|
46 | ; mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"]; |
---|
47 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; |
---|
48 | ; |
---|
49 | ; interp_erai_lwr [shape=box, |
---|
50 | ; fontname=Courier, |
---|
51 | ; color=blue, |
---|
52 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_lwr.pro", |
---|
53 | ; label="${PROJECT}/src/interp_erai_lwr.pro"]; |
---|
54 | ; |
---|
55 | ; {file_in mask} -> {interp_erai_lwr} -> {file_out} |
---|
56 | ; |
---|
57 | ; } |
---|
58 | ; |
---|
59 | ; SEE ALSO |
---|
60 | ; ======== |
---|
61 | ; |
---|
62 | ; :ref:`interpolate_data` |
---|
63 | ; |
---|
64 | ; Used by :ref:`tropflux.sh` |
---|
65 | ; |
---|
66 | ; :ref:`project_profile.sh` |
---|
67 | ; |
---|
68 | ; :func:`report <saxo:report>` |
---|
69 | ; :func:`isadirectory <saxo:isadirectory>` |
---|
70 | ; :func:`isafile <saxo:isafile>` |
---|
71 | ; :func:`initncdf <saxo:initncdf>` |
---|
72 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
73 | ; :func:`domdef <saxo:domdef>` |
---|
74 | ; :func:`call_interp2d <saxo:call_interp2d>` |
---|
75 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
76 | ; |
---|
77 | ; :ref:`add_19890101.sh` |
---|
78 | ; |
---|
79 | ; EXAMPLES |
---|
80 | ; ======== |
---|
81 | ; |
---|
82 | ; :: |
---|
83 | ; |
---|
84 | ; .compile file_interp |
---|
85 | ; yyyymmddb = 20000101L |
---|
86 | ; yyyymmdde = 20001231L |
---|
87 | ; result = interp_erai_lwr(yyyymmddb, yyyymmdde) |
---|
88 | ; print, result |
---|
89 | ; |
---|
90 | ; TODO |
---|
91 | ; ==== |
---|
92 | ; |
---|
93 | ; lwr first date 19991231 vs yyyymmddb = 20000101L |
---|
94 | ; |
---|
95 | ; make it work : pb on loholt1 idl8: |
---|
96 | ; |
---|
97 | ; reach end but bad values (all NaN) |
---|
98 | ; |
---|
99 | ; make it work : pb on loholt1 idl6:: |
---|
100 | ; |
---|
101 | ; lwr[longitude,latitude,time]=lwrout:lwr_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr @ globattr |
---|
102 | ; % NCDF_VARPUT: Operation Failed, bad file (4) or variable [0] id ? |
---|
103 | ; (NC_ERROR=-31) |
---|
104 | ; % Stop encountered: INTERP_ERAI_LWR_1989_2009 1 |
---|
105 | ; /home/pinsard/tropflux_ws/src/interp_erai_lwr_1989_2009.pro |
---|
106 | ; |
---|
107 | ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call |
---|
108 | ; |
---|
109 | ; use real output of :ref:`compute_erai_daily_region_2d.sh`. |
---|
110 | ; |
---|
111 | ; remove hard coded time |
---|
112 | ; |
---|
113 | ; 19890101 is not provided in ERA-Intermim file str : a possible workaround is to copy 19890102 |
---|
114 | ; dataset to 19890101 using nco after this processing. see :ref:`compute_erai_daily_region_2d.sh` |
---|
115 | ; |
---|
116 | ; check if there is the same issue with 19790101 vs 19790102. |
---|
117 | ; |
---|
118 | ; coding rules |
---|
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$ |
---|
130 | ; |
---|
131 | ; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_lwr.pro $ |
---|
132 | ; |
---|
133 | ; - fplod 20120320 |
---|
134 | ; |
---|
135 | ; * no more timegen |
---|
136 | ; |
---|
137 | ; - fplod 20120319 |
---|
138 | ; |
---|
139 | ; * taking project_overwite into account |
---|
140 | ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite |
---|
141 | ; * pro -> function |
---|
142 | ; |
---|
143 | ; - fplod 20110830T145010Z cratos (Linux) |
---|
144 | ; |
---|
145 | ; * replace xlon by lon and xlat by lat; suppress extra initcdf call |
---|
146 | ; |
---|
147 | ; - fplod 20110830T135030Z cratos (Linux) |
---|
148 | ; |
---|
149 | ; * replace tt by time |
---|
150 | ; |
---|
151 | ; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
152 | ; |
---|
153 | ; * retry on loholt1 with idl8 and idl6 |
---|
154 | ; |
---|
155 | ; - fplod 20110819T084310Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
156 | ; |
---|
157 | ; * replace next step lwr_correction_ncdf.pro by :ref:`add_19890101.sh` |
---|
158 | ; * fix output file name to erai_lwr_19890102_20091231_oafluxgrid.nc |
---|
159 | ; |
---|
160 | ; - pinsard 2011-08-08T16:03:48Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
161 | ; |
---|
162 | ; * remove return statement |
---|
163 | ; |
---|
164 | ; - fplod 20110808T094156Z cratos (Linux) |
---|
165 | ; |
---|
166 | ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call |
---|
167 | ; * fix typo |
---|
168 | ; .. note:: |
---|
169 | ; |
---|
170 | ; IDL do not warn when asking size of an undefined array:: |
---|
171 | ; |
---|
172 | ; IDL> must_crash=size(ginette) |
---|
173 | ; |
---|
174 | ; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
175 | ; |
---|
176 | ; * usage of $PROJECT_ID and $PROJECT_OD |
---|
177 | ; |
---|
178 | ; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
179 | ; |
---|
180 | ; * remove hard coded directory for mask_oaflux_30N30S.nc |
---|
181 | ; |
---|
182 | ; - fplod 20101215T094137Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
183 | ; |
---|
184 | ; * add graph in header |
---|
185 | ; |
---|
186 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
187 | ; |
---|
188 | ; * minimal header |
---|
189 | ; |
---|
190 | ; - pbk 2008 |
---|
191 | ; |
---|
192 | ; * creation |
---|
193 | ; |
---|
194 | ;- |
---|
195 | function interp_erai_lwr $ |
---|
196 | , yyyymmddb $ |
---|
197 | , yyyymmdde |
---|
198 | ; |
---|
199 | ;++compile_opt idl2, strictarrsubs, logical_predicate |
---|
200 | ; |
---|
201 | @cm_4cal |
---|
202 | @cm_4data |
---|
203 | @cm_4mesh |
---|
204 | @cm_4data |
---|
205 | @cm_project |
---|
206 | ; |
---|
207 | ; Return to caller if errors |
---|
208 | ON_ERROR, 2 |
---|
209 | ; |
---|
210 | result = -1 |
---|
211 | ; |
---|
212 | usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde)' |
---|
213 | nparam = N_PARAMS() |
---|
214 | IF (nparam NE 2) THEN BEGIN |
---|
215 | ras = report(['Incorrect number of arguments.' $ |
---|
216 | + '!C' $ |
---|
217 | + 'Usage : ' + usage]) |
---|
218 | return, result |
---|
219 | ENDIF |
---|
220 | ; |
---|
221 | ; check for input directory |
---|
222 | ; |
---|
223 | ; test if ${PROJECT_ID} defined |
---|
224 | CASE project_id_env OF |
---|
225 | '' : BEGIN |
---|
226 | msg = 'eee : ${PROJECT_ID} is not defined' |
---|
227 | ras = report(msg) |
---|
228 | return, result |
---|
229 | END |
---|
230 | ELSE: BEGIN |
---|
231 | msg = 'iii : ${PROJECT_ID} is ' + project_id_env |
---|
232 | ras = report(msg) |
---|
233 | END |
---|
234 | ENDCASE |
---|
235 | ; |
---|
236 | iodirin = isadirectory(project_id_env) |
---|
237 | ; |
---|
238 | ; existence and protection of ${PROJECT_ID} |
---|
239 | IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
240 | msg = 'eee : the directory' + iodirin + ' is not accessible.' |
---|
241 | ras = report(msg) |
---|
242 | return, result |
---|
243 | ENDIF |
---|
244 | ; |
---|
245 | ; build mask filename |
---|
246 | filename_msk='mask_oaflux_30N30S.nc' |
---|
247 | ; |
---|
248 | ; check if this file exists |
---|
249 | msg='iii : looking for ' + filename_msk |
---|
250 | ras = report(msg) |
---|
251 | fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST) |
---|
252 | IF fullfilename_msk[0] EQ '' THEN BEGIN |
---|
253 | msg = 'eee : the file ' + fullfilename_msk + ' was not found.' |
---|
254 | ras = report(msg) |
---|
255 | return, result |
---|
256 | ENDIF |
---|
257 | ; |
---|
258 | st=19890101 |
---|
259 | en=20090801 |
---|
260 | ; |
---|
261 | ; build data filename |
---|
262 | filename='20c3m_erai_str_TROP_1989_2009.nc' |
---|
263 | ; |
---|
264 | ; check if this file exists |
---|
265 | msg='iii : looking for ' + filename |
---|
266 | ras = report(msg) |
---|
267 | fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST) |
---|
268 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
269 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
270 | ras = report(msg) |
---|
271 | return, result |
---|
272 | ENDIF |
---|
273 | ; |
---|
274 | ; test if ${PROJECT_OD} defined |
---|
275 | CASE project_od_env OF |
---|
276 | '' : BEGIN |
---|
277 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
278 | ras = report(msg) |
---|
279 | return, result |
---|
280 | END |
---|
281 | ELSE: BEGIN |
---|
282 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
283 | ras = report(msg) |
---|
284 | END |
---|
285 | ENDCASE |
---|
286 | ; |
---|
287 | ; check if output data will be possible |
---|
288 | iodirout = isadirectory(project_od_env) |
---|
289 | ; |
---|
290 | ; existence and protection |
---|
291 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
292 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
293 | ras = report(msg) |
---|
294 | return, result |
---|
295 | ENDIF |
---|
296 | ; |
---|
297 | ; build output filename |
---|
298 | filename_out = 'erai_lwr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' |
---|
299 | fullfilename_out = iodirout + filename_out |
---|
300 | ; in order to avoid unexpected overwritten |
---|
301 | IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN |
---|
302 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
303 | ras = report(msg) |
---|
304 | return, result |
---|
305 | ENDIF |
---|
306 | ; |
---|
307 | initncdf, fullfilename |
---|
308 | lwrin=read_ncdf("str",yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) |
---|
309 | lwrin=-1*lwrin |
---|
310 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
311 | jptin=n_elements(timein) |
---|
312 | da=jul2date(time[0]) |
---|
313 | cda0=string(da,format='(i8.8)') |
---|
314 | da=jul2date(time[jpt-1]) |
---|
315 | cda1=string(da,format='(i8.8)') |
---|
316 | print, 'lwr first date ', cda0 |
---|
317 | print, 'lwr last date ' , cda1 |
---|
318 | ; |
---|
319 | initncdf, fullfilename |
---|
320 | domdef |
---|
321 | latin=reform(gphit[0,*]) |
---|
322 | lonin=reform(glamt[*,0]) |
---|
323 | print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0] |
---|
324 | print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0] |
---|
325 | ; |
---|
326 | tab=lwrin[*,*,0] |
---|
327 | mskin=glamt*0.+1. |
---|
328 | ; |
---|
329 | initncdf, fullfilename_msk |
---|
330 | domdef |
---|
331 | latout=reform(gphit[0,*]) |
---|
332 | lonout=reform(glamt[*,0]) |
---|
333 | print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0] |
---|
334 | print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0] |
---|
335 | mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) |
---|
336 | ; |
---|
337 | lwrout=fltarr(jpi,jpj,jptin) |
---|
338 | ; |
---|
339 | for jt=0,jptin-1 do begin |
---|
340 | ; ++print, 'Interpolation jt=',jt,' / ',jptin-1 |
---|
341 | ; |
---|
342 | tab=reform(lwrin[*,*,jt]) |
---|
343 | lwrout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $ |
---|
344 | , lonout,latout,method='bilinear' $ |
---|
345 | , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) |
---|
346 | lwrout[*,*,jt]=lwrout[*,*,jt]*mskout+(1.-mskout)*1.e20 |
---|
347 | ; |
---|
348 | endfor |
---|
349 | ; |
---|
350 | lat=latout |
---|
351 | lon=lonout |
---|
352 | ncfile='!' + fullfilename_out |
---|
353 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
354 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
355 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
356 | globattr={source:'Tropical ocean fluxes obtained from ERA Interim',timerange:cda0+' - '+cda1} |
---|
357 | lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation ',short_name:'lwr',axis:'TYX'} |
---|
358 | ; |
---|
359 | ncfields = 'lwr[longitude,latitude,*time]=lwrout:lwr_attr; ' $ |
---|
360 | + 'longitude[]=lon:lon_attr; ' $ |
---|
361 | + 'latitude[]=lat:lat_attr; ' $ |
---|
362 | + 'time[]=timein:time_attr ' $ |
---|
363 | + ' @ globattr' |
---|
364 | ; |
---|
365 | @ncdf_quickwrite |
---|
366 | ; |
---|
367 | result = 0 |
---|
368 | return, result |
---|
369 | ; |
---|
370 | end |
---|