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