1 | ;+ |
---|
2 | ; |
---|
3 | ; .. _lwr_correction_ncdf.pro: |
---|
4 | ; |
---|
5 | ; ======================= |
---|
6 | ; lwr_correction_ncdf.pro |
---|
7 | ; ======================= |
---|
8 | ; |
---|
9 | ; Correction of lwr on OAFLUX grid |
---|
10 | ; |
---|
11 | ; :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` have been |
---|
12 | ; produced by :ref:`interp_erai_lwr_1989_2009.pro`. |
---|
13 | ; |
---|
14 | ; Corrected lwr on OAFLUX grid is written in |
---|
15 | ; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc` |
---|
16 | ; if this file not already exists. |
---|
17 | ; |
---|
18 | ; This file will be used by :ref:`TropFlux_19890101_20091231.pro`. |
---|
19 | ; |
---|
20 | ; .. graphviz:: |
---|
21 | ; |
---|
22 | ; digraph lwr_correction_ncdf { |
---|
23 | ; graph [ |
---|
24 | ; rankdir="LR", |
---|
25 | ; ] |
---|
26 | ; |
---|
27 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc"]; |
---|
28 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc"]; |
---|
29 | ; |
---|
30 | ; lwr_correction_ncdf [shape=box, |
---|
31 | ; fontname=Courier, |
---|
32 | ; color=blue, |
---|
33 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/lwr_correction_ncdf.pro", |
---|
34 | ; label="${PROJECT}/src/lwr_correction_ncdf.pro"]; |
---|
35 | ; |
---|
36 | ; {file_in} -> {lwr_correction_ncdf} -> {file_out} |
---|
37 | ; |
---|
38 | ; } |
---|
39 | ; |
---|
40 | ; SEE ALSO |
---|
41 | ; ======== |
---|
42 | ; |
---|
43 | ; :ref:`project_profile.sh` |
---|
44 | ; |
---|
45 | ; :ref:`mooring_corrections` |
---|
46 | ; |
---|
47 | ; :ref:`interp_erai_lwr_1989_2009.pro` |
---|
48 | ; |
---|
49 | ; :func:`initncdf <saxo:initncdf>` |
---|
50 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
51 | ; :func:`grossemoyenne <saxo:grossemoyenne>` |
---|
52 | ; :func:`julday <saxo:julday>` |
---|
53 | ; :func:`caldat <saxo:caldat>` |
---|
54 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
55 | ; |
---|
56 | ; EXAMPLES |
---|
57 | ; ======== |
---|
58 | ; |
---|
59 | ; :: |
---|
60 | ; |
---|
61 | ; IDL> lwr_correction_ncdf |
---|
62 | ; |
---|
63 | ; TODO |
---|
64 | ; ==== |
---|
65 | ; |
---|
66 | ; coding rules |
---|
67 | ; |
---|
68 | ; lwr long name 'Air Temperature at 2m" : ??? |
---|
69 | ; |
---|
70 | ; 19890101 is not provided in ERA-Intermim file str : a possible workaround is |
---|
71 | ; to copy 19890102 |
---|
72 | ; dataset to 19890101 using nco before processing. |
---|
73 | ; |
---|
74 | ; here is the sequence used by pk wher erai_lwr_19890102_20091231_oafluxgrid.nc is the regridded (interpolated output) |
---|
75 | ; |
---|
76 | ; $ ncks -d time,0,0 erai_lwr_19890102_20091231_oafluxgrid.nc erai_lwr_step0.nc |
---|
77 | ; |
---|
78 | ; This will combine the two files :: |
---|
79 | ; |
---|
80 | ; $ ncrcat erai_lwr_step0.nc erai_lwr_19890102_20091231_oafluxgrid.nc erai_lwr_19890101_20091231_oafluxgrid.nc. |
---|
81 | ; |
---|
82 | ; must be put in a shell script or find IDL equivalent |
---|
83 | ; |
---|
84 | ; here I (fp) replace hard coded date 19890102 by 19890101. must check |
---|
85 | ; consistency with this module and interp_erai_lwr_1989_2009.pro. |
---|
86 | ; |
---|
87 | ; KNOWN ISSUES |
---|
88 | ; ============ |
---|
89 | ; |
---|
90 | ; test of existence of fullfilename_in not very efficient because |
---|
91 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
92 | ; |
---|
93 | ; EVOLUTIONS |
---|
94 | ; ========== |
---|
95 | ; |
---|
96 | ; - fplod 20110808T120234Z cratos (Linux) |
---|
97 | ; |
---|
98 | ; * usage of ${PROJECT_OD} |
---|
99 | ; * complete description |
---|
100 | ; * replace erai_lwr_19890102_20091231_oafluxgrid.nc by erai_lwr_19890101_20091231 |
---|
101 | ; * remove v1 in output filename |
---|
102 | ; |
---|
103 | ; - fplod 20101215T113707Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
104 | ; |
---|
105 | ; * add graph in header |
---|
106 | ; |
---|
107 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
108 | ; |
---|
109 | ; * minimal header |
---|
110 | ; |
---|
111 | ; - pbk 2008 |
---|
112 | ; |
---|
113 | ; * creation |
---|
114 | ; |
---|
115 | ;- |
---|
116 | pro lwr_correction_ncdf |
---|
117 | ; |
---|
118 | @cm_4cal |
---|
119 | @cm_4data |
---|
120 | @cm_4mesh |
---|
121 | @cm_4data |
---|
122 | @cm_project |
---|
123 | ; |
---|
124 | ; test if ${PROJECT_OD} defined |
---|
125 | CASE project_od_env OF |
---|
126 | '' : BEGIN |
---|
127 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
128 | ras = report(msg) |
---|
129 | STOP |
---|
130 | END |
---|
131 | ELSE: BEGIN |
---|
132 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
133 | ras = report(msg) |
---|
134 | END |
---|
135 | ENDCASE |
---|
136 | ; |
---|
137 | ; check if output data will be possible |
---|
138 | iodirout = isadirectory(project_od_env) |
---|
139 | ; |
---|
140 | ; existence and protection for reading |
---|
141 | IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
142 | msg = 'eee : the directory' + iodirout + ' is not accessible.' |
---|
143 | ras = report(msg) |
---|
144 | STOP |
---|
145 | ENDIF |
---|
146 | ; |
---|
147 | ; existence and protection for writing |
---|
148 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
149 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
150 | ras = report(msg) |
---|
151 | STOP |
---|
152 | ENDIF |
---|
153 | ; |
---|
154 | da1=19880101 & da2=20091231 |
---|
155 | ; |
---|
156 | ; build data filename |
---|
157 | filename='erai_lwr_19890101_20091231_oafluxgrid.nc' |
---|
158 | ; |
---|
159 | ; check if this file exists |
---|
160 | fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST) |
---|
161 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
162 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
163 | ras = report(msg) |
---|
164 | STOP |
---|
165 | ENDIF |
---|
166 | ; |
---|
167 | ; build output filename |
---|
168 | filename_out = 'TropFlux_lwr_19890101_20091231.nc' |
---|
169 | fullfilename_out = iodirout + filename_out |
---|
170 | ; in order to avoid unexpected overwritten |
---|
171 | IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN |
---|
172 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
173 | ras = report(msg) |
---|
174 | STOP |
---|
175 | ENDIF |
---|
176 | ; |
---|
177 | initncdf, fullfilename |
---|
178 | lwr=read_ncdf('lwr',da1,da2,file=fullfilename,/nostr) |
---|
179 | help, lwr |
---|
180 | ; |
---|
181 | lwr_mean=grossemoyenne(lwr,'t',/nan) |
---|
182 | help,lwr_mean |
---|
183 | |
---|
184 | tt=time & jpt=n_elements(time) |
---|
185 | caldat, time,mon,day,yea |
---|
186 | lwr_m=lwr*0. |
---|
187 | |
---|
188 | for jt=0,jpt-1 do begin |
---|
189 | jtt=(time(jt)-julday(1,1,yea(jt))) < 364 |
---|
190 | t=reform(lwr_mean(*,*)) |
---|
191 | lwr_m(*,*,jt)=t |
---|
192 | endfor |
---|
193 | help, lwr_m |
---|
194 | |
---|
195 | lwr_ano=lwr-lwr_m |
---|
196 | |
---|
197 | ;; correction for mean based on scatter |
---|
198 | lwr_m=lwr_m+4.61667 |
---|
199 | |
---|
200 | help, lwr_ano |
---|
201 | |
---|
202 | ;; applying the correction for varyability based on the scatter |
---|
203 | lwr_ano=lwr_ano*(1/0.760667) |
---|
204 | |
---|
205 | ;; applying the correction for varyability based on the scatter |
---|
206 | |
---|
207 | lwr_new=lwr_m+lwr_ano |
---|
208 | help, lwr_new |
---|
209 | |
---|
210 | ;writing field |
---|
211 | lat=reform(gphit(0,0:jpj-1)) |
---|
212 | lon=reform(glamt(0:jpi-1,0)) |
---|
213 | time=timegen(7669, units='days', start=julday(1,2,1989)) & jpt=n_elements(time) |
---|
214 | |
---|
215 | cda0=string(jul2date(time(0)),format='(i8.8)') |
---|
216 | cda1=string(jul2date(time(jpt-1)),format='(i8.8)') |
---|
217 | |
---|
218 | time=time-julday(1,1,1950) & jpt=n_elements(time) |
---|
219 | |
---|
220 | ncfile='!' + fullfilename_out |
---|
221 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
222 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
223 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
224 | lwr_attr={units:'degK',missing_value:1.e20,long_name:'Air Temperature at 2m',short_name:'lwr',axis:'TYX'} |
---|
225 | globattr={source:'Basic data obtained from ERAI. Mean correction for bias and correction for variability are applied',timerange:cda0+' - '+cda1} |
---|
226 | |
---|
227 | ncfields = 'lwr[longitude,latitude,time]=lwr_new:lwr_attr; ' $ |
---|
228 | + 'longitude[]=lon:lon_attr; ' $ |
---|
229 | + 'latitude[]=lat:lat_attr; ' $ |
---|
230 | + 'time[*time]=time:time_attr ' $ |
---|
231 | + ' @ globattr' |
---|
232 | |
---|
233 | @ncdf_quickwrite |
---|
234 | |
---|
235 | end |
---|