source: trunk/src/read_basic_var.pro @ 152

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

first diag on pkb tools for timeseries

  • Property svn:executable set to *
  • Property svn:keywords set to URL Id
File size: 4.5 KB
Line 
1;+
2;
3; .. _read_basic_var.pro:
4;
5; ==================
6; read_basic_var.pro
7; ==================
8;
9; DESCRIPTION
10; ===========
11;
12; SEE ALSO
13; ========
14;
15; :ref:`project_profile.sh`
16;
17; called by :ref:`basic_variable_evaluation_tpr_timeseries.pro`
18;
19; TODO
20; ====
21;
22; supprimer ./paper01/fig3/read_basic_var.pro
23; car ce module a l'air d'être le même
24;
25; make it work
26;
27; coding rules
28;
29; EVOLUTIONS
30; ==========
31;
32; $Id$
33;
34; $URL$
35;
36; - fplod 20111130T133857Z cratos (Linux)
37;
38;   * try to make it work on my account on cratos
39;
40;-
41pro read_basic_var, csite,date1,date2,nsmooth, $
42                     at, rh, sst, wu, wv, ws
43
44@common
45@cm_project
46
47;; DEFINE THE OUTPUT TIME AXIS
48;
49jda1=date2jul(date1)
50jda2=date2jul(date2)
51jpt=(jda2-jda1+1l)
52time=jda1+dindgen(jpt)
53
54;
55;; FIRST READ ALL DATA FROM SITE
56;;   - if file exists, extract correct time axis
57;;   - if not, fill variable with missing values
58;
59
60
61;;SHORTWAVE
62fi=project_id_env+'rad'+csite+'_dy.cdf'
63f=file_test(fi)
64sw=fltarr(jpt)+!values.f_nan
65sw_q=fltarr(jpt)+!values.f_nan
66;tt=fltarr(jpt)+!values.f_nan
67if (f) then begin
68  tt0=time_lec(fi)
69  sw0=ncdf_lec(fi,var='RD_495')
70  sw_q0=ncdf_lec(fi,var='QSW_5495')
71  tt0=tt0-time(0)
72  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
73  if (ind(0) ne -1) then begin
74  sw(tt0(ind))=sw0(ind)
75  sw_q(tt0(ind))=sw_q0(ind)
76  endif
77endif
78
79ind_sw=where(sw_q ne 1. and sw_q ne 2.)
80
81;;LHF
82fi=project_id_env+'qlat'+csite+'_dy.cdf'
83f=file_test(fi)
84lh=fltarr(jpt)+!values.f_nan
85lh_q=fltarr(jpt)+!values.f_nan
86if (f) then begin
87  tt0=time_lec(fi)
88  lh0=ncdf_lec(fi,var='QL_137')
89  lh_q0=ncdf_lec(fi,var='QQL_5137')
90  tt0=tt0-time(0)
91  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
92  if (ind(0) ne -1) then begin
93  lh(tt0(ind))=lh0(ind)
94  lh_q(tt0(ind))=lh_q0(ind)
95  endif
96endif
97
98;;POSITION
99fi=project_id_env+'pos'+csite+'_dy.cdf'
100f=file_test(fi)
101lat=fltarr(jpt)+!values.f_nan
102lon=fltarr(jpt)+!values.f_nan
103if (f) then begin
104  tt0=time_lec(fi)
105  lat0=ncdf_lec(fi,var='LAT_500')
106  lon0=ncdf_lec(fi,var='LON_502')
107  tt0=tt0-time(0)
108  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
109  if (ind(0) ne -1) then begin
110    lat(tt0(ind))=lat0(ind)
111    lon(tt0(ind))=lon0(ind)
112  endif
113endif
114
115
116;;MET PARAMETERS
117fi=project_id_env+'met'+csite+'_dy.cdf'
118f=file_test(fi)
119wu=fltarr(jpt)+!values.f_nan
120wv=fltarr(jpt)+!values.f_nan
121ws=fltarr(jpt)+!values.f_nan
122ws_q=fltarr(jpt)+!values.f_nan
123at=fltarr(jpt)+!values.f_nan
124at_q=fltarr(jpt)+!values.f_nan
125rh=fltarr(jpt)+!values.f_nan
126rh_q=fltarr(jpt)+!values.f_nan
127sst=fltarr(jpt)+!values.f_nan
128sst_q=fltarr(jpt)+!values.f_nan
129
130if (f) then begin
131  tt0=time_lec(fi)
132  wu0=ncdf_lec(fi,var='WU_422')
133  wv0=ncdf_lec(fi,var='WV_423')
134  ws0=ncdf_lec(fi,var='WS_401')
135  ws_q0=ncdf_lec(fi,var='QWS_5401')
136  at0=ncdf_lec(fi,var='AT_21')
137  at_q0=ncdf_lec(fi,var='QAT_5021')
138  rh0=ncdf_lec(fi,var='RH_910')
139  rh_q0=ncdf_lec(fi,var='QRH_5910')
140  sst0=ncdf_lec(fi,var='T_25')
141  sst_q0=ncdf_lec(fi,var='QT_5025')
142  tt0=tt0-time(0)
143  ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
144  if (ind(0) ne -1) then begin
145    wu(tt0(ind))=wu0(ind)
146    wv(tt0(ind))=wv0(ind)
147    ws(tt0(ind))=ws0(ind)
148    ws_q(tt0(ind))=ws_q0(ind)
149    at(tt0(ind))=at0(ind)
150    at_q(tt0(ind))=at_q0(ind)
151    rh(tt0(ind))=rh0(ind)
152    rh_q(tt0(ind))=rh_q0(ind)
153    sst(tt0(ind))=sst0(ind)
154    sst_q(tt0(ind))=sst_q0(ind)
155  endif
156endif
157
158ind_at=where(at_q ne 1 and at_q ne 2)   &  ind_ws=where(ws_q ne 1 and ws_q ne 2)
159ind_rh=where(rh_q ne 1 and rh_q ne 2)   &  ind_sst=where(sst_q ne 1 and sst_q ne 2)
160ind_lh=where(lh_q ne 1 and lh_q ne 2)
161
162ind=union(ind_at, union(ind_rh, union(ind_ws, union(ind_lh, ind_sst))))
163
164if (ind(0) ne -1) then begin
165  sw(ind)=!Values.f_nan   &   at(ind)=!Values.f_nan
166  rh(ind)=!Values.f_nan   &   ws(ind)=!Values.f_nan
167  sst(ind)=!Values.f_nan  &   lh(ind)=!Values.f_nan
168  wu(ind)=!Values.f_nan  &    wv(ind)=!Values.f_nan
169endif
170;
171;; Replace missing values by "NaN"
172;
173tsvars=['at','sw','rh','sst','wu','wv','ws','lat','lon']
174vars=[tsvars]
175nn=n_elements(vars)
176for n=0,nn-1 do begin
177  var=vars(n)
178  com='ind=where('+var+' ge 1.e20) & if (ind(0) ne -1) then '+var+'(ind)=!values.f_nan'
179  r=execute(com)
180endfor
181
182nsmooth=nsmooth
183at=smooth(at,nsmooth,/nan) & sst=smooth(sst,nsmooth,/nan)
184lh=smooth(lh,nsmooth,/nan) & rh=smooth(rh,nsmooth,/nan)
185wu=smooth(wu,nsmooth,/nan) & wv=smooth(wv,nsmooth,/nan)
186ws=smooth(ws,nsmooth,/nan) & sw=smooth(sw,nsmooth,/nan)
187
188end
189
190function time_lec, fi
191tt=ncdf_lec(fi,var='time')
192fid=ncdf_open(fi) & vid=ncdf_varid(fid,'time')
193ncdf_attget, fid,vid,'units',orig
194orig=string(orig)
195yy=long(strmid(orig,11,4))
196mm=long(strmid(orig,16,2))
197dd=long(strmid(orig,19,2))
198tt=julday(mm,dd,yy,12,00)+tt
199return, tt
200end
Note: See TracBrowser for help on using the repository browser.