MEDprofileWr.c
Aller à la documentation de ce fichier.
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2020 EDF R&D, CEA/DEN
* MED is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MED is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MED. If not, see <http://www.gnu.org/licenses/>.
*/
#include <med.h>
#include <med_config.h>
#include <med_outils.h>
#include <string.h>
#include <stdlib.h>
med_err
MEDprofileWr(const med_idt fid,
const char* const profilename,
const med_int profilesize,
const med_int* const profilearray)
{
med_access_mode _MED_ACCESS_MODE;
med_idt _root=0,_pfid=0;
med_err _ret=-1;
char _path[MED_PROFILE_GRP_SIZE+MED_NAME_SIZE+1]=MED_PROFILE_GRP;
med_filter _filter = MED_FILTER_INIT;
/*
* On inhibe le gestionnaire d'erreur
*/
_MEDmodeErreurVerrouiller();
if (_MEDcheckVersion30(fid) < 0) goto ERROR;
if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
goto ERROR;
}
if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
ISCRUTE_int(_MED_ACCESS_MODE);
goto ERROR;
}
/*
* Si le DataGroup /PROFILS/ n'existe pas, on le cree
*/
if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
goto ERROR;
}
NOFINALBLANK(profilename,ERROR);
/*
* Si le DataGroup /PROFILS/<profilename> n'existe pas, on le cree
*/
if ((_pfid = _MEDdatagroupOuvrir(_root,profilename)) < 0)
if ((_pfid = _MEDdatagroupCreer(_root,profilename)) < 0) {
MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,profilename);
SSCRUTE(_path);goto ERROR;
}
strcat(_path,profilename);
/*
* On stocke "profilesize" sous forme d'attribut
*/
if (_MEDattributeIntWr(_pfid,MED_NOM_NBR,&profilesize) < 0) {
MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PROFILE_MSG);
SSCRUTE(profilename);SSCRUTE(MED_NOM_NBR);ISCRUTE(profilesize);
goto ERROR;
}
/*
* On stocke le profil dans un dataset
*/
if ( MEDfilterEntityCr(fid, profilesize, 1, 1, MED_ALL_CONSTITUENT,
MED_NO_INTERLACE,MED_UNDEF_STMODE,
MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
goto ERROR;
}
if ( _MEDdatasetWr(_pfid,MED_NOM_PFL,MED_INTERNAL_INT,&_filter, profilearray) < 0) {
MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_PFL);SSCRUTE(_path);
goto ERROR;
}
if ( MEDfilterClose(&_filter) < 0 ) {
MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_PROFILE_MSG); SSCRUTE(_path);
goto ERROR;
}
_ret = 0;
ERROR:
if (_pfid>0) if (_MEDdatagroupFermer(_pfid) < 0) {
MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,profilename);
ISCRUTE_id(_pfid);
}
if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_PROFILE_GRP);
ISCRUTE_id(_root);
}
return _ret;
}
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition build.python3.12/include/med.h:81
MED_NO_INTERLACE
@ MED_NO_INTERLACE
Definition build.python3.12/include/med.h:98
MED_FILTER_INIT
#define MED_FILTER_INIT
Definition build.python3.12/include/med.h:365
MED_UNDEF_STMODE
@ MED_UNDEF_STMODE
Definition build.python3.12/include/med.h:108
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition build.python3.12/include/med.h:293
med_int
int med_int
Definition build.python3.12/include/med.h:333
MED_UNDEF_SIZE
#define MED_UNDEF_SIZE
Definition build.python3.12/include/med.h:297
MED_INTERNAL_INT
@ MED_INTERNAL_INT
Definition build.python3.12/include/med.h:158
MED_NO_PROFILE
#define MED_NO_PROFILE
Definition build.python3.12/include/med.h:279
med_err
herr_t med_err
Definition build.python3.12/include/med.h:323
med_access_mode
med_access_mode
Definition build.python3.12/include/med.h:120
MED_ACC_UNDEF
@ MED_ACC_UNDEF
Definition build.python3.12/include/med.h:124
MED_ACC_RDONLY
@ MED_ACC_RDONLY
Definition build.python3.12/include/med.h:120
med_idt
hid_t med_idt
Definition build.python3.12/include/med.h:322
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition build.python3.12/include/med_utils.h:160
SSCRUTE
#define SSCRUTE(chaine)
Definition build.python3.12/include/med_utils.h:323
ISCRUTE
#define ISCRUTE(entier)
Definition build.python3.12/include/med_utils.h:313
ISCRUTE_id
#define ISCRUTE_id(entier)
Definition build.python3.12/include/med_utils.h:319
NOFINALBLANK
#define NOFINALBLANK(chaine, label)
Definition build.python3.12/include/med_utils.h:311
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition build.python3.12/include/med_utils.h:314
MEDfilterClose
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
Definition MEDfilterClose.c:35
MEDfilterEntityCr
MEDC_EXPORT med_err MEDfilterEntityCr(const med_idt fid, const med_int nentity, const med_int nvaluesperentity, const med_int nconstituentpervalue, const med_int constituentselect, const med_switch_mode switchmode, const med_storage_mode storagemode, const char *const profilename, const med_int filterarraysize, const med_int *const filterarray, med_filter *const filter)
Definition MEDfilterEntityCr.c:55
MEDprofileWr
med_err MEDprofileWr(const med_idt fid, const char *const profilename, const med_int profilesize, const med_int *const profilearray)
Cette routine permet d'écrire un profil dans un fichier MED.
Definition MEDprofileWr.c:40
MED_ERR_ACCESSMODE
#define MED_ERR_ACCESSMODE
Definition med_err.h:104
MED_ERR_FILTER
#define MED_ERR_FILTER
Definition med_err.h:93
MED_ERR_DATAGROUP
#define MED_ERR_DATAGROUP
Definition med_err.h:99
MED_ERR_CLOSE
#define MED_ERR_CLOSE
Definition med_err.h:30
MED_ERR_INVALID
#define MED_ERR_INVALID
Definition med_err.h:40
MED_ERR_ATTRIBUTE
#define MED_ERR_ATTRIBUTE
Definition med_err.h:100
MED_ERR_CREATE
#define MED_ERR_CREATE
Definition med_err.h:27
MED_ERR_INTERNAL_MSG
#define MED_ERR_INTERNAL_MSG
Definition med_err.h:196
MED_ERR_PROFILE_MSG
#define MED_ERR_PROFILE_MSG
Definition med_err.h:144
MED_ERR_FILE_MSG
#define MED_ERR_FILE_MSG
Definition med_err.h:132
MED_ERR_WRITE
#define MED_ERR_WRITE
Definition med_err.h:29
MED_ERR_UNRECOGNIZED
#define MED_ERR_UNRECOGNIZED
Definition med_err.h:39
MED_ERR_DATASET
#define MED_ERR_DATASET
Definition med_err.h:98
_MEDdatasetWr
MEDC_EXPORT med_err _MEDdatasetWr(const med_idt id, const char *const datasetname, const med_internal_type datatype, const med_filter *const filter, const void *const value)
_MEDdatagroupCreer
MEDC_EXPORT med_idt _MEDdatagroupCreer(med_idt pid, const char *const nom)
_MEDattributeIntWr
#define _MEDattributeIntWr(w, x, y)
Definition med_hdfi.h:45
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
_MEDdatagroupFermer
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
_MEDdatagroupOuvrir
MEDC_EXPORT med_idt _MEDdatagroupOuvrir(med_idt pid, const char *const nom)
_MEDcheckVersion30
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
_MEDmodeAcces
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
MED_PROFILE_GRP
#define MED_PROFILE_GRP
Definition med_outils.h:233
MED_NOM_PFL
#define MED_NOM_PFL
Definition med_outils.h:140
MED_NOM_NBR
#define MED_NOM_NBR
Definition med_outils.h:40
MED_PROFILE_GRP_SIZE
#define MED_PROFILE_GRP_SIZE
Definition med_outils.h:234
med_outils.h
med_filter
Filtre de sélection.
Definition build.python3.12/include/med.h:346