source: trunk/src/interp_erai_lwr_1989_2009.pro @ 70

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

fix call_interp2d call

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