# MEDfieldCr.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  EDF R&D, CEA/DEN
    00004  *  MED is free software: you can redistribute it and/or modify
    00005  *  it under the terms of the GNU Lesser General Public License as published by
    00006  *  the Free Software Foundation, either version 3 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  MED is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Lesser General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Lesser General Public License
    00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
    00016  */
    00017
    00018
    00019 #include <med.h>
    00020 #include <med_config.h>
    00021 #include <med_outils.h>
    00022
    00023 #include <string.h>
    00024 #include <stdlib.h>
    00025
    00040 med_err
    00041 MEDfieldCr( const med_idt fid,
    00042             const char * const fieldname,
    00043             const med_field_type fieldtype,
    00044             const med_int ncomponent,
    00045             const char * const componentname,
    00046             const char * const componentunit,
    00047             const char * const dtunit,
    00048             const char * const meshname)
    00049 {
    00050   med_err _ret=-1;
    00051   med_idt _root=0,_datagroup1=0;
    00052   med_int _fieldtype = (med_int) fieldtype;
    00053   char _datagroupname1    [MED_NAME_SIZE+1]="";
    00054   med_access_mode _MED_ACCESS_MODE;
    00055
    00056  _MEDmodeErreurVerrouiller();
    00057  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00058
    00059   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00060     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00061     goto ERROR;
    00062   }
    00063
    00064   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00065     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00066     ISCRUTE_int(_MED_ACCESS_MODE);
    00067     goto ERROR;
    00068   }
    00069
    00070   /*
    00071    * Si le DataGroup MED_CHA n'existe pas, on le cree
    00072    */
    00073   if ((_root = _MEDdatagroupOuvrir(fid,MED_CHA)) < 0)
    00074     if ((_root = _MEDdatagroupCreer(fid,MED_CHA)) < 0) {
    00075      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_CHA);
    00076      goto ERROR;
    00077     }
    00078
    00079   NOFINALBLANK(fieldname,ERROR);
    00080   /*
    00081    * Si le Data Group "/CHA/<fieldname>" n'existe pas, on le cree
    00082    */
    00083   if ((_datagroup1 = _MEDdatagroupOuvrir(_root,fieldname)) < 0)
    00084     if ((_datagroup1 = _MEDdatagroupCreer(_root,fieldname)) < 0 ) {
    00085       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_CHA);
    00086       SSCRUTE(fieldname);goto ERROR;
    00087     }
    00088
    00089
    00090   /*
    00091    * Les infos sur les composantes du champ
    00092    */
    00093   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NCO,&ncomponent) < 0 ) {
    00094     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    00095     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NCO);
    00096     ISCRUTE(ncomponent);goto ERROR;
    00097   }
    00098   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_fieldtype) < 0) {
    00099     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    00100     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
    00101     ISCRUTE(_fieldtype);goto ERROR;
    00102   }
    00103   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,
    00104                             MED_SNAME_SIZE*ncomponent,componentname) < 0) {
    00105     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    00106     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
    00107     SSCRUTE(componentname);goto ERROR;
    00108   }
    00109   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,
    00110                             MED_SNAME_SIZE*ncomponent,componentunit) < 0) {
    00111     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    00112     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
    00113     SSCRUTE(componentunit);goto ERROR;
    00114   }
    00115
    00116   /*MODEL : MED_NOM_UNI vient du niveau en dessous
    00117     Cree ou ouvre l'attribut  MED_NOM_UNI pour écriture
    00118   */
    00119   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
    00120     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    00121     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
    00122     SSCRUTE(dtunit);goto ERROR;
    00123   }
    00124
    00125   /*MODEL : MED_NOM_MAI est écrit dans l'API de création de champ
    00126    * Si c'est la première référence à un maillage, initialise l'attribut MED_MAI à ce maillage
    00127    */
    00128   NOFINALBLANK(meshname,ERROR);
    00129
    00130   if (_MEDattributeStringWr(_datagroup1,MED_NOM_MAI,MED_NAME_SIZE,meshname) < 0) {
    00131     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    00132     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_MAI);
    00133     SSCRUTE(meshname);
    00134     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,meshname);
    00135     goto ERROR;
    00136   }
    00137
    00138
    00139   /*
    00140    * On ferme tout
    00141    */
    00142
    00143   _ret=0;
    00144  ERROR:
    00145
    00146   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    00147     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
    00148     ISCRUTE_id(_datagroup1);
    00149   }
    00150
    00151   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    00152     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_CHA);
    00153     ISCRUTE_id(_root);
    00154   }
    00155
    00156   return _ret;
    00157 }