source: trunk/src/sst_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: 7.0 KB
Line 
1;+
2;
3; .. _sst_correction_ncdf.pro:
4;
5; =======================
6; sst_correction_ncdf.pro
7; =======================
8;
9; Correction of sst on OAFLUX grid
10;
11; :file:`${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc` have been
12; produced by :ref:`interp_erai_sst_1989_2009.pro`.
13;
14; Corrected sst on OAFLUX grid is written in
15; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc`
16; if this file not already exists.
17;
18; This file will be used by :ref:`cronin_gustiness_ncdf.pro` and
19; :ref:`TropFlux_19890101_20091231.pro`.
20;
21;     .. graphviz::
22;
23;        digraph sst_correction_ncdf {
24;           graph [
25;           rankdir="LR",
26;           ]
27;
28;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc"];
29;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
30;
31;           sst_correction_ncdf [shape=box,
32;           fontname=Courier,
33;           color=blue,
34;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/sst_correction_ncdf.pro",
35;           label="${PROJECT}/src/sst_correction_ncdf.pro"];
36;
37;           {file_in} -> {sst_correction_ncdf} -> {file_out}
38;
39;        }
40;
41;
42; SEE ALSO
43; ========
44;
45; :ref:`project_profile.sh`
46;
47; :ref:`mooring_corrections`
48;
49; :ref:`interp_erai_sst_1989_2009.pro`
50;
51; :func:`initncdf <saxo:initncdf>`
52; :func:`read_ncdf <saxo:read_ncdf>`
53; :func:`grossemoyenne <saxo:grossemoyenne>`
54; :func:`julday <saxo:julday>`
55; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
56;
57; EXAMPLES
58; ========
59;
60; ::
61;
62;  IDL> sst_correction_ncdf
63;
64; TODO
65; ====
66;
67; very strange value of time on lohlot1 idl6 but not always and not always at the same indices !!::
68;
69;    print, time[7080:7090]
70;       2454607.5       2454608.5       2454609.5   9.9692100e+36   9.9692100e+36
71;   9.9692100e+36   9.9692100e+36   9.9692100e+36   9.9692100e+36       2454616.5
72;       2454617.5
73;
74; while ::
75;
76;   $ ncks -H -C -v time -d time,7080,7090 ${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc
77;   time[7080]=450432
78;   time[7081]=450456
79;   time[7082]=450480
80;   time[7083]=450504
81;   time[7084]=450528
82;   time[7085]=450552
83;   time[7086]=450576
84;   time[7087]=450600
85;   time[7088]=450624
86;   time[7089]=450648
87;   time[7090]=450672
88;
89; and
90;   ncks -H -C -v time -d time,7080,7090 ${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc
91;   time[7080]=21325
92;   time[7081]=21326
93;   time[7082]=21327
94;   time[7083]=9.96920996839e+36
95;   time[7084]=9.96920996839e+36
96;   time[7085]=9.96920996839e+36
97;   time[7086]=9.96920996839e+36
98;   time[7087]=9.96920996839e+36
99;   time[7088]=9.96920996839e+36
100;   time[7089]=21334
101;   time[7090]=21335
102;   
103; and ::
104;
105;   fplod@cratos$ ncks -H -C -v time -d time,7080,7090 ${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc
106;   time[7080]=21325
107;   time[7081]=21326
108;   time[7082]=21327
109;   time[7083]=21328
110;   time[7084]=21329
111;   time[7085]=21330
112;   time[7086]=21331
113;   time[7087]=21332
114;   time[7088]=21333
115;   time[7089]=21334
116;   time[7090]=21335
117
118; coding rules
119;
120; temperature SI units = K : why + and - 273...
121;
122; hard coded coefficient correction.
123;
124; KNOWN ISSUES
125; ============
126;
127; test of existence of fullfilename_in not very efficient because
128; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
129;
130; EVOLUTIONS
131; ==========
132;
133; $Id$
134;
135; $URL$
136;
137; - fplod 20110808T124236Z cratos (Linux)
138;
139;   * usage of ${PROJECT_OD}
140;   * complete description
141;   * remove v20 in output filename
142;
143; - fplod 20101215T114224Z aedon.locean-ipsl.upmc.fr (Darwin)
144;
145;   * add graph in header
146;
147; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
148;
149;   * minimal header
150;
151; - pbk 2008
152;
153;   * creation
154;
155;-
156pro sst_correction_ncdf
157;
158@cm_4cal
159@cm_4data
160@cm_4mesh
161@cm_4data
162@cm_project
163;
164; test if ${PROJECT_OD} defined
165CASE project_od_env OF
166  '' : BEGIN
167         msg = 'eee : ${PROJECT_OD} is not defined'
168         ras = report(msg)
169       STOP
170       END
171  ELSE: BEGIN
172          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
173          ras = report(msg)
174        END
175 ENDCASE
176;
177; check if output data will be possible
178iodirout = isadirectory(project_od_env)
179;
180; existence and protection for reading
181IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
182   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
183   ras = report(msg)
184   STOP
185ENDIF
186;
187; existence and protection for writing
188IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
189    msg = 'eee : the directory' + iodirout  + ' was not found.'
190    ras = report(msg)
191    STOP
192ENDIF
193;
194da1=19880101 & da2=20091231
195;
196; build data filename
197filename='erai_sst_19890101_20091231_oafluxgrid.nc'
198;
199; check if this file exists
200fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
201IF fullfilename[0] EQ '' THEN BEGIN
202   msg = 'eee : the file ' + fullfilename + ' was not found.'
203   ras = report(msg)
204   STOP
205ENDIF
206;
207; build output filename
208filename_out = 'TropFlux_sst_19890101_20091231.nc'
209fullfilename_out = iodirout + filename_out
210; in order to avoid unexpected overwritten
211IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
212   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
213   ras = report(msg)
214   STOP
215ENDIF
216;
217initncdf, fullfilename
218sst=read_ncdf('sst',da1,da2,file=fullfilename,/nostr) & sst=sst-273.15
219help, sst
220
221sst_mean=grossemoyenne(sst,'t',/nan)
222help, sst_mean
223
224tt=time & jpt=n_elements(time)
225caldat, time,mon,day,yea
226;
227; debug to understand some time value 9.9692100e+36 on idl 6 lohloht1
228print, time[7080:7090]
229;
230sst_m=sst*0.
231
232for jt=0,jpt-1 do begin
233  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
234  t=reform(sst_mean(*,*))
235  sst_m(*,*,jt)=t
236endfor
237help, sst_m
238
239sst_ano=sst-sst_m
240
241;; correction for mean based on scatter
242;sst_m=sst_m+0.0521111   ;; (2000-2008)
243sst_m=sst_m+0.0533692    ;; (2000-2009)
244
245help, sst_ano
246
247;; applying the correction for varyability based on the scatter
248;sst_ano=sst_ano*(1/0.989889)  ;; (2000-2008)
249sst_ano=sst_ano*(1/0.986196)   ;; (2000-2009)
250
251sst_new=sst_m+sst_ano+273.15
252help, sst_new
253
254;writing field
255lat=reform(gphit(0,0:jpj-1))
256lon=reform(glamt(0:jpi-1,0))
257time=timegen(7670, units='days', start=julday(1,1,1989)) & jpt=n_elements(time)
258
259cda0=string(jul2date(time(0)),format='(i8.8)')
260cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
261
262time=time-julday(1,1,1950) & jpt=n_elements(time)
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'}
268sst_attr={units:'degK',missing_value:1.e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'}
269globattr={source:'Basic data obtained from ERAI.  Bias and variability correction are applied',timerange:cda0+' - '+cda1}
270
271ncfields = 'sst[longitude,latitude,time]=sst_new:sst_attr; ' $
272                      + 'longitude[]=lon:lon_attr; ' $
273                      + 'latitude[]=lat:lat_attr; ' $
274                      + 'time[*time]=time:time_attr ' $
275                      + ' @ globattr'
276
277@ncdf_quickwrite
278
279end
Note: See TracBrowser for help on using the repository browser.