[4] | 1 | ;+ |
---|
| 2 | ; |
---|
| 3 | ; @file_comments |
---|
[14] | 4 | ; produce cond_sed_<orcares>.nc or Br_<orcares>.nc |
---|
| 5 | ; dependent on orcares and variable parameters |
---|
[4] | 6 | ; |
---|
| 7 | ; @categories |
---|
[14] | 8 | ; output, netcdf |
---|
[4] | 9 | ; |
---|
| 10 | ; @param orcares {in}{required}{type=string} |
---|
| 11 | ; code of ORCA grid to use for output results |
---|
[10] | 12 | ; must be 'ORCA2' or 'ORCA025' |
---|
[4] | 13 | ; |
---|
[14] | 14 | ; @param variable {in}{required}{type=structure return by NCDF_VARINQ} |
---|
[18] | 15 | ; { NAME:"", DATATYPE:"", NDIMS:0L, NATTS:0L, DIM:LONARR(NDIMS) } |
---|
| 16 | ; variable of condmag.nc to be written |
---|
[14] | 17 | ; variable.NAME must be 'cond_sed' or 'Br' |
---|
[4] | 18 | ; |
---|
[14] | 19 | ; @param title {in}{required}{type=string} |
---|
[36] | 20 | ; title must belong_name 'Conductance' or 'Magnetic_field' ++ |
---|
[4] | 21 | ; |
---|
[14] | 22 | ; @param long_name {in}{required}{type=string} |
---|
| 23 | ; long_name must be 'Conductance' or 'magnetic_field' ++ |
---|
| 24 | ; |
---|
| 25 | ; @param units {in}{required}{type=string} |
---|
| 26 | ; units must be 'siemens' or 'tesla' |
---|
| 27 | ; |
---|
| 28 | ; @param jpio {in}{required}{type=integer} |
---|
| 29 | ; x dimension of the 3d array to be written |
---|
| 30 | ; must be greater than 1 |
---|
| 31 | ; |
---|
[36] | 32 | ; @param jpjo {in}{required}{type=integer} |
---|
[14] | 33 | ; y dimension of the 3d array to be written |
---|
| 34 | ; must be greater than 1 |
---|
| 35 | ; |
---|
| 36 | ; @param olon {in}{required}{type=1d array of floats} |
---|
| 37 | ; x++ longitude values |
---|
| 38 | ; must be ++ |
---|
| 39 | ; |
---|
| 40 | ; @param olat {in}{required}{type=1d array of floats} |
---|
| 41 | ; x++ latitude values |
---|
| 42 | ; must be ++ |
---|
| 43 | ; |
---|
[16] | 44 | ; @param values {in}{required}{type=nd array of variable.DATATYPE} |
---|
[14] | 45 | ; values of the variable to be written |
---|
| 46 | ; ++ must be |
---|
| 47 | ; |
---|
[4] | 48 | ; @restrictions |
---|
| 49 | ; - Requires SAXO tools |
---|
| 50 | ; |
---|
| 51 | ; @todo |
---|
| 52 | ; produce a NetCDF GDT or CF compliant |
---|
[14] | 53 | ; check if jpio and jpjo are not present in some "common" after getgridparam |
---|
| 54 | ; in order to remove them from parameters |
---|
[4] | 55 | ; |
---|
| 56 | ; @pre |
---|
[18] | 57 | ; reading of condmag.nc |
---|
[14] | 58 | ; see condmag_on_orca.pro |
---|
[4] | 59 | ; |
---|
| 60 | ; @post |
---|
| 61 | ; cond_sed_<I>orcasres</I>.nc is now present in ${GEOMAG_OD}/ |
---|
[14] | 62 | ; or |
---|
[6] | 63 | ; Br_<I>orcasres</I>.nc is now present in ${GEOMAG_OD}/ |
---|
[4] | 64 | ; see geomag_env.sh |
---|
| 65 | ; |
---|
| 66 | ; @examples |
---|
[6] | 67 | ; IDL> .run condmag_on_orca |
---|
[36] | 68 | ; IDL> condmag_output, 'ORCA2', 'cond_sed', 'Conductance', 'Conductance', 'siemens', jpio, jpjo, olon, olat, values |
---|
[4] | 69 | ; |
---|
| 70 | ; @history |
---|
[14] | 71 | ; reee522 2006-12-13T11:44:19Z rhodes (IRIX64) |
---|
| 72 | ; add attributes in parameters list |
---|
| 73 | ; reee522 2006-11-28T14:07:32Z rhodes (IRIX64) |
---|
| 74 | ; written from current release of condmag_on_orca.pro |
---|
[4] | 75 | ; |
---|
| 76 | ; @version |
---|
| 77 | ; $Id$ |
---|
| 78 | ; |
---|
| 79 | ;- |
---|
[36] | 80 | PRO condmag_output, orcares, variable, title, long_name, units, jpio, jpjo, olon, olat, values |
---|
[4] | 81 | ; |
---|
| 82 | compile_opt idl2, strictarrsubs |
---|
| 83 | ; |
---|
| 84 | ;---- |
---|
| 85 | ; check input parameters |
---|
| 86 | ;---- |
---|
| 87 | ; |
---|
| 88 | ; check orcares definition |
---|
| 89 | ; |
---|
| 90 | CASE orcares OF |
---|
| 91 | 'ORCA2': BEGIN |
---|
[6] | 92 | msg = 'iii : valid orcares parameter = ' + orcares |
---|
[19] | 93 | ras = report(msg) |
---|
[4] | 94 | END |
---|
[10] | 95 | 'ORCA025': BEGIN |
---|
| 96 | msg = 'iii : valid orcares parameter = ' + orcares |
---|
[19] | 97 | ras = report(msg) |
---|
[10] | 98 | END |
---|
[4] | 99 | ELSE : BEGIN |
---|
[6] | 100 | msg = 'eee : invalid orcares parameter = ' + orcares |
---|
[19] | 101 | ras = report(msg) |
---|
[10] | 102 | msg = 'eee : orcares must be ORCA2 or ORCA025' |
---|
[19] | 103 | ras = report(msg) |
---|
[4] | 104 | RETURN |
---|
| 105 | END |
---|
| 106 | ENDCASE |
---|
| 107 | ; |
---|
[14] | 108 | ; check variable definition |
---|
| 109 | ; ++ dimension etc. |
---|
| 110 | CASE variable.NAME OF |
---|
| 111 | 'cond_sed': BEGIN |
---|
| 112 | msg = 'iii : valid variable.NAME parameter = ' + variable.NAME |
---|
[19] | 113 | ras = report(msg) |
---|
[14] | 114 | CASE title OF |
---|
| 115 | 'Conductance': BEGIN |
---|
| 116 | msg = 'iii : valid title parameter = ' + title |
---|
[19] | 117 | ras = report(msg) |
---|
[14] | 118 | END |
---|
| 119 | ELSE : BEGIN |
---|
| 120 | msg = 'eee : invalid title parameter = ' + title |
---|
[19] | 121 | ras = report(msg) |
---|
[14] | 122 | msg = 'eee : title must be Conductance' |
---|
[19] | 123 | ras = report(msg) |
---|
[14] | 124 | RETURN |
---|
| 125 | END |
---|
| 126 | ENDCASE |
---|
| 127 | CASE long_name OF |
---|
| 128 | 'Conductance': BEGIN |
---|
| 129 | msg = 'iii : valid long_name parameter = ' + long_name |
---|
[19] | 130 | ras = report(msg) |
---|
[14] | 131 | END |
---|
| 132 | ELSE : BEGIN |
---|
| 133 | msg = 'eee : invalid long_name parameter = ' + long_name |
---|
[19] | 134 | ras = report(msg) |
---|
[14] | 135 | msg = 'eee : long_name must be Conductance' |
---|
[19] | 136 | ras = report(msg) |
---|
[14] | 137 | RETURN |
---|
| 138 | END |
---|
| 139 | ENDCASE |
---|
| 140 | CASE units OF |
---|
| 141 | 'siemens': BEGIN |
---|
| 142 | msg = 'iii : valid units parameter = ' + units |
---|
[19] | 143 | ras = report(msg) |
---|
[14] | 144 | END |
---|
| 145 | ELSE : BEGIN |
---|
| 146 | msg = 'eee : invalid units parameter = ' + units |
---|
[19] | 147 | ras = report(msg) |
---|
[14] | 148 | msg = 'eee : units must be siemens' |
---|
[19] | 149 | ras = report(msg) |
---|
[14] | 150 | RETURN |
---|
| 151 | END |
---|
| 152 | ENDCASE |
---|
[4] | 153 | END |
---|
[14] | 154 | 'Br' : BEGIN |
---|
| 155 | msg = 'iii : valid variable.NAME parameter = ' + variable.NAME |
---|
[19] | 156 | ras = report(msg) |
---|
[14] | 157 | CASE title OF |
---|
| 158 | 'Magnetic field': BEGIN |
---|
| 159 | msg = 'iii : valid title parameter = ' + title |
---|
[19] | 160 | ras = report(msg) |
---|
[14] | 161 | END |
---|
| 162 | ELSE : BEGIN |
---|
| 163 | msg = 'eee : invalid title parameter = ' + title |
---|
[19] | 164 | ras = report(msg) |
---|
[14] | 165 | msg = 'eee : title must be Magnetic field' |
---|
[19] | 166 | ras = report(msg) |
---|
[14] | 167 | RETURN |
---|
| 168 | END |
---|
| 169 | ENDCASE |
---|
| 170 | CASE long_name OF |
---|
| 171 | 'magnetic field': BEGIN |
---|
| 172 | msg = 'iii : valid long_name parameter = ' + long_name |
---|
[19] | 173 | ras = report(msg) |
---|
[14] | 174 | END |
---|
| 175 | ELSE : BEGIN |
---|
| 176 | msg = 'eee : invalid long_name parameter = ' + long_name |
---|
[19] | 177 | ras = report(msg) |
---|
[14] | 178 | msg = 'eee : long_name must be magnetic field' |
---|
[19] | 179 | ras = report(msg) |
---|
[14] | 180 | RETURN |
---|
| 181 | END |
---|
| 182 | ENDCASE |
---|
| 183 | CASE units OF |
---|
| 184 | 'tesla': BEGIN |
---|
| 185 | msg = 'iii : valid units parameter = ' + units |
---|
[19] | 186 | ras = report(msg) |
---|
[14] | 187 | END |
---|
| 188 | ELSE : BEGIN |
---|
| 189 | msg = 'eee : invalid units parameter = ' + units |
---|
[19] | 190 | ras = report(msg) |
---|
[14] | 191 | msg = 'eee : units must be tesla' |
---|
[19] | 192 | ras = report(msg) |
---|
[14] | 193 | RETURN |
---|
| 194 | END |
---|
| 195 | ENDCASE |
---|
[4] | 196 | END |
---|
| 197 | ELSE : BEGIN |
---|
[14] | 198 | msg = 'eee : invalid variable.NAME parameter = ' + variable.NAME |
---|
[19] | 199 | ras = report(msg) |
---|
[14] | 200 | msg = 'eee : variable.NAME must be cond_sed or Br' |
---|
[19] | 201 | ras = report(msg) |
---|
[4] | 202 | RETURN |
---|
| 203 | END |
---|
| 204 | ENDCASE |
---|
| 205 | ; |
---|
[14] | 206 | ; check jpio |
---|
[36] | 207 | IF (jpio LT 1) THEN BEGIN |
---|
[14] | 208 | msg = ' eee : invalid jpio parameter = ' + STRING(jpio) |
---|
[19] | 209 | ras = report(msg) |
---|
[14] | 210 | msg = ' eee : jpio must be greater or equal to 1' |
---|
[19] | 211 | ras = report(msg) |
---|
[4] | 212 | RETURN |
---|
[14] | 213 | ENDIF ELSE BEGIN |
---|
| 214 | msg = 'iii : valid jpio parameter = ' + STRING(jpio) |
---|
[19] | 215 | ras = report(msg) |
---|
[14] | 216 | ENDELSE |
---|
[4] | 217 | ; |
---|
[14] | 218 | ; check jpjo |
---|
[36] | 219 | IF (jpjo LT 1) THEN BEGIN |
---|
[14] | 220 | msg = ' eee : invalid jpjo parameter = ' + STRING(jpjo) |
---|
[19] | 221 | ras = report(msg) |
---|
[14] | 222 | msg = ' eee : jpjo must be greater or equal to 1' |
---|
[19] | 223 | ras = report(msg) |
---|
[4] | 224 | RETURN |
---|
[14] | 225 | ENDIF ELSE BEGIN |
---|
| 226 | msg = 'iii : valid jpjo parameter = ' + STRING(jpjo) |
---|
[19] | 227 | ras = report(msg) |
---|
[14] | 228 | ENDELSE |
---|
[4] | 229 | ; |
---|
[14] | 230 | ; check olon ++ what to check |
---|
| 231 | ; when decided reproduce with olat ++ |
---|
| 232 | IF (N_ELEMENTS(olon) NE jpio*jpjo) THEN BEGIN |
---|
| 233 | msg = ' eee : invalid nb of elements of olon parameter = ' + STRING(N_ELEMENTS(olon)) |
---|
[19] | 234 | ras = report(msg) |
---|
[14] | 235 | msg = ' eee : nb of elements of olon must be equal to jpio*jpjo = ' + STRING(jpio*jpjo) |
---|
[19] | 236 | ras = report(msg) |
---|
[4] | 237 | RETURN |
---|
[14] | 238 | ENDIF ELSE BEGIN |
---|
[18] | 239 | msg = 'iii : valid nb of elements olon parameter' |
---|
[19] | 240 | ras = report(msg) |
---|
[14] | 241 | ENDELSE |
---|
[4] | 242 | ; |
---|
[14] | 243 | ; check values ++ |
---|
[4] | 244 | ; test if ${GEOMAG_OD} defined |
---|
| 245 | geomag_od_env=GETENV('GEOMAG_OD') |
---|
| 246 | CASE geomag_od_env OF |
---|
| 247 | '' : BEGIN |
---|
[6] | 248 | msg = 'eee : ${GEOMAG_OD} is not defined' |
---|
[19] | 249 | ras = report(msg) |
---|
[4] | 250 | RETURN |
---|
| 251 | END |
---|
| 252 | ELSE: BEGIN |
---|
[6] | 253 | msg = 'iii : ${GEOMAG_OD} is ' + geomag_od_env |
---|
[19] | 254 | ras = report(msg) |
---|
[18] | 255 | END |
---|
[4] | 256 | ENDCASE |
---|
| 257 | ; |
---|
| 258 | ; check if output data will be possible |
---|
| 259 | iodirout = isadirectory(geomag_od_env) |
---|
| 260 | ; |
---|
| 261 | ; existence and protection |
---|
| 262 | IF (FILE_TEST(iodirout, /DIRECTORY,/WRITE) EQ 0) THEN BEGIN |
---|
[6] | 263 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
[19] | 264 | ras = report(msg) |
---|
[4] | 265 | RETURN |
---|
| 266 | ENDIF |
---|
| 267 | ; |
---|
[6] | 268 | ; build output filenames |
---|
[14] | 269 | filename = variable.NAME + '_' + orcares +'.nc' |
---|
| 270 | fullfilename = iodirout + filename |
---|
[4] | 271 | ; |
---|
| 272 | ; in order to avoid unexpected overwritten |
---|
[14] | 273 | IF (FILE_TEST(fullfilename) EQ 1) THEN BEGIN |
---|
| 274 | msg = 'eee : the file ' + fullfilename + ' already exists.' |
---|
[19] | 275 | ras = report(msg) |
---|
[4] | 276 | RETURN |
---|
| 277 | ENDIF |
---|
| 278 | ; |
---|
| 279 | ; d'après ncdump -h /usr/work/sur/fvi/OPA/geomag/condmag.nc |
---|
[14] | 280 | ; ces lignes n'ont rien a faire la ++ ces information devrait etre en parameter |
---|
[4] | 281 | condmaglonname = 'lo' |
---|
| 282 | condmaglatname = 'la' |
---|
[14] | 283 | varname = variable.NAME |
---|
[4] | 284 | ; |
---|
| 285 | ;--------------------------- |
---|
[14] | 286 | ; Creation of the NetCdf output file |
---|
[4] | 287 | ;--------------------------- |
---|
| 288 | ; |
---|
[14] | 289 | netcdf_id = NCDF_CREATE(fullfilename, /clobber) |
---|
| 290 | NCDF_CONTROL, netcdf_id, /NOFILL |
---|
[6] | 291 | ; |
---|
[4] | 292 | ; dimension |
---|
[14] | 293 | dimidx = NCDF_DIMDEF(netcdf_id, 'x' , jpio) |
---|
| 294 | dimidy = NCDF_DIMDEF(netcdf_id, 'y' , jpjo) |
---|
| 295 | dimidt = NCDF_DIMDEF(netcdf_id, 'lo', /UNLIMITED) |
---|
[4] | 296 | ; |
---|
| 297 | ; global attributes |
---|
[14] | 298 | NCDF_ATTPUT, netcdf_id, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformite |
---|
| 299 | NCDF_ATTPUT, netcdf_id, 'file_name' , filename, /GLOBAL |
---|
| 300 | NCDF_ATTPUT, netcdf_id, 'Title' , title, /GLOBAL |
---|
[4] | 301 | ; |
---|
| 302 | ; declaration of variables |
---|
| 303 | ; 4 common variables for the two files to produce |
---|
[14] | 304 | varid = lonarr(4) |
---|
[4] | 305 | ; |
---|
[14] | 306 | varid[0] = NCDF_VARDEF(netcdf_id, 'nav_lon' , [dimidx, dimidy], /FLOAT) |
---|
| 307 | NCDF_ATTPUT, netcdf_id, varid[0], 'units' , 'degrees_east' |
---|
[18] | 308 | NCDF_ATTPUT, netcdf_id, varid[0], 'valid_min', min(olon, max = omax), /FLOAT |
---|
| 309 | NCDF_ATTPUT, netcdf_id, varid[0], 'valid_max', omax, /FLOAT |
---|
[14] | 310 | NCDF_ATTPUT, netcdf_id, varid[0], 'long_name', 'Longitude at t-point' |
---|
[4] | 311 | ; |
---|
[14] | 312 | varid[1] = NCDF_VARDEF(netcdf_id, 'nav_lat' , [dimidx, dimidy], /FLOAT) |
---|
| 313 | NCDF_ATTPUT, netcdf_id, varid[1], 'units' , 'degrees_north' |
---|
[18] | 314 | NCDF_ATTPUT, netcdf_id, varid[1], 'valid_min', min(olat, max = omax), /FLOAT |
---|
| 315 | NCDF_ATTPUT, netcdf_id, varid[1], 'valid_max', omax, /FLOAT |
---|
[14] | 316 | NCDF_ATTPUT, netcdf_id, varid[1], 'long_name', 'Latitude at t-point' |
---|
[4] | 317 | ; |
---|
[14] | 318 | varid[2] = NCDF_VARDEF(netcdf_id, 'time' , [dimidt], /FLOAT) |
---|
[4] | 319 | ; |
---|
[14] | 320 | varid[3] = NCDF_VARDEF(netcdf_id, varname, [dimidx, dimidy, dimidt], /FLOAT) |
---|
| 321 | NCDF_ATTPUT, netcdf_id, varid[3], 'long_name', long_name |
---|
| 322 | NCDF_ATTPUT, netcdf_id, varid[3], 'units', units |
---|
[4] | 323 | ; pour min et max, il faut avoir lu la variable ... cf. plus bas ++ |
---|
| 324 | ; donc pour l'instant on les met à valeur manquante |
---|
[18] | 325 | NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', !VALUES.F_NAN, /FLOAT |
---|
| 326 | NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', !VALUES.F_NAN, /FLOAT |
---|
[6] | 327 | ; |
---|
[4] | 328 | ;--------------------------- |
---|
[6] | 329 | ; end of header definition, writing of the NetCdf files |
---|
[4] | 330 | ;--------------------------- |
---|
[6] | 331 | ; |
---|
[14] | 332 | NCDF_CONTROL, netcdf_id, /ENDEF |
---|
| 333 | ; |
---|
| 334 | NCDF_VARPUT, netcdf_id, 'nav_lon', olon |
---|
| 335 | NCDF_VARPUT, netcdf_id, 'nav_lat', olat |
---|
| 336 | NCDF_VARPUT, netcdf_id, varid[2], FLOAT(0.5) ; ++ c'est quoi cette valeur |
---|
[4] | 337 | ; |
---|
| 338 | ; compute min max |
---|
[14] | 339 | minarr = min(values, max = maxarr) |
---|
[4] | 340 | ; |
---|
| 341 | ; put back the masked value |
---|
[14] | 342 | ;++ IF bad[0] NE -1 THEN values[TEMPORARY(bad)] = 32767 |
---|
[4] | 343 | ; |
---|
| 344 | ; write the data |
---|
[14] | 345 | NCDF_VARPUT, netcdf_id, varname, values, COUNT = [jpio, jpjo, 1], OFFSET = [0, 0, 0] |
---|
[4] | 346 | ; |
---|
| 347 | ; update min max attributes |
---|
[14] | 348 | NCDF_CONTROL, netcdf_id, /REDEF |
---|
[18] | 349 | NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', minarr, /FLOAT |
---|
| 350 | NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', maxarr, /FLOAT |
---|
[14] | 351 | NCDF_CONTROL, netcdf_id, /ENDEF |
---|
[4] | 352 | ; |
---|
[6] | 353 | ; close the netcdf files |
---|
[14] | 354 | NCDF_CLOSE, netcdf_id |
---|
[6] | 355 | ; |
---|
[14] | 356 | msg = 'iii : ' + fullfilename + ' created' |
---|
[19] | 357 | ras = report(msg) |
---|
[4] | 358 | ; |
---|
| 359 | END |
---|