source: trunk/src/interp_erai_lwr_1989_2009.pro @ 153

Last change on this file since 153 was 153, checked in by pinsard, 12 years ago

pro oaflux_mask_30n30s is now a function

  • Property svn:keywords set to Id
File size: 8.7 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`
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; :func:`oaflux_mask_30n30s`.
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;        IDL do not warn when asking size of an undefined array::
150;
151;           IDL> must_crash=size(ginette)
152;
153; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
154;
155;   * usage of $PROJECT_ID and $PROJECT_OD
156;
157; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
158;
159;   * remove hard coded directory for mask_oaflux_30N30S.nc
160;
161; - fplod 20101215T094137Z aedon.locean-ipsl.upmc.fr (Darwin)
162;
163;   * add graph in header
164;
165; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
166;
167;   * minimal header
168;
169; - pbk 2008
170;
171;   * creation
172;
173;-
174pro interp_erai_lwr_1989_2009
175;
176@cm_4cal
177@cm_4data
178@cm_4mesh
179@cm_4data
180@cm_project
181;
182; check for input directory
183;
184; test if ${PROJECT_ID} defined
185CASE project_id_env OF
186    ''  :  BEGIN
187     msg = 'eee : ${PROJECT_ID} is not defined'
188     ras = report(msg)
189     STOP
190           END
191 ELSE: BEGIN
192     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
193     ras = report(msg)
194       END
195ENDCASE
196;
197iodirin = isadirectory(project_id_env)
198;
199; existence and protection of ${PROJECT_ID}
200IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
201   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
202   ras = report(msg)
203   STOP
204ENDIF
205;
206; build mask filename
207filename_msk='mask_oaflux_30N30S.nc'
208;
209; check if this file exists
210msg='iii : looking for ' + filename_msk
211ras = report(msg)
212fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
213IF fullfilename_msk[0] EQ '' THEN BEGIN
214   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
215   ras = report(msg)
216   STOP
217ENDIF
218;
219st=19890101
220en=20090801
221;
222; build data filename
223filename='20c3m_erai_str_TROP_1989_2009.nc'
224;
225; check if this file exists
226msg='iii : looking for ' + filename
227ras = report(msg)
228fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
229IF fullfilename[0] EQ '' THEN BEGIN
230   msg = 'eee : the file ' + fullfilename + ' was not found.'
231   ras = report(msg)
232   STOP
233ENDIF
234;
235; test if ${PROJECT_OD} defined
236CASE project_od_env OF
237  '' : BEGIN
238         msg = 'eee : ${PROJECT_OD} is not defined'
239         ras = report(msg)
240       STOP
241       END
242  ELSE: BEGIN
243          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
244          ras = report(msg)
245        END
246 ENDCASE
247;
248; check if output data will be possible
249iodirout = isadirectory(project_od_env)
250;
251; existence and protection
252IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
253    msg = 'eee : the directory' + iodirout  + ' was not found.'
254    ras = report(msg)
255    STOP
256ENDIF
257;
258; build output filename
259filename_out = 'erai_lwr_19890102_20091231_oafluxgrid.nc'
260fullfilename_out = iodirout + filename_out
261; in order to avoid unexpected overwritten
262IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
263   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
264   ras = report(msg)
265   STOP
266ENDIF
267;
268initncdf, fullfilename
269lwrin=read_ncdf("str",0,7668,/timestep,file=fullfilename,/nostr)
270lwrin=-1*lwrin
271;
272initncdf, fullfilename
273domdef
274latin=reform(gphit(0,*))
275lonin=reform(glamt(*,0))
276print, 'lat grid ',min(latin),max(latin),latin(1)-latin(0)
277print, 'lon grid ',min(lonin),max(lonin),lonin(1)-lonin(0)
278;
279jptin=jpt
280tab=lwrin(*,*,0)
281mskin=glamt*0.+1.
282;
283initncdf, fullfilename_msk
284domdef
285latout=reform(gphit(0,*))
286lonout=reform(glamt(*,0))
287print, 'lat grid ',min(latout),max(latout),latout(1)-latout(0)
288print, 'lon grid ',min(lonout),max(lonout),lonout(1)-lonout(0)
289mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
290;
291lwrout=fltarr(jpi,jpj,jptin)
292;
293for jt=0,jptin-1 do begin
294  ; ++print, 'Interpolation jt=',jt,' / ',jptin-1
295;
296  tab=reform(lwrin(*,*,jt))
297  lwrout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin $
298      , lonout,latout,method='bilinear' $
299      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
300  lwrout(*,*,jt)=lwrout(*,*,jt)*mskout+(1.-mskout)*1.e20
301;
302endfor
303;
304time=timegen(7669, start=julday(1,2,1989,0), units='days')
305jpt=n_elements(time)
306cda0=string(jul2date(time(0)),format='(i8.8)')
307cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
308time=time-julday(1,1,1950,00,00,00)
309;
310lat=latout
311lon=lonout
312ncfile='!' + fullfilename_out
313lon_attr={units:'degrees_east',long_name:'Longitude'}
314lat_attr={units:'degrees_north',long_name:'Latitude'}
315time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
316globattr={source:'Tropical ocean fluxes obtained from ERA Interim',timerange:cda0+' - '+cda1}
317lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation ',short_name:'lwr',axis:'TYX'}
318;
319ncfields = 'lwr[longitude,latitude,time]=lwrout:lwr_attr; ' $
320                      + 'longitude[]=lon:lon_attr; ' $
321                      + 'latitude[]=lat:lat_attr; ' $
322                      + 'time[*time]=time:time_attr ' $
323                      + ' @ globattr'
324;
325@ncdf_quickwrite
326;
327end
Note: See TracBrowser for help on using the repository browser.