source: trunk/src/ws_correction_ncdf.pro @ 175

Last change on this file since 175 was 175, checked in by pinsard, 12 years ago

an other bunch of new functions

  • Property svn:keywords set to URL
File size: 7.0 KB
Line 
1;+
2;
3; ======================
4; ws_correction_ncdf.pro
5; ======================
6;
7; .. function:: ws_correction_ncdf(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Correction of ws on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/erai_ws_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
15; containing
16; ++
17; have been produced by
18; :func:`interp_erai_ws`.
19;
20; Corrected ws on OAFLUX grid
21; is written in
22; :file:`${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc`
23; if this file not already exists.
24;
25; This output file
26; :file:`${PROJECT_OD}/TropFlux_ws_{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 ws_correction_ncdf {
39;
40;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_ws_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
41;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc"];
42;
43;           ws_correction_ncdf [shape=box,
44;           fontname=Courier,
45;           color=blue,
46;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/ws_correction_ncdf.pro",
47;           label="${PROJECT}/src/ws_correction_ncdf.pro"];
48;
49;           {file_in} -> {ws_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_ws`
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; ::
75;
76;  IDL> yyyymmddb = 20000101L
77;  IDL> yyyymmdde = 20001231L
78;  IDL> result = ws_correction_ncdf(yyyymmddb, yyyymmdde)
79;  IDL> print, result
80;
81; TODO
82; ====
83;
84; coding rules
85;
86; hard coded correction
87;
88; KNOWN ISSUES
89; ============
90;
91; test of existence of fullfilename_in not very efficient because
92; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
93;
94; EVOLUTIONS
95; ==========
96;
97; $Id: ws_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $
98;
99; $URL$
100;
101; - fplod 20120322
102;
103;   * taking project_overwite into account
104;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
105;   * pro -> function
106;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
107;   * get rid of timegen
108;
109; - fplod 20110808T131954Z aedon.locean-ipsl.upmc.fr (Darwin)
110;
111;   * usage of ${PROJECT_OD}
112;   * complete description
113;   * remove v20 in output filename
114;
115; - fplod 20101215T115916Z aedon.locean-ipsl.upmc.fr (Darwin)
116;
117;   * add graph in header
118;
119; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
120;
121;   * minimal header
122;
123; - pbk 2008
124;
125;   * creation
126;
127;-
128function ws_correction_ncdf $
129         , yyyymmddb $
130         , yyyymmdde
131;
132;++compile_opt idl2, strictarrsubs, logical_predicate
133;
134@cm_4data
135@cm_4mesh
136@cm_4data
137@cm_project
138;
139; Return to caller if errors
140ON_ERROR, 2
141;
142result = -1
143;
144usage = 'result = ws_correction_ncdf(yyyymmddb, yyyymmdde)'
145nparam = N_PARAMS()
146IF (nparam NE 2) THEN BEGIN
147    ras = report(['Incorrect number of arguments.' $
148          + '!C' $
149          + 'Usage : ' + usage])
150    return, result
151ENDIF
152;
153@cm_4cal
154; test if ${PROJECT_OD} defined
155CASE project_od_env OF
156  '' : BEGIN
157         msg = 'eee : ${PROJECT_OD} is not defined'
158         ras = report(msg)
159       return, result
160       END
161  ELSE: BEGIN
162          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
163          ras = report(msg)
164        END
165 ENDCASE
166;
167; check if output data will be possible
168iodirout = isadirectory(project_od_env)
169;
170; existence and protection for reading
171IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
172   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
173   ras = report(msg)
174   return, result
175ENDIF
176;
177; existence and protection for writing
178IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
179    msg = 'eee : the directory' + iodirout  + ' was not found.'
180    ras = report(msg)
181    return, result
182ENDIF
183;
184; build data filename
185filename='erai_ws_' $
186    + string(yyyymmddb,format='(i8.8)') $
187    + '_' $
188    + string(yyyymmdde,format='(i8.8)') $
189    + '_oafluxgrid.nc'
190;
191; check if this file exists
192msg='iii : looking for ' + filename
193ras = report(msg)
194fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
195IF fullfilename[0] EQ '' THEN BEGIN
196   msg = 'eee : the file ' + fullfilename + ' was not found.'
197   ras = report(msg)
198   return, result
199ENDIF
200;
201; build output filename
202filename_out = 'TropFlux_ws_' $
203    + string(yyyymmddb,format='(i8.8)') $
204    + '_' $
205    + string(yyyymmdde,format='(i8.8)') $
206    + '.nc'
207fullfilename_out = iodirout + filename_out
208; in order to avoid unexpected overwritten
209IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
210   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
211   ras = report(msg)
212   return, result
213ENDIF
214;
215initncdf, fullfilename
216u=read_ncdf('u10',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
217timein=24.d*(time-julday(1,1,1957,0,0,0))
218jpt=n_elements(timein)
219da=jul2date(time[0])
220cda0=string(da,format='(i8.8)')
221da=jul2date(time[jpt-1])
222cda1=string(da,format='(i8.8)')
223print, 'u10 in ws_correction_ncdf first date ', cda0
224print, 'u10 in ws_correction_ncdf last date ' , cda1
225;
226v=read_ncdf('v10',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
227timein=24.d*(time-julday(1,1,1957,0,0,0))
228jpt=n_elements(timein)
229da=jul2date(time[0])
230cda0=string(da,format='(i8.8)')
231da=jul2date(time[jpt-1])
232cda1=string(da,format='(i8.8)')
233print, 'v10 in ws_correction_ncdf first date ', cda0
234print, 'v10 in ws_correction_ncdf last date ' , cda1
235;
236w=sqrt(u*u+v*v)
237;
238help, w
239;
240w_mean=grossemoyenne(w,'t',/nan)
241help, w_mean
242;
243jpt=n_elements(time)
244caldat, time,mon,day,yea
245w_m=w*0.
246;
247for jt=0,jpt-1 do begin
248  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
249  q=reform(w_mean[*,*])
250  w_m[*,*,jt]=q
251endfor
252help, w_m
253;
254w_ano=w-w_m
255;
256; correction for mean based on scatter
257;w_m=w_m+0.282667    ; (2000-2008)
258w_m=w_m+0.276739     ; (2000-2009)
259;
260help, w_ano
261;
262; applying the correction for varyability based on the scatter
263;w_ano=w_ano*(1/0.897667)   ; (2000-2008)
264w_ano=w_ano*(1/0.903587)    ; (2000-2009)
265;
266w_new=w_m+w_ano
267help, w_new
268;
269;writing field
270lat=reform(gphit[0,0:jpj-1])
271lon=reform(glamt[0:jpi-1,0])
272;
273ncfile='!' + fullfilename_out
274lon_attr={units:'degrees_east',long_name:'Longitude'}
275lat_attr={units:'degrees_north',long_name:'Latitude'}
276time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
277globattr={source:'Basic data obtained from ERAI. Bias and variability correction are applied',timerange:cda0+' - '+cda1}
278w_attr={units:'m/s',missing_value:1.e20,long_name:'mean wind speed',short_name:'w',axis:'TYX'}
279;
280ncfields = 'ws[longitude,latitude,*time]=w_new:w_attr; ' $
281                      + 'longitude[]=lon:lon_attr; ' $
282                      + 'latitude[]=lat:lat_attr; ' $
283                      + 'time[]=timein:time_attr ' $
284                      + ' @ globattr'
285;
286@ncdf_quickwrite
287;
288result = 0
289return, result
290;
291end
Note: See TracBrowser for help on using the repository browser.