source: trunk/src/cronin_gustiness_ncdf.pro @ 205

Last change on this file since 205 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
RevLine 
[6]1;+
2;
3; =========================
4; cronin_gustiness_ncdf.pro
5; =========================
6;
[174]7; .. function:: cronin_gustiness_ncdf(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
[72]12; Cronin gustiness correction on corrected sst on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc` have been produced by
[175]15; :func:`sst_correction_ncdf`.
[72]16;
17; Cronin gustiness corrected ++ on corrected sst on OAFLUX grid
18; is written in
[174]19; :file:`${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc`
[72]20; if this file not already exists.
21;
[100]22; This file will be used by
[174]23; :func:`tropflux_swr_blnd`
[100]24; and
[175]25; :func:`tropflux`.
[72]26;
[8]27;     .. graphviz::
28;
29;        digraph cronin_gustiness_ncdf {
[72]30;
[204]31;           file_in [shape=ellipse,
32;           fontname=Courier,
33;           label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
[174]34;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc"];
[72]35;
[8]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",
[50]40;           label="${PROJECT}/src/cronin_gustiness_ncdf.pro"];
[72]41;
42;           {file_in} -> {cronin_gustiness_ncdf} -> {file_out}
[8]43;        }
44;
[6]45; EXAMPLES
46; ========
47;
[203]48; .. code-block:: idl
[6]49;
[203]50;    yyyymmddb = 20000101L
51;    yyyymmdde = 20001231L
52;    result = cronin_gustiness_ncdf(yyyymmddb, yyyymmdde)
53;    print, result
[6]54;
[20]55; SEE ALSO
56; ========
57;
[72]58; :ref:`project_profile.sh`
59;
60; :ref:`mooring_corrections`
61;
[175]62; :func:`sst_correction_ncdf`.
[72]63;
[20]64; :func:`initncdf <saxo:initncdf>`
65; :func:`julday <saxo:julday>`
66; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
67;
[6]68; TODO
69; ====
70;
[174]71; going on time parametrization
72;
[6]73; coding rules
74;
[94]75; why da1=19880101 and da2=20101231 ? should be 19890101 and 20091231 or better
[88]76; deduce from reading sst
[72]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;
[6]84; EVOLUTIONS
85; ==========
86;
[81]87; $Id$
88;
89; $URL$
90;
[174]91; - fplod 20120321
92;
93;   * pro -> func
[204]94;   * taking project_overwrite into account
[174]95;
[98]96; - fplod 20110830T140029Z cratos (Linux)
97;
98;   * replace tt by time
99;
[72]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;
[8]107; - fplod 20101215T092619Z aedon.locean-ipsl.upmc.fr (Darwin)
108;
109;   * add graph in header
110;
[6]111; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
112;
113;   * minimal header
114;
115; - pbk 2008
116;
117;   * creation
118;
119;-
[174]120function cronin_gustiness_ncdf $
[203]121, yyyymmddb $
122, yyyymmdde
[72]123;
[174]124;++ compile_opt idl2, strictarrsubs, logical_predicate
125;
[72]126@cm_4cal
127@cm_4data
128@cm_4mesh
129@cm_4data
130@cm_project
131;
[174]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;
[72]146; test if ${PROJECT_OD} defined
147CASE project_od_env OF
[204]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
[72]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
[204]164    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
165    ras = report(msg)
166    return, result
[72]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)
[174]173    return, result
[72]174ENDIF
175;
[97]176da1=19880101
[94]177da2=20101231
[72]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
[204]185    msg = 'eee : the file ' + fullfilename + ' was not found.'
186    ras = report(msg)
187    return, result
[72]188ENDIF
189;
190; build output filename
[174]191filename_out = 'TropFlux_gustiness' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
[72]192fullfilename_out = iodirout + filename_out
193; in order to avoid unexpected overwritten
[174]194IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
[204]195    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
196    ras = report(msg)
197    return, result
[72]198ENDIF
199;
200initncdf, fullfilename
[97]201sst=read_ncdf('sst',da1,da2,file=fullfilename,/nostr)
[94]202sst=reform(sst-273.15)
[5]203help, sst
[97]204;
[5]205sst_clim=grossemoyenne(sst, 't',/nan)
[97]206;wg=0.175*sst_clim-3.17  ; line fit obtained from the scatter (Cronin gustiness Vs ERAI SST)
[5]207;help, wg
[97]208;
[5]209jpt=n_elements(time)
[97]210;
[5]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
[97]216;
217; writing field
[100]218time=timegen(7670, start=julday(1,1,1989,0), units='days')
[94]219jpt=n_elements(time)
[97]220;
[5]221cda0=string(jul2date(time(0)),format='(i8.8)')
222cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
[98]223time=time-julday(1,1,1950,00,00,00)
[97]224xlon=reform(glamt(*,0) )
[94]225ylat=reform(gphit(0,*))
[97]226;
[72]227ncfile='!' + fullfilename_out
[5]228lon_attr={units:'degrees_east',long_name:'Longitude'}
229lat_attr={units:'degrees_north',long_name:'Latitude'}
[100]230time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
[5]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}
[97]233;
[5]234ncfields = 'wg[longitude,latitude,time]=wg_tot:gust_attr; ' $
235                      + 'longitude[]=xlon:lon_attr; ' $
236                      + 'latitude[]=ylat:lat_attr; ' $
[98]237                      + 'time[*time]=time:time_attr ' $
[5]238                      + ' @ globattr'
[97]239;
[5]240@ncdf_quickwrite
[97]241;
[174]242result = 0
243return, result
244;
[5]245end
Note: See TracBrowser for help on using the repository browser.