[6] | 1 | ;+ |
---|
| 2 | ; |
---|
| 3 | ; |
---|
[170] | 4 | ; =================== |
---|
| 5 | ; interp_erai_sst.pro |
---|
| 6 | ; =================== |
---|
[6] | 7 | ; |
---|
[170] | 8 | ; .. function:: interp_erai_sst(yyyymmddb,yyyymmdde) |
---|
| 9 | ; |
---|
[67] | 10 | ; DESCRIPTION |
---|
| 11 | ; =========== |
---|
| 12 | ; |
---|
[66] | 13 | ; Interpolation of sst from ERA-I grid to OAFLUX grid |
---|
| 14 | ; |
---|
[92] | 15 | ; :file:`${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc` |
---|
| 16 | ; containing sst from ERA-I |
---|
[93] | 17 | ; has been produced by |
---|
[92] | 18 | ; :ref:`compute_erai_daily_region_2d.sh`. |
---|
[66] | 19 | ; |
---|
[92] | 20 | ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` |
---|
| 21 | ; containing |
---|
| 22 | ; OAFLUX grid |
---|
[93] | 23 | ; has been produced by |
---|
[153] | 24 | ; :func:`oaflux_mask_30n30s`. |
---|
[66] | 25 | ; |
---|
[92] | 26 | ; Interpolated sst |
---|
| 27 | ; is written in |
---|
[170] | 28 | ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` |
---|
[92] | 29 | ; if this file not already exists. |
---|
[66] | 30 | ; |
---|
[92] | 31 | ; This output file |
---|
[170] | 32 | ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` |
---|
[92] | 33 | ; must be processed after by |
---|
[175] | 34 | ; :func:`sst_correction_ncdf`. |
---|
[66] | 35 | ; |
---|
[92] | 36 | ; .. only:: man |
---|
[66] | 37 | ; |
---|
[92] | 38 | ; Figure is visible on PDF and HTML documents only. |
---|
| 39 | ; |
---|
| 40 | ; .. only:: html or latex |
---|
| 41 | ; |
---|
[9] | 42 | ; .. graphviz:: |
---|
| 43 | ; |
---|
[170] | 44 | ; digraph interp_erai_sst { |
---|
[71] | 45 | ; |
---|
[66] | 46 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc"]; |
---|
[50] | 47 | ; mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"]; |
---|
[170] | 48 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; |
---|
[9] | 49 | ; |
---|
[170] | 50 | ; interp_erai_sst [shape=box, |
---|
[9] | 51 | ; fontname=Courier, |
---|
| 52 | ; color=blue, |
---|
[170] | 53 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_sst.pro", |
---|
| 54 | ; label="${PROJECT}/src/interp_erai_sst.pro"]; |
---|
[9] | 55 | ; |
---|
[170] | 56 | ; {file_in mask} -> {interp_erai_sst} -> {file_out} |
---|
[71] | 57 | ; |
---|
[100] | 58 | ; } |
---|
[9] | 59 | ; |
---|
[6] | 60 | ; SEE ALSO |
---|
| 61 | ; ======== |
---|
| 62 | ; |
---|
[92] | 63 | ; :ref:`interpolate_data` |
---|
| 64 | ; |
---|
[170] | 65 | ; Used by :ref:`tropflux.sh` |
---|
| 66 | ; |
---|
[50] | 67 | ; :ref:`project_profile.sh` |
---|
[19] | 68 | ; |
---|
[20] | 69 | ; :func:`report <saxo:report>` |
---|
| 70 | ; :func:`isadirectory <saxo:isadirectory>` |
---|
| 71 | ; :func:`isafile <saxo:isafile>` |
---|
| 72 | ; :func:`initncdf <saxo:initncdf>` |
---|
| 73 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
| 74 | ; :func:`domdef <saxo:domdef>` |
---|
| 75 | ; :func:`call_interp2d <saxo:call_interp2d>` |
---|
| 76 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
| 77 | ; |
---|
[175] | 78 | ; :func:`sst_correction_ncdf` |
---|
[66] | 79 | ; |
---|
[6] | 80 | ; EXAMPLES |
---|
| 81 | ; ======== |
---|
| 82 | ; |
---|
| 83 | ; :: |
---|
| 84 | ; |
---|
[66] | 85 | ; IDL> .compile file_interp |
---|
[173] | 86 | ; IDL> yyyymmddb = 20000101L |
---|
| 87 | ; IDL> yyyymmdde = 20001231L |
---|
[171] | 88 | ; IDL> result = interp_erai_sst(yyyymmddb, yyyymmdde) |
---|
[170] | 89 | ; IDL> print, result |
---|
[6] | 90 | ; |
---|
[170] | 91 | ; |
---|
[6] | 92 | ; TODO |
---|
| 93 | ; ==== |
---|
| 94 | ; |
---|
[72] | 95 | ; on cratos strange red data looking with ncview |
---|
| 96 | ; |
---|
[70] | 97 | ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call |
---|
| 98 | ; |
---|
[6] | 99 | ; coding rules |
---|
| 100 | ; |
---|
[66] | 101 | ; use real output of :ref:`compute_erai_daily_region_2d.sh`. |
---|
| 102 | ; |
---|
[170] | 103 | ; scientific validation (strange look of data with ncview now) |
---|
| 104 | ; |
---|
| 105 | ; check [yyyymmddb,yyyymmdde] validity |
---|
| 106 | ; |
---|
| 107 | ; check if [yyyymmddb,yyyymmdde] is included in ERA-I file |
---|
| 108 | ; |
---|
| 109 | ; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file |
---|
| 110 | ; |
---|
[19] | 111 | ; KNOWN ISSUES |
---|
| 112 | ; ============ |
---|
| 113 | ; |
---|
| 114 | ; test of existence of fullfilename_msk not very efficient because |
---|
| 115 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
| 116 | ; |
---|
[6] | 117 | ; EVOLUTIONS |
---|
| 118 | ; ========== |
---|
| 119 | ; |
---|
[66] | 120 | ; $Id$ |
---|
| 121 | ; |
---|
[170] | 122 | ; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_sst.pro $ |
---|
[66] | 123 | ; |
---|
[170] | 124 | ; - fplod 20120320 |
---|
| 125 | ; |
---|
| 126 | ; * taking project_overwite into account |
---|
| 127 | ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite |
---|
| 128 | ; * pro -> function |
---|
[173] | 129 | ; * no more timegen |
---|
[170] | 130 | ; |
---|
[92] | 131 | ; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
| 132 | ; |
---|
| 133 | ; * retry on loholt1 with idl8 and idl6 |
---|
| 134 | ; |
---|
[70] | 135 | ; - fplod 20110808T094156Z cratos (Linux) |
---|
| 136 | ; |
---|
| 137 | ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call |
---|
| 138 | ; |
---|
[66] | 139 | ; - pinsard 2011-07-04T15:45:35Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
| 140 | ; |
---|
| 141 | ; * usage of ${PROJECT_ID} and $PROJECT_OD |
---|
| 142 | ; |
---|
[19] | 143 | ; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 144 | ; |
---|
| 145 | ; * remove hard coded directory for mask_oaflux_30N30S.nc |
---|
| 146 | ; |
---|
[9] | 147 | ; - fplod 20101215T100932Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 148 | ; |
---|
| 149 | ; * add graph in header |
---|
| 150 | ; |
---|
[6] | 151 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 152 | ; |
---|
| 153 | ; * minimal header |
---|
| 154 | ; |
---|
| 155 | ; - pbk 2008 |
---|
| 156 | ; |
---|
| 157 | ; * creation |
---|
| 158 | ; |
---|
| 159 | ;- |
---|
[170] | 160 | function interp_erai_sst $ |
---|
| 161 | , yyyymmddb $ |
---|
| 162 | , yyyymmdde |
---|
[66] | 163 | ; |
---|
[170] | 164 | ;++compile_opt idl2, strictarrsubs, logical_predicate |
---|
| 165 | ; |
---|
[66] | 166 | @cm_4cal |
---|
| 167 | @cm_4data |
---|
| 168 | @cm_4mesh |
---|
| 169 | @cm_4data |
---|
[50] | 170 | @cm_project |
---|
[19] | 171 | ; |
---|
[170] | 172 | ; Return to caller if errors |
---|
| 173 | ON_ERROR, 2 |
---|
| 174 | ; |
---|
| 175 | result = -1 |
---|
| 176 | ; |
---|
[173] | 177 | usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde)' |
---|
[170] | 178 | nparam = N_PARAMS() |
---|
| 179 | IF (nparam NE 2) THEN BEGIN |
---|
| 180 | ras = report(['Incorrect number of arguments.' $ |
---|
| 181 | + '!C' $ |
---|
| 182 | + 'Usage : ' + usage]) |
---|
| 183 | return, result |
---|
| 184 | ENDIF |
---|
| 185 | ; |
---|
[20] | 186 | ; check for input directory |
---|
[19] | 187 | ; |
---|
[50] | 188 | ; test if ${PROJECT_ID} defined |
---|
| 189 | CASE project_id_env OF |
---|
[19] | 190 | '' : BEGIN |
---|
[50] | 191 | msg = 'eee : ${PROJECT_ID} is not defined' |
---|
[19] | 192 | ras = report(msg) |
---|
[170] | 193 | return, result |
---|
[19] | 194 | END |
---|
| 195 | ELSE: BEGIN |
---|
[50] | 196 | msg = 'iii : ${PROJECT_ID} is ' + project_id_env |
---|
[19] | 197 | ras = report(msg) |
---|
| 198 | END |
---|
| 199 | ENDCASE |
---|
| 200 | ; |
---|
[50] | 201 | iodirin = isadirectory(project_id_env) |
---|
[19] | 202 | ; |
---|
[50] | 203 | ; existence and protection of ${PROJECT_ID} |
---|
[19] | 204 | IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
| 205 | msg = 'eee : the directory' + iodirin + ' is not accessible.' |
---|
| 206 | ras = report(msg) |
---|
[170] | 207 | return, result |
---|
[19] | 208 | ENDIF |
---|
| 209 | ; |
---|
| 210 | ; build mask filename |
---|
| 211 | filename_msk='mask_oaflux_30N30S.nc' |
---|
| 212 | ; |
---|
| 213 | ; check if this file exists |
---|
[92] | 214 | msg='iii : looking for ' + filename_msk |
---|
| 215 | ras = report(msg) |
---|
[19] | 216 | fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST) |
---|
| 217 | IF fullfilename_msk[0] EQ '' THEN BEGIN |
---|
| 218 | msg = 'eee : the file ' + fullfilename_msk + ' was not found.' |
---|
| 219 | ras = report(msg) |
---|
[170] | 220 | return, result |
---|
[19] | 221 | ENDIF |
---|
[66] | 222 | ; |
---|
| 223 | ; build data filename |
---|
| 224 | filename='20c3m_erai_sstk_TROP_1989_2009.nc' |
---|
| 225 | ; |
---|
| 226 | ; check if this file exists |
---|
[92] | 227 | msg='iii : looking for ' + filename |
---|
| 228 | ras = report(msg) |
---|
[66] | 229 | fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST) |
---|
[71] | 230 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
| 231 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
[66] | 232 | ras = report(msg) |
---|
[170] | 233 | return, result |
---|
[66] | 234 | ENDIF |
---|
| 235 | ; |
---|
| 236 | ; test if ${PROJECT_OD} defined |
---|
| 237 | CASE project_od_env OF |
---|
| 238 | '' : BEGIN |
---|
| 239 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
| 240 | ras = report(msg) |
---|
[170] | 241 | return, result |
---|
[66] | 242 | END |
---|
| 243 | ELSE: BEGIN |
---|
| 244 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
| 245 | ras = report(msg) |
---|
| 246 | END |
---|
| 247 | ENDCASE |
---|
| 248 | ; |
---|
| 249 | ; check if output data will be possible |
---|
| 250 | iodirout = isadirectory(project_od_env) |
---|
| 251 | ; |
---|
| 252 | ; existence and protection |
---|
| 253 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
| 254 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
| 255 | ras = report(msg) |
---|
[170] | 256 | return, result |
---|
[66] | 257 | ENDIF |
---|
| 258 | ; |
---|
| 259 | ; build output filename |
---|
[170] | 260 | filename_out = 'erai_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' |
---|
[66] | 261 | fullfilename_out = iodirout + filename_out |
---|
| 262 | ; in order to avoid unexpected overwritten |
---|
[170] | 263 | IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN |
---|
[66] | 264 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
| 265 | ras = report(msg) |
---|
[170] | 266 | return, result |
---|
[66] | 267 | ENDIF |
---|
| 268 | ; |
---|
| 269 | initncdf, fullfilename |
---|
[5] | 270 | domdef |
---|
[170] | 271 | latin=reform(gphit[0,*]) |
---|
| 272 | lonin=reform(glamt[*,0]) |
---|
| 273 | print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0] |
---|
| 274 | print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0] |
---|
[173] | 275 | sstkin=read_ncdf("sstk",yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) |
---|
[97] | 276 | ; |
---|
[173] | 277 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
| 278 | jptin=n_elements(timein) |
---|
| 279 | da=jul2date(time[0]) |
---|
| 280 | cda0=string(da,format='(i8.8)') |
---|
| 281 | da=jul2date(time[jpt-1]) |
---|
| 282 | cda1=string(da,format='(i8.8)') |
---|
[174] | 283 | print, 'sst first date ', cda0 |
---|
| 284 | print, 'sst last date ' , cda1 |
---|
[173] | 285 | ; |
---|
[170] | 286 | tab=sstkin[*,*,0] |
---|
[97] | 287 | mskin=glamt*0.+1. |
---|
| 288 | ind=where((tab eq 1.e9) or finite(tab,/nan)) |
---|
[170] | 289 | mskin[ind]=0. |
---|
[97] | 290 | ; |
---|
[19] | 291 | initncdf, fullfilename_msk |
---|
[5] | 292 | domdef |
---|
[170] | 293 | latout=reform(gphit[0,*]) |
---|
| 294 | lonout=reform(glamt[*,0]) |
---|
| 295 | print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0] |
---|
| 296 | print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0] |
---|
[19] | 297 | mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) |
---|
[97] | 298 | ; |
---|
[5] | 299 | help, sstkin,lonin,latin,mskin,lonout,latout,mskout |
---|
[97] | 300 | ; |
---|
[5] | 301 | sstkout=fltarr(jpi,jpj,jptin) |
---|
| 302 | for jt=0,jptin-1 do begin |
---|
[92] | 303 | ; ++print, 'Interpolation jt=',jt,' / ',jptin-1 |
---|
[170] | 304 | tab=reform(sstkin[*,*,jt]) |
---|
| 305 | sstkout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $ |
---|
[71] | 306 | , lonout,latout,method='bilinear' $ |
---|
| 307 | , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) |
---|
[170] | 308 | sstkout[*,*,jt]=sstkout[*,*,jt]*mskout+(1.-mskout)*1.e20 |
---|
[5] | 309 | endfor |
---|
[97] | 310 | ; |
---|
[19] | 311 | initncdf, fullfilename_msk |
---|
[97] | 312 | ; |
---|
[5] | 313 | lat=latout |
---|
| 314 | lon=lonout |
---|
[66] | 315 | ncfile='!' + fullfilename_out |
---|
[5] | 316 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
| 317 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
[100] | 318 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
| 319 | globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1} |
---|
[5] | 320 | sstk_attr={units:'degK',missing_value:1e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'} |
---|
[97] | 321 | ; |
---|
[173] | 322 | ncfields = 'sst[longitude,latitude,*time]=sstkout:sstk_attr; ' $ |
---|
[5] | 323 | + 'longitude[]=lon:lon_attr; ' $ |
---|
| 324 | + 'latitude[]=lat:lat_attr; ' $ |
---|
[173] | 325 | + 'time[]=timein:time_attr ' $ |
---|
[5] | 326 | + ' @ globattr' |
---|
[97] | 327 | ; |
---|
[5] | 328 | @ncdf_quickwrite |
---|
[97] | 329 | ; |
---|
[170] | 330 | result = 0 |
---|
| 331 | return, result |
---|
| 332 | ; |
---|
[5] | 333 | end |
---|