Index: /trunk/condmag_on_orca.pro
===================================================================
--- /trunk/condmag_on_orca.pro	(revision 13)
+++ /trunk/condmag_on_orca.pro	(revision 14)
@@ -21,4 +21,9 @@
 ; to specify on which grid we do the interpolation T, U, V
 ; must belong to T, U or V
+;
+; @keyword DRAKKAR_EXP {type=string}
+; code for Drakkar experiment
+; only used when orcares = ORC025
+; must be G42 ++ G70
 ;
 ; @restrictions
@@ -40,5 +45,5 @@
 ; for ORCA2 filename is meshmask_bab.nc
 ; ++ au pif entre mesh_hgr, mesh_zgr et mask
-; for ORCA0252 filename is ORCA025-G42_mesh_hgr.nc 
+; for ORCA0252 filename is ORCA025-G42_mesh_hgr.nc
 ;
 ; @post
@@ -52,4 +57,8 @@
 ;
 ; @history
+; reee522 2006-12-13T13:50:32Z rhodes (IRIX64)
+; add optional keyword drakkar_exp
+; reee522 2006-12-13T12:09:05Z rhodes (IRIX64)
+; externalisation of netcdf writing
 ; reee522 2006-11-23T13:34:31Z rhodes (IRIX64)
 ; add ORCA025 (beginning)
@@ -63,5 +72,5 @@
 ; ++ not very beautifuly implemented
 ; fplod 2006-11-22T10:38:51Z aedon.locean-ipsl.upmc.fr (Darwin)
-; always use msg = 'iii : ...' or msg = 'eee : ...' 
+; always use msg = 'iii : ...' or msg = 'eee : ...'
 ; information on open io
 ; fplod 2006-11-20T10:32:02Z aedon.locean-ipsl.upmc.fr (Darwin)
@@ -82,5 +91,5 @@
 ;
 ;-
-PRO condmag_on_orca, orcares, method, gridtype
+PRO condmag_on_orca, orcares, method, gridtype, DRAKKAR_EXP = drakkar_exp
 ;
   compile_opt idl2, strictarrsubs
@@ -94,12 +103,37 @@
   CASE orcares OF
      'ORCA2': BEGIN
-                 msg = 'iii : valid orcares parameter = ' +  orcares
+                 msg = 'iii : valid orcares parameter = ' + orcares
                  PRINT, msg
                  filename_oce = 'meshmask_bab.nc'
+                 IF keyword_set(DRAKKAR_EXP) THEN BEGIN
+                    msg = 'www : unused DRAKKAR_EXP keyword = ' + drakkar_exp
+                    PRINT, msg
+                 END
               END
      'ORCA025': BEGIN
-                 msg = 'iii : valid orcares parameter = ' +  orcares
+                 msg = 'iii : valid orcares parameter = ' + orcares
                  PRINT, msg
-                 filename_oce = orcares + '-G42_mesh_hgr.nc' 
+                 IF keyword_set(DRAKKAR_EXP) THEN BEGIN
+                    msg = 'iii : DRAKKAR_EXP keyword set'
+                    PRINT, msg
+                    msg = 'iii : DRAKKAR_EXP = ' + drakkar_exp
+                    PRINT, msg
+                    CASE drakkar_exp OF
+                       'G42' : BEGIN
+                                  msg = 'iii : valid DRAKKAR_EXP keyword = ' + drakkar_exp
+                                  PRINT, msg
+                               END
+                       'G70' : BEGIN
+                                  msg = 'iii : valid DRAKKAR_EXP keyword = ' + drakkar_exp
+                                  PRINT, msg
+                               END
+                       ELSE : BEGIN
+                                  msg = 'eee : invalid DRAKKAR_EXP keyword = ' + drakkar_exp
+                                  PRINT, msg
+                                  RETURN
+                              END
+                    ENDCASE
+                    filename_oce = orcares + '-' + drakkar_exp + '_mesh_hgr.nc'
+                 END
               END
       ELSE  : BEGIN
@@ -123,5 +157,5 @@
                  END
      ELSE      : BEGIN
-                    msg = 'eee : invalid method parameter = ' + method 
+                    msg = 'eee : invalid method parameter = ' + method
                     PRINT, msg
                     msg = 'eee : method must be bilinear or imoms3'
@@ -147,5 +181,5 @@
            END
      ELSE: BEGIN
-              msg = 'eee : invalid gridtype parameter = ' + gridtype 
+              msg = 'eee : invalid gridtype parameter = ' + gridtype
               PRINT, msg
               msg = 'eee : gridtype must be T, U or V'
@@ -168,5 +202,5 @@
              msg = 'iii : ${GEOMAG_ID} is ' + geomag_id_env
              PRINT, msg
-           END 
+           END
   ENDCASE
 ;
@@ -200,5 +234,6 @@
 ; mesh mask
 ; check if this file exists
-  fullfilename_oce = isafile(iodirin + filename_oce, NEW=0,/MUST_EXIST, RECURSIVE=0)
+  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.'
@@ -225,5 +260,5 @@
              msg = 'iii : ${GEOMAG_OD} is ' + geomag_od_env
              PRINT, msg
-           END 
+           END
   ENDCASE
 ;
@@ -238,30 +273,7 @@
   ENDIF
 ;
-; build output filenames
-  filename_cond_sed = 'cond_sed' + '_' + orcares +'.nc'
-  fullfilename_cond_sed = iodirout + filename_cond_sed
-;
-; in order to avoid unexpected overwritten
-  IF (FILE_TEST(fullfilename_cond_sed) EQ 1) THEN BEGIN
-     msg = 'eee : the file ' + fullfilename_cond_sed  + ' already exists.'
-     PRINT, msg
-     RETURN
-  ENDIF
-;
-  filename_br = 'Br' + '_' + orcares +'.nc'
-  fullfilename_br = iodirout + filename_br
-;
-; in order to avoid unexpected overwritten
-  IF (FILE_TEST(fullfilename_br) EQ 1) THEN BEGIN
-     msg = 'eee : the file ' + fullfilename_br  + ' already exists.'
-     PRINT, msg
-     RETURN
-  ENDIF
-;
 ; d'après ncdump -h /usr/work/sur/fvi/OPA/geomag/condmag.nc
   condmaglonname = 'lo'
   condmaglatname = 'la'
-  varname_cond_sed = 'cond_sed'
-  varname_br = 'Br'
 ;
 ;----
@@ -300,110 +312,17 @@
   msg = 'iii : ' + fullfilename_condmag[0] + ' opened for read'
   PRINT, msg
-  
+;
+  varname_cond_sed = 'cond_sed'
+  varname_br = 'Br'
+;
   varinq_cond_sed = NCDF_VARINQ(netcdf_id_condmag, varname_cond_sed)
+  NCDF_VARGET, netcdf_id_condmag, varname_cond_sed, varin_cond_sed
+;
   varinq_br = NCDF_VARINQ(netcdf_id_condmag, varname_br)
+  NCDF_VARGET, netcdf_id_condmag, varname_br, varin_br
+;
+  NCDF_CLOSE, netcdf_id_condmag
 ;
 ;---------------------------
-; Creation of the NetCdf file for cond_sed and Br
-;---------------------------
-;
-  netcdf_id_cond_sed = NCDF_CREATE(fullfilename_cond_sed, /clobber)
-  NCDF_CONTROL, netcdf_id_cond_sed, /NOFILL
-  netcdf_id_br = NCDF_CREATE(fullfilename_br, /clobber)
-  NCDF_CONTROL, netcdf_id_br, /NOFILL
-;
-; dimension
-  dimidx = NCDF_DIMDEF(netcdf_id_cond_sed, 'x' ,  jpio)
-  dimidy = NCDF_DIMDEF(netcdf_id_cond_sed, 'y' ,  jpjo)
-  dimidt = NCDF_DIMDEF(netcdf_id_cond_sed, 'lo', /UNLIMITED)
-  dimidx = NCDF_DIMDEF(netcdf_id_br, 'x' ,  jpio)
-  dimidy = NCDF_DIMDEF(netcdf_id_br, 'y' ,  jpjo)
-  dimidt = NCDF_DIMDEF(netcdf_id_br, 'lo', /UNLIMITED)
-;
-; global attributes
-  NCDF_ATTPUT, netcdf_id_cond_sed, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformité
-  NCDF_ATTPUT, netcdf_id_cond_sed, 'file_name'  , filename_cond_sed, /GLOBAL
-  NCDF_ATTPUT, netcdf_id_cond_sed, 'Title'      , 'Conductance', /GLOBAL
-  NCDF_ATTPUT, netcdf_id_br, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformité
-  NCDF_ATTPUT, netcdf_id_br, 'file_name'  , filename_Br, /GLOBAL
-  NCDF_ATTPUT, netcdf_id_br, 'Title'      , 'Magnetic field', /GLOBAL
-;
-; declaration of variables
-; 4 common variables for the two files to produce
-  varid = lonarr(3)
-;
-  varid[0] = NCDF_VARDEF(netcdf_id_cond_sed, 'nav_lon'  , [dimidx, dimidy], /FLOAT)
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'units'    , 'degrees_east'
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'valid_min', min(olon, max = omax),/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'valid_max', omax,/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[0], 'long_name', 'Longitude at t-point'
-  varid[0] = NCDF_VARDEF(netcdf_id_br, 'nav_lon'  , [dimidx, dimidy], /FLOAT)
-  NCDF_ATTPUT, netcdf_id_br, varid[0], 'units'    , 'degrees_east'
-  NCDF_ATTPUT, netcdf_id_br, varid[0], 'valid_min', min(olon, max = omax),/FLOAT
-  NCDF_ATTPUT, netcdf_id_br, varid[0], 'valid_max', omax,/FLOAT
-  NCDF_ATTPUT, netcdf_id_br, varid[0], 'long_name', 'Longitude at t-point'
-;
-  varid[1] = NCDF_VARDEF(netcdf_id_cond_sed, 'nav_lat'  , [dimidx, dimidy], /FLOAT)
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'units'    , 'degrees_north'
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'valid_min', min(olat, max = omax),/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'valid_max', omax,/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid[1], 'long_name', 'Latitude at t-point'
-  varid[1] = NCDF_VARDEF(netcdf_id_br, 'nav_lat'  , [dimidx, dimidy], /FLOAT)
-  NCDF_ATTPUT, netcdf_id_br, varid[1], 'units'    , 'degrees_north'
-  NCDF_ATTPUT, netcdf_id_br, varid[1], 'valid_min', min(olat, max = omax),/FLOAT
-  NCDF_ATTPUT, netcdf_id_br, varid[1], 'valid_max', omax,/FLOAT
-  NCDF_ATTPUT, netcdf_id_br, varid[1], 'long_name', 'Latitude at t-point'
-;
-  varid[2] = NCDF_VARDEF(netcdf_id_cond_sed, 'time'     , [dimidt], /FLOAT)
-  varid[2] = NCDF_VARDEF(netcdf_id_br, 'time'     , [dimidt], /FLOAT)
-;
-; each of the two files to produce contains a specific variable
-;
-  varid_cond_sed = lonarr(1)
-  varid_cond_sed[0] = NCDF_VARDEF(netcdf_id_cond_sed, varname_cond_sed, [dimidx, dimidy, dimidt], /FLOAT)
-;
-; variable 3
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'long_name', 'Conductance' ; ++ non cf 
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'units', 'siemens' ; ++ récupérer l'unite de cond_sed dans condmag.nc
-; 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_cond_sed, varid_cond_sed[0], 'valid_min', !VALUES.F_NAN ,/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_max', !VALUES.F_NAN ,/FLOAT
-;
-  varid_br = lonarr(1)
-  varid_br[0] = NCDF_VARDEF(netcdf_id_br, varname_br, [dimidx, dimidy, dimidt], /FLOAT)
-;
-; variable 3
-  NCDF_ATTPUT, netcdf_id_br, varid_br[0], 'long_name', 'magnetic field' ; ++ non cf 
-  NCDF_ATTPUT, netcdf_id_br, varid_br[0], 'units', 'tesla' ; ++ récupérer l'unité de Br dans condmag.nc
-; 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_br, varid_br[0], 'valid_min', !VALUES.F_NAN ,/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_max', !VALUES.F_NAN ,/FLOAT
-;
-;---------------------------
-; end of header definition, writing of the NetCdf files
-;---------------------------
-  NCDF_CONTROL, netcdf_id_cond_sed, /ENDEF
-  NCDF_CONTROL, netcdf_id_br, /ENDEF
-  NCDF_CLOSE, netcdf_id_condmag ; ++ si le close n'est pas ici ça merde mais je ne sais pas pourquoi
-;
-; grid
-  NCDF_VARPUT, netcdf_id_cond_sed, 'nav_lon', olon
-  NCDF_VARPUT, netcdf_id_cond_sed, 'nav_lat', olat
-  NCDF_VARPUT, netcdf_id_cond_sed, varid[2], FLOAT(0.5) ; ++ c'est quoi cette valeur
-  NCDF_VARPUT, netcdf_id_br, 'nav_lon', olon
-  NCDF_VARPUT, netcdf_id_br, 'nav_lat', olat
-  NCDF_VARPUT, netcdf_id_br, varid[2], FLOAT(0.5) ; ++ c'est quoi cette valeur
-
-;---------------------------
-; réouverture du fichier ... mais pourquoi on le relit !!++
-  netcdf_id_condmag = NCDF_OPEN(fullfilename_condmag[0],/NOWRITE)
-  msg = 'iii : ' + fullfilename_condmag[0] + ' reopened for read'
-  PRINT, msg
-;
-  NCDF_VARGET, netcdf_id_condmag, varname_cond_sed, varin_cond_sed ; , COUNT = [jpia, jpja, 1], OFFSET = [0, 0, 0]
-  NCDF_VARGET, netcdf_id_condmag, varname_br, varin_br ; , COUNT = [jpia, jpja, 1], OFFSET = [0, 0, 0]
-;
 ; do the interpolation
       varin_cond_sed = TOTAL(weig*varin_cond_sed[addr], 1)
@@ -412,10 +331,6 @@
       varin_br = REFORM(varin_br, jpio, jpjo, /OVER)
 ;
-      NCDF_CLOSE, netcdf_id_condmag
       varout_cond_sed = TEMPORARY(varin_cond_sed)
       varout_br = TEMPORARY(varin_br)
-; compute min max
-      minarr_cond_sed = min(varout_cond_sed, max = maxarr_cond_sed)
-      minarr_br = min(varout_br, max = maxarr_br)
 ;
 ; put back the masked value
@@ -423,27 +338,14 @@
 ;++      IF bad[0] NE -1 THEN varout_br[TEMPORARY(bad)] = 32767
 ;
-; write the data
-      NCDF_VARPUT, netcdf_id_cond_sed, varname_cond_sed, varout_cond_sed, COUNT = [jpio, jpjo, 1], OFFSET = [0, 0, 0]
-      NCDF_VARPUT, netcdf_id_br, varname_br, varout_br, COUNT = [jpio, jpjo, 1], OFFSET = [0, 0, 0]
-;
-; update min max attributes
-  NCDF_CONTROL, netcdf_id_cond_sed, /REDEF
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_min', minarr_cond_sed,/FLOAT
-  NCDF_ATTPUT, netcdf_id_cond_sed, varid_cond_sed[0], 'valid_max', maxarr_cond_sed,/FLOAT
-  NCDF_CONTROL, netcdf_id_cond_sed, /ENDEF
-  NCDF_CONTROL, netcdf_id_br, /REDEF
-  NCDF_ATTPUT, netcdf_id_br, varid_br[0], 'valid_min', minarr_br,/FLOAT
-  NCDF_ATTPUT, netcdf_id_br, varid_br[0], 'valid_max', maxarr_br,/FLOAT
-  NCDF_CONTROL, netcdf_id_br, /ENDEF
-;
-;---------------------------
-; close the netcdf files
-  NCDF_CLOSE, netcdf_id_cond_sed
-  NCDF_CLOSE, netcdf_id_br
-;
-  msg = 'iii : ' + fullfilename_cond_sed + ' created'
-  PRINT, msg
-  msg = 'iii : ' + fullfilename_br + ' created'
-  PRINT, msg
+;
+; produce outputs
+  condmag_output, orcares, $
+     varinq_cond_sed, 'Conductance', 'Conductance', 'siemens', $
+     jpio, jpjo, olon, olat, $
+     varout_cond_sed
+  condmag_output, orcares, $
+     varinq_br, 'Magnetic field', 'magnetic field', 'tesla', $
+     jpio, jpjo, olon, olat, $
+     varout_br
 ;
 END
Index: /trunk/condmag_output.pro
===================================================================
--- /trunk/condmag_output.pro	(revision 14)
+++ /trunk/condmag_output.pro	(revision 14)
@@ -0,0 +1,364 @@
+;+
+;
+; @file_comments
+; produce cond_sed_<orcares>.nc or Br_<orcares>.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 ++
+;
+; @parameter 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_<I>orcasres</I>.nc is now present in ${GEOMAG_OD}/
+; or
+; Br_<I>orcasres</I>.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
+                 PRINT, msg
+              END
+     'ORCA025': BEGIN
+                 msg = 'iii : valid orcares parameter = ' +  orcares
+                 PRINT, msg
+              END
+      ELSE  : BEGIN
+                 msg = 'eee : invalid orcares parameter = ' + orcares
+                 PRINT, msg
+                 msg = 'eee : orcares must be ORCA2 or ORCA025'
+                 PRINT, msg
+                 RETURN
+              END
+  ENDCASE
+;
+; check variable definition
+; ++ dimension etc.
+  CASE variable.NAME OF
+     'cond_sed': BEGIN
+                    msg = 'iii : valid variable.NAME parameter = ' + variable.NAME
+                    PRINT, msg
+                    CASE title OF
+                       'Conductance': BEGIN
+                                     msg = 'iii : valid title parameter = ' + title
+                                     PRINT, msg
+                                  END
+                        ELSE      : BEGIN
+                                      msg = 'eee : invalid title parameter = ' + title
+                                      PRINT, msg
+                                      msg = 'eee : title must be Conductance'
+                                      PRINT, msg
+                                      RETURN
+                                   END
+                        ENDCASE
+                    CASE long_name OF
+                       'Conductance': BEGIN
+                                     msg = 'iii : valid long_name parameter = ' + long_name
+                                     PRINT, msg
+                                  END
+                        ELSE      : BEGIN
+                                      msg = 'eee : invalid long_name parameter = ' + long_name
+                                      PRINT, msg
+                                      msg = 'eee : long_name must be Conductance'
+                                      PRINT, msg
+                                      RETURN
+                                   END
+                        ENDCASE
+                    CASE units OF
+                       'siemens': BEGIN
+                                     msg = 'iii : valid units parameter = ' + units
+                                     PRINT, msg
+                                  END
+                        ELSE      : BEGIN
+                                      msg = 'eee : invalid units parameter = ' + units
+                                      PRINT, msg
+                                      msg = 'eee : units must be siemens'
+                                      PRINT, msg
+                                      RETURN
+                                   END
+                        ENDCASE
+                 END
+     'Br'  : BEGIN
+                    msg = 'iii : valid variable.NAME parameter = ' + variable.NAME
+                    PRINT, msg
+                    CASE title OF
+                       'Magnetic field': BEGIN
+                                     msg = 'iii : valid title parameter = ' + title
+                                     PRINT, msg
+                                  END
+                        ELSE      : BEGIN
+                                      msg = 'eee : invalid title parameter = ' + title
+                                      PRINT, msg
+                                      msg = 'eee : title must be Magnetic field'
+                                      PRINT, msg
+                                      RETURN
+                                   END
+                        ENDCASE
+                    CASE long_name OF
+                       'magnetic field': BEGIN
+                                     msg = 'iii : valid long_name parameter = ' + long_name
+                                     PRINT, msg
+                                  END
+                        ELSE      : BEGIN
+                                      msg = 'eee : invalid long_name parameter = ' + long_name
+                                      PRINT, msg
+                                      msg = 'eee : long_name must be magnetic field'
+                                      PRINT, msg
+                                      RETURN
+                                   END
+                        ENDCASE
+                    CASE units OF
+                       'tesla': BEGIN
+                                     msg = 'iii : valid units parameter = ' + units
+                                     PRINT, msg
+                                  END
+                        ELSE      : BEGIN
+                                      msg = 'eee : invalid units parameter = ' + units
+                                      PRINT, msg
+                                      msg = 'eee : units must be tesla'
+                                      PRINT, msg
+                                      RETURN
+                                   END
+                        ENDCASE
+                 END
+     ELSE      : BEGIN
+                    msg = 'eee : invalid variable.NAME parameter = ' + variable.NAME
+                    PRINT, msg
+                    msg = 'eee : variable.NAME must be cond_sed or Br'
+                    PRINT, msg
+                    RETURN
+                 END
+  ENDCASE
+;
+; check jpio
+  IF jpio LT 1 THEN BEGIN
+     msg = ' eee : invalid jpio parameter = ' + STRING(jpio)
+     PRINT, msg
+     msg = ' eee : jpio must be greater or equal to 1'
+     PRINT, msg
+     RETURN
+  ENDIF ELSE BEGIN
+     msg = 'iii : valid jpio parameter = ' + STRING(jpio)
+     PRINT, msg
+  ENDELSE
+
+;
+; check jpjo
+  IF jpjo LT 1 THEN BEGIN
+     msg = ' eee : invalid jpjo parameter = ' + STRING(jpjo)
+     PRINT, msg
+     msg = ' eee : jpjo must be greater or equal to 1'
+     PRINT, msg
+     RETURN
+  ENDIF ELSE BEGIN
+     msg = 'iii : valid jpjo parameter = ' + STRING(jpjo)
+     PRINT, 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))
+     PRINT, msg
+     msg = ' eee : nb of elements of olon must be equal to jpio*jpjo = ' + STRING(jpio*jpjo)
+     PRINT, msg
+     RETURN
+  ENDIF ELSE BEGIN
+     msg = 'iii : valid nb of elements olon parameter' 
+     PRINT, 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'
+             PRINT, msg
+             RETURN
+          END
+     ELSE: BEGIN
+             msg = 'iii : ${GEOMAG_OD} is ' + geomag_od_env
+             PRINT, 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.'
+     PRINT, 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.'
+     PRINT, 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'
+  PRINT, msg
+;
+END
