MEDprofileWr.c
Aller à la documentation de ce fichier.
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2021 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_ERR_CREATE
#define MED_ERR_CREATE
Definition: med_err.h:27
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
_MEDdatagroupFermer
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
med_filter
Filtre de sélection.
Definition: med.h:355
MED_FILTER_INIT
#define MED_FILTER_INIT
Definition: med.h:374
ISCRUTE_id
#define ISCRUTE_id(entier)
Definition: med_utils.h:319
MED_PROFILE_GRP_SIZE
#define MED_PROFILE_GRP_SIZE
Definition: med_outils.h:234
MED_UNDEF_SIZE
#define MED_UNDEF_SIZE
Definition: med.h:306
_MEDmodeAcces
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
med_idt
hid_t med_idt
Definition: med.h:331
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
_MEDattributeIntWr
#define _MEDattributeIntWr(w, x, y)
Definition: med_hdfi.h:45
MED_ACC_RDONLY
Definition: med.h:120
MED_ERR_INVALID
#define MED_ERR_INVALID
Definition: med_err.h:40
MED_UNDEF_STMODE
Definition: med.h:108
MED_ERR_ATTRIBUTE
#define MED_ERR_ATTRIBUTE
Definition: med_err.h:100
med_err
herr_t med_err
Definition: med.h:332
_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)
MED_ERR_CLOSE
#define MED_ERR_CLOSE
Definition: med_err.h:30
MED_ERR_FILTER
#define MED_ERR_FILTER
Definition: med_err.h:93
med_int
int med_int
Definition: med.h:342
MED_ERR_WRITE
#define MED_ERR_WRITE
Definition: med_err.h:29
med.h
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
med_access_mode
med_access_mode
Definition: med.h:120
MEDfilterClose
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
Definition: MEDfilterClose.c:35
MED_INTERNAL_INT
Definition: med.h:158
MED_ERR_INTERNAL_MSG
#define MED_ERR_INTERNAL_MSG
Definition: med_err.h:196
MED_ERR_ACCESSMODE
#define MED_ERR_ACCESSMODE
Definition: med_err.h:104
_MEDdatagroupCreer
MEDC_EXPORT med_idt _MEDdatagroupCreer(med_idt pid, const char *const nom)
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MED_ERR_DATASET
#define MED_ERR_DATASET
Definition: med_err.h:98
MED_ERR_DATAGROUP
#define MED_ERR_DATAGROUP
Definition: med_err.h:99
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_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
_MEDcheckVersion30
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
med_outils.h
MED_PROFILE_GRP
#define MED_PROFILE_GRP
Definition: med_outils.h:233
med_config.h
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:299
MED_ERR_PROFILE_MSG
#define MED_ERR_PROFILE_MSG
Definition: med_err.h:144
MED_NOM_PFL
#define MED_NOM_PFL
Definition: med_outils.h:140
MED_NO_PROFILE
#define MED_NO_PROFILE
Definition: med.h:281
MED_NO_INTERLACE
Definition: med.h:98
MED_NOM_NBR
#define MED_NOM_NBR
Definition: med_outils.h:40
NOFINALBLANK
#define NOFINALBLANK(chaine, label)
Definition: med_utils.h:311
MED_ERR_UNRECOGNIZED
#define MED_ERR_UNRECOGNIZED
Definition: med_err.h:39
MED_ERR_FILE_MSG
#define MED_ERR_FILE_MSG
Definition: med_err.h:132
_MEDdatagroupOuvrir
MEDC_EXPORT med_idt _MEDdatagroupOuvrir(med_idt pid, const char *const nom)
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
MED_ACC_UNDEF
Definition: med.h:124