Changeset 132


Ignore:
Timestamp:
10/14/10 14:52:38 (14 years ago)
Author:
hozdoba
Message:

suite interface cpp<->fortran

Location:
XMLIO_V2/dev/dev_rv/src/XMLIO
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.cpp

    r131 r132  
    2929/* ********************************************************** */ 
    3030 
    31 void xios_handle_create_(XHandle * _ret, const XDType * const _dtype, const XString * const _id) 
     31void xios_handle_create_(XHandle * _ret, const XDType * const _dtype, XString _id) 
    3232{ 
    33    try { 
    34       switch(*_dtype) 
    35       { 
    36          /*ECONTEXT, 
    37       EAXIS, EDOMAIN, EFIELD, EFILE, EGRID, 
    38       GAXIS, GDOMAIN, GFIELD, GFILE, GGRID*/ 
    39          case (ECONTEXT): 
    40             //if (Context::) 
    41             break; 
     33   // Si le handle n'est pas initialisé à 0, on ne fait aucun traitement. 
     34   if (!isNullHandle(*_ret)) return; 
     35   std::string __id = stringXtoStd(_id); 
     36   switch(*_dtype) 
     37   { 
     38      /* EAXIS, EDOMAIN, EFIELD, EFILE, EGRID, GAXIS, GDOMAIN, GFIELD, GFILE, GGRID*/ 
     39      case (ECONTEXT): 
     40         // Si le context n'existe pas, on retourne un handle vide/nul. 
     41         if (!Context::HasContext(__id)) { *_ret = NULLHANDLE; return ; } 
     42         _ret->data_type = *_dtype; 
     43         _ret->data_ptr  = Context::GetContext(__id); 
     44         return ; 
    4245 
    43          default : 
    44             break; 
    45       }; 
    46    } catch(const Exception &exc) 
    47    { ERROR(exc.displayText()); } 
    48 } 
    49  
    50 void xios_handle_verify_(XBool * _ret, const XHandle * const _hd) 
    51 { 
    52    try { 
    53  
    54    } catch(const Exception &exc) 
    55    { ERROR(exc.displayText()); } 
    56 } 
    57  
    58 void xios_handle_getType_(XDType * _ret, const XHandle * const _hd) 
    59 { 
    60    try { 
    61  
    62    } catch(const Exception &exc) 
    63    { ERROR(exc.displayText()); } 
    64 } 
    65  
    66 void xios_handle_isType_(XBool * _ret, const XHandle * const _hd, const XDType  * const _dtype) 
    67 { 
    68    try { 
    69  
    70    } catch(const Exception &exc) 
    71    { ERROR(exc.displayText()); } 
    72 } 
    73  
    74 void xios_handle_isId_(XBool * _ret, const XHandle * const _hd, const XString * const _id) 
    75 { 
    76    try { 
    77  
    78    } catch(const Exception &exc) 
    79    { ERROR(exc.displayText()); } 
    80 } 
    81  
    82 void xios_handle_isGroup_(XBool * _ret, const XHandle * const _hd) 
    83 { 
    84    try { 
    85  
    86    } catch(const Exception &exc) 
    87    { ERROR(exc.displayText()); } 
    88 } 
    89  
    90 void xios_handle_isElement_(XBool * _ret, const XHandle * const _hd) 
    91 { 
    92    try { 
    93  
    94    } catch(const Exception &exc) 
    95    { ERROR(exc.displayText()); } 
     46      default : 
     47         *_ret = NULLHANDLE; 
     48         return ; 
     49   }; 
    9650} 
    9751 
     
    10256void xios_xml_parse_file_(XString _filename) 
    10357{ 
    104    try { 
    105       std::string   __filename = stringXtoStd(_filename); 
    106       std::ifstream __istr( __filename.c_str() , std::ifstream::in ); 
     58   std::string   __filename = stringXtoStd(_filename); 
     59   std::ifstream __istr( __filename.c_str() , std::ifstream::in ); 
    10760 
    108       // On commence la lecture du flux de donnée xml. 
    109       XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); 
     61   // On commence la lecture du flux de donnée xml. 
     62   XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); 
    11063 
    111       // On parse le fichier xml noeud par noeud 
    112       // (ie on construit dynamiquement notre arbre d'objets). 
    113       XMLParser::Parse(node); 
    114  
    115    } catch(const Exception &exc) 
    116    { ERROR(exc.displayText()); } 
     64   // On parse le fichier xml noeud par noeud 
     65   // (ie on construit dynamiquement notre arbre d'objets). 
     66   XMLParser::Parse(node); 
    11767} 
    11868 
    11969void xios_xml_parse_string_(XString _xmlcontent) 
    12070{ 
    121    try { 
    122       std::string        __xmlcontent = stringXtoStd(_xmlcontent); 
    123       std::istringstream __istr(__xmlcontent); 
     71   std::string        __xmlcontent = stringXtoStd(_xmlcontent); 
     72   std::istringstream __istr(__xmlcontent); 
    12473 
    125       // On commence la lecture du flux de donnée xml. 
    126       XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); 
     74   // On commence la lecture du flux de donnée xml. 
     75   XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); 
    12776 
    128       // On parse le fichier xml noeud par noeud 
    129       // (ie on construit dynamiquement notre arbre d'objets). 
    130       XMLParser::Parse(node); 
     77   // On parse le fichier xml noeud par noeud 
     78   // (ie on construit dynamiquement notre arbre d'objets). 
     79   XMLParser::Parse(node); 
     80} 
     81/* ********************************************************** */ 
     82/*                      DATA TREATMENT INTERFACE              */ 
     83/* ********************************************************** */ 
    13184 
    132    } catch(const Exception &exc) 
    133    { ERROR(exc.displayText()); } 
     85static std::vector<DataTreatment *> AllDataTreatment; 
     86 
     87static void deleteAllDataTreatment(void) 
     88{ 
     89   std::vector<DataTreatment *>::iterator it; 
     90   for (it  = AllDataTreatment.begin(); 
     91        it != AllDataTreatment.end(); it++) 
     92      delete (*it); 
    13493} 
    13594 
    136 /* ********************************************************** */ 
    137 /*                      MAIN ENTRY                            */ 
    138 /* ********************************************************** */ 
     95void xios_dtreatment_new_(XHandle * _dt, const XHandle * const _hd) 
     96{ 
     97   static bool called = false; 
    13998 
    140 void main_c_(void) // voué à disparaître 
    141 { /* Ne rien faire de plus */ } 
     99   // Si le handle de traitement n'est pas initialisé à 0, on ne fait aucun traitement. 
     100   if (!isNullHandle(*_dt) || (_hd->data_type != ECONTEXT)) return; 
     101   Context* const __ctxt = (Context*) _hd->data_ptr; 
     102 
     103   _dt->data_type = DTREATMENT; 
     104   _dt->data_ptr  = new DataTreatment(__ctxt); 
     105 
     106   if (!called) 
     107   { 
     108      atexit (&deleteAllDataTreatment); 
     109      called = true; 
     110   } 
     111} 
     112 
     113void xios_dtreatment_create_files_and_headers_(const XHandle * const _hd, const XFileType * const _ft) 
     114{ 
     115   // Si le handle de traitement n'est pas initialisé à 0, on ne fait aucun traitement. 
     116   if (isNullHandle(*_hd) || (_hd->data_type != DTREATMENT)) return; 
     117   DataTreatment * const __dt = (DataTreatment*)_hd->data_ptr; 
     118   AllDataTreatment.push_back (__dt); 
     119   switch(*_ft) 
     120   { 
     121      case (NETCDF4): 
     122         __dt->createDataOutput<NetCDF4DataOutput>(); 
     123         return; 
     124      // Autres formats de fichiers si disponibles... 
     125      default: 
     126         return; 
     127   } 
     128} 
     129 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.hpp

    r131 r132  
    1212#endif //__cplusplus 
    1313 
    14    typedef long int XInt; //integer 
    15    typedef bool XBool;    //logical 
     14   typedef long int XInt; // Integer 
     15   typedef bool XBool;    // Logical 
     16   typedef void *XPtr;    // Pointeur C non typé 
    1617 
    1718   typedef enum _datatype 
    1819   { 
     20      NOTYPE = 0, 
    1921      DTREATMENT, DATE, CALENDAR, ECONTEXT, 
    2022      EAXIS, EDOMAIN, EFIELD, EFILE, EGRID, 
     
    2426   typedef enum _filetype 
    2527   { 
    26       NETCDF4 
     28      NETCDF4 = 0 
    2729   } XFileType; 
    28  
    29    typedef struct _ptr    // Pointeur C non-typé. 
    30    { void * ptr; } XPtr; 
    3130 
    3231   typedef struct _handle // Référence C à une objet de la bibliothÚque. 
     
    3938   { int year, month, day, hour, minute, second; } XDate, XDuration; 
    4039 
     40   const XHandle NULLHANDLE = { NOTYPE, NULL }; 
     41 
     42#define isNullHandle(hdl) ((hdl).data_type == NOTYPE && (hdl).data_ptr == NULL) 
     43 
    4144   /* ******************** HANDLE INTERFACE ******************** */ 
    42    void xios_handle_create_ (XHandle * _ret, const XDType  * const _dtype, const XString * const _id); 
     45   void xios_handle_create_ (XHandle * _ret, const XDType * const _dtype, XString _id); 
    4346   void xios_handle_verify_ (XBool   * _ret, const XHandle * const _hd); 
    4447   void xios_handle_getType_(XDType  * _ret, const XHandle * const _hd); 
    4548 
    4649   void xios_handle_isType_   (XBool * _ret, const XHandle * const _hd, const XDType  * const _dtype); 
    47    void xios_handle_isId_    (XBool * _ret, const XHandle * const _hd, const XString * const _id); 
     50   void xios_handle_isId_     (XBool * _ret, const XHandle * const _hd, const XString * const _id); 
    4851   void xios_handle_isGroup_  (XBool * _ret, const XHandle * const _hd); 
    4952   void xios_handle_isElement_(XBool * _ret, const XHandle * const _hd); 
     
    5457 
    5558   /* ******************** DATA TREATMENT INTERFACE ************ */ 
    56    void xios_dtreatment_new(XHandle * _dt, const XHandle * const _hd); 
    57    void xios_dtreatment_createFilesAndHeaders(const XHandle * const _hd); 
     59   void xios_dtreatment_new_(XHandle * _dt, const XHandle * const _hd); 
     60   void xios_dtreatment_create_files_and_headers_(const XHandle * const _hd, const XFileType * const _ft); 
    5861 
    5962   /* ******************** CALENDAR INTERFACE ****************** */ 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp

    r131 r132  
    191191         } 
    192192 
     193         static bool HasContext(const string& id) 
     194         { 
     195            Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
     196            return (AllListContext.find(id) != AllListContext.end()); 
     197         } 
     198 
     199         static Context* GetContext(const string& id) 
     200         { return (Context::GetAllListObject()[id][id]); } 
     201 
    193202         static Context* SwapContext(void) 
    194203         { 
     
    208217         { return (Context::GetObject(Context::GetCurrentContextId())); } 
    209218 
    210          static void SetCurrentContext(const string& id, bool withSwap = false) 
     219         static void SetCurrentContext(const string& id, bool withSwap = false, bool withcheck = true) 
    211220         { 
    212221            if (withSwap) Stid.push (Context::GetCurrentContextId()); 
     222 
     223            if (!Context::HasContext(id) && withcheck) 
     224               throw new XMLIOUndefinedValueException 
     225                     ("Impossible de se placer dans le contexte "+id+" car celui-ci n'existe pas dans l'arborescence!"); 
    213226 
    214227            // On modifie le context courrant pour tout les ObjectTemplate 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90

    r131 r132  
    33! --------------------------------------------------- ! 
    44 
    5 MODULE XML 
     5MODULE XTYPE 
     6   IMPLICIT NONE 
     7 
     8   ! Ne jamais modifier les valeurs internes de ce type dans le code fortran. 
     9   TYPE XHandle 
     10      INTEGER :: dtype 
     11      INTEGER :: daddr 
     12   END TYPE XHandle 
     13 
     14   TYPE XDate 
     15      INTEGER :: year, month, day, hour, minute, second 
     16   END TYPE XDate 
     17 
     18   TYPE XDuration 
     19      REAL(kind = 4) :: year, month, day, hour, minute, second 
     20   END TYPE XDuration 
     21 
     22   ! enum XDType 
     23   INTEGER, PARAMETER  :: NOTYPE = 0 
     24   INTEGER, PARAMETER  :: DTREATMENT = 1, DDATE = 2, CALENDAR = 3, ECONTEXT = 4 
     25   INTEGER, PARAMETER  :: EAXIS = 5 , EDOMAIN = 6 , EFIELD = 7 , EFILE = 8 , EGRID = 9 
     26   INTEGER, PARAMETER  :: GAXIS = 10, GDOMAIN = 11, GFIELD = 12, GFILE = 13, GGRID = 14 
     27 
     28   ! enum XFileType 
     29   INTEGER, PARAMETER  :: NETCDF4 = 0 
     30 
     31   ! Autres constantes 
     32   TYPE(XHandle)  , PARAMETER :: NULLHANDLE = XHandle(0, 0) 
     33   TYPE(XDuration), PARAMETER :: NONEDUR    = XDuration(0., 0., 0., 0., 0., 0.) 
     34 
     35END MODULE XTYPE 
     36 
     37MODULE IXHANDLE 
     38 
     39   INTERFACE 
     40 
     41      SUBROUTINE xios_handle_create(ret, dtype, idt) 
     42         USE XTYPE 
     43         TYPE(XHandle), INTENT(OUT) :: ret 
     44         INTEGER      , INTENT(IN)  :: dtype 
     45         CHARACTER*(*), INTENT(IN)  :: idt 
     46      END SUBROUTINE xios_handle_create 
     47 
     48   END INTERFACE 
     49 
     50END MODULE IXHANDLE 
     51 
     52MODULE IXML 
     53   IMPLICIT NONE 
    654   INTERFACE 
    755 
     
    1563 
    1664   END INTERFACE 
    17 END MODULE XML 
     65END MODULE IXML 
     66 
     67MODULE IDATATREATMENT 
     68   IMPLICIT NONE 
     69   INTERFACE 
     70 
     71      SUBROUTINE xios_dtreatment_new(dt, context) 
     72         USE XTYPE 
     73         TYPE(XHandle), INTENT(OUT) :: dt 
     74         TYPE(XHandle), INTENT(IN)  :: context 
     75      END SUBROUTINE xios_dtreatment_new 
     76 
     77      SUBROUTINE xios_dtreatment_create_files_and_headers(dt, ftype) 
     78         USE XTYPE 
     79         TYPE(XHandle), INTENT(IN) :: dt 
     80         INTEGER      , INTENT(IN) :: ftype 
     81      END SUBROUTINE xios_dtreatment_create_files_and_headers 
     82 
     83   END INTERFACE 
     84END MODULE IDATATREATMENT 
    1885 
    1986PROGRAM MAIN 
    20    USE XML 
     87   USE XTYPE 
     88   USE IXHANDLE 
     89   USE IXML 
     90   USE IDATATREATMENT 
     91 
    2192   IMPLICIT NONE 
    2293 
    23    CHARACTER(LEN = 100):: filename 
     94   TYPE(XHandle) :: context1 = NULLHANDLE 
     95   TYPE(XHandle) :: dtreat   = NULLHANDLE 
    2496 
    25    filename = "/local/XMLIOSERVER_DEV/dev_rv/test/iodef_simple_test.xml" 
     97   ! Parsing du document xml depuis un fichier situé sur le disque. 
     98   CALL xios_xml_Parse_File("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_simple_test.xml") 
    2699 
    27    CALL xios_xml_Parse_File(filename) 
     100   ! Création d'un handle sur le contexte dans lequel on souhaite travailler, càd 'context1' ici. 
     101   CALL xios_handle_create(context1, ECONTEXT, "context1") 
     102   iF ((context1%dtype == 0) .AND. (context1%daddr == 0)) THEN 
     103      PRINT *, "Impossible de créer un handle sur l'élément context1 !" 
     104      STOP 
     105   END IF 
     106 
     107   ! ----------- Début du traitement ----------- ! 
     108 
     109   ! Création et initialisation d'une instance de traitement des données dans 'context1'. 
     110   CALL xios_dtreatment_new(dtreat, context1) 
     111   iF ((dtreat%dtype == 0) .AND. (dtreat%daddr == 0)) THEN 
     112      PRINT *, "Impossible d'initialiser l'instance de traitement !" 
     113      STOP 
     114   END IF 
     115 
     116   ! Création des fichiers et des entêtes dans le contexte. 
     117   CALL xios_dtreatment_create_files_and_headers(dtreat, NETCDF4) 
    28118 
    29119END PROGRAM MAIN 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xml_node.hpp

    r127 r132  
    7979            { THashAttributes __attributes; this->getAttributes(__attributes); return (__attributes); } 
    8080 
    81             ~XMLNode() 
     81            ~XMLNode(void) 
    8282            { /* Ne rien faire de plus */ } 
    8383 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xml_parser.hpp

    r127 r132  
    3535                  { WARNING("Le context ne sera pas traité car il existe déjà un autre context possédant le même nom !"); continue; } 
    3636 
    37                   Context::SetCurrentContext(attributes["id"]); 
     37                  Context::SetCurrentContext(attributes["id"], false, false); 
    3838                  Context& context = *Context::CreateObject(attributes["id"]); 
    3939 
Note: See TracChangeset for help on using the changeset viewer.