source: trunk/src/read_basic_var.pro

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • Property svn:executable set to *
  • Property svn:keywords set to URL Id
File size: 4.7 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, $
42at, 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;;MET PARAMETERS
116fi=project_id_env+'met'+csite+'_dy.cdf'
117f=file_test(fi)
118wu=fltarr(jpt)+!values.f_nan
119wv=fltarr(jpt)+!values.f_nan
120ws=fltarr(jpt)+!values.f_nan
121ws_q=fltarr(jpt)+!values.f_nan
122at=fltarr(jpt)+!values.f_nan
123at_q=fltarr(jpt)+!values.f_nan
124rh=fltarr(jpt)+!values.f_nan
125rh_q=fltarr(jpt)+!values.f_nan
126sst=fltarr(jpt)+!values.f_nan
127sst_q=fltarr(jpt)+!values.f_nan
128
129if (f) then begin
130    tt0=time_lec(fi)
131    wu0=ncdf_lec(fi,var='WU_422')
132    wv0=ncdf_lec(fi,var='WV_423')
133    ws0=ncdf_lec(fi,var='WS_401')
134    ws_q0=ncdf_lec(fi,var='QWS_5401')
135    at0=ncdf_lec(fi,var='AT_21')
136    at_q0=ncdf_lec(fi,var='QAT_5021')
137    rh0=ncdf_lec(fi,var='RH_910')
138    rh_q0=ncdf_lec(fi,var='QRH_5910')
139    sst0=ncdf_lec(fi,var='T_25')
140    sst_q0=ncdf_lec(fi,var='QT_5025')
141    tt0=tt0-time(0)
142    ind=where((tt0 ge -1e-5) and (tt0 le jpt-1+1e-5))
143    if (ind(0) ne -1) then begin
144        wu(tt0(ind))=wu0(ind)
145        wv(tt0(ind))=wv0(ind)
146        ws(tt0(ind))=ws0(ind)
147        ws_q(tt0(ind))=ws_q0(ind)
148        at(tt0(ind))=at0(ind)
149        at_q(tt0(ind))=at_q0(ind)
150        rh(tt0(ind))=rh0(ind)
151        rh_q(tt0(ind))=rh_q0(ind)
152        sst(tt0(ind))=sst0(ind)
153        sst_q(tt0(ind))=sst_q0(ind)
154    endif
155endif
156
157ind_at=where(at_q ne 1 and at_q ne 2)   &  ind_ws=where(ws_q ne 1 and ws_q ne 2)
158ind_rh=where(rh_q ne 1 and rh_q ne 2)   &  ind_sst=where(sst_q ne 1 and sst_q ne 2)
159ind_lh=where(lh_q ne 1 and lh_q ne 2)
160
161ind=union(ind_at, union(ind_rh, union(ind_ws, union(ind_lh, ind_sst))))
162
163if (ind(0) ne -1) then begin
164    sw(ind)=!Values.f_nan   &   at(ind)=!Values.f_nan
165    rh(ind)=!Values.f_nan   &   ws(ind)=!Values.f_nan
166    sst(ind)=!Values.f_nan  &   lh(ind)=!Values.f_nan
167    wu(ind)=!Values.f_nan  &    wv(ind)=!Values.f_nan
168endif
169;
170;; Replace missing values by "NaN"
171;
172tsvars=['at','sw','rh','sst','wu','wv','ws','lat','lon']
173vars=[tsvars]
174nn=n_elements(vars)
175for n=0,nn-1 do begin
176    var=vars(n)
177    com='ind=where('+var+' ge 1.e20) & if (ind(0) ne -1) then '+var+'(ind)=!values.f_nan'
178    r=execute(com)
179endfor
180
181nsmooth=nsmooth
182at=smooth(at,nsmooth,/nan) & sst=smooth(sst,nsmooth,/nan)
183lh=smooth(lh,nsmooth,/nan) & rh=smooth(rh,nsmooth,/nan)
184wu=smooth(wu,nsmooth,/nan) & wv=smooth(wv,nsmooth,/nan)
185ws=smooth(ws,nsmooth,/nan) & sw=smooth(sw,nsmooth,/nan)
186
187end
188
189function time_lec, fi
190tt=ncdf_lec(fi,var='time')
191fid=ncdf_open(fi) & vid=ncdf_varid(fid,'time')
192ncdf_attget, fid,vid,'units',orig
193orig=string(orig)
194yy=long(strmid(orig,11,4))
195mm=long(strmid(orig,16,2))
196dd=long(strmid(orig,19,2))
197tt=julday(mm,dd,yy,12,00)+tt
198return, tt
199end
Note: See TracBrowser for help on using the repository browser.