source: trunk/src/lwr_correction_ncdf.pro

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • Property svn:keywords set to URL
File size: 7.0 KB
Line 
1;+
2;
3; =======================
4; lwr_correction_ncdf.pro
5; =======================
6;
7; .. function:: lwr_correction_ncdf(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Correction of lwr on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
15; containing
16; ++
17; have been produced by
18; :func:`interp_erai_lwr` and :ref:`add_19890101.sh`.
19;
20; Corrected lwr on OAFLUX grid
21; is written in
22; :file:`${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc`
23; if this file not already exists.
24;
25; This output file
26; :file:`${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc`
27; will be used by
28; :func:`tropflux`.
29;
30; .. only:: man
31;
32;    Figure is visible on PDF and HTML documents only.
33;
34; .. only:: html or latex
35;
36;     .. graphviz::
37;
38;        digraph lwr_correction_ncdf {
39;
40;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
41;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc"];
42;
43;           lwr_correction_ncdf [shape=box,
44;           fontname=Courier,
45;           color=blue,
46;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/lwr_correction_ncdf.pro",
47;           label="${PROJECT}/src/lwr_correction_ncdf.pro"];
48;
49;           {file_in} -> {lwr_correction_ncdf} -> {file_out}
50;
51;        }
52;
53; SEE ALSO
54; ========
55;
56; :ref:`mooring_corrections`
57;
58; Used by :ref:`tropflux.sh`
59;
60; :ref:`project_profile.sh`
61;
62; :func:`interp_erai_lwr` and :ref:`add_19890101.sh`
63;
64; :func:`initncdf <saxo:initncdf>`
65; :func:`read_ncdf <saxo:read_ncdf>`
66; :func:`grossemoyenne <saxo:grossemoyenne>`
67; :func:`julday <saxo:julday>`
68; :func:`caldat <saxo:caldat>`
69; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
70;
71; EXAMPLES
72; ========
73;
74; .. code-block:: idl
75;
76;    yyyymmddb = 20000101L
77;    yyyymmdde = 20001231L
78;    result = lwr_correction_ncdf(yyyymmddb, yyyymmdde)
79;    print, result
80;
81; TODO
82; ====
83;
84; coding rules
85;
86; lwr long name 'Air Temperature at 2m" : ???
87;
88; remove hard coded time
89;
90; add_19890101.sh sould not be the previous step in a near future
91;
92; KNOWN ISSUES
93; ============
94;
95; test of existence of fullfilename_in not very efficient because
96; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
97;
98; EVOLUTIONS
99; ==========
100;
101; $Id: lwr_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $
102;
103; $URL$
104;
105; - fplod 20120322
106;
107;   * taking project_overwrite into account
108;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
109;   * pro -> function
110;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
111;   * get rid of timegen
112;
113; - fplod 20110819T105050Z aedon.locean-ipsl.upmc.fr (Darwin)
114;
115;   * replace previous step interp_erai_lwr_1989_2009.pro
116;     by :ref:`add_19890101.sh`
117;   * change 19890102 to 19890101
118;
119; - fplod 20110808T120234Z cratos (Linux)
120;
121;   * usage of ${PROJECT_OD}
122;   * complete description
123;   * replace erai_lwr_19890102_20091231_oafluxgrid.nc by erai_lwr_19890101_20091231
124;   * remove v1 in output filename
125;
126; - fplod 20101215T113707Z aedon.locean-ipsl.upmc.fr (Darwin)
127;
128;   * add graph in header
129;
130; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
131;
132;   * minimal header
133;
134; - pbk 2008
135;
136;   * creation
137;
138;-
139function lwr_correction_ncdf $
140, yyyymmddb $
141, yyyymmdde
142;
143;++compile_opt idl2, strictarrsubs, logical_predicate
144;
145@cm_4cal
146@cm_4data
147@cm_4mesh
148@cm_4data
149@cm_project
150;
151; Return to caller if errors
152ON_ERROR, 2
153;
154result = -1
155;
156usage = 'result = lwr_correction_ncdf(yyyymmddb, yyyymmdde)'
157nparam = N_PARAMS()
158IF (nparam NE 2) THEN BEGIN
159    ras = report(['Incorrect number of arguments.' $
160    + '!C' $
161    + 'Usage : ' + usage])
162    return, result
163ENDIF
164;
165; test if ${PROJECT_OD} defined
166CASE project_od_env OF
167    '' : BEGIN
168        msg = 'eee : ${PROJECT_OD} is not defined'
169        ras = report(msg)
170        return, result
171    END
172    ELSE : BEGIN
173        msg = 'iii : ${PROJECT_OD} is ' + project_od_env
174        ras = report(msg)
175    END
176ENDCASE
177;
178; check if output data will be possible
179iodirout = isadirectory(project_od_env)
180;
181; existence and protection for reading
182IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
183    msg = 'eee : the directory' + iodirout + ' is not accessible.'
184    ras = report(msg)
185    return, result
186ENDIF
187;
188; existence and protection for writing
189IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
190    msg = 'eee : the directory' + iodirout + ' was not found.'
191    ras = report(msg)
192    return, result
193ENDIF
194;
195; build data filename
196filename='erai_lwr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
197;
198; check if this file exists
199msg='iii : looking for ' + filename
200ras = report(msg)
201fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
202IF fullfilename[0] EQ '' THEN BEGIN
203    msg = 'eee : the file ' + fullfilename + ' was not found.'
204    ras = report(msg)
205    return, result
206ENDIF
207;
208; build output filename
209filename_out = 'TropFlux_lwr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
210fullfilename_out = iodirout + filename_out
211; in order to avoid unexpected overwritten
212IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
213    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
214    ras = report(msg)
215    return, result
216ENDIF
217;
218initncdf, fullfilename
219lwr=read_ncdf('lwr',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
220timein=24.d*(time-julday(1,1,1957,0,0,0))
221jpt=n_elements(timein)
222da=jul2date(time[0])
223cda0=string(da,format='(i8.8)')
224da=jul2date(time[jpt-1])
225cda1=string(da,format='(i8.8)')
226print, 'lwr in lwr_correction_ncdf first date ', cda0
227print, 'lwr in lwr_correction_ncdf last date ' , cda1
228;
229help, lwr
230;
231lwr_mean=grossemoyenne(lwr,'t',/nan)
232help,lwr_mean
233;
234jpt=n_elements(time)
235caldat, time,mon,day,yea
236lwr_m=lwr*0.
237;
238for jt=0,jpt-1 do begin
239    jtt=(time[jt]-julday(1,1,yea[jt])) < 364
240    t=reform(lwr_mean[*,*])
241    lwr_m[*,*,jt]=t
242endfor
243help, lwr_m
244;
245lwr_ano=lwr-lwr_m
246;
247; correction for mean based on scatter
248lwr_m=lwr_m+4.61667
249;
250help, lwr_ano
251;
252; applying the correction for variability based on the scatter
253lwr_ano=lwr_ano*(1/0.760667)
254;
255; applying the correction for variability based on the scatter
256;
257lwr_new=lwr_m+lwr_ano
258help, lwr_new
259;
260;writing field
261lat=reform(gphit[0,0:jpj-1])
262lon=reform(glamt[0:jpi-1,0])
263;
264ncfile='!' + fullfilename_out
265lon_attr={units:'degrees_east',long_name:'Longitude'}
266lat_attr={units:'degrees_north',long_name:'Latitude'}
267time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
268globattr={source:'Basic data obtained from ERAI. Mean correction for bias and correction for variability are applied',timerange:cda0+' - '+cda1}
269lwr_attr={units:'degK',missing_value:1.e20,long_name:'Air Temperature at 2m',short_name:'lwr',axis:'TYX'}
270;
271ncfields = 'lwr[longitude,latitude,*time]=lwr_new:lwr_attr; ' $
272+ 'longitude[]=lon:lon_attr; ' $
273+ 'latitude[]=lat:lat_attr; ' $
274+ 'time[]=timein:time_attr ' $
275+ ' @ globattr'
276;
277@ncdf_quickwrite
278;
279result = 0
280return, result
281;
282end
Note: See TracBrowser for help on using the repository browser.