1 | ;+ |
---|
2 | ; |
---|
3 | ; ======================= |
---|
4 | ; sst_correction_ncdf.pro |
---|
5 | ; ======================= |
---|
6 | ; |
---|
7 | ; .. function:: sst_correction_ncdf(yyyymmddb,yyyymmdde) |
---|
8 | ; |
---|
9 | ; DESCRIPTION |
---|
10 | ; =========== |
---|
11 | ; |
---|
12 | ; Correction of sst on OAFLUX grid |
---|
13 | ; |
---|
14 | ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` |
---|
15 | ; containing |
---|
16 | ; ++ |
---|
17 | ; has been produced by |
---|
18 | ; :func:`interp_erai_sst`. |
---|
19 | ; |
---|
20 | ; Corrected sst on OAFLUX grid |
---|
21 | ; is written in |
---|
22 | ; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc` |
---|
23 | ; if this file not already exists. |
---|
24 | ; |
---|
25 | ; This output file |
---|
26 | ; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc` |
---|
27 | ; will be used by |
---|
28 | ; :func:`cronin_gustiness_ncdf` |
---|
29 | ; and |
---|
30 | ; :func:`tropflux`. |
---|
31 | ; |
---|
32 | ; This output file |
---|
33 | ; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc` |
---|
34 | ; is one of the deliverable of TropFlux. |
---|
35 | ; |
---|
36 | ; .. only:: man |
---|
37 | ; |
---|
38 | ; Figure is visible on PDF and HTML documents only. |
---|
39 | ; |
---|
40 | ; .. only:: html or latex |
---|
41 | ; |
---|
42 | ; .. graphviz:: |
---|
43 | ; |
---|
44 | ; digraph sst_correction_ncdf { |
---|
45 | ; |
---|
46 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; |
---|
47 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc"]; |
---|
48 | ; |
---|
49 | ; sst_correction_ncdf [shape=box, |
---|
50 | ; fontname=Courier, |
---|
51 | ; color=blue, |
---|
52 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/sst_correction_ncdf.pro", |
---|
53 | ; label="${PROJECT}/src/sst_correction_ncdf.pro"]; |
---|
54 | ; |
---|
55 | ; {file_in} -> {sst_correction_ncdf} -> {file_out} |
---|
56 | ; |
---|
57 | ; } |
---|
58 | ; |
---|
59 | ; SEE ALSO |
---|
60 | ; ======== |
---|
61 | ; |
---|
62 | ; :ref:`mooring_corrections` |
---|
63 | ; |
---|
64 | ; Used by :ref:`tropflux.sh` |
---|
65 | ; |
---|
66 | ; :ref:`project_profile.sh` |
---|
67 | ; |
---|
68 | ; :func:`interp_erai_sst` |
---|
69 | ; |
---|
70 | ; :func:`initncdf <saxo:initncdf>` |
---|
71 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
72 | ; :func:`grossemoyenne <saxo:grossemoyenne>` |
---|
73 | ; :func:`julday <saxo:julday>` |
---|
74 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
75 | ; |
---|
76 | ; EXAMPLES |
---|
77 | ; ======== |
---|
78 | ; |
---|
79 | ; :: |
---|
80 | ; |
---|
81 | ; yyyymmddb = 20000101L |
---|
82 | ; yyyymmdde = 20001231L |
---|
83 | ; result = sst_correction_ncdf(yyyymmddb, yyyymmdde) |
---|
84 | ; print, result |
---|
85 | ; |
---|
86 | ; TODO |
---|
87 | ; ==== |
---|
88 | ; |
---|
89 | ; make it work on loholt1 idl8: |
---|
90 | ; reach end whithout error but with bad values (9.96921e+36 on time and sst, nb timestep 5716 |
---|
91 | ; |
---|
92 | ; see commands:: |
---|
93 | ; |
---|
94 | ; ncks -v sst -d time,0,1 -d latitude,0,1 -d longitude,0,1 /homedata/pinsard/tropflux_d/TropFlux_sst_19890101_20091231.nc |
---|
95 | ; |
---|
96 | ; very strange value of time on lohlot1 idl6 but not always and not always at the same indices !!:: |
---|
97 | ; |
---|
98 | ; print, time[7080:7090] |
---|
99 | ; 2454607.5 2454608.5 2454609.5 9.9692100e+36 9.9692100e+36 |
---|
100 | ; 9.9692100e+36 9.9692100e+36 9.9692100e+36 9.9692100e+36 2454616.5 |
---|
101 | ; 2454617.5 |
---|
102 | ; |
---|
103 | ; while :: |
---|
104 | ; |
---|
105 | ; $ ncks -H -C -v time -d time,7080,7090 ${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc |
---|
106 | ; time[7080]=450432 |
---|
107 | ; time[7081]=450456 |
---|
108 | ; time[7082]=450480 |
---|
109 | ; time[7083]=450504 |
---|
110 | ; time[7084]=450528 |
---|
111 | ; time[7085]=450552 |
---|
112 | ; time[7086]=450576 |
---|
113 | ; time[7087]=450600 |
---|
114 | ; time[7088]=450624 |
---|
115 | ; time[7089]=450648 |
---|
116 | ; time[7090]=450672 |
---|
117 | ; |
---|
118 | ; and |
---|
119 | ; ncks -H -C -v time -d time,7080,7090 ${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc |
---|
120 | ; time[7080]=21325 |
---|
121 | ; time[7081]=21326 |
---|
122 | ; time[7082]=21327 |
---|
123 | ; time[7083]=9.96920996839e+36 |
---|
124 | ; time[7084]=9.96920996839e+36 |
---|
125 | ; time[7085]=9.96920996839e+36 |
---|
126 | ; time[7086]=9.96920996839e+36 |
---|
127 | ; time[7087]=9.96920996839e+36 |
---|
128 | ; time[7088]=9.96920996839e+36 |
---|
129 | ; time[7089]=21334 |
---|
130 | ; time[7090]=21335 |
---|
131 | ; |
---|
132 | ; and :: |
---|
133 | ; |
---|
134 | ; fplod@cratos$ ncks -H -C -v time -d time,7080,7090 ${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc |
---|
135 | ; time[7080]=21325 |
---|
136 | ; time[7081]=21326 |
---|
137 | ; time[7082]=21327 |
---|
138 | ; time[7083]=21328 |
---|
139 | ; time[7084]=21329 |
---|
140 | ; time[7085]=21330 |
---|
141 | ; time[7086]=21331 |
---|
142 | ; time[7087]=21332 |
---|
143 | ; time[7088]=21333 |
---|
144 | ; time[7089]=21334 |
---|
145 | ; time[7090]=21335 |
---|
146 | ; |
---|
147 | ; coding rules |
---|
148 | ; |
---|
149 | ; temperature SI units = K : why + and - 273... |
---|
150 | ; |
---|
151 | ; hard coded coefficient correction. |
---|
152 | ; |
---|
153 | ; KNOWN ISSUES |
---|
154 | ; ============ |
---|
155 | ; |
---|
156 | ; test of existence of fullfilename_in not very efficient because |
---|
157 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
158 | ; |
---|
159 | ; EVOLUTIONS |
---|
160 | ; ========== |
---|
161 | ; |
---|
162 | ; $Id: sst_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $ |
---|
163 | ; |
---|
164 | ; $URL$ |
---|
165 | ; |
---|
166 | ; - fplod 20120322 |
---|
167 | ; |
---|
168 | ; * taking project_overwite into account |
---|
169 | ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite |
---|
170 | ; * pro -> function |
---|
171 | ; * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters |
---|
172 | ; * get rid of timegen |
---|
173 | ; |
---|
174 | ; - fplod 20110808T124236Z cratos (Linux) |
---|
175 | ; |
---|
176 | ; * usage of ${PROJECT_OD} |
---|
177 | ; * complete description |
---|
178 | ; * remove v20 in output filename |
---|
179 | ; |
---|
180 | ; - fplod 20101215T114224Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
181 | ; |
---|
182 | ; * add graph in header |
---|
183 | ; |
---|
184 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
185 | ; |
---|
186 | ; * minimal header |
---|
187 | ; |
---|
188 | ; - pbk 2008 |
---|
189 | ; |
---|
190 | ; * creation |
---|
191 | ; |
---|
192 | ;- |
---|
193 | function sst_correction_ncdf $ |
---|
194 | , yyyymmddb $ |
---|
195 | , yyyymmdde |
---|
196 | ; |
---|
197 | ;++compile_opt idl2, strictarrsubs, logical_predicate |
---|
198 | ; |
---|
199 | @cm_4cal |
---|
200 | @cm_4data |
---|
201 | @cm_4mesh |
---|
202 | @cm_4data |
---|
203 | @cm_project |
---|
204 | ; |
---|
205 | ; Return to caller if errors |
---|
206 | ON_ERROR, 2 |
---|
207 | ; |
---|
208 | result = -1 |
---|
209 | ; |
---|
210 | usage = 'result = sst_correction_ncdf(yyyymmddb, yyyymmdde)' |
---|
211 | nparam = N_PARAMS() |
---|
212 | IF (nparam NE 2) THEN BEGIN |
---|
213 | ras = report(['Incorrect number of arguments.' $ |
---|
214 | + '!C' $ |
---|
215 | + 'Usage : ' + usage]) |
---|
216 | return, result |
---|
217 | ENDIF |
---|
218 | ; |
---|
219 | ; test if ${PROJECT_OD} defined |
---|
220 | CASE project_od_env OF |
---|
221 | '' : BEGIN |
---|
222 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
223 | ras = report(msg) |
---|
224 | return, result |
---|
225 | END |
---|
226 | ELSE: BEGIN |
---|
227 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
228 | ras = report(msg) |
---|
229 | END |
---|
230 | ENDCASE |
---|
231 | ; |
---|
232 | ; check if output data will be possible |
---|
233 | iodirout = isadirectory(project_od_env) |
---|
234 | ; |
---|
235 | ; existence and protection for reading |
---|
236 | IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
237 | msg = 'eee : the directory' + iodirout + ' is not accessible.' |
---|
238 | ras = report(msg) |
---|
239 | return, result |
---|
240 | ENDIF |
---|
241 | ; |
---|
242 | ; existence and protection for writing |
---|
243 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
244 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
245 | ras = report(msg) |
---|
246 | return, result |
---|
247 | ENDIF |
---|
248 | ; |
---|
249 | ; build data filename |
---|
250 | filename='erai_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' |
---|
251 | ; |
---|
252 | ; check if this file exists |
---|
253 | msg='iii : looking for ' + filename |
---|
254 | ras = report(msg) |
---|
255 | fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST) |
---|
256 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
257 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
258 | ras = report(msg) |
---|
259 | return, result |
---|
260 | ENDIF |
---|
261 | ; |
---|
262 | ; build output filename |
---|
263 | filename_out = 'TropFlux_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc' |
---|
264 | fullfilename_out = iodirout + filename_out |
---|
265 | ; in order to avoid unexpected overwritten |
---|
266 | IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN |
---|
267 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
268 | ras = report(msg) |
---|
269 | return, result |
---|
270 | ENDIF |
---|
271 | ; |
---|
272 | initncdf, fullfilename |
---|
273 | sst=read_ncdf('sst',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) |
---|
274 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
275 | jpt=n_elements(timein) |
---|
276 | da=jul2date(time[0]) |
---|
277 | cda0=string(da,format='(i8.8)') |
---|
278 | da=jul2date(time[jpt-1]) |
---|
279 | cda1=string(da,format='(i8.8)') |
---|
280 | print, 'sst in sst_correction_ncdf first date ', cda0 |
---|
281 | print, 'sst in sst_correction_ncdf last date ' , cda1 |
---|
282 | ; |
---|
283 | sst=sst-273.15 |
---|
284 | help, sst |
---|
285 | ; |
---|
286 | sst_mean=grossemoyenne(sst,'t',/nan) |
---|
287 | help, sst_mean |
---|
288 | ; |
---|
289 | jpt=n_elements(time) |
---|
290 | caldat, time,mon,day,yea |
---|
291 | ; |
---|
292 | ;++ debug to understand some time value 9.9692100e+36 on idl 6 lohloht1 |
---|
293 | ; print, time[7080:7090] when working on [19890101,19891231] |
---|
294 | ; |
---|
295 | sst_m=sst*0. |
---|
296 | ; |
---|
297 | for jt=0,jpt-1 do begin |
---|
298 | jtt=(time[jt]-julday(1,1,yea[jt])) < 364 |
---|
299 | t=reform(sst_mean[*,*]) |
---|
300 | sst_m[*,*,jt]=t |
---|
301 | endfor |
---|
302 | help, sst_m |
---|
303 | ; |
---|
304 | sst_ano=sst-sst_m |
---|
305 | ; |
---|
306 | ; correction for mean based on scatter |
---|
307 | ;sst_m=sst_m+0.0521111 ; (2000-2008) |
---|
308 | sst_m=sst_m+0.0533692 ; (2000-2009) |
---|
309 | ; |
---|
310 | help, sst_ano |
---|
311 | ; |
---|
312 | ; applying the correction for varyability based on the scatter |
---|
313 | ;sst_ano=sst_ano*(1/0.989889) ; (2000-2008) |
---|
314 | sst_ano=sst_ano*(1/0.986196) ; (2000-2009) |
---|
315 | ; |
---|
316 | sst_new=sst_m+sst_ano+273.15 |
---|
317 | help, sst_new |
---|
318 | ; |
---|
319 | ;writing field |
---|
320 | lat=reform(gphit[0,0:jpj-1]) |
---|
321 | lon=reform(glamt[0:jpi-1,0]) |
---|
322 | ; |
---|
323 | ncfile='!' + fullfilename_out |
---|
324 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
325 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
326 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
327 | globattr={source:'Basic data obtained from ERAI. Bias and variability correction are applied',timerange:cda0+' - '+cda1} |
---|
328 | sst_attr={units:'degK',missing_value:1.e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'} |
---|
329 | ; |
---|
330 | ncfields = 'sst[longitude,latitude,*time]=sst_new:sst_attr; ' $ |
---|
331 | + 'longitude[]=lon:lon_attr; ' $ |
---|
332 | + 'latitude[]=lat:lat_attr; ' $ |
---|
333 | + 'time[]=timein:time_attr ' $ |
---|
334 | + ' @ globattr' |
---|
335 | ; |
---|
336 | @ncdf_quickwrite |
---|
337 | ; |
---|
338 | result = 0 |
---|
339 | return, result |
---|
340 | ; |
---|
341 | end |
---|