Index: XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90
===================================================================
--- XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90	(revision 134)
+++ XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90	(revision 137)
@@ -1,177 +1,186 @@
 ! --------------------------------------------------- !
-! ------------- XMLIO SERVER MAIN TEST  ------------- !
+!               XMLIO SERVER MAIN TEST                !
 ! --------------------------------------------------- !
 
-MODULE XTYPE
-   IMPLICIT NONE
-
-   ! Ne jamais modifier les valeurs internes de ce type dans le code fortran.
-   TYPE XHandle
-      INTEGER :: dtype
-      INTEGER :: daddr
-   END TYPE XHandle
-
-   TYPE XDate
-      INTEGER :: year, month, day, hour, minute, second
-   END TYPE XDate
-
-   TYPE XDuration
-      REAL(kind = 8) :: year, month, day, hour, minute, second
-   END TYPE XDuration
-
-   ! enum XDType
-   INTEGER, PARAMETER  :: NOTYPE = 0
-   INTEGER, PARAMETER  :: DTREATMENT = 1, DDATE = 2, CALENDAR = 3, ECONTEXT = 4
-   INTEGER, PARAMETER  :: EAXIS = 5 , EDOMAIN = 6 , EFIELD = 7 , EFILE = 8 , EGRID = 9
-   INTEGER, PARAMETER  :: GAXIS = 10, GDOMAIN = 11, GFIELD = 12, GFILE = 13, GGRID = 14
-
-   ! enum XFileType
-   INTEGER, PARAMETER  :: NETCDF4 = 0
-
-   ! Autres constantes
-   TYPE(XHandle)  , PARAMETER :: NULLHANDLE = XHandle(0, 0)
-   TYPE(XDuration), PARAMETER :: NONEDUR    = XDuration(0., 0., 0., 0., 0., 0.)
-
-END MODULE XTYPE
-
-MODULE IXHANDLE
-
-   INTERFACE
-
-      SUBROUTINE xios_handle_create(ret, dtype, idt)
-         USE XTYPE
-         TYPE(XHandle), INTENT(OUT) :: ret
-         INTEGER      , INTENT(IN)  :: dtype
-         CHARACTER*(*), INTENT(IN)  :: idt
-      END SUBROUTINE xios_handle_create
-
-   END INTERFACE
-
-END MODULE IXHANDLE
-
-MODULE IXML
-   IMPLICIT NONE
-   INTERFACE
-
-      SUBROUTINE xios_xml_Parse_File(filename)
-         CHARACTER*(*), INTENT(IN) :: filename
-      END SUBROUTINE xios_xml_Parse_File
-
-      SUBROUTINE xios_xml_Parse_String(xmlcontent)
-         CHARACTER*(*), INTENT(IN) :: xmlcontent
-      END SUBROUTINE xios_xml_Parse_String
-
-   END INTERFACE
-END MODULE IXML
-
-MODULE ICONTEXT
-   IMPLICIT NONE
-   INTERFACE
-
-      SUBROUTINE xios_context_set_current(context, withswap)
-         USE XTYPE
-         TYPE(XHandle),     INTENT(IN) :: context
-         LOGICAL, OPTIONAL, INTENT(IN) :: withswap
-      END SUBROUTINE xios_context_set_current
-
-      SUBROUTINE xios_context_get_current(context)
-         USE XTYPE
-         TYPE(XHandle), INTENT(IN) :: context
-      END SUBROUTINE xios_context_get_current
-
-      SUBROUTINE xios_context_get_calendar(context, calend)
-         USE XTYPE
-         TYPE(XHandle), INTENT(IN)  :: context
-         TYPE(XHandle), INTENT(OUT) :: calend
-      END SUBROUTINE xios_context_get_calendar
-
-   END INTERFACE
-
-END MODULE ICONTEXT
-
-MODULE ICALENDAR
-   IMPLICIT NONE
-   INTERFACE
-
-      SUBROUTINE xios_calendar_set_timestep(calend, dur)
-         USE XTYPE
-         TYPE(XHandle)  , INTENT(IN) :: calend
-         TYPE(XDuration), INTENT(IN) :: dur
-      END SUBROUTINE xios_calendar_set_timestep
-
-   END INTERFACE
-
-END MODULE ICALENDAR
-
-MODULE IDATATREATMENT
-   IMPLICIT NONE
-   INTERFACE
-
-      SUBROUTINE xios_dtreatment_new(dt, context)
-         USE XTYPE
-         TYPE(XHandle), INTENT(OUT) :: dt
-         TYPE(XHandle), INTENT(IN)  :: context
-      END SUBROUTINE xios_dtreatment_new
-
-      SUBROUTINE xios_dtreatment_create_files_and_headers(dt, ftype)
-         USE XTYPE
-         TYPE(XHandle), INTENT(IN) :: dt
-         INTEGER      , INTENT(IN) :: ftype
-      END SUBROUTINE xios_dtreatment_create_files_and_headers
-
-   END INTERFACE
-END MODULE IDATATREATMENT
-
 PROGRAM MAIN
-   USE XTYPE
    USE IXHANDLE
    USE IXML
+   USE IXMLTREE
    USE ICONTEXT
+   USE ICALENDAR
+   USE IEXTENDED
    USE IDATATREATMENT
-   USE ICALENDAR
 
-   IMPLICIT NONE
+   INTEGER       :: compt = 0
 
-   INTEGER         :: compt
-   TYPE(XHandle)   :: context1    = NULLHANDLE
-   TYPE(XHandle)   :: dtreat      = NULLHANDLE
-   TYPE(XHandle)   :: calend      = NULLHANDLE
+   TYPE(XHandle) :: nemo_style_ctxt     = NULLHANDLE, &
+                    orchidee_style_ctxt = NULLHANDLE, &
+                    lmdz_style_ctxt     = NULLHANDLE
+
+   TYPE(XHandle) :: temp_mod  = NULLHANDLE, &
+                    temp_mod_ = NULLHANDLE
+
+   ! Axes verticaux
+   REAL(kind = 8), DIMENSION(10) :: vaxis  = (/(i, i=1, 10)/)
+                                    !vvaxis = (/(i, i=1, 5)/)
+
+   ! Domaines horizontaux
+   REAL(kind = 8), DIMENSION(20) :: lonrect_orch0  = (/(i, i=11, 30)/),&
+                                    latrect_orch0  = (/(i, i=11, 30)/)
+
+   REAL(kind = 8), DIMENSION(10,10) :: loncurv_nemo0  = 1, &
+                                       latcurv_nemo0  = 1
+
+   ! Les durÃ©es
    TYPE(XDuration) :: timestep_1h = XDuration(0., 0., 0., 1., 0., 0.)
+                      !timestep_2h = XDuration(0., 0., 0., 2., 0., 0.)
+
+   ! Les masques
+   LOGICAL(kind = 1), DIMENSION(20, 20) :: mask0  = .TRUE._1
+
+   CHARACTER(len = *), PARAMETER :: filename = &
+            "/local/XMLIOSERVER_DEV/dev_rv/test/iodef_simple_test.xml"
+
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
    ! Parsing du document xml depuis un fichier situÃ© sur le disque.
-   CALL xios_xml_Parse_File("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_simple_test.xml")
+   CALL xml_Parse_File(filename)
 
-   ! Le calendrier doit Ãªtre initialisÃ© ici s'il ne l'a pas dÃ©jÃ  Ã©tÃ© depuis le document xml.
+   ! CrÃ©ation de handle sur les contextes exstants dans lequels on souhaite travailler.
+   CALL handle_create(nemo_style_ctxt, ECONTEXT, "nemo_style")
+   CALL context_set_current(nemo_style_ctxt)
 
-   ! CrÃ©ation d'un handle sur le contexte dans lequel on souhaite travailler, cÃ d 'context1' ici.
-   CALL xios_handle_create(context1, ECONTEXT, "context1")
-   iF ((context1%dtype == 0) .AND. (context1%daddr == 0)) THEN
-      PRINT *, "Impossible de crÃ©er un handle sur l'Ã©lÃ©ment context1 !"
-      STOP
-   END IF
+   CALL handle_create(temp_mod, EDOMAIN,  "domaine0")
+      CALL xml_domain_addAttribut(domain_hdl    = temp_mod,      &
+                                  lonvalue_curv = loncurv_nemo0, &
+                                  latvalue_curv = latcurv_nemo0, &
+                                  domtype       = "curvilinear")
+
+   CALL handle_create(lmdz_style_ctxt, ECONTEXT, "lmdz_style")
+   CALL context_set_current(lmdz_style_ctxt)
+
+   !!!!!!!!!!!!!!!!!!!! EXEMPLE RECONSTRUCTION !!!!!!!!!!!!!!!!!!!!!
+   ! On crÃ©e un nouveau context et on lui associe un handle.
+   CALL context_create(context_hdl   = orchidee_style_ctxt, &
+                       context_id    = "orchidee_style",    &
+                       calendar_type = GREGORIAN)
+
+   ! ---------> field_dÃ©finition
+   CALL handle_create(temp_mod, GFIELD,  "field_definition")
+      CALL xml_tree_add(parent_hdl = temp_mod,        &
+                        child_hdl  = temp_mod_,       &
+                        child_type = GFIELD,          &
+                        child_id   = "ss_fieldgroup")
+      CALL xml_group_field_addAttribut(gfield_hdl = temp_mod_, &
+                                       flevel     = 1,         &
+                                       fprec      = 4,         &
+                                       fenabled   = .TRUE._1)
+         CALL xml_tree_add(parent_hdl = temp_mod_,    &
+                           child_hdl  = temp_mod ,    &
+                           child_type = EFIELD,       &
+                           child_id   = "field0")
+         CALL xml_field_addAttribut(field_hdl      = temp_mod,       &
+                                    fname          = "field0_name",  &
+                                    fstandard_name = "field0_sname", &
+                                    flong_name     = "field0_lname", &
+                                    funit          = "Pa",           &
+                                    foperation     = "inst",         &
+                                    ffreq_op       = timestep_1h,    &
+                                    fgrid_ref      = "grid0")
+   ! ---------> axis_dÃ©finition
+   CALL handle_create(temp_mod, GAXIS,   "axis_definition")
+      CALL xml_tree_add(parent_hdl = temp_mod,        &
+                        child_hdl  = temp_mod_,       &
+                        child_type = GAXIS,           &
+                        child_id   = "ss_axisgroup")
+      CALL xml_group_axis_addAttribut(gaxis_hdl = temp_mod_, &
+                                      aunit     = "SI")
+         CALL xml_tree_add(parent_hdl = temp_mod_,    &
+                           child_hdl  = temp_mod ,    &
+                           child_type = EAXIS,        &
+                           child_id   = "axis0")
+         CALL xml_axis_addAttribut(axis_hdl       = temp_mod,             &
+                                   aname          = "saxev",              &
+                                   astandard_name = "saxev",              &
+                                   along_name     = "Simple axe vertical",&
+                                   avalue         = vaxis)
+
+   ! ---------> domain_dÃ©finition
+   CALL handle_create(temp_mod, GDOMAIN, "domain_definition")
+      CALL xml_tree_add(parent_hdl = temp_mod,        &
+                        child_hdl  = temp_mod_,       &
+                        child_type = GDOMAIN,         &
+                        child_id   = "ss_domaingroup")
+      CALL xml_group_domain_addAttribut(gdomain_hdl = temp_mod_, &
+                                        ni_glo      = 40,        &
+                                        nj_glo      = 40)
+         CALL xml_tree_add(parent_hdl = temp_mod_,    &
+                           child_hdl  = temp_mod ,    &
+                           child_type = EDOMAIN,      &
+                           child_id   = "domain0")
+         CALL xml_domain_addAttribut(domain_hdl     = temp_mod,             &
+                                     dname          = "Compressee",         &
+                                     dstandard_name = "DomOrchTest",        &
+                                     dlong_name     = "Test type orchidee", &
+                                     ibegin         = 10,                   &
+                                     iend           = 31,                   &
+                                     jbegin         = 10,                   &
+                                     jend           = 31,                   &
+                                     mask           = mask0,                &
+                                     data_dim       = 1,                    &
+                                     data_ni        = 400,                  &
+                                     data_ibegin    = 1,                    &
+                                     lonvalue_rect  = lonrect_orch0,        &
+                                     latvalue_rect  = latrect_orch0,        &
+                                     domtype        = "rectilinear")
+
+   ! ---------> file_dÃ©finition
+   CALL handle_create(temp_mod, GFILE,   "file_definition")
+      CALL xml_tree_add(parent_hdl = temp_mod,        &
+                        child_hdl  = temp_mod_,       &
+                        child_type = GFILE)
+      CALL xml_group_file_addAttribut(gfile_hdl = temp_mod_,   &
+                                      fofreq   = timestep_1h,  &
+                                      folevel   = 2,           &
+                                      fenabled  = .TRUE._1)
+         CALL xml_tree_add(parent_hdl = temp_mod_,    &
+                           child_hdl  = temp_mod ,    &
+                           child_type = EFILE,        &
+                           child_id   = "file0")
+         CALL xml_file_addAttribut(file_hdl     = temp_mod,                      &
+                                   fname        = "data/orchidee_test.nc",       &
+                                   fdescription = "Test sur grille type orchidee")
+            CALL xml_tree_add(parent_hdl = temp_mod , &
+                              child_hdl  = temp_mod_, &
+                              child_type = EFIELD)
+            CALL xml_field_addAttribut(field_hdl  = temp_mod_, &
+                                       ffield_ref = "field0")
+
+   ! ---------> grid_dÃ©finition
+   CALL handle_create(temp_mod, GGRID,   "grid_definition")
+      CALL xml_tree_add(parent_hdl = temp_mod,        &
+                        child_hdl  = temp_mod_,       &
+                        child_type = GGRID,           &
+                        child_id   = "ss_gridgroup")
+      CALL xml_group_grid_addAttribut(ggrid_hdl    = temp_mod_, &
+                                      gdomain_ref  = "domain0", &
+                                      gaxis_ref    = "axis0");
+         CALL xml_tree_add(parent_hdl = temp_mod_,    &
+                           child_hdl  = temp_mod ,    &
+                           child_type = EGRID,        &
+                           child_id   = "grid0")
+         CALL xml_grid_addAttribut(grid_hdl     = temp_mod,           &
+                                   gname        = "GRectiCompressee", &
+                                   gdescription = "Grille orchidee");
+
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+   ! Affichage de l'arbre xml au niveau de la sortie.
+   CALL xml_tree_show("xmlio_tree_prev.log")
+   ! CALL xml_tree_show()
 
    ! ----------- DÃ©but du traitement ----------- !
-
-   CALL xios_context_set_current(context1, .TRUE.)
-
-   ! CrÃ©ation et initialisation d'une instance de traitement des donnÃ©es dans 'context1'.
-   CALL xios_dtreatment_new(dtreat, context1)
-   iF ((dtreat%dtype == 0) .AND. (dtreat%daddr == 0)) THEN
-      PRINT *, "Impossible d'initialiser l'instance de traitement !"
-      STOP
-   END IF
-
-   ! CrÃ©ation des fichiers et des entÃªtes dans le contexte.
-   CALL xios_dtreatment_create_files_and_headers(dtreat, NETCDF4)
-
-   ! On rÃ©cupÃ©re le calendrier associÃ© au contexte en cours de traitement.
-   CALL xios_context_get_calendar(context1, calend)
-   iF ((calend%dtype == 0) .AND. (calend%daddr == 0)) THEN
-      PRINT *, "Impossible de rÃ©cupÃ©rer le calendrier !"
-      STOP
-   END IF
-
-   ! On change la durÃ©e du timestep.
-   CALL xios_calendar_set_timestep(calend, timestep_1h)
+   ! On choisit le context dans lequel on va travailler et on commence le traitement des donnÃ©es.
+   CALL dtreatment_start(orchidee_style_ctxt, NETCDF4)
 
    ! ExÃ©cution de la boucle de calcul-Ã©criture.
@@ -180,3 +189,6 @@
    END DO
 
+   ! Affichage de l'arbre xml au niveau de la sortie.
+   CALL xml_tree_show("xmlio_tree_next.log")
+
 END PROGRAM MAIN
