source: trunk/src/interp_erai_sst_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.2 KB
Line 
1;+
2;
3; .. _interp_erai_sst_1989_2009.pro:
4;
5; =============================
6; interp_erai_sst_1989_2009.pro
7; =============================
8;
9; DESCRIPTION
10; ===========
11;
12; Interpolation of sst from ERA-I grid to OAFLUX grid
13;
14; :file:`${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc` containing sst 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 p roduced by :ref:`oaflux_mask_30N30S.pro`.
18;
19; Interpolated sst is written in
20; :file:`${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc` if this file not already exists.
21;
22; This output file :file:`${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc` must be processed after by :ref:`sst_correction_ncdf.pro`.
23;
24;
25;     .. graphviz::
26;
27;        digraph interp_erai_sst_1989_2009 {
28;           graph [
29;           rankdir="LR",
30;           ]
31;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc"];
32;
33;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
34;
35;           ncfile [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc"];
36;
37;           interp_erai_sst_1989_2009 [shape=box,
38;           fontname=Courier,
39;           color=blue,
40;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_sst_1989_2009.pro",
41;           label="${PROJECT}/src/interp_erai_sst_1989_2009.pro"];
42;
43;           {file_in mask} -> {interp_erai_sst_1989_2009} -> {ncfile}
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:`sst_correction_ncdf.pro`
61;
62; EXAMPLES
63; ========
64;
65; ::
66;
67;  IDL> .compile file_interp
68;  IDL> interp_erai_sst_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; coding rules
80;
81; use real output of :ref:`compute_erai_daily_region_2d.sh`.
82;
83; KNOWN ISSUES
84; ============
85;
86; test of existence of fullfilename_msk not very efficient because
87; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
88;
89; EVOLUTIONS
90; ==========
91;
92; $Id$
93;
94; $URL$
95;
96; - fplod 20110808T094156Z cratos (Linux)
97;
98;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
99;
100; - pinsard 2011-07-04T15:45:35Z loholt1.ipsl.polytechnique.fr (Linux)
101;
102;   * usage of ${PROJECT_ID} and $PROJECT_OD
103;
104; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
105;
106;   * remove hard coded directory for mask_oaflux_30N30S.nc
107;
108; - fplod 20101215T100932Z aedon.locean-ipsl.upmc.fr (Darwin)
109;
110;   * add graph in header
111;
112; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
113;
114;   * minimal header
115;
116; - pbk 2008
117;
118;   * creation
119;
120;-
121pro interp_erai_sst_1989_2009
122;
123@cm_4cal
124@cm_4data
125@cm_4mesh
126@cm_4data
127@cm_project
128;
129; check for input directory
130;
131; test if ${PROJECT_ID} defined
132CASE project_id_env OF
133    ''  :  BEGIN
134     msg = 'eee : ${PROJECT_ID} is not defined'
135     ras = report(msg)
136     STOP
137           END
138 ELSE: BEGIN
139     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
140     ras = report(msg)
141       END
142ENDCASE
143;
144iodirin = isadirectory(project_id_env)
145;
146; existence and protection of ${PROJECT_ID}
147IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
148   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
149   ras = report(msg)
150   STOP
151ENDIF
152;
153; build mask filename
154filename_msk='mask_oaflux_30N30S.nc'
155;
156; check if this file exists
157fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
158IF fullfilename_msk[0] EQ '' THEN BEGIN
159   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
160   ras = report(msg)
161   STOP
162ENDIF
163;
164; build data filename
165filename='20c3m_erai_sstk_TROP_1989_2009.nc'
166;
167; check if this file exists
168fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
169IF fullfilename_msk[0] EQ '' THEN BEGIN
170   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
171   ras = report(msg)
172   STOP
173ENDIF
174;
175; test if ${PROJECT_OD} defined
176CASE project_od_env OF
177  '' : BEGIN
178         msg = 'eee : ${PROJECT_OD} is not defined'
179         ras = report(msg)
180       STOP
181       END
182  ELSE: BEGIN
183          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
184          ras = report(msg)
185        END
186 ENDCASE
187;
188; check if output data will be possible
189iodirout = isadirectory(project_od_env)
190;
191; existence and protection
192IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
193    msg = 'eee : the directory' + iodirout  + ' was not found.'
194    ras = report(msg)
195    STOP
196ENDIF
197;
198; build output filename
199filename_out = 'erai_sst_19890101_20091231_oafluxgrid.nc'
200fullfilename_out = iodirout + filename_out
201; in order to avoid unexpected overwritten
202IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
203   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
204   ras = report(msg)
205   STOP
206ENDIF
207;
208initncdf, fullfilename
209domdef
210latin=reform(gphit(0,*)) & lonin=reform(glamt(*,0))
211print, 'lat grid ',min(latin),max(latin),latin(1)-latin(0)
212print, 'lon grid ',min(lonin),max(lonin),lonin(1)-lonin(0)
213sstkin=read_ncdf("sstk",19871201,20100930,file=fullfilename,/nostr)
214
215timein=time & jptin=jpt
216tab=sstkin(*,*,0)
217mskin=glamt*0.+1. & ind=where((tab eq 1.e9) or finite(tab,/nan)) & mskin(ind)=0.
218;mskin=glamt*0.+1.
219
220initncdf, fullfilename_msk
221domdef
222latout=reform(gphit(0,*)) & lonout=reform(glamt(*,0))
223print, 'lat grid ',min(latout),max(latout),latout(1)-latout(0)
224print, 'lon grid ',min(lonout),max(lonout),lonout(1)-lonout(0)
225mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
226;stop
227help, sstkin,lonin,latin,mskin,lonout,latout,mskout
228
229si=size(sstkin)
230sstkout=fltarr(jpi,jpj,jptin)
231for jt=0,jptin-1 do begin
232  print, 'Interpolation jt=',jt,' / ',jptin-1
233  tab=reform(sstkin(*,*,jt))
234  sstkout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin $
235     , lonout,latout,method='bilinear' $
236     , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
237  sstkout(*,*,jt)=sstkout(*,*,jt)*mskout+(1.-mskout)*1.e20
238endfor
239
240
241timein=timein & jptin=jpt
242
243initncdf, fullfilename_msk
244time=timegen(7670, units='days', start=julday(1,1,1989)) & jpt=n_elements(time)
245tt=time
246cda0=string(jul2date(time(0)),format='(i8.8)')
247cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
248timein=timein-julday(1,1,1950,00,00)
249
250lat=latout
251lon=lonout
252ncfile='!' + fullfilename_out
253lon_attr={units:'degrees_east',long_name:'Longitude'}
254lat_attr={units:'degrees_north',long_name:'Latitude'}
255time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:' 1950-JAN-01 00:00:00'}
256sstk_attr={units:'degK',missing_value:1e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'}
257globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
258
259
260ncfields = 'sst[longitude,latitude,time]=sstkout:sstk_attr; ' $
261                      + 'longitude[]=lon:lon_attr; ' $
262                      + 'latitude[]=lat:lat_attr; ' $
263                      + 'time[*time]=timein:time_attr ' $
264                      + ' @ globattr'
265
266@ncdf_quickwrite
267
268
269end
Note: See TracBrowser for help on using the repository browser.