med_int nmlcflow(med_idt *fid, char *lname,med_int *lnamelen, med_int *gtype, med_int *sdim, med_float *ecoo, med_int *swm, med_int *nip, med_float *icoo, med_float *wght,char * giname, med_int *ginamelen, char * isname, med_int *isnamelen) #endif { med_err _ret=0; char *_fn1,*_fn2,*_fn3; med_switch_mode _swm = (med_switch_mode) *swm; med_geometry_type _gtype = (med_geometry_type) *gtype; _fn1 = _MED2cstring((char *) lname, (int) *lnamelen); if (!_fn1) return(-1); _fn2 = _MED2cstring((char *) giname, (int) *ginamelen); if (!_fn2) return(-1); _fn3 = _MED2cstring((char *) isname, (int) *isnamelen); if (!_fn3) return(-1); _ret = (med_int) MEDlocalizationWr((const med_idt) *fid, _fn1, _gtype, (med_int) *sdim, (med_float *) ecoo, _swm, (med_int) *nip, (med_float *) icoo, (med_float *) wght, _fn2, _fn3); _MEDcstringFree(_fn1); _MEDcstringFree(_fn2); _MEDcstringFree(_fn3); return (_ret); }
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; /* Maillage support aux champs*/ /* Ces maillages sont vides*/ char maa1[MED_NAME_SIZE+1]= "maa1"; char maa2[MED_NAME_SIZE+1]= "maa2"; char * lien_maa2 = "./testfoo.med"; char maa3[MED_NAME_SIZE+1]= "maa3"; /* Caractéristiques du champ n° 1 sur TRIA6 */ char nomcha1[MED_NAME_SIZE+1] = "champ reel"; char comp1[2*MED_SNAME_SIZE+1] = "comp1 comp2 "; /*12345678901234561234567890123456*/ char unit1[2*MED_SNAME_SIZE+1] = "unit1 unit2 "; med_int ncomp1 = 2; /* Caractéristiques du model n° 1 de localisation des points de gauss pour le champ n° 1*/ med_int ngauss1_1 = 6; char gauss1_1[MED_NAME_SIZE+1] = "Model n1"; med_float refcoo1[12] = { -1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 }; /* Constantes */ med_float gscoo1_1[12] = { 2*_b-1, 1-4*_b, 2*_b-1, 2*_b-1, 1-4*_b, 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 }; med_float wg1_1[6] = { 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 }; med_int nval1_1= 1*6; /*1 valeurs et 6 points de gauss par valeur */ med_int _nent1_1= 1; /*1 valeurs et 6 points de gauss par valeur */ med_float valr1_1[1*6*2] = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ /* Caractéristiques du model n° 2 de localisation des points de gauss pour le champ n° 1*/ med_int ngauss1_2 = 3; char gauss1_2[MED_NAME_SIZE+1] = "Model n2"; med_float gscoo1_2[6] = { -2.0/3,1.0/3, -2.0/3,-2.0/3, 1.0/3,-2.0/3 }; med_float wg1_2[3] = { 2.0/3, 2.0/3, 2.0/3 }; med_int nval1_2= 2*3; /*2 valeurs et 3 points de gauss par valeur */ med_int _nent1_2= 2; /*2 valeurs et 3 points de gauss par valeur */ med_float valr1_2[2*3*2] = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ med_float valr1_2p[2*3*2] = { 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ /* Caractéristiques du model n° 3 sans points de gauss pour le champ n° 1*/ med_int nval1_3= 6; /*6 valeurs et pas de points de gauss */ med_int _nent1_3= 6; /*6 valeurs et pas de points de gauss */ med_float valr1_3[2*3*2] = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ med_float valr1_3p[2*2*2] = { 2.0,3.0, 10.0,11.0 }; /* 2 composantes profil1 */ /* Caractéristiques du champ n° 2 */ char nomcha2[MED_NAME_SIZE+1] = "champ entier"; char comp2[3*MED_SNAME_SIZE+1] = "comp1 comp2 comp3 "; /*123456789012345612345678901234561234567890123456*/ char unit2[3*MED_SNAME_SIZE+1] = "unit1 unit2 unit3 "; med_int ncomp2 = 3; med_int nval2 = 5; /*5 valeurs */ med_int valr2[5*3 ] = {0,1,2, 10,11,12, 20,21,22, 30,31,32, 40,41,42}; /* 3 composantes*/ med_int valr2p[3*3 ] = {0,1,2, 20,21,22, 40,41,42}; /* 3 composantes*/ /* Profils utilisés */ char nomprofil1[MED_NAME_SIZE+1] = "PROFIL(champ(1))"; char nomprofil1b[MED_NAME_SIZE+1] = "PROFIL(champ(1b))"; char nomprofil2[MED_NAME_SIZE+1] = "PROFIL(champ2)"; med_int profil1[2] = { 2, 3 }; med_int profil2[3] = { 1, 3, 5 }; /* Caractéristiques du champ n° 3 */ char nomcha3[MED_NAME_SIZE+1] = "champ entier 3"; char comp3[3*MED_SNAME_SIZE+1] = "comp1 comp2 "; /*123456789012345612345678901234561234567890123456*/ char unit3[3*MED_SNAME_SIZE+1] = "unit1 unit2 "; char dtunit[MED_SNAME_SIZE+1] = "s"; med_int ncomp3 = 2; med_int nval3 = 5*4; /*5 valeurs et 4 noeuds par element*/ med_int _nent3 = 5; /*5 valeurs et 4 noeuds par element*/ med_int valr3[5*4*2] = {0,1, 10,11, 20,21, 30,31, 40,41, 50,51, 60,61, 70,71, 80,81, 90,91, 100,101, 110,111, 120,121, 130,131, 140,141, 150,151, 160,161, 170,171, 180,181, 190,191}; /* 2 composantes*/ med_int valr3p[3*4*2] = {0,1, 10,11, 20,21, 30,31, 80,81, 90,91, 100,101, 110,111, 160,161, 170,171, 180,181, 190,191}; /* 2 composantes*/ char nomcoo[3*MED_SNAME_SIZE+1] = "x y z "; char unicoo[3*MED_SNAME_SIZE+1] = "cm cm cm "; char _maa[MED_NAME_SIZE+1]=""; char _desc[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_int _nstep=0; med_axis_type _rep; med_mesh_type _type; med_sorting_type _sort; char __dtunit [MED_SNAME_SIZE+1]=""; med_int _mdim=0,_sdim=0; med_int ncha=0; med_access_mode _accessmode; /* Il n'est pas necessaire de pré-allouer la mémoire. med-fichier s'occupe d'allouer la mémoire au fil de l'utilsation de l'API.*/ /* Attention la structure doit être initialisée à MED_MEMFILE_INIT avant toute première utilisation.*/ med_memfile memfile[1] = MED_MEMFILE_INIT; /* On décide de pré-allouer suffisement de mémoire : 10MB */ /* med-fichier utilisera l'espace réservé sans réallocation.*/ /* memfile[0].app_image_size = 10*1024*1024; */ /* memfile[0].app_image_ptr = calloc(memfile[0].app_image_size,sizeof(char)); */ /* On décide de pré-allouer insuffisement de mémoire : 1KB */ /* med-fichier utilisera l'espace réservé puis effectuera une réallocation.*/ /* memfile[0].app_image_size = 1024; */ /* memfile[0].app_image_ptr = calloc(memfile[0].app_image_size,sizeof(char)); */ AFF_MEMFILE; /* Ouverture du fichier */ /* mode RDWR uniquement si le fichier test10.med a préalablement été généré par test10 ou par le sync de test10_mem (en CREATE). Si test10.med n'existe pas et demande le mode RDWR -> erreur car nous n'avons pas initialisé une image mémoire valide ! */ _accessmode = MED_ACC_CREAT; if ((fid = MEDmemFileOpen("test10.med",memfile,MED_TRUE,_accessmode) ) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } /* Ouverture du fichier */ /* Si l'on ne veut pas créer de fichier sur disque, sync=MED_FALSE */ /* if ((fid = MEDmemFileOpen("test10.med",memfile,MED_FALSE,MED_ACC_CREAT) ) < 0){ */ /* MESSAGE("Erreur à l'ouverture du fichier : "); */ /* return -1; */ /* } */ AFF_MEMFILE; /* combien de champs dans le fichier (pour tester le fichier mémoire)*/ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); } printf("Nombre de champs : "IFORMAT" \n",ncha); if (ncha == 3 ) { /*Un quatrième champ est crée seulement si un fichier test10.med existait et mode RDWR + sync */ /* creation du champ réel n° 1 */ if ( MEDfieldCr(fid,"Ajout Complémentaire",MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE("Ajout Complémentaire"); ret = -1; }; } /* creation de maa1 de dimension 3*/ if (MEDmeshCr( fid, maa1, 3, 3, MED_UNSTRUCTURED_MESH, "Maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa1); ret = -1; } /* creation de maa3 de dimension 3*/ if (MEDmeshCr( fid, maa3, 3, 3, MED_UNSTRUCTURED_MESH, "Maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa3); ret = -1; } /* creation du champ réel n° 1 */ if ( MEDfieldCr(fid,nomcha1,MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha1); ret = -1; }; /* creation du champ entier n° 2 */ if ( MEDfieldCr(fid,nomcha2,MED_INT32,ncomp2,comp2,unit2,dtunit,maa2 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha2); ret = -1; }; /* creation du lien au fichier distant contenant maa2 */ if (MEDlinkWr(fid,maa2,lien_maa2) < 0) { MESSAGE("Erreur à la création du lien : ");SSCRUTE(lien_maa2); ret = -1; }; /* creation de la localisation des points de Gauss modèle n° 1 */ if (MEDlocalizationWr(fid, gauss1_1, MED_TRIA6, MED_TRIA6/100, refcoo1, USER_INTERLACE, ngauss1_1, gscoo1_1, wg1_1, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT ) < 0) { MESSAGE("Erreur à la création du modèle n° 1 : ");SSCRUTE(gauss1_1); ret = -1; }; /* creation de la localisation des points de Gauss modèle n° 2 */ if (MEDlocalizationWr(fid, gauss1_2, MED_TRIA6, MED_TRIA6/100, refcoo1, USER_INTERLACE, ngauss1_2, gscoo1_2, wg1_2, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) { MESSAGE("Erreur à la création du modèle n° 1 : ");SSCRUTE(gauss1_2); ret = -1; }; /* ecriture du champ n° 1*/ /* enregistre uniquement les composantes n° 2 de valr1_1, et n'utilise ni pas de temps ni n° d'ordre*/ if ( MEDfieldValueWithProfileWr(fid, nomcha1,MED_NO_DT,MED_NO_IT,0.0,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_1,USER_INTERLACE, 2, _nent1_1, (unsigned char*)valr1_1 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre uniquement les composantes n° 1 de valr1_1, et n'utilise ni pas de temps ni n° d'ordre */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,MED_NO_DT,MED_NO_IT,0.0,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_1,USER_INTERLACE, 1, _nent1_1, (unsigned char*)valr1_1 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre uniquement les composantes n° 1 de valr1_2, au pas de temps n° 1(5.5), n'utilise pas de n° d'ordre*/ /* ce champ repose sur le maillage maa2 qui est distant */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,MED_NO_IT,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_2,USER_INTERLACE, 1, _nent1_2, (unsigned char*)valr1_2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Le test initial utilisait un deuxième maillage epour un même champ et une même séquence de calcul, ceci n'existe plus en 3.0*/ /* enregistre uniquement les composantes n° 2 de valr1_2, au pas de temps n° 1(5.5), n'utilise pas de n° d'ordre*/ /* ce champ repose sur le maillage maa1 qui est local */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,1,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_1,USER_INTERLACE, 2, _nent1_1, (unsigned char*)valr1_1 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre uniquement les composantes n° 1 de valr1_1, au pas de temps n° 1(5.5), et n° d'itération n° 2*/ /* ce champ repose sur le maillage maa3 qui est local */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,2,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_2,USER_INTERLACE, 1, _nent1_2, (unsigned char*)valr1_2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Creation d'un profil (selection du deuxieme élément de valr1_1) */ /* On n'utilise que la première valeur (2) du profil */ if ( MEDprofileWr(fid,nomprofil1,1,profil1) < 0) { MESSAGE("Erreur à l'écriture du profil : "); SSCRUTE(nomprofil1); ret = -1; }; if ( MEDprofileWr(fid,nomprofil1b,1,profil1) < 0) { MESSAGE("Erreur à l'écriture du profil : "); SSCRUTE(nomprofil1b); ret = -1; }; /* enregistre toutes les composantes du deuxième élément de valr1_1 (premier élément en stockage compact de valr1p), au pas de temps n° 2(5.6), et n° d'itération n° 2*/ if ( MEDfieldValueWithProfileWr(fid, nomcha1,2,2,5.6,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1, MED_NO_LOCALIZATION,USER_INTERLACE, MED_ALL_CONSTITUENT, nval1_3, (unsigned char*)valr1_3p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre toutes les composantes du deuxième élément de valr1_1 (premier élément en stockage compact de valr1p), au pas de temps n° 2(5.6), et n° d'itération n° 2 */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,2,2,5.6,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1b, gauss1_2,USER_INTERLACE, MED_ALL_CONSTITUENT, _nent1_2, (unsigned char*)valr1_2p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWithProfileWr(fid, nomcha1,3,2,5.7,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1, MED_NO_LOCALIZATION,USER_INTERLACE, 2, _nent1_3, (unsigned char*)valr1_3p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Ecriture du champ n° 2 */ if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0, MED_DESCENDING_EDGE,MED_SEG2, USER_INTERLACE, 1, nval2, (unsigned char*)valr2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_NODE,MED_NONE, USER_INTERLACE, 2, nval2, (unsigned char*)valr2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_DESCENDING_FACE,MED_TRIA6, USER_INTERLACE, 3, nval2, (unsigned char*)valr2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Creation d'un profil (selection des éléments 1,3,5 de valr2) */ /* On utilise les trois valeurs du profil */ if ( MEDprofileWr(fid,nomprofil2,3,profil2) < 0) { MESSAGE("Erreur à l'écriture du profil : "); SSCRUTE(nomprofil2); ret = -1; }; if ( MEDfieldValueWithProfileWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_CELL,MED_TRIA6,USER_MODE,nomprofil2, MED_NO_LOCALIZATION,USER_INTERLACE, 3, nval2, (unsigned char*)valr2p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* creation du champ entier n° 3 */ if ( MEDfieldCr(fid,nomcha3,MED_INT32,ncomp3,comp3,unit3,dtunit,maa1) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha3); ret = -1; }; /* Ecriture du champ n° 3 */ if ( MEDfieldValueWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_CELL,MED_QUAD4, USER_INTERLACE, 1, nval3, (unsigned char*)valr3 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_NODE_ELEMENT,MED_QUAD4, USER_INTERLACE, MED_ALL_CONSTITUENT, _nent3, (unsigned char*)valr3 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWithProfileWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_NODE_ELEMENT,MED_QUAD4,USER_MODE,nomprofil2, MED_NO_LOCALIZATION,USER_INTERLACE, MED_ALL_CONSTITUENT, _nent3, (unsigned char*)valr3p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; AFF_MEMFILE; /* fermeture du fichier */ if ( MEDfileClose(fid) < 0 ) { ret=-1; MESSAGE("Erreur à la fermeture du fichier "); } AFF_MEMFILE; /* H5Fflush(fid, H5F_SCOPE_GLOBAL ); */ _accessmode = MED_ACC_RDWR; /*ATTENTION : Il faut au moins une écriture/création dans le fichier pour que le sync se fasse en mode RW*/ if ((fid = MEDmemFileOpen("test10_mem.med",memfile,MED_TRUE,_accessmode) ) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } AFF_MEMFILE; /* combien de champs dans le fichier (pour tester le fichier mémoire)*/ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); } printf("Nombre de champs : "IFORMAT" \n",ncha); /*Il faut une écriture pour que le sync se fasse en mode RW*/ if ( (ncha == 3) || (_accessmode == MED_ACC_RDWR) ) /* creation du champ complémentaire n° 2 */ if ( MEDfieldCr(fid,"Ajout Complémentaire 2",MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) { MESSAGE("Erreur à la création du champ : Complémentaire 2"); ret = -1; }; AFF_MEMFILE; /* 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 champs dans le fichier (pour tester le fichier mémoire)*/ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); } printf("Nombre de champs : "IFORMAT" \n",ncha); if ( MEDfileClose(fid) < 0 ) { ret=-1; MESSAGE("Erreur à la fermeture du fichier "); } AFF_MEMFILE; free(memfile[0].app_image_ptr); memfile->app_image_size =0; return ret; }