source: trunk/src/paper01/fig3/read_variables_v2.pro @ 70

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

replace TROPFLUX by PROJECT

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1;+
2;
3; .. _read_variables_v2.pro:
4;
5; =====================
6; read_variables_v2.pro
7; =====================
8;
9; DESCRIPTION
10; ===========
11;
12; .. graphviz::
13;
14;    digraph read_variables_v2 {
15;       graph [
16;       rankdir="LR",
17;       ]
18;       rad [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/rad*_dy.cdf"];
19;       qlat[shape=ellipse,fontname=Courier,label="${PROJECT_ID}/qlat*_dy.cdf"];
20;       pos[shape=ellipse,fontname=Courier,label="${PROJECT_ID}/pos*_dy.cdf"];
21;       met[shape=ellipse,fontname=Courier,label="${PROJECT_ID}/met*_dy.cdf"];
22;
23;       at [shape=tab,fontname=Courier,label="at"]
24;       sw [shape=tab,fontname=Courier,label="sw"]
25;       rh [shape=tab,fontname=Courier,label="rh"]
26;       sst [shape=tab,fontname=Courier,label="sst"]
27;       wu [shape=tab,fontname=Courier,label="wu"]
28;       wv [shape=tab,fontname=Courier,label="wv"]
29;       ws [shape=tab,fontname=Courier,label="ws"]
30;       lh [shape=tab,fontname=Courier,label="lh"]
31;
32;       read_variables_v2 [shape=box,
33;       fontname=Courier,
34;       color=blue,
35;       URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/paper01/fig2/read_variables_v2.pro",
36;       label="${TROPFLUX}/src/paper01/fig2/read_variables_v2.pro"];
37;
38;       {qlat rad pos met} -> {read_variables_v2} -> {at sw rh sst wu wv ws lh}
39;    }
40;
41; SEE ALSO
42; ========
43;
44; :ref:`project_profile.sh`
45;
46; :ref:`air_validation_scatter_2000_2009_v50.pro`
47; :ref:`q2m_validation_scatter_2000_2009_v50.pro`
48; :ref:`sst_validation_scatter_2000_2009_v50.pro`
49; :ref:`ws_validation_scatter_2000_2009_v50.pro`
50; :ref:`air_validation_scatter_2000_2009_basin.pro`
51; :ref:`q2m_validation_scatter_2000_2009_basin.pro`
52; :ref:`sst_validation_scatter_2000_2009_basin.pro`
53; :ref:`ws_validation_scatter_2000_2009_basin.pro`
54; :ref:`lhf_validation_scatter_2000_2009.pro`
55; :ref:`shf_validation_scatter_2000_2009.pro`
56;
57; EXAMPLES
58; ========
59;
60; ::
61;
62;  IDL> csite=++
63;  IDL> ++
64;  IDL> read_variables_v2, csite, date1, date2, nsmooth, at, sw, rh, sst, wu, wv, ws, lh
65;
66; TODO
67; ====
68;
69; externalize function
70;
71; make it work (missing data)
72;
73; EVOLUTIONS
74; ==========
75;
76; $Id$
77;
78; - fplod 20110412T110534Z aedon.locean-ipsl.upmc.fr (Darwin)
79;
80;   * remove hard coding path
81;   * add graphviz
82;
83; - fplod 20110411T142955Z aedon.locean-ipsl.upmc.fr (Darwin)
84;
85;   * minimal header
86;
87;-
88pro read_variables_v2, csite, date1, date2, nsmooth, $
89                     at, sw, rh, sst, wu, wv, ws, lh
90@cm_project
91;
92;; DEFINE THE OUTPUT TIME AXIS
93;
94jda1=date2jul(date1)
95jda2=date2jul(date2)
96jpt=(jda2-jda1+1l)
97time=jda1+dindgen(jpt)
98
99;
100;; FIRST READ ALL DATA FROM SITE
101;;   - if file exists, extract correct time axis
102;;   - if not, fill variable with missing values
103;
104;;SHORTWAVE
105fi=project_id_env+'rad'+csite+'_dy.cdf'
106f=file_test(fi)
107sw=fltarr(jpt)+!values.f_nan
108sw_q=fltarr(jpt)+!values.f_nan
109;tt=fltarr(jpt)+!values.f_nan
110if (f) then begin
111  tt0=time_lec(fi)
112  sw0=ncdf_lec(fi,var='RD_495')
113  sw_q0=ncdf_lec(fi,var='QSW_5495')
114  tt0=tt0-time(0)
115  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
116  if (ind(0) ne -1) then begin
117     sw(tt0(ind))=sw0(ind)
118     sw_q(tt0(ind))=sw_q0(ind)
119  endif
120endif else begin
121  print, fi, ' not found'
122endelse
123
124ind_sw=where(sw_q ne 1. and sw_q ne 2.)
125
126;;LHF
127fi=project_id_env+'qlat'+csite+'_dy.cdf'
128f=file_test(fi)
129lh=fltarr(jpt)+!values.f_nan
130lh_q=fltarr(jpt)+!values.f_nan
131if (f) then begin
132  tt0=time_lec(fi)
133  lh0=ncdf_lec(fi,var='QL_137')
134  lh_q0=ncdf_lec(fi,var='QQL_5137')
135  tt0=tt0-time(0)
136  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
137  if (ind(0) ne -1) then begin
138     lh(tt0(ind))=lh0(ind)
139     lh_q(tt0(ind))=lh_q0(ind)
140  endif
141endif else begin
142  print, fi, ' not found'
143endelse
144
145;;POSITION
146fi=project_id_env+'pos'+csite+'_dy.cdf'
147f=file_test(fi)
148lat=fltarr(jpt)+!values.f_nan
149lon=fltarr(jpt)+!values.f_nan
150if (f) then begin
151  tt0=time_lec(fi)
152  lat0=ncdf_lec(fi,var='LAT_500')
153  lon0=ncdf_lec(fi,var='LON_502')
154  tt0=tt0-time(0)
155  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
156  if (ind(0) ne -1) then begin
157    lat(tt0(ind))=lat0(ind)
158    lon(tt0(ind))=lon0(ind)
159  endif
160endif else begin
161  print, fi, ' not found'
162endelse
163
164
165;;MET PARAMETERS
166fi=project_id_env+'met'+csite+'_dy.cdf'
167f=file_test(fi)
168wu=fltarr(jpt)+!values.f_nan
169wv=fltarr(jpt)+!values.f_nan
170ws=fltarr(jpt)+!values.f_nan
171ws_q=fltarr(jpt)+!values.f_nan
172at=fltarr(jpt)+!values.f_nan
173at_q=fltarr(jpt)+!values.f_nan
174rh=fltarr(jpt)+!values.f_nan
175rh_q=fltarr(jpt)+!values.f_nan
176sst=fltarr(jpt)+!values.f_nan
177sst_q=fltarr(jpt)+!values.f_nan
178
179if (f) then begin
180  tt0=time_lec(fi)
181  wu0=ncdf_lec(fi,var='WU_422')
182  wv0=ncdf_lec(fi,var='WV_423')
183  ws0=ncdf_lec(fi,var='WS_401')
184  ws_q0=ncdf_lec(fi,var='QWS_5401')
185  at0=ncdf_lec(fi,var='AT_21')
186  at_q0=ncdf_lec(fi,var='QAT_5021')
187  rh0=ncdf_lec(fi,var='RH_910')
188  rh_q0=ncdf_lec(fi,var='QRH_5910')
189  sst0=ncdf_lec(fi,var='T_25')
190  sst_q0=ncdf_lec(fi,var='QT_5025')
191  tt0=tt0-time(0)
192  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
193  if (ind(0) ne -1) then begin
194    wu(tt0(ind))=wu0(ind)
195    wv(tt0(ind))=wv0(ind)
196    ws(tt0(ind))=ws0(ind)
197    ws_q(tt0(ind))=ws_q0(ind)
198    at(tt0(ind))=at0(ind)
199    at_q(tt0(ind))=at_q0(ind)
200    rh(tt0(ind))=rh0(ind)
201    rh_q(tt0(ind))=rh_q0(ind)
202    sst(tt0(ind))=sst0(ind)
203    sst_q(tt0(ind))=sst_q0(ind)
204  endif
205endif else begin
206  print, fi, ' not found'
207endelse
208
209ind_at=where(at_q ne 1 and at_q ne 2)   &  ind_ws=where(ws_q ne 1 and ws_q ne 2)
210ind_rh=where(rh_q ne 1 and rh_q ne 2)   &  ind_sst=where(sst_q ne 1 and sst_q ne 2)
211ind_lh=where(lh_q ne 1 and lh_q ne 2)
212
213ind=union(ind_at, union(ind_rh, union(ind_ws, union(ind_lh, ind_sst))))
214
215if (ind(0) ne -1) then begin
216  sw(ind)=!Values.f_nan   &   at(ind)=!Values.f_nan
217  rh(ind)=!Values.f_nan   &   ws(ind)=!Values.f_nan
218  sst(ind)=!Values.f_nan  &   lh(ind)=!Values.f_nan
219  wu(ind)=!Values.f_nan  &    wv(ind)=!Values.f_nan
220endif
221;
222;; Replace missing values by "NaN"
223;
224tsvars=['at','sw','rh','sst','wu','wv','ws','lat','lon']
225vars=[tsvars]
226nn=n_elements(vars)
227for n=0,nn-1 do begin
228  var=vars(n)
229  com='ind=where('+var+' ge 1.e20) & if (ind(0) ne -1) then '+var+'(ind)=!values.f_nan'
230  r=execute(com)
231endfor
232
233nsmooth=nsmooth
234at=smooth(at,nsmooth,/nan) & sst=smooth(sst,nsmooth,/nan)
235lh=smooth(lh,nsmooth,/nan) & rh=smooth(rh,nsmooth,/nan)
236wu=smooth(wu,nsmooth,/nan) & wv=smooth(wv,nsmooth,/nan)
237ws=smooth(ws,nsmooth,/nan) & sw=smooth(sw,nsmooth,/nan)
238
239end
240
241
242function time_lec, fi
243tt=ncdf_lec(fi,var='time')
244fid=ncdf_open(fi) & vid=ncdf_varid(fid,'time')
245ncdf_attget, fid,vid,'units',orig
246orig=string(orig)
247yy=long(strmid(orig,11,4))
248mm=long(strmid(orig,16,2))
249dd=long(strmid(orig,19,2))
250tt=julday(mm,dd,yy,12,00)+tt
251return, tt
252end
Note: See TracBrowser for help on using the repository browser.