source: trunk/src/ws_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.4 KB
Line 
1;+
2;
3; .. _ws_correction_ncdf.pro:
4;
5; ======================
6; ws_correction_ncdf.pro
7; ======================
8;
9; Correction of ws on OAFLUX grid
10;
11; :file:`${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc` have been
12; produced by :ref:`interp_erai_ws_1989_2009.pro`.
13;
14; Corrected ws on OAFLUX grid is written in
15; :file:`${PROJECT_OD}/TropFlux_ws_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 ws_correction_ncdf {
23;           graph [
24;           rankdir="LR",
25;           ]
26;
27;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc"];
28;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc"];
29;
30;           ws_correction_ncdf [shape=box,
31;           fontname=Courier,
32;           color=blue,
33;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/ws_correction_ncdf.pro",
34;           label="${PROJECT}/src/ws_correction_ncdf.pro"];
35;
36;           {file_in} -> {ws_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_vs_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> ws_correction_ncdf
62;
63; TODO
64; ====
65;
66; coding rules
67;
68; hard coded correction
69;
70; KNOWN ISSUES
71; ============
72;
73; test of existence of fullfilename_in not very efficient because
74; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
75;
76; EVOLUTIONS
77; ==========
78;
79; - fplod 20110808T131954Z aedon.locean-ipsl.upmc.fr (Darwin)
80;
81;   * usage of ${PROJECT_OD}
82;   * complete description
83;   * remove v20 in output filename
84
85; - fplod 20101215T115916Z aedon.locean-ipsl.upmc.fr (Darwin)
86;
87;   * add graph in header
88;
89; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
90;
91;   * minimal header
92;
93; - pbk 2008
94;
95;   * creation
96;
97;-
98pro ws_correction_ncdf
99;
100@cm_4cal
101@cm_4data
102@cm_4mesh
103@cm_4data
104@cm_project
105;
106; test if ${PROJECT_OD} defined
107CASE project_od_env OF
108  '' : BEGIN
109         msg = 'eee : ${PROJECT_OD} is not defined'
110         ras = report(msg)
111       STOP
112       END
113  ELSE: BEGIN
114          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
115          ras = report(msg)
116        END
117 ENDCASE
118;
119; check if output data will be possible
120iodirout = isadirectory(project_od_env)
121;
122; existence and protection for reading
123IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
124   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
125   ras = report(msg)
126   STOP
127ENDIF
128;
129; existence and protection for writing
130IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
131    msg = 'eee : the directory' + iodirout  + ' was not found.'
132    ras = report(msg)
133    STOP
134ENDIF
135;
136da1=19880101 & da2=20101231
137;
138; build data filename
139filename='erai_ws_19890101_20091231_oafluxgrid.nc'
140;
141; check if this file exists
142fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
143IF fullfilename[0] EQ '' THEN BEGIN
144   msg = 'eee : the file ' + fullfilename + ' was not found.'
145   ras = report(msg)
146   STOP
147ENDIF
148;
149; build output filename
150filename_out = 'TropFlux_ws_19890101_20091231.nc'
151fullfilename_out = iodirout + filename_out
152; in order to avoid unexpected overwritten
153IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
154   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
155   ras = report(msg)
156   STOP
157ENDIF
158;
159initncdf, fullfilename
160u=read_ncdf('u10',da1,da2,file=fullfilename,/nostr)
161v=read_ncdf('v10',da1,da2,file=fullfilename,/nostr)
162w=sqrt(u*u+v*v)
163
164help, w
165
166w_mean=grossemoyenne(w,'t',/nan)
167help, w_mean
168
169tt=time & jpt=n_elements(time)
170caldat, time,mon,day,yea
171w_m=w*0.
172
173for jt=0,jpt-1 do begin
174  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
175  q=reform(w_mean(*,*))
176  w_m(*,*,jt)=q
177endfor
178help, w_m
179
180w_ano=w-w_m
181
182;; correction for mean based on scatter
183;w_m=w_m+0.282667    ;; (2000-2008)
184w_m=w_m+0.276739     ;; (2000-2009)
185
186help, w_ano
187
188;; applying the correction for varyability based on the scatter
189;w_ano=w_ano*(1/0.897667)   ;; (2000-2008)
190w_ano=w_ano*(1/0.903587)    ;; (2000-2009)
191
192w_new=w_m+w_ano
193help, w_new
194
195;writing field
196lat=reform(gphit(0,0:jpj-1))
197lon=reform(glamt(0:jpi-1,0))
198time=timegen(7670, units='days', start=julday(1,1,1989,0)) & jpt=n_elements(time)
199
200cda0=string(jul2date(time(0)),format='(i8.8)')
201cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
202
203time=time-julday(1,1,1950) & jpt=n_elements(time)
204
205ncfile='!' + fullfilename_out
206lon_attr={units:'degrees_east',long_name:'Longitude'}
207lat_attr={units:'degrees_north',long_name:'Latitude'}
208time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
209w_attr={units:'m/s',missing_value:1.e20,long_name:'mean wind speed',short_name:'w',axis:'TYX'}
210globattr={source:'Basic data obtained from ERAI. Bias and variability correction are applied',timerange:cda0+' - '+cda1}
211
212ncfields = 'ws[longitude,latitude,time]=w_new:w_attr; ' $
213                      + 'longitude[]=lon:lon_attr; ' $
214                      + 'latitude[]=lat:lat_attr; ' $
215                      + 'time[*time]=time:time_attr ' $
216                      + ' @ globattr'
217
218@ncdf_quickwrite
219
220end
Note: See TracBrowser for help on using the repository browser.