source: trunk/src/TropFlux_19890101_20091231.pro @ 81

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

progress on swr and olr processing

  • Property svn:executable set to *
File size: 14.7 KB
Line 
1;+
2;
3; .. _TropFlux_19890101_20091231.pro:
4;
5; ==============================
6; TropFlux_19890101_20091231.pro
7; ==============================
8;
9; This program computes net heat flux components on the 1° oaflux grid.
10;
11; all input variables are corrected for mean bias and variability.
12;
13; gustiness correction is applied for wind speed based on cronin's climatological
14; gustiness values.
15;
16; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` containing OAFLUX grid have been produced by :ref:`oaflux_mask_30N30S.pro`.
17;
18; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc` containing sst corrected on OAFLUX grid have been produced by :ref:`sst_correction_ncdf.pro`.
19;
20; :file:`${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc` containing ws corrected on OAFLUX grid have been produced by :ref:`ws_correction_ncdf.pro`.
21;
22; :file:`${PROJECT_OD}/TropFlux_gustiness_19890101_20091231.nc` containing ++
23; have been produced by :ref:`cronin_gustiness_ncdf.pro`.
24;
25; :file:`${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc` containing ws corrected on OAFLUX grid
26; have been produced by :ref:`TropFlux_swr_BLND_19890101_20091231.pro`.
27;
28; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc` containing lwr corrected on OAFLUX grid have been produced by :ref:`lwr_correction_ncdf.pro`.
29;
30; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc` containing t2m corrected on OAFLUX grid have been produced by :ref:`t2m_correction_ncdf.pro`.
31;
32; :file:`${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc` containing q2m corrected on OAFLUX grid have been produced by :ref:`d2m_to_q2m_erai.pro`.
33;
34; net heat flux components are written
35; in :file:`${PROJECT_OD}/TropFlux_19890101_20091231.nc`
36; if this file not already exists.
37;
38;     .. graphviz::
39;
40;        digraph tropflux_19890101_20091231 {
41;           graph [
42;           rankdir="LR",
43;           ]
44;
45;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
46;           file_sst [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
47;           file_ws [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc"];
48;           file_wg [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_19890101_20091231.nc"];
49;           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc"];
50;           file_lwr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc"];
51;           file_t2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"];
52;           file_q2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc"];
53;
54;           file_out[shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_19890101_20091231.nc"];
55;
56;           tropflux_19890101_20091231 [shape=box,
57;           fontname=Courier,
58;           color=blue,
59;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/TropFlux_19890101_20091231.pro",
60;           label="${PROJECT}/src/TropFlux_19890101_20091231.pro"];
61;
62;           {mask file_sst file_ws file_wg file_swr file_lwr file_t2m file_q2m} -> {tropflux_19890101_20091231} -> {file_out}
63;
64;          }
65;
66; SEE ALSO
67; ========
68;
69; :ref:`project_profile.sh`
70;
71; :func:`report <saxo:report>`
72; :func:`isadirectory <saxo:isadirectory>`
73; :func:`isafile <saxo:isafile>`
74; :func:`initncdf <saxo:initncdf>`
75; :func:`ncdf_lec <saxo:ncdf_lec>`
76; :func:`read_ncdf <saxo:read_ncdf>`
77; :func:`caldat <saxo:caldat>`
78; :func:`julday <saxo:julday>`
79; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
80;
81; :func:`cor30a`
82;
83; EXAMPLES
84; ========
85;
86; ::
87;
88;  IDL> .compile TropFlux_19890101_20091231
89;  IDL> tropflux_19890101_20091231
90;
91; TODO
92; ====
93;
94; no ${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc yet because of pb in
95; TropFlux_swr_BLND_19890101_20091231.pro
96;
97; avoid mix lower/uppercase in pro name to avoid compile
98;
99; coding rules
100;
101; KNOWN ISSUES
102; ============
103;
104; test of existence of fullfilename_msk not very efficient because
105; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
106;
107; EVOLUTIONS
108; ==========
109;
110; $Id
111;
112; $URL$
113;
114; - fplod 20110809T110911Z aedon.locean-ipsl.upmc.fr (Darwin)
115;
116;   * complete descritption
117;   * remove v* from filenames (in and out)
118;   * usage of ${PROJECT_OD}
119;   * remove return statement
120;   * add test on IO files
121;
122; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
123;
124;   * remove hard coded directory for mask_oaflux_30N30S.nc
125;
126; - fplod 20101214T112131Z aedon.locean-ipsl.upmc.fr (Darwin)
127;
128;   * add graph
129;
130; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
131;
132;   * minimal header
133;
134; - pbk 2008
135;
136;   * creation
137;
138;-
139;
140pro TropFlux_19890101_20091231
141;
142@cm_4cal
143@cm_4data
144@cm_4mesh
145@cm_4data
146@cm_project
147;
148; check for input directory
149;
150; test if ${PROJECT_ID} defined
151CASE project_id_env OF
152    ''  :  BEGIN
153     msg = 'eee : ${PROJECT_ID} is not defined'
154     ras = report(msg)
155     STOP
156           END
157 ELSE: BEGIN
158     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
159     ras = report(msg)
160       END
161ENDCASE
162;
163iodirin = isadirectory(project_id_env)
164;
165; existence and protection of ${PROJECT_ID}
166IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
167   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
168   ras = report(msg)
169   STOP
170ENDIF
171;
172; build mask filename
173filename_msk='mask_oaflux_30N30S.nc'
174;
175; check if this file exists
176msg='iii : looking for ' + filename_msk
177ras = report(msg)
178fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
179IF fullfilename_msk[0] EQ '' THEN BEGIN
180   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
181   ras = report(msg)
182   STOP
183ENDIF
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;
215; build sst data filename
216filename_sst='TropFlux_sst_19890101_20091231.nc'
217;
218; check if this file exists
219msg='iii : looking for ' + filename_sst
220ras = report(msg)
221fullfilename_sst = isafile(iodirout + filename_sst, NEW=0, /MUST_EXIST)
222IF fullfilename_sst[0] EQ '' THEN BEGIN
223   msg = 'eee : the file ' + fullfilename_sst + ' was not found.'
224   ras = report(msg)
225   STOP
226ENDIF
227;
228; build ws data filename
229filename_ws='TropFlux_ws_19890101_20091231.nc'
230;
231; check if this file exists
232msg='iii : looking for ' + filename_ws
233ras = report(msg)
234fullfilename_ws = isafile(iodirout + filename_ws, NEW=0, /MUST_EXIST)
235IF fullfilename_ws[0] EQ '' THEN BEGIN
236   msg = 'eee : the file ' + fullfilename_ws + ' was not found.'
237   ras = report(msg)
238   STOP
239ENDIF
240;
241; build swr data filename
242filename_swr='TropFlux_swr_19890101_20091231_BLND.nc'
243;
244; check if this file exists
245msg='iii : looking for ' + filename_swr
246ras = report(msg)
247fullfilename_swr = isafile(iodirout + filename_swr, NEW=0, /MUST_EXIST)
248IF fullfilename_swr[0] EQ '' THEN BEGIN
249   msg = 'eee : the file ' + fullfilename_swr + ' was not found.'
250   ras = report(msg)
251   STOP
252ENDIF
253;
254; build lwr data filename
255filename_lwr='TropFlux_lwr_19890101_20091231.nc'
256;
257; check if this file exists
258msg='iii : looking for ' + filename_lwr
259ras = report(msg)
260fullfilename_lwr = isafile(iodirout + filename_lwr, NEW=0, /MUST_EXIST)
261IF fullfilename_lwr[0] EQ '' THEN BEGIN
262   msg = 'eee : the file ' + fullfilename_lwr + ' was not found.'
263   ras = report(msg)
264   STOP
265ENDIF
266;
267; build t2m data filename
268filename_t2m='TropFlux_t2m_19890101_20091231.nc'
269;
270; check if this file exists
271msg='iii : looking for ' + filename_t2m
272ras = report(msg)
273fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
274IF fullfilename_t2m[0] EQ '' THEN BEGIN
275   msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
276   ras = report(msg)
277   STOP
278ENDIF
279;
280; build q2m data filename
281filename_q2m='TropFlux_q2m_19890101_20091231.nc'
282;
283; check if this file exists
284msg='iii : looking for ' + filename_q2m
285ras = report(msg)
286fullfilename_q2m = isafile(iodirout + filename_q2m, NEW=0, /MUST_EXIST)
287IF fullfilename_q2m[0] EQ '' THEN BEGIN
288   msg = 'eee : the file ' + fullfilename_q2m + ' was not found.'
289   ras = report(msg)
290   STOP
291ENDIF
292;
293; build wg data filename
294filename_wg='TropFlux_gustiness_19890101_20091231.nc'
295;
296; check if this file exists
297msg='iii : looking for ' + filename_wg
298ras = report(msg)
299fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST)
300IF fullfilename_wg[0] EQ '' THEN BEGIN
301   msg = 'eee : the file ' + fullfilename_wg + ' was not found.'
302   ras = report(msg)
303   STOP
304ENDIF
305;
306da1=19880101 & da2=20101231
307;
308initncdf, fullfilename_msk
309msk=ncdf_lec(fullfilename_msk,var='msk')
310
311initncdf, fullfilename_sst
312
313ws=read_ncdf('ws',da1,da2,file=fullfilename_ws,/nostr)
314wg=read_ncdf('wg',da1-1,da2,file=fullfilename_wg,/nostr)
315tt=time & jpt=n_elements(time)
316sst=read_ncdf('sst',da1,da2,file=fullfilename_sst,/nostr)
317sst=reform(sst-273.15)
318swd=read_ncdf('swr',da1,da2,file=fullfilename_swr,/nostr)
319lw=read_ncdf('lwr',da1,da2,file=fullfilename_lwr,/nostr)
320swd=swd/0.94  ;; converting from net swr to downward swr
321
322t2m=read_ncdf('t2m',da1,da2,file=fullfilename_t2m,/nostr)-273.15   ; in C
323q2m=read_ncdf('q2m',da1,da2,file=fullfilename_q2m,/nostr)    ; in g/kg
324
325w=sqrt(ws*ws+wg*wg)  ;; wind corrected for gustiness
326w=ws
327tmask=msk
328help, ws,w,wg,u,sst,swd,t2m,q2m
329ocean=where(msk eq 1,compl=land)
330valmask=1.e20
331time=tt & jpt=n_elements(time)
332
333;
334;; Constants for flux computation
335;
336zu=10.                          ; height of wind speed measurement (m)
337us=0.                           ; surf current (m/s)
338zt=2.                           ; Height of air T measurement (m)
339zq=2.                           ; height of humidity measurement (m)
340P=1008.                         ; Pressure
341zi=600.                         ; Inversion height (m)
342jcool=0                         ; Compute cool-skin
343jwave=0                         ; No waves
344twave=5.
345hwave=1.
346
347caldat, time,mon,day,yea
348swr=fltarr(jpi,jpj,jpt)+1.e20
349lwr=fltarr(jpi,jpj,jpt)+1.e20
350lat=fltarr(jpi,jpj,jpt)+1.e20
351sen=fltarr(jpi,jpj,jpt)+1.e20
352lwnet_clrk=fltarr(jpi,jpj,jpt)+1.e20
353;Ch=fltarr(jpi,jpj,jpt)+1.e20
354;Ce=fltarr(jpi,jpj,jpt)+1.e20
355junk=fltarr(jpi,jpj,jpt)+1.e20
356
357for jt=0,jpt-1 do begin
358  jday=time(jt)-julday(1,1,yea(jt))
359  print, 'Computing Fluxes ',jt,' / ',jpt-1
360;
361;  P=msl(*,*,jt) & P=P(ocean)
362  wn=w(*,*,jt) & wn=wn(ocean)          ; wind speed (m/s)
363  ts=sst(*,*,jt) & ts=ts(ocean)        ; Bulk sst (°C)
364  t=t2m(*,*,jt) & t=t(ocean)           ; 2m Air T (°C)
365  qs=qsee(ts,P)                        ; Sea surface sat. spec. humidity (g/kg)
366  q=q2m(*,*,jt) & q=q(ocean)           ; 2m AIr specific humidity  (g/kg)
367  Rs=swd(*,*,jt) & Rs=Rs(ocean)        ; Downward solar flux (W/m2)
368  ylat=gphit(ocean)
369;  cld=calc_cloud(jday,Rs,ylat)
370  cld=calc_cloud_vlat(jday,Rs,ylat)
371;  Rl=lwdown_clark(ts,q,cld,t,P)        ; Downward IR flux (W/m2)
372  Rl=lw(*,*,jt) & Rl=Rl(ocean)
373  rain=0.
374  lw_clrk=-lwnet_clark(ts,q,cld,t,P)
375;  junk(*,*,jt)=lw_clrk
376;
377;stop
378  y=cor30a(wn,us,ts,t,Qs,Q,Rs,Rl,rain,zi,P,zu,zt,zq,ylat,jcool,jwave,twave,hwave)
379;
380
381; A few punctual missing values (coare does not converge): filled by spatial extrapolation
382  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,0)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & swr(*,*,jt)=tab*msk+valmask*(1-msk)
383  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,1)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & lwr(*,*,jt)=tab*msk+valmask*(1-msk)
384  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,2)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & lat(*,*,jt)=tab*msk+valmask*(1-msk)
385  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,3)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & sen(*,*,jt)=tab*msk+valmask*(1-msk)
386;  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(lw_clrk) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & lwnet_clrk(*,*,jt)=tab*msk+valmask*(1-msk)
387;  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,6)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & Ch(*,*,jt)=tab*msk+valmask*(1-msk)
388;  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,7)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & Ce(*,*,jt)=tab*msk+valmask*(1-msk)
389endfor
390tt=time
391time=timegen(7670, start=julday(1,1,1989,0), units='days') & jpt=n_elements(time)
392;
393cda0=string(jul2date(time(0)),format='(i8.8)')
394cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
395tt=time-julday(1,1,1950,00,00,00)
396xlon=reform(glamt(*,0) ) & ylat=reform(gphit(0,*))
397
398ncfile='!${PROJECT_OD}/TropFlux_19890101_20091231.nc'
399lon_attr={units:'degrees_east',long_name:'Longitude'}
400lat_attr={units:'degrees_north',long_name:'Latitude'}
401swr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net shortwave radiation',short_name:'swr',axis:'TYX'}
402lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation',short_name:'lwr',axis:'TYX'}
403lwr_clrk_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation from clark',short_name:'lwr',axis:'TYX'}
404lhf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface latent flux',short_name:'lhf',axis:'TYX'}
405shf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface sensible flux',short_name:'shf',axis:'TYX'}
406time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:' 1950-JAN-01 00:00:00'}
407Ch_attr={units:'',missing_value:valmask,long_name:'heat transfer coefficient at zt',short_name:'Ch',axis:'TYX'}
408Ce_attr={units:'',missing_value:valmask,long_name:'moisture transfer coefficient at zq',short_name:'Ce',axis:'TYX'}
409
410globattr={source:'Fluxes for the Global Tropical Ocean - TropFlux',timerange:cda0+' - '+cda1}
411
412help, swr,lwr,lat,sen,tt,xlon,ylat
413
414ncfields = 'swr[longitude,latitude,time]=swr:swr_attr; ' $
415;          +'lwr_coare[longitude,latitude,time]=lwr:lwr_attr; ' $
416          +'lwr[longitude,latitude,time]=lwnet_clrk:lwr_clrk_attr; ' $
417          +'lhf[longitude,latitude,time]=lat:lhf_attr; ' $
418          +'shf[longitude,latitude,time]=sen:shf_attr; ' $
419;          +'Ch[longitude,latitude,time]=Ch:Ch_attr; ' $
420;          +'Ce[longitude,latitude,time]=Ce:Ce_attr; ' $
421                      + 'longitude[]=xlon:lon_attr; ' $
422                      + 'latitude[]=ylat:lat_attr; ' $
423                      + 'tt[*time]=tt:time_attr ' $
424                      + ' @ globattr'
425
426@ncdf_quickwrite
427
428end
Note: See TracBrowser for help on using the repository browser.