source: trunk/src/lwr_correction_ncdf.pro @ 79

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

start to work on correction tools

File size: 5.8 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. see
73; ref:`compute_erai_daily_region_2d.sh`
74;
75; here I (fp) replace hard coded date 19890102 by 19890101. must check
76; consistency with this module and interp_erai_lwr_1989_2009.pro.
77;
78; KNOWN ISSUES
79; ============
80;
81; test of existence of fullfilename_in not very efficient because
82; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
83;
84; EVOLUTIONS
85; ==========
86;
87; - fplod 20110808T120234Z cratos (Linux)
88;
89;   * usage of ${PROJECT_OD}
90;   * complete description
91;   * replace erai_lwr_19890102_20091231_oafluxgrid.nc by erai_lwr_19890101_20091231
92;   * remove v1 in output filename
93;
94; - fplod 20101215T113707Z aedon.locean-ipsl.upmc.fr (Darwin)
95;
96;   * add graph in header
97;
98; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
99;
100;   * minimal header
101;
102; - pbk 2008
103;
104;   * creation
105;
106;-
107pro lwr_correction_ncdf
108;
109@cm_4cal
110@cm_4data
111@cm_4mesh
112@cm_4data
113@cm_project
114;
115; test if ${PROJECT_OD} defined
116CASE project_od_env OF
117  '' : BEGIN
118         msg = 'eee : ${PROJECT_OD} is not defined'
119         ras = report(msg)
120       STOP
121       END
122  ELSE: BEGIN
123          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
124          ras = report(msg)
125        END
126 ENDCASE
127;
128; check if output data will be possible
129iodirout = isadirectory(project_od_env)
130;
131; existence and protection for reading
132IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
133   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
134   ras = report(msg)
135   STOP
136ENDIF
137;
138; existence and protection for writing
139IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
140    msg = 'eee : the directory' + iodirout  + ' was not found.'
141    ras = report(msg)
142    STOP
143ENDIF
144;
145da1=19880101 & da2=20091231
146;
147; build data filename
148filename='erai_lwr_19890101_20091231_oafluxgrid.nc'
149;
150; check if this file exists
151fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
152IF fullfilename[0] EQ '' THEN BEGIN
153   msg = 'eee : the file ' + fullfilename + ' was not found.'
154   ras = report(msg)
155   STOP
156ENDIF
157;
158; build output filename
159filename_out = 'TropFlux_lwr_19890101_20091231.nc'
160fullfilename_out = iodirout + filename_out
161; in order to avoid unexpected overwritten
162IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
163   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
164   ras = report(msg)
165   STOP
166ENDIF
167;
168initncdf, fullfilename
169lwr=read_ncdf('lwr',da1,da2,file=fullfilename,/nostr)
170help, lwr
171;
172lwr_mean=grossemoyenne(lwr,'t',/nan)
173help,lwr_mean
174
175tt=time & jpt=n_elements(time)
176caldat, time,mon,day,yea
177lwr_m=lwr*0.
178
179for jt=0,jpt-1 do begin
180  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
181  t=reform(lwr_mean(*,*))
182  lwr_m(*,*,jt)=t
183endfor
184help, lwr_m
185
186lwr_ano=lwr-lwr_m
187
188;; correction for mean based on scatter
189lwr_m=lwr_m+4.61667
190
191help, lwr_ano
192
193;; applying the correction for varyability based on the scatter
194lwr_ano=lwr_ano*(1/0.760667)
195
196;; applying the correction for varyability based on the scatter
197
198lwr_new=lwr_m+lwr_ano
199help, lwr_new
200
201;writing field
202lat=reform(gphit(0,0:jpj-1))
203lon=reform(glamt(0:jpi-1,0))
204time=timegen(7669, units='days', start=julday(1,2,1989)) & jpt=n_elements(time)
205
206cda0=string(jul2date(time(0)),format='(i8.8)')
207cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
208
209time=time-julday(1,1,1950) & jpt=n_elements(time)
210
211ncfile='!' + fullfilename_out
212lon_attr={units:'degrees_east',long_name:'Longitude'}
213lat_attr={units:'degrees_north',long_name:'Latitude'}
214time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
215lwr_attr={units:'degK',missing_value:1.e20,long_name:'Air Temperature at 2m',short_name:'lwr',axis:'TYX'}
216globattr={source:'Basic data obtained from ERAI.  Mean correction for  bias and correction for variability are applied',timerange:cda0+' - '+cda1}
217
218ncfields = 'lwr[longitude,latitude,time]=lwr_new:lwr_attr; ' $
219                      + 'longitude[]=lon:lon_attr; ' $
220                      + 'latitude[]=lat:lat_attr; ' $
221                      + 'time[*time]=time:time_attr ' $
222                      + ' @ globattr'
223
224@ncdf_quickwrite
225
226end
Note: See TracBrowser for help on using the repository browser.