[6] | 1 | ;+ |
---|
| 2 | ; |
---|
[19] | 3 | ; .. _interp_erai_lwr_1989_2009.pro: |
---|
[6] | 4 | ; |
---|
[67] | 5 | ; ============================= |
---|
| 6 | ; interp_erai_lwr_1989_2009.pro |
---|
| 7 | ; ============================= |
---|
[6] | 8 | ; |
---|
[67] | 9 | ; DESCRIPTION |
---|
| 10 | ; =========== |
---|
| 11 | ; |
---|
[66] | 12 | ; Interpolation of str from ERA-I grid to OAFLUX grid |
---|
| 13 | ; |
---|
| 14 | ; :file:`${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc` containing str from ERA-I have been produced |
---|
| 15 | ; by :ref:`compute_erai_daily_region_2d.sh`. |
---|
| 16 | ; |
---|
| 17 | ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` containing OAFLUX grid have been produced by :ref:`oaflux_mask_30N30S.pro`. |
---|
| 18 | ; |
---|
| 19 | ; Interpolated str is written in |
---|
| 20 | ; :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` if this file not already exists. |
---|
| 21 | ; |
---|
| 22 | ; This output file :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` must be processed after by :ref:`lwr_correction_ncdf.pro`. |
---|
| 23 | ; |
---|
[8] | 24 | ; .. graphviz:: |
---|
| 25 | ; |
---|
| 26 | ; digraph interp_erai_lwr_1989_2009 { |
---|
| 27 | ; graph [ |
---|
| 28 | ; rankdir="LR", |
---|
| 29 | ; ] |
---|
| 30 | ; |
---|
[66] | 31 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc"]; |
---|
[71] | 32 | ; mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"]; |
---|
| 33 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc"]; |
---|
[8] | 34 | ; |
---|
| 35 | ; interp_erai_lwr_1989_2009 [shape=box, |
---|
| 36 | ; fontname=Courier, |
---|
| 37 | ; color=blue, |
---|
| 38 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_lwr_1989_2009.pro", |
---|
[50] | 39 | ; label="${PROJECT}/src/interp_erai_lwr_1989_2009.pro"]; |
---|
[8] | 40 | ; |
---|
[71] | 41 | ; {file_in mask} -> {interp_erai_lwr_1989_2009} -> {file_out} |
---|
[8] | 42 | ; |
---|
| 43 | ; } |
---|
| 44 | ; |
---|
[6] | 45 | ; SEE ALSO |
---|
| 46 | ; ======== |
---|
| 47 | ; |
---|
[50] | 48 | ; :ref:`project_profile.sh` |
---|
[19] | 49 | ; |
---|
[20] | 50 | ; :func:`report <saxo:report>` |
---|
| 51 | ; :func:`isadirectory <saxo:isadirectory>` |
---|
| 52 | ; :func:`isafile <saxo:isafile>` |
---|
| 53 | ; :func:`initncdf <saxo:initncdf>` |
---|
| 54 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
| 55 | ; :func:`domdef <saxo:domdef>` |
---|
| 56 | ; :func:`call_interp2d <saxo:call_interp2d>` |
---|
| 57 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
| 58 | ; |
---|
[67] | 59 | ; :ref:`lwr_correction_ncdf.pro` |
---|
[66] | 60 | ; |
---|
[6] | 61 | ; EXAMPLES |
---|
| 62 | ; ======== |
---|
| 63 | ; |
---|
| 64 | ; :: |
---|
| 65 | ; |
---|
[66] | 66 | ; IDL> .compile file_interp |
---|
[6] | 67 | ; IDL> interp_erai_lwr_1989_2009 |
---|
| 68 | ; |
---|
| 69 | ; TODO |
---|
| 70 | ; ==== |
---|
| 71 | ; |
---|
[73] | 72 | ; make it work : pb on loholt1 idl8:: |
---|
[6] | 73 | ; |
---|
[71] | 74 | ; OUTMASK_IND UNDEFINED = <Undefined> |
---|
| 75 | ; SET_OUTMSKVAL UNDEFINED = <Undefined> |
---|
| 76 | ; |
---|
| 77 | ; lwr[longitude,latitude,time]=lwrout:lwr_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr @ globattr |
---|
| 78 | ; % NCDF_DIMDEF: 0 is not a valid cdfid. |
---|
| 79 | ; % Stop encountered: INTERP_ERAI_LWR_1989_2009 1 |
---|
| 80 | ; /home/pinsard/tropflux_ws/src/interp_erai_lwr_1989_2009.pro |
---|
[66] | 81 | ; |
---|
[73] | 82 | ; make it work : pb on loholt1 idl6:: |
---|
| 83 | ; |
---|
| 84 | ; OUTMASK_IND UNDEFINED = <Undefined> |
---|
| 85 | ; SET_OUTMSKVAL UNDEFINED = <Undefined> |
---|
| 86 | ; lwr[longitude,latitude,time]=lwrout:lwr_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr @ globattr |
---|
| 87 | ; % NCDF_VARPUT: Operation Failed, bad file (4) or variable (0) id ? |
---|
| 88 | ; (NC_ERROR=-31) |
---|
| 89 | ; % Stop encountered: INTERP_ERAI_LWR_1989_2009 1 |
---|
| 90 | ; /home/pinsard/tropflux_ws/src/interp_erai_lwr_1989_2009.pro |
---|
| 91 | ; |
---|
[70] | 92 | ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call |
---|
| 93 | ; |
---|
| 94 | ; use real output of :ref:`compute_erai_daily_region_2d.sh`. |
---|
| 95 | ; |
---|
| 96 | ; 19890101 is not provided in ERA-Intermim file str : a possible workaround is to copy 19890102 |
---|
[78] | 97 | ; dataset to 19890101 using nco after this processing. see :ref:`compute_erai_daily_region_2d.sh` |
---|
[70] | 98 | ; |
---|
[6] | 99 | ; coding rules |
---|
| 100 | ; |
---|
[19] | 101 | ; KNOWN ISSUES |
---|
| 102 | ; ============ |
---|
| 103 | ; |
---|
| 104 | ; test of existence of fullfilename_msk not very efficient because |
---|
| 105 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
| 106 | ; |
---|
[6] | 107 | ; EVOLUTIONS |
---|
| 108 | ; ========== |
---|
| 109 | ; |
---|
[66] | 110 | ; $Id$ |
---|
| 111 | ; |
---|
| 112 | ; $URL$ |
---|
| 113 | ; |
---|
[73] | 114 | ; - pinsard 2011-08-08T16:03:48Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
| 115 | ; |
---|
| 116 | ; * remove return statement |
---|
| 117 | ; |
---|
[70] | 118 | ; - fplod 20110808T094156Z cratos (Linux) |
---|
| 119 | ; |
---|
| 120 | ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call |
---|
| 121 | ; * fix typo |
---|
| 122 | ; .. note:: |
---|
| 123 | ; |
---|
| 124 | ; IDL do not warn when asking size of an undefined array:: |
---|
| 125 | ; |
---|
| 126 | ; IDL> must_crash=size(ginette) |
---|
| 127 | ; |
---|
[66] | 128 | ; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
| 129 | ; |
---|
| 130 | ; * usage of $PROJECT_ID and $PROJECT_OD |
---|
| 131 | ; |
---|
[19] | 132 | ; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 133 | ; |
---|
| 134 | ; * remove hard coded directory for mask_oaflux_30N30S.nc |
---|
| 135 | ; |
---|
[8] | 136 | ; - fplod 20101215T094137Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 137 | ; |
---|
| 138 | ; * add graph in header |
---|
| 139 | ; |
---|
[6] | 140 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 141 | ; |
---|
| 142 | ; * minimal header |
---|
| 143 | ; |
---|
| 144 | ; - pbk 2008 |
---|
| 145 | ; |
---|
| 146 | ; * creation |
---|
| 147 | ; |
---|
| 148 | ;- |
---|
[5] | 149 | pro interp_erai_lwr_1989_2009 |
---|
[19] | 150 | ; |
---|
[66] | 151 | @cm_4cal |
---|
| 152 | @cm_4data |
---|
| 153 | @cm_4mesh |
---|
| 154 | @cm_4data |
---|
| 155 | @cm_project |
---|
| 156 | ; |
---|
[20] | 157 | ; check for input directory |
---|
[19] | 158 | ; |
---|
[50] | 159 | ; test if ${PROJECT_ID} defined |
---|
| 160 | CASE project_id_env OF |
---|
[19] | 161 | '' : BEGIN |
---|
[50] | 162 | msg = 'eee : ${PROJECT_ID} is not defined' |
---|
[19] | 163 | ras = report(msg) |
---|
| 164 | STOP |
---|
| 165 | END |
---|
| 166 | ELSE: BEGIN |
---|
[50] | 167 | msg = 'iii : ${PROJECT_ID} is ' + project_id_env |
---|
[19] | 168 | ras = report(msg) |
---|
| 169 | END |
---|
| 170 | ENDCASE |
---|
| 171 | ; |
---|
[50] | 172 | iodirin = isadirectory(project_id_env) |
---|
[19] | 173 | ; |
---|
[50] | 174 | ; existence and protection of ${PROJECT_ID} |
---|
[19] | 175 | IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
| 176 | msg = 'eee : the directory' + iodirin + ' is not accessible.' |
---|
| 177 | ras = report(msg) |
---|
| 178 | STOP |
---|
| 179 | ENDIF |
---|
| 180 | ; |
---|
| 181 | ; build mask filename |
---|
| 182 | filename_msk='mask_oaflux_30N30S.nc' |
---|
| 183 | ; |
---|
| 184 | ; check if this file exists |
---|
| 185 | fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST) |
---|
| 186 | IF fullfilename_msk[0] EQ '' THEN BEGIN |
---|
| 187 | msg = 'eee : the file ' + fullfilename_msk + ' was not found.' |
---|
| 188 | ras = report(msg) |
---|
| 189 | STOP |
---|
| 190 | ENDIF |
---|
[5] | 191 | |
---|
| 192 | st=19890101 & en=20090801 |
---|
| 193 | |
---|
[66] | 194 | ; build data filename |
---|
| 195 | filename='20c3m_erai_str_TROP_1989_2009.nc' |
---|
| 196 | ; |
---|
| 197 | ; check if this file exists |
---|
| 198 | fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST) |
---|
[71] | 199 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
| 200 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
[66] | 201 | ras = report(msg) |
---|
| 202 | STOP |
---|
| 203 | ENDIF |
---|
| 204 | ; |
---|
| 205 | ; test if ${PROJECT_OD} defined |
---|
| 206 | CASE project_od_env OF |
---|
| 207 | '' : BEGIN |
---|
| 208 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
| 209 | ras = report(msg) |
---|
| 210 | STOP |
---|
| 211 | END |
---|
| 212 | ELSE: BEGIN |
---|
| 213 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
| 214 | ras = report(msg) |
---|
| 215 | END |
---|
| 216 | ENDCASE |
---|
| 217 | ; |
---|
| 218 | ; check if output data will be possible |
---|
| 219 | iodirout = isadirectory(project_od_env) |
---|
| 220 | ; |
---|
| 221 | ; existence and protection |
---|
| 222 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
| 223 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
| 224 | ras = report(msg) |
---|
| 225 | STOP |
---|
| 226 | ENDIF |
---|
| 227 | ; |
---|
| 228 | ; build output filename |
---|
| 229 | filename_out = 'erai_lwr_19890101_20091231_oafluxgrid.nc' |
---|
| 230 | fullfilename_out = iodirout + filename_out |
---|
| 231 | ; in order to avoid unexpected overwritten |
---|
| 232 | IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN |
---|
| 233 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
| 234 | ras = report(msg) |
---|
| 235 | STOP |
---|
| 236 | ENDIF |
---|
| 237 | ; |
---|
| 238 | initncdf, fullfilename |
---|
| 239 | lwrin=read_ncdf("str",0,7668,/timestep,file=fullfilename,/nostr) |
---|
[5] | 240 | lwrin=-1*lwrin |
---|
| 241 | |
---|
[66] | 242 | initncdf, fullfilename |
---|
[5] | 243 | domdef |
---|
| 244 | latin=reform(gphit(0,*)) & lonin=reform(glamt(*,0)) |
---|
| 245 | print, 'lat grid ',min(latin),max(latin),latin(1)-latin(0) |
---|
| 246 | print, 'lon grid ',min(lonin),max(lonin),lonin(1)-lonin(0) |
---|
| 247 | |
---|
| 248 | timein=time & jptin=jpt |
---|
| 249 | tab=lwrin(*,*,0) |
---|
| 250 | mskin=glamt*0.+1. |
---|
| 251 | |
---|
[19] | 252 | initncdf, fullfilename_msk |
---|
[5] | 253 | domdef |
---|
| 254 | latout=reform(gphit(0,*)) & lonout=reform(glamt(*,0)) |
---|
| 255 | print, 'lat grid ',min(latout),max(latout),latout(1)-latout(0) |
---|
| 256 | print, 'lon grid ',min(lonout),max(lonout),lonout(1)-lonout(0) |
---|
[19] | 257 | mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) |
---|
[5] | 258 | |
---|
[70] | 259 | si=size(lwrin) |
---|
[5] | 260 | lwrout=fltarr(jpi,jpj,jptin) |
---|
| 261 | |
---|
| 262 | for jt=0,jptin-1 do begin |
---|
| 263 | print, 'Interpolation jt=',jt,' / ',jptin-1 |
---|
| 264 | |
---|
| 265 | tab=reform(lwrin(*,*,jt)) |
---|
[70] | 266 | lwrout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin $ |
---|
[71] | 267 | , lonout,latout,method='bilinear' $ |
---|
| 268 | , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) |
---|
[70] | 269 | help, OUTMASK_IND |
---|
| 270 | help, SET_OUTMSKVAL |
---|
[5] | 271 | lwrout(*,*,jt)=lwrout(*,*,jt)*mskout+(1.-mskout)*1.e20 |
---|
| 272 | |
---|
| 273 | endfor |
---|
| 274 | |
---|
| 275 | time=timegen(7669, start=julday(1,2,1989,0), units='days') & jpt=n_elements(time) |
---|
| 276 | tt=time & jptin=jpt |
---|
| 277 | cda0=string(jul2date(tt(0)),format='(i8.8)') |
---|
| 278 | cda1=string(jul2date(tt(jpt-1)),format='(i8.8)') |
---|
| 279 | tt=tt-julday(1,1,1950,00,00,00) |
---|
| 280 | xlon=reform(glamt(*,0) ) & ylat=reform(gphit(0,*)) |
---|
| 281 | |
---|
[19] | 282 | initncdf, fullfilename_msk |
---|
[5] | 283 | valmask=1.e20 |
---|
| 284 | |
---|
| 285 | ylat=latout |
---|
| 286 | xlon=lonout |
---|
[66] | 287 | ncfile='!' + fullfilename_out |
---|
[5] | 288 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
| 289 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
| 290 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:' 1950-JAN-01 00:00:00'} |
---|
| 291 | |
---|
| 292 | lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation ',short_name:'lwr',axis:'TYX'} |
---|
| 293 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:' 1950-JAN-01 00:00:00'} |
---|
| 294 | globattr={source:'Tropical ocean fluxes obtained from ERA Interim',timerange:cda0+' - '+cda1} |
---|
| 295 | |
---|
| 296 | ncfields = 'lwr[longitude,latitude,time]=lwrout:lwr_attr; ' $ |
---|
| 297 | + 'longitude[]=xlon:lon_attr; ' $ |
---|
| 298 | + 'latitude[]=ylat:lat_attr; ' $ |
---|
| 299 | + 'tt[*time]=tt:time_attr ' $ |
---|
| 300 | + ' @ globattr' |
---|
| 301 | |
---|
| 302 | @ncdf_quickwrite |
---|
| 303 | |
---|
| 304 | end |
---|