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 | ;- |
---|
41 | pro 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 | ; |
---|
49 | jda1=date2jul(date1) |
---|
50 | jda2=date2jul(date2) |
---|
51 | jpt=(jda2-jda1+1l) |
---|
52 | time=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 |
---|
62 | fi=project_id_env+'rad'+csite+'_dy.cdf' |
---|
63 | f=file_test(fi) |
---|
64 | sw=fltarr(jpt)+!values.f_nan |
---|
65 | sw_q=fltarr(jpt)+!values.f_nan |
---|
66 | ;tt=fltarr(jpt)+!values.f_nan |
---|
67 | if (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 |
---|
77 | endif |
---|
78 | |
---|
79 | ind_sw=where(sw_q ne 1. and sw_q ne 2.) |
---|
80 | |
---|
81 | ;;LHF |
---|
82 | fi=project_id_env+'qlat'+csite+'_dy.cdf' |
---|
83 | f=file_test(fi) |
---|
84 | lh=fltarr(jpt)+!values.f_nan |
---|
85 | lh_q=fltarr(jpt)+!values.f_nan |
---|
86 | if (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 |
---|
96 | endif |
---|
97 | |
---|
98 | ;;POSITION |
---|
99 | fi=project_id_env+'pos'+csite+'_dy.cdf' |
---|
100 | f=file_test(fi) |
---|
101 | lat=fltarr(jpt)+!values.f_nan |
---|
102 | lon=fltarr(jpt)+!values.f_nan |
---|
103 | if (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 |
---|
113 | endif |
---|
114 | |
---|
115 | ;;MET PARAMETERS |
---|
116 | fi=project_id_env+'met'+csite+'_dy.cdf' |
---|
117 | f=file_test(fi) |
---|
118 | wu=fltarr(jpt)+!values.f_nan |
---|
119 | wv=fltarr(jpt)+!values.f_nan |
---|
120 | ws=fltarr(jpt)+!values.f_nan |
---|
121 | ws_q=fltarr(jpt)+!values.f_nan |
---|
122 | at=fltarr(jpt)+!values.f_nan |
---|
123 | at_q=fltarr(jpt)+!values.f_nan |
---|
124 | rh=fltarr(jpt)+!values.f_nan |
---|
125 | rh_q=fltarr(jpt)+!values.f_nan |
---|
126 | sst=fltarr(jpt)+!values.f_nan |
---|
127 | sst_q=fltarr(jpt)+!values.f_nan |
---|
128 | |
---|
129 | if (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 |
---|
155 | endif |
---|
156 | |
---|
157 | ind_at=where(at_q ne 1 and at_q ne 2) & ind_ws=where(ws_q ne 1 and ws_q ne 2) |
---|
158 | ind_rh=where(rh_q ne 1 and rh_q ne 2) & ind_sst=where(sst_q ne 1 and sst_q ne 2) |
---|
159 | ind_lh=where(lh_q ne 1 and lh_q ne 2) |
---|
160 | |
---|
161 | ind=union(ind_at, union(ind_rh, union(ind_ws, union(ind_lh, ind_sst)))) |
---|
162 | |
---|
163 | if (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 |
---|
168 | endif |
---|
169 | ; |
---|
170 | ;; Replace missing values by "NaN" |
---|
171 | ; |
---|
172 | tsvars=['at','sw','rh','sst','wu','wv','ws','lat','lon'] |
---|
173 | vars=[tsvars] |
---|
174 | nn=n_elements(vars) |
---|
175 | for 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) |
---|
179 | endfor |
---|
180 | |
---|
181 | nsmooth=nsmooth |
---|
182 | at=smooth(at,nsmooth,/nan) & sst=smooth(sst,nsmooth,/nan) |
---|
183 | lh=smooth(lh,nsmooth,/nan) & rh=smooth(rh,nsmooth,/nan) |
---|
184 | wu=smooth(wu,nsmooth,/nan) & wv=smooth(wv,nsmooth,/nan) |
---|
185 | ws=smooth(ws,nsmooth,/nan) & sw=smooth(sw,nsmooth,/nan) |
---|
186 | |
---|
187 | end |
---|
188 | |
---|
189 | function time_lec, fi |
---|
190 | tt=ncdf_lec(fi,var='time') |
---|
191 | fid=ncdf_open(fi) & vid=ncdf_varid(fid,'time') |
---|
192 | ncdf_attget, fid,vid,'units',orig |
---|
193 | orig=string(orig) |
---|
194 | yy=long(strmid(orig,11,4)) |
---|
195 | mm=long(strmid(orig,16,2)) |
---|
196 | dd=long(strmid(orig,19,2)) |
---|
197 | tt=julday(mm,dd,yy,12,00)+tt |
---|
198 | return, tt |
---|
199 | end |
---|