1 #ifndef MEDSPLITTER_MESHCOLLECTIONMEDXMLDRIVER_H
2 #define MEDSPLITTER_MESHCOLLECTIONMEDXMLDRIVER_H
5 #include <libxml/tree.h>
6 #include <libxml/parser.h>
7 #include <libxml/xpath.h>
8 #include <libxml/xpathInternals.h>
12 /*!reads a distributed field
14 * \param fields vector of fields (one field per subdomain)
15 * \param fieldname name of the field
16 * \param itnumber number of iteration
17 * \param ordernumber internal number inside the iteration
20 void MESHCollectionMedXMLDriver::_readFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname, int itnumber, int ordernumber)
22 for (int i=0; i<m_collection->getMesh().size(); i++)
25 strcpy(filename,m_filename[i].c_str());
26 cout << "maillage : " << filename << " champ : " << fieldname << endl;
27 // MEDMEM::FIELD<T>* field = new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber);
28 fields.push_back (new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber));
33 /*!writes a distributed field
35 * \param fields vector of fields (one field per subdomain)
36 * \param fieldname name of the field
39 void MESHCollectionMedXMLDriver::_writeFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname)
41 xmlDocPtr master_doc=xmlParseFile(m_master_filename.c_str());
44 throw MEDEXCEPTION("MEDSPLITTER writeFields - Master File does not exist");
48 xmlXPathContextPtr xpathCtx = xmlXPathNewContext(master_doc);
49 xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(BAD_CAST "//mapping/mesh", xpathCtx);
50 //assuming there is only one mesh in the XML file
51 xmlNodePtr mesh_node= xpathObj->nodesetval->nodeTab[0];
53 //adds the field to the master file if necessary
54 bool exist_field =false;
55 xpathObj = xmlXPathEvalExpression(BAD_CAST "//mapping/mesh/field", xpathCtx);
56 //assuming there is only one mesh in the XML file
57 int field_nr = xpathObj->nodesetval->nodeNr;
58 for (int i=0; i<field_nr; i++)
60 //field node has only one property
61 if ( strcmp((const char*)xpathObj->nodesetval->nodeTab[i]->properties->children->content, fieldname)==0)
65 xmlNodePtr field_node;
68 field_node = xmlNewChild(mesh_node, 0, BAD_CAST "field",0);
69 xmlNewProp(field_node,BAD_CAST "name",BAD_CAST fieldname);
73 for (int i=0; i<m_collection->getMesh().size(); i++)
76 strcpy(filename,m_filename[i].c_str());
77 int driverid = fields[i]->addDriver(MEDMEM::MED_DRIVER, filename, fieldname);
78 fields[i]->write(driverid);
80 //adds the partition to the master file if the field had not been
84 xmlNodePtr chunk_node= xmlNewChild(field_node,0,BAD_CAST "chunk",0);
87 xmlNewProp(chunk_node,BAD_CAST "subdomain",BAD_CAST id);
88 //xmlNewProp(chunk_node,BAD_CAST "name", BAD_CAST fieldname);
89 //xmlNodePtr fieldname_node=
90 xmlNewChild(chunk_node,0,BAD_CAST "name", BAD_CAST fieldname);
94 xmlKeepBlanksDefault(0);
95 xmlSaveFormatFileEnc(m_master_filename.c_str(), master_doc, "UTF-8", 1);
98 xmlXPathFreeContext(xpathCtx);
99 xmlFreeDoc(master_doc);