source: trunk/src/cronin_gustiness_ncdf.pro @ 174

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

bunch of new functions

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