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; }
EVersion GetVersionId(const std::string& theFileName, bool theDoPreCheckInSeparateProcess) { INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'"<<std::endl); EVersion aVersion = eVUnknown; #ifndef WIN32 if (access(theFileName.c_str(),F_OK)) return aVersion; if(theDoPreCheckInSeparateProcess){ // First check, is it possible to deal with the file std::ostringstream aStr; // File name is in quotes for the case of space(s) inside it (PAL13009) aStr<<"bash -c \""<<getenv("SMESH_ROOT_DIR")<<"/bin/salome/mprint_version \'"<<theFileName<<"\'\""; if(!MYDEBUG) aStr<<" 2>&1 > /dev/null"; std::string aCommand = aStr.str(); int aStatus = system(aCommand.c_str()); BEGMSG(MYDEBUG,"aCommand = '"<<aCommand<<"'; aStatus = "<<aStatus<<std::endl); if(aStatus != 0) return aVersion; } #endif // check compatibility of hdf and med versions med_bool hdfok, medok; MEDfileCompatibility(theFileName.c_str(), &hdfok, &medok); if ((!hdfok) /*|| (!medok)*/) // med-2.1 is KO since med-3.0.0 return aVersion; // Next, try to open the file trough the MED API const char* aFileName = theFileName.c_str(); med_idt aFid = MEDfileOpen(aFileName,MED_ACC_RDONLY); MSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aFid = "<<aFid<<std::endl); if(aFid >= 0){ med_int aMajor, aMinor, aRelease; med_err aRet = MEDfileNumVersionRd(aFid,&aMajor,&aMinor,&aRelease); INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aRet = "<<aRet<<std::endl); if(aRet >= 0){ if(aMajor == 2 && aMinor == 1) aVersion = eV2_1; else aVersion = eV2_2; } else { // VSR: simulate med 2.3.6 behavior, med file version is assumed to 2.1 aVersion = eV2_1; } } MEDfileClose(aFid); BEGMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aVersion = "<<aVersion<<std::endl); return aVersion; }
med_int nmfifclo(med_idt *fid) #endif { med_int _ret; _ret = (med_int) MEDfileClose(*fid); return(_ret); }
int main (int argc, char **argv) { med_err ret = 0; med_idt fid; char des[MED_COMMENT_SIZE+1]="Ceci est une courte description de mon fichier test1.med"; /* Creation du fichier "test1.med" */ fid = MEDfileOpen("test1.med",MODE_ACCES); if (fid < 0) { MESSAGE("Erreur à la creation du fichier"); return -1; } /* Ecriture d'un en-tete dans le fichier */ if (MEDfileCommentWr(fid,des) < 0) { MESSAGE("Erreur à l'ecriture de l'en-tete du fichier"); ret = -1; } /* Fermeture du fichier */ if ((ret = MEDfileClose(fid)) < 0) { MESSAGE("Erreur à la fermeture du fichier"); return -1; } /* Re-ouverture du fichier en lecture seule */ fid = MEDfileOpen("test1.med",MED_ACC_RDONLY); if (fid < 0) { MESSAGE("Erreur à l'ouverture du fichier en mode MED_LECTURE"); return -1; } /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) ret = -1; return ret; }
int main (int argc, char **argv) { med_err _ret=0; med_idt _fid=0; /*Exemple 1 : - Elément de référence de type géométrique MED_TRIA3 - Point X(X1,X2) quelconque dans le plan de l'élément de référence - Fonctions de base : P1(X)=1-X1-X2 ; P2(X)=X1; P3(X)=X2; (issu du choix de la base polynomiale (1,X1,X2) et des trois noeuds de la maille de référence pour construire l'interpolation) */ const char _interpname1[] ="interpname1"; med_geometry_type _geotype1 =MED_TRIA3; med_bool _cellnodes1 =MED_TRUE; /* med_int _nbasisfunc1 =3; */ med_int _nvariable1 =2; med_int _maxdegree1 =1; med_int _nmaxcoefficient1=3; /* Ouverture en mode creation du fichier "current.med" */ _fid = MEDfileOpen("current.med",MODE_ACCES); if (_fid < 0) { MESSAGE("Erreur a la creation du fichier current.med"); return -1; } if ( (_ret = MEDinterpCr(_fid, _interpname1, _geotype1, _cellnodes1, _nvariable1, _maxdegree1, _nmaxcoefficient1 ) <0) ) { MESSAGE("Erreur à la création de la fonction d'interpolation n°1"); } 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=0; char _fieldname1[MED_NAME_SIZE+1] = "champ reel"; char _interpname[MED_NAME_SIZE+1] = ""; med_int _ninterp = 0; int _interpit=0; /* Ouverture en mode creation du fichier "current.med" */ _fid = MEDfileOpen("current.med",MED_ACC_RDONLY); if (_fid < 0) { MESSAGE("Erreur a la creation du fichier current.med"); return -1; } if ( (_ninterp = MEDfieldnInterp(_fid, _fieldname1 ) ) < 0 ) { MESSAGE("Erreur à la lecture du nombre de fonctions d'interpolation sur le champ : "); SSCRUTE(_fieldname1);_ret=_ninterp; goto ERROR; } for (_interpit=0;_interpit < _ninterp; ++_interpit ) { if ( (_ret = MEDfieldInterpInfo(_fid, _fieldname1, _interpit+1, _interpname ) <0) ) { MESSAGE("Erreur à la lecture des informations de la fonction d'interpolation n° :"); ISCRUTE(_interpit);SSCRUTE("sur le champ : ");SSCRUTE(_fieldname1); goto ERROR; } else fprintf(stdout,"Le nom de la fonction d'interpolation n°%d du champ %s est %s\n", _interpit+1,_fieldname1,_interpname); } ERROR: if (MEDfileClose(_fid) < 0) { MESSAGE("ERROR : file closing"); return -1; } return _ret; }
bool getMEDVersion( const std::string& fname, int& major, int& minor, int& release ) { med_idt f = MEDfileOpen(fname.c_str(), MED_ACC_RDONLY ); if( f<0 ) return false; med_int aMajor, aMinor, aRelease; med_err aRet = MEDfileNumVersionRd( f, &aMajor, &aMinor, &aRelease ); major = aMajor; minor = aMinor; release = aRelease; MEDfileClose( f ); if( aRet<0 ) { // VSR: simulate med 2.3.6 behavior, med file version is assumed to 2.1 major = 2; minor = release = -1; //return false; } return true; }
ecs_med_t * ecs_post_med__detruit_cas(ecs_med_t *cas_med) { ecs_int_t ind; ecs_med_maillage_t * maillage_med; /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ if (cas_med != NULL) { /* Destruction du cas */ if (cas_med->fid != 0) { if (MEDfileClose(cas_med->fid) != 0) ecs_error(__FILE__, __LINE__, 0, _("MED: error closing file \"%s\"."), cas_med->nom_fic); } ECS_FREE(cas_med->nom_cas); ECS_FREE(cas_med->nom_fic); for (ind = 0; ind < cas_med->nbr_maillages; ind++) { maillage_med = cas_med->tab_maillages[ind]; ECS_FREE(maillage_med->nom_maillage); ECS_FREE(maillage_med); } ECS_FREE(cas_med->tab_maillages); cas_med->nbr_maillages = 0; ECS_FREE(cas_med); } return cas_med; }
int MEDimport(char * filein, char * fileout) { med_idt fid, gid; med_err ret; med_int majeur, mineur, release; med_bool hdfok=MED_FALSE; med_bool medok=MED_FALSE; char *_fileout,*tmp=NULL; int _fileoutsize; bool hasfileout=false; char *commande; med_int nprofil; char chemin_profils[MED_TAILLE_PROFILS+1]; char chemin_liens[MED_TAILLE_LIENS+1]; char version[9]; int MAJ_21_22 = 0, MAJ_231_232 = 0, MAJ_236_300 = 0, MAJ_300_310 = 0, MAJ_310_320 = 0 ; #ifdef PPRO_NT char *drive, *dir, *ext; #endif unsigned char reponse='o'; med_bool _noversion=MED_FALSE; EXIT_IF(filein == NULL,"Le nom du fichier d'entrée est vide : ", filein); hasfileout = strcmp(fileout,""); if ( hasfileout ) { _fileoutsize = strlen(fileout); _fileout = fileout; } else { _fileoutsize = strlen(filein)+strlen(PACKAGE_VERSION); tmp = (char *) malloc(sizeof(char)*(_fileoutsize+1)); strcpy(tmp,filein); strcat(tmp,PACKAGE_VERSION); #ifdef PPRO_NT _splitpath( tmp, drive, dir, _fileout, ext ); #else _fileout = basename(tmp); #endif _fileoutsize = strlen(_fileout); } /* Test du format du fichier */ ret = MEDfileCompatibility(filein,&hdfok,&medok); if (ret < 0 ) { fprintf(stdout,">>> Attention le fichier %s ne contient pas de numéro de version. \n",filein); fprintf(stdout,">>> Le fichier %s est supposé être en version 2.1.1. \n",filein); /* PAs d'interactif dans une bibliothèque !*/ /* fprintf(stdout,">>> Voulez-vous essayer une conversion d'un fichier < 2.2 (o/n) ? "); */ /* scanf("%c",&reponse); */ if ( (reponse != 'o') && (reponse != 'O') && (reponse != 'y') && (reponse != 'Y') ) { EXIT_IF(MEDfileCompatibility(filein,&hdfok,&medok) < 0, "Erreur d'appel de MEDfileCompatibility : ", filein); } _noversion = MED_TRUE; } EXIT_IF( !hdfok , "Le fichier d'entrée n'est pas dans un format HDF compatible : ", filein); /* EXIT_IF( !medok , */ /* "MEDimport ne gère pas le format MED de ce fichier : ", filein); */ /* Creation et ouverture du fichier que l'on va convertir au format MED actuel */ commande = (char *) malloc(sizeof(char)*(strlen("cp ")+strlen(filein)+ strlen(" ")+_fileoutsize + 4 +1 ) ); EXIT_IF(commande == NULL,NULL,NULL); strcpy(commande,"cp \""); strcat(commande,filein); strcat(commande,"\" \""); strcat(commande,_fileout); strcat(commande,"\""); fprintf(stdout,">>> Creation du fichier %s : %s \n",_fileout,commande); system(commande); free(commande); commande = (char *) malloc(sizeof(char)*(strlen("chmod u+w \"") + _fileoutsize +1 +1 ) ); EXIT_IF(commande == NULL,NULL,NULL); strcpy(commande,"chmod u+w \""); strcat(commande,_fileout); strcat(commande,"\""); fprintf(stdout,">>> Chmod +w du fichier %s : %s \n",_fileout,commande); system(commande); free(commande); fid = MEDfileOpen(_fileout,MED_ACC_RDWR); EXIT_IF(fid < 0,"Ouverture du fichier : ", _fileout); /* Verification du numero de version */ if (! _noversion) ret = MEDfileNumVersionRd(fid,&majeur,&mineur,&release); else { ret=0; majeur=2; mineur=1; release=1; } sprintf(version, IFORMAT"_"IFORMAT"_"IFORMAT, majeur, mineur, release); EXIT_IF(ret < 0,"Lecture du numero de version de MED-fichier",NULL); if (strcmp(version, "2_2_0") < 0) MAJ_21_22 = 1; if (strcmp(version, "2_3_2") < 0) MAJ_231_232 = 1; if (strcmp(version, "3_0_0") < 0) MAJ_236_300 = 1; if (strcmp(version, "3_1_0") < 0) MAJ_300_310 = 1; if (strcmp(version, "3_2_0") < 0) MAJ_310_320 = 1; /* Ne pas oublier que la version cible du fichier à convertir est celui de la bibliothèque. */ if (MAJ_310_320 == 0) { fprintf(stdout,"Le fichier %s est déjà au bon format !!! \n",_fileout); ret = MEDfileClose(fid); EXIT_IF(ret < 0,"Fermeture du fichier",filein); return 0; } /* On avertit qu'on commence la conversion */ fprintf(stdout,">>> Lancement de la normalisation du fichier selon le format " PACKAGE_VERSION " ...\n"); /* On inhibe le gestionnaire d'erreur HDF5 */ _MEDmodeErreurVerrouiller(); /* Mise a jour du numero de version */ fprintf(stdout,"- Lancement de la mise à jour du numéro de version ... \n"); /* La mise à jour MAJ_version(fid); doit être différée pour que les majs des fichiers anciens fonctionnent correctement*/ /* MAJ_version(fid); */ MAJ_write_version_num(fid,2,3,6); fprintf(stdout," Numéro de version : ... OK ... \n"); if (MAJ_21_22) { /* Mise a jour des maillages : type = MED_NON_STRUCTURE, description, ... */ fprintf(stdout,"- Lancement de la mise à jour des maillages (21_22)... \n"); MAJ_21_22_maillages(fid); fprintf(stdout," Maillage(s) : ... OK ...\n"); /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (21_22)... \n"); MAJ_21_22_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); /* Mise a jour des profils eventuels */ nprofil = MEDnProfil(fid); if (nprofil > 0) { fprintf(stdout,"- Lancement de la mise à jour des profils (21_22)... \n"); MAJ_21_22_profils(fid,nprofil); fprintf(stdout," Profils(s) : ... OK ...\n"); } else { strncpy(chemin_profils,MED_PROFILS,MED_TAILLE_PROFILS-1); chemin_profils[MED_TAILLE_PROFILS-1] = '\0'; gid = _MEDdatagroupCreer(fid,chemin_profils); EXIT_IF(gid < 0,"Creation du groupe HDF sur les profils",chemin_profils); ret = _MEDdatagroupFermer(gid); EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les profils",chemin_profils); } /* On cree le groupe HDF pour les liens */ strncpy(chemin_liens,MED_LIENS,MED_TAILLE_LIENS-1); chemin_liens[MED_TAILLE_LIENS-1] = '\0'; gid = _MEDdatagroupCreer(fid,chemin_liens); EXIT_IF(gid < 0,"Creation du groupe HDF sur les liens",chemin_liens); ret = _MEDdatagroupFermer(gid); EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les liens",chemin_liens); } if (MAJ_231_232) { /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (231_232)... \n"); MAJ_231_232_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); fprintf(stdout,"- Lancement de la mise à jour des noms de maillages (231_232)... \n"); MAJ_231_232_maillages(fid); fprintf(stdout," Noms(s) de maillage(s): ... OK ...\n"); } if (MAJ_236_300) { /* Le système de cache de version a été developpé à partir de la 3.0*/ /* Initialise le cache sur une 2.3.6 (cas d'absence d'INFO)*/ _MEDfileVersion(fid); /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (236_300)... \n"); MAJ_236_300_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); /* MAJ_version(fid); */ fprintf(stdout,"- Lancement de la mise à jour des maillages (236_300)... \n"); MAJ_236_300_maillages(fid); fprintf(stdout," Maillage(s): ... OK ...\n"); /* MAJ_version(fid); */ } if (MAJ_300_310) { /* Le système de cache de version a été developpé à partir de la 3.0*/ /* Initialise le cache sur une 3.0.8 (cas d'absence d'INFO)*/ /* s'il n'a pas déjà été instanciée ds les MAJ précédentes */ MAJ_write_version_num(fid,3,0,8); _MEDfileVersion(fid); /* Si le cache était dèjà instancié, met à jour le cache */ MAJ_version_num(fid,3,0,8); /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (300_310) ... \n"); MAJ_300_310_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); } if (MAJ_310_320) { /* Le système de cache de version a été developpé à partir de la 3.0*/ /* Initialise le cache sur une 3.0.8 (cas d'absence d'INFO)*/ /* s'il n'a pas été déjà été instanciée ds les MAJ_ précédentes */ MAJ_write_version_num(fid,3,1,0); _MEDfileVersion(fid); /* Si le cache était dèjà instancié, met à jour le cache */ MAJ_version_num(fid,3,1,0); /* Mise a jour des familles/groupes */ fprintf(stdout,"- Lancement de la mise à jour des familles/groupes (310_320) ... \n"); MAJ_310_320_familles(fid); fprintf(stdout," Famille(s)/Groupe(s) : ... OK ...\n"); } /* A l'écriture d'une nouvelle version de MAJ ex 310_320, il est necessaire de revisiter les appels à MAJ_version(fid) pour les remplacer par les appels MAJ_version(fid,3,1,Lastest31z) */ MAJ_version(fid); MAJ_write_version_num(fid,MED_NUM_MAJEUR,MED_NUM_MINEUR,MED_NUM_RELEASE); /* Fermeture du fichier */ ret = MEDfileClose(fid); EXIT_IF(ret < 0,"Fermeture du fichier",_fileout); /* On avertit que c'est fini */ fprintf(stdout,">>> Conversion du fichier %s au format MED V" PACKAGE_VERSION " terminée\n", _fileout); /* On libere la memoire */ if (!hasfileout) free(tmp); return 0; }
int main (int argc, char **argv) { med_idt fid; const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD"; const med_int ncomponent = 1; const char componentname[MED_SNAME_SIZE+1] = "TEMPERATURE"; const char componentunit[MED_SNAME_SIZE+1] = "C"; const med_int nquad4 = 4; const med_float quad4values_step1[4*4] = { 10000., 20000., 30000., 40000., 50000., 60000., 70000., 80000., 90000., 100000., 110000., 120000., 130000., 140000., 150000., 160000. }; const med_float quad4values_step2[4*4] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000., 1100., 1200., 1300., 1400., 1500., 1600. }; int ret=-1; /* file creation */ fid = MEDfileOpen("UsesCase_MEDfield_13.med",MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); goto ERROR; } /* create mesh link */ if (MEDlinkWr(fid,meshname,"./UsesCase_MEDmesh_1.med") < 0) { MESSAGE("ERROR : create mesh link ..."); goto ERROR; } /* * Temperature field creation : * - 1 component * - component unit : celsius degree * - mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c use case. * - computation step unit in 'ms' */ if (MEDfieldCr(fid, fieldname, MED_FLOAT64, ncomponent, componentname, componentunit, "ms", meshname) < 0) { MESSAGE("ERROR : create field"); goto ERROR; } /* two computation steps */ /* write values at nodes elements : 4 MED_QUAD4 */ /* STEP 1 : dt1 = 5.5, it = 1*/ /* MED_QUAD4 : with no profile */ if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_NODE_ELEMENT, MED_QUAD4, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nquad4, (unsigned char*) quad4values_step1) < 0) { MESSAGE("ERROR : write field values on MED_QUAD4 "); goto ERROR; } /* STEP 2 : dt2 = 8.9, it = 1*/ /* MED_QUAD4 : with no profile */ if (MEDfieldValueWithProfileWr(fid, fieldname, 2, 1, 8.9, MED_NODE_ELEMENT, MED_QUAD4, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nquad4, (unsigned char*) quad4values_step2) < 0) { MESSAGE("ERROR : write field values on MED_QUAD4 ... "); goto ERROR; } ret=0; ERROR: /* close file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); ret=-1; } return ret; }
int main (int argc, char **argv) { med_err _ret=-1; med_idt _fid=0; char _meshname1[MED_NAME_SIZE+1] = "meshname1"; char _axisname[3*MED_SNAME_SIZE+1] = "x y z "; char _unitname[3*MED_SNAME_SIZE+1] = "cm cm cm "; char _fieldname1[MED_NAME_SIZE+1] = "champ reel"; char _componentname1[2*MED_SNAME_SIZE+1] = "comp1 comp2 "; /*12345678901234561234567890123456*/ char _unitname1[2*MED_SNAME_SIZE+1] = "unit1 unit2 "; char _dtunit[MED_SNAME_SIZE+1] = "s"; med_int _ncomponentname1 = 2; /*Exemple 1 : - Elément de référence de type géométrique MED_TRIA3 - Point X(X1,X2) quelconque dans le plan de l'élément de référence - Fonctions de base : P1(X)=1-X1-X2 ; P2(X)=X1; P3(X)=X2; (issu du choix de la base polynomiale (1,X1,X2) et des trois noeuds de la maille de référence pour construire l'interpolation) */ const char _interpname1[] ="interpname1"; med_geometry_type _geotype1 =MED_TRIA3; /* Ouverture en mode creation du fichier "current.med" */ _fid = MEDfileOpen("current.med",MODE_ACCES); if (_fid < 0) { MESSAGE("Erreur a la creation du fichier current.med"); return -1; } /* Creation de _meshname1 de dimension 2 dans un espace de dimension 3*/ if (MEDmeshCr( _fid, _meshname1, 3, 2, MED_UNSTRUCTURED_MESH, "Maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, _axisname, _unitname) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(_meshname1); goto ERROR; } /* Creation du champ réel n°1 */ if ( MEDfieldCr(_fid,_fieldname1,MED_FLOAT64, _ncomponentname1,_componentname1,_unitname1,_dtunit,_meshname1 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(_fieldname1); goto ERROR; }; if ( (_ret = MEDfieldInterpWr(_fid, _fieldname1, _interpname1) <0) ) { MESSAGE("Erreur à l'écriture de la fonction d'interpolation n°1 sur le champ : ");SSCRUTE(_fieldname1); } 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=0; med_geometry_type _geotype=MED_NONE; const char _elementname1[]="MED_BILLE"; med_int _elementdim1=3; const char _supportmeshname1[]="MED_BILLE_SUPPORT"; med_entity_type _entitytype1=MED_NODE; med_int _nnode1=1; med_int _ncell1=0; med_int _geocelltype1=MED_NONE; const char _constattname1_1[MED_NAME_SIZE+1]="MED_FOO_ATR1_1"; const med_attribute_type _constatttype1_1=MED_ATT_INT; const med_int _ncomponent1_1=2; const char _profilename1_1[MED_NAME_SIZE+1]=MED_NO_PROFILE; const med_int _cstatrvalue1_1[2]={ 20 , 21 }; const char _constattname1_2[MED_NAME_SIZE+1]="MED_FOO_ATR1_2"; const med_attribute_type _constatttype1_2=MED_ATT_FLOAT64; const med_int _ncomponent1_2=2; const char _profilename1_2[MED_NAME_SIZE+1]=MED_NO_PROFILE; const med_float _cstatrvalue1_2[2]={ 20.1 , 21.2 }; const char _constattname1_3[MED_NAME_SIZE+1]="MED_FOO_ATR1_3"; const med_attribute_type _constatttype1_3=MED_ATT_NAME; const med_int _ncomponent1_3=2; const char _profilename1_3[MED_NAME_SIZE+1]=MED_NO_PROFILE; /*0123456789012345678901234567890123456789012345678901234567890123*/ const char _cstatrvalue1_3[2*MED_NAME_SIZE+1]={ "MED_FOO_ATR1_3_________________________________________________1" \ "MED_FOO_ATR1_3_________________________________________________2" }; /*TODO : Tester avec un profil sur un maillage support*/ /* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */ _fid = MEDfileOpen("current.med",MODE_ACCES); if (_fid < 0) { MESSAGE("Erreur à la lecture du fichier current.med"); return -1; } if ( (_ret = MEDstructElementConstAttWr(_fid, _elementname1, _constattname1_1, _constatttype1_1, _ncomponent1_1, _entitytype1, _cstatrvalue1_1 )) < 0 ) { return _ret; } if ( (_ret = MEDstructElementConstAttWr(_fid, _elementname1, _constattname1_2, _constatttype1_2, _ncomponent1_2, _entitytype1, _cstatrvalue1_2 )) < 0 ) { return _ret; } if ( (_ret = MEDstructElementConstAttWr(_fid, _elementname1, _constattname1_3, _constatttype1_3, _ncomponent1_3, _entitytype1, _cstatrvalue1_3 )) < 0 ) { return _ret; } if (MEDfileClose(_fid) < 0) { MESSAGE("ERROR : file closing"); return -1; } return _ret; }
int main (int argc, char **argv) { med_idt fid=0; med_int majeur=0, mineur=0, release=0; med_bool hdfok=MED_FALSE,medok=MED_FALSE; char medversion[MED_SNAME_SIZE+1]=""; /* Creation du fichier test18.med */ if ((fid = MEDfileOpen("test18.med",MODE_ACCES)) < 0) { MESSAGE("Erreur a la creation du fichier test18.med"); return -1; } fprintf(stdout,"- Creation du fichier test18.med \n"); if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } fprintf(stdout,"- Fermeture du fichier \n"); /* * Quelle version de la bibliotheque MED est utilisee ? */ MEDlibraryNumVersion(&majeur, &mineur, &release); fprintf(stdout,"- Version de MED utilisee pour lire le fichier : "IFORMAT"."IFORMAT"."IFORMAT" \n",majeur,mineur,release); /* * Le fichier à lire est-il au bon format de fichier HDF ? */ if (MEDfileCompatibility("test18.med",&hdfok,&medok)<0 ) { MESSAGE("Erreur à la vérification de la compatibilité du fichier avec les bibliothèques med et hdf."); return -1; } if ( hdfok ) fprintf(stdout,"- Format HDF du fichier MED conforme au format HDF utilise par la bibliotheque \n"); else fprintf(stdout,"- Format HDF du fichier MED non conforme au format HDF utilise par la bibliotheque \n"); /* * Le fichier a lire a-t-il été créé avec une version de la bibliothèque MED conforme avec celle utilise ? * (Numéros majeur et mineur identiques). */ if ( medok) fprintf(stdout,"- Version MED du fichier conforme a la bibliotheque MED utilisee \n"); else fprintf(stdout,"- Version MED du fichier non conforme a la bibliotheque MED utilisee \n"); if ((fid = MEDfileOpen("test18.med",MED_ACC_RDONLY)) < 0) { MESSAGE("Erreur a l'ouverture du fichier test18.med"); return -1; } fprintf(stdout,"- Ouverture du fichier en lecture \n"); /* * Une fois le fichier ouvert on peut avoir acces au numero de version complet */ if (MEDfileNumVersionRd(fid, &majeur, &mineur, &release) < 0) { MESSAGE("Erreur a la lecture du numero de version de la bibliothèque "); return -1; } fprintf(stdout,"- Ce fichier a ete cree avec MED "IFORMAT"."IFORMAT"."IFORMAT" \n",majeur,mineur,release); if ( MEDfileStrVersionRd(fid, medversion) < 0 ) { MESSAGE("Erreur à la lecture de la version du fichier MED"); return -1; } fprintf(stdout,"- Ce fichier a ete cree avec %s\n",medversion); if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } fprintf(stdout,"- Fermeture du fichier \n"); return 0; }
med_err generateFieldFile( const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue, const med_switch_mode constituentmode,GetBlocksOfEntitiesType getBlockOfEntities, const med_int nbblocksperproc, GenerateDataType generateDatas, const med_storage_mode storagemode, const med_size profilearraysize, const char * const fieldnameprefix, COM_info * const cominfo ) { /* static int _fileno=0; */ med_err _ret=-1; char _filename [255]=""; char _meshname[MED_NAME_SIZE+1]="Empty mesh"; med_int _meshdim=3; char _meshcomponentname[3*MED_SNAME_SIZE+1] = "x y z "; char _meshcomponentunit[3*MED_SNAME_SIZE+1] = "cm cm cm "; char _fieldname [MED_NAME_SIZE+1]=""; char *componentname,*componentunit; char _profilename[MED_NAME_SIZE+1]=MED_NO_PROFILE; med_int *_profilearray=0; int _i=0,_j=0,_k=0, _lastusedrank=0; med_size _blocksize=0,_lastblocksize=0,_count=0,_stride=0,_start=0,_index=0; med_float *_arrayvalues; med_filter filter = MED_FILTER_INIT; med_size _nusedentities = nentities; med_size _io_count = nbblocksperproc; med_idt _fidseq,_fid; MPI_Info info = cominfo->info; MPI_Comm comm = cominfo->comm; int mpi_size = cominfo->mpi_size; int mpi_rank = cominfo->mpi_rank; char *_MED_MODE_SWITCH_MSG[3]={"MED_FULL_INTERLACE", "MED_NO_INTERLACE","MED_UNDEF_INTERLACE",}; char *_MED_STORAGE_MODE_MSG[3]={"MED_NO_STMODE","MED_GLOBAL_STMODE", "MED_COMPACT_STMODE"}; med_geometry_type _geotype = MED_TRIA6; med_int _geodim = _geotype/100; med_int _geonnodes = _geotype%100; char _ipointname[MED_NAME_SIZE+1]; med_float* _ipointrefcoo = 0; med_int _ipoint = nvaluesperentity; med_float* _ipointcoo = 0; med_float* _ipointwg = 0; sprintf(_filename,"%s_CPU-%03d_@_%s_%s.med",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]); /* SSCRUTE(_filename); */ /* Ouverture du fichier en mode parallel */ if ((_fid = MEDparFileOpen(_filename, MODE_ACCES ,comm, info)) < 0){ MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename); goto ERROR; } /* SSCRUTE(_meshname); */ if (MEDmeshCr( _fid,_meshname,_meshdim,_meshdim, MED_UNSTRUCTURED_MESH, "Un maillage pour le test parallel","s", MED_SORT_DTIT, MED_CARTESIAN, _meshcomponentname, _meshcomponentunit) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_MESH,_meshname); goto ERROR; }; componentname = (char*) malloc((nconstituentpervalue*MED_SNAME_SIZE+1)*sizeof(char)); componentunit = (char*) malloc((nconstituentpervalue*MED_SNAME_SIZE+1)*sizeof(char)); /*TODO : Compléter le nom */ strcpy(componentname,""); strcpy(componentunit,""); strcpy(_fieldname,fieldnameprefix); if ( MEDfieldCr(_fid,_fieldname,MED_FLOAT64,nconstituentpervalue,componentname,componentunit,"s",_meshname ) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FIELD,_fieldname); goto ERROR; }; free(componentname); free(componentunit); if ( _ipoint > 1 ) { MESSAGE("Creating a localization of integration points..."); strcpy(_ipointname,_fieldname); strcat(_ipointname,"_loc"); /*Attention ancienne spec*/ _ipointrefcoo = (med_float *) calloc(_geodim*_geonnodes,sizeof(med_float)); _ipointcoo = (med_float *) calloc(_ipoint*_geodim,sizeof(med_float)); _ipointwg = (med_float *) calloc(_ipoint,sizeof(med_float)); if (MEDlocalizationWr(_fid, _ipointname, _geotype, _geotype/100, _ipointrefcoo, constituentmode, _ipoint, _ipointcoo, _ipointwg, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT ) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LOCALIZATION,_ipointname); ISCRUTE_int(constituentmode); goto ERROR; } free(_ipointrefcoo ); free(_ipointcoo ); free(_ipointwg ); } else { strcpy(_ipointname,MED_NO_LOCALIZATION); } if (profilearraysize) { MESSAGE("Creating a profile..."); strcpy(_profilename,_fieldname);strcat(_profilename,"_profile"); _profilearray = (med_int*) calloc(profilearraysize,sizeof(med_int)); for (_i=0; _i < profilearraysize; ++_i) _profilearray[_i]=_i; if ( MEDprofileWr(_fid,_profilename,profilearraysize,_profilearray) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_PROFILE,_profilename); goto ERROR; }; _nusedentities = profilearraysize; } else { strcpy(_profilename,MED_NO_PROFILE); } MESSAGE("Generating partition..."); getBlockOfEntities ( mpi_rank , mpi_size, _nusedentities, &_start, &_stride, &_io_count, &_blocksize, &_lastusedrank, &_lastblocksize); _count=_io_count; MESSAGE("Generating filter..."); if ( MEDfilterBlockOfEntityCr(_fid, nentities, nvaluesperentity, nconstituentpervalue, MED_ALL_CONSTITUENT, constituentmode, storagemode, _profilename, _start,_stride,_count,_blocksize,_lastblocksize, &filter) < 0 ) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,""); goto ERROR; } MESSAGE("Generating datas..."); generateDatas(mpi_rank, _lastusedrank, sizeof(med_float), storagemode, profilearraysize, _profilearray, _start, _stride, _count, _blocksize, _lastblocksize, nentities, nvaluesperentity, nconstituentpervalue, &_arrayvalues ); MESSAGE("Writing field..."); if ( MEDfieldValueAdvancedWr(_fid,_fieldname,MED_NO_DT,MED_NO_IT,0.0, MED_CELL, _geotype, _ipointname, &filter, (unsigned char*)_arrayvalues ) < 0) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_FIELD,_fieldname); ISCRUTE(mpi_rank); goto ERROR; } /* Test de lecture du même fichier avec filtre simple par un seul processeur */ /* TODO : Créer MEDflush */ H5Fflush(_fid, H5F_SCOPE_GLOBAL ); /*Le flush suffit pas besoin de synchroniser les processus : MPI_Barrier(MPI_COMM_WORLD); */ if (mpi_rank == 0 ) { MESSAGE("Reading field..."); med_int _nentitiesarrayvalues=0; med_float *_filteredarrayvalues=NULL; med_filter filter2=MED_FILTER_INIT; int _ind=0; FILE * _asciifile; char _asciifilename[255]=""; if ((_fidseq = MEDfileOpen(_filename, MED_ACC_RDONLY )) < 0){ MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename); goto ERROR; } sprintf(_asciifilename,"%s_CPU-%03d_@_%s_%s.ascii",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]); _asciifile=fopen(_asciifilename, "w"); /*Génère un filtre de selection simple s'il n'a pas déjà été généré lors d'un précédent appel */ /*TODO : Déplacer cette appel dans le main après avoir externaliser la génération du profile */ if (!(cominfo->filterarray)) if ( generateFilterArray( nentities, nvaluesperentity, nconstituentpervalue, profilearraysize, _profilearray, &(cominfo->nentitiesfiltered), &(cominfo->filterarray) ) < 0 ) { goto ERROR; } ISCRUTE(cominfo->nentitiesfiltered); /*Stocke le filtre utilisé dans le fichier .ascii*/ for (_i=0; _i < cominfo->nentitiesfiltered; ++_i ) { /* ISCRUTE(cominfo->filterarray[_i]); */ fprintf(_asciifile,"%d ",cominfo->filterarray[_i]) ; } fprintf(_asciifile,"\n") ; /*Pas de profile possible (profilearraysize == 0) en MED_GLOBAL_STMODE sur un fichier géré en parallel */ if ( profilearraysize ) { _nentitiesarrayvalues = profilearraysize; } else { _nentitiesarrayvalues = nentities; } /*Attention allocation mémoire potentiellement grosse car réalisée uniquement par le processus 0 qui rassemble les données.*/ /* C'est une taille maxi qui ne prend pas en compte le COMPACT+filter */ /* TODO : Ajuster la taille au storage_mode*/ _filteredarrayvalues = (med_float*) malloc(_nentitiesarrayvalues* nvaluesperentity* nconstituentpervalue*sizeof(med_float)); /* Permet de vérifier une erreur d'indiçage après la lecture */ for (_i=0;_i<_nentitiesarrayvalues*nvaluesperentity*nconstituentpervalue; ++_i) _filteredarrayvalues[_i]=-_i; /*Création d'un filtre de sélection simple, pour une lecture séquentielle par le processys 0*/ if ( MEDfilterEntityCr(_fidseq, nentities, nvaluesperentity, nconstituentpervalue, MED_ALL_CONSTITUENT, constituentmode, storagemode, _profilename, cominfo->nentitiesfiltered,cominfo->filterarray, &filter2) < 0 ) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,""); goto ERROR; } if ( MEDfieldValueAdvancedRd(_fidseq,_fieldname,MED_NO_DT,MED_NO_IT, MED_CELL, _geotype, &filter2, (unsigned char*)_filteredarrayvalues ) < 0) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_FIELD,_fieldname); ISCRUTE(mpi_rank); goto ERROR; } /*AFFICHAGE TOUJOURS EN FULL INTERLACE QUELQUES SOIENT LES COMBINAISONS*/ /*TODO : Externaliser l'affichage*/ if ( storagemode == MED_GLOBAL_STMODE ) { switch (constituentmode) { case MED_FULL_INTERLACE: for (_i=0; _i < cominfo->nentitiesfiltered; ++_i) for (_j=0; _j < nvaluesperentity; ++_j) for (_k=0; _k < nconstituentpervalue; ++_k) { _ind = (cominfo->filterarray[_i]-1)*nvaluesperentity*nconstituentpervalue+ _j*nconstituentpervalue+_k; /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesFULLGLB[",_ind,"]",_filteredarrayvalues[_ind]) ; */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ; } break; case MED_NO_INTERLACE: for (_j=0; _j < cominfo->nentitiesfiltered; ++_j) for (_k=0; _k < nvaluesperentity; ++_k) for (_i=0; _i < nconstituentpervalue; ++_i) { _ind =_i*nentities*nvaluesperentity+ (cominfo->filterarray[_j]-1)*nvaluesperentity +_k; /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesNOGLB[",_ind,"]",_filteredarrayvalues[_ind]); */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]); } break; } } else switch (constituentmode) { case MED_FULL_INTERLACE: for (_i=0; _i < cominfo->nentitiesfiltered; ++_i ) for (_j=0; _j < nvaluesperentity; ++_j) for (_k=0; _k < nconstituentpervalue; ++_k) { _ind = _i*nvaluesperentity*nconstituentpervalue+_j*nconstituentpervalue+_k; /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesFULLCP[",_ind,"]",_filteredarrayvalues[_ind]) ; */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ; } break; case MED_NO_INTERLACE: for (_j=0; _j < cominfo->nentitiesfiltered; ++_j) for (_k=0; _k < nvaluesperentity; ++_k) for (_i=0; _i < nconstituentpervalue; ++_i) { _ind =_i*cominfo->nentitiesfiltered*nvaluesperentity+ _j*nvaluesperentity +_k; /* _ind =_i*_nentitiesarrayvalues*nvaluesperentity+ (_filterarray[_j]-1)*nvaluesperentity +_k; */ /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesNOCP[",_ind,"]",_filteredarrayvalues[_ind]); */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]); } break; } free(_filteredarrayvalues); fclose(_asciifile); if ( MEDfilterClose(&filter2) < 0 ) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,""); goto ERROR; } } /*fin if (mpi_rank == 0) */ if ( MEDfilterClose(&filter) < 0 ) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,""); goto ERROR; } _ret=0; ERROR: if (_arrayvalues) free(_arrayvalues); if (profilearraysize) free(_profilearray); if ( MEDfileClose(_fid) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1; } if (mpi_rank == 0 ) { if ( MEDfileClose(_fidseq) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1; } } return _ret; }
int main (int argc, char **argv) { med_err ret = 0; med_idt fid; /* la dimension du maillage */ med_int mdim = 2; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1] = "maa1"; /* le nombre de noeuds */ med_int nnoe = 4; /* table des coordonnees (dimension * nombre de noeuds) */ med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0}; /* tables des noms et des unites des coordonnees (dimension*MED_SNAME_SIZE+1) */ /* 12345678901234561234567890123456*/ char nomcoo[2*MED_SNAME_SIZE+1] = "x y "; char unicoo[2*MED_SNAME_SIZE+1] = "cm cm "; /* tables des noms, numeros, numeros de familles des noeuds autant d'elements que de noeuds - les noms ont pout longueur MED_SNAME_SIZE */ /* 1234567890123456123456789012345612345678901234561234567890123456*/ char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 "; med_int numnoe[4] = {1,2,3,4}; med_int nufano[4] = {0,1,2,2}; const med_float phi1=0; const med_float phi2=M_PI_4; const med_float phi3=M_PI_2; med_float trsf1[7]= {0,0,0, cos(phi1/2), 0, sin(phi1/2), 0 }; med_float trsf2[7]= {0,0,0, cos(phi2/2), 0, sin(phi2/2), 0 }; med_float trsf3[7]= {0,0,0, cos(phi3/2), 0, sin(phi3/2), 0 }; /* ouverture du fichier */ if ((fid = MEDfileOpen("Test_MEDmeshNodeCoordinateTrsfWr.med",MODE_ACCES)) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } /* Creation du maillage "maa" de type MED_NON_STRUCURE et de dimension 2 */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour Test_MEDmeshNodeCoordinateTrsfWr","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE,nnoe, coo) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) { MESSAGE("Erreur a l'ecriture des noms des noeuds"); ret = -1; } /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) { MESSAGE("Erreur a l'ecriture des numeros des noeuds"); ret = -1; } /* Ecriture des numeros de famille des noeuds */ if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) { MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds"); ret = -1; } /* Transformation des coordonnees des noeuds coo_1 : */ fprintf(stdout,"Un message d'erreur est attendu: \n"); if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,MED_NO_DT,MED_NO_IT,0.4,trsf1) >= 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); MESSAGE("Aucune transformation géométrique à la séquence de calcul MED_NO_DT,MED_NO_IT n'est possible."); } fprintf(stdout,"Fin du message d'erreur attendu\n :"); /* Transformation des coordonnees des noeuds coo_1 : */ if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,1,1,0.4,trsf1) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ fprintf(stdout,"Un message d'erreur est attendu : \n"); if (MEDmeshNodeCoordinateWr(fid,maa,1,1, 0.5, MED_FULL_INTERLACE,nnoe, coo_2) >= 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); MESSAGE("Aucune ecriture des coordonnees des noeuds n'est possible sur une séquence de calcul comportant "\ "une transformation géométrique."); } fprintf(stdout,"Fin du message d'erreur attendu :\n"); /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,2,1, 0.5, MED_FULL_INTERLACE,nnoe, coo_2) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Transformation des coordonnees des noeuds coo_2 : */ fprintf(stdout,"Un message d'erreur est attendu\n :"); if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,2,1,0.5,trsf2) >= 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°2"); MESSAGE("Aucune transformation géométrique à une séquence de calcul comportant de nouvelles coordonnées n'est possible."); } fprintf(stdout,"Fin du message d'erreur attendu\n :"); /* Transformation des coordonnees des noeuds coo_2 : */ if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,2,2,0.6,trsf2) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°2"); ret = -1; } /* Transformation des coordonnees des noeuds coo_3 : */ if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,3,2,0.7,trsf3) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°3"); ret = -1; } if ( MEDmeshComputationStepCr(fid,maa, 3,2, 3,3, 3.3) < 0) { MESSAGE("Erreur a la creation d'un pas de temps du maillage maa"); } /* Modification des numeros des noeuds (optionnel dans un maillage MED) */ numnoe[2]=200; if (MEDmeshEntityNumberWr(fid,maa,3,3,MED_NODE,MED_NONE,nnoe,numnoe) < 0) { MESSAGE("Erreur a l'ecriture des numeros des noeuds"); ret = -1; } if ( MEDmeshComputationStepCr(fid,maa, 3,3, 3,4, 3.4) < 0) { MESSAGE("Erreur a la creation d'un pas de temps du maillage maa"); } /*TODO : Ecrire un test de comparaison interne next prev et ordre de découverte itératif */ /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier test4.med"); return -1; } return ret; }
int main (int argc, char **argv) /*TODO : Tester l'écriture des attributs famille,numéros optionnels, noms optionnels*/ { med_idt fid=0; med_int mdim=2,axe=0,nind=0; med_float indiceX[4] = {1.0,1.1,1.2,1.3}; med_float indiceY[4] = {2.0,2.1,2.2,2.3}; med_float coo[8] = {0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0}; med_int nnoeuds = 4; med_int structure_grille[2] = {2,2}; char maa [MED_NAME_SIZE+1]= "grille_cartesian"; char maa2[MED_NAME_SIZE+1]= "grille_curvilinear"; /* composantes et unites */ /* 12345678901234561234567890123456 */ char comp[2*MED_SNAME_SIZE+1] = "X Y "; char unit[2*MED_SNAME_SIZE+1] = "cm cm "; /* Creation du fichier test27.med */ fid = MEDfileOpen("test27.med",MODE_ACCES); if (fid < 0) { MESSAGE("Erreur a la creation du fichier test27.med"); return -1; } printf("Creation du fichier test27.med \n"); /* Creation du maillage "maa" de type MED_NON_STRUCURE et de dimension 2 */ if (MEDmeshCr( fid, "maillage vide",2, 2, MED_UNSTRUCTURED_MESH, "un maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, comp, unit) < 0) { MESSAGE("Erreur a la creation du maillage MED_UNSTRUCTURED_MESH : "); SSCRUTE(maa); return -1; } /* creation d'une grille cartesienne de dimension 2 */ /* on commence par definir un maillage MED_STRUCTURED_MESH de dimension 2 */ if (MEDmeshCr( fid, maa,mdim, mdim, MED_STRUCTURED_MESH, "un exemple de grille cartesienne","s", MED_SORT_DTIT, MED_CARTESIAN, comp, unit) < 0) { MESSAGE("Erreur a la creation de la grille"); return -1; } printf("Creation d'un maillage structure MED_STRUCTURED_MESH \n"); /* On specifie la nature du maillage structure : MED_GRILLE_CARTESIENNE */ if (MEDmeshGridTypeWr(fid,maa, MED_CARTESIAN_GRID) < 0) { MESSAGE("Erreur a l'ecriture de la nature de la grille"); return -1; } printf("On definit la nature du maillage structure : MED_GRILLE_CARTESIENNE \n"); /* on definit les indices des coordonnees de la grille selon chaque dimension */ /* axe des "X" */ nind = 4; axe = 1; if (MEDmeshGridIndexCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, axe,nind,indiceX) < 0) { MESSAGE("Erreur a l'ecriture de l'axe X"); return -1; } printf("Ecriture des indices des coordonnees selon l'axe des X \n"); /* axe des "Y" */ nind = 4; axe = 2; if (MEDmeshGridIndexCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, axe,nind,indiceY) < 0) { MESSAGE("Erreur a l'ecriture de l'axe Y"); return -1; } printf("Ecriture des indices des coordonnees selon l'axe des Y \n"); /* Creation d'une grille MED_CURVILINEAR_GRID de dimension 2 */ /* on commence par definir un maillage MED_STRUCTURED_MESH de dimension 2 */ if (MEDmeshCr( fid, maa2,mdim, mdim, MED_STRUCTURED_MESH, "un exemple de grille standard","s", MED_SORT_DTIT, MED_CARTESIAN, comp, unit) < 0) { MESSAGE("Erreur a la creation de la 2e grille"); return -1; } printf("Creation d'un maillage structure MED_STRUCTURED_MESH \n"); /* On specifie la nature du maillage structure : MED_CURVILINEAR_GRID */ if (MEDmeshGridTypeWr(fid,maa2, MED_CURVILINEAR_GRID) < 0) { MESSAGE("Erreur a l'ecriture de la nature de la grille"); return -1; } printf("On definit la nature du maillage structure : MED_CURVILINEAR_GRID \n"); if (MEDmeshNodeCoordinateWr(fid,maa2,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE,nnoeuds, coo) < 0) { MESSAGE("Erreur a l'ecriture des noeuds de la grille MED_CURVILINEAR_GRID"); return -1; } printf("Ecriture des coordonnees des noeuds \n"); /* On definit la structure de la grille */ if ( MEDmeshGridStructWr(fid,maa2,MED_NO_DT,MED_NO_IT, MED_UNDEF_DT, structure_grille ) < 0) { MESSAGE("Erreur a l'ecriture de la structure de la grille"); return -1; } printf("Ecriture de la structure de la grille : / 2,2 / \n"); /* On ferme le fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } printf("Fermeture du fichier \n"); return 0; }
med_idt MEDparFileOpen(const char* const filename, const med_access_mode accessmode, const MPI_Comm comm, const MPI_Info info) { med_idt _fid = -1; /* * On inhibe le gestionnaire d'erreur HDF */ _MEDmodeErreurVerrouiller(); /* * On ouvre le fichier MED sous HDF */ switch(accessmode) { case MED_ACC_RDONLY : if (access(filename,F_OK)) { MED_ERR_(_fid,MED_ERR_DOESNTEXIST,MED_ERR_FILE,filename); goto ERROR; } else { if ((_fid = _MEDparFileOpen((char*) filename, accessmode, comm, info)) < 0) { MED_ERR_(_fid,MED_ERR_OPEN,MED_ERR_FILE,filename); goto ERROR; } }; break; case MED_ACC_RDWR : if (access(filename,F_OK)) { if ((_fid = _MEDparFileCreate((char*) filename,accessmode, comm, info)) < 0) { MED_ERR_(_fid,MED_ERR_CREATE,MED_ERR_FILE,filename); goto ERROR; } } else if ((_fid = _MEDparFileOpen((char*) filename,accessmode, comm, info)) < 0) { MED_ERR_(_fid,MED_ERR_OPEN,MED_ERR_FILE,filename); goto ERROR; } break; case MED_ACC_RDEXT : if (access(filename,F_OK)) { if ((_fid = _MEDparFileCreate((char*) filename,accessmode, comm, info)) < 0) { MED_ERR_(_fid,MED_ERR_CREATE,MED_ERR_FILE,filename); goto ERROR; } } else if ((_fid = _MEDparFileOpen((char *) filename, accessmode, comm, info)) < 0) { MED_ERR_(_fid,MED_ERR_OPEN,MED_ERR_FILE,filename); goto ERROR; } break; case MED_ACC_CREAT : if ((_fid = _MEDparFileCreate((char *) filename,MED_ACC_RDWR, comm, info)) < 0) { MED_ERR_(_fid,MED_ERR_CREATE,MED_ERR_FILE,filename); goto ERROR; } break; default : MED_ERR_(_fid,MED_ERR_RANGE,MED_ERR_PARAMETER,""); ISCRUTE_int(accessmode); goto ERROR; } if (_MEDcheckVersion30(_fid) < 0) { MEDfileClose(_fid); _fid=-1;goto ERROR; } ERROR: return _fid; }
int main (int argc, char **argv) { med_idt fid; const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; const med_int spacedim = 2; const med_int meshdim = 2; /* 12345678901234561234567890123456 */ const char axisname[2*MED_SNAME_SIZE+1] = "x y "; const char unitname[2*MED_SNAME_SIZE+1] = "cm cm "; const med_float coordinates[30] = { 2.,1., 7.,1., 12.,1., 17.,1., 22.,1., 2.,6., 7.,6., 12.,6., 17.,6., 22.,6., 2.,11., 7.,11., 12.,11., 17.,11., 22.,11.}; const med_int nnodes = 15; const med_int triaconnectivity[24] = { 1,7,6, 2,7,1, 3,7,2, 8,7,3, 13,7,8, 12,7,13, 11,7,12, 6,7,11 }; const med_int ntria3 = 8; const med_int quadconnectivity[16] = {3,4,9,8, 4,5,10,9, 15,14,9,10, 13,8,9,14}; const med_int nquad4 = 4; med_err ret=-1; /* open MED file */ fid = MEDfileOpen("UsesCase_MEDmesh_1.med",MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); goto ERROR; } /* write a comment in the file */ if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) { MESSAGE("ERROR : write file description ..."); goto ERROR; } /* mesh creation : a 2D unstructured mesh */ if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, "A 2D unstructured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) { MESSAGE("ERROR : mesh creation ..."); goto ERROR; } /* nodes coordinates in a cartesian axis in full interlace mode (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step */ if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_FULL_INTERLACE, nnodes, coordinates) < 0) { MESSAGE("ERROR : nodes coordinates ..."); goto ERROR; } /* cells connectiviy is defined in nodal mode with no iteration and computation step */ if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_TRIA3, MED_NODAL, MED_FULL_INTERLACE, ntria3, triaconnectivity) < 0) { MESSAGE("ERROR : triangular cells connectivity ..."); goto ERROR; } if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4, MED_NODAL, MED_FULL_INTERLACE, nquad4, quadconnectivity) < 0) { MESSAGE("ERROR : quadrangular cells connectivity ..."); goto ERROR; } /* create family 0 : by default, all mesh entities family number is 0 */ if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) { MESSAGE("ERROR : family 0 creation ..."); goto ERROR; } ret = 0; ERROR : /* close MED file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); return -1; } return ret; }
int main(int argc, char *argv[]) { med_idt fid =0; med_int majeur =0, mineur=0, release=0; med_err ret =-1; med_bool hdfok =MED_FALSE; med_bool medok =MED_FALSE; med_bool fileexist =MED_FALSE; med_bool accessok =MED_FALSE; if (argc != 2) { fprintf(stdout,">> Utilisation : medconforme <nom_de_fichier_med> \n"); return 0; } /* * Quelle version de la bibliotheque MED est utilisee ? */ ret=MEDlibraryNumVersion(&majeur, &mineur, &release); EXIT_IF( ret<0 , "Erreur d'appel de la routine MEDlibraryNumVersion.", NULL); fprintf(stdout,"- Version de MED-fichier utilisée par medconforme : "IFORMAT"."IFORMAT"."IFORMAT" \n",majeur,mineur,release); /* * Le fichier à lire est-il accessible ? */ ret = MEDfileExist(argv[1],MED_ACC_RDONLY,&fileexist,&accessok ); MED_ERR_EXIT_IF(ret < 0 , MED_ERR_CALL,MED_ERR_API,"MEDfileExist"); if ( !fileexist ) { fprintf(stdout,"- Le fichier [%s] n'existe pas \n",argv[1]); goto SORTIE; } if ( !accessok ) { fprintf(stdout,"- Le fichier [%s] n'est pas accessible en lecture \n",argv[1]); goto SORTIE; } /* * Le fichier à lire est-il au bon format de fichier HDF ? */ ret=MEDfileCompatibility(argv[1],&hdfok,&medok); MED_ERR_EXIT_IF(ret < 0 , MED_ERR_CALL,MED_ERR_API,"MEDfileCompatibility"); if ( hdfok ) fprintf(stdout,"- Format HDF du fichier MED [%s] conforme au format HDF utilisé par la bibliothèque \n",argv[1]); else { fprintf(stdout,"- Format HDF du fichier MED [%s] non conforme au format HDF utilisé par la bibliothèque \n",argv[1]); goto SORTIE; } /* * Le fichier à lire a-t-il été créé avec une version de la bilbiothèque MED conforme avec celle utilisée ? * (Numéros majeur identique et mineur de la bibliothèque supérieur à celui du fichier). */ if ( medok ) { fprintf(stdout,"- Version MED du fichier [%s] conforme a la bibliothèque MED utilisée \n",argv[1]); if ((fid = MEDfileOpen(argv[1],MED_ACC_RDONLY)) < 0) { MED_ERR_(ret,MED_ERR_OPEN,MED_ERR_FILE,argv[1]); goto ERROR; } /* * Une fois le fichier ouvert on peut avoir acces au numero de version complet */ if ( MEDfileNumVersionRd(fid, &majeur, &mineur, &release) < 0 ) { MED_ERR_(ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd"); goto ERROR; } fprintf(stdout,"- Ce fichier a ete créé avec MED-fichier V"IFORMAT"."IFORMAT"."IFORMAT" \n",majeur,mineur,release); } else fprintf(stdout,"- Version MED du fichier [%s] non conforme avec celle de la bibliothèque utilisée \n",argv[1]); SORTIE: ret = 0; ERROR: if (fid > 0) if (MEDfileClose(fid) < 0) { MED_ERR_(ret,MED_ERR_CLOSE,MED_ERR_FILE,argv[1]); ret = -1; } return ret; }
int main (int argc, char **argv) { med_idt fid; char meshname[MED_NAME_SIZE+1]=""; med_bool localmesh; const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD"; med_field_type fieldtype; char componentname[MED_SNAME_SIZE+1]=""; char componentunit[MED_SNAME_SIZE+1]=""; char dtunit[MED_SNAME_SIZE+1]=""; med_float *values = NULL; med_int nstep, nvalues; med_int ncomponent = 1; med_int csit, numit, numdt, meshnumit, meshnumdt, it; med_float dt; med_geometry_type geotype; med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE; int ret=-1; /* open file */ fid = MEDfileOpen("UsesCase_MEDfield_4.med",MED_ACC_RDONLY); if (fid < 0) { MESSAGE("ERROR : open file ..."); goto ERROR; } /* * ... we know that the MED file has only one field with one component , * a real code working would check ... */ /* * if you know the field name, direct access to field informations */ if (MEDfieldInfoByName(fid, fieldname, meshname, &localmesh, &fieldtype, componentname, componentunit, dtunit, &nstep) < 0) { MESSAGE("ERROR : Field info by name ..."); goto ERROR; } /* * Read field values for each computing step */ for (csit=0; csit<nstep; csit++) { if (MEDfieldComputingStepMeshInfo(fid, fieldname, csit+1, &numdt, &numit, &dt, &meshnumdt, &meshnumit) < 0) { MESSAGE("ERROR : Computing step info ..."); goto ERROR; } /* * ... In our case, we suppose that the field values are only defined on cells ... */ for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) { geotype = geotypes[it]; if ((nvalues = MEDfieldnValue(fid, fieldname, numdt, numit, MED_CELL, geotype)) < 0) { MESSAGE("ERROR : read number of values ..."); goto ERROR; } if (nvalues) { if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent)) == NULL) { MESSAGE("ERROR : memory allocation ..."); goto ERROR; } if (MEDfieldValueRd(fid, fieldname, numdt, numit, MED_CELL, geotype, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) values) < 0) { MESSAGE("ERROR : read fields values for cells ..."); free(values); goto ERROR; } free(values); } } } ret=0; ERROR: /* close file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); ret=-1; } return ret; }
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) { med_err ret = 0; med_idt fid; /* la dimension du maillage */ med_int mdim = 2; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1] = "maa1"; /* le nombre de noeuds */ med_int nnoe = 4; /* table des coordonnees (dimension * nombre de noeuds) */ med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0}; /* tables des noms et des unites des coordonnees (dimension*MED_SNAME_SIZE+1) */ /* 12345678901234561234567890123456*/ char nomcoo[2*MED_SNAME_SIZE+1] = "x y "; char unicoo[2*MED_SNAME_SIZE+1] = "cm cm "; /* tables des noms, numeros, numeros de familles des noeuds autant d'elements que de noeuds - les noms ont pout longueur MED_SNAME_SIZE */ /* 1234567890123456123456789012345612345678901234561234567890123456*/ char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 "; med_int numnoe[4] = {1,2,3,4}; med_int nufano[4] = {0,1,2,2}; /* Creation du fichier "test4.med" */ /* ouverture du fichier */ if ((fid = MEDfileOpen("test4.med",MODE_ACCES)) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } /* Creation du maillage "maa" de type MED_NON_STRUCURE et de dimension 2 */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour test4","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE,nnoe, coo) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Ecriture des attributs des noeuds du maillage */ if (MEDmeshAttributeWr(fid,maa, 0, nnoe, 0) < 0 ) { MESSAGE("Erreur a l'ecriture des attributs des noeuds du maillage"); ret = -1; } /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) { MESSAGE("Erreur a l'ecriture des noms des noeuds"); ret = -1; } /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) { MESSAGE("Erreur a l'ecriture des numeros des noeuds"); ret = -1; } /* Ecriture des numeros de famille des noeuds */ if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) { MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds"); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,0,5,0.5, MED_FULL_INTERLACE,nnoe, coo_2) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,2,0,2.0, MED_FULL_INTERLACE,nnoe, coo) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /*TODO : Ecrire un test de comparaison next prev et ordre de découverte itératif */ MEDmeshComputationStepCr(fid,maa,-1,-1,0,2,0.25); MEDmeshComputationStepCr(fid,maa,0,2,0,3,0.35); /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier test4.med"); return -1; } return ret; }
int main (int argc, char **argv) { med_err ret,lret; med_idt fid; char * fichier = NULL; char maa[MED_NAME_SIZE+1]=""; char desc[MED_COMMENT_SIZE+1]=""; char pflname[MED_NAME_SIZE+1]="",nomlien[MED_NAME_SIZE+1]=""; char _meshname [MED_NAME_SIZE+1]=""; char _dtunit [MED_SNAME_SIZE+1]=""; char locname[MED_NAME_SIZE+1]=""; char * lien = NULL; char *comp= NULL, *unit= NULL; char nomcha [MED_NAME_SIZE+1]=""; med_int mdim=0,sdim=0,ncomp,ncha,npro,nln,pflsize,*pflval,nval; med_int _ncstp=0,ngauss=0,nloc=0,locsdim=0,lnsize=0; int t1,t2,t3; med_field_type typcha; med_geometry_type type_geo; med_float *refcoo, *gscoo, *wg; int i,j; med_bool _local; char dtunit[MED_SNAME_SIZE+1]=""; char nomcoo[3*MED_SNAME_SIZE+1]=""; char unicoo[3*MED_SNAME_SIZE+1]=""; char geointerpname[MED_SNAME_SIZE+1]=""; char ipointstructmeshname[MED_SNAME_SIZE+1]=""; med_mesh_type type; med_sorting_type sort; med_int nstep=0; med_axis_type rep; med_int nsectionmeshcell; med_geometry_type sectiongeotype; if (argc != 2) { MESSAGE("Aucun nom de fichier precise, fichier test10.med utilise "); fichier = "test10.med"; } else { fichier = argv[1]; }; /* Ouverture du fichier med */ if ((fid = MEDfileOpen(fichier,MED_ACC_RDONLY)) < 0){ MESSAGE("Erreur a l'ouverture du fichier : ");SSCRUTE(fichier); return -1; } ret = 0; /* 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 : %d , et de type %d\n",maa,mdim,type); printf("\t -Dimension de l'espace : %d\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 : %d\n",nstep); printf("\t -Unité des dates : |%s|\n",dtunit); } /* combien de champs dans le fichier */ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); return ncha; } printf("Nombre de champs : "IFORMAT" \n",ncha); /* lecture de tous les champs */ for (i =0;i<ncha;i++) { lret = 0; printf("\nChamp numero : %d \n",i+1); /* Lecture du nombre de composantes */ if ((ncomp = MEDfieldnComponent(fid,i+1)) < 0) { MESSAGE("Erreur a la lecture du nombre de composantes : "); ISCRUTE(ncomp); ret = -1; continue; } /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/ comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1); EXIT_IF(comp == NULL,NULL,NULL); unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1); EXIT_IF(unit == NULL,NULL,NULL); if ( MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp) < 0 ) { MESSAGE("Erreur a la demande d'information sur les champs : "); ISCRUTE_int(i+1);SSCRUTE(nomcha);ISCRUTE_int(typcha);SSCRUTE(comp);SSCRUTE(unit); ISCRUTE(ncomp); ret = -1; continue; } printf("Nom du champ : |%s| de type %d\n",nomcha,typcha); printf("Nom des composantes : |%s|\n",comp); printf("Unites des composantes : |%s| \n",unit); printf("Unites des dates : |%s| \n",_dtunit); printf("Le maillage associé est |%s|\n",_meshname); printf("Nombre de séquences de calcul |%d|\n",_ncstp); /* Le maillage reference est-il porte par un autre fichier */ if ( !_local ) { if ( (lnsize=MEDlinkInfoByName(fid,_meshname) ) < 0 ) { MESSAGE("Erreur a la lecture de la taille du lien : "); SSCRUTE(_meshname); ret = -1; } else { lien = malloc(lnsize*sizeof(char)); EXIT_IF(lien == NULL,NULL,NULL); if ( MEDlinkRd(fid,_meshname, lien) < 0 ) { MESSAGE("Erreur a la lecture du lien : "); SSCRUTE(_meshname);SSCRUTE(lien); ret = -1; } else { printf("\tLe maillage |%s| est porte par un fichier distant |%s|\n",_meshname,lien); } free(lien); } } free(comp); free(unit); /*TODO : Créer les API30 spécifiques pour la lecture de champs multi-maillages*/ if (strcmp(nomcha,"champ entier")) { MESSAGE("There is no API yest for reading field on multiple meshes"); continue; } lret = getFieldsOn(fid, nomcha, typcha, ncomp, MED_NODE, USER_INTERLACE,_ncstp ); if (lret == 0) lret = getFieldsOn(fid, nomcha, typcha, ncomp, MED_CELL, USER_INTERLACE,_ncstp ); else { MESSAGE("Erreur a la lecture des champs aux noeuds "); ret = -1; continue;} if (lret == 0) lret = getFieldsOn(fid, nomcha, typcha, ncomp, MED_DESCENDING_FACE,USER_INTERLACE,_ncstp); else { MESSAGE("Erreur a la lecture des champs aux mailles "); ret = -1; continue;} if (lret == 0) lret = getFieldsOn(fid, nomcha, typcha, ncomp, MED_DESCENDING_EDGE,USER_INTERLACE,_ncstp); else {MESSAGE("Erreur a la lecture des champs aux faces "); ret = -1; continue;} if (lret == 0) lret = getFieldsOn(fid, nomcha, typcha, ncomp, MED_NODE_ELEMENT,USER_INTERLACE,_ncstp); else {MESSAGE("Erreur a la lecture des champs aux aretes"); ret = -1; continue;} /*TODO */ /* if (lret == 0) lret = getFieldsOn(fid, nomcha, typcha, ncomp, MED_STRUCT_ELEMENT,USER_INTERLACE,_ncstp); */ /* else {MESSAGE("Erreur a la lecture des champs aux éléments de structure"); ret = -1; continue;} */ if (lret != 0) {MESSAGE("Erreur a la lecture des champs aux noeuds des mailles "); ret = -1;}; } /* Interrogation des profils */ npro = MEDnProfile(fid); printf("\nNombre de profils stockes : "IFORMAT"\n\n",npro); for (i=1 ; i <= npro ; i++ ) { if ( MEDprofileInfo(fid, i, pflname, &nval) < 0) { MESSAGE("Erreur a la demande d'information sur le profil n° : "); ISCRUTE_int(i); ret = -1;continue; } printf("\t- Profil n°%i de nom |%s| et de taille "IFORMAT"\n",i,pflname,nval); pflval = (med_int*) malloc(sizeof(med_int)*nval); if ( MEDprofileRd(fid, pflname, pflval) < 0) { MESSAGE("Erreur a la lecture des valeurs du profil : "); SSCRUTE(pflname); ret = -1; } else { printf("\t"); for (j=0;j<nval;j++) printf(" "IFORMAT" ",*(pflval+j)); printf("\n\n"); } free(pflval); } /* Interrogation des liens */ nln = MEDnLink(fid); printf("\nNombre de liens stockes : "IFORMAT"\n\n",nln); for (i=1 ; i <= nln ; i++ ) { if ( MEDlinkInfo(fid, i, nomlien, &nval) < 0) { MESSAGE("Erreur a la demande d'information sur le lien n° : "); ISCRUTE_int(i); ret = -1;continue; } printf("\t- Lien n°%i de nom |%s| et de taille "IFORMAT"\n",i,nomlien,nval); lien = malloc((nval+1)*sizeof(char)); EXIT_IF(lien == NULL,NULL,NULL); if ( MEDlinkRd(fid, nomlien, lien ) < 0 ) { MESSAGE("Erreur a la lecture du lien : "); SSCRUTE(nomlien);SSCRUTE(lien); ret = -1; } else { lien[nval] = '\0'; printf("\t\t|%s|\n\n",lien); } free(lien); } /* Interrogation des localisations des points de GAUSS */ nloc = MEDnLocalization(fid); printf("\nNombre de localisations stockees : "IFORMAT"\n\n",nloc); for (i=1 ; i <= nloc ; i++ ) { if ( MEDlocalizationInfo(fid, i, locname, &type_geo, &locsdim,&ngauss, geointerpname, ipointstructmeshname, &nsectionmeshcell,§iongeotype) < 0) { MESSAGE("Erreur a la demande d'information sur la localisation n° : "); ISCRUTE_int(i); ret = -1;continue; } printf("\t- Loc. n°%i de nom |%s| de dimension %i avec "IFORMAT" pts de GAUSS \n",i,locname,locsdim,ngauss); t1 = (type_geo%100)*(type_geo/100); t2 = ngauss*(type_geo/100); t3 = ngauss; refcoo = (med_float *) malloc(sizeof(med_float)*t1 ); gscoo = (med_float *) malloc(sizeof(med_float)*t2 ); wg = (med_float *) malloc(sizeof(med_float)*t3 ); if ( MEDlocalizationRd(fid, locname, USER_INTERLACE, refcoo, gscoo, wg ) < 0) { MESSAGE("Erreur a la lecture des valeurs de la localisation : "); SSCRUTE(locname); ret = -1; } else { printf("\t Coordonnees de l'element de reference de type %i :\n\t\t",type_geo); for (j=0;j<t1;j++) printf(" %f ",*(refcoo+j)); printf("\n"); printf("\t Localisation des points de GAUSS : \n\t\t"); for (j=0;j<t2;j++) printf(" %f ",*(gscoo+j)); printf("\n"); printf("\t Poids associes aux points de GAUSS :\n\t\t"); for (j=0;j<t3;j++) printf(" %f ",*(wg+j)); printf("\n\n"); } free(refcoo); free(gscoo); free(wg); } /* fermeture du fichier */ if ( MEDfileClose(fid) < 0) return -1; return ret; }
int main (int argc, char **argv) { med_err _ret=0; med_idt _fid=0; int _i =0; med_int _nstructelement=0; med_geometry_type _geotype=MED_NONE; char _elementname[MED_NAME_SIZE+1]=""; med_int _elementdim=0; char _supportmeshname[MED_NAME_SIZE+1]=""; med_entity_type _entitytype=MED_UNDEF_ENTITY_TYPE; med_int _nnode=0; med_int _ncell=0; med_geometry_type _geocelltype=MED_NONE; med_int _nconstantattribute=0; med_bool _anyprofile=0; med_int _nvariableattribute=0; /* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */ _fid = MEDfileOpen("current.med",MED_ACC_RDONLY); if (_fid < 0) { MESSAGE("Erreur à la lecture du fichier current.med"); return -1; } if ( (_nstructelement = MEDnStructElement(_fid)) <0) _ret=_nstructelement; for ( _i=1; _i<= _nstructelement; ++_i) { if ( MEDstructElementInfo(_fid, _i, _elementname, &_geotype, &_elementdim, _supportmeshname, &_entitytype, &_nnode, &_ncell, &_geocelltype, &_nconstantattribute, &_anyprofile, &_nvariableattribute ) ) return -1; fprintf(stdout,"Elément de structure n° %d |%s| de type géométrique n° %d et de dimension %d\n", _i,_elementname,_geotype,_elementdim); if ( strlen(_supportmeshname) ) { fprintf(stdout,"\t Maillage support de nom |%s|",_supportmeshname); if (_ncell) fprintf(stdout," avec %d mailles de type %d et ",_ncell,_geocelltype); if (_nnode) fprintf(stdout," avec %d noeuds\n",_nnode); else { fprintf(stderr,"\n Erreur : les noeuds doivent être définis s'il existe un maillage support\n"); } } else fprintf(stdout," avec support implicite sur noeud\n"); fprintf(stdout,"\t Nombre d'attributs constants : %d",_nconstantattribute); if (_anyprofile) fprintf(stdout,", avec profil.\n"); else fprintf(stdout,", sans profil.\n"); fprintf(stdout,"\t Nombre d'attributs variables : %d\n",_nvariableattribute); } if (MEDfileClose(_fid) < 0) { MESSAGE("ERROR : file closing"); return -1; } return _ret; }
int main (int argc, char **argv) { med_idt fid; med_idt nfield, i, j; char meshname[MED_NAME_SIZE+1]=""; med_bool localmesh; char fieldname[MED_NAME_SIZE+1]=""; med_field_type fieldtype; char *componentname = NULL; char *componentunit = NULL; char dtunit[MED_SNAME_SIZE+1]=""; med_float *values = NULL; med_int nstep, nvalues; med_int ncomponent; med_int csit, numit, numdt, meshnumit, meshnumdt, it; med_float dt; med_geometry_type geotype; med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE; int k; int ret=-1; /* open file */ fid = MEDfileOpen("UsesCase_MEDfield_4.med",MED_ACC_RDONLY); if (fid < 0) { MESSAGE("ERROR : open file ..."); goto ERROR; } /* * generic approach : how many fields in the file and identification * of each field. */ if ((nfield = MEDnField(fid)) < 0) { MESSAGE("ERROR : How many fields in the file ..."); goto ERROR; } /* * read values for each field */ for (i=0; i<nfield; i++) { if ((ncomponent = MEDfieldnComponent(fid,i+1)) < 0) { MESSAGE("ERROR : number of field component ..."); goto ERROR; } if ((componentname = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) { MESSAGE("ERROR : memory allocation ..."); goto ERROR; } if ((componentunit = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) { MESSAGE("ERROR : memory allocation ..."); goto ERROR; } if (MEDfieldInfo(fid, i+1, fieldname, meshname, &localmesh, &fieldtype, componentname, componentunit, dtunit, &nstep) < 0) { MESSAGE("ERROR : Field info ..."); free(componentname); free(componentunit); goto ERROR; } free(componentname); free(componentunit); /* * Read field values for each computing step */ for (csit=0; csit<nstep; csit++) { if (MEDfieldComputingStepMeshInfo(fid, fieldname, csit+1, &numdt, &numit, &dt, &meshnumdt, &meshnumit) < 0) { MESSAGE("ERROR : Computing step info ..."); goto ERROR; } /* * ... In our case, we suppose that the field values are only defined on cells ... */ for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) { geotype = geotypes[it]; if ((nvalues = MEDfieldnValue(fid, fieldname, numdt, numit, MED_CELL, geotype)) < 0) { MESSAGE("ERROR : read number of values ..."); goto ERROR; } if (nvalues) { if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent)) == NULL) { MESSAGE("ERROR : memory allocation ..."); goto ERROR; } if (MEDfieldValueRd(fid, fieldname, numdt, numit, MED_CELL, geotype, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) values) < 0) { MESSAGE("ERROR : read fields values for cells ..."); free(values); goto ERROR; } free(values); } } } } ret=0; ERROR: /* close file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); ret=-1; } return ret; }
int main (int argc, char **argv) { med_idt fid; const char filename[] = "Unittest_MEDparameter_1.med"; const char comment[] = "Parameters unit tests"; const char p1name[] = "FLOAT_PARAMETER"; const char p2name[] = "INT_PARAMETER_1"; const char p3name[] = "INT_PARAMETER_2"; const med_parameter_type p1type = MED_FLOAT64; const med_parameter_type p2type = MED_INT; const med_parameter_type p3type = MED_INT; const char p1description[] = "PARAMETER 1 DESCRIPTION"; const char p2description[] = "PARAMETER 2 DESCRIPTION"; const char p3description[] = "PARAMETER 3 DESCRIPTION"; const char dtunit1[] = "DT UNIT P1"; const char dtunit2[] = "DT UNIT P2"; const char dtunit3[] = "DT UNIT P3"; med_int np; char nameToRead[MED_NAME_SIZE+1]; char descriptionToRead[MED_COMMENT_SIZE+1]; med_parameter_type typeToRead; char dtunitToRead[MED_SNAME_SIZE+1]; med_int nstepToRead; int i,j; med_float p1v1 = 6.98; med_float p1v2 = 19.07; med_float p1v3 = 78.0; med_int p1numdt1 = MED_NO_DT; med_int p1numdt2 = 1; med_int p1numdt3 = 1; med_int p1numit1 = MED_NO_IT; med_int p1numit2 = 3; med_int p1numit3 = 2; med_float p1dt1 = 0.0; med_float p1dt2 = 0.1; med_float p1dt3 = 5.5; const med_int p1ncpst = 3; med_int p2v1 = 5; med_int p2v2 = 6; med_int p2numit1 = MED_NO_IT; med_int p2numdt1 = MED_NO_DT; med_float p2dt1 = 0.0; const med_int p2ncpst = 1; med_int p3v1 = 77; med_int p3v2 = 89; med_int p3numdt1 = 1; med_int p3numit1 = 1; med_float p3dt1 = 18.9; med_int p3numdt2 = MED_NO_DT; med_int p3numit2 = MED_NO_IT; med_float p3dt2 = 0.0; const med_int p3ncpst = 2; med_int numdtToRead; med_int numitToRead; med_float dtToRead; med_float fvalueToRead; med_int ivalueToRead; /* file creation */ fid = MEDfileOpen(filename,MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); SSCRUTE(filename); return -1; } if (MEDfileCommentWr(fid,comment) < 0) { MESSAGE("ERROR : write comment ..."); SSCRUTE(comment); return -1; } /* create a MED_FLOAT64 parameter */ if (MEDparameterCr(fid, p1name, p1type, p1description, dtunit1) < 0) { MESSAGE("ERROR : parameter p1 creation ..."); SSCRUTE(p1name); return -1; } if (MEDparameterValueWr(fid, p1name, p1numdt1, p1numit1, p1dt1, (unsigned char*) &p1v1) < 0) { MESSAGE("ERROR : write p1v1 ..."); SSCRUTE(p1name); return -1; } if (MEDparameterValueWr(fid, p1name, p1numdt2, p1numit2, p1dt2, (unsigned char*) &p1v2) < 0) { MESSAGE("ERROR : write p1v2 ..."); SSCRUTE(p1name); return -1; } if (MEDparameterValueWr(fid, p1name, p1numdt3, p1numit3, p1dt3, (unsigned char*) &p1v3) < 0) { MESSAGE("ERROR : write p1v3 ..."); SSCRUTE(p1name); return -1; } /* create a MED_INT parameter with different values */ if (MEDparameterCr(fid, p2name, p2type, p2description, dtunit2) < 0) { MESSAGE("ERROR : paramter p2 creation ..."); SSCRUTE(p2name); return -1; } if (MEDparameterValueWr(fid, p2name, p2numdt1, p2numit1, p2dt1, (unsigned char*) &p2v1) < 0) { MESSAGE("ERROR : write p2v1 ..."); SSCRUTE(p2name); return -1; } if (MEDparameterValueWr(fid, p2name, p2numdt1, p2numit1, p2dt1, (unsigned char*) &p2v2) < 0) { MESSAGE("ERROR : write p2v2 on same computation step ..."); SSCRUTE(p2name); return -1; } /* create another MED_INT parameter */ if (MEDparameterCr(fid, p3name, p3type, p3description, dtunit3) < 0) { MESSAGE("ERROR : paramter p3 creation ..."); SSCRUTE(p3name); return -1; } if (MEDparameterValueWr(fid, p3name, p3numdt1, p3numit1, p3dt1, (unsigned char*) &p3v1) < 0) { MESSAGE("ERROR : write p3v1 ..."); SSCRUTE(p3name); return -1; } if (MEDparameterValueWr(fid, p3name, p3numdt2, p3numit2, p3dt2, (unsigned char*) &p3v2) < 0) { MESSAGE("ERROR : write p3v2 ..."); SSCRUTE(p3name); return -1; } /* close file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : file closing ..."); return -1; } /* open file in READ ONLY access mode */ fid = MEDfileOpen(filename,MED_ACC_RDONLY); if (fid < 0) { MESSAGE("ERROR : open in READ ONLY ACCESS mode ..."); SSCRUTE(filename); return -1; } /* direct access to parameters */ if (MEDparameterInfoByName(fid, p1name, &typeToRead, descriptionToRead, dtunitToRead, &nstepToRead) < 0) { MESSAGE("ERROR : read information for parameter p1 ..."); SSCRUTE(p1name); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if ((typeToRead != p1type) || strcmp(descriptionToRead, p1description) || strcmp(dtunitToRead,dtunit1) || (nstepToRead != p1ncpst)) { MESSAGE("ERROR : read information for parameter p1 : attributes ..."); SSCRUTE(p1name); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if (MEDparameterInfoByName(fid, p2name, &typeToRead, descriptionToRead, dtunitToRead, &nstepToRead) < 0) { MESSAGE("ERROR : read information for parameter p2 ..."); SSCRUTE(p2name); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if ((typeToRead != p2type) || strcmp(descriptionToRead, p2description) || strcmp(dtunitToRead,dtunit2) || (nstepToRead != p2ncpst)) { MESSAGE("ERROR : read information for parameter p2 : attributes ..."); SSCRUTE(p2name); ISCRUTE(typeToRead); ISCRUTE(p2type); SSCRUTE(descriptionToRead); SSCRUTE(p2description); SSCRUTE(dtunitToRead); SSCRUTE(dtunit2); ISCRUTE(nstepToRead); ISCRUTE(p2ncpst); return -1; } if (MEDparameterInfoByName(fid, p3name, &typeToRead, descriptionToRead, dtunitToRead, &nstepToRead) < 0) { MESSAGE("ERROR : read information for parameter p3 ..."); SSCRUTE(p3name); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if ((typeToRead != p3type) || strcmp(descriptionToRead, p3description) || strcmp(dtunitToRead,dtunit3) || (nstepToRead != p3ncpst)) { MESSAGE("ERROR : read information for parameter p2 : attributes ..."); SSCRUTE(p3name); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } /* how many parameter(s) in the file ? */ if ((np = MEDnParameter(fid)) < 0) { MESSAGE("ERROR : read number of paremeter ..."); ISCRUTE(np); return -1; } if (np != 3) { MESSAGE("The number of parameter is 3 !"); ISCRUTE(np); return -1; } /* TODO : A SUPPRIMER */ np=0; /* read informations for each parameter */ for (i=0;i<np;i++) { if (MEDparameterInfo(fid, i+1, nameToRead, &typeToRead, descriptionToRead, dtunitToRead, &nstepToRead) < 0) { MESSAGE("ERROR : read information for parameter p3 ..."); SSCRUTE(nameToRead); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if (i == 0) if (strcmp(nameToRead, p1name) || (typeToRead != p1type) || strcmp(descriptionToRead, p1description) || strcmp(dtunitToRead,dtunit1) || (nstepToRead != p1ncpst)) { MESSAGE("ERROR : read information for parameter p1 : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if (i == 1) if ( strcmp(nameToRead, p2name) || (typeToRead != p2type) || strcmp(descriptionToRead, p2description) || strcmp(dtunitToRead,dtunit2) || (nstepToRead != p2ncpst)) { MESSAGE("ERROR : read information for parameter p2 : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } if (i == 3) if (strcmp(nameToRead,p3name) || (typeToRead != p3type) || strcmp(descriptionToRead, p3description) || strcmp(dtunitToRead,dtunit3) || (nstepToRead != p3ncpst)) { MESSAGE("ERROR : read information for parameter p2 : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(typeToRead); SSCRUTE(descriptionToRead); SSCRUTE(dtunitToRead); ISCRUTE(nstepToRead); return -1; } /* read informations about each computation step and then read value for each parameter */ for (j=0; j<nstepToRead; j++) { if (MEDparameterComputationStepInfo(fid, nameToRead, j+1, &numdtToRead, &numitToRead, &dtToRead) < 0) { MESSAGE("ERROR : read information about computation step ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(numitToRead); return -1; } if (typeToRead == MED_FLOAT64) if (MEDparameterValueRd(fid, nameToRead, numdtToRead, numitToRead, (unsigned char *) &fvalueToRead) < 0) { MESSAGE("ERROR : read parameter value ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(numitToRead); return -1; } if (typeToRead != MED_FLOAT64) if (MEDparameterValueRd(fid, nameToRead, numdtToRead, numitToRead, (unsigned char *) &ivalueToRead) < 0) { MESSAGE("ERROR : read parameter value ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(numitToRead); ISCRUTE(ivalueToRead); return -1; } /* data verifications */ if ((i==0) && (j==0)) if ((numdtToRead != p1numdt1) || (numitToRead != p1numit1) || (dtToRead != p1dt1) || (fvalueToRead != p1v1)) { MESSAGE("ERROR : false informations for computation step : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(p1numdt1); ISCRUTE(numitToRead); ISCRUTE(p1numit1); return -1; } if ((i==0) && (j==1)) if ((numdtToRead != p1numdt3) || (numitToRead != p1numit3) || (dtToRead != p1dt3) || (fvalueToRead != p1v3)) { MESSAGE("ERROR : false informations for computation step : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(p1numdt3); ISCRUTE(numitToRead); ISCRUTE(p1numit3); return -1; } if ((i==0) && (j==2)) if ((numdtToRead != p1numdt2) || (numitToRead != p1numit2) || (dtToRead != p1dt2) || (fvalueToRead != p1v2)) { MESSAGE("ERROR : false informations for computation step : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(p1numdt2); ISCRUTE(numitToRead); ISCRUTE(p1numit2); return -1; } if (i==1) if ((numdtToRead != p2numdt1) || (numitToRead != p2numit1) || (dtToRead != p2dt1) || (ivalueToRead != p2v2)) { MESSAGE("ERROR : false informations for computation step : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(p2numdt1); ISCRUTE(numitToRead); ISCRUTE(p2numit1); return -1; } if ((i == 2) && (j == 0)) if ((numdtToRead != p3numdt2) || (numitToRead != p3numit2) || (dtToRead != p3dt2) || (ivalueToRead != p3v2)) { MESSAGE("ERROR : false informations for computation step : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(p3numdt2); ISCRUTE(numitToRead); ISCRUTE(p3numit2); return -1; } if ((i == 2) && (j == 1)) if ((numdtToRead != p3numdt1) || (numitToRead != p3numit1) || (dtToRead != p3dt1) || (ivalueToRead != p3v1)) { MESSAGE("ERROR : false informations for computation step : attributes ..."); SSCRUTE(nameToRead); ISCRUTE(j); ISCRUTE(numdtToRead); ISCRUTE(p3numdt1); ISCRUTE(numitToRead); ISCRUTE(p3numit1); return -1; } } } /* close file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); return -1; } return 0; }
int main (int argc, char **argv) { med_idt fid; const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; const med_int spacedim = 2; const med_int meshdim = 2; const char axisname[2*MED_SNAME_SIZE+1] = "x y "; const char unitname[2*MED_SNAME_SIZE+1] = "cm cm "; const med_float initial_coordinates[30] = { 2.,1., 7.,1., 12.,1., 17.,1., 22.,1., 2.,6., 7.,6., 12.,6., 17.,6., 22.,6., 2.,11., 7.,11., 12.,11., 17.,11., 22.,11.}; const med_int nnodes = 15; const med_int triaconnectivity[24] = { 1,7,6, 2,7,1, 3,7,2, 8,7,3, 13,7,8, 12,7,13, 11,7,12, 6,7,11 }; const med_int ntria3 = 8; const med_int quadconnectivity[16] = {3,4,9,8, 4,5,10,9, 15,14,9,10, 13,8,9,14}; const med_int nquad4 = 4; /* matrix transformation (step 1) : rotation about the Y-axis : 45 degrees */ const med_float tansfMatrix_step1 [7] = { 0.0, 0.0, 0.0, 0.92388, 0.0, 0.38268, 0.0 }; /* matrix transformation (step 2) : rotation about the Y-axis : 90 degrees */ const med_float tansfMatrix_step2 [7] = { 0.0, 0.0, 0.0, 0.707, 0.0, 0.707, 0.0 }; int ret=-1; /* open MED file */ fid = MEDfileOpen("UsesCase_MEDmesh_9.med",MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); goto ERROR; } /* write a comment in the file */ if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) { MESSAGE("ERROR : write file description ..."); goto ERROR; } /* mesh creation : a 2D unstructured mesh */ if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, "A 2D structured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) { MESSAGE("ERROR : mesh creation ..."); goto ERROR; } /* nodes coordinates in a cartesian axis in full interlace mode (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step */ if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nnodes, initial_coordinates) < 0) { MESSAGE("ERROR : nodes coordinates ..."); goto ERROR; } /* cells connectiviy is defined in nodal mode */ if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_TRIA3, MED_NODAL, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, ntria3, triaconnectivity) < 0) { MESSAGE("ERROR : triangular cells connectivity ..."); goto ERROR; } if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4, MED_NODAL, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nquad4, quadconnectivity) < 0) { MESSAGE("ERROR : quadrangular cells connectivity ..."); goto ERROR; } /* * Mesh deformation (nodes coordinates) in 2 steps * A rotation by step for each node */ /* STEP 1 : dt1 = 5.5, it = 1*/ if ( MEDmeshNodeCoordinateTrsfWr(fid, meshname, 1, 1, 5.5, tansfMatrix_step1) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); goto ERROR; } /* STEP 2 : dt2 = 8.9, it = 1*/ if ( MEDmeshNodeCoordinateTrsfWr(fid, meshname, 2, 2, 8.9, tansfMatrix_step2 ) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); goto ERROR; } /* create family 0 : by default, all mesh entities family number is 0 */ if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) { MESSAGE("ERROR : create family ..."); goto ERROR; } ret=0; ERROR: /* close MED file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); ret=-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 main (int argc, char **argv) { med_idt fid; const char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family"; med_geometry_type geotype =MED_NONE; med_bool cellnodes =MED_FALSE; med_int nbasisfunc =0; med_int nvariable =0; med_int maxdegree =0; med_int nmaxcoefficient =0; int basisfuncit =0; int powerit =0; med_int ncoefficient =0; med_int* power =NULL; med_float* coefficient =NULL; int coefficientit =0; int ret=-1; /* file creation */ fid = MEDfileOpen("UsesCase_MEDinterp_1.med",MED_ACC_RDONLY); if (fid < 0) { MESSAGE("ERROR : file creation ..."); goto ERROR; } /* with direct access by the family name */ if (MEDinterpInfoByName(fid,interpname,&geotype,&cellnodes,&nbasisfunc, &nvariable,&maxdegree,&nmaxcoefficient) < 0) { MESSAGE("ERROR : interpolation function information ..."); goto ERROR; } /* read each basis function */ for ( basisfuncit=1; basisfuncit<= nbasisfunc; ++basisfuncit) { if ((ncoefficient = MEDinterpBaseFunctionCoefSize(fid,interpname,basisfuncit) ) <0 ) { MESSAGE("ERROR : read number of coefficient in the base function ..."); goto ERROR; } coefficient = (med_float*) calloc(sizeof(med_float),ncoefficient); power = (med_int*) calloc(sizeof(med_int),nvariable*ncoefficient); if (MEDinterpBaseFunctionRd(fid,interpname,basisfuncit,&ncoefficient,power,coefficient) < 0) { MESSAGE("ERROR : read base function ..."); free(coefficient); free(power); goto ERROR; } free(coefficient); free(power); } ret=0; ERROR: /* close file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); ret=-1; } return ret; }
int main (int argc, char **argv) { med_idt fid; const char meshname[MED_NAME_SIZE+1] = "3D Unstructured Mesh With 2 polyhedrons"; const med_int spacedim = 3; const med_int meshdim = 3; /* 12345678901234561234567890123456 */ const char axisname[3*MED_SNAME_SIZE+1] = "x y z "; const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm "; const med_int nnodes = 16; const med_float coordinates[3 * 16] = { /* [ 1 ] */ -10.0, -10.0, +0.0, /* [ 2 ] */ -10.0, -10.0, +10., /* [ 3 ] */ -10.0, +10.0, +10., /* [ 4 ] */ -10.0, +10.0, +0.0, /* [ 5 ] */ +10.0, -10.0, +0.0, /* [ 6 ] */ +10.0, -10.0, +10., /* [ 7 ] */ +10.0, +10.0, +10., /* [ 8 ] */ +10.0, +10.0, +0.0, /* [ 9 ] */ -10.0, +0.0 , +10.0, /* [ 10 ] */ -10.0, +0.0 , +0.0 , /* [ 11 ] */ +0.0 , -10.0 , +10.0, /* [ 12 ] */ +0.0 , -10.0 , +0.0 , /* [ 13 ] */ +0.0 , +10.0 , +10.0, /* [ 14 ] */ +10.0, +0.0 , +10.0, /* [ 15 ] */ +0.0 , +10.0 , +0.0 , /* [ 16 ] */ +10.0, +0.0 , +0.0 }; /*Il y a 58 numéros de noeuds dans le tableau de connextivité*/ const med_int connectivity[26+32] = { /* - Poly 1 : */ /* - Face 1 : */ 1, 2 , 9 , 3 , 10, /* - Face 2 : */ 1, 12 , 5 , 6 , 11, 2, /* - Face 3 : */ 2, 11 , 6 , 3 , 9 , /* - Face 4 : */ 3, 6 , 5 , /* - Face 5 : */ 3, 5 , 10 , /* - Face 6 : */ 1, 10 , 5 , 12, /* - Poly 2 : */ /* - Face 1 : */ 3, 13 , 7 , 8 , 15, 4, /* - Face 2 : */ 3, 4 , 10 , /* - Face 3 : */ 4, 15 , 8 , 16 , 5, 10, /* - Face 4 : */ 3, 6 , 14 , 7 , 13, /* - Face 5 : */ 5, 16 , 8 , 7 , 14, 6, /* - Face 6 : */ 3, 10 , 5 , /* - Face 7 : */ 3, 5 , 6 }; /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */ /* La face 7 du Poly 2 utilise 59-56=3 noeuds */ const med_int nodeindex[6+7+1] = { 1, 6, 12, 17, 20, 23, 27, 33, 36, 42, 47, 53, 56, 59}; /* Il y a un total de 13 faces */ /* NodeIndexSize == Nbre De Faces +1 */ const med_int nodeindexSize = 6+7+1; /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */ /* Pn+1 == FaceIndex[n+1]== NodeIndexSize== Nbre De Faces +1 */ const med_int faceindex[3] = {1,7,14}; const med_int faceindexSize = 3; /* open MED file */ fid = MEDfileOpen("UsesCase_MEDmesh_15.med", MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); return -1; } /* write a comment in the file */ if (MEDfileCommentWr(fid, "A 3D unstructured mesh : 2 polyhedrons") < 0) { MESSAGE("ERROR : write file description ..."); return -1; } /* mesh creation : a 3D unstructured mesh */ if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, "A 3D mesh with 2 polyhedron", "", MED_SORT_DTIT, MED_CARTESIAN, axisname, unitname) < 0) { MESSAGE("ERROR : mesh creation ..."); return -1; } /* nodes coordinates in a cartesian axis in full interlace mode (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step */ if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_FULL_INTERLACE, nnodes, coordinates) < 0) { MESSAGE("ERROR : nodes coordinates ..."); return -1; } /* cells connectiviy is defined in nodal mode */ if (MEDmeshPolyhedronWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_CELL, MED_NODAL, faceindexSize, faceindex, nodeindexSize, nodeindex, connectivity) < 0) { MESSAGE("ERROR : polyhedron connectivity ..."); return -1; } /* create family 0 : by default, all mesh entities family number is 0 */ if (MEDfamilyCr(fid, meshname, "", 0, 0, "") < 0) { MESSAGE("ERROR : quadrangular cells connectivity ..."); return -1; } /* close MED file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); return -1; } return 0; }