source: trunk/src/lwr_correction_ncdf.pro @ 85

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

restart consolidation of paper01 software

File size: 6.1 KB
Line 
1;+
2;
3; .. _lwr_correction_ncdf.pro:
4;
5; =======================
6; lwr_correction_ncdf.pro
7; =======================
8;
9; Correction of lwr on OAFLUX grid
10;
11; :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` have been
12; produced by :ref:`interp_erai_lwr_1989_2009.pro`.
13;
14; Corrected lwr on OAFLUX grid is written in
15; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc`
16; if this file not already exists.
17;
18; This file will be used by :ref:`TropFlux_19890101_20091231.pro`.
19;
20;     .. graphviz::
21;
22;        digraph lwr_correction_ncdf {
23;           graph [
24;           rankdir="LR",
25;           ]
26;
27;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc"];
28;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc"];
29;
30;           lwr_correction_ncdf [shape=box,
31;           fontname=Courier,
32;           color=blue,
33;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/lwr_correction_ncdf.pro",
34;           label="${PROJECT}/src/lwr_correction_ncdf.pro"];
35;
36;           {file_in} -> {lwr_correction_ncdf} -> {file_out}
37;
38;        }
39;
40; SEE ALSO
41; ========
42;
43; :ref:`project_profile.sh`
44;
45; :ref:`mooring_corrections`
46;
47; :ref:`interp_erai_lwr_1989_2009.pro`
48;
49; :func:`initncdf <saxo:initncdf>`
50; :func:`read_ncdf <saxo:read_ncdf>`
51; :func:`grossemoyenne <saxo:grossemoyenne>`
52; :func:`julday <saxo:julday>`
53; :func:`caldat <saxo:caldat>`
54; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
55;
56; EXAMPLES
57; ========
58;
59; ::
60;
61;  IDL> lwr_correction_ncdf
62;
63; TODO
64; ====
65;
66; coding rules
67;
68; lwr long name 'Air Temperature at 2m" : ???
69;
70; 19890101 is not provided in ERA-Intermim file str : a possible workaround is
71; to copy 19890102
72; dataset to 19890101 using nco before processing.
73;
74; here is the sequence used by pk wher erai_lwr_19890102_20091231_oafluxgrid.nc is the regridded (interpolated output)
75;
76;   $ ncks -d time,0,0 erai_lwr_19890102_20091231_oafluxgrid.nc erai_lwr_step0.nc
77;
78; This will combine the two files ::
79;
80;   $ ncrcat erai_lwr_step0.nc erai_lwr_19890102_20091231_oafluxgrid.nc erai_lwr_19890101_20091231_oafluxgrid.nc.
81;
82; must be put in a shell script or find IDL equivalent
83;
84; here I (fp) replace hard coded date 19890102 by 19890101. must check
85; consistency with this module and interp_erai_lwr_1989_2009.pro.
86;
87; KNOWN ISSUES
88; ============
89;
90; test of existence of fullfilename_in not very efficient because
91; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
92;
93; EVOLUTIONS
94; ==========
95;
96; $Id$
97;
98; $URL$
99;
100; - fplod 20110808T120234Z cratos (Linux)
101;
102;   * usage of ${PROJECT_OD}
103;   * complete description
104;   * replace erai_lwr_19890102_20091231_oafluxgrid.nc by erai_lwr_19890101_20091231
105;   * remove v1 in output filename
106;
107; - fplod 20101215T113707Z aedon.locean-ipsl.upmc.fr (Darwin)
108;
109;   * add graph in header
110;
111; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
112;
113;   * minimal header
114;
115; - pbk 2008
116;
117;   * creation
118;
119;-
120pro lwr_correction_ncdf
121;
122@cm_4cal
123@cm_4data
124@cm_4mesh
125@cm_4data
126@cm_project
127;
128; test if ${PROJECT_OD} defined
129CASE project_od_env OF
130  '' : BEGIN
131         msg = 'eee : ${PROJECT_OD} is not defined'
132         ras = report(msg)
133       STOP
134       END
135  ELSE: BEGIN
136          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
137          ras = report(msg)
138        END
139 ENDCASE
140;
141; check if output data will be possible
142iodirout = isadirectory(project_od_env)
143;
144; existence and protection for reading
145IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
146   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
147   ras = report(msg)
148   STOP
149ENDIF
150;
151; existence and protection for writing
152IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
153    msg = 'eee : the directory' + iodirout  + ' was not found.'
154    ras = report(msg)
155    STOP
156ENDIF
157;
158da1=19880101 & da2=20091231
159;
160; build data filename
161filename='erai_lwr_19890101_20091231_oafluxgrid.nc'
162;
163; check if this file exists
164fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
165IF fullfilename[0] EQ '' THEN BEGIN
166   msg = 'eee : the file ' + fullfilename + ' was not found.'
167   ras = report(msg)
168   STOP
169ENDIF
170;
171; build output filename
172filename_out = 'TropFlux_lwr_19890101_20091231.nc'
173fullfilename_out = iodirout + filename_out
174; in order to avoid unexpected overwritten
175IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
176   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
177   ras = report(msg)
178   STOP
179ENDIF
180;
181initncdf, fullfilename
182lwr=read_ncdf('lwr',da1,da2,file=fullfilename,/nostr)
183help, lwr
184;
185lwr_mean=grossemoyenne(lwr,'t',/nan)
186help,lwr_mean
187
188tt=time & jpt=n_elements(time)
189caldat, time,mon,day,yea
190lwr_m=lwr*0.
191
192for jt=0,jpt-1 do begin
193  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
194  t=reform(lwr_mean(*,*))
195  lwr_m(*,*,jt)=t
196endfor
197help, lwr_m
198
199lwr_ano=lwr-lwr_m
200
201;; correction for mean based on scatter
202lwr_m=lwr_m+4.61667
203
204help, lwr_ano
205
206;; applying the correction for varyability based on the scatter
207lwr_ano=lwr_ano*(1/0.760667)
208
209;; applying the correction for varyability based on the scatter
210
211lwr_new=lwr_m+lwr_ano
212help, lwr_new
213
214;writing field
215lat=reform(gphit(0,0:jpj-1))
216lon=reform(glamt(0:jpi-1,0))
217time=timegen(7669, units='days', start=julday(1,2,1989)) & jpt=n_elements(time)
218
219cda0=string(jul2date(time(0)),format='(i8.8)')
220cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
221
222time=time-julday(1,1,1950) & jpt=n_elements(time)
223
224ncfile='!' + fullfilename_out
225lon_attr={units:'degrees_east',long_name:'Longitude'}
226lat_attr={units:'degrees_north',long_name:'Latitude'}
227time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
228lwr_attr={units:'degK',missing_value:1.e20,long_name:'Air Temperature at 2m',short_name:'lwr',axis:'TYX'}
229globattr={source:'Basic data obtained from ERAI.  Mean correction for  bias and correction for variability are applied',timerange:cda0+' - '+cda1}
230
231ncfields = 'lwr[longitude,latitude,time]=lwr_new:lwr_attr; ' $
232                      + 'longitude[]=lon:lon_attr; ' $
233                      + 'latitude[]=lat:lat_attr; ' $
234                      + 'time[*time]=time:time_attr ' $
235                      + ' @ globattr'
236
237@ncdf_quickwrite
238
239end
Note: See TracBrowser for help on using the repository browser.