;+ ; ; @file_comments ; interpolate cond_sed_orcares.nc and Br_orcares.nc ; and produce condmag_from_orcares.nc file ; ; condmag_from_orcares.nc might be compare to condmag.nc ; ; NB : cond_oc and cond_tot won't be reproduced ; ++ should I write missing values ? ; ; inverse of condmag_on_orca ; ; @categories ; interpolation, orca grid ; ; @param orcares {in}{required}{type=string} ; code of ORCA grid to use for output results ; must be 'ORCA2' or 'ORCA025' ; ; @param method {in}{required}{type=string} ; code for interpolation method ; must be 'bilinear' ; parameter is therefore here to be visible. see restrictions below. ; ; @param gridtype {in}{required}{type=string} ; to specify on which grid we do the interpolation T, U, V ; must belong to T, U or V ; ++ je ne sais pas comment ce paramètre doit intervenir ; ; @keyword DRAKKAR_EXP ; code for Drakkar experiment ; only used when orcares = ORCA025 ; must be G42 ++ G70 ; ++ je ne sais pas comment ce paramètre doit intervenir a priori ; la partie mesh est la même pour toutes les expériences mais attention ; pas forcément le mask. ; ; @keyword PERF ; if set activate performance with profiler ; PERF vs key_performance dans les commons ; ; @restrictions ; - Requires SAXO ; - won't be relevant if 'imoms3' was used as interpolation method in ; condmag_on_orca ; ; @todo ; add version variable inside code ; provide tools to plot output files ; produce a NetCDF GDT or CF compliant ; ; @pre ; see geomag_profile.sh ; ; be sure to have cond_sed_*.nc and Br_*.nc in the directory defined ; in ${GEOMAG_ID}/ ; be sure to have condmag.nc in the directory defined ; in ${GEOMAG_ID}/ ; be sure to not have condmag_from_*.nc in the directory defined in ; ${GEOMAG_OD}/ ; be sure to have meshmask of ORCA grid you choose in the directory defined in ; ${GEOMAG_ID}/ ; for ORCA2 filename is meshmask_bab.nc ; ++ au pif entre mesh_hgr, mesh_zgr et mask ; for ORCA025 filename is ORCA025-G42_mesh_hgr.nc ; ; @post ; see geomag_profile.sh ; condmag_from_orcares.nc is now present in ${GEOMAG_OD}/ ; ; @examples ; IDL> .run condmag_from_orca ; IDL> condmag_from_orca, 'ORCA2', 'bilinear','T' ; ; @history ; reee522 2007-06-06T15:14:24Z rhodes (IRIX64) ; replace call of initorca2_bab by initocemesh ; reee522 2007-06-06T14:57:39Z rhodes (IRIX64) ; correction for DRAKKAR_EXP usage ; fplod 2007-03-21T13:23:55Z aedon.locean-ipsl.upmc.fr (Darwin) ; create from condmag_on_orca to validate step1 of GEOMAG ; ; @version ; $Id$ ; ;- PRO condmag_from_orca, orcares, method, gridtype, DRAKKAR_EXP = drakkar_exp, PERF = perf ; compile_opt idl2, strictarrsubs ; IF keyword_set(perf) EQ 1 THEN BEGIN msg = 'iii : start profiler' ras = report(msg) ;PROFILER, /SYSTEM & PROFILER PROFILER, /SYSTEM & PROFILER ; ++ ne tracera que les modules compilés au moment de l'appel à cette commande ; donc ++ regarder si on a bien tout et si on doit ajouter des PROFILER,toto dans ; tous les modules ENDIF ; ;---- ; check input parameters ;---- ; ; check orcares definition ; CASE orcares OF 'ORCA2': BEGIN msg = 'iii : valid orcares parameter = ' + orcares ras = report(msg) filename_oce = 'meshmask_bab.nc' IF keyword_set(DRAKKAR_EXP) THEN BEGIN msg = 'www : unused DRAKKAR_EXP keyword = ' + drakkar_exp ras = report(msg) END END 'ORCA025': BEGIN msg = 'iii : valid orcares parameter = ' + orcares ras = report(msg) IF keyword_set(DRAKKAR_EXP) THEN BEGIN msg = 'iii : DRAKKAR_EXP keyword set' ras = report(msg) msg = 'iii : DRAKKAR_EXP = ' + drakkar_exp ras = report(msg) CASE drakkar_exp OF 'G42' : BEGIN msg = 'iii : valid DRAKKAR_EXP keyword = ' + drakkar_exp ras = report(msg) END 'G70' : BEGIN msg = 'iii : valid DRAKKAR_EXP keyword = ' + drakkar_exp ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid DRAKKAR_EXP keyword = ' + drakkar_exp ras = report(msg) RETURN END ENDCASE filename_oce = orcares + '-' + drakkar_exp + '_mesh_hgr.nc' ENDIF ELSE BEGIN msg = 'eee : unset DRAKKAR_EXP keyword' ras = report(msg) msg = 'eee : orcares must be G42 or G70' ras = report(msg) RETURN ENDELSE 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 method definition CASE method OF 'bilinear': BEGIN msg = 'iii : valid method parameter = ' + method ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid method parameter = ' + method ras = report(msg) msg = 'eee : method must be bilinear' ras = report(msg) RETURN END ENDCASE ; ; check gridtype definition gridtype = strupcase(gridtype) CASE gridtype OF 'T' : BEGIN msg = 'iii : valid gridtype parameter = ' + gridtype ras = report(msg) END 'U' : BEGIN msg = 'iii : valid gridtype parameter = ' + gridtype ras = report(msg) END 'V' : BEGIN msg = 'iii : valid gridtype parameter = ' + gridtype ras = report(msg) END ELSE : BEGIN msg = 'eee : invalid gridtype parameter = ' + gridtype ras = report(msg) msg = 'eee : gridtype must be T, U or V' ras = report(msg) RETURN END ENDCASE ; ; check for input files ; ; test if ${GEOMAG_ID} defined geomag_id_env=GETENV('GEOMAG_ID') CASE geomag_id_env OF '' : BEGIN msg = 'eee : ${GEOMAG_ID} is not defined' ras = report(msg) RETURN END ELSE: BEGIN msg = 'iii : ${GEOMAG_ID} is ' + geomag_id_env ras = report(msg) END ENDCASE ; iodirin = isadirectory(geomag_id_env) ; ; existence and protection of ${GEOMAG_ID} IF (FILE_TEST(iodirin, /DIRECTORY,/EXECUTABLE , /READ) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirin + ' is not accessible.' ras = report(msg) RETURN ENDIF ; ; build input filenames filename_cond_sed = 'cond_sed' + '_' + orcares +'.nc' fullfilename_cond_sed = iodirin + filename_cond_sed ; ; check if this file exists fullfilename_cond_sed = isafile(iodirin + filename_cond_sed, NEW=0,/MUST_EXIST) IF fullfilename_cond_sed[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_cond_sed + ' was not found.' ras = report(msg) RETURN ENDIF ; ; protection IF (FILE_TEST(fullfilename_cond_sed[0], /READ) EQ 0) THEN BEGIN msg = 'eee : the file ' + fullfilename_cond_sed[0] + ' is not readable.' ras = report(msg) RETURN ENDIF ; filename_Br = 'Br' + '_' + orcares +'.nc' fullfilename_Br = iodirin + filename_Br ; ; check if this file exists fullfilename_Br = isafile(iodirin + filename_Br, NEW=0,/MUST_EXIST) IF fullfilename_Br[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_Br + ' was not found.' ras = report(msg) RETURN ENDIF ; ; protection IF (FILE_TEST(fullfilename_Br[0], /READ) EQ 0) THEN BEGIN msg = 'eee : the file ' + fullfilename_Br[0] + ' is not readable.' ras = report(msg) RETURN ENDIF ; ; mesh mask ; check if this file exists fullfilename_oce = isafile(iodirin + filename_oce, NEW=0, /MUST_EXIST, $ RECURSIVE=0) IF fullfilename_oce[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_oce + ' was not found.' ras = report(msg) RETURN ENDIF ; ; protection IF (FILE_TEST(fullfilename_oce[0], /READ) EQ 0) THEN BEGIN msg = 'eee : the file ' + fullfilename_oce[0] + ' is not readable.' ras = report(msg) RETURN ENDIF ; filename_condmag = 'condmag.nc' fullfilename_condmag = iodirin + filename_condmag ; ; check if this file exists fullfilename_condmag = isafile(iodirin + filename_condmag, NEW=0,/MUST_EXIST) IF fullfilename_condmag[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_condmag + ' was not found.' ras = report(msg) RETURN ENDIF ; ; protection IF (FILE_TEST(fullfilename_condmag[0], /READ) EQ 0) THEN BEGIN msg = 'eee : the file ' + fullfilename_condmag[0] + ' is not readable.' ras = report(msg) RETURN ENDIF ; ; 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 filename filename = 'condmag_from_' + 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 ; ;---- ; Oceanic grid parameters ie input grid + mask ;---- ; initocemesh, orcares, DRAKKAR_EXP = drakkar_exp ; ;---- ; read data to interpolate on regular grid ;---- ; a=read_ncdf('cond_sed', 0, /timestep, $ file = fullfilename_cond_sed[0], /nostruct) msg = 'iii : ' + fullfilename_cond_sed[0] + ' opened for read' ras = report(msg) ; mask and limite cond_sed on values below 5000 ++ cond_sedin = extrapsmooth(a, tmask[*, *, 0]*(a le 5000), /x_periodic) ; b = read_ncdf('Br', 0, /timestep, $ file = fullfilename_Br[0], /nostruct) msg = 'iii : ' + fullfilename_Br[0] + ' opened for read' ras = report(msg) ; mask and limit Br on values below/above ++ Brin = extrapsmooth(b, tmask[*, *, 0]*(b), /x_periodic) ; glamin = glamt gphiin = gphit maskin = tmask[*, *, 0] ; ;--- ; conductivity and magnetic field grid parameters ie output grid ;---- initncdf, fullfilename_condmag[0], xaxisname = 'lo', yaxisname = 'la' msg = 'iii : ' + fullfilename_condmag[0] + ' opened for read' ras = report(msg) ; glamout = glamt gphiout = gphit ; dimidxout = jpi dimidyout = jpj ; ;--------------- ; Interpolate ;--------------- ;++ cond_sedout = fromirr('bilinear', cond_sedin, glamin, gphiin, maskin, glamout, gphiout, -1, WEIG = weights, ADDR = addresses) cond_sedout=dindgen(dimidxout,dimidyout) ;Brout=fromirr('bilinear', Brin, weights, addresses) ; ++ pb doc % Variable is undefined: LONOUT ;++Brout = fromirr('bilinear', Brin, glamin, gphiin, maskin, glamout, gphiout, -1, WEIG = weights, ADDR = addresses) ; Brout=dindgen(dimidxout,dimidyout) ; ;--------------- ; Produce outputs ;--------------- ; netcdf_id = NCDF_CREATE(fullfilename, /clobber) NCDF_CONTROL, netcdf_id, /NOFILL ; ; dimension dimidxout = NCDF_DIMDEF(netcdf_id, 'la' , jpi) dimidyout = NCDF_DIMDEF(netcdf_id, 'lo' , jpj) ; ; 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 varid = lonarr(4) ; varid[0] = NCDF_VARDEF(netcdf_id, 'la' , [dimidxout], /FLOAT) varid[1] = NCDF_VARDEF(netcdf_id, 'lo' , [dimidyout], /FLOAT) varid[2] = NCDF_VARDEF(netcdf_id, 'cond_sed' , [dimidxout, dimidyout], /FLOAT) NCDF_ATTPUT, netcdf_id, varid[2], 'units' , 'siemens' varid[3] = NCDF_VARDEF(netcdf_id, 'Br' , [dimidxout, dimidyout], /FLOAT) NCDF_ATTPUT, netcdf_id, varid[3], 'units' , 'siemens' ; NCDF_CONTROL, netcdf_id, /ENDEF ; NCDF_VARPUT, netcdf_id, varid[0], dindgen(dimidxout,dimidyout) NCDF_VARPUT, netcdf_id, varid[1], dindgen(dimidyout,dimidyout) ; ; write the data ; NCDF_VARPUT, netcdf_id, varid[2], cond_sedout ;++ NCDF_VARPUT, netcdf_id, 'Br', Brout ;--------------------------- ; close the netcdf files NCDF_CLOSE, netcdf_id ; msg = 'iii : ' + fullfilename + ' created' ras = report(msg) ; IF keyword_set(perf) EQ 1 THEN BEGIN msg = 'iii : report profiler results' ras = report(msg) ; ++ tri par ordre alpha , par ordre de pourcentage croissant ou décroissant ; +++ d'utilisation profiler,/REPORT ; shut down all profiling (according to ; http://www.dfanning.com/code_tips/whyslow.html) profiler, /CLEAR, /SYSTEM profiler, /CLEAR, /RESET ENDIF ; END