int main (int argc, char **argv) { int _i=0; med_err _ret=-1; med_idt _fid=0; med_int _ngeotype=0; const char _meshname[MED_NAME_SIZE+1]="maa1"; med_bool _chgt=MED_FALSE,_trsf=MED_FALSE; /*TODO : Traduire MED_TAILLE_NOM_ENTITE */ char _geotypename[MED_NAME_SIZE+1]=""; med_geometry_type _geotype=MED_NO_GEOTYPE; /* Ouverture en mode creation du fichier med */ _fid = MEDfileOpen("Test_MEDmeshStructElementVarAttWr.med",MED_ACC_RDONLY); if (_fid < 0) { MESSAGE("Erreur a la creation du fichier current.med"); return -1; } /* TODO : Créer un itérateur sur les types d'entités*/ if ( (_ngeotype = MEDmeshnEntity(_fid,_meshname,MED_NO_DT,MED_NO_IT, MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_GLOBAL_STMODE, &_chgt,&_trsf) ) < 0 ) { MESSAGE ("Erreur à la lecture du nombre de type géométrique pour le type d'entités MED_STRUCT_ELEMENT"); goto ERROR; } ISCRUTE(_ngeotype); for (_i=0; _i < _ngeotype; _i++) { if ( MEDmeshEntityInfo(_fid, _meshname, MED_NO_DT,MED_NO_IT, MED_STRUCT_ELEMENT, _i+1, _geotypename,&_geotype ) <0 ){ MESSAGE ("Erreur à la demande d'informations pour le type d'entités MED_STRUCT_ELEMENT"); ISCRUTE_int(_i); goto ERROR; } SSCRUTE(_geotypename); ISCRUTE(_geotype); } _ret = 0; ERROR: if (MEDfileClose(_fid) < 0) { MESSAGE("ERROR : file closing"); return -1; } return _ret; }
int main (int argc, char **argv) { med_err ret = 0; med_idt fid; med_int mdim,sdim; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1]; /* le nombre de noeuds */ med_int nnoe = 0; /* table des numeros global */ med_int *numglobalnoe=NULL; /* variable de stockage pour reperer le maillage */ med_int i; char des[MED_COMMENT_SIZE+1]=""; char dtunit[MED_SNAME_SIZE+1]=""; char nomcoo[3*MED_SNAME_SIZE+1]=""; char unicoo[3*MED_SNAME_SIZE+1]=""; med_axis_type rep; med_mesh_type type; med_sorting_type sort; med_int nstep=0; med_bool chgt=MED_FALSE,trsf=MED_FALSE; if (argc != 2) { MESSAGE("Il faut passer un fichier MED en param�tre"); return -1; } /* Ouverture du fichier passe en argument */ if ((fid = MEDfileOpen(argv[1],MED_ACC_RDWR)) < 0) { MESSAGE("Erreur a l'ouverture du fichier : "); SSCRUTE(argv[1]); return -1; } if ((sdim=MEDmeshnAxis(fid, 1)) <0) { MESSAGE("Erreur � la lecture de la dimension de l'espace du maillage :"); SSCRUTE(maa); return -1; } /* Lecture des infos concernant le premier maillage */ if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, des, dtunit, &sort, &nstep, &rep, nomcoo,unicoo) < 0 ) { MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa); return -1; } else { printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type); printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim); printf("\t -Description du maillage : %s\n",des); printf("\t -Noms des axes : %s\n",nomcoo); printf("\t -Unit�s des axes : %s\n",unicoo); printf("\t -Type de rep�re : %d\n",rep); printf("\t -Nombre d'�tapes de calcul : "IFORMAT"\n",nstep); printf("\t -Unit� des dates : %s\n\n",dtunit); } /* Lecture du nombre de noeuds */ if ( (nnoe = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE, &chgt,&trsf)) < 0) { MESSAGE("Erreur a la lecture du nombre de noeuds "); return -1; } printf("Nombre de noeuds : "IFORMAT" \n",nnoe); /* Allocations memoires */ /* table de la numerotation globale profil : (nombre de noeuds ) */ if (nnoe > 0) { numglobalnoe = (med_int*) malloc(sizeof(med_int)*nnoe); for (i=0;i<nnoe;i++) { numglobalnoe[i]=i+100; } } /* ecriture de la numerotation globale */ if (MEDmeshGlobalNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numglobalnoe)<0) { MESSAGE("Erreur a l''ecriture de la numerotation globale"); return -1; } free(numglobalnoe); /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } return 0; }
int GModel::readMED(const std::string &name) { med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE); if(fid < 0) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } med_int v[3], vf[3]; MEDversionDonner(&v[0], &v[1], &v[2]); MEDversionLire(fid, &vf[0], &vf[1], &vf[2]); Msg::Info("Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0], vf[1], vf[2], v[0], v[1], v[2]); if(vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)){ Msg::Error("Cannot read MED file older than V2.2"); return 0; } std::vector<std::string> meshNames; for(int i = 0; i < MEDnMaa(fid); i++){ char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1]; med_int spaceDim; med_maillage meshType; #if (MED_MAJOR_NUM == 3) med_int meshDim, nStep; char dtUnit[MED_SNAME_SIZE + 1]; char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1]; med_sorting_type sortingType; med_axis_type axisType; if(MEDmeshInfo(fid, i + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc, dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){ #else if(MEDmaaInfo(fid, i + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){ #endif Msg::Error("Unable to read mesh information"); return 0; } meshNames.push_back(meshName); } if(MEDfermer(fid) < 0){ Msg::Error("Unable to close file '%s'", (char*)name.c_str()); return 0; } int ret = 1; for(unsigned int i = 0; i < meshNames.size(); i++){ // we use the filename as a kind of "partition" indicator, allowing to // complete a model part by part (used e.g. in DDM, since MED does not store // a partition index) GModel *m = findByName(meshNames[i], name); if(!m) m = new GModel(meshNames[i]); ret = m->readMED(name, i); if(!ret) return 0; } return ret; } int GModel::readMED(const std::string &name, int meshIndex) { med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE); if(fid < 0){ Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int numMeshes = MEDnMaa(fid); if(meshIndex >= numMeshes){ Msg::Info("Could not find mesh %d in MED file", meshIndex); return 0; } checkPointMaxNumbers(); GModel::setCurrent(this); // make sure we increment max nums in this model // read mesh info char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1]; med_int spaceDim, nStep = 1; med_maillage meshType; #if (MED_MAJOR_NUM == 3) med_int meshDim; char dtUnit[MED_SNAME_SIZE + 1]; char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1]; med_sorting_type sortingType; med_axis_type axisType; if(MEDmeshInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc, dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){ #else if(MEDmaaInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){ #endif Msg::Error("Unable to read mesh information"); return 0; } // FIXME: we should support multi-step MED3 meshes (probably by // storing each mesh as a separate model, with a naming convention // e.g. meshName_step%d). This way we could also handle multi-mesh // time sequences in MED3. if(nStep > 1) Msg::Warning("Discarding %d last meshes in multi-step MED mesh", nStep - 1); setName(meshName); setFileName(name); if(meshType == MED_NON_STRUCTURE){ Msg::Info("Reading %d-D unstructured mesh <<%s>>", spaceDim, meshName); } else{ Msg::Error("Reading structured MED meshes is not supported"); return 0; } med_int vf[3]; MEDversionLire(fid, &vf[0], &vf[1], &vf[2]); // read nodes #if (MED_MAJOR_NUM == 3) med_bool changeOfCoord, geoTransform; med_int numNodes = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, MED_COORDINATE, MED_NO_CMODE, &changeOfCoord, &geoTransform); #else med_int numNodes = MEDnEntMaa(fid, meshName, MED_COOR, MED_NOEUD, MED_NONE, MED_NOD); #endif if(numNodes < 0){ Msg::Error("Could not read number of MED nodes"); return 0; } if(numNodes == 0){ Msg::Error("No nodes in MED mesh"); return 0; } std::vector<MVertex*> verts(numNodes); std::vector<med_float> coord(spaceDim * numNodes); #if (MED_MAJOR_NUM == 3) if(MEDmeshNodeCoordinateRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, &coord[0]) < 0){ #else std::vector<char> coordName(spaceDim * MED_TAILLE_PNOM + 1); std::vector<char> coordUnit(spaceDim * MED_TAILLE_PNOM + 1); med_repere rep; if(MEDcoordLire(fid, meshName, spaceDim, &coord[0], MED_FULL_INTERLACE, MED_ALL, 0, 0, &rep, &coordName[0], &coordUnit[0]) < 0){ #endif Msg::Error("Could not read MED node coordinates"); return 0; } std::vector<med_int> nodeTags(numNodes); #if (MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, &nodeTags[0]) < 0) #else if(MEDnumLire(fid, meshName, &nodeTags[0], numNodes, MED_NOEUD, MED_NONE) < 0) #endif nodeTags.clear(); for(int i = 0; i < numNodes; i++) verts[i] = new MVertex(coord[spaceDim * i], (spaceDim > 1) ? coord[spaceDim * i + 1] : 0., (spaceDim > 2) ? coord[spaceDim * i + 2] : 0., 0, nodeTags.empty() ? 0 : nodeTags[i]); // read elements (loop over all possible MSH element types) for(int mshType = 0; mshType < MSH_NUM_TYPE; mshType++){ med_geometrie_element type = msh2medElementType(mshType); if(type == MED_NONE) continue; #if (MED_MAJOR_NUM == 3) med_bool changeOfCoord; med_bool geoTransform; med_int numEle = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, MED_CONNECTIVITY, MED_NODAL, &changeOfCoord, &geoTransform); #else med_int numEle = MEDnEntMaa(fid, meshName, MED_CONN, MED_MAILLE, type, MED_NOD); #endif if(numEle <= 0) continue; int numNodPerEle = type % 100; std::vector<med_int> conn(numEle * numNodPerEle); #if (MED_MAJOR_NUM == 3) if(MEDmeshElementConnectivityRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, MED_NODAL, MED_FULL_INTERLACE, &conn[0]) < 0){ #else if(MEDconnLire(fid, meshName, spaceDim, &conn[0], MED_FULL_INTERLACE, 0, MED_ALL, MED_MAILLE, type, MED_NOD) < 0){ #endif Msg::Error("Could not read MED elements"); return 0; } std::vector<med_int> fam(numEle, 0); #if (MED_MAJOR_NUM == 3) if(MEDmeshEntityFamilyNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, &fam[0]) < 0){ #else if(MEDfamLire(fid, meshName, &fam[0], numEle, MED_MAILLE, type) < 0){ #endif Msg::Info("No family number for elements: using 0 as default family number"); } std::vector<med_int> eleTags(numEle); #if (MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, &eleTags[0]) < 0) #else if(MEDnumLire(fid, meshName, &eleTags[0], numEle, MED_MAILLE, type) < 0) #endif eleTags.clear(); std::map<int, std::vector<MElement*> > elements; MElementFactory factory; for(int j = 0; j < numEle; j++){ std::vector<MVertex*> v(numNodPerEle); for(int k = 0; k < numNodPerEle; k++) v[k] = verts[conn[numNodPerEle * j + med2mshNodeIndex(type, k)] - 1]; MElement *e = factory.create(mshType, v, eleTags.empty() ? 0 : eleTags[j]); if(e) elements[-fam[j]].push_back(e); } _storeElementsInEntities(elements); } _associateEntityWithMeshVertices(); _storeVerticesInEntities(verts); // read family info med_int numFamilies = MEDnFam(fid, meshName); if(numFamilies < 0){ Msg::Error("Could not read MED families"); return 0; } for(int i = 0; i < numFamilies; i++){ #if (MED_MAJOR_NUM == 3) med_int numAttrib = (vf[0] == 2) ? MEDnFamily23Attribute(fid, meshName, i + 1) : 0; med_int numGroups = MEDnFamilyGroup(fid, meshName, i + 1); #else med_int numAttrib = MEDnAttribut(fid, meshName, i + 1); med_int numGroups = MEDnGroupe(fid, meshName, i + 1); #endif if(numAttrib < 0 || numGroups < 0){ Msg::Error("Could not read MED groups or attributes"); return 0; } std::vector<med_int> attribId(numAttrib + 1); std::vector<med_int> attribVal(numAttrib + 1); std::vector<char> attribDes(MED_TAILLE_DESC * numAttrib + 1); std::vector<char> groupNames(MED_TAILLE_LNOM * numGroups + 1); char familyName[MED_TAILLE_NOM + 1]; med_int familyNum; #if (MED_MAJOR_NUM == 3) if(vf[0] == 2){ // MED2 file if(MEDfamily23Info(fid, meshName, i + 1, familyName, &attribId[0], &attribVal[0], &attribDes[0], &familyNum, &groupNames[0]) < 0){ Msg::Error("Could not read info for MED2 family %d", i + 1); continue; } } else{ if(MEDfamilyInfo(fid, meshName, i + 1, familyName, &familyNum, &groupNames[0]) < 0){ Msg::Error("Could not read info for MED3 family %d", i + 1); continue; } } #else if(MEDfamInfo(fid, meshName, i + 1, familyName, &familyNum, &attribId[0], &attribVal[0], &attribDes[0], &numAttrib, &groupNames[0], &numGroups) < 0){ Msg::Error("Could not read info for MED family %d", i + 1); continue; } #endif // family tags are unique (for all dimensions) GEntity *ge; if((ge = getRegionByTag(-familyNum))){} else if((ge = getFaceByTag(-familyNum))){} else if((ge = getEdgeByTag(-familyNum))){} else ge = getVertexByTag(-familyNum); if(ge){ elementaryNames[std::pair<int, int>(ge->dim(), -familyNum)] = familyName; if(numGroups > 0){ for(int j = 0; j < numGroups; j++){ char tmp[MED_TAILLE_LNOM + 1]; strncpy(tmp, &groupNames[j * MED_TAILLE_LNOM], MED_TAILLE_LNOM); tmp[MED_TAILLE_LNOM] = '\0'; // don't use same physical number across dimensions, as e.g. getdp // does not support this int pnum = setPhysicalName(tmp, ge->dim(), getMaxPhysicalNumber(-1) + 1); if(std::find(ge->physicals.begin(), ge->physicals.end(), pnum) == ge->physicals.end()) ge->physicals.push_back(pnum); } } } } // check if we need to read some post-processing data later #if (MED_MAJOR_NUM == 3) bool postpro = (MEDnField(fid) > 0) ? true : false; #else bool postpro = (MEDnChamp(fid, 0) > 0) ? true : false; #endif if(MEDfermer(fid) < 0){ Msg::Error("Unable to close file '%s'", (char*)name.c_str()); return 0; } return postpro ? 2 : 1; } template<class T> static void fillElementsMED(med_int family, std::vector<T*> &elements, std::vector<med_int> &conn, std::vector<med_int> &fam, med_geometrie_element &type) { if(elements.empty()) return; type = msh2medElementType(elements[0]->getTypeForMSH()); if(type == MED_NONE){ Msg::Warning("Unsupported element type in MED format"); return; } for(unsigned int i = 0; i < elements.size(); i++){ elements[i]->setVolumePositive(); for(int j = 0; j < elements[i]->getNumVertices(); j++) conn.push_back(elements[i]->getVertex(med2mshNodeIndex(type, j))->getIndex()); fam.push_back(family); } } static void writeElementsMED(med_idt &fid, char *meshName, std::vector<med_int> &conn, std::vector<med_int> &fam, med_geometrie_element type) { if(fam.empty()) return; #if (MED_MAJOR_NUM == 3) if(MEDmeshElementWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_CELL, type, MED_NODAL, MED_FULL_INTERLACE, (med_int)fam.size(), &conn[0], MED_FALSE, 0, MED_FALSE, 0, MED_TRUE, &fam[0]) < 0) #else if(MEDelementsEcr(fid, meshName, (med_int)3, &conn[0], MED_FULL_INTERLACE, 0, MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size(), MED_MAILLE, type, MED_NOD) < 0) #endif Msg::Error("Could not write MED elements"); } int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor) { med_idt fid = MEDouvrir((char*)name.c_str(), MED_CREATION); if(fid < 0){ Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } // write header if(MEDfichDesEcr(fid, (char*)"MED file generated by Gmsh") < 0){ Msg::Error("Unable to write MED descriptor"); return 0; } char *meshName = (char*)getName().c_str(); // Gmsh always writes 3D unstructured meshes #if (MED_MAJOR_NUM == 3) char dtUnit[MED_SNAME_SIZE + 1] = ""; char axisName[3 * MED_SNAME_SIZE + 1] = ""; char axisUnit[3 * MED_SNAME_SIZE + 1] = ""; if(MEDmeshCr(fid, meshName, 3, 3, MED_UNSTRUCTURED_MESH, "Mesh created with Gmsh", dtUnit, MED_SORT_DTIT, MED_CARTESIAN, axisName, axisUnit) < 0){ #else if(MEDmaaCr(fid, meshName, 3, MED_NON_STRUCTURE, (char*)"Mesh created with Gmsh") < 0){ #endif Msg::Error("Could not create MED mesh"); return 0; } // if there are no physicals we save all the elements if(noPhysicalGroups()) saveAll = true; // index the vertices we save in a continuous sequence (MED // connectivity is given in terms of vertex indices) indexMeshVertices(saveAll); // get a vector containing all the geometrical entities in the // model (the ordering of the entities must be the same as the one // used during the indexing of the vertices) std::vector<GEntity*> entities; getEntities(entities); std::map<GEntity*, int> families; // write the families { // always create a "0" family, with no groups or attributes #if (MED_MAJOR_NUM == 3) if(MEDfamilyCr(fid, meshName, "F_0", 0, 0, "") < 0) #else if(MEDfamCr(fid, meshName, (char*)"F_0", 0, 0, 0, 0, 0, 0, 0) < 0) #endif Msg::Error("Could not create MED family 0"); // create one family per elementary entity, with one group per // physical entity and no attributes for(unsigned int i = 0; i < entities.size(); i++){ if(saveAll || entities[i]->physicals.size()){ int num = - ((int)families.size() + 1); families[entities[i]] = num; std::ostringstream fs; fs << entities[i]->dim() << "D_" << entities[i]->tag(); std::string familyName = "F_" + fs.str(); std::string groupName; for(unsigned j = 0; j < entities[i]->physicals.size(); j++){ std::string tmp = getPhysicalName (entities[i]->dim(), entities[i]->physicals[j]); if(tmp.empty()){ // create unique name std::ostringstream gs; gs << entities[i]->dim() << "D_" << entities[i]->physicals[j]; groupName += "G_" + gs.str(); } else groupName += tmp; groupName.resize((j + 1) * MED_TAILLE_LNOM, ' '); } #if (MED_MAJOR_NUM == 3) if(MEDfamilyCr(fid, meshName, familyName.c_str(), (med_int)num, (med_int)entities[i]->physicals.size(), groupName.c_str()) < 0) #else if(MEDfamCr(fid, meshName, (char*)familyName.c_str(), (med_int)num, 0, 0, 0, 0, (char*)groupName.c_str(), (med_int)entities[i]->physicals.size()) < 0) #endif Msg::Error("Could not create MED family %d", num); } } } // write the nodes { std::vector<med_float> coord; std::vector<med_int> fam; for(unsigned int i = 0; i < entities.size(); i++){ for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ MVertex *v = entities[i]->mesh_vertices[j]; if(v->getIndex() >= 0){ coord.push_back(v->x() * scalingFactor); coord.push_back(v->y() * scalingFactor); coord.push_back(v->z() * scalingFactor); fam.push_back(0); // we never create node families } } } if(fam.empty()){ Msg::Error("No nodes to write in MED mesh"); return 0; } #if (MED_MAJOR_NUM == 3) if(MEDmeshNodeWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_FULL_INTERLACE, (med_int)fam.size(), &coord[0], MED_FALSE, "", MED_FALSE, 0, MED_TRUE, &fam[0]) < 0) #else char coordName[3 * MED_TAILLE_PNOM + 1] = "x y z "; char coordUnit[3 * MED_TAILLE_PNOM + 1] = "unknown unknown unknown "; if(MEDnoeudsEcr(fid, meshName, (med_int)3, &coord[0], MED_FULL_INTERLACE, MED_CART, coordName, coordUnit, 0, MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size()) < 0) #endif Msg::Error("Could not write nodes"); } // write the elements { { // points med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(viter it = firstVertex(); it != lastVertex(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->points, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // lines med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(eiter it = firstEdge(); it != lastEdge(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->lines, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // triangles med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(fiter it = firstFace(); it != lastFace(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->triangles, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // quads med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(fiter it = firstFace(); it != lastFace(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->quadrangles, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // tets med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->tetrahedra, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // hexas med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->hexahedra, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // prisms med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->prisms, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // pyramids med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->pyramids, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } } if(MEDfermer(fid) < 0){ Msg::Error("Unable to close file '%s'", (char*)name.c_str()); return 0; } return 1; } #else int GModel::readMED(const std::string &name) { Msg::Error("Gmsh must be compiled with MED support to read '%s'", name.c_str()); return 0; }
int main (int argc, char **argv) { med_err ret = 0; med_idt fid = 0; med_int mdim=0,sdim=0; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1]; /* le nombre de noeuds */ med_int nnoe = 0; /* table des coordonnees */ med_float *coo; /* tables des noms et des unites des coordonnees (dimension*MED_SNAME_SIZE+1) */ char nomcoo[3*MED_SNAME_SIZE+1]=""; char unicoo[3*MED_SNAME_SIZE+1]=""; /* tables des noms, numeros, numeros de familles des noeuds autant d'elements que de noeuds - les noms ont pour longueur MED_SNAME_SIZE */ char *nomnoe; med_int *numnoe; med_int *nufano; med_bool inonoe,inunoe,inufam; med_bool chgt=MED_FALSE, trsf=MED_FALSE; char str [MED_SNAME_SIZE+1] =""; char desc [MED_COMMENT_SIZE+1]=""; char dtunit[MED_SNAME_SIZE+1] =""; med_mesh_type type; med_sorting_type sort; med_axis_type rep; med_int nstep=0; med_int i; /* Ouverture du fichier en mode lecture seule */ if ((fid = MEDfileOpen(argv[1],MED_ACC_RDONLY)) < 0) { MESSAGE("Erreur a l'ouverture du fichier."); return -1; } if ((sdim=MEDmeshnAxis(fid, 1)) <0) { MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :"); SSCRUTE(maa); return -1; } /* Lecture des infos concernant le premier maillage */ if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, desc, dtunit, &sort, &nstep, &rep, nomcoo,unicoo) < 0 ) { MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa); return -1; } else { printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type); printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim); printf("\t -Description du maillage : |%s|\n",desc); printf("\t -Noms des axes : |%s|\n",nomcoo); printf("\t -Unités des axes : |%s|\n",unicoo); printf("\t -Type de repère : %d\n",rep); printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep); printf("\t -Unité des dates : |%s|\n",dtunit); } /* Combien de triangles et de segments */ if ((nnoe = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NODE,MED_COORDINATE, MED_NO_CMODE, &chgt, &trsf)) < 0) { MESSAGE("Erreur a la lecture du nombre de noeuds"); return -1; } printf("Nombre de noeuds : "IFORMAT" \n",nnoe); /* Allocations memoires */ /* table des coordonnees profil : (dimension * nombre de noeuds ) */ if (nnoe > 0) { coo = (med_float*) malloc(sizeof(med_float)*nnoe*mdim); /* table des des numeros, des numeros de familles des noeuds profil : (nombre de noeuds) */ numnoe = (med_int*) malloc(sizeof(med_int)*nnoe); nufano = (med_int*) calloc(nnoe,sizeof(med_int)); /* table des noms des noeuds profil : (nnoe*MED_SNAME_SIZE+1) */ nomnoe = (char*) malloc(MED_SNAME_SIZE*nnoe+1); /* Lecture des noeuds : - Coordonnees - Noms (optionnel dans un fichier MED) - Numeros (optionnel dans un fichier MED) - Numeros de familles */ if (MEDmeshNodeRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE, coo,&inonoe,nomnoe,&inunoe,numnoe,&inufam,nufano) < 0) { MESSAGE("Erreur a la lecture des noeuds du maillage"); ret = -1; } /* Affichage */ if (ret == 0) { printf("Type de repere : %d \n",rep); printf("Nom des coordonnees : \n"); for (i=0;i<mdim;i++) { strncpy(str,nomcoo+i*MED_SNAME_SIZE,MED_SNAME_SIZE); str[MED_SNAME_SIZE] = '\0'; printf("|%s| ",str); } printf("\nUnites des coordonnees : \n"); for (i=0;i<mdim;i++) { strncpy(str,unicoo+i*MED_SNAME_SIZE,MED_SNAME_SIZE); str[MED_SNAME_SIZE] = '\0'; printf("|%s| ",str); } printf("\nCoordonnees des noeuds : \n"); for (i=0;i<nnoe*mdim;i++) printf("%f ",*(coo+i)); if (inonoe) { printf("\nNoms des noeuds : \n"); for (i=0;i<nnoe;i++) { strncpy(str,nomnoe+i*MED_SNAME_SIZE,MED_SNAME_SIZE); str[MED_SNAME_SIZE] = '\0'; printf(" |%s| ",str); } } if (inunoe) { printf("\nNumeros des noeuds : \n"); for (i=0;i<nnoe;i++) printf(""IFORMAT" ",*(numnoe+i)); } printf("\nPrésence de numeros des familles des noeuds : %d\n",inufam); printf("\nNumeros des familles des noeuds : \n"); for (i=0;i<nnoe;i++) printf(IFORMAT" ",*(nufano+i)); printf("\n"); } /* Liberation memoire */ free(coo); free(nomnoe); free(numnoe); free(nufano); } /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } return ret; }
int main (int argc, char **argv) { int _i = 0; int _j = 0; med_idt _fid = 0; med_int _meshdim = 3; med_int _rmeshdim = 0; med_int _rspacedim = 0; med_int _n = 0; med_int _rnnoe = 0; med_int _rnse2 = 0; med_int _rnaxis = 0; const med_int _nnoe = 5; /* table des coordonnees (dimension * nombre de noeuds) */ med_float coo[5*3] = {0.0, 0.0, 0.0, 0.1 , 0.0, 0.0, 1.0, 0.0, 0.0, 1.1 , 0.0, 0.0, 2.0, 0.0, 0.0 }; med_float * _rcoo=NULL; med_int nse2 = 4; med_int se2[10] = {1,2, 2,3, 3,4, 4,5}; med_int * _rse2=NULL; const char _supportmeshname[]="SUPPORT_POUTRE"; char _axisname[3*MED_SNAME_SIZE+1]=""; char _axisunit[3*MED_SNAME_SIZE+1]=""; char _rsupportmeshname[MED_NAME_SIZE+1]=""; char _raxisname[3*MED_SNAME_SIZE+1]=""; char _raxisunit[3*MED_SNAME_SIZE+1]=""; char _rdescription[MED_COMMENT_SIZE+1]=""; med_axis_type _raxistype; med_bool _chgt=MED_FALSE,_trsf=MED_FALSE; strcat(_axisname,"x "); strcat(_axisname,"y "); strcat(_axisname,"z "); strcat(_axisunit,"cm "); strcat(_axisunit,"cm "); strcat(_axisunit,"cm "); /* ouverture du fichier */ if ((_fid = MEDfileOpen("current.med",MODE_ACCES)) < 0) { MESSAGE("Impossible de creer le fichier current.med"); return -1; } if (MEDsupportMeshCr( _fid, _supportmeshname, _meshdim, _meshdim,"Maillage support ED de type poutre", MED_CARTESIAN,_axisname, _axisname) < 0) { MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(_supportmeshname); return -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(_fid,_supportmeshname,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE, _nnoe, coo) < 0) { MESSAGE("Erreur a l'écriture des coordonnees des noeuds du maillage support"); return -1; } /* ecriture des connectivites des segments */ if ( MEDmeshElementConnectivityWr(_fid,_supportmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_CELL, MED_SEG2, MED_NODAL, MED_FULL_INTERLACE, nse2, se2) < 0 ) { MESSAGE("Impossible d'ecrire la connectivité des segments du maillage support : "); return -1; } if (MEDsupportMeshCr( _fid, "MED_BILLE_SUPPORT", _meshdim, _meshdim,"Maillage support ED de type bille", MED_CARTESIAN,_axisname, _axisname) < 0) { MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(_supportmeshname); return -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(_fid,"MED_BILLE_SUPPORT",MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE, 1, coo) < 0) { MESSAGE("Erreur a l'écriture des coordonnees des noeuds du maillage support : MED_BILLE_SUPPORT."); return -1; } if ( (_n =MEDnSupportMesh(_fid)) < 0 ) { MESSAGE("Erreur à la lecture du nombre de maillages supports : "); return -1; } for (_i=1; _i <= _n; ++_i) { if ( (_rnaxis = MEDsupportMeshnAxis(_fid, _i)) < 0) { MESSAGE("Erreur à la lecture du nombre d'axe du repère d'un maillage support : "); return -1; } printf("\t -Dimension de l'espace : %d\n",_rnaxis); if ( MEDsupportMeshInfo(_fid, _i , _rsupportmeshname, &_rspacedim, &_rmeshdim, _rdescription, &_raxistype, _raxisname, _raxisunit) < 0 ) { MESSAGE("Erreur à la lecture des informations sur le maillage support : "); SSCRUTE(_supportmeshname); return -1; } printf("Maillage support de nom : |%s| , de dimension : %d.\n",_rsupportmeshname, _rmeshdim); printf("\t -Dimension de l'espace : %d\n",_rspacedim); printf("\t -Description du maillage : %s\n",_rdescription); printf("\t -Noms des axes : %s\n",_raxisname); printf("\t -Unités des axes : %s\n",_raxisunit); /* Combien de noeuds a lire ? */ _rnnoe = MEDmeshnEntity(_fid,_rsupportmeshname,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE, &_chgt,&_trsf); if (_rnnoe < 0) { MESSAGE("Erreur a la lecture du nombre de noeuds. "); return -1; } else printf("Nombre de noeuds du maillage support: "IFORMAT" \n",_rnnoe); /* Allocations memoires */ if (_rnnoe > 0) { /* table des coordonnees (dimension * nombre de noeuds ) */ _rcoo = (med_float*) calloc(_rnnoe*_rspacedim,sizeof(med_float)); if ( MEDmeshNodeCoordinateRd(_fid, _rsupportmeshname, MED_NO_DT, MED_NO_IT,MED_FULL_INTERLACE, _rcoo) < 0 ) { MESSAGE("Erreur a la lecture des coordonnees des noeuds"); return -1; } else { printf("Valeur de _rcoo : "); for (_j=0;_j<_rnnoe*_rspacedim;_j++) printf("%4.2f ",_rcoo[_j]); printf("\n"); } free(_rcoo); } /* Combien de segments à lire ? */ _rnse2 = MEDmeshnEntity(_fid,_rsupportmeshname,MED_NO_DT,MED_NO_IT, MED_CELL,MED_SEG2,MED_CONNECTIVITY,MED_NODAL, &_chgt,&_trsf); if (_rnse2 < 0) { MESSAGE("Erreur a la lecture du nombre de segments."); return -1; } else printf("Nombre de segments du maillage support: "IFORMAT" \n",_rnse2); if (_rnse2 > 0) { /* table des connectivités (_rnse2 * nombre de noeuds ds un MED_SE2) */ _rse2 = (med_int*) calloc(_rnse2*2,sizeof(med_int)); if ( MEDmeshElementConnectivityRd(_fid, _rsupportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_SEG2,MED_NODAL,MED_FULL_INTERLACE, _rse2) < 0 ) { MESSAGE("Erreur a la lecture des connectivités des segments"); return -1; } else { printf("Valeur de _rse2 : "); for (_j=0;_j<_rnse2*2;_j++) printf("%d ",_rse2[_j]); printf("\n"); } free(_rse2); } } return 0; }
med_int nmsefspw(med_int *fid, char *mname, med_int *mnamelen, char *aname, med_int *anamelen, med_int *atype, med_int *anc, med_int *setype, char *pname, med_int *pnamelen, char *val, med_int *vallen) #endif { med_int _ret; char *_fn1, *_fn2,*_fn3, *_fn4; med_attribute_type _atype = (med_attribute_type) *atype; med_entity_type _setype = (med_entity_type) *setype; int _nentity=0; med_geometry_type _geotype=0; med_int _modeldim=0; char _supportmeshname[MED_NAME_SIZE+1]=""; med_entity_type _entitytype=0; med_int _nnode=0; med_int _ncell=0; med_geometry_type _sgeotype=0; med_int _nconstatt=0; med_bool _anyprofile=0; med_int _nvaratt=0; med_bool _coordinatechangement=MED_FALSE; med_bool _geotransformation=MED_FALSE; _fn1 = _MED2cstring((char *) mname, (int) *mnamelen); if (!_fn1) return(-1); _fn2 = _MED2cstring((char *) aname, (int) *anamelen); if (!_fn2) return(-1); _fn3 = _MED2cstring((char *) pname, (int) *pnamelen); if (!_fn3) return(-1); /* on recupere le nom du maillage support */ _ret = MEDstructElementInfoByName((med_idt) *fid, _fn1, &_geotype, &_modeldim, _supportmeshname, &_entitytype, &_nnode, &_ncell, &_sgeotype, &_nconstatt, &_anyprofile, &_nvaratt); if (_ret < 0) return (-1); /* on recupere le nombre d'entite dans le maillage support : MED_NODE ou MED_CELL */ if (_setype == MED_NODE) _nentity = MEDmeshnEntity((med_idt) *fid, _supportmeshname, MED_NO_DT, MED_NO_IT, _setype, _sgeotype, MED_COORDINATE, MED_NO_CMODE, &_coordinatechangement, &_geotransformation); else _nentity = MEDmeshnEntity((med_idt) *fid, _supportmeshname, MED_NO_DT, MED_NO_IT, _setype, _sgeotype, MED_CONNECTIVITY, MED_NODAL, &_coordinatechangement, &_geotransformation); if (_nentity < 0) return (-1); _fn4 = _MED1cstring((char *) val, (int) *vallen*_nentity, (int) *anc*_nentity*MED_NAME_SIZE); if (!_fn4) return(-1); _ret = (med_int) MEDstructElementConstAttWithProfileWr((const med_idt) *fid, _fn1, _fn2, _atype, (med_int) *anc, _setype, _fn3, (void *) _fn4); _MEDcstringFree(_fn1); _MEDcstringFree(_fn2); _MEDcstringFree(_fn3); _MEDcstringFree(_fn4); return _ret; }
med_err MEDstructElementInfoByName(const med_idt fid, const char * const modelname, med_geometry_type * const mgeotype, med_int* const modeldim, char* const supportmeshname, med_entity_type* const sentitytype, med_int* const snnode, med_int* const sncell, med_geometry_type* const sgeotype, med_int* const nconstantattribute, med_bool* const anyprofile, med_int* const nvariableattribute ) { med_err _ret=-1; med_idt _elemid=0, _cstid=0; char _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1]=MED_STRCT; char __profilename [MED_NAME_SIZE+1]=MED_NO_PROFILE_INTERNAL; const char* _profilename = __profilename; med_int _intentitytype = MED_UNDEF_ENTITY_TYPE; med_int _nentity = 0; med_size _tmpn = 0; med_bool _chgt=MED_FALSE,_trsf=MED_FALSE; med_int _medintmgeotype = MED_NONE; med_int _medintsgeotype = MED_NONE; med_int _intanyprofile = 0; strcat(_path,modelname); /* * Si le DataGroup /STRUCT/<modelname> n'existe pas => erreur */ if ((_elemid = _MEDdatagroupOpen(fid,_path)) < 0) { MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path); goto ERROR; } /* * Lecture de l'attribut MED_NOM_NEO (numéro de type géométrique associé à un élément de structure) */ if ( _MEDattrEntierLire(_elemid,MED_NOM_NEO,&_medintmgeotype) < 0 ) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintmgeotype); goto ERROR; } *mgeotype=_medintmgeotype; /* * Lecture de l'attribut MED_NOM_DIM (dimension de l'élément) */ if ( _MEDattrEntierLire(_elemid,MED_NOM_DIM,modeldim) < 0 ) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_DIM);ISCRUTE(*modeldim); goto ERROR; } /* * Lecture de l'attribut MED_NOM_NOM (nom du maillage support) */ /* Chercher plutôt ds le maillage support et supprimer les attributs NBM et NBN */ if ( _MEDattrStringLire(_elemid,MED_NOM_NOM,MED_NAME_SIZE,supportmeshname) < 0) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_NOM);SSCRUTE(supportmeshname); goto ERROR; } /* * Lecture de l'attribut MED_NOM_ENT (type d'entité support) */ if ( _MEDattrEntierLire(_elemid,MED_NOM_ENT,&_intentitytype) < 0 ) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_ENT);ISCRUTE(_intentitytype); goto ERROR; } *sentitytype = (med_entity_type) _intentitytype; /* * Lecture de l'attribut MED_NOM_GEO (type géométrique des mailles support) */ if ( _MEDattrEntierLire(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype); goto ERROR; } *sgeotype=_medintsgeotype; /* * Lecture du nombre de noeuds support */ if (strlen(supportmeshname)) { if ( (*snnode = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE, &_chgt,&_trsf) ) <= 0) { MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity"); ISCRUTE(*snnode);goto ERROR; } } else { *snnode=1; } /* * Lecture du nombre de mailles support */ if (strlen(supportmeshname)) { if ( (*sncell = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT, MED_CELL,*sgeotype,MED_CONNECTIVITY,MED_NODAL, &_chgt,&_trsf) ) < 0) { MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity"); ISCRUTE(*sncell);goto ERROR; } } else { *sncell=0; } _MEDnObjects(_elemid,MED_CSTATR_NOM,&_tmpn); if ( _tmpn > 0) { if ((_cstid = _MEDdatagroupOpen(_elemid,MED_CSTATR_NOM)) < 0) { MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_CSTATR_NOM); SSCRUTE(_path);goto ERROR; } if ( _MEDattrEntierLire(_cstid,MED_NOM_PFU,&_intanyprofile) < 0) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_STRUCT_MSG); SSCRUTE(modelname);SSCRUTE(MED_NOM_PFU); goto ERROR; } *anyprofile=_intanyprofile; *nconstantattribute = (med_int) _tmpn; } else { *anyprofile = MED_FALSE; *nconstantattribute = 0; } _MEDnObjects(_elemid,MED_VARATR_NOM,&_tmpn); if ( _tmpn > 0) *nvariableattribute = (med_int) _tmpn; else *nvariableattribute = (med_int) 0; _ret=0; ERROR: if (_cstid>0) if (_MEDdatagroupFermer(_cstid) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_CSTATR_NOM); ISCRUTE_id(_cstid); } if (_elemid>0) if (_MEDdatagroupFermer(_elemid) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,modelname); ISCRUTE_id(_elemid); } return _ret; }
med_geometry_type MEDstructElementCr(const med_idt fid, const char* const modelname, const med_int modeldim, const char* const supportmeshname, const med_entity_type sentitytype, const med_geometry_type sgeotype ) { med_access_mode _MED_ACCESS_MODE; med_err _err=-1; med_idt _root=0,_elemid=0; med_int _ret=-1; char _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1]=MED_STRCT; med_size _tmpn=0; med_geometry_type _stgeotype=0; med_int _medintstgeotype = 0; med_int _medintsgeotype = sgeotype; med_int _intentitytype = sentitytype; med_int _nnode=0,_ncell=0; med_bool _chgt=MED_FALSE,_trsf=MED_FALSE; /* char _entitytypename[MED_TAILLE_NOM_ENTITE+1]=""; */ /* * On inhibe le gestionnaire d'erreur */ _MEDmodeErreurVerrouiller(); if (_MEDcheckVersion30(fid) < 0) goto ERROR; if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) { MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG); goto ERROR; } if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) { MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG); ISCRUTE_int(_MED_ACCESS_MODE); goto ERROR; } /* * Si le DataGroup /STRUCT/ n'existe pas, on le cree */ if ((_root = _MEDdatagroupOpen(fid,_path)) < 0) if ((_root = _MEDdatagroupCrOrderCr(fid,_path)) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path); goto ERROR; } NOFINALBLANK(modelname,ERROR); /* * Si le DataGroup /STRUCT/<modelname> n'existe pas, on le cree */ if ((_elemid = _MEDdatagroupOpen(_root,modelname)) < 0) { if ((_elemid = _MEDdatagroupCreer(_root,modelname)) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,modelname); SSCRUTE(_path);goto ERROR; } } else { /* * Lecture de l'attribut MED_NOM_NEO (num�ro de type g�om�trique associ� � un �l�ment de structure) */ if ( _MEDattrEntierLire(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype); goto ERROR; } _stgeotype = _medintstgeotype; } strcat(_path,modelname); /* * Creation/Ecriture de l'attribut MED_NOM_DIM (dimension de l'�l�ment) */ if ( _MEDattributeIntWr(_elemid,MED_NOM_DIM,&modeldim) < 0 ) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_DIM);ISCRUTE(modeldim); goto ERROR; } /* * Creation/Ecriture de l'attribut MED_NOM_NOM (nom du maillage support) */ if ( _MEDattributeStringWr(_elemid,MED_NOM_NOM,MED_NAME_SIZE,supportmeshname) < 0) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_NOM);SSCRUTE(supportmeshname); goto ERROR; } /* * Creation/Ecriture de l'attribut MED_NOM_ENT (type d'entit� support) */ /* if (_MEDgetEntityTypeName(_entitytypename,sentitytype) < 0) { */ /* MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG); */ /* ISCRUTE_int(sentitytype);SSCRUTE(_entitytypename);SSCRUTE(_path); */ /* goto ERROR; */ /* } */ if ( _MEDattributeIntWr(_elemid,MED_NOM_ENT,&_intentitytype) < 0 ) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_ENT);ISCRUTE(_intentitytype); goto ERROR; } /* Lecture dans le maillages support du nombre de noeuds S'il n'y a pas de maillage support : 1 */ if (strlen(supportmeshname)) { if ( (_nnode = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE, &_chgt,&_trsf) ) <= 0) { MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity"); ISCRUTE(_nnode);goto ERROR; } } else { _nnode=1; } if (strlen(supportmeshname)) { if ( (_ncell = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT, MED_CELL,sgeotype,MED_CONNECTIVITY,MED_NODAL, &_chgt,&_trsf) ) < 0) { MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity"); ISCRUTE(_ncell);goto ERROR; } } else { _ncell=0; } /* * Creation/Ecriture de l'attribut MED_NOM_GEO (type g�om�trique des mailles support) */ _medintsgeotype = sgeotype; if ( _MEDattributeIntWr(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype); goto ERROR; } /* * Creation/Ecriture de l'attribut MED_NOM_NAV (nombre d'attributs variables associ�s � un �l�ment de structure) */ /* if ( _MEDattributeIntWr(_elemid,MED_NOM_NAV,&nvariableattribute) < 0 ) { */ /* MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */ /* SSCRUTE(MED_NOM_NAV);ISCRUTE(nvariableattribute); */ /* goto ERROR; */ /* } */ /* * Creation/Ecriture de l'attribut MED_NOM_NAC (nombre d'attributs constant associ�s � un �l�ment de structure) */ /* if ( _MEDattributeIntWr(_elemid,MED_NOM_NAC,&nconstattribute) < 0 ) { */ /* MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */ /* SSCRUTE(MED_NOM_NAC);ISCRUTE(nconstattribute); */ /* goto ERROR; */ /* } */ /* * Nombre d'�l�ments de structure */ if ( !_stgeotype ) { /*Si l'�l�ment de struture ne pr�-existait pas, il a �t� cr�e en d�but de proc�dure (il y a au moins 1 �l�ment dans le groupe) */ if ((_err=_MEDnObjects(fid,MED_STRCT,&_tmpn)) <0) { MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_STRUCT,MED_STRCT); goto ERROR; } _stgeotype=_tmpn+MED_STRUCT_GEO_INTERNAL; _medintstgeotype=_stgeotype; /* * Ecriture de l'attribut MED_NOM_NEO (num�ro de type g�om�trique associ� � un �l�ment de structure) */ if ( _MEDattributeIntWr(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype); goto ERROR; } } _ret = _stgeotype; ERROR: if (_elemid>0) if (_MEDdatagroupFermer(_elemid) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path); ISCRUTE_id(_elemid); } if (_root>0) if (_MEDdatagroupFermer(_root) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_STRCT); ISCRUTE_id(_root); } return _ret; }