Changeset 134
- Timestamp:
- 10/15/10 11:16:12 (14 years ago)
- Location:
- XMLIO_V2/dev/dev_rv/src/XMLIO
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.cpp
r133 r134 5 5 /* ********************************************************** */ 6 6 7 static inline std::string stringXtoStd( XString _str)7 static inline std::string stringXtoStd(const XString _str) 8 8 { 9 9 char * const temp = new char[_str.len+1](); … … 25 25 } 26 26 27 static inline Duration durationXtoXMLIO(const XDuration * const _xdur) // Non testée 28 { 29 Duration __dur= { _xdur->year, _xdur->month , _xdur->day, 30 _xdur->hour, _xdur->minute, _xdur->second }; 31 return (__dur); 32 } 33 27 34 /* ********************************************************** */ 28 35 /* HANDLE INTERFACE */ 29 36 /* ********************************************************** */ 30 37 31 void xios_handle_create_(XHandle * _ret, const XDType * const _dtype,XString _id)38 void xios_handle_create_(XHandle * const _ret, const XDType * const _dtype, const XString _id) 32 39 { 33 40 // Si le handle n'est pas initialisé à 0, on ne fait aucun traitement. … … 54 61 /* ********************************************************** */ 55 62 56 void xios_xml_parse_file_( XString _filename)63 void xios_xml_parse_file_(const XString _filename) 57 64 { 58 65 std::string __filename = stringXtoStd(_filename); … … 67 74 } 68 75 69 void xios_xml_parse_string_( XString _xmlcontent)76 void xios_xml_parse_string_(const XString _xmlcontent) 70 77 { 71 78 std::string __xmlcontent = stringXtoStd(_xmlcontent); … … 94 101 } 95 102 96 void xios_dtreatment_new_(XHandle * _dt, const XHandle * const _hd)103 void xios_dtreatment_new_(XHandle * const _dt, const XHandle * const _hd) 97 104 { 98 105 static bool called = false; … … 100 107 // Si le handle de traitement n'est pas initialisé à 0, on ne fait aucun traitement. 101 108 if (!isNullHandle(*_dt) || (_hd->data_type != ECONTEXT)) return; 102 Context* const __ctxt = (Context*) _hd->data_ptr; 109 Context * const __ctxt = (Context*) _hd->data_ptr; 110 DataTreatment * const __dtrt =__ctxt->setDataTreatment<DataTreatment>(); 103 111 104 _dt->data_type = DTREATMENT; 105 _dt->data_ptr = new DataTreatment(__ctxt); 106 107 if (!called) 112 if (__dtrt != NULL) 108 113 { 109 atexit (&deleteAllDataTreatment); 110 called = true; 114 AllDataTreatment.push_back(__dtrt); 115 _dt->data_type = DTREATMENT; 116 _dt->data_ptr = __dtrt; 117 if (!called) 118 { 119 atexit (&deleteAllDataTreatment); 120 called = true; 121 } 111 122 } 112 123 } … … 116 127 if (isNullHandle(*_hd) || (_hd->data_type != DTREATMENT)) return; 117 128 DataTreatment * const __dt = (DataTreatment*)_hd->data_ptr; 118 AllDataTreatment.push_back (__dt);119 129 switch(*_ft) 120 130 { … … 136 146 bool __wswap = (_wswap == NULL) ? false : *_wswap; 137 147 if (isNullHandle(*_ctxt) || (_ctxt->data_type != ECONTEXT)) return; 138 139 148 Context* const __ctxt = (Context*) _ctxt->data_ptr; 140 149 Context::SetCurrentContext(__ctxt->getId(), __wswap) ; 141 150 } 142 151 152 void xios_context_get_current_ (XHandle * _ctxt) 153 { 154 // Si le handle de traitement n'est pas initialisé à 0, on ne fait aucun traitement. 155 if ((Context::GetAllListObject().size() == 0) || 156 !isNullHandle(*_ctxt)) return; 157 _ctxt->data_type = ECONTEXT; 158 _ctxt->data_ptr = Context::GetCurrentContext(); 159 } 160 161 void xios_context_get_calendar_(const XHandle * const _ctxt, XHandle * _cal) 162 { 163 if (!isNullHandle(*_cal) || isNullHandle(*_ctxt) || 164 (_ctxt->data_type != ECONTEXT)) return; 165 Context* const __ctxt = (Context*) _ctxt->data_ptr; 166 AbstractCalendar * const __cal = __ctxt->getCalendar(); 167 if (__cal != NULL) 168 { 169 _cal->data_type = CALENDAR; 170 _cal->data_ptr = __cal; 171 } 172 } 173 174 /* ********************************************************** */ 175 /* CALENDAR INTERFACE */ 176 /* ********************************************************** */ 177 178 void xios_calendar_set_timestep_(const XHandle * const _cal, const XDuration * const _dur) 179 { 180 if (isNullHandle(*_cal) || (_cal->data_type != CALENDAR)) return; 181 const Duration __dur = durationXtoXMLIO(_dur); 182 AbstractCalendar * const __cal = (AbstractCalendar*) _cal->data_ptr; 183 __cal->setTimeStep(__dur); 184 } 185 186 #undef isNullHandle -
XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.hpp
r133 r134 13 13 14 14 typedef long int XInt; // Integer 15 typedef bool XBool;// Logical16 typedef void *XPtr;// Pointeur C non typé15 typedef bool XBool;// Logical 16 typedef void *XPtr; // Pointeur C non typé 17 17 18 18 typedef enum _datatype … … 35 35 { char * str; int len; } XString; 36 36 37 typedef struct _ymdhms // Durée et date. 38 { int year, month, day, hour, minute, second; } XDate, XDuration; 37 typedef struct _ymdhms_int 38 { int year, month, day, hour, minute, second; } XDate; 39 40 typedef struct _ymdhms_double 41 { double year, month, day, hour, minute, second; } XDuration; 39 42 40 43 const XHandle NULLHANDLE = { NOTYPE, NULL }; 41 44 42 #define isNullHandle(hdl) ((hdl).data_type == NOTYPE && (hdl).data_ptr == NULL) 45 #define isNullHandle(hdl) \ 46 ((hdl).data_type == NOTYPE && (hdl).data_ptr == NULL) 43 47 44 48 /* ******************** HANDLE INTERFACE ******************** */ 45 void xios_handle_create_ (XHandle * _ret, const XDType * const _dtype, XString _id); 46 47 /* 48 void xios_handle_verify_ (XBool * _ret, const XHandle * const _hd); 49 void xios_handle_getType_(XDType * _ret, const XHandle * const _hd); 50 51 void xios_handle_isType_ (XBool * _ret, const XHandle * const _hd, const XDType * const _dtype); 52 void xios_handle_isId_ (XBool * _ret, const XHandle * const _hd, const XString * const _id); 53 void xios_handle_isGroup_ (XBool * _ret, const XHandle * const _hd); 54 void xios_handle_isElement_(XBool * _ret, const XHandle * const _hd); 55 */ 49 void xios_handle_create_ (XHandle * const _ret, const XDType * const _dtype, const XString _id); 56 50 57 51 /* ******************** XML INTERFACE *********************** */ 58 void xios_xml_parse_file_ ( XString _filename);59 void xios_xml_parse_string_( XString _xmlcontent);52 void xios_xml_parse_file_ (const XString _filename); 53 void xios_xml_parse_string_(const XString _xmlcontent); 60 54 61 55 /* ******************** DATA TREATMENT INTERFACE ************ */ 62 void xios_dtreatment_new_(XHandle * _dt, const XHandle * const _hd);56 void xios_dtreatment_new_(XHandle * const _dt, const XHandle * const _hd); 63 57 void xios_dtreatment_create_files_and_headers_(const XHandle * const _hd, const XFileType * const _ft); 64 58 65 59 /* ******************** CONTEXT INTERFACE ******************* */ 66 void xios_context_set_current_(const XHandle * const _ctxt, const bool * const _wswap); 60 void xios_context_set_current_ (const XHandle * const _ctxt, const bool * const _wswap); 61 void xios_context_get_current_ (XHandle * _ctxt); 62 void xios_context_get_calendar_(const XHandle * const _ctxt, XHandle * _cal); 63 /// void xios_context_ShowTree_ (void); 67 64 68 69 /* 70 void xios_context_GetCurrent_(XHandle * _ctxt); 71 void xios_context_ShowTree_ (void); 72 73 void xios_context_getCalendar_(const XHandle * const _ctxt, XHandle* _cal); 74 */ 75 76 /* ******************** AXIS INTERFACE ********************** */ 77 /* ******************** DOMAIN INTERFACE ******************** */ 78 /* ******************** FIELD INTERFACE ********************* */ 79 /* ******************** FILE INTERFACE ********************** */ 80 /* ******************** GRID INTERFACE ********************** */ 81 /* ******************** GROUP INTERFACE ********************* */ 65 /* ******************** CALENDAR INTERFACE ****************** */ 66 void xios_calendar_set_timestep_(const XHandle * const _cal, const XDuration * const _dur); 82 67 83 68 #ifdef __cplusplus -
XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp
r132 r134 5 5 namespace XMLIOSERVER 6 6 { 7 class DataTreatment; 8 7 9 class Context : public ObjectTemplate<Context> 8 10 { … … 10 12 11 13 Context(void) 12 : ObjectTemplate<Context>(), ccalendar(NULL), 14 : ObjectTemplate<Context>(), 15 dtreatment(NULL), ccalendar(NULL), 13 16 fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL), domainDef(NULL) 14 { /* Ne rien faire de plus */}17 { /* Ne rien faire de plus */ } 15 18 16 19 Context(const string& _id) 17 : ObjectTemplate<Context>(_id), ccalendar(NULL), 20 : ObjectTemplate<Context>(_id), 21 dtreatment(NULL), ccalendar(NULL), 18 22 fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL), domainDef(NULL) 19 { /* Ne rien faire de plus */}20 21 FieldDefinition* getFieldDefinition (void) const { return (this->fieldDef ); }22 FileDefinition* getFileDefinition (void) const { return (this->fileDef ); }23 AxisDefinition* getAxisDefinition (void) const { return (this->axisDef ); }24 GridDefinition* getGridDefinition (void) const { return (this->gridDef ); }23 { /* Ne rien faire de plus */ } 24 25 FieldDefinition * getFieldDefinition (void) const { return (this->fieldDef ); } 26 FileDefinition * getFileDefinition (void) const { return (this->fileDef ); } 27 AxisDefinition * getAxisDefinition (void) const { return (this->axisDef ); } 28 GridDefinition * getGridDefinition (void) const { return (this->gridDef ); } 25 29 DomainDefinition * getDomainDefinition(void) const { return (this->domainDef); } 26 30 27 AbstractCalendar * getCalendar(void) const { return (this->ccalendar ); } 31 AbstractCalendar * getCalendar (void) const { return (ccalendar ); } 32 DataTreatment * getDataTreatment(void) const { return (dtreatment); } 28 33 29 34 AbstractCalendar * setCalendar(const string& _calName, const string& _dateStr) 30 35 { 36 if(ccalendar != NULL) delete ccalendar; 37 31 38 if (_calName.compare("D360") == 0) 32 39 return (ccalendar = new D360Calendar(_dateStr)); … … 45 52 } 46 53 47 ~Context(void) 54 template <class T> 55 DataTreatment * setDataTreatment(void) 56 { return (dtreatment = (ccalendar == NULL)? NULL : new T(this)); } 57 58 public : /* virtual */ 59 60 virtual ~Context(void) 48 61 { 49 62 // Désallocation dynamique de mémoire pour chacun des groupes de définition si nécessaire. 50 if( fieldDef != NULL) delete fieldDef; if(fileDef != NULL) delete fileDef ;51 if( axisDef != NULL) delete axisDef; if(gridDef != NULL) delete gridDef ;63 if( fieldDef != NULL) delete fieldDef ; if(fileDef != NULL) delete fileDef ; 64 if( axisDef != NULL) delete axisDef ; if(gridDef != NULL) delete gridDef ; 52 65 if(domainDef != NULL) delete domainDef ; 53 66 54 67 // Désallocation dynamique de mémoire pour le calendrier associé au contexte courant si nécessaire. 55 if(ccalendar != NULL) delete ccalendar; 56 } 57 58 public : /* virtual */ 68 if(ccalendar != NULL) delete ccalendar; 69 // INFO La mémoire dédiée à dtreatment est désallouée ailleurs. 70 } 59 71 60 72 virtual void parse (XMLNode& _node) … … 117 129 virtual void printChild(ostream& out) const 118 130 { 119 if( fieldDef != NULL) out << *(FieldGroup*) fieldDef<< std::endl;120 if( fileDef != NULL) out << *(FileGroup*) fileDef<< std::endl;121 if( axisDef != NULL) out << *(AxisDefinition*) axisDef<< std::endl;122 if( gridDef != NULL) out << *(GridDefinition*) gridDef<< std::endl;131 if( fieldDef != NULL) out << *( FieldDefinition*) fieldDef << std::endl; 132 if( fileDef != NULL) out << *( FileDefinition*) fileDef << std::endl; 133 if( axisDef != NULL) out << *( AxisDefinition*) axisDef << std::endl; 134 if( gridDef != NULL) out << *( GridDefinition*) gridDef << std::endl; 123 135 if(domainDef != NULL) out << *(DomainDefinition*) domainDef << std::endl; 124 136 } … … 128 140 if (_parent != 0) return; 129 141 // Résolution des héritages descendants pour chacun des groupes de définitions. 130 if( fieldDef != NULL) fieldDef->solveDescInheritance();131 if( fileDef != NULL) fileDef->solveDescInheritance();132 if( axisDef != NULL) axisDef->solveDescInheritance();133 if( gridDef != NULL) gridDef->solveDescInheritance();142 if( fieldDef != NULL) fieldDef->solveDescInheritance(); 143 if( fileDef != NULL) fileDef->solveDescInheritance(); 144 if( axisDef != NULL) axisDef->solveDescInheritance(); 145 if( gridDef != NULL) gridDef->solveDescInheritance(); 134 146 if(domainDef != NULL) domainDef->solveDescInheritance(); 135 147 } … … 176 188 Poco::HashMap<string, StrHashMap<Context> >::Iterator it; 177 189 178 for ( it = AllListContext.begin(); it != AllListContext.end(); it++) 190 for ( it = AllListContext.begin(); 191 it != AllListContext.end(); it++) 179 192 { 180 193 // Résolution des héritages descendants (cà d des héritages de groupes) pour chacun des contextes. … … 192 205 193 206 static bool HasContext(const string& id) 194 { 195 Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 196 return (AllListContext.find(id) != AllListContext.end()); 197 } 207 { return (Context::GetAllListObject().find(id) != Context::GetAllListObject().end()); } 198 208 199 209 static Context* GetContext(const string& id) 200 210 { return (Context::GetAllListObject()[id][id]); } 201 211 212 static const std::stack<string>& GetStackContextId(void) 213 { return (Context::Stid); } 214 215 static Context* GetCurrentContext(void) 216 { return (Context::GetObject(Context::GetCurrentContextId())); } 217 202 218 static Context* SwapContext(void) 203 219 { … … 210 226 return (Context::GetObject(lastId)); 211 227 } 212 213 static const std::stack<string>& GetStackContextId(void)214 { return (Context::Stid); }215 216 static Context* GetCurrentContext(void)217 { return (Context::GetObject(Context::GetCurrentContextId())); }218 228 219 229 static void SetCurrentContext(const string& id, bool withSwap = false, bool withcheck = true) … … 248 258 static std::stack<string> Stid; 249 259 260 DataTreatment * dtreatment; 250 261 AbstractCalendar * ccalendar; 251 262 252 FieldDefinition* fieldDef;253 FileDefinition* fileDef;254 AxisDefinition* axisDef;255 GridDefinition* gridDef;263 FieldDefinition * fieldDef; 264 FileDefinition * fileDef; 265 AxisDefinition * axisDef; 266 GridDefinition * gridDef; 256 267 DomainDefinition * domainDef; 257 268 -
XMLIO_V2/dev/dev_rv/src/XMLIO/data_treatment.hpp
r131 r134 8 8 public : 9 9 10 DataTreatment(Context* const _ctxt 11 10 DataTreatment(Context* const _ctxt = Context::GetCurrentContext(), 11 const AbstractCalendar& cal = *Context::GetCurrentContext()->getCalendar()) 12 12 : enabledFiles(), currentContext(_ctxt) 13 13 { this->doTreatment(cal); } … … 131 131 132 132 // Résolution des héritages par référence au niveau des fichiers. 133 const std::vector<CFile*>& allFiles = CFile::GetCurrentListObject().getVector(); 134 for (unsigned int i = 0; i < allFiles.size(); i++) allFiles[i]->solveFieldRefInheritance(); 133 const std::vector<CFile*>& allFiles = 134 CFile::GetCurrentListObject().getVector(); 135 for (unsigned int i = 0; i < allFiles.size(); i++) 136 allFiles[i]->solveFieldRefInheritance(); 135 137 } 136 138 -
XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90
r133 r134 17 17 18 18 TYPE XDuration 19 REAL(kind = 4) :: year, month, day, hour, minute, second19 REAL(kind = 8) :: year, month, day, hour, minute, second 20 20 END TYPE XDuration 21 21 … … 71 71 SUBROUTINE xios_context_set_current(context, withswap) 72 72 USE XTYPE 73 TYPE(XHandle), INTENT(IN) 74 LOGICAL, OPTIONAL, INTENT(IN) 73 TYPE(XHandle), INTENT(IN) :: context 74 LOGICAL, OPTIONAL, INTENT(IN) :: withswap 75 75 END SUBROUTINE xios_context_set_current 76 77 SUBROUTINE xios_context_get_current(context) 78 USE XTYPE 79 TYPE(XHandle), INTENT(IN) :: context 80 END SUBROUTINE xios_context_get_current 81 82 SUBROUTINE xios_context_get_calendar(context, calend) 83 USE XTYPE 84 TYPE(XHandle), INTENT(IN) :: context 85 TYPE(XHandle), INTENT(OUT) :: calend 86 END SUBROUTINE xios_context_get_calendar 76 87 77 88 END INTERFACE 78 89 79 90 END MODULE ICONTEXT 91 92 MODULE ICALENDAR 93 IMPLICIT NONE 94 INTERFACE 95 96 SUBROUTINE xios_calendar_set_timestep(calend, dur) 97 USE XTYPE 98 TYPE(XHandle) , INTENT(IN) :: calend 99 TYPE(XDuration), INTENT(IN) :: dur 100 END SUBROUTINE xios_calendar_set_timestep 101 102 END INTERFACE 103 104 END MODULE ICALENDAR 80 105 81 106 MODULE IDATATREATMENT … … 104 129 USE ICONTEXT 105 130 USE IDATATREATMENT 131 USE ICALENDAR 106 132 107 133 IMPLICIT NONE 108 134 109 TYPE(XHandle) :: context1 = NULLHANDLE 110 TYPE(XHandle) :: dtreat = NULLHANDLE 135 INTEGER :: compt 136 TYPE(XHandle) :: context1 = NULLHANDLE 137 TYPE(XHandle) :: dtreat = NULLHANDLE 138 TYPE(XHandle) :: calend = NULLHANDLE 139 TYPE(XDuration) :: timestep_1h = XDuration(0., 0., 0., 1., 0., 0.) 111 140 112 141 ! Parsing du document xml depuis un fichier situé sur le disque. 113 142 CALL xios_xml_Parse_File("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_simple_test.xml") 143 144 ! Le calendrier doit être initialisé ici s'il ne l'a pas déjà été depuis le document xml. 114 145 115 146 ! Création d'un handle sur le contexte dans lequel on souhaite travailler, cà d 'context1' ici. … … 134 165 CALL xios_dtreatment_create_files_and_headers(dtreat, NETCDF4) 135 166 167 ! On récupére le calendrier associé au contexte en cours de traitement. 168 CALL xios_context_get_calendar(context1, calend) 169 iF ((calend%dtype == 0) .AND. (calend%daddr == 0)) THEN 170 PRINT *, "Impossible de récupérer le calendrier !" 171 STOP 172 END IF 173 174 ! On change la durée du timestep. 175 CALL xios_calendar_set_timestep(calend, timestep_1h) 176 177 ! Exécution de la boucle de calcul-écriture. 178 DO compt = 0, 9 179 180 END DO 181 136 182 END PROGRAM MAIN
Note: See TracChangeset
for help on using the changeset viewer.