;+ ; ; @file_comments ; produce cond_sed_.nc or Br_.nc ; dependent on orcares and variable parameters ; ; @categories ; output, netcdf ; ; @param orcares {in}{required}{type=string} ; code of ORCA grid to use for output results ; must be 'ORCA2' or 'ORCA025' ; ; @param variable {in}{required}{type=structure return by NCDF_VARINQ} ; { NAME:"", DATATYPE:"", NDIMS:0L, NATTS:0L, DIM:LONARR(NDIMS) } ; variable of condmag.nc to be written ; variable.NAME must be 'cond_sed' or 'Br' ; ; @param title {in}{required}{type=string} ; title must belong_name 'Conductance' or 'Magnetic_field' ++ ; ; @param long_name {in}{required}{type=string} ; long_name must be 'Conductance' or 'magnetic_field' ++ ; ; @param units {in}{required}{type=string} ; units must be 'siemens' or 'tesla' ; ; @param jpio {in}{required}{type=integer} ; x dimension of the 3d array to be written ; must be greater than 1 ; ; @param jpjo {in}{required}{type=integer} ; y dimension of the 3d array to be written ; must be greater than 1 ; ; @param olon {in}{required}{type=1d array of floats} ; x++ longitude values ; must be ++ ; ; @param olat {in}{required}{type=1d array of floats} ; x++ latitude values ; must be ++ ; ; @param values {in}{required}{type=nd array of variable.DATATYPE} ; values of the variable to be written ; ++ must be ; ; @restrictions ; - Requires SAXO tools ; ; @todo ; produce a NetCDF GDT or CF compliant ; check if jpio and jpjo are not present in some "common" after getgridparam ; in order to remove them from parameters ; ; @pre ; reading of condmag.nc ; see condmag_on_orca.pro ; ; @post ; cond_sed_orcasres.nc is now present in ${GEOMAG_OD}/ ; or ; Br_orcasres.nc is now present in ${GEOMAG_OD}/ ; see geomag_env.sh ; ; @examples ; IDL> .run condmag_on_orca ; IDL> condmag_output, 'ORCA2', 'cond_sed', 'Conductance', 'Conductance', 'siemens', jpio, jpjo, olon, olat, values ; ; @history ; reee522 2006-12-13T11:44:19Z rhodes (IRIX64) ; add attributes in parameters list ; reee522 2006-11-28T14:07:32Z rhodes (IRIX64) ; written from current release of condmag_on_orca.pro ; ; @version ; $Id$ ; ;- PRO condmag_output, orcares, variable, title, long_name, units, jpio, jpjo, olon, olat, values ; compile_opt idl2, strictarrsubs ; ;---- ; check input parameters ;---- ; ; check orcares definition ; CASE orcares OF 'ORCA2': BEGIN msg = 'iii : valid orcares parameter = ' + orcares ras = report(msg) END 'ORCA025': BEGIN msg = 'iii : valid orcares parameter = ' + orcares ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid orcares parameter = ' + orcares ras = report(msg) msg = 'eee : orcares must be ORCA2 or ORCA025' ras = report(msg) RETURN END ENDCASE ; ; check variable definition ; ++ dimension etc. CASE variable.NAME OF 'cond_sed': BEGIN msg = 'iii : valid variable.NAME parameter = ' + variable.NAME ras = report(msg) CASE title OF 'Conductance': BEGIN msg = 'iii : valid title parameter = ' + title ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid title parameter = ' + title ras = report(msg) msg = 'eee : title must be Conductance' ras = report(msg) RETURN END ENDCASE CASE long_name OF 'Conductance': BEGIN msg = 'iii : valid long_name parameter = ' + long_name ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid long_name parameter = ' + long_name ras = report(msg) msg = 'eee : long_name must be Conductance' ras = report(msg) RETURN END ENDCASE CASE units OF 'siemens': BEGIN msg = 'iii : valid units parameter = ' + units ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid units parameter = ' + units ras = report(msg) msg = 'eee : units must be siemens' ras = report(msg) RETURN END ENDCASE END 'Br' : BEGIN msg = 'iii : valid variable.NAME parameter = ' + variable.NAME ras = report(msg) CASE title OF 'Magnetic field': BEGIN msg = 'iii : valid title parameter = ' + title ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid title parameter = ' + title ras = report(msg) msg = 'eee : title must be Magnetic field' ras = report(msg) RETURN END ENDCASE CASE long_name OF 'magnetic field': BEGIN msg = 'iii : valid long_name parameter = ' + long_name ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid long_name parameter = ' + long_name ras = report(msg) msg = 'eee : long_name must be magnetic field' ras = report(msg) RETURN END ENDCASE CASE units OF 'tesla': BEGIN msg = 'iii : valid units parameter = ' + units ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid units parameter = ' + units ras = report(msg) msg = 'eee : units must be tesla' ras = report(msg) RETURN END ENDCASE END ELSE : BEGIN msg = 'eee : invalid variable.NAME parameter = ' + variable.NAME ras = report(msg) msg = 'eee : variable.NAME must be cond_sed or Br' ras = report(msg) RETURN END ENDCASE ; ; check jpio IF (jpio LT 1) THEN BEGIN msg = ' eee : invalid jpio parameter = ' + STRING(jpio) ras = report(msg) msg = ' eee : jpio must be greater or equal to 1' ras = report(msg) RETURN ENDIF ELSE BEGIN msg = 'iii : valid jpio parameter = ' + STRING(jpio) ras = report(msg) ENDELSE ; ; check jpjo IF (jpjo LT 1) THEN BEGIN msg = ' eee : invalid jpjo parameter = ' + STRING(jpjo) ras = report(msg) msg = ' eee : jpjo must be greater or equal to 1' ras = report(msg) RETURN ENDIF ELSE BEGIN msg = 'iii : valid jpjo parameter = ' + STRING(jpjo) ras = report(msg) ENDELSE ; ; check olon ++ what to check ; when decided reproduce with olat ++ IF (N_ELEMENTS(olon) NE jpio*jpjo) THEN BEGIN msg = ' eee : invalid nb of elements of olon parameter = ' + STRING(N_ELEMENTS(olon)) ras = report(msg) msg = ' eee : nb of elements of olon must be equal to jpio*jpjo = ' + STRING(jpio*jpjo) ras = report(msg) RETURN ENDIF ELSE BEGIN msg = 'iii : valid nb of elements olon parameter' ras = report(msg) ENDELSE ; ; check values ++ ; test if ${GEOMAG_OD} defined geomag_od_env=GETENV('GEOMAG_OD') CASE geomag_od_env OF '' : BEGIN msg = 'eee : ${GEOMAG_OD} is not defined' ras = report(msg) RETURN END ELSE : BEGIN msg = 'iii : ${GEOMAG_OD} is ' + geomag_od_env ras = report(msg) END ENDCASE ; ; check if output data will be possible iodirout = isadirectory(geomag_od_env) ; ; existence and protection IF (FILE_TEST(iodirout, /DIRECTORY,/WRITE) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirout + ' was not found.' ras = report(msg) RETURN ENDIF ; ; build output filenames filename = variable.NAME + '_' + orcares +'.nc' fullfilename = iodirout + filename ; ; in order to avoid unexpected overwritten IF (FILE_TEST(fullfilename) EQ 1) THEN BEGIN msg = 'eee : the file ' + fullfilename + ' already exists.' ras = report(msg) RETURN ENDIF ; ; d'après ncdump -h /usr/work/sur/fvi/OPA/geomag/condmag.nc ; ces lignes n'ont rien a faire la ++ ces information devrait etre en parameter condmaglonname = 'lo' condmaglatname = 'la' varname = variable.NAME ; ;--------------------------- ; Creation of the NetCdf output file ;--------------------------- ; netcdf_id = NCDF_CREATE(fullfilename, /clobber) NCDF_CONTROL, netcdf_id, /NOFILL ; ; dimension dimidx = NCDF_DIMDEF(netcdf_id, 'x' , jpio) dimidy = NCDF_DIMDEF(netcdf_id, 'y' , jpjo) dimidt = NCDF_DIMDEF(netcdf_id, 'lo', /UNLIMITED) ; ; global attributes NCDF_ATTPUT, netcdf_id, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformite NCDF_ATTPUT, netcdf_id, 'file_name' , filename, /GLOBAL NCDF_ATTPUT, netcdf_id, 'Title' , title, /GLOBAL ; ; declaration of variables ; 4 common variables for the two files to produce varid = lonarr(4) ; varid[0] = NCDF_VARDEF(netcdf_id, 'nav_lon' , [dimidx, dimidy], /FLOAT) NCDF_ATTPUT, netcdf_id, varid[0], 'units' , 'degrees_east' NCDF_ATTPUT, netcdf_id, varid[0], 'valid_min', min(olon, max = omax), /FLOAT NCDF_ATTPUT, netcdf_id, varid[0], 'valid_max', omax, /FLOAT NCDF_ATTPUT, netcdf_id, varid[0], 'long_name', 'Longitude at t-point' ; varid[1] = NCDF_VARDEF(netcdf_id, 'nav_lat' , [dimidx, dimidy], /FLOAT) NCDF_ATTPUT, netcdf_id, varid[1], 'units' , 'degrees_north' NCDF_ATTPUT, netcdf_id, varid[1], 'valid_min', min(olat, max = omax), /FLOAT NCDF_ATTPUT, netcdf_id, varid[1], 'valid_max', omax, /FLOAT NCDF_ATTPUT, netcdf_id, varid[1], 'long_name', 'Latitude at t-point' ; varid[2] = NCDF_VARDEF(netcdf_id, 'time' , [dimidt], /FLOAT) ; varid[3] = NCDF_VARDEF(netcdf_id, varname, [dimidx, dimidy, dimidt], /FLOAT) NCDF_ATTPUT, netcdf_id, varid[3], 'long_name', long_name NCDF_ATTPUT, netcdf_id, varid[3], 'units', units ; pour min et max, il faut avoir lu la variable ... cf. plus bas ++ ; donc pour l'instant on les met à valeur manquante NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', !VALUES.F_NAN, /FLOAT NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', !VALUES.F_NAN, /FLOAT ; ;--------------------------- ; end of header definition, writing of the NetCdf files ;--------------------------- ; NCDF_CONTROL, netcdf_id, /ENDEF ; NCDF_VARPUT, netcdf_id, 'nav_lon', olon NCDF_VARPUT, netcdf_id, 'nav_lat', olat NCDF_VARPUT, netcdf_id, varid[2], FLOAT(0.5) ; ++ c'est quoi cette valeur ; ; compute min max minarr = min(values, max = maxarr) ; ; put back the masked value ;++ IF bad[0] NE -1 THEN values[TEMPORARY(bad)] = 32767 ; ; write the data NCDF_VARPUT, netcdf_id, varname, values, COUNT = [jpio, jpjo, 1], OFFSET = [0, 0, 0] ; ; update min max attributes NCDF_CONTROL, netcdf_id, /REDEF NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', minarr, /FLOAT NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', maxarr, /FLOAT NCDF_CONTROL, netcdf_id, /ENDEF ; ; close the netcdf files NCDF_CLOSE, netcdf_id ; msg = 'iii : ' + fullfilename + ' created' ras = report(msg) END