source: trunk/src/cronin_gustiness_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 Id URL
File size: 6.1 KB
Line 
1;+
2;
3; =========================
4; cronin_gustiness_ncdf.pro
5; =========================
6;
7; .. function:: cronin_gustiness_ncdf(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Cronin gustiness correction on corrected sst on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc` have been produced by
15; :func:`sst_correction_ncdf`.
16;
17; Cronin gustiness corrected ++ on corrected sst on OAFLUX grid
18; is written in
19; :file:`${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc`
20; if this file not already exists.
21;
22; This file will be used by
23; :func:`tropflux_swr_blnd`
24; and
25; :func:`tropflux`.
26;
27;     .. graphviz::
28;
29;        digraph cronin_gustiness_ncdf {
30;
31;           file_in [shape=ellipse,
32;           fontname=Courier,
33;           label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
34;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc"];
35;
36;           cronin_gustiness_ncdf [shape=box,
37;           fontname=Courier,
38;           color=blue,
39;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/cronin_gustiness_ncdf.pro",
40;           label="${PROJECT}/src/cronin_gustiness_ncdf.pro"];
41;
42;           {file_in} -> {cronin_gustiness_ncdf} -> {file_out}
43;        }
44;
45; EXAMPLES
46; ========
47;
48; .. code-block:: idl
49;
50;    yyyymmddb = 20000101L
51;    yyyymmdde = 20001231L
52;    result = cronin_gustiness_ncdf(yyyymmddb, yyyymmdde)
53;    print, result
54;
55; SEE ALSO
56; ========
57;
58; :ref:`project_profile.sh`
59;
60; :ref:`mooring_corrections`
61;
62; :func:`sst_correction_ncdf`.
63;
64; :func:`initncdf <saxo:initncdf>`
65; :func:`julday <saxo:julday>`
66; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
67;
68; TODO
69; ====
70;
71; going on time parametrization
72;
73; coding rules
74;
75; why da1=19880101 and da2=20101231 ? should be 19890101 and 20091231 or better
76; deduce from reading sst
77;
78; KNOWN ISSUES
79; ============
80;
81; test of existence of fullfilename_in not very efficient because
82; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
83;
84; EVOLUTIONS
85; ==========
86;
87; $Id$
88;
89; $URL$
90;
91; - fplod 20120321
92;
93;   * pro -> func
94;   * taking project_overwrite into account
95;
96; - fplod 20110830T140029Z cratos (Linux)
97;
98;   * replace tt by time
99;
100; - fplod 20110808T144208Z aedon.locean-ipsl.upmc.fr (Darwin)
101;
102;   * usage of ${PROJECT_OD}
103;   * complete description
104;   * remove v50 in output filename
105;   * remove return statement
106;
107; - fplod 20101215T092619Z aedon.locean-ipsl.upmc.fr (Darwin)
108;
109;   * add graph in header
110;
111; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
112;
113;   * minimal header
114;
115; - pbk 2008
116;
117;   * creation
118;
119;-
120function cronin_gustiness_ncdf $
121, yyyymmddb $
122, yyyymmdde
123;
124;++ compile_opt idl2, strictarrsubs, logical_predicate
125;
126@cm_4cal
127@cm_4data
128@cm_4mesh
129@cm_4data
130@cm_project
131;
132; Return to caller if errors
133ON_ERROR, 2
134;
135result = -1
136;
137usage = 'result = tropflux_swr_nrt(yyyymmddb, yyyymmdde)'
138nparam = N_PARAMS()
139IF (nparam NE 2) THEN BEGIN
140   ras = report(['Incorrect number of arguments.' $
141         + '!C' $
142         + 'Usage : ' + usage])
143   return, result
144ENDIF
145;
146; test if ${PROJECT_OD} defined
147CASE project_od_env OF
148    '' : BEGIN
149        msg = 'eee : ${PROJECT_OD} is not defined'
150        ras = report(msg)
151        return, result
152    END
153    ELSE : BEGIN
154        msg = 'iii : ${PROJECT_OD} is ' + project_od_env
155        ras = report(msg)
156    END
157ENDCASE
158;
159; check if output data will be possible
160iodirout = isadirectory(project_od_env)
161;
162; existence and protection for reading
163IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
164    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
165    ras = report(msg)
166    return, result
167ENDIF
168;
169; existence and protection for writing
170IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
171    msg = 'eee : the directory' + iodirout  + ' was not found.'
172    ras = report(msg)
173    return, result
174ENDIF
175;
176da1=19880101
177da2=20101231
178;
179; build data filename
180filename='TropFlux_sst_19890101_20091231.nc'
181;
182; check if this file exists
183fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
184IF fullfilename[0] EQ '' THEN BEGIN
185    msg = 'eee : the file ' + fullfilename + ' was not found.'
186    ras = report(msg)
187    return, result
188ENDIF
189;
190; build output filename
191filename_out = 'TropFlux_gustiness' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
192fullfilename_out = iodirout + filename_out
193; in order to avoid unexpected overwritten
194IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
195    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
196    ras = report(msg)
197    return, result
198ENDIF
199;
200initncdf, fullfilename
201sst=read_ncdf('sst',da1,da2,file=fullfilename,/nostr)
202sst=reform(sst-273.15)
203help, sst
204;
205sst_clim=grossemoyenne(sst, 't',/nan)
206;wg=0.175*sst_clim-3.17  ; line fit obtained from the scatter (Cronin gustiness Vs ERAI SST)
207;help, wg
208;
209jpt=n_elements(time)
210;
211wg_tot=sst*0.
212for jt=0, jpt-1 do begin
213    wg_tot(*,*,jt)=(((sst_clim(*,*)-23.7)*2.1/(29.8-23.7)) > 1.) <2.1
214endfor
215help, wg_tot
216;
217; writing field
218time=timegen(7670, start=julday(1,1,1989,0), units='days')
219jpt=n_elements(time)
220;
221cda0=string(jul2date(time(0)),format='(i8.8)')
222cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
223time=time-julday(1,1,1950,00,00,00)
224xlon=reform(glamt(*,0) )
225ylat=reform(gphit(0,*))
226;
227ncfile='!' + fullfilename_out
228lon_attr={units:'degrees_east',long_name:'Longitude'}
229lat_attr={units:'degrees_north',long_name:'Latitude'}
230time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
231gust_attr={units:'m/s',missing_value:valmask,long_name:'Climatological gustiness',short_name:'wg',axis:'TYX'}
232globattr={source:'Climatological wind gustiness obtained by fitting cronins gustiness values against sst ',timerange:cda0+' - '+cda1}
233;
234ncfields = 'wg[longitude,latitude,time]=wg_tot:gust_attr; ' $
235                      + 'longitude[]=xlon:lon_attr; ' $
236                      + 'latitude[]=ylat:lat_attr; ' $
237                      + 'time[*time]=time:time_attr ' $
238                      + ' @ globattr'
239;
240@ncdf_quickwrite
241;
242result = 0
243return, result
244;
245end
Note: See TracBrowser for help on using the repository browser.