Пример #1
0
/*
 * Test nc_open.
 * If in read-only section of tests,
 *    Try to open a non-existent netCDF file, check error return.
 *    Open a file that is not a netCDF file, check error return.
 *    Open a netCDF file with a bad mode argument, check error return.
 *    Open a netCDF file with NC_NOWRITE mode, try to write, check error.
 *    Try to open a netcdf twice, check whether returned netcdf ids different.
 * If in writable section of tests,
 *    Open a netCDF file with NC_WRITE mode, write something, close it.
 * On exit, any open netCDF files are closed.
 */
void
test_nc_open(void)
{
    int err;
    int ncid;
    int ncid2;

    /* Try to open a nonexistent file */
    err = nc_open("tooth-fairy.nc", NC_NOWRITE, &ncid);/* should fail */
    IF (err == NC_NOERR)
	error("nc_open of nonexistent file should have failed");
#ifndef USE_PARALLEL
    IF (! NC_ISSYSERR(err))
	error("nc_open of nonexistent file should have returned system error");
#endif

    /* Open a file that is not a netCDF file.  But need a portable
     * test that also works for cross-compiles ... */
    /* err = nc_open("nc_test.o", NC_NOWRITE, &ncid);/\* should fail *\/ */
    /* IF (err != NC_ENOTNC) */
    /* 	error("nc_open of non-netCDF file: status = %d", err); */

    /* Open a netCDF file in read-only mode, check that write fails */
    err = nc_open(testfile, NC_NOWRITE, &ncid);
    IF (err)
	error("nc_open: %s", nc_strerror(err));
    err = nc_redef(ncid);	/* should fail */
    IF (err != NC_EPERM)
	error("nc_redef of read-only file should fail");
    /* Opened OK, see if can open again and get a different netCDF ID */
    err = nc_open(testfile, NC_NOWRITE, &ncid2);
    IF (err)
	error("nc_open: %s", nc_strerror(err));
    else {
Пример #2
0
Файл: ncdf.c Проект: cran/ncdf
void R_nc_redef( int *ncid )
{
	int	err;
	err = nc_redef(*ncid);
	if( err != NC_NOERR ) 
		REprintf( "Error in R_nc_redef: %s\n", 
			nc_strerror(err) );
}
Пример #3
0
/* This internal function adds a new user defined type to the metadata
 * of a group of an open file. */
static int
add_user_type(int ncid, size_t size, const char *name, nc_type base_typeid,
	      nc_type type_class, nc_type *typeidp)
{
   NC_HDF5_FILE_INFO_T *h5;
   NC_GRP_INFO_T *grp;
   char norm_name[NC_MAX_NAME + 1];
   int retval;

   /* Check and normalize the name. */
   if ((retval = nc4_check_name(name, norm_name)))
      return retval;

   LOG((2, "add_user_type: ncid 0x%x size %d name %s base_typeid %d ", 
	ncid, size, norm_name, base_typeid));

   /* Find group metadata. */
   if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
      return retval;

   /* Only netcdf-4 files! */
   if (!h5)
      return NC_ENOTNC4;

   /* Turn on define mode if it is not on. */
   if (!(h5->cmode & NC_INDEF))
      if ((retval = nc_redef(ncid)))
	 return retval;

   /* No size is provided for vlens or enums, get it from the base type. */
   if (type_class == NC_VLEN || type_class == NC_ENUM)
   {
      if ((retval = nc4_get_typelen_mem(grp->file->nc4_info, base_typeid, 0, 
					&size)))
	 return retval;
   }
   else if (size <= 0)
      return NC_EINVAL;

   /* Check that this name is not in use as a var, grp, or type. */
   if ((retval = nc4_check_dup_name(grp, norm_name)))
      return retval;
   
   /* Add to our list of types. */
   if ((retval = nc4_type_list_add(&(grp->type), grp->file->nc4_info->next_typeid, 
				   size, norm_name, type_class, base_typeid)))
      return retval;
   
   /* Return the typeid to the user. */
   if (typeidp)
      *typeidp = grp->file->nc4_info->next_typeid;

   grp->file->nc4_info->next_typeid++;

   return NC_NOERR;
}
Пример #4
0
int ncd_wdset(int ncid,char *path,char *name, void *val,  \
              enum ADIOS_TYPES type, int rank,              \
              struct adios_bp_dimension_struct *dims)
{
  int i,valid,retval;
  char fullname[100];
  char dimname[100];
  fullname[0]='\0';
  char *result=NULL; 
  int dimids[2];
  dimids[1]=0;

  strcpy(fullname,name);
  if(start[0]==0)
  {
     retval=nc_redef(ncid);
     sprintf(dimname,"%s_%d",name,0);
     retval=nc_inq_unlimdim(ncid,&dimids[1]);
     if(dimids[1]==-1)retval=nc_def_dim(ncid,"timesteps",NC_UNLIMITED,&dimids[0]);
     retval=nc_def_dim(ncid,dimname,dims[0].local_bound,&dimids[1]);
     if(type==adios_real)
        retval=nc_def_var(ncid,fullname,NC_FLOAT,2,dimids,&valid);
     if(type==adios_integer)
        retval=nc_def_var(ncid,fullname,NC_INT,2,dimids,&valid);
     if(type==adios_long)
        retval=nc_def_var(ncid,fullname,NC_LONG,2,dimids,&valid);
     if(type==adios_double)
     {
        retval=nc_def_var(ncid,fullname,NC_DOUBLE,2,dimids,&valid);
        ERR(retval);
     }
     //printf("\t RANK=%d, DIMS:%s[0]=%d dimids[1]=%d\n",rank,dimname,dims[0].local_bound,dimids[1]);
     retval=nc_enddef(ncid);
  }
  else
     retval=nc_inq_varid (ncid, fullname, &valid);
  
  start[1]=0;//dims[0].local_bound;
  count[0]=1;
  count[1]=dims[0].local_bound;

  if(type==adios_double)
     retval=nc_put_vara_double(ncid,valid,start,count,val);
  if(type==adios_real)
     retval=nc_put_vara_float(ncid,valid,start,count,val);
  if(type==adios_integer)
     retval=nc_put_vara_int(ncid,valid,start,count,val);
  if(type==adios_long)
     retval=nc_put_vara_long(ncid,valid,start,count,val);
//#if DEBUG
  //printf("create dataset:%s\n",fullname);
  //printf("start:%dx%d. count:%dx%d\n",start[0],start[1],count[0],count[1]);
  //printf("-------------------\n");
//#endif
  return;
}
Пример #5
0
Файл: v2i.c Проект: stcorp/harp
int
ncredef(int ncid)
{
	const int status =  nc_redef(ncid);
	if(status != NC_NOERR)
	{
		nc_advise("ncredef", status, "ncid %d", ncid);
		return -1;
	}
	return 0;
}
Пример #6
0
void bi::SMCNetCDFBuffer::create() {
  nc_redef(ncid);

  nc_put_att(ncid, "libbi_schema", "SMC");
  nc_put_att(ncid, "libbi_schema_version", 1);
  nc_put_att(ncid, "libbi_version", PACKAGE_VERSION);

  lwVar = nc_def_var(ncid, "logweight", NC_REAL, npDim);

  nc_enddef(ncid);
}
Пример #7
0
/* Test a small file with two record vars, which grow, and has
 * attributes added. */
static int
test_two_growing_with_att(const char *testfile)
{
   int ncid, dimid, varid[NUM_VARS];
   char data[MAX_RECS], data_in;
   char att_name[NC_MAX_NAME + 1];
   size_t start[ONE_DIM], count[ONE_DIM], index[ONE_DIM], len_in;
   int v, r;

   /* Create a file with one ulimited dimensions, and one var. */
   if (nc_create(testfile, NC_CLOBBER, &ncid)) ERR;
   if (nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid)) ERR;
   if (nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid[0])) ERR;
   if (nc_def_var(ncid, VAR_NAME2, NC_CHAR, 1, &dimid, &varid[1])) ERR;
   if (nc_close(ncid)) ERR;

   /* Create some phoney data. */
   for (data[0] = 'a', r = 1; r < MAX_RECS; r++)
      data[r] = data[r - 1] + 1;

   /* Normally one would not close and reopen the file for each
    * record, nor add an attribute each time I add a record, but I am
    * giving the library a little work-out here... */
   for (r = 0; r < MAX_RECS; r++)
   {
      /* Write one record of var data, a single character. */
      if (nc_open(testfile, NC_WRITE, &ncid)) ERR;
      count[0] = 1;
      start[0] = r;
      sprintf(att_name, "a_%d", data[r]);
      for (v = 0; v < NUM_VARS; v++)
      {
	 if (nc_put_vara_text(ncid, varid[v], start, count, &data[r])) ERR;
	 if (nc_redef(ncid)) ERR;
	 if (nc_put_att_text(ncid, varid[v], att_name, 1, &data[r])) ERR;
	 if (nc_enddef(ncid)) ERR;
      }
      if (nc_close(ncid)) ERR;
      
      /* Reopen the file and check it. */
      if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq_dimlen(ncid, 0, &len_in)) ERR;
      if (len_in != r + 1) ERR;
      index[0] = r;
      for (v = 0; v < NUM_VARS; v++)
      {
	 if (nc_get_var1_text(ncid, varid[v], index, &data_in)) ERR;
	 if (data_in != data[r]) ERR;
      }
      if (nc_close(ncid)) ERR; 
   } /* Next record. */
   return 0;
}
void bi::OptimiserNetCDFBuffer::create() {
    nc_redef(ncid);

    nc_put_att(ncid, "libbi_schema", "Optimiser");
    nc_put_att(ncid, "libbi_schema_version", 2);
    nc_put_att(ncid, "libbi_version", PACKAGE_VERSION);

    valueVar = nc_def_var(ncid, "optimiser.value", NC_REAL, npDim);
    sizeVar = nc_def_var(ncid, "optimiser.size", NC_REAL, npDim);

    nc_enddef(ncid);
}
Пример #9
0
void bi::MCMCNetCDFBuffer::create() {
  nc_redef(ncid);

  nc_put_att(ncid, "libbi_schema", "MCMC");
  nc_put_att(ncid, "libbi_schema_version", 1);
  nc_put_att(ncid, "libbi_version", PACKAGE_VERSION);

  llVar = nc_def_var(ncid, "loglikelihood", NC_REAL, npDim);
  lpVar = nc_def_var(ncid, "logprior", NC_REAL, npDim);

  nc_enddef(ncid);
}
Пример #10
0
NcBool NcFile::define_mode( void )
{
    if (! is_valid())
      return FALSE;
    if (in_define_mode)
      return TRUE;
    if (NcError::set_err(
			 nc_redef(the_id)
			 ) != NC_NOERR)
      return FALSE;
    in_define_mode = 1;
    return TRUE;
}
Пример #11
0
/*********************************************************************
   void mpp_redef(int fid) 
   redef the meta data of netcdf file with fid.
 *******************************************************************/
void mpp_redef(int fid) {
  int status;
  char errmsg[512];
  
  if( mpp_pe() != mpp_root_pe() ) return;
  if(fid<0 || fid >=nfiles) mpp_error("mpp_io(mpp_redef): invalid fid number, fid should be "
				      "a nonnegative integer that less than nfiles");
  
  status = nc_redef(files[fid].ncid);
  if(status != NC_NOERR) {
    sprintf(errmsg, "mpp_io(mpp_redef): Error in redef the meta data of file %s", files[fid].name );
    netcdf_error(errmsg, status);
  }
} /* mpp_redef */
Пример #12
0
//-------------------------------------------------------------------------
// Function to set the netCDF file to be in define mode or data mode
//-------------------------------------------------------------------------
void SetFileState(NcFile* nc,State s)
{
   switch(s)
   {
   case DATA:
      try{ncCheck(nc_enddef(nc->getId()),(char*)__FILE__,__LINE__);}
      catch(netCDF::exceptions::NcNotInDefineMode){std::cout<<"Already in data mode"<<std::endl;}
      break;
   case DEFINE:
      try{ncCheck(nc_redef(nc->getId()),(char*)__FILE__,__LINE__);}
      catch(netCDF::exceptions::NcInDefineMode){std::cout<<"Already in define mode."<<std::endl;}
      break;
   }
}
Пример #13
0
NCstate NCdataSetTextAttribute(int ncid, int varid, const char *attName, const char *text) {
    int status;
    bool redef;


    redef = nc_redef(ncid) == NC_NOERR ? true : false;

    status = nc_put_att_text(ncid, varid, attName, strlen(text) + 1, text);
    if (redef) nc_enddef(ncid);
    if (status != NC_NOERR) {
        NCprintNCError (status, "NCdataSetTextAttribute");
        return (NCfailed);
    }
    return (NCsucceeded);
}
Пример #14
0
/*!
This function put a netcdf file into define mode, given its id
\param [in] ncId id of the opening netcdf file to be put into define mode
\return Status code
*/
int CNetCdfInterface::reDef(int ncId)
{
  int status = nc_redef(ncId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;
    sstr << "Error when calling function nc_redef(ncId)" << std::endl
      << errormsg << std::endl
      << "Unable to put this file into define mode given its id: " << ncId << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
Пример #15
0
int ncd_attr_str_ds (int ncid, char *path, char *name, void *val)
{
    int valid,retval;
    char *text=(char *)val;
    retval=nc_redef(ncid);
    retval=nc_inq_varid(ncid,path,&valid);
    //printf("varname=%s, valid=%d\n",path,valid);
    if(valid>0)
    {
       retval=nc_put_att_text(ncid,valid,name,strlen(text),text);
       ERR(retval);
       printf("varname=%s, valid=%d text=%s len=%d\n",path,valid,text,strlen(text));
    }
    retval=nc_enddef(ncid);
    return 0;
} 
Пример #16
0
NCstate NCdataCopyAttributes(int inNCid, int inVarid, int outNCid, int outVarid, bool overwrite) {
    bool redef;
    int status, att = 0, attId;
    char attName[NC_MAX_NAME];

    redef = nc_redef(outNCid) == NC_NOERR;
    while ((status = nc_inq_attname(inNCid, inVarid, att++, attName)) == NC_NOERR) {
        if (overwrite || (nc_inq_attid(outNCid, outVarid, attName, &attId) != NC_NOERR)) {
            if ((status = nc_copy_att(inNCid, inVarid, attName, outNCid, outVarid)) != NC_NOERR) {
                NCprintNCError (status, "_NCdataCopyAttributes");
                return (NCfailed);
            }
        }
    }
    if (redef) nc_enddef(outNCid);
    return (NCsucceeded);
}
Пример #17
0
/* Test a diskless file with two record vars, which grow, and has
 * attributes added. */
static int
test_two_growing_with_att(const char *testfile)
{
   int ncid, dimid, varid[NUM_VARS];
   char data[MAX_RECS], data_in;
   char att_name[NC_MAX_NAME + 1];
   size_t start[ONE_DIM], count[ONE_DIM], index[ONE_DIM], len_in;
   int v, r;

   /* Create a file with one ulimited dimensions, and one var. */
   if((status=nc_create(testfile, diskmode|NC_CLOBBER, &ncid))) ERRSTAT(status);
   if((status=nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid))) ERRSTAT(status);
   if((status=nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid[0]))) ERRSTAT(status);
   if((status=nc_def_var(ncid, VAR_NAME2, NC_CHAR, 1, &dimid, &varid[1]))) ERRSTAT(status);
   if((status=nc_enddef(ncid))) ERRSTAT(status);

   /* Create some phoney data. */
   for (data[0] = 'a', r = 1; r < MAX_RECS; r++)
      data[r] = data[r - 1] + 1;

   for (r = 0; r < MAX_RECS; r++)
   {
      count[0] = 1;
      start[0] = r;
      sprintf(att_name, "a_%d", data[r]);
      for (v = 0; v < NUM_VARS; v++)
      {
	 if((status=nc_put_vara_text(ncid, varid[v], start, count, &data[r]))) ERRSTAT(status);
	 if((status=nc_redef(ncid))) ERRSTAT(status);
	 if((status=nc_put_att_text(ncid, varid[v], att_name, 1, &data[r]))) ERRSTAT(status);
	 if((status=nc_enddef(ncid))) ERRSTAT(status);
      }

      /* verify */
      if((status=nc_inq_dimlen(ncid, 0, &len_in))) ERRSTAT(status);
      if (len_in != r + 1) ERR;
      index[0] = r;
      for (v = 0; v < NUM_VARS; v++)
      {
	 if((status=nc_get_var1_text(ncid, varid[v], index, &data_in))) ERRSTAT(status);
	 if (data_in != data[r]) ERR;
      }
   } /* Next record. */
  if((status=nc_close(ncid))) ERRSTAT(status);
   return 0;
}
Пример #18
0
/* Create a group. It's ncid is returned in the new_ncid pointer. */
int
nc_def_grp(int parent_ncid, const char *name, int *new_ncid)
{
   NC_GRP_INFO_T *grp, *g;
   NC_HDF5_FILE_INFO_T *h5;
   char norm_name[NC_MAX_NAME + 1];
   int retval;

   LOG((2, "nc_def_grp: parent_ncid 0x%x name %s", parent_ncid, name));

   /* Find info for this file and group, and set pointer to each. */
   if ((retval = nc4_find_grp_h5(parent_ncid, &grp, &h5)))
      return retval;
   if (!h5)
      return NC_ENOTNC4;

   /* Check and normalize the name. */
   if ((retval = nc4_check_name(name, norm_name)))
      return retval;

   /* Check that this name is not in use as a var, grp, or type. */
   if ((retval = nc4_check_dup_name(grp, norm_name)))
      return retval;

   /* No groups in netcdf-3! */
   if (h5->cmode & NC_CLASSIC_MODEL)
      return NC_ESTRICTNC3;

   /* If it's not in define mode, switch to define mode. */
   if (!(h5->flags & NC_INDEF))
      if ((retval = nc_redef(parent_ncid)))
	 return retval;

   /* Update internal lists to reflect new group. The actual HDF5
    * group creation will be done when metadata is written by a
    * sync. */
   if ((retval = nc4_grp_list_add(&(grp->children), h5->next_nc_grpid, 
				  grp, grp->file, norm_name, &g)))
      return retval;
   if (new_ncid)
      *new_ncid = grp->file->ext_ncid | h5->next_nc_grpid;
   h5->next_nc_grpid++;
   
   return NC_NOERR;
}
Пример #19
0
int ncd_wscalar(int ncid,char *path,char *name, void *val,  \
              enum ADIOS_TYPES type)
{
  int i,valid,retval;
  char fullname[100];
  char dimname[100];
  fullname[0]='\0';
  char *result=NULL; 
  int dimids[1];
  dimids[0]=0;

  strcpy(fullname,name);
  if(start[0]==0)
  {
     retval=nc_redef(ncid);
     sprintf(dimname,"%s_%d",name,0);
     retval=nc_inq_unlimdim(ncid,&dimids[0]);

     if(dimids[0]==-1)retval=nc_def_dim(ncid,"timesteps",NC_UNLIMITED,&dimids[0]);
    
     if(type==adios_real)
        retval=nc_def_var(ncid,fullname,NC_FLOAT,1,dimids,&valid);
     else if(type==adios_double)
        retval=nc_def_var(ncid,fullname,NC_DOUBLE,1,dimids,&valid);
     else if(type==adios_integer)
        retval=nc_def_var(ncid,fullname,NC_INT,1,dimids,&valid);
     else if(type==adios_long)
        retval=nc_def_var(ncid,fullname,NC_LONG,1,dimids,&valid);
     retval=nc_enddef(ncid);
  }
  else
     retval=nc_inq_varid (ncid, fullname, &valid);
  if(type==adios_real)
     retval=nc_put_vara_float(ncid,valid,start_scalar,count_scalar,val);
  else if(type==bp_double)
     retval=nc_put_vara_double(ncid,valid,start_scalar,count_scalar,val);
  else if(type==adios_integer)
     retval=nc_put_vara_int(ncid,valid,start_scalar,count_scalar,val);
  else if(type==adios_long)
     retval=nc_put_vara_long(ncid,valid,start_scalar,count_scalar,val);
  ERR(retval);
  return 0;
}
Пример #20
0
int ex_create_group (int parent_id, const char *group_name)
{
  int exoid = -1;
  int status;
  char errmsg[MAX_ERR_LENGTH];
   
  exerrval = 0; /* clear error code */

#if defined(NOT_NETCDF4)
  exerrval = NC_ENOTNC4;
  sprintf(errmsg,
	  "Error: Group capabilities are not available in this netcdf version--not netcdf4");
  ex_err("ex_create_group",errmsg,exerrval);
  return (EX_FATAL);
#else
  if ((status = nc_redef (parent_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to put file id %d into define mode", parent_id);
    ex_err("ex_create_group",errmsg,exerrval);
    return (EX_FATAL);
  }
  
  if ((status = nc_def_grp (parent_id, group_name, &exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
    "Error: group create failed for %s in file id %d",
      group_name, parent_id);
    ex_err("ex_create_group",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_enddef (parent_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d", exoid);
    ex_err("ex_create",errmsg,exerrval);
    return (EX_FATAL);
  }
#endif
  return (exoid);
}
Пример #21
0
int ncd_wdset1(int ncid,char *path,char *name, void *val,  \
              enum ADIOS_TYPES type, int rank,              \
              struct adios_bp_dimension_struct *dims)
{
  int i,valid,retval;
  char fullname[100];
  char dimname[100];
  fullname[0]='\0';
  char *result=NULL; 
  int dimids[1];

  strcpy(fullname,name);
  retval=nc_redef(ncid);
  sprintf(dimname,"%s_%d",name,0);
  retval=nc_def_dim(ncid,dimname,dims[0].local_bound,&dimids[1]);
  if(type==adios_real)
     retval=nc_def_var(ncid,fullname,NC_FLOAT,1,dimids,&valid);
  if(type==adios_integer)
        retval=nc_def_var(ncid,fullname,NC_INT,1,dimids,&valid);
  if(type==adios_long)
        retval=nc_def_var(ncid,fullname,NC_LONG,1,dimids,&valid);
  if(type==adios_double)
  {
        retval=nc_def_var(ncid,fullname,NC_DOUBLE,1,dimids,&valid);
        ERR(retval);
  }
  retval=nc_enddef(ncid);
  size_t a[1],b[1];
  a[0]=0;
  b[0]=dims[0].local_bound; 
  if(type==adios_double)
     retval=nc_put_vara_double(ncid,valid,a,b,val);
  if(type==adios_real)
     retval=nc_put_vara_float(ncid,valid,a,b,val);
  if(type==adios_integer)
     retval=nc_put_vara_int(ncid,valid,a,b,val);
  if(type==adios_long)
     retval=nc_put_vara_long(ncid,valid,a,b,val);
  return;
}
Пример #22
0
      virtual void serialize(const PropertyBag &v) 
      {
        int retval;

        /**
         * Check if the netcdf file is already in define mode.
         * Increase counter every time serialize function is called and no errors occurs.
         */
        if ( ncopen ) {
          ncopen++;
        }
        else {
          retval = nc_redef(ncid);
           if ( retval )
             log(Error) << "Could not enter define mode in NetcdfHeaderMarshaller, error "<< retval <<endlog();
           else
             ncopen++;
        }
        
        for (
          PropertyBag::const_iterator i = v.getProperties().begin();
          i != v.getProperties().end();
          i++ )
            {                 
              this->serialize(*i);
            }

        /**
         * Decrease counter, if zero enter data mode else stay in define mode 
         */
        if (--ncopen)
          log(Info) << "Serializer still in progress" <<endlog();
        else {
          retval = nc_enddef(ncid);
           if (retval)
             log(Error) << "Could not leave define mode, error" << retval <<endlog();
        }
      }
Пример #23
0
// NetcdfFile::NC_createReservoir()
int NetcdfFile::NC_createReservoir(bool hasBins, double reservoirT, int iseed,
                                   int& eptotVID, int& binsVID)
{
    int dimensionID[1];
    dimensionID[0] = frameDID_;
    if (ncid_ == -1 || dimensionID[0] == -1) return 1;
    // Place file back in define mode
    if ( checkNCerr( nc_redef( ncid_ ) ) ) return 1;
    // Define eptot, bins, temp0
    if ( checkNCerr( nc_def_var(ncid_, NCEPTOT, NC_DOUBLE, 1, dimensionID, &eptotVID)) ) {
        mprinterr("Error: defining eptot variable ID.\n");
        return 1;
    }
    if (hasBins) {
        if ( checkNCerr( nc_def_var(ncid_, NCBINS, NC_INT, 1, dimensionID, &binsVID)) ) {
            mprinterr("Error: defining bins variable ID.\n");
            return 1;
        }
    } else
        binsVID = -1;
    if (NC_defineTemperature(dimensionID, 0)) return 1;
    // Random seed, make global
    if ( checkNCerr( nc_put_att_int(ncid_, NC_GLOBAL, "iseed", NC_INT, 1, &iseed) ) ) {
        mprinterr("Error: setting random seed attribute.\n");
        return 1;
    }
    // End definitions
    if (checkNCerr(nc_enddef(ncid_))) {
        mprinterr("NetCDF error on ending definitions.");
        return 1;
    }
    // Write temperature
    if (checkNCerr(nc_put_var_double(ncid_,TempVID_,&reservoirT)) ) {
        mprinterr("Error: Writing reservoir temperature.\n");
        return 1;
    }
    return 0;
}
Пример #24
0
void bi::ParticleFilterNetCDFBuffer::create() {
  nc_redef(ncid);

  if (schema == FLEXI) {
    nc_put_att(ncid, "libbi_schema", "FlexiParticleFilter");
    nc_put_att(ncid, "libbi_schema_version", 1);
  } else {
    nc_put_att(ncid, "libbi_schema", "ParticleFilter");
    nc_put_att(ncid, "libbi_schema_version", 1);
  }
  nc_put_att(ncid, "libbi_version", PACKAGE_VERSION);

  if (schema == FLEXI) {
    aVar = nc_def_var(ncid, "ancestor", NC_INT, nrpDim);
    lwVar = nc_def_var(ncid, "logweight", NC_REAL, nrpDim);
  } else {
    aVar = nc_def_var(ncid, "ancestor", NC_INT, nrDim, npDim);
    lwVar = nc_def_var(ncid, "logweight", NC_REAL, nrDim, npDim);
  }
  llVar = nc_def_var(ncid, "loglikelihood", NC_REAL);

  nc_enddef(ncid);
}
Пример #25
0
NCstate NCtableCommitField (int ncid, char *tablename, NCfield_t *field)
{
	int status, dimid, varid;

	if (nc_inq_varid(ncid,field->Name,&varid) != NC_NOERR)
	{
		if(field->Len > 1) return (NCfailed);
		if((status = nc_inq_dimid(ncid,tablename,&dimid)) != NC_NOERR)
		{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
		if((status = nc_redef(ncid) != NC_NOERR))
		{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
		if ((status = nc_def_var(ncid,field->Name,field->Type,1,&dimid,&varid)) != NC_NOERR)
		{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
		if((status = nc_enddef(ncid) != NC_NOERR))
		{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
	}
	switch (field->Type)
	{
		default:
		case NC_CHAR:
			if((status = nc_put_var_text(ncid,varid,(char *) field->Data)) != NC_NOERR)
			{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
			break;
		case NC_BYTE:
		case NC_SHORT:
		case NC_INT:
			if((status = nc_put_var_int(ncid,varid, (int *)  field->Data)) != NC_NOERR)
			{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
			break;
		case NC_FLOAT:
		case NC_DOUBLE:
			if((status = nc_put_var_double(ncid,varid,(double *) field->Data)) != NC_NOERR)
			{ NCprintNCError (status,"NCtableCommitField"); return (NCfailed);}
			break;
	}
	return (NCsucceeded);
}
Пример #26
0
int ex_put_map_param(int exoid, int num_node_maps, int num_elem_maps)
{
  int  dim[2], dimid, strdim, varid, status;
  int  var_nm_id, var_em_id;
  int  i;
  char errmsg[MAX_ERR_LENGTH];
  int  id_type  = NC_INT;
  int  int_type = NC_INT;
#if NC_HAS_HDF5
  int fill = NC_FILL_CHAR;
#endif

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
    id_type = NC_INT64;
  }
  if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
    int_type = NC_INT64;
  }

  /* return if these have been defined before */
  if ((num_node_maps > 0 && ((nc_inq_dimid(exoid, DIM_NUM_NM, &dimid)) == NC_NOERR)) ||
      (num_elem_maps > 0 && ((nc_inq_dimid(exoid, DIM_NUM_EM, &dimid)) == NC_NOERR))) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: number of maps already defined for file id %d", exoid);
    ex_err(__func__, errmsg, EX_BADPARAM);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  if ((num_node_maps > 0) || (num_elem_maps > 0)) {

    /* inquire previously defined dimensions  */
    if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get string length in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    /* put file into define mode */
    if ((status = nc_redef(exoid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    /* node maps: */
    if (num_node_maps > 0) {

      if ((status = nc_def_dim(exoid, DIM_NUM_NM, num_node_maps, &dimid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define number of node maps in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /* node maps id array: */
      dim[0] = dimid;
      if ((status = nc_def_var(exoid, VAR_NM_PROP(1), id_type, 1, dim, &var_nm_id)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to create node maps property array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /*   store property name as attribute of property array variable */
      if ((status = nc_put_att_text(exoid, var_nm_id, ATT_PROP_NAME, 3, "ID")) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to store node map property name %s in file id %d", "ID", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /* Node map names... */
      dim[0] = dimid;
      dim[1] = strdim;

      if (nc_def_var(exoid, VAR_NAME_NM, NC_CHAR, 2, dim, &varid) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define node map name array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }
#if NC_HAS_HDF5
      nc_def_var_fill(exoid, varid, 0, &fill);
#endif

      /* determine number of nodes */
      if ((status = nc_inq_dimid(exoid, DIM_NUM_NODES, &dimid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: couldn't determine number of nodes in file id %d",
                 exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      dim[0] = dimid;

      /* create variable array in which to store the node maps */
      for (i = 0; i < num_node_maps; i++) {
        if ((status = nc_def_var(exoid, VAR_NODE_MAP(i + 1), int_type, 1, dim, &varid)) !=
            NC_NOERR) {
          if (status == NC_ENAMEINUSE) {
            snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: node map %d already defined in file id %d", i,
                     exoid);
            ex_err(__func__, errmsg, status);
          }
          else {
            snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create node map %d in file id %d", i,
                     exoid);
            ex_err(__func__, errmsg, status);
          }
          goto error_ret; /* exit define mode and return */
        }
        ex_compress_variable(exoid, varid, 1);
      }
    }

    /* element maps: */
    if (num_elem_maps > 0) {
      if ((status = nc_def_dim(exoid, DIM_NUM_EM, num_elem_maps, &dimid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define number of element maps in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /* element maps id array: */
      dim[0] = dimid;
      if ((status = nc_def_var(exoid, VAR_EM_PROP(1), id_type, 1, dim, &var_em_id)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to create element maps property array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /*   store property name as attribute of property array variable */
      if ((status = nc_put_att_text(exoid, var_em_id, ATT_PROP_NAME, 3, "ID")) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to store element map property name %s in file id %d", "ID", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /* Element map names... */
      dim[0] = dimid;
      dim[1] = strdim;

      if ((status = nc_def_var(exoid, VAR_NAME_EM, NC_CHAR, 2, dim, &varid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define element map name array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }
#if NC_HAS_HDF5
      nc_def_var_fill(exoid, varid, 0, &fill);
#endif

      /* determine number of elements */
      if ((status = nc_inq_dimid(exoid, DIM_NUM_ELEM, &dimid)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: couldn't determine number of elements in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }

      /* create variable array in which to store the element maps */
      dim[0] = dimid;
      for (i = 0; i < num_elem_maps; i++) {
        if ((status = nc_def_var(exoid, VAR_ELEM_MAP(i + 1), int_type, 1, dim, &varid)) !=
            NC_NOERR) {
          if (status == NC_ENAMEINUSE) {
            snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: element map %d already defined in file id %d",
                     i, exoid);
            ex_err(__func__, errmsg, status);
          }
          else {
            snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create element map %d in file id %d",
                     i, exoid);
            ex_err(__func__, errmsg, status);
          }
          goto error_ret; /* exit define mode and return */
        }
        ex_compress_variable(exoid, varid, 1);
      }
    }

    /* leave define mode */
    if ((status = nc_enddef(exoid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to complete variable definitions in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    /* Fill the id arrays with EX_INVALID_ID */
    {
      int  maxset      = num_node_maps > num_elem_maps ? num_node_maps : num_elem_maps;
      int *invalid_ids = malloc(maxset * sizeof(int));
      if (invalid_ids == NULL) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to allocate memory for invalid id "
                 "storage in file id %d",
                 exoid);
        ex_err(__func__, errmsg, EX_MEMFAIL);
        EX_FUNC_LEAVE(EX_FATAL);
      }
      for (i = 0; i < maxset; i++) {
        invalid_ids[i] = EX_INVALID_ID;
      }
      if (num_node_maps > 0) {
        status = nc_put_var_int(exoid, var_nm_id, invalid_ids);
        assert(status == NC_NOERR);
      }
      if (num_elem_maps > 0) {
        status = nc_put_var_int(exoid, var_em_id, invalid_ids);
        assert(status == NC_NOERR);
      }
      free(invalid_ids);
    }
  }

  EX_FUNC_LEAVE(EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  if ((status = nc_enddef(exoid)) != NC_NOERR) /* exit define mode */
  {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid);
    ex_err(__func__, errmsg, status);
  }
  EX_FUNC_LEAVE(EX_FATAL);
}
Пример #27
0
int ex_put_set_param (int exoid,
                      ex_entity_type set_type,
                      int set_id,
                      int num_entries_in_set,
                      int num_dist_fact_in_set)
{
  int status;
  size_t temp;
  int dimid, varid, set_id_ndx, dims[1]; 
  size_t start[1]; 
  int num_sets;
  int ldum;
  int cur_num_sets, set_stat;
  char *cdum;
  char errmsg[MAX_ERR_LENGTH];
  char* dimptr;
  char* idsptr;
  char* statptr;
  char* numentryptr = NULL;
  char* numdfptr = NULL;
  char* factptr = NULL;
  char* entryptr = NULL;
  char* extraptr = NULL;

  exerrval = 0; /* clear error code */

  cdum = 0;

  /* setup pointers based on set_type 
     NOTE: there is another block that sets more stuff later ... */
  if (set_type == EX_NODE_SET) {
    dimptr = DIM_NUM_NS;
    idsptr = VAR_NS_IDS;
    statptr = VAR_NS_STAT;
  }
  else if (set_type == EX_EDGE_SET) {
    dimptr = DIM_NUM_ES;
    idsptr = VAR_ES_IDS;
    statptr = VAR_ES_STAT;
  }
  else if (set_type == EX_FACE_SET) {
    dimptr = DIM_NUM_FS;
    idsptr = VAR_FS_IDS;
    statptr = VAR_FS_STAT;
  }
  else if (set_type == EX_SIDE_SET) {
    dimptr = DIM_NUM_SS;
    idsptr = VAR_SS_IDS;
    statptr = VAR_SS_STAT;
  }
  else if (set_type == EX_ELEM_SET) {
    dimptr = DIM_NUM_ELS;
    idsptr = VAR_ELS_IDS;
    statptr = VAR_ELS_STAT;
  }
  else {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: invalid set type (%d)", set_type);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* first check if any of that set type is specified */

  if ((status = nc_inq_dimid(exoid, dimptr, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: no %ss specified in file id %d", ex_name_of_object(set_type),
	    exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check for duplicate set id entry */
  ex_id_lkup(exoid, set_type, set_id);
  if (exerrval != EX_LOOKUPFAIL) {  /* found the side set id */
    sprintf(errmsg,
	    "Error: %s %d already defined in file id %d", ex_name_of_object(set_type),
	    set_id,exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* Get number of sets specified for this file */
  if ((status = nc_inq_dimlen(exoid,dimid,&temp)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of %ss in file id %d",
	    ex_name_of_object(set_type), exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }
  num_sets = temp;


  /* Keep track of the total number of sets defined using a counter stored
     in a linked list keyed by exoid.
     NOTE: ex_get_file_item finds the maximum number of sets defined
     for a specific file and returns that value.
  */
  cur_num_sets=ex_get_file_item(exoid, ex_get_counter_list(set_type));
  if (cur_num_sets >= num_sets) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: exceeded number of %ss (%d) defined in file id %d",
	    ex_name_of_object(set_type), num_sets,exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /*   NOTE: ex_inc_file_item finds the current number of sets defined
       for a specific file and returns that value incremented. */

  cur_num_sets=ex_inc_file_item(exoid, ex_get_counter_list(set_type));
  set_id_ndx = cur_num_sets + 1;

  /* setup more pointers based on set_type */
  if (set_type == EX_NODE_SET) {
    numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
    entryptr = VAR_NODE_NS(set_id_ndx);
    extraptr = NULL;
    /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
    numdfptr = DIM_NUM_NOD_NS(set_id_ndx);
    factptr = VAR_FACT_NS(set_id_ndx);
  }
  else if (set_type == EX_EDGE_SET) {
    numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
    entryptr = VAR_EDGE_ES(set_id_ndx);
    extraptr = VAR_ORNT_ES(set_id_ndx);
    numdfptr = DIM_NUM_DF_ES(set_id_ndx);
    factptr = VAR_FACT_ES(set_id_ndx);
  }
  else if (set_type == EX_FACE_SET) {
    numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
    entryptr = VAR_FACE_FS(set_id_ndx);
    extraptr = VAR_ORNT_FS(set_id_ndx);
    numdfptr = DIM_NUM_DF_FS(set_id_ndx);
    factptr = VAR_FACT_FS(set_id_ndx);
  }
  else if (set_type == EX_SIDE_SET) {
    numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
    entryptr = VAR_ELEM_SS(set_id_ndx);
    extraptr = VAR_SIDE_SS(set_id_ndx);
    numdfptr = DIM_NUM_DF_SS(set_id_ndx);
    factptr = VAR_FACT_SS(set_id_ndx);
  }
  if (set_type == EX_ELEM_SET) {
    numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
    entryptr = VAR_ELEM_ELS(set_id_ndx);
    extraptr = NULL;
    numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
    factptr = VAR_FACT_ELS(set_id_ndx);
  }

  /* write out information to previously defined variable */

  /* first: get id of set id variable */
  if ((status = nc_inq_varid(exoid, idsptr, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s %d in file id %d", ex_name_of_object(set_type),
	    set_id, exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* write out set id */
  start[0] = cur_num_sets;

  ldum = (int)set_id;
  if ((status = nc_put_var1_int(exoid, varid, start, &ldum)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store %s id %d in file id %d", ex_name_of_object(set_type),
	    set_id, exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_entries_in_set == 0) /* Is this a NULL  set? */
    set_stat = 0; /* change set status to NULL */
  else
    set_stat = 1; /* change set status to TRUE */

  if ((status = nc_inq_varid(exoid, statptr, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s status in file id %d", ex_name_of_object(set_type),
	    exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  ldum = (int)set_stat;
  if ((status = nc_put_var1_int(exoid, varid, start, &ldum)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store %s %d status to file id %d", ex_name_of_object(set_type),
	    set_id, exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_entries_in_set == 0) {/* Is this a NULL set? */
    return(EX_NOERR);
  }

  /* put netcdf file into define mode  */
  if ((status = nc_redef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to put file id %d into define mode",
	    exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* define dimensions and variables */
  if ((status = nc_def_dim(exoid, numentryptr,
			   num_entries_in_set, &dimid)) != NC_NOERR) {
    exerrval = status;
    if (status == NC_ENAMEINUSE)
      {
	sprintf(errmsg,
		"Error: %s %d size already defined in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
      }
    else {
      sprintf(errmsg,
	      "Error: failed to define number of entries in %s %d in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set_param",errmsg,exerrval);
    }
    goto error_ret;
  }

  /* create variable array in which to store the entry lists */

  dims[0] = dimid;
  if ((status = nc_def_var(exoid, entryptr, NC_INT, 1, dims, &varid)) != NC_NOERR) {
    exerrval = status;
    if (status == NC_ENAMEINUSE) {
      sprintf(errmsg,
	      "Error: entry list already exists for %s %d in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set_param",errmsg,exerrval);
    } else {
      sprintf(errmsg,
	      "Error: failed to create entry list for %s %d in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set_param",errmsg,exerrval);
    }
    goto error_ret;            /* exit define mode and return */
  }

  if (extraptr) {
    if ((status = nc_def_var(exoid, extraptr, NC_INT, 1, dims, &varid)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {
	sprintf(errmsg,
		"Error: extra list already exists for %s %d in file id %d",
		ex_name_of_object(set_type), set_id, exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
      } else {
	sprintf(errmsg,
		"Error: failed to create extra list for %s %d in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
      }
      goto error_ret;         /* exit define mode and return */
           
    }
  }

  /* Create distribution factors variable if required */

  if (num_dist_fact_in_set > 0) {

    if (set_type == EX_NODE_SET) {
      /* but num_dist_fact_in_set must equal number of nodes */
      if (num_dist_fact_in_set != num_entries_in_set) {
	exerrval = EX_FATAL;
	sprintf(errmsg,
		"Error: # dist fact (%d) not equal to # nodes (%d) in node  set %d file id %d",
		num_dist_fact_in_set, num_entries_in_set, set_id, exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
	goto error_ret;    /* exit define mode and return */
      }

      /* resuse dimid from entry lists */

    } else {
      if ((status = nc_def_dim(exoid, numdfptr, 
			       num_dist_fact_in_set, &dimid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of dist factors in %s %d in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
	goto error_ret;          /* exit define mode and return */
      }
    }

    /* create variable array in which to store the set distribution factors
     */
    dims[0] = dimid;
    if ((status = nc_def_var(exoid, factptr, nc_flt_code(exoid), 1, dims, &varid)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {
	sprintf(errmsg,
		"Error: dist factors list already exists for %s %d in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
      } else {
	sprintf(errmsg,
		"Error: failed to create dist factors list for %s %d in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_set_param",errmsg,exerrval);
      }
      goto error_ret;            /* exit define mode and return */
    }
  }

  /* leave define mode  */
  if ((status = nc_enddef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to complete definition in file id %d", exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
  }
  return (EX_FATAL);
}
Пример #28
0
int ex_put_sets (int   exoid,
		 size_t set_count,
		 const struct ex_set *sets)
{
  size_t i;
  int needs_define = 0;
  int set_stat;
  int dimid, varid, status, dims[1];
  int set_id_ndx;
  size_t start[1]; 
  int cur_num_sets;
  char errmsg[MAX_ERR_LENGTH];
  int* sets_to_define = NULL;
  char* numentryptr 	= NULL;
  char* entryptr = NULL;
  char* extraptr = NULL;
  char* idsptr = NULL;
  char* statptr = NULL;
  char* numdfptr = NULL;
  char* factptr = NULL;

  size_t int_size;
  
  exerrval = 0; /* clear error code */

  sets_to_define = malloc(set_count*sizeof(int));
  
  /* Note that this routine can be called:
     1) just define the sets
     2) just output the set data (after a previous call to define)
     3) define and output the set data in one call.
  */
  for (i=0; i < set_count; i++) {
    /* first check if any sets are specified */
    if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(sets[i].type), &dimid)) != NC_NOERR) {
      if (status == NC_EBADDIM) {
	exerrval = status;
	sprintf(errmsg,
		"Error: no %ss defined for file id %d", ex_name_of_object(sets[i].type), exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
      } else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate %ss defined in file id %d",
		ex_name_of_object(sets[i].type), exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
      }
      return (EX_FATAL);
    }

    set_id_ndx = ex_id_lkup(exoid, sets[i].type, sets[i].id);
    if (exerrval != EX_LOOKUPFAIL) {  /* found the side set id, so set is already defined... */
      sets_to_define[i] = 0;
      continue;
    } else {
      needs_define++;
      sets_to_define[i] = 1;
    }
  }
    
  if (needs_define > 0) {
    /* put netcdf file into define mode  */
    if ((status = nc_redef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to put file id %d into define mode",
	      exoid);
      ex_err("ex_put_sets",errmsg,exerrval);
      return (EX_FATAL);
    }
    
    for (i=0; i < set_count; i++) {
      if (sets_to_define[i] == 0)
	continue;
      
      /*   NOTE: ex_inc_file_item finds the current number of sets defined
	   for a specific file and returns that value incremented. */
      cur_num_sets=ex_inc_file_item(exoid, ex_get_counter_list(sets[i].type));
      set_id_ndx = cur_num_sets + 1;
      sets_to_define[i] = set_id_ndx;
      
      if (sets[i].num_entry == 0)
	continue;
      
      /* setup pointers based on set_type */
      if (sets[i].type == EX_NODE_SET) {
	numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
	entryptr = VAR_NODE_NS(set_id_ndx);
	extraptr = NULL;
	/* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
	numdfptr = DIM_NUM_NOD_NS(set_id_ndx);
	factptr = VAR_FACT_NS(set_id_ndx);
      }
      else if (sets[i].type == EX_EDGE_SET) {
	numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
	entryptr = VAR_EDGE_ES(set_id_ndx);
	extraptr = VAR_ORNT_ES(set_id_ndx);
	numdfptr = DIM_NUM_DF_ES(set_id_ndx);
	factptr = VAR_FACT_ES(set_id_ndx);
      }
      else if (sets[i].type == EX_FACE_SET) {
	numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
	entryptr = VAR_FACE_FS(set_id_ndx);
	extraptr = VAR_ORNT_FS(set_id_ndx);
	numdfptr = DIM_NUM_DF_FS(set_id_ndx);
	factptr = VAR_FACT_FS(set_id_ndx);
      }
      else if (sets[i].type == EX_SIDE_SET) {
	numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
	entryptr = VAR_ELEM_SS(set_id_ndx);
	extraptr = VAR_SIDE_SS(set_id_ndx);
	numdfptr = DIM_NUM_DF_SS(set_id_ndx);
	factptr = VAR_FACT_SS(set_id_ndx);
      }
      else if (sets[i].type == EX_ELEM_SET) {
	numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
	entryptr = VAR_ELEM_ELS(set_id_ndx);
	extraptr = NULL;
	numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
	factptr = VAR_FACT_ELS(set_id_ndx);
      }

      /* define dimensions and variables */
      if ((status = nc_def_dim(exoid, numentryptr,
			       sets[i].num_entry, &dimid)) != NC_NOERR) {
	exerrval = status;
	if (status == NC_ENAMEINUSE) {
	  sprintf(errmsg,
		  "Error: %s %"PRId64" -- size already defined in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	}
	else {
	  sprintf(errmsg,
		  "Error: failed to define number of entries in %s %"PRId64" in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	}
	goto error_ret;
      }
      
      int_size = sizeof(int);
      if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
	int_size = sizeof(int64_t);
      }
      
      /* create variable array in which to store the entry lists */
      dims[0] = dimid;
      if ((status = nc_def_var(exoid, entryptr, int_size, 1, dims, &varid)) != NC_NOERR) {
	exerrval = status;
	if (status == NC_ENAMEINUSE) {
	  sprintf(errmsg,
		  "Error: entry list already exists for %s %"PRId64" in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	} else {
	  sprintf(errmsg,
		  "Error: failed to create entry list for %s %"PRId64" in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	}
	goto error_ret;            /* exit define mode and return */
      }
      ex_compress_variable(exoid, varid, 1);
      
      if (extraptr) {
	if ((status = nc_def_var(exoid, extraptr, int_size, 1, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  if (status == NC_ENAMEINUSE) {
	    sprintf(errmsg,
		    "Error: extra list already exists for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id, exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  } else {
	    sprintf(errmsg,
		    "Error: failed to create extra list for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  }
	  goto error_ret;         /* exit define mode and return */
	}
	ex_compress_variable(exoid, varid, 1);
      }

      /* Create distribution factors variable if required */
      if (sets[i].num_distribution_factor > 0) {
	if (sets[i].type != EX_SIDE_SET) {
	  /* but sets[i].num_distribution_factor must equal number of nodes */
	  if (sets[i].num_distribution_factor != sets[i].num_entry) {
	    exerrval = EX_FATAL;
	    sprintf(errmsg,
		    "Error: # dist fact (%"PRId64") not equal to # nodes (%"PRId64") in node  set %"PRId64" file id %d",
		    sets[i].num_distribution_factor, sets[i].num_entry, sets[i].id, exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	    goto error_ret;    /* exit define mode and return */
	  }
	} else {
	  /* resuse dimid from entry lists */
	  if ((status = nc_def_dim(exoid, numdfptr, 
				   sets[i].num_distribution_factor, &dimid)) != NC_NOERR) {
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to define number of dist factors in %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	    goto error_ret;          /* exit define mode and return */
	  }
	}
	
	/* create variable array in which to store the set distribution factors
	 */
	dims[0] = dimid;
	if ((status = nc_def_var(exoid, factptr, nc_flt_code(exoid), 1, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  if (status == NC_ENAMEINUSE) {
	    sprintf(errmsg,
		    "Error: dist factors list already exists for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  } else {
	    sprintf(errmsg,
		    "Error: failed to create dist factors list for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  }
	  goto error_ret;            /* exit define mode and return */
	}
	ex_compress_variable(exoid, varid, 2);
      }
    }

    /* leave define mode  */
    if ((status = nc_enddef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to complete definition in file id %d", exoid);
      ex_err("ex_put_sets",errmsg,exerrval);
      return (EX_FATAL);
    }

    /* Output the set ids and status... */
    for (i=0; i < set_count; i++) {
    /* setup pointers based on sets[i].type */
      if (sets[i].type == EX_NODE_SET) {
	idsptr = VAR_NS_IDS;
	statptr = VAR_NS_STAT;
      }
      else if (sets[i].type == EX_EDGE_SET) {
	idsptr = VAR_ES_IDS;
	statptr = VAR_ES_STAT;
      }
      else if (sets[i].type == EX_FACE_SET) {
	idsptr = VAR_FS_IDS;
	statptr = VAR_FS_STAT;
      }
      else if (sets[i].type == EX_SIDE_SET) {
	idsptr = VAR_SS_IDS;
	statptr = VAR_SS_STAT;
      }
      else if (sets[i].type == EX_ELEM_SET) {
	idsptr = VAR_ELS_IDS;
	statptr = VAR_ELS_STAT;
      }
      
      /* first: get id of set id variable */
      if ((status = nc_inq_varid(exoid, idsptr, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate %s %"PRId64" in file id %d", ex_name_of_object(sets[i].type),
		sets[i].id, exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
      
      /* write out set id */
      start[0] = sets_to_define[i]-1;
      status = nc_put_var1_longlong(exoid, varid, start, (long long*)&sets[i].id);
    
      if (status != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store %s id %"PRId64" in file id %d", ex_name_of_object(sets[i].type),
		sets[i].id, exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
      
      set_stat = (sets[i].num_entry == 0) ? 0 : 1;
      
      if ((status = nc_inq_varid(exoid, statptr, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate %s status in file id %d", ex_name_of_object(sets[i].type),
		exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
      
      if ((status = nc_put_var1_int(exoid, varid, start, &set_stat)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store %s %"PRId64" status to file id %d", ex_name_of_object(sets[i].type),
		sets[i].id, exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
    free(sets_to_define);
  }
  
  /* Sets are now all defined; see if any set data needs to be output... */
  status = EX_NOERR;
  for (i=0; i < set_count; i++) {
    int stat;
    if (sets[i].entry_list != NULL || sets[i].extra_list != NULL) {
      /* NOTE: ex_put_set will write the warning/error message... */
      stat = ex_put_set(exoid, sets[i].type, sets[i].id, sets[i].entry_list, sets[i].extra_list);
      if (stat != EX_NOERR) status = EX_FATAL;
    }
    if (sets[i].distribution_factor_list != NULL) {
      /* NOTE: ex_put_set_dist_fact will write the warning/error message... */
      stat = ex_put_set_dist_fact(exoid, sets[i].type, sets[i].id, sets[i].distribution_factor_list);
      if (stat != EX_NOERR) status = EX_FATAL;
    }
  }  
  return (status);

  /* Fatal error: exit definition mode and return */
 error_ret:
  free(sets_to_define);
  
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_sets",errmsg,exerrval);
  }
  return (EX_FATAL);
}
Пример #29
0
void ParcelManager::
output(const TimeLevelIndex<2> &timeIdx, int ncId) const {
    int parcelDimId, skel1DimId, dimDimId, tracerDimId;
    int idVarId;
    int cDimIds[2], cVarId;
    int hDimIds[3], hVarId;
    int mDimIds[2], mVarId;
    int sDimIds[3], s1VarId;
#define OUTPUT_TRACER_SHAPE
#ifdef OUTPUT_TRACER_SHAPE
    int skel2DimId, s2VarId, numSkel2 = 40;
#endif
    char str[100];
    int l;
    int *intData;
    double *doubleData;

    nc_redef(ncId);

    nc_def_dim(ncId, "parcel", _parcels.size(), &parcelDimId);
    nc_def_dim(ncId, "dim", mesh->domain().numDim(), &dimDimId);
    nc_def_dim(ncId, "tracer", Tracers::numTracer(), &tracerDimId);
    nc_def_dim(ncId, "skel1", SkeletonPoints::numPoint(), &skel1DimId);

#ifdef OUTPUT_TRACER_SHAPE
    if (mesh->domain().numDim() == 2) {
        // Only output skeleton in 2D domain, since in 3D it could be messy.
        nc_def_dim(ncId, "skel2", numSkel2, &skel2DimId);
    }
#endif
    
    nc_def_var(ncId, "id", NC_INT, 1, &parcelDimId, &idVarId);
    sprintf(str, "parcel identifier");
    nc_put_att(ncId, idVarId, "long_name", NC_CHAR, strlen(str), str);

    cDimIds[0] = parcelDimId; cDimIds[1] = dimDimId;
    nc_def_var(ncId, "c", NC_DOUBLE, 2, cDimIds, &cVarId);
    sprintf(str, "parcel centroid coordinates on %s", mesh->domain().brief().c_str());
    nc_put_att(ncId, cVarId, "long_name", NC_CHAR, strlen(str), str);

    hDimIds[0] = parcelDimId; hDimIds[1] = dimDimId; hDimIds[2] = dimDimId;
    nc_def_var(ncId, "h", NC_DOUBLE, 3, hDimIds, &hVarId);
    sprintf(str, "parcel linear deformation matrix");
    nc_put_att(ncId, hVarId, "long_name", NC_CHAR, strlen(str), str);

    mDimIds[0] = parcelDimId; mDimIds[1] = tracerDimId;
    nc_def_var(ncId, "m", NC_DOUBLE, 2, mDimIds, &mVarId);
    sprintf(str, "tracer mass");
    nc_put_att(ncId, mVarId, "long_name", NC_CHAR, strlen(str), str);

    sDimIds[0] = parcelDimId; sDimIds[1] = skel1DimId; sDimIds[2] = dimDimId;
    nc_def_var(ncId, "s1", NC_DOUBLE, 3, sDimIds, &s1VarId);
    sprintf(str, "parcel actual skeleton");
    nc_put_att(ncId, s1VarId, "long_name", NC_CHAR, strlen(str), str);

#ifdef OUTPUT_TRACER_SHAPE
    if (mesh->domain().numDim() == 2) {
        sDimIds[1] = skel2DimId;
        nc_def_var(ncId, "s2", NC_DOUBLE, 3, sDimIds, &s2VarId);
        sprintf(str, "parcel fitted skeleton");
        nc_put_att(ncId, s2VarId, "long_name", NC_CHAR, strlen(str), str);
    }
#endif
    
    nc_enddef(ncId);

    intData = new int[_parcels.size()];
    l = 0;
    for (auto parcel : _parcels) {
        intData[l++] = parcel->id();
    }
    nc_put_var(ncId, idVarId, intData);
    delete [] intData;
    
    doubleData = new double[_parcels.size()*mesh->domain().numDim()];
    l = 0;
    for (auto parcel : _parcels) {
        for (uword m = 0; m < mesh->domain().numDim(); ++m) {
            doubleData[l++] = parcel->x(timeIdx)(m);
        }
    }
    nc_put_var(ncId, cVarId, doubleData);
    delete [] doubleData;

    doubleData = new double[_parcels.size()*mesh->domain().numDim()*mesh->domain().numDim()];
    l = 0;
    for (auto parcel : _parcels) {
        for (uword m1 = 0; m1 < mesh->domain().numDim(); ++m1) {
            for (uword m2 = 0; m2 < mesh->domain().numDim(); ++m2) {
                doubleData[l++] = parcel->H(timeIdx)(m1, m2);
            }
        }
    }
    nc_put_var(ncId, hVarId, doubleData);
    delete [] doubleData;
    
    doubleData = new double[_parcels.size()*Tracers::numTracer()];
    l = 0;
    for (auto parcel : _parcels) {
        for (int t = 0; t < Tracers::numTracer(); ++t) {
            doubleData[l++] = parcel->tracers().mass(t);
        }
    }
    nc_put_var(ncId, mVarId, doubleData);
    delete [] doubleData;

    doubleData = new double[_parcels.size()*SkeletonPoints::numPoint()*mesh->domain().numDim()];
    l = 0;
    for (auto parcel : _parcels) {
        for (auto xs : parcel->skeletonPoints().spaceCoords(timeIdx)) {
            for (uword m = 0; m < mesh->domain().numDim(); ++m) {
                doubleData[l++] = xs(m);
            }
        }
    }
    nc_put_var(ncId, s1VarId, doubleData);
    delete [] doubleData;

#ifdef OUTPUT_TRACER_SHAPE
    if (mesh->domain().numDim() == 2) {
        double dtheta = PI2/numSkel2;
        BodyCoord y(2); SpaceCoord x(2);
        doubleData = new double[_parcels.size()*numSkel2*mesh->domain().numDim()];
        l = 0;
        for (auto parcel : _parcels) {
            for (int i = 0; i < numSkel2; ++i) {
                double theta = i*dtheta;
                y(0) = cos(theta);
                y(1) = sin(theta);
                parcel->calcSpaceCoord(timeIdx, y, x);
                for (uword m = 0; m < mesh->domain().numDim(); ++m) {
                    doubleData[l++] = x(m);
                }
            }
        }
        nc_put_var(ncId, s2VarId, doubleData);
        delete [] doubleData;
    }
#endif
} // output
Пример #30
0
int ex_put_id_map (int  exoid,
       ex_entity_type map_type,
       const int *map)
{
  int dimid, mapid, status, dims[1];
  char errmsg[MAX_ERR_LENGTH];
  const char* tname;
  const char* dnumentries;
  const char* vmap;

  exerrval = 0; /* clear error code */

  switch ( map_type ) {
  case EX_NODE_MAP:
    tname = "node";
    dnumentries = DIM_NUM_NODES;
    vmap = VAR_NODE_NUM_MAP;
    break;
  case EX_EDGE_MAP:
    tname = "edge";
    dnumentries = DIM_NUM_EDGE;
    vmap = VAR_EDGE_NUM_MAP;
    break;
  case EX_FACE_MAP:
    tname = "face";
    dnumentries = DIM_NUM_FACE;
    vmap = VAR_FACE_NUM_MAP;
    break;
  case EX_ELEM_MAP:
    tname = "element";
    dnumentries = DIM_NUM_ELEM;
    vmap = VAR_ELEM_NUM_MAP;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg,
       "Error: Bad map type (%d) specified for file id %d",
       map_type, exoid );
    ex_err( "ex_put_id_map", errmsg, exerrval );
    return (EX_FATAL);
  }

  /* Make sure the file contains entries */
  if (nc_inq_dimid (exoid, dnumentries, &dimid) != NC_NOERR) {
    return (EX_NOERR);
  }
   
  /* put netcdf file into define mode  */
  if (nc_inq_varid (exoid, vmap, &mapid) != NC_NOERR) {
    if ((status = nc_redef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to put file id %d into define mode",
        exoid);
      ex_err("ex_put_id_map",errmsg,exerrval);
      return (EX_FATAL);
    }
    

    /* create a variable array in which to store the id map  */
    dims[0] = dimid;
    
    if ((status = nc_def_var(exoid, vmap, NC_INT, 1, dims, &mapid)) != NC_NOERR) {
      if (status == NC_ENAMEINUSE) {
  exerrval = status;
  sprintf(errmsg,
    "Error: %s numbering map already exists in file id %d",
    tname, exoid);
  ex_err("ex_put_id_map",errmsg,exerrval);
      } else {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to create %s id map in file id %d",
    tname, exoid);
  ex_err("ex_put_id_map",errmsg,exerrval);
      }
      goto error_ret;         /* exit define mode and return */
    }
    

    /* leave define mode  */
    if ((status = nc_enddef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to complete definition in file id %d",
        exoid);
      ex_err("ex_put_id_map",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* write out the entity numbering map  */
  status = nc_put_var_int(exoid, mapid, map);

  if (status!= NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to store %s numbering map in file id %d",
      tname, exoid);
    ex_err("ex_put_id_map",errmsg,exerrval);
    return (EX_FATAL);
  }


  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR)     /* exit define mode */
    {
      sprintf(errmsg,
              "Error: failed to complete definition for file id %d",
              exoid);
      ex_err("ex_put_id_map",errmsg,exerrval);
    }
  return (EX_FATAL);
}