source: trunk/src/sst_correction_ncdf.pro @ 152

Last change on this file since 152 was 100, checked in by pinsard, 13 years ago

start to homogenize (to be cont.)

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