source: trunk/src/interp_erai_lwr_1989_2009.pro @ 79

Last change on this file since 79 was 78, checked in by pinsard, 13 years ago

precision in procedure (tools and fields)

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