static void test_large_short_var(const char *testfile) { int ncid, varid, dimids[NUMDIMS]; int int_val_in, int_val_out = 99; size_t index[2]; int cflag = NC_CLOBBER; if (nc_create(testfile, cflag, &ncid)) ERR; if (nc_def_dim(ncid, "dim3", DIM3, &dimids[0])) ERR; if (nc_def_dim(ncid, "dim4", DIM4, &dimids[1])) ERR; if (nc_def_var(ncid, "var", NC_SHORT, NUMDIMS, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; index[0] = 0; index[1] = 1; if (nc_put_var1_int(ncid, varid, index, &int_val_out)) ERR; if (nc_close(ncid)) ERR; if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR; if (nc_inq_varid(ncid, "var", &varid)) ERR; if (nc_get_var1_int(ncid, varid, index, &int_val_in)) ERR; if (int_val_in != int_val_out) ERR; #ifndef NOFILL index[0] = 1; index[1] = 2; if (nc_get_var1_int(ncid, varid, index, &int_val_in)) ERR; if (int_val_in != NC_FILL_SHORT) ERR; #endif if (nc_close(ncid)) ERR; }
/* * In netCDF-3.6.2, an assertion failure occurs on 32-bit platforms * when creating a byte variable for which the product of dimensions * is greater than 2**32. Check that this bug has been fixed. */ static int test_big_var(const char *testfile) { int ncid, varid, dimids[NUMDIMS]; size_t index[NUMDIMS]; int nval = 99; int nval_in; /* Create a file with one big variable. */ if (nc_create(testfile, NC_CLOBBER, &ncid)) ERR; if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR; if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR; if (nc_def_dim(ncid, "dim2", DIM2 - 1, &dimids[1])) ERR; if (nc_def_var(ncid, "var", NC_BYTE, NUMDIMS, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; index[0] = DIM1 - 1; index[1] = DIM2 - 2; if (nc_put_var1_int(ncid, varid, index, &nval)) ERR; if (nc_close(ncid)) ERR; /* Open the file and check it. */ if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR; if (nc_inq_varid(ncid, "var", &varid)) ERR; if (nc_get_var1_int(ncid, varid, index, &nval_in)) ERR; if (nval != nval_in) ERR; if (nc_close(ncid)) ERR; return 0; }
/** * Write int data to corresponding variable name */ void store(Property<int> *v) { int retval; int varid; int value = v->get(); std::string sname = composeName(v->getName()); /** * Get netcdf variable ID from name */ retval = nc_inq_varid(ncid, sname.c_str(), &varid); if (retval) log(Error) << "Could not get variable id of " << sname << ", error " << retval <<endlog(); /** * Write a single data value */ retval = nc_put_var1_int(ncid, varid, &index, &value); if(retval) log(Error) << "Could not write variable " << sname << ", error " << retval <<endlog(); }
/* * Put a single numeric data value into a variable of an open netCDF. */ static void c_ncvpt1 ( int ncid, /* netCDF ID */ int varid, /* variable ID */ const size_t* indices,/* multidim index of data to be written */ const void* value, /* pointer to data value to be written */ int* rcode /* returned error code */ ) { int status; nc_type datatype; if ((status = nc_inq_vartype(ncid, varid, &datatype)) == 0) { switch (datatype) { case NC_CHAR: status = NC_ECHAR; break; case NC_BYTE: # if NF_INT1_IS_C_SIGNED_CHAR status = nc_put_var1_schar(ncid, varid, indices, (const signed char*)value); # elif NF_INT1_IS_C_SHORT status = nc_put_var1_short(ncid, varid, indices, (const short*)value); # elif NF_INT1_IS_C_INT status = nc_put_var1_int(ncid, varid, indices, (const int*)value); # elif NF_INT1_IS_C_LONG status = nc_put_var1_long(ncid, varid, indices, (const long*)value); # endif break; case NC_SHORT: # if NF_INT2_IS_C_SHORT status = nc_put_var1_short(ncid, varid, indices, (const short*)value); # elif NF_INT2_IS_C_INT status = nc_put_var1_int(ncid, varid, indices, (const int*)value); # elif NF_INT2_IS_C_LONG status = nc_put_var1_long(ncid, varid, indices, (const long*)value); # endif break; case NC_INT: # if NF_INT_IS_C_INT status = nc_put_var1_int(ncid, varid, indices, (const int*)value); # elif NF_INT_IS_C_LONG status = nc_put_var1_long(ncid, varid, indices, (const long*)value); # endif break; case NC_FLOAT: # if NF_REAL_IS_C_FLOAT status = nc_put_var1_float(ncid, varid, indices, (const float*)value); # elif NF_REAL_IS_C_DOUBLE status = nc_put_var1_double(ncid, varid, indices, (const double*)value); # endif break; case NC_DOUBLE: # if NF_DOUBLEPRECISION_IS_C_FLOAT status = nc_put_var1_float(ncid, varid, indices, (const float*)value); # elif NF_DOUBLEPRECISION_IS_C_DOUBLE status = nc_put_var1_double(ncid, varid, indices, (const double*)value); # endif break; } } if (status == 0) *rcode = 0; else { nc_advise("NCVPT1", status, ""); *rcode = ncerr; } }
/*! \internal */ int cpy_var_val(int in_id,int out_id,char *var_nm) /* int in_id: input netCDF input-file ID int out_id: input netCDF output-file ID char *var_nm: input variable name */ { /* Routine to copy the variable data from an input netCDF file * to an output netCDF file. */ int *dim_id; int idx; int nbr_dim; int var_in_id; int var_out_id; size_t *dim_cnt; size_t *dim_sz; size_t *dim_srt; size_t var_sz=1L; nc_type var_type_in, var_type_out; void *void_ptr = NULL; /* Get the var_id for the requested variable from both files. */ (void)nc_inq_varid(in_id, var_nm, &var_in_id); (void)nc_inq_varid(out_id,var_nm, &var_out_id); /* Get the number of dimensions for the variable. */ (void)nc_inq_vartype( out_id, var_out_id, &var_type_out); (void)nc_inq_varndims(out_id, var_out_id, &nbr_dim); (void)nc_inq_vartype( in_id, var_in_id, &var_type_in); (void)nc_inq_varndims(in_id, var_in_id, &nbr_dim); /* Allocate space to hold the dimension IDs */ dim_cnt = malloc(nbr_dim*sizeof(size_t)); dim_id=malloc(nbr_dim*sizeof(int)); dim_sz=malloc(nbr_dim*sizeof(size_t)); dim_srt=malloc(nbr_dim*sizeof(size_t)); /* Get the dimension IDs from the input file */ (void)nc_inq_vardimid(in_id, var_in_id, dim_id); /* Get the dimension sizes and names from the input file */ for(idx=0;idx<nbr_dim;idx++){ /* NB: For the unlimited dimension, ncdiminq() returns the maximum value used so far in writing data for that dimension. Thus if you read the dimension sizes from the output file, then the ncdiminq() returns dim_sz=0 for the unlimited dimension until a variable has been written with that dimension. This is the reason for always reading the input file for the dimension sizes. */ (void)nc_inq_dimlen(in_id,dim_id[idx],dim_cnt+idx); /* Initialize the indicial offset and stride arrays */ dim_srt[idx]=0L; var_sz*=dim_cnt[idx]; } /* end loop over dim */ /* Allocate enough space to hold the variable */ if (var_sz > 0) void_ptr=malloc(var_sz * type_size(var_type_in)); /* Get the variable */ /* if variable is float or double, convert if necessary */ if(nbr_dim==0){ /* variable is a scalar */ if (var_type_in == NC_INT && var_type_out == NC_INT) { nc_get_var1_int(in_id, var_in_id, 0L, void_ptr); nc_put_var1_int(out_id, var_out_id, 0L, void_ptr); } else if (var_type_in == NC_INT64 && var_type_out == NC_INT64) { nc_get_var1_longlong(in_id, var_in_id, 0L, void_ptr); nc_put_var1_longlong(out_id, var_out_id, 0L, void_ptr); } else if (var_type_in == NC_FLOAT) { nc_get_var1_float(in_id, var_in_id, 0L, void_ptr); nc_put_var1_float(out_id, var_out_id, 0L, void_ptr); } else if (var_type_in == NC_DOUBLE) { nc_get_var1_double(in_id, var_in_id, 0L, void_ptr); nc_put_var1_double(out_id, var_out_id, 0L, void_ptr); } else if (var_type_in == NC_CHAR) { nc_get_var1_text(in_id, var_in_id, 0L, void_ptr); nc_put_var1_text(out_id, var_out_id, 0L, void_ptr); } else { assert(1==0); } } else { /* variable is a vector */ if (var_type_in == NC_INT && var_type_out == NC_INT) { (void)nc_get_var_int(in_id, var_in_id, void_ptr); (void)nc_put_var_int(out_id, var_out_id, void_ptr); } else if (var_type_in == NC_INT64 && var_type_out == NC_INT64) { (void)nc_get_var_longlong(in_id, var_in_id, void_ptr); (void)nc_put_var_longlong(out_id, var_out_id, void_ptr); } else if (var_type_in == NC_FLOAT) { (void)nc_get_var_float(in_id, var_in_id, void_ptr); (void)nc_put_var_float(out_id, var_out_id, void_ptr); } else if (var_type_in == NC_DOUBLE) { (void)nc_get_var_double(in_id, var_in_id, void_ptr); (void)nc_put_var_double(out_id, var_out_id, void_ptr); } else if (var_type_in == NC_CHAR) { (void)nc_get_var_text(in_id, var_in_id, void_ptr); (void)nc_put_var_text(out_id, var_out_id, void_ptr); } else { assert(1==0); } } /* end if variable is an array */ /* Free the space that held the dimension IDs */ (void)free(dim_cnt); (void)free(dim_id); (void)free(dim_sz); (void)free(dim_srt); /* Free the space that held the variable */ (void)free(void_ptr); return(EX_NOERR); } /* end cpy_var_val() */
int ex_put_prop (int exoid, ex_entity_type obj_type, int obj_id, const char *prop_name, int value) { int status; int oldfill, temp; int found = FALSE; int num_props, i, dimid, propid, dims[1]; size_t start[1]; size_t prop_name_len, name_length; int ldum; char name[MAX_VAR_NAME_LENGTH+1]; char tmpstr[MAX_STR_LENGTH+1]; char dim_name[MAX_VAR_NAME_LENGTH+1]; int vals[1]; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* check if property has already been created */ num_props = ex_get_num_props(exoid, obj_type); if (num_props > 1) { /* any properties other than the default 1? */ for (i=1; i<=num_props; i++) { switch (obj_type) { case EX_ELEM_BLOCK: strcpy (name, VAR_EB_PROP(i)); break; case EX_EDGE_BLOCK: strcpy (name, VAR_ED_PROP(i)); break; case EX_FACE_BLOCK: strcpy (name, VAR_FA_PROP(i)); break; case EX_NODE_SET: strcpy (name, VAR_NS_PROP(i)); break; case EX_EDGE_SET: strcpy (name, VAR_ES_PROP(i)); break; case EX_FACE_SET: strcpy (name, VAR_FS_PROP(i)); break; case EX_ELEM_SET: strcpy (name, VAR_ELS_PROP(i)); break; case EX_SIDE_SET: strcpy (name, VAR_SS_PROP(i)); break; case EX_ELEM_MAP: strcpy (name, VAR_EM_PROP(i)); break; case EX_FACE_MAP: strcpy (name, VAR_FAM_PROP(i)); break; case EX_EDGE_MAP: strcpy (name, VAR_EDM_PROP(i)); break; case EX_NODE_MAP: strcpy (name, VAR_NM_PROP(i)); break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: object type %d not supported; file id %d", obj_type, exoid); ex_err("ex_put_prop",errmsg,exerrval); return(EX_FATAL); } if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get property array id in file id %d", exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_FATAL); } /* compare stored attribute name with passed property name */ memset(tmpstr, 0, MAX_STR_LENGTH+1); if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get property name in file id %d", exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_FATAL); } if (strcmp(tmpstr, prop_name) == 0) { found = TRUE; break; } } } /* if property array has not been created, create it */ if (!found) { name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH)+1; /* put netcdf file into define mode */ if ((status = nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_FATAL); } /* create a variable with a name xx_prop#, where # is the new number */ /* of the property */ switch (obj_type){ case EX_ELEM_BLOCK: strcpy (name, VAR_EB_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_EL_BLK); break; case EX_FACE_BLOCK: strcpy (name, VAR_FA_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_FA_BLK); break; case EX_EDGE_BLOCK: strcpy (name, VAR_ED_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_ED_BLK); break; case EX_NODE_SET: strcpy (name, VAR_NS_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_NS); break; case EX_EDGE_SET: strcpy (name, VAR_ES_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_ES); break; case EX_FACE_SET: strcpy (name, VAR_FS_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_FS); break; case EX_ELEM_SET: strcpy (name, VAR_ELS_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_ELS); break; case EX_SIDE_SET: strcpy (name, VAR_SS_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_SS); break; case EX_ELEM_MAP: strcpy (name, VAR_EM_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_EM); break; case EX_FACE_MAP: strcpy (name, VAR_FAM_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_FAM); break; case EX_EDGE_MAP: strcpy (name, VAR_EDM_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_EDM); break; case EX_NODE_MAP: strcpy (name, VAR_NM_PROP(num_props+1)); strcpy (dim_name, DIM_NUM_NM); break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: object type %d not supported; file id %d", obj_type, exoid); ex_err("ex_put_prop",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } /* inquire id of previously defined dimension (number of objects) */ if ((status = nc_inq_dimid(exoid, dim_name, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of objects in file id %d", exoid); ex_err("ex_put_prop",errmsg, exerrval); goto error_ret; /* Exit define mode and return */ } dims[0] = dimid; nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */ if ((status = nc_def_var(exoid, name, NC_INT, 1, dims, &propid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create property array variable in file id %d", exoid); ex_err("ex_put_prop",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } vals[0] = 0; /* fill value */ /* create attribute to cause variable to fill with zeros per routine spec */ if ((status = nc_put_att_int(exoid, propid, _FillValue, NC_INT, 1, vals)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create property name fill attribute in file id %d", exoid); ex_err("ex_put_prop",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } /* Check that the property name length is less than MAX_NAME_LENGTH */ prop_name_len = strlen(prop_name)+1; if (prop_name_len > name_length) { fprintf(stderr, "Warning: The property name '%s' is too long.\n\tIt will be truncated from %d to %d characters\n", prop_name, (int)prop_name_len-1, (int)name_length-1); prop_name_len = name_length; } /* store property name as attribute of property array variable */ if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, prop_name_len, (void*)prop_name)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store property name %s in file id %d", prop_name,exoid); ex_err("ex_put_prop",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } ex_update_max_name_length(exoid, prop_name_len-1); /* leave define mode */ if ((status = nc_enddef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to leave define mode in file id %d", exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_FATAL); } nc_set_fill(exoid, oldfill, &temp); /* default: nofill */ } /* find index into property array using obj_id; put value in property */ /* array at proper index; ex_id_lkup returns an index that is 1-based,*/ /* but netcdf expects 0-based arrays so subtract 1 */ /* special case: property name ID - check for duplicate ID assignment */ if (strcmp("ID",prop_name) == 0) { start[0] = ex_id_lkup (exoid, obj_type, value); if (exerrval != EX_LOOKUPFAIL) /* found the id */ { exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: attempt to assign duplicate %s ID %d in file id %d", ex_name_of_object(obj_type), value, exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_WARN); } } start[0] = ex_id_lkup (exoid, obj_type, obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no properties allowed for NULL %s id %d in file id %d", ex_name_of_object(obj_type), obj_id,exoid); ex_err("ex_put_prop",errmsg,EX_MSG); return (EX_WARN); } else { sprintf(errmsg, "Error: failed to find value %d in %s property array in file id %d", obj_id, ex_name_of_object(obj_type), exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_FATAL); } } start[0] = start[0] - 1; ldum = (int)value; if ((status = nc_put_var1_int(exoid, propid, start, &ldum)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store property value in file id %d", exoid); ex_err("ex_put_prop",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: nc_set_fill(exoid, oldfill, &temp); /* default: nofill */ 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_prop",errmsg,exerrval); } return (EX_FATAL); }
/*! * writes an element map; this is a vector of integers of length number * of elements */ int ex_put_partial_elem_map (int exoid, int map_id, int ent_start, int ent_count, const int *elem_map) { int status; int dimid, varid, map_ndx, map_exists; size_t start[1]; size_t num_elem_maps, num_elem, count[1]; int cur_num_elem_maps; char *cdum; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ map_exists = 0; cdum = 0; /* Make sure the file contains elements */ if (nc_inq_dimid (exoid, DIM_NUM_ELEM, &dimid) != NC_NOERR ) { return (EX_NOERR); } /* first check if any element maps are specified */ if ((status = nc_inq_dimid(exoid, DIM_NUM_EM, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: no element maps specified in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* Check for duplicate element map id entry */ map_ndx = ex_id_lkup(exoid,EX_ELEM_MAP,map_id); if (exerrval == EX_LOOKUPFAIL) { /* did not find the element map id */ map_exists = 0; /* Map is being defined */ map_ndx = -1; } else { map_exists = 1; /* A portion of this map has already been written */ } if (!map_exists) { /* Get number of element maps initialized for this file */ if ((status = nc_inq_dimlen(exoid,dimid,&num_elem_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of element maps in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* Keep track of the total number of element maps defined using a counter stored in a linked list keyed by exoid. NOTE: ex_get_file_item is used to find the number of element maps for a specific file and returns that value. */ cur_num_elem_maps = ex_get_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP)); if (cur_num_elem_maps >= (int)num_elem_maps) { exerrval = EX_FATAL; sprintf(errmsg, "Error: exceeded number of element maps (%ld) specified in file id %d", (long)num_elem_maps,exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* NOTE: ex_inc_file_item is used to find the number of element maps for a specific file and returns that value incremented. */ cur_num_elem_maps = ex_inc_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP)); } else { cur_num_elem_maps = map_ndx-1; } /* determine number of elements */ if ((status = nc_inq_dimid(exoid, DIM_NUM_ELEM, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: couldn't determine number of elements in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, &num_elem)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of elements in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* Check input parameters for a valid range of numbers */ if (ent_start <= 0 || (size_t)ent_start > num_elem) { exerrval = EX_FATAL; sprintf(errmsg, "Error: start count is invalid in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } if (ent_count < 0) { exerrval = EX_FATAL; sprintf(errmsg, "Error: Invalid count value in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } if ((size_t)(ent_start+ent_count-1) > num_elem) { exerrval = EX_FATAL; sprintf(errmsg, "Error: start+count-1 is larger than element count in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* write out information to previously defined variable */ /* first get id of variable */ if ((status = nc_inq_varid(exoid, VAR_EM_PROP(1), &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate element map ids in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* then, write out element map id */ if (!map_exists) { start[0] = cur_num_elem_maps; if ((status = nc_put_var1_int(exoid, varid, start, &map_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store element map id %d in file id %d", map_id,exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } } /* locate variable array in which to store the element map */ if ((status = nc_inq_varid(exoid,VAR_ELEM_MAP(cur_num_elem_maps+1), &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate element map %d in file id %d", map_id,exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } /* write out the element map */ start[0] = ent_start-1; count[0] = ent_count; status = nc_put_vara_int(exoid, varid, start, count, elem_map); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store element map in file id %d", exoid); ex_err("ex_put_partial_elem_map",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); }
int main(int argc,char *argv[]) { struct DataMap *ptr; struct DataMapScalar *sx,*sy; struct DataMapArray *ax,*ay; size_t index[256]; size_t start[256]; size_t count[256]; int s; unsigned char vbflg=0; unsigned char help=0; unsigned char option=0; unsigned char zflg=0; FILE *fp=NULL; gzFile zfp=0; FILE *mapfp; int n,c,x; int ncid; int block=0; int varid; int strsze; char **strptr; char *tmpbuf=NULL; OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"vb",'x',&vbflg); OptionAdd(&opt,"z",'x',&zflg); if (argc>1) { arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if (zflg) { zfp=gzopen(argv[arg],"r"); if (zfp==0) { fprintf(stderr,"File not found.\n"); exit(-1); } } else { fp=fopen(argv[arg],"r"); if (fp==NULL) { fprintf(stderr,"File not found.\n"); exit(-1); } } } else { OptionPrintInfo(stdout,errstr); exit(-1); } /* load the map */ mapfp=fopen(argv[arg+1],"r"); loadmap(mapfp); fclose(mapfp); s=nc_open(argv[arg+2],NC_WRITE,&ncid); if (s !=NC_NOERR) { fprintf(stderr,"Error opening CDF file.\n"); exit(-1); } block=0; while (1) { if (zflg) ptr=DataMapReadZ(zfp); else ptr=DataMapFread(fp); if (ptr==NULL) break; for (c=0;c<ptr->snum;c++) { sx=ptr->scl[c]; for (n=0;n<snum;n++) { sy=sptr[n]; if (strcmp(sx->name,sy->name) !=0) continue; if (sx->type !=sy->type) continue; break; } if (n !=snum) { /* mapped variable */ s=nc_inq_varid(ncid,cdfsname[n],&varid); if (s !=NC_NOERR) { fprintf(stderr,"Error accessing CDF file.\n"); exit(-1); } index[0]=block; switch (sx->type) { case DATACHAR: s=nc_put_var1_text(ncid,varid,index,sx->data.cptr); break; case DATASHORT: s=nc_put_var1_short(ncid,varid,index,sx->data.sptr); break; case DATAINT: s=nc_put_var1_int(ncid,varid,index,sx->data.iptr); break; case DATAFLOAT: s=nc_put_var1_float(ncid,varid,index,sx->data.fptr); break; case DATADOUBLE: s=nc_put_var1_double(ncid,varid,index,sx->data.dptr); break; case DATASTRING: start[0]=block; start[1]=0; count[0]=1; count[1]=strlen(*((char **) sx->data.vptr))+1; s=nc_put_vara_text(ncid,varid,start,count, *((char **) sx->data.vptr)); break; } if (s !=NC_NOERR) { fprintf(stderr,"Error writing CDF file (%d).\n",s); exit(-1); } } } for (c=0;c<ptr->anum;c++) { ax=ptr->arr[c]; for (n=0;n<anum;n++) { ay=aptr[n]; if (strcmp(ax->name,ay->name) !=0) continue; if (ax->type !=ay->type) continue; if (ax->dim !=ay->dim) continue; break; } if (n !=anum) { /* mapped variable */ s=nc_inq_varid(ncid,cdfaname[n],&varid); if (s !=NC_NOERR) { fprintf(stderr,"Error accessing CDF file.\n"); exit(-1); } start[0]=block; count[0]=1; n=1; for (x=0;x<ax->dim;x++) { start[1+x]=0; count[1+x]=ax->rng[x]; n=n*ax->rng[x]; } if (ax->type==DATASTRING) { int ndims; int dimids[NC_MAX_VAR_DIMS]; size_t dimlen; s=nc_inq_varndims(ncid,varid,&ndims); if (s !=NC_NOERR) { fprintf(stderr,"Error accessing CDF file.\n"); exit(-1); } s=nc_inq_vardimid(ncid,varid,dimids); if (s !=NC_NOERR) { fprintf(stderr,"Error accessing CDF file.\n"); exit(-1); } if (ndims-2!=ax->dim) { fprintf(stderr,"Error matching dimensions.\n"); exit(-1); } s=nc_inq_dimlen(ncid,dimids[ndims-1],&dimlen); if (s !=NC_NOERR) { fprintf(stderr,"Error accessing CDF file.\n"); exit(-1); } strsze=dimlen; tmpbuf=malloc(n*strsze); if (tmpbuf==NULL) { fprintf(stderr,"Failed to allocate buffer.\n"); exit(-1); } memset(tmpbuf,0,n*strsze); start[1+ax->dim]=0; count[1+ax->dim]=strsze; strptr=(char **) ax->data.vptr; for (x=0;x<n;x++) strncpy(tmpbuf+x*strsze,strptr[x],strsze); } switch (ax->type) { case DATACHAR: s=nc_put_vara_text(ncid,varid,start,count,ax->data.cptr); break; case DATASHORT: s=nc_put_vara_short(ncid,varid,start,count,ax->data.sptr); break; case DATAINT: s=nc_put_vara_int(ncid,varid,start,count,ax->data.iptr); break; case DATAFLOAT: s=nc_put_vara_float(ncid,varid,start,count,ax->data.fptr); break; case DATADOUBLE: s=nc_put_vara_double(ncid,varid,start,count,ax->data.dptr); break; case DATASTRING: s=nc_put_vara_text(ncid,varid,start,count,tmpbuf); break; } if (tmpbuf !=NULL) { free(tmpbuf); tmpbuf=NULL; } if (s !=NC_NOERR) { fprintf(stderr,"Error writing CDF file (%d).\n",s); exit(-1); } } } DataMapFree(ptr); block++; } nc_close(ncid); if (zflg) gzclose(zfp); else fclose(fp); return 0; }
int extract_unary_single(int mpi_rank,int mpi_size, int ncid,int vlid,int ncidout,int vlidout,int ndims,nc_type vtype,size_t *shape,size_t *begins,size_t *ends, ptrdiff_t *strides,size_t preLen,size_t *outLen){ int i,j,res; size_t *divider=(size_t *)malloc(sizeof(size_t)*ndims); //input divider size_t *dividerOut=(size_t *)malloc(sizeof(size_t)*ndims); // output divider size_t *start=(size_t*)malloc(sizeof(size_t)*ndims); //start position for reading element from input file size_t *startOut=(size_t*)malloc(sizeof(size_t)*ndims); //start position for writing element to output file size_t *shapeOut=(size_t*)malloc(sizeof(size_t)*ndims); //output dimension shape int lenOut=1; for(i=0;i<ndims;++i){ shapeOut[i]=(ends[i]-begins[i])/strides[i]+1; lenOut*=shapeOut[i]; } if(outLen!=NULL) *outLen=lenOut; getDivider(ndims,shape,divider); getDivider(ndims,shapeOut,dividerOut); /* decide element boundary for each mpi process */ size_t beginOut; size_t endOut; if(lenOut>=mpi_size){ beginOut=mpi_rank*(lenOut/mpi_size); if(mpi_rank!=mpi_size-1) endOut=(mpi_rank+1)*(lenOut/mpi_size); else endOut=lenOut; }else{ //mpi_size is bigger than lenOut if(mpi_rank<lenOut){ beginOut=mpi_rank; endOut=mpi_rank+1; }else{ beginOut=0; endOut=0; } } printf("mpi_rank %d, beginOut %d, endOut %d\n",mpi_rank,beginOut,endOut); void *data=malloc(sizeof(double)); size_t rem,remIn; for(i=beginOut;i<endOut;++i){ rem=i+preLen; remIn=i; for(j=0;j<ndims;++j){ startOut[j]=rem/dividerOut[j]; start[j]=begins[j]+(remIn/dividerOut[j])*strides[j]; rem=rem%dividerOut[j]; remIn=remIn%dividerOut[j]; } switch(vtype){ case NC_BYTE: if((res=nc_get_var1_uchar(ncid,vlid,start,data))) BAIL(res); if((res=nc_put_var1_uchar(ncidout,vlidout,startOut,(unsigned char *)data))) BAIL(res); break; case NC_CHAR: if((res=nc_get_var1_schar(ncid,vlid,start,(signed char *)data))) BAIL(res); if((res=nc_put_var1_schar(ncidout,vlidout,startOut,(signed char *)data))) BAIL(res); break; case NC_SHORT: if((res=nc_get_var1_short(ncid,vlid,start,data))) BAIL(res); if((res=nc_put_var1_short(ncidout,vlidout,startOut,(short *)data))) BAIL(res); break; case NC_INT: if((res=nc_get_var1_int(ncid,vlid,start,(int *)data))) BAIL(res); if((res=nc_put_var1_int(ncidout,vlidout,startOut,(int *)data))) BAIL(res); break; case NC_FLOAT: if((res=nc_get_var1_float(ncid,vlid,start,data))) BAIL(res); if((res=nc_put_var1_float(ncidout,vlidout,startOut,(float *)data))) BAIL(res); break; case NC_DOUBLE: if((res=nc_get_var1_double(ncid,vlid,start,data))) BAIL(res); if((res=nc_put_var1_double(ncidout,vlidout,startOut,(double *)data))) BAIL(res); break; default: printf("Unknown data type\n"); } } /*free resourses*/ free(divider); free(dividerOut); free(start); free(startOut); free(shapeOut); free(data); return 0; }
int ex_put_cmap_params_cc(int exoid, void_int *node_cmap_ids, void_int *node_cmap_node_cnts, void_int *node_proc_ptrs, void_int *elem_cmap_ids, void_int *elem_cmap_elem_cnts, void_int *elem_proc_ptrs ) { const char *func_name="ex_put_cmap_params_cc"; size_t num_n_comm_maps, num_e_comm_maps, num_procs_in_file; int status, icm, n_varid[2], e_varid[2], iproc; int varid, n_dimid[1], e_dimid[1]; int n_varid_idx, e_varid_idx; int num_icm; size_t start[1], count[1]; size_t ecnt_cmap, ncnt_cmap; long long nl_ecnt_cmap, nl_ncnt_cmap; void_int *n_var_idx = NULL; void_int *e_var_idx = NULL; int nmstat; char errmsg[MAX_ERR_LENGTH]; int format; int index_type, bulk_type; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* See if using NC_FORMAT_NETCDF4 format... */ nc_inq_format(exoid, &format); if ((ex_int64_status(exoid) & EX_BULK_INT64_DB) || (format == NC_FORMAT_NETCDF4)) { index_type = NC_INT64; } else { index_type = NC_INT; } if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { bulk_type = NC_INT64; } else { bulk_type = NC_INT; } /* Get the number of processors in the file */ if ((status = nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &n_dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get dimension ID for \"%s\" in file ID %d", DIM_NUM_PROCS_F, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_procs_in_file)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_PROCS_F, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* * since I cannot get variables while in define mode, I need to * get the cmap information index variables before I go into * define mode */ /* Check to see if there are nodal communications maps in the file */ if (nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &n_dimid[0]) != NC_NOERR) { num_n_comm_maps = 0; } else { if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_n_comm_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in \ file ID %d", DIM_NUM_N_CMAPS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (num_n_comm_maps > 0) { /* Get the variable ID for the comm map index vector */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_INFO_IDX, &n_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* allocate space for the index variable */ if (index_type == NC_INT64) { n_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long)); } else { n_var_idx = malloc((num_procs_in_file + 1) * sizeof(int)); } if (!n_var_idx) { exerrval = EX_MSG; sprintf(errmsg, "Error: insufficient memory to read index variable from file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* and set the last value of the index */ /* get the communication map info index */ if (index_type == NC_INT64) { ((long long*)n_var_idx)[0] = 0; status = nc_get_var_longlong(exoid, n_varid_idx, &((long long*)n_var_idx)[1]); } else { ((int*)n_var_idx)[0] = 0; status = nc_get_var_int(exoid, n_varid_idx, &((int*)n_var_idx)[1]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get variable \"%s\" from file ID %d", VAR_N_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* "if (num_n_comm_maps > 0)" */ /* Check to see if there are elemental communications maps in the file */ if ((status = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &e_dimid[0])) != NC_NOERR) { num_e_comm_maps = 0; } else { if ((status = nc_inq_dimlen(exoid, e_dimid[0], &num_e_comm_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in \ file ID %d", DIM_NUM_E_CMAPS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (num_e_comm_maps > 0) { /* Get the variable ID for the comm map index vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_INFO_IDX, &e_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* allocate space for the index variable */ if (index_type == NC_INT64) { e_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long)); } else { e_var_idx = malloc((num_procs_in_file + 1) * sizeof(int)); } if (!e_var_idx) { exerrval = EX_MSG; sprintf(errmsg, "Error: insufficient memory to read index variable from file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* get the communication map info index */ if (index_type == NC_INT64) { ((long long*)e_var_idx)[0] = 0; status = nc_get_var_longlong(exoid, e_varid_idx, &((long long*)e_var_idx)[1]); } else { ((int*)e_var_idx)[0] = 0; status = nc_get_var_int(exoid, e_varid_idx, &((int*)e_var_idx)[1]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get variable \"%s\" from file ID %d", VAR_E_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* "if (num_e_comm_maps >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(func_name, errmsg, exerrval); return (EX_FATAL); } /* * Add dimensions for the size of the number of nodal * communication maps. */ if (num_n_comm_maps > 0) { /* add the communications data index variable */ if ((status = nc_def_var(exoid, VAR_N_COMM_DATA_IDX, index_type, 1, n_dimid, &n_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* now add up all of the nodal communications maps */ ncnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { if (index_type == NC_INT64) { num_icm = ((int64_t*)n_var_idx)[iproc+1] - ((int64_t*)n_var_idx)[iproc]; } else { num_icm = ((int*)n_var_idx)[iproc+1] - ((int*)n_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { if (ex_int64_status(exoid) & EX_BULK_INT64_API) { ncnt_cmap += ((int64_t*)node_cmap_node_cnts)[((int64_t*)node_proc_ptrs)[iproc]+icm]; } else { ncnt_cmap += ((int*)node_cmap_node_cnts)[((int*)node_proc_ptrs)[iproc]+icm]; } } } if ((status = nc_def_dim(exoid, DIM_NCNT_CMAP, ncnt_cmap, &n_dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension for \"%s\" of size %"ST_ZU" in file ID %d", DIM_NCNT_CMAP, ncnt_cmap, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Define variables for the nodal IDS and processor vectors */ if ((status = nc_def_var(exoid, VAR_N_COMM_NIDS, bulk_type, 1, n_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_NIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_N_COMM_PROC, NC_INT, 1, n_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); } /* End "if (num_n_comm_maps > 0)" */ /* * Add dimensions for the size of the number of elemental * communication maps. */ if (num_e_comm_maps > 0) { /* add the communications data index variable */ if ((status = nc_def_var(exoid, VAR_E_COMM_DATA_IDX, index_type, 1, e_dimid, &e_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* now add up all of the nodal communications maps */ ecnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { if (index_type == NC_INT64) { num_icm = ((int64_t*)e_var_idx)[iproc+1] - ((int64_t*)e_var_idx)[iproc]; } else { num_icm = ((int*)e_var_idx)[iproc+1] - ((int*)e_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { if (ex_int64_status(exoid) & EX_BULK_INT64_API) { ecnt_cmap += ((int64_t*)elem_cmap_elem_cnts)[((int64_t*)elem_proc_ptrs)[iproc]+icm]; } else { ecnt_cmap += ((int*)elem_cmap_elem_cnts)[((int*)elem_proc_ptrs)[iproc]+icm]; } } } /* Add dimensions for elemental communications maps */ if ((status = nc_def_dim(exoid, DIM_ECNT_CMAP, ecnt_cmap, &e_dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension for \"%s\" in file ID %d", DIM_ECNT_CMAP, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Define variables for the element IDS and processor vectors */ if ((status = nc_def_var(exoid, VAR_E_COMM_EIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_EIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_E_COMM_PROC, NC_INT, 1, e_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_E_COMM_SIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_SIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); } /* End "if (num_e_comm_maps > 0)" */ /* Exit define mode */ ex_leavedef(exoid, func_name); /* Set the status of the nodal communication maps */ if (num_n_comm_maps > 0) { /* need to get the two "n_comm_*" variable ids */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &n_varid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the comm map IDs vector */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &n_varid[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* reset the index variable */ nl_ncnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { size_t proc_ptr; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { proc_ptr = ((int64_t*)node_proc_ptrs)[iproc]; } else { proc_ptr = ((int*)node_proc_ptrs)[iproc]; } if (index_type == NC_INT64) { num_icm = ((int64_t*)n_var_idx)[iproc+1] - ((int64_t*)n_var_idx)[iproc]; } else { num_icm = ((int*)n_var_idx)[iproc+1] - ((int*)n_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { size_t cnt; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { cnt = ((int64_t*)node_cmap_node_cnts)[proc_ptr+icm]; } else { cnt = ((int*)node_cmap_node_cnts)[proc_ptr+icm]; } if (index_type == NC_INT64) { start[0] = ((int64_t*)n_var_idx)[iproc] + icm; } else { start[0] = ((int*)n_var_idx)[iproc] + icm; } if (cnt > 0) { nmstat = 1; } else { nmstat = 0; } if ((status = nc_put_var1_int(exoid, n_varid[0], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* increment to the next starting position */ nl_ncnt_cmap += cnt; /* fill the data index variable */ status = nc_put_var1_longlong(exoid, n_varid_idx, start, &nl_ncnt_cmap); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "for(icm=0; icm < num_icm; icm++)" */ if (num_icm > 0) { /* Output the nodal comm map IDs */ if (index_type == NC_INT64) { start[0] = ((int64_t*)n_var_idx)[iproc]; } else { start[0] = ((int*)n_var_idx)[iproc]; } count[0] = num_icm; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_vara_longlong(exoid, n_varid[1], start, count, &((long long*)node_cmap_ids)[proc_ptr]); } else { status = nc_put_vara_int(exoid, n_varid[1], start, count, &((int*)node_cmap_ids)[proc_ptr]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */ /* free up memory for index */ free(n_var_idx); } /* End "if (num_n_comm_maps > 0)" */ /* Set the status of the elemental communication maps */ if (num_e_comm_maps > 0) { /* need to get the two "e_comm_*" variables" */ /* Get variable ID for elemental status vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &e_varid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the elemental comm map IDs vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &e_varid[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* reset the index variable */ nl_ecnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { size_t proc_ptr; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { proc_ptr = ((int64_t*)elem_proc_ptrs)[iproc]; } else { proc_ptr = ((int*)elem_proc_ptrs)[iproc]; } if (index_type == NC_INT64) { num_icm = ((int64_t*)e_var_idx)[iproc+1] - ((int64_t*)e_var_idx)[iproc]; } else { num_icm = ((int*)e_var_idx)[iproc+1] - ((int*)e_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { size_t cnt; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { cnt = ((int64_t*)elem_cmap_elem_cnts)[proc_ptr+icm]; } else { cnt = ((int*)elem_cmap_elem_cnts)[proc_ptr+icm]; } if (index_type == NC_INT64) { start[0] = ((int64_t*)e_var_idx)[iproc] + icm; } else { start[0] = ((int*)e_var_idx)[iproc] + icm; } if (cnt > 0) { nmstat = 1; } else { nmstat = 0; } if ((status = nc_put_var1_int(exoid, e_varid[0], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* increment to the next starting position */ nl_ecnt_cmap += cnt; /* fill the data index variable */ status = nc_put_var1_longlong(exoid, e_varid_idx, start, &nl_ecnt_cmap); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "for(icm=0; icm < num_icm; icm++)" */ if (num_icm > 0) { /* Output the elemental comm map IDs */ if (index_type == NC_INT64) { start[0] = ((int64_t*)e_var_idx)[iproc]; } else { start[0] = ((int*)e_var_idx)[iproc]; } count[0] = num_icm; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_vara_longlong(exoid, e_varid[1], start, count, &((long long*)elem_cmap_ids)[proc_ptr]); } else { status = nc_put_vara_int(exoid, e_varid[1], start, count, &((int*)elem_cmap_ids)[proc_ptr]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */ free(e_var_idx); } /* End "if (num_e_comm_maps > 0)" */ return (EX_NOERR); }
int mov_session::save() { int ierr,ncid,i; int dimid_ntimeseries,dimid_one; int varid_filename,varid_colors,varid_units,varid_names; int varid_xshift,varid_yshift,varid_type,varid_coldstart; int varid_stationfile,varid_plottitle,varid_xlabel,varid_ylabel; int varid_startdate,varid_enddate,varid_precision,varid_ymin,varid_ymax; int varid_autodate,varid_autoy,varid_checkState; int dims_1d[1]; int nTimeseries; QString relPath,TempFile,Directory,tempString; QByteArray tempByte; size_t start[1]; size_t iu; double mydatadouble[1]; int mydataint[1]; const char * mydatastring[1]; QFile Session(this->sessionFileName); QVector<QString> filenames_ts; QVector<QString> filetype_ts; QVector<QString> colors_ts; QVector<double> units_ts; QVector<QString> seriesname_ts; QVector<double> xshift_ts; QVector<double> yshift_ts; QVector<QString> date_ts; QVector<QString> stationfile_ts; QVector<int> checkStates_ts; //Remove the old file if(Session.exists()) Session.remove(); //Get the path of the session file so we can save a relative path later mov_generic::splitPath(this->sessionFileName,TempFile,Directory); QDir CurrentDir(Directory); ierr = mov_generic::NETCDF_ERR(nc_create(this->sessionFileName.toUtf8(),NC_NETCDF4,&ncid)); if(ierr!=NC_NOERR)return 1; //Start setting up the definitions nTimeseries = this->tableWidget->rowCount(); filenames_ts.resize(nTimeseries); colors_ts.resize(nTimeseries); units_ts.resize(nTimeseries); seriesname_ts.resize(nTimeseries); xshift_ts.resize(nTimeseries); yshift_ts.resize(nTimeseries); date_ts.resize(nTimeseries); stationfile_ts.resize(nTimeseries); filetype_ts.resize(nTimeseries); checkStates_ts.resize(nTimeseries); for(i=0;i<nTimeseries;i++) { filenames_ts[i] = this->tableWidget->item(i,6)->text(); seriesname_ts[i] = this->tableWidget->item(i,1)->text(); colors_ts[i] = this->tableWidget->item(i,2)->text(); units_ts[i] = this->tableWidget->item(i,3)->text().toDouble(); xshift_ts[i] = this->tableWidget->item(i,4)->text().toDouble(); yshift_ts[i] = this->tableWidget->item(i,5)->text().toDouble(); date_ts[i] = this->tableWidget->item(i,7)->text(); filetype_ts[i] = this->tableWidget->item(i,8)->text(); stationfile_ts[i] = this->tableWidget->item(i,10)->text(); if(this->tableWidget->item(i,0)->checkState()==Qt::Checked) checkStates_ts[i] = 1; else checkStates_ts[i] = 0; } ierr = mov_generic::NETCDF_ERR(nc_def_dim(ncid,"ntimeseries",static_cast<size_t>(nTimeseries),&dimid_ntimeseries)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_dim(ncid,"one",1,&dimid_one)); if(ierr!=NC_NOERR)return 1; //Arrays dims_1d[0] = dimid_ntimeseries; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_filename",NC_STRING,1,dims_1d,&varid_filename)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_colors",NC_STRING,1,dims_1d,&varid_colors)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_names",NC_STRING,1,dims_1d,&varid_names)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_filetype",NC_STRING,1,dims_1d,&varid_type)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_coldstartdate",NC_STRING,1,dims_1d,&varid_coldstart)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_stationfile",NC_STRING,1,dims_1d,&varid_stationfile)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_xshift",NC_DOUBLE,1,dims_1d,&varid_xshift)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_yshift",NC_DOUBLE,1,dims_1d,&varid_yshift)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_units",NC_DOUBLE,1,dims_1d,&varid_units)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_checkState",NC_INT,1,dims_1d,&varid_checkState)); if(ierr!=NC_NOERR)return 1; //Scalars dims_1d[0] = dimid_one; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_plottitle",NC_STRING,1,dims_1d,&varid_plottitle)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_xlabel",NC_STRING,1,dims_1d,&varid_xlabel)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_ylabel",NC_STRING,1,dims_1d,&varid_ylabel)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_precision",NC_INT,1,dims_1d,&varid_precision)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_startdate",NC_STRING,1,dims_1d,&varid_startdate)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_enddate",NC_STRING,1,dims_1d,&varid_enddate)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_ymin",NC_DOUBLE,1,dims_1d,&varid_ymin)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_ymax",NC_DOUBLE,1,dims_1d,&varid_ymax)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_autodate",NC_INT,1,dims_1d,&varid_autodate)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_def_var(ncid,"timeseries_autoy",NC_INT,1,dims_1d,&varid_autoy)); if(ierr!=NC_NOERR)return 1; ierr = mov_generic::NETCDF_ERR(nc_enddef(ncid)); if(ierr!=NC_NOERR)return 1; tempByte = this->plotTitleWidget->text().toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var_string(ncid,varid_plottitle,mydatastring)); if(ierr!=NC_NOERR)return 1; tempByte = this->xLabelWidget->text().toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var_string(ncid,varid_xlabel,mydatastring)); if(ierr!=NC_NOERR)return 1; tempByte = this->yLabelWidget->text().toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var_string(ncid,varid_ylabel,mydatastring)); if(ierr!=NC_NOERR)return 1; tempByte = this->startDateEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss").toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var_string(ncid,varid_startdate,mydatastring)); if(ierr!=NC_NOERR)return 1; tempByte = this->endDateEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss").toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var_string(ncid,varid_enddate,mydatastring)); if(ierr!=NC_NOERR)return 1; mydataint[0] = 3; ierr = mov_generic::NETCDF_ERR(nc_put_var_int(ncid,varid_precision,mydataint)); if(ierr!=NC_NOERR)return 1; mydatadouble[0] = this->yMinSpinBox->value(); ierr = mov_generic::NETCDF_ERR(nc_put_var_double(ncid,varid_ymin,mydatadouble)); if(ierr!=NC_NOERR)return 1; mydatadouble[0] = this->yMaxSpinBox->value(); ierr = mov_generic::NETCDF_ERR(nc_put_var_double(ncid,varid_ymax,mydatadouble)); if(ierr!=NC_NOERR)return 1; if(this->checkAllData->isChecked()) mydataint[0] = 1; else mydataint[0] = 0; ierr = mov_generic::NETCDF_ERR(nc_put_var_int(ncid,varid_autodate,mydataint)); if(ierr!=NC_NOERR)return 1; if(this->checkYAuto->isChecked()) mydataint[0] = 1; else mydataint[0] = 0; ierr = mov_generic::NETCDF_ERR(nc_put_var_int(ncid,varid_autoy,mydataint)); if(ierr!=NC_NOERR)return 1; for(iu=0;iu<static_cast<unsigned int>(nTimeseries);iu++) { start[0] = iu; relPath = CurrentDir.relativeFilePath(filenames_ts[iu]); tempByte = relPath.toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var1_string(ncid,varid_filename,start,mydatastring)); if(ierr!=NC_NOERR)return 1; mydatastring[0] = NULL; tempString = seriesname_ts[iu]; tempByte = tempString.toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var1_string(ncid,varid_names,start,mydatastring)); if(ierr!=NC_NOERR)return 1; mydatastring[0] = NULL; tempByte = colors_ts[iu].toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var1_string(ncid,varid_colors,start,mydatastring)); if(ierr!=NC_NOERR)return 1; mydatastring[0] = NULL; tempByte = date_ts[iu].toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var1_string(ncid,varid_coldstart,start,mydatastring)); if(ierr!=NC_NOERR)return 1; mydatastring[0] = NULL; relPath = CurrentDir.relativeFilePath(stationfile_ts[iu]); tempByte = relPath.toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var1_string(ncid,varid_stationfile,start,mydatastring)); if(ierr!=NC_NOERR)return 1; mydatastring[0] = NULL; tempByte = filetype_ts[iu].toUtf8(); mydatastring[0] = tempByte.data(); ierr = mov_generic::NETCDF_ERR(nc_put_var1_string(ncid,varid_type,start,mydatastring)); if(ierr!=NC_NOERR)return 1; mydatastring[0] = NULL; mydatadouble[0] = xshift_ts[iu]; ierr = mov_generic::NETCDF_ERR(nc_put_var1_double(ncid,varid_xshift,start,mydatadouble)); if(ierr!=NC_NOERR)return 1; mydatadouble[0] = yshift_ts[iu]; ierr = mov_generic::NETCDF_ERR(nc_put_var1_double(ncid,varid_yshift,start,mydatadouble)); if(ierr!=NC_NOERR)return 1; mydatadouble[0] = units_ts[iu]; ierr = mov_generic::NETCDF_ERR(nc_put_var1_double(ncid,varid_units,start,mydatadouble)); if(ierr!=NC_NOERR)return 1; mydataint[0] = checkStates_ts[iu]; ierr = mov_generic::NETCDF_ERR(nc_put_var1_int(ncid,varid_checkState,start,mydataint)); if(ierr!=NC_NOERR)return 1; } ierr = mov_generic::NETCDF_ERR(nc_close(ncid)); if(ierr!=NC_NOERR)return 1; }
int ex_put_init_info(int exoid, int num_proc, int num_proc_in_f, char *ftype) { const char *func_name = "ex_put_init_info"; int dimid, varid; int ltempsv; int lftype; int status; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* Check the file type */ if (!ftype) { exerrval = EX_MSG; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: NULL file type input for file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Set the file type */ if (ftype[0] == 'p' || ftype[0] == 'P') { lftype = 0; } else if (ftype[0] == 's' || ftype[0] == 'S') { lftype = 1; } else { exerrval = EX_MSG; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file type requested for file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Put file into define mode */ if ((status = nc_redef(exoid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file ID %d into define mode", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Define dimension for the number of processors */ if ((status = nc_inq_dimid(exoid, DIM_NUM_PROCS, &dimid)) != NC_NOERR) { ltempsv = num_proc; if ((status = nc_def_dim(exoid, DIM_NUM_PROCS, ltempsv, &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d", DIM_NUM_PROCS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } } /* If this is a parallel file then the status vectors are size 1 */ if (nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &dimid) != NC_NOERR) { ltempsv = num_proc_in_f; if ((status = nc_def_dim(exoid, DIM_NUM_PROCS_F, ltempsv, &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d", DIM_NUM_PROCS_F, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } } /* Output the file type */ if (nc_inq_varid(exoid, VAR_FILE_TYPE, &varid) != NC_NOERR) { if ((status = nc_def_var(exoid, VAR_FILE_TYPE, NC_INT, 0, NULL, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define file type in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } if (ex_leavedef(exoid, func_name) != EX_NOERR) { return (EX_FATAL); } if ((status = nc_put_var1_int(exoid, varid, NULL, &lftype)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to output file type variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } else { if (ex_leavedef(exoid, func_name) != EX_NOERR) { return (EX_FATAL); } } return (EX_NOERR); }
int ex_put_block_params( int exoid, size_t block_count, const struct ex_block *blocks) { size_t i; int conn_int_type; int status; int arbitrary_polyhedra = 0; /* 1 if block is arbitrary 2d polyhedra type; 2 if 3d polyhedra */ int att_name_varid = -1; int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim; size_t start[2]; size_t num_blk; int cur_num_blk, numblkdim, numattrdim; int nnodperentdim = -1; int nedgperentdim = -1; int nfacperentdim = -1; int connid; int npeid; char errmsg[MAX_ERR_LENGTH]; char entity_type1[5]; char entity_type2[5]; int* blocks_to_define = NULL; const char* dnumblk = NULL; const char* vblkids = NULL; const char* vblksta = NULL; const char* vnodcon = NULL; const char* vnpecnt = NULL; const char* vedgcon = NULL; const char* vfaccon = NULL; const char* vconn = NULL; const char* vattnam = NULL; const char* vblkatt = NULL; const char* dneblk = NULL; const char* dnape = NULL; const char* dnnpe = NULL; const char* dnepe = NULL; const char* dnfpe = NULL; exerrval = 0; /* clear error code */ blocks_to_define = malloc(block_count*sizeof(int)); for (i=0; i < block_count; i++) { switch (blocks[i].type) { case EX_EDGE_BLOCK: dnumblk = DIM_NUM_ED_BLK; vblkids = VAR_ID_ED_BLK; vblksta = VAR_STAT_ED_BLK; break; case EX_FACE_BLOCK: dnumblk = DIM_NUM_FA_BLK; vblkids = VAR_ID_FA_BLK; vblksta = VAR_STAT_FA_BLK; break; case EX_ELEM_BLOCK: dnumblk = DIM_NUM_EL_BLK; vblkids = VAR_ID_EL_BLK; vblksta = VAR_STAT_EL_BLK; break; default: exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad block type (%d) specified for entry %d file id %d", blocks[i].type, (int)i, exoid ); ex_err( "ex_put_block_params", errmsg, exerrval ); free(blocks_to_define); return (EX_FATAL); } /* first check if any blocks of that type are specified */ if ((status = ex_get_dimension(exoid, dnumblk, ex_name_of_object(blocks[i].type), &num_blk, &dimid, "ex_put_block_params")) != NC_NOERR) { sprintf(errmsg, "Error: No %ss defined in file id %d", ex_name_of_object(blocks[i].type), exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return EX_FATAL; } /* Next: Make sure that there are not any duplicate block ids by searching the vblkids array. WARNING: This must be done outside of define mode because id_lkup accesses the database to determine the position */ if ((status = nc_inq_varid(exoid, vblkids, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s ids in file id %d", ex_name_of_object(blocks[i].type), exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return EX_FATAL; } ex_id_lkup(exoid,blocks[i].type,blocks[i].id); /* Error value used, but don't need return value */ if (exerrval != EX_LOOKUPFAIL) { /* found the element block id */ exerrval = EX_FATAL; sprintf(errmsg, "Error: %s id %"PRId64" already exists in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return (EX_FATAL); } /* Keep track of the total number of element blocks defined using a counter stored in a linked list keyed by exoid. NOTE: ex_get_file_item is a function that finds the number of element blocks for a specific file and returns that value. */ cur_num_blk=ex_get_file_item(exoid, ex_get_counter_list(blocks[i].type)); if (cur_num_blk >= (int)num_blk) { exerrval = EX_FATAL; sprintf(errmsg, "Error: exceeded number of %ss (%d) defined in file id %d", ex_name_of_object(blocks[i].type), (int)num_blk,exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return (EX_FATAL); } /* NOTE: ex_inc_file_item is a function that finds the number of element blocks for a specific file and returns that value incremented. */ cur_num_blk=ex_inc_file_item(exoid, ex_get_counter_list(blocks[i].type)); start[0] = cur_num_blk; /* write out block id to previously defined id array variable*/ status = nc_put_var1_longlong(exoid, varid, start, (long long*)&blocks[i].id); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s id to file id %d", ex_name_of_object(blocks[i].type), exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return (EX_FATAL); } blocks_to_define[i] = start[0]+1; /* element id index into vblkids array*/ if (blocks[i].num_entry == 0) /* Is this a NULL element block? */ blk_stat = 0; /* change element block status to NULL */ else blk_stat = 1; /* change element block status to EX_EX_TRUE */ if ((status = nc_inq_varid (exoid, vblksta, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s status in file id %d", ex_name_of_object(blocks[i].type), exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return (EX_FATAL); } if ((status = nc_put_var1_int(exoid, varid, start, &blk_stat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s id %"PRId64" status to file id %d", ex_name_of_object(blocks[i].type), blocks[i].id, exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return (EX_FATAL); } } /* put netcdf file into define mode */ if ((status=nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid); ex_err("ex_put_block_params",errmsg,exerrval); free(blocks_to_define); return (EX_FATAL); } for (i=0; i < block_count; i++) { if (blocks[i].num_entry == 0) {/* Is this a NULL element block? */ continue; } blk_id_ndx = blocks_to_define[i]; switch (blocks[i].type) { case EX_EDGE_BLOCK: dneblk = DIM_NUM_ED_IN_EBLK(blk_id_ndx); dnnpe = DIM_NUM_NOD_PER_ED(blk_id_ndx); dnepe = 0; dnfpe = 0; dnape = DIM_NUM_ATT_IN_EBLK(blk_id_ndx); vblkatt = VAR_EATTRIB(blk_id_ndx); vattnam = VAR_NAME_EATTRIB(blk_id_ndx); vnodcon = VAR_EBCONN(blk_id_ndx); vedgcon = 0; vfaccon = 0; break; case EX_FACE_BLOCK: dneblk = DIM_NUM_FA_IN_FBLK(blk_id_ndx); dnnpe = DIM_NUM_NOD_PER_FA(blk_id_ndx); dnepe = 0; dnfpe = 0; dnape = DIM_NUM_ATT_IN_FBLK(blk_id_ndx); vblkatt = VAR_FATTRIB(blk_id_ndx); vattnam = VAR_NAME_FATTRIB(blk_id_ndx); vnodcon = VAR_FBCONN(blk_id_ndx); vnpecnt = VAR_FBEPEC(blk_id_ndx); vedgcon = 0; vfaccon = 0; break; case EX_ELEM_BLOCK: dneblk = DIM_NUM_EL_IN_BLK(blk_id_ndx); dnnpe = DIM_NUM_NOD_PER_EL(blk_id_ndx); dnepe = DIM_NUM_EDG_PER_EL(blk_id_ndx); dnfpe = DIM_NUM_FAC_PER_EL(blk_id_ndx); dnape = DIM_NUM_ATT_IN_BLK(blk_id_ndx); vblkatt = VAR_ATTRIB(blk_id_ndx); vattnam = VAR_NAME_ATTRIB(blk_id_ndx); vnodcon = VAR_CONN(blk_id_ndx); vnpecnt = VAR_EBEPEC(blk_id_ndx); vedgcon = VAR_ECONN(blk_id_ndx); vfaccon = VAR_FCONN(blk_id_ndx); break; default: goto error_ret; } /* define some dimensions and variables*/ if ((status = nc_def_dim(exoid,dneblk,blocks[i].num_entry, &numblkdim )) != NC_NOERR) { if (status == NC_ENAMEINUSE) { /* duplicate entry */ exerrval = status; sprintf(errmsg, "Error: %s %"PRId64" already defined in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to define number of entities/block for %s %"PRId64" file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } if ( dnnpe && blocks[i].num_nodes_per_entry > 0) { /* A nfaced block would not have any nodes defined... */ if ((status = nc_def_dim(exoid,dnnpe,blocks[i].num_nodes_per_entry, &nnodperentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of nodes/entity for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (dnepe && blocks[i].num_edges_per_entry > 0 ) { if ((status = nc_def_dim (exoid,dnepe,blocks[i].num_edges_per_entry, &nedgperentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of edges/entity for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if ( dnfpe && blocks[i].num_faces_per_entry > 0 ) { if ((status = nc_def_dim(exoid,dnfpe,blocks[i].num_faces_per_entry, &nfacperentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of faces/entity for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } /* element attribute array */ if (blocks[i].num_attribute > 0) { if ((status = nc_def_dim(exoid, dnape, blocks[i].num_attribute, &numattrdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of attributes in %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } dims[0] = numblkdim; dims[1] = numattrdim; if ((status = nc_def_var(exoid, vblkatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define attributes for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, varid, 2); /* inquire previously defined dimensions */ if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get string length in file id %d",exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; } /* Attribute names... */ dims[0] = numattrdim; dims[1] = strdim; if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &att_name_varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define %s attribute name array in file id %d", ex_name_of_object(blocks[i].type), exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } conn_int_type = NC_INT; if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { conn_int_type = NC_INT64; } /* See if storing an 'nsided' element block (arbitrary 2d polyhedra or super element) */ if (strlen(blocks[i].topology) >= 3) { if ((blocks[i].topology[0] == 'n' || blocks[i].topology[0] == 'N') && (blocks[i].topology[1] == 's' || blocks[i].topology[1] == 'S') && (blocks[i].topology[2] == 'i' || blocks[i].topology[2] == 'I')) arbitrary_polyhedra = 1; else if ((blocks[i].topology[0] == 'n' || blocks[i].topology[0] == 'N') && (blocks[i].topology[1] == 'f' || blocks[i].topology[1] == 'F') && (blocks[i].topology[2] == 'a' || blocks[i].topology[2] == 'A')) /* If a FACE_BLOCK, then we are dealing with the faces of the nfaced blocks[i]. */ arbitrary_polyhedra = blocks[i].type == EX_FACE_BLOCK ? 1 : 2; } /* element connectivity array */ if (arbitrary_polyhedra > 0) { if (blocks[i].type != EX_FACE_BLOCK && blocks[i].type != EX_ELEM_BLOCK) { exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad block type (%d) for nsided/nfaced block in file id %d", blocks[i].type, exoid ); ex_err( "ex_put_block_params", errmsg, exerrval ); goto error_ret; } if (arbitrary_polyhedra == 1) { dims[0] = nnodperentdim; vconn = vnodcon; /* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/ strcpy(entity_type1, "NODE"); if (blocks[i].type == EX_ELEM_BLOCK) strcpy(entity_type2, "ELEM"); else strcpy(entity_type2, "FACE"); } else if (arbitrary_polyhedra == 2) { dims[0] = nfacperentdim; vconn = vfaccon; /* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/ strcpy(entity_type1, "FACE"); strcpy(entity_type2, "ELEM"); } if ((status = nc_def_var(exoid, vconn, conn_int_type, 1, dims, &connid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create connectivity array for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* element face-per-element or node-per-element count array */ dims[0] = numblkdim; if ((status = nc_def_var(exoid, vnpecnt, conn_int_type, 1, dims, &npeid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create face- or node- per-entity count array for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id, exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_put_att_text(exoid, npeid, "entity_type1", strlen(entity_type1)+1, entity_type1)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store entity type attribute text for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id, exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_put_att_text(exoid, npeid, "entity_type2", strlen(entity_type2)+1, entity_type2)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store entity type attribute text for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id, exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } else { /* "Normal" (non-polyhedra) element block type */ dims[0] = numblkdim; dims[1] = nnodperentdim; if ((status = nc_def_var(exoid, vnodcon, conn_int_type, 2, dims, &connid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create connectivity array for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, connid, 1); } /* store element type as attribute of connectivity variable */ if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(blocks[i].topology)+1, blocks[i].topology)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s type name %s in file id %d", ex_name_of_object(blocks[i].type), blocks[i].topology,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if (arbitrary_polyhedra == 0) { if (vedgcon && blocks[i].num_edges_per_entry ) { dims[0] = numblkdim; dims[1] = nedgperentdim; if ((status = nc_def_var(exoid, vedgcon, conn_int_type, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create edge connectivity array for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if ( vfaccon && blocks[i].num_faces_per_entry ) { dims[0] = numblkdim; dims[1] = nfacperentdim; if ((status = nc_def_var(exoid, vfaccon, conn_int_type, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create face connectivity array for %s %"PRId64" in file id %d", ex_name_of_object(blocks[i].type), blocks[i].id,exoid); ex_err("ex_put_block_params",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } } } free(blocks_to_define); /* leave define mode */ if ((exerrval=nc_enddef (exoid)) != NC_NOERR) { sprintf(errmsg, "Error: failed to complete %s definition in file id %d", ex_name_of_object(blocks[i].type), exoid); ex_err("ex_put_block_params",errmsg,exerrval); return (EX_FATAL); } for (i=0; i < block_count; i++) { switch (blocks[i].type) { case EX_EDGE_BLOCK: vblkids = VAR_ID_ED_BLK; break; case EX_FACE_BLOCK: vblkids = VAR_ID_FA_BLK; break; case EX_ELEM_BLOCK: vblkids = VAR_ID_EL_BLK; break; default: return (EX_FATAL); /* should have been handled earlier; quiet compiler here */ } nc_inq_varid(exoid, vblkids, &att_name_varid); if (blocks[i].num_attribute > 0 && att_name_varid >= 0) { /* Output a dummy empty attribute name in case client code doesn't write anything; avoids corruption in some cases. */ size_t count[2]; char *text = ""; size_t j; count[0] = 1; start[1] = 0; count[1] = strlen(text)+1; for (j = 0; j < blocks[i].num_attribute; j++) { start[0] = j; nc_put_vara_text(exoid, att_name_varid, start, count, text); } } } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: free(blocks_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_block_params",errmsg,exerrval); } return (EX_FATAL); }
int ex_put_cmap_params(int exoid, void_int *node_cmap_ids, void_int *node_cmap_node_cnts, void_int *elem_cmap_ids, void_int *elem_cmap_elem_cnts, int64_t processor ) { const char *func_name="ex_put_cmap_params"; size_t num_n_comm_maps, num_e_comm_maps; size_t ncnt_cmap, ecnt_cmap; size_t icm; int varid, dimid[1], n_varid, e_varid, status; int n_varid_idx, e_varid_idx; size_t start[1]; char ftype[2]; int64_t nl_ncnt_cmap, nl_ecnt_cmap; int nmstat; char errmsg[MAX_ERR_LENGTH]; int index_type = NC_INT; int id_type = NC_INT; int format; nc_inq_format(exoid, &format); if ((ex_int64_status(exoid) & EX_BULK_INT64_DB) || (format == NC_FORMAT_NETCDF4)) { index_type = NC_INT64; } if (ex_int64_status(exoid) & EX_IDS_INT64_DB) { id_type = NC_INT64; } /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* ** with the new database format, this function sould only ** be used for writing a parallel file */ /* Get the file type */ if (ex_get_file_type(exoid, ftype) != EX_NOERR) { exerrval = EX_MSG; sprintf(errmsg, "Error: failed to get file type from file ID %d\n", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* make sure that this is a parallel file */ if (ftype[0] != 'p') { exerrval = EX_MSG; sprintf(errmsg, "Error: function for use with parallel files only, file ID %d\n", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Put NetCDF file into define mode */ if ((status = nc_redef(exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to file ID %d into define mode", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Check to see if there are nodal communications maps in the file */ if ((status = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &dimid[0])) != NC_NOERR) { num_n_comm_maps = 0; } else { if ((status = nc_inq_dimlen(exoid, dimid[0], &num_n_comm_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_N_CMAPS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* * Add dimensions for the size of the number of nodal * communication maps. */ if (num_n_comm_maps > 0) { /* add the communications data index variable */ if ((status = nc_def_var(exoid, VAR_N_COMM_DATA_IDX, index_type, 1, dimid, &n_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Add dimensions for all of the nodal communication maps */ ncnt_cmap = 0; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { for(icm=0; icm < num_n_comm_maps; icm++) { ncnt_cmap += ((int64_t*)node_cmap_node_cnts)[icm]; } } else { for(icm=0; icm < num_n_comm_maps; icm++) { ncnt_cmap += ((int*)node_cmap_node_cnts)[icm]; } } if ((status = nc_def_dim(exoid, DIM_NCNT_CMAP, ncnt_cmap, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension for \"%s\" in file ID %d", DIM_NCNT_CMAP, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Define variables for the nodal IDS and processor vectors */ if ((status = nc_def_var(exoid, VAR_N_COMM_NIDS, id_type, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_NIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_N_COMM_PROC, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); } /* End "if (num_n_comm_maps > 0)" */ /* Check to see if there are elemental communications maps in the file */ if ((status = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &dimid[0])) != NC_NOERR) { num_e_comm_maps = 0; } else{ if ((status = nc_inq_dimlen(exoid, dimid[0], &num_e_comm_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_E_CMAPS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* * Add dimensions for the size of the number of elemental * communication maps. */ if (num_e_comm_maps > 0) { /* add the communications data index variable */ if ((status = nc_def_var(exoid, VAR_E_COMM_DATA_IDX, index_type, 1, dimid, &e_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Add dimensions for each of the nodal communication maps */ ecnt_cmap = 0; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { for(icm=0; icm < num_e_comm_maps; icm++) ecnt_cmap += ((int64_t*)elem_cmap_elem_cnts)[icm]; } else { for(icm=0; icm < num_e_comm_maps; icm++) ecnt_cmap += ((int*)elem_cmap_elem_cnts)[icm]; } if ((status = nc_def_dim(exoid, DIM_ECNT_CMAP, ecnt_cmap, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension for \"%s\" in file ID %d", DIM_ECNT_CMAP, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Define variables for the element IDS and processor vectors */ if ((status = nc_def_var(exoid, VAR_E_COMM_EIDS, id_type, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_EIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_E_COMM_PROC, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_E_COMM_SIDS, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_SIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); } /* End "if (num_e_comm_maps > 0)" */ /* Exit define mode */ ex_leavedef(exoid, func_name); /* Set the status of the nodal communication maps */ if (num_n_comm_maps > 0) { if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &n_varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } nl_ncnt_cmap = 0; /* reset this for index */ for(icm=0; icm < num_n_comm_maps; icm++) { size_t ncnc; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { ncnc = ((int64_t*)node_cmap_node_cnts)[icm]; } else { ncnc = ((int*)node_cmap_node_cnts)[icm]; } start[0] = icm; if (ncnc > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(exoid, n_varid, start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* increment to the next starting position */ nl_ncnt_cmap += ncnc; /* fill the cmap data index */ if ((status = nc_put_var1_longlong(exoid, n_varid_idx, start, (long long*)&nl_ncnt_cmap)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "for(icm=0; icm < num_n_comm_maps; icm++)" */ /* Get the variable ID for the comm map IDs vector */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &n_varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the nodal comm map IDs */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, n_varid, node_cmap_ids); } else { status = nc_put_var_int(exoid, n_varid, node_cmap_ids); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (num_n_comm_maps > 0)" */ /* Set the status of the elemental communication maps */ if (num_e_comm_maps > 0) { /* Get variable ID for elemental status vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &e_varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } nl_ecnt_cmap = 0; /* reset this for index */ for(icm=0; icm < num_e_comm_maps; icm++) { size_t ecec; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { ecec = ((int64_t*)elem_cmap_elem_cnts)[icm]; } else { ecec = ((int*)elem_cmap_elem_cnts)[icm]; } start[0] = icm; if (ecec > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(exoid, e_varid, start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* increment to the next starting position */ nl_ecnt_cmap += ecec; /* fill the cmap data index */ if ((status = nc_put_var1_longlong(exoid, e_varid_idx, start, (long long*)&nl_ecnt_cmap)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "for(icm=0; icm < num_e_comm_maps; icm++)" */ /* Get the variable ID for the elemental comm map IDs vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &e_varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the elemental comm map IDs */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, e_varid, elem_cmap_ids); } else { status = nc_put_var_int(exoid, e_varid, elem_cmap_ids); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (num_e_comm_maps > 0)" */ return (EX_NOERR); }
int ex_put_num_map ( int exoid, ex_entity_type map_type, int map_id, const int *map ) { int dimid, varid; size_t start[1]; int ldum; int num_maps; size_t num_entries; int cur_num_maps; char errmsg[MAX_ERR_LENGTH]; const char* dnumentries; const char* dnummaps; const char* vmapids; const char* vmap; int status; exerrval = 0; /* clear error code */ switch ( map_type ) { case EX_NODE_MAP: dnumentries = DIM_NUM_NODES; dnummaps = DIM_NUM_NM; vmapids = VAR_NM_PROP(1); break; case EX_EDGE_MAP: dnumentries = DIM_NUM_EDGE; dnummaps = DIM_NUM_EDM; vmapids = VAR_EDM_PROP(1); break; case EX_FACE_MAP: dnumentries = DIM_NUM_FACE; dnummaps = DIM_NUM_FAM; vmapids = VAR_FAM_PROP(1); break; case EX_ELEM_MAP: dnumentries = DIM_NUM_ELEM; dnummaps = DIM_NUM_EM; vmapids = VAR_EM_PROP(1); break; default: exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad map type (%d) specified for file id %d", map_type, exoid ); ex_err( "ex_put_num_map", errmsg, exerrval ); return (EX_FATAL); } /* Make sure the file contains entries */ if (nc_inq_dimid (exoid, dnumentries, &dimid) != NC_NOERR ) { return (EX_NOERR); } /* first check if any maps are specified */ if ((status = nc_inq_dimid (exoid, dnummaps, &dimid)) != NC_NOERR ) { exerrval = status; sprintf(errmsg, "Error: no %ss specified in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } /* Check for duplicate map id entry */ ex_id_lkup(exoid,map_type,map_id); if (exerrval != EX_LOOKUPFAIL) /* found the map id */ { sprintf(errmsg, "Error: %s %d already defined in file id %d", ex_name_of_object(map_type),map_id,exoid); ex_err("ex_put_num_map",errmsg,exerrval); return(EX_FATAL); } /* Get number of maps initialized for this file */ if ((status = nc_inq_dimlen(exoid,dimid,&num_entries)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of %ss in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } num_maps = num_entries; /* Keep track of the total number of maps defined using a counter stored in a linked list keyed by exoid. NOTE: ex_get_file_item is used to find the number of maps for a specific file and returns that value. */ cur_num_maps = ex_get_file_item(exoid, ex_get_counter_list(map_type)); if (cur_num_maps >= num_maps) { exerrval = EX_FATAL; sprintf(errmsg, "Error: exceeded number of %ss (%d) specified in file id %d", ex_name_of_object(map_type),num_maps,exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } /* NOTE: ex_inc_file_item is used to find the number of maps for a specific file and returns that value incremented. */ cur_num_maps = ex_inc_file_item(exoid, ex_get_counter_list(map_type)); /* write out information to previously defined variable */ /* first get id of variable */ if ((status = nc_inq_varid (exoid, vmapids, &varid)) == -1) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s ids in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } /* then, write out map id */ start[0] = cur_num_maps; ldum = (int)map_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(map_type),map_id,exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } switch ( map_type ) { case EX_NODE_MAP: vmap = VAR_NODE_MAP(cur_num_maps+1); break; case EX_EDGE_MAP: vmap = VAR_EDGE_MAP(cur_num_maps+1); break; case EX_FACE_MAP: vmap = VAR_FACE_MAP(cur_num_maps+1); break; case EX_ELEM_MAP: vmap = VAR_ELEM_MAP(cur_num_maps+1); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized map type in switch: %d in file id %d", map_type,exoid); ex_err("ex_putt_n_one_attr",errmsg,EX_MSG); return (EX_FATAL); } /* locate variable array in which to store the map */ if ((status = nc_inq_varid(exoid,vmap,&varid)) != NC_NOERR) { int dims[2]; /* determine number of entries */ if ((status = nc_inq_dimid (exoid, dnumentries, &dimid)) == -1 ) { exerrval = status; sprintf(errmsg, "Error: couldn't determine number of %s entries in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } status = 0; if ((status = nc_redef( exoid )) != NC_NOERR ) { exerrval = status; sprintf(errmsg, "Error: failed to place file id %d into define mode", exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } dims[0] = dimid; if ((status = nc_def_var( exoid, vmap, NC_INT, 1, dims, &varid )) == -1 ) { exerrval = status; sprintf(errmsg, "Error: failed to define map %s in file id %d", vmap, exoid); ex_err("ex_put_num_map",errmsg,exerrval); } if ((status = nc_enddef(exoid)) != NC_NOERR ) { /* exit define mode */ sprintf( errmsg, "Error: failed to complete definition for file id %d", exoid ); ex_err( "ex_put_num_map", errmsg, exerrval ); varid = -1; /* force early exit */ } if ( varid == -1 ) /* we couldn't define variable and have prepared error message. */ return (EX_FATAL); } /* write out the map */ if ((status = nc_put_var_int(exoid, varid, map)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); }
int main(int argc, char **argv) { int ncid, spockid, kirkid, dimids[NUMDIMS]; int int_val_in, int_val_out = 99; double double_val_in, double_val_out = 1.79769313486230e+308; /* from ncx.h */ size_t index[2] = {QTR_CLASSIC_MAX-1, 0}; /* These are for the revolutionary generals tests. */ int cromwellid, collinsid, washingtonid; int napoleanid, dimids_gen[4], dimids_gen1[4]; /* All create modes will be anded to this. All tests will be run twice, with and without NC_SHARE.*/ int cmode_run; int cflag = NC_CLOBBER; int res; printf("\n*** Testing large files, quickly.\n"); for (cmode_run=0; cmode_run<2; cmode_run++) { /* On second pass, try using NC_SHARE. */ if (cmode_run == 1) { cflag |= NC_SHARE; printf("*** Turned on NC_SHARE for subsequent tests.\n"); } /* Create a netCDF 64-bit offset format file. Write a value. */ printf("*** Creating %s for 64-bit offset large file test...", FILE_NAME); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "longdim", QTR_CLASSIC_MAX, dimids))) ERR; if ((res = nc_def_var(ncid, "spock", NC_DOUBLE, NUMDIMS, dimids, &spockid))) ERR; if ((res = nc_def_var(ncid, "kirk", NC_DOUBLE, NUMDIMS, dimids, &kirkid))) ERR; if ((res = nc_enddef(ncid))) ERR; if ((res = nc_put_var1_double(ncid, kirkid, index, &double_val_out))) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* How about a meteorological data file about the weather experience by various generals of revolutionary armies? This has 3 dims, 4 vars. The dimensions are such that this will (just barely) not fit in a classic format file. The first three vars are cromwell, 536870911 bytes, washington, 2*536870911 bytes, and napolean, 536870911 bytes. That's a grand total of 2147483644 bytes. Recall our magic limit for the combined size of all fixed vars: 2 GiB - 4 bytes, or 2147483644. So you would think these would exactly fit, unless you realized that everything is rounded to a 4 byte boundary, so you need to add some bytes for that (how many?), and that pushes us over the limit. We will create this file twice, once to ensure it succeeds (with 64-bit offset format), and once to make sure it fails (with classic format). Then some variations to check record var boundaries. */ printf("*** Now a 64-bit offset, large file, fixed var test..."); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", QTR_CLASSIC_MAX, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", QTR_CLASSIC_MAX, &dimids_gen[1]))) ERR; if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 1, &dimids_gen[0], &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, &dimids_gen[1], &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 1, &dimids_gen[0], &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], &collinsid))) ERR; if ((res = nc_enddef(ncid))) ERR; printf("ok\n"); /* Write a value or two just for fun. */ /*index[0] = QTR_CLASSIC_MAX - 296; if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out))) ERR; if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in))) ERR; if (int_val_in != int_val_out) BAIL2;*/ printf("*** Now writing some values..."); index[0] = QTR_CLASSIC_MAX - 295; if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out))) ERR; if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in))) ERR; if (int_val_in != int_val_out) ERR; index[0] = QTR_CLASSIC_MAX - 1; if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out))) ERR; if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in))) ERR; if (int_val_in != int_val_out) ERR; index[0] = QTR_CLASSIC_MAX - 1; if ((res = nc_put_var1_int(ncid, washingtonid, index, &int_val_out))) ERR; if ((res = nc_get_var1_int(ncid, washingtonid, index, &int_val_in))) ERR; if (int_val_in != int_val_out) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* This time it should fail, because we're trying to cram this into a classic format file. nc_enddef will detect our violations and give an error. We've*/ printf("*** Now a classic file which will fail..."); if ((res = nc_create(FILE_NAME, cflag, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", QTR_CLASSIC_MAX, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", QTR_CLASSIC_MAX, &dimids_gen[1]))) ERR; if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 1, &dimids_gen[0], &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, &dimids_gen[1], &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 1, &dimids_gen[0], &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], &collinsid))) ERR; if ((res = nc_enddef(ncid)) != NC_EVARSIZE) ERR; if ((res = nc_close(ncid)) != NC_EVARSIZE) ERR; printf("ok\n"); /* This will create some max sized 64-bit offset format fixed vars. */ printf("*** Now a 64-bit offset, simple fixed var create test..."); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[0]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_SHORT, 1, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_SHORT, 1, dimids_gen, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, dimids_gen, &collinsid))) ERR; if ((res = nc_enddef(ncid))) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* This will exceed the 64-bit offset format limits for one of the fixed vars. */ printf("*** Now a 64-bit offset, over-sized file that will fail..."); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; /* max dim size is MAX_CLASSIC_BYTES. */ if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, dimids_gen))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 1, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, dimids_gen, &washingtonid))) if ((res = nc_enddef(ncid)) != NC_EVARSIZE) ERR; if ((res = nc_close(ncid)) != NC_EVARSIZE) ERR; printf("ok\n"); /* Now let's see about record vars. First create a 64-bit offset file with three rec variables, each with the same numbers as defined above for the fixed var tests. This should all work. */ printf("*** Now a 64-bit offset, record var file..."); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", QTR_CLASSIC_MAX, &dimids_gen[1]))) ERR; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", QTR_CLASSIC_MAX, &dimids_gen[2]))) ERR; if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[3]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen, &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], &collinsid))) ERR; if ((res = nc_enddef(ncid))) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* Now try this record file in classic format. It should fail and the enddef. Too many bytes in the first record.*/ printf("*** Now a classic file that's too big and will fail..."); if ((res = nc_create(FILE_NAME, cflag, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", QTR_CLASSIC_MAX, &dimids_gen[1]))) ERR; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", QTR_CLASSIC_MAX, &dimids_gen[2]))) ERR; if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[3]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen, &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], &collinsid))) ERR; if ((res = nc_enddef(ncid)) != NC_EVARSIZE) ERR; if ((res = nc_close(ncid)) != NC_EVARSIZE) ERR; printf("ok\n"); /* Now try this record file in classic format. It just barely passes at the enddef. Almost, but not quite, too many bytes in the first record. Since I'm adding a fixed variable (Collins), I don't get the last record size exemption. */ printf("*** Now a classic file with recs and one fixed will fail..."); if ((res = nc_create(FILE_NAME, cflag, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[1]))) ERR; if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], &collinsid))) ERR; if ((res = nc_enddef(ncid))) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* Try a classic file with several records, and the last record var with a record size greater than our magic number of 2 GiB - 4 bytes. We'll start with just one oversized record var. This should work. Cromwell has been changed to NC_DOUBLE, and that increases his size to 2147483644 (the max dimension size) times 8, or about 16 GB per record. Zowie! (Mind you, Cromwell certainly had a great deal of revolutionary fervor.) */ printf("*** Now a classic file with one large rec var..."); if ((res = nc_create(FILE_NAME, cflag, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[1]))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_enddef(ncid))) ERR; index[0] = 0; index[1] = MAX_CLASSIC_BYTES - 1; if ((res = nc_put_var1_double(ncid, cromwellid, index, &double_val_out))) ERR; if ((res = nc_get_var1_double(ncid, cromwellid, index, &double_val_in))) ERR; if (double_val_in != double_val_out) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* This is a classic format file with an extra-large last record var. */ printf("*** Now a classic file with extra-large last record var..."); if ((res = nc_create(FILE_NAME, cflag, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[1]))) ERR; dimids_gen1[0] = dimids_gen[0]; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 5368, &dimids_gen1[1]))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, &collinsid))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_enddef(ncid))) ERR; index[0] = 0; index[1] = MAX_CLASSIC_BYTES - 1; if ((res = nc_put_var1_double(ncid, cromwellid, index, &double_val_out))) ERR; if ((res = nc_get_var1_double(ncid, cromwellid, index, &double_val_in))) ERR; if (double_val_in != double_val_out) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); /* This is a classic format file with an extra-large second to last record var. But this time it won't work, because the size exemption only applies to the last record var. Note that one dimension is small (5000). */ printf("*** Now a classic file xtra-large 2nd to last var that will fail..."); if ((res = nc_create(FILE_NAME, cflag, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[1]))) ERR; dimids_gen1[0] = dimids_gen[0]; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 5000, &dimids_gen1[1]))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, &collinsid))) ERR; if ((res = nc_enddef(ncid)) != NC_EVARSIZE) ERR; if ((res = nc_close(ncid)) != NC_EVARSIZE) ERR; printf("ok\n"); /* Now try an extra large second to last ver with 64-bit offset. This won't work either, because the cromwell var is so large. It exceeds the 4GiB - 4 byte per record limit for record vars. */ printf("*** Now a 64-bit offset file with too-large rec var that will fail..."); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[1]))) ERR; dimids_gen1[0] = dimids_gen[0]; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 5368, &dimids_gen1[1]))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, &collinsid))) ERR; if ((res = nc_enddef(ncid)) != NC_EVARSIZE) ERR; if ((res = nc_close(ncid)) != NC_EVARSIZE) ERR; printf("ok\n"); /* A 64-bit offset record file that just fits... */ printf("*** Now a 64 bit-offset file that just fits..."); if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid))) ERR; if ((res = nc_set_fill(ncid, NC_NOFILL, NULL))) ERR; if ((res = nc_def_dim(ncid, "political_trouble", NC_UNLIMITED, &dimids_gen[0]))) ERR; if ((res = nc_def_dim(ncid, "revolutionary_fervor", MAX_CLASSIC_BYTES, &dimids_gen[1]))) ERR; dimids_gen1[0] = dimids_gen[0]; if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", MAX_CLASSIC_BYTES, &dimids_gen1[1]))) ERR; if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, &washingtonid))) ERR; if ((res = nc_def_var(ncid, "Napolean", NC_SHORT, 2, dimids_gen1, &napoleanid))) ERR; if ((res = nc_def_var(ncid, "Cromwell", NC_SHORT, 2, dimids_gen, &cromwellid))) ERR; if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, &collinsid))) ERR; if ((res = nc_enddef(ncid))) ERR; index[0] = 0; index[1] = MAX_CLASSIC_BYTES - 1; if ((res = nc_put_var1_int(ncid, cromwellid, index, &int_val_out))) ERR; if ((res = nc_get_var1_int(ncid, cromwellid, index, &int_val_in))) ERR; if (int_val_in != int_val_out) ERR; if ((res = nc_close(ncid))) ERR; printf("ok\n"); } /* end of cmode run */ /* Wow! Everything worked! */ printf("\n*** All large file tests were successful.\n"); /* Delete the huge data file we created. */ (void) remove(FILE_NAME); printf("*** Success ***\n"); return 0; }
int ex_put_block( int exoid, ex_entity_type blk_type, int blk_id, const char* entry_descrip, int num_entries_this_blk, int num_nodes_per_entry, int num_edges_per_entry, int num_faces_per_entry, int num_attr_per_entry ) { int status; int arbitrary_polyhedra = 0; /* 1 if block is arbitrary 2d polyhedra type; 2 if 3d polyhedra */ int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim; size_t start[2]; int num_blk; size_t temp; int cur_num_blk, numblkdim, numattrdim; int nnodperentdim, nedgperentdim, nfacperentdim; int connid; int npeid; char errmsg[MAX_ERR_LENGTH]; char entity_type1[5]; char entity_type2[5]; const char* dnumblk = NULL; const char* vblkids = NULL; const char* vblksta = NULL; const char* vnodcon = NULL; const char* vnpecnt = NULL; const char* vedgcon = NULL; const char* vfaccon = NULL; const char* vconn = NULL; const char* vattnam = NULL; const char* vblkatt = NULL; const char* dneblk = NULL; const char* dnape = NULL; const char* dnnpe = NULL; const char* dnepe = NULL; const char* dnfpe = NULL; exerrval = 0; /* clear error code */ switch (blk_type) { case EX_EDGE_BLOCK: dnumblk = DIM_NUM_ED_BLK; vblkids = VAR_ID_ED_BLK; vblksta = VAR_STAT_ED_BLK; break; case EX_FACE_BLOCK: dnumblk = DIM_NUM_FA_BLK; vblkids = VAR_ID_FA_BLK; vblksta = VAR_STAT_FA_BLK; break; case EX_ELEM_BLOCK: dnumblk = DIM_NUM_EL_BLK; vblkids = VAR_ID_EL_BLK; vblksta = VAR_STAT_EL_BLK; break; default: exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad block type (%d) specified for file id %d", blk_type, exoid ); ex_err( "ex_put_block", errmsg, exerrval ); return (EX_FATAL); } /* first check if any element blocks are specified */ if ((status = ex_get_dimension(exoid, dnumblk, ex_name_of_object(blk_type), &temp, &dimid, "ex_put_block")) != NC_NOERR) { return EX_FATAL; } num_blk = (int)temp; /* Next: Make sure that this is not a duplicate element block id by searching the vblkids array. WARNING: This must be done outside of define mode because id_lkup accesses the database to determine the position */ if ((status = nc_inq_varid(exoid, vblkids, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s ids in file id %d", ex_name_of_object(blk_type), exoid); ex_err("ex_put_block",errmsg,exerrval); } blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id); if (exerrval != EX_LOOKUPFAIL) { /* found the element block id */ exerrval = EX_FATAL; sprintf(errmsg, "Error: %s id %d already exists in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } /* Keep track of the total number of element blocks defined using a counter stored in a linked list keyed by exoid. NOTE: ex_get_file_item is a function that finds the number of element blocks for a specific file and returns that value incremented. */ cur_num_blk=ex_get_file_item(exoid, ex_get_counter_list(blk_type)); if (cur_num_blk >= num_blk) { exerrval = EX_FATAL; sprintf(errmsg, "Error: exceeded number of %ss (%d) defined in file id %d", ex_name_of_object(blk_type), num_blk,exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } /* NOTE: ex_get_file_item is a function that finds the number of element blocks for a specific file and returns that value incremented. */ cur_num_blk=ex_inc_file_item(exoid, ex_get_counter_list(blk_type)); start[0] = cur_num_blk; /* write out element block id to previously defined id array variable*/ if ((status = nc_put_var1_int(exoid, varid, start, &blk_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s id to file id %d", ex_name_of_object(blk_type), exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } blk_id_ndx = ((int)start[0])+1; /* element id index into vblkids array*/ if (num_entries_this_blk == 0) /* Is this a NULL element block? */ blk_stat = 0; /* change element block status to NULL */ else blk_stat = 1; /* change element block status to TRUE */ if ((status = nc_inq_varid (exoid, vblksta, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s status in file id %d", ex_name_of_object(blk_type), exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_put_var1_int(exoid, varid, start, &blk_stat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s id %d status to file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } if (num_entries_this_blk == 0) {/* Is this a NULL element block? */ return(EX_NOERR); } /* put netcdf file into define mode */ if ((status=nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } switch (blk_type) { case EX_EDGE_BLOCK: dneblk = DIM_NUM_ED_IN_EBLK(blk_id_ndx); dnnpe = DIM_NUM_NOD_PER_ED(blk_id_ndx); dnepe = 0; dnfpe = 0; dnape = DIM_NUM_ATT_IN_EBLK(blk_id_ndx); vblkatt = VAR_EATTRIB(blk_id_ndx); vattnam = VAR_NAME_EATTRIB(blk_id_ndx); vnodcon = VAR_EBCONN(blk_id_ndx); vedgcon = 0; vfaccon = 0; break; case EX_FACE_BLOCK: dneblk = DIM_NUM_FA_IN_FBLK(blk_id_ndx); dnnpe = DIM_NUM_NOD_PER_FA(blk_id_ndx); dnepe = 0; dnfpe = 0; dnape = DIM_NUM_ATT_IN_FBLK(blk_id_ndx); vblkatt = VAR_FATTRIB(blk_id_ndx); vattnam = VAR_NAME_FATTRIB(blk_id_ndx); vnodcon = VAR_FBCONN(blk_id_ndx); vnpecnt = VAR_FBEPEC(blk_id_ndx); vedgcon = 0; vfaccon = 0; break; case EX_ELEM_BLOCK: dneblk = DIM_NUM_EL_IN_BLK(blk_id_ndx); dnnpe = DIM_NUM_NOD_PER_EL(blk_id_ndx); dnepe = DIM_NUM_EDG_PER_EL(blk_id_ndx); dnfpe = DIM_NUM_FAC_PER_EL(blk_id_ndx); dnape = DIM_NUM_ATT_IN_BLK(blk_id_ndx); vblkatt = VAR_ATTRIB(blk_id_ndx); vattnam = VAR_NAME_ATTRIB(blk_id_ndx); vnodcon = VAR_CONN(blk_id_ndx); vnpecnt = VAR_EBEPEC(blk_id_ndx); vedgcon = VAR_ECONN(blk_id_ndx); vfaccon = VAR_FCONN(blk_id_ndx); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized block type in switch: %d in file id %d", blk_type,exoid); ex_err("ex_put_block",errmsg,EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } /* define some dimensions and variables*/ if ((status = nc_def_dim(exoid,dneblk,num_entries_this_blk, &numblkdim )) != NC_NOERR) { if (status == NC_ENAMEINUSE) { /* duplicate entry */ exerrval = status; sprintf(errmsg, "Error: %s %d already defined in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to define number of entities/block for %s %d file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } if ( dnnpe && num_nodes_per_entry > 0) { /* A nfaced block would not have any nodes defined... */ if ((status = nc_def_dim(exoid,dnnpe,num_nodes_per_entry, &nnodperentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of nodes/entity for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (dnepe && num_edges_per_entry > 0 ) { if ((status = nc_def_dim (exoid,dnepe,num_edges_per_entry, &nedgperentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of edges/entity for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if ( dnfpe && num_faces_per_entry > 0 ) { if ((status = nc_def_dim(exoid,dnfpe,num_faces_per_entry, &nfacperentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of faces/entity for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } /* element attribute array */ if (num_attr_per_entry > 0) { if ((status = nc_def_dim(exoid, dnape, num_attr_per_entry, &numattrdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of attributes in %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } dims[0] = numblkdim; dims[1] = numattrdim; if ((status = nc_def_var(exoid, vblkatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define attributes for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* inquire previously defined dimensions */ if ((status = nc_inq_dimid(exoid, DIM_STR, &strdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get string length in file id %d",exoid); ex_err("ex_put_block",errmsg,exerrval); return (EX_FATAL); } /* Attribute names... */ dims[0] = numattrdim; dims[1] = strdim; if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define %s attribute name array in file id %d", ex_name_of_object(blk_type), exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } /* See if storing an 'nsided' element block (arbitrary 2d polyhedra or super element) */ if (strlen(entry_descrip) >= 3) { if ((entry_descrip[0] == 'n' || entry_descrip[0] == 'N') && (entry_descrip[1] == 's' || entry_descrip[1] == 'S') && (entry_descrip[2] == 'i' || entry_descrip[2] == 'I')) arbitrary_polyhedra = 1; else if ((entry_descrip[0] == 'n' || entry_descrip[0] == 'N') && (entry_descrip[1] == 'f' || entry_descrip[1] == 'F') && (entry_descrip[2] == 'a' || entry_descrip[2] == 'A')) /* If a FACE_BLOCK, then we are dealing with the faces of the nfaced block. */ arbitrary_polyhedra = blk_type == EX_FACE_BLOCK ? 1 : 2; } /* element connectivity array */ if (arbitrary_polyhedra > 0) { if (blk_type != EX_FACE_BLOCK && blk_type != EX_ELEM_BLOCK) { exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad block type (%d) for nsided/nfaced block in file id %d", blk_type, exoid ); ex_err( "ex_put_block", errmsg, exerrval ); return (EX_FATAL); } if (arbitrary_polyhedra == 1) { dims[0] = nnodperentdim; vconn = vnodcon; /* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/ strcpy(entity_type1, "NODE"); if (blk_type == EX_ELEM_BLOCK) strcpy(entity_type2, "ELEM"); else strcpy(entity_type2, "FACE"); } else if (arbitrary_polyhedra == 2) { dims[0] = nfacperentdim; vconn = vfaccon; /* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/ strcpy(entity_type1, "FACE"); strcpy(entity_type2, "ELEM"); } if ((status = nc_def_var(exoid, vconn, NC_INT, 1, dims, &connid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create connectivity array for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* element face-per-element or node-per-element count array */ dims[0] = numblkdim; if ((status = nc_def_var(exoid, vnpecnt, NC_INT, 1, dims, &npeid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create face- or node- per-entity count array for %s %d in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_put_att_text(exoid, npeid, "entity_type1", strlen(entity_type1)+1, entity_type1)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store entity type attribute text for %s %d in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_put_att_text(exoid, npeid, "entity_type2", strlen(entity_type2)+1, entity_type2)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store entity type attribute text for %s %d in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } else { /* "Normal" (non-polyhedra) element block type */ dims[0] = numblkdim; dims[1] = nnodperentdim; if ((status = nc_def_var(exoid, vnodcon, NC_INT, 2, dims, &connid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create connectivity array for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } /* store element type as attribute of connectivity variable */ if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(entry_descrip)+1, entry_descrip)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s type name %s in file id %d", ex_name_of_object(blk_type), entry_descrip,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if (arbitrary_polyhedra == 0) { if (vedgcon && num_edges_per_entry ) { dims[0] = numblkdim; dims[1] = nedgperentdim; if ((status = nc_def_var(exoid, vedgcon, NC_INT, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create edge connectivity array for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if ( vfaccon && num_faces_per_entry ) { dims[0] = numblkdim; dims[1] = nfacperentdim; if ((status = nc_def_var(exoid, vfaccon, NC_INT, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create face connectivity array for %s %d in file id %d", ex_name_of_object(blk_type), blk_id,exoid); ex_err("ex_put_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } } /* leave define mode */ if ((exerrval=nc_enddef (exoid)) != NC_NOERR) { sprintf(errmsg, "Error: failed to complete %s definition in file id %d", ex_name_of_object(blk_type), exoid); ex_err("ex_put_block",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_block",errmsg,exerrval); } return (EX_FATAL); }
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); }
/*ARGSUSED*/ int main(int argc, char *argv[]) { int cmode=NC_CLOBBER, omode, ret; int id; char buf[256]; #ifdef SYNCDEBUG char *str = "one"; #endif int ii; size_t ui; const struct tcdfvar *tvp = testvars; union getret got; const size_t initialsz = 8192; size_t chunksz = 8192; size_t align = 8192/32; MPI_Init(&argc, &argv); /* cmode |= NC_PNETCDF |NC_64BIT_OFFSET; */ cmode != NC_PNETCDF |NC_64BIT_DATA; ret = nc_create_par(fname,cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &id); if(ret != NC_NOERR) { fprintf(stderr,"Error %s in file %s at line %d\n",nc_strerror(ret),__FILE__,__LINE__); exit(ret); } assert( nc_put_att_text(id, NC_GLOBAL, "TITLE", 12, "another name") == NC_NOERR); assert( nc_get_att_text(id, NC_GLOBAL, "TITLE", buf) == NC_NOERR); /* (void) printf("title 1 \"%s\"\n", buf); */ assert( nc_put_att_text(id, NC_GLOBAL, "TITLE", strlen(fname), fname) == NC_NOERR); assert( nc_get_att_text(id, NC_GLOBAL, "TITLE", buf) == NC_NOERR); buf[strlen(fname)] = 0; /* (void) printf("title 2 \"%s\"\n", buf); */ assert( strcmp(fname, buf) == 0); createtestdims(id, NUM_DIMS, sizes, dim_names); testdims(id, NUM_DIMS, sizes, dim_names); createtestvars(id, testvars, NUM_TESTVARS); { int ifill = -1; double dfill = -9999; assert( nc_put_att_int(id, Long_id, _FillValue, NC_INT, 1, &ifill) == NC_NOERR); assert( nc_put_att_double(id, Double_id, _FillValue, NC_DOUBLE, 1, &dfill) == NC_NOERR); } #ifdef REDEF assert( nc__enddef(id, 0, align, 0, 2*align) == NC_NOERR ); assert( nc_put_var1_int(id, Long_id, indices[3], &birthday) == NC_NOERR ); fill_seq(id); assert( nc_redef(id) == NC_NOERR ); /* assert( nc_rename_dim(id,2, "a long dim name") == NC_NOERR); */ #endif assert( nc_rename_dim(id,1, "IXX") == NC_NOERR); assert( nc_inq_dim(id, 1, buf, &ui) == NC_NOERR); /* (void) printf("dimrename: %s\n", buf); */ assert( nc_rename_dim(id,1, dim_names[1]) == NC_NOERR); #ifdef ATTRX assert( nc_rename_att(id, 1, "UNITS", "units") == NC_NOERR); assert( nc_del_att(id, 4, "FIELDNAM")== NC_NOERR); assert( nc_del_att(id, 2, "SCALEMIN")== NC_NOERR); assert( nc_del_att(id, 2, "SCALEMAX")== NC_NOERR); #endif /* ATTRX */ assert( nc__enddef(id, 0, align, 0, 2*align) == NC_NOERR ); #ifndef REDEF fill_seq(id); assert( nc_put_var1_int(id, Long_id, indices[3], &birthday)== NC_NOERR ); #endif assert( nc_put_vara_schar(id, Byte_id, s_start, s_edges, (signed char *)sentence) == NC_NOERR); assert( nc_put_var1_schar(id, Byte_id, indices[6], (signed char *)(chs+1)) == NC_NOERR); assert( nc_put_var1_schar(id, Byte_id, indices[5], (signed char *)chs) == NC_NOERR); assert( nc_put_vara_text(id, Char_id, s_start, s_edges, sentence) == NC_NOERR); assert( nc_put_var1_text(id, Char_id, indices[6], (chs+1)) == NC_NOERR) ; assert( nc_put_var1_text(id, Char_id, indices[5], chs) == NC_NOERR); assert( nc_put_var1_short(id, Short_id, indices[4], shs) == NC_NOERR); assert( nc_put_var1_float(id, Float_id, indices[2], &e) == NC_NOERR); assert( nc_put_var1_double(id, Double_id, indices[1], &zed) == NC_NOERR); assert( nc_put_var1_double(id, Double_id, indices[0], &pinot) == NC_NOERR); #ifdef SYNCDEBUG (void) printf("Hit Return to sync\n"); gets(str); nc_sync(id,0); (void) printf("Sync done. Hit Return to continue\n"); gets(str); #endif /* SYNCDEBUG */ ret = nc_close(id); /* (void) printf("nc_close ret = %d\n\n", ret); */ /* * read it */ omode = NC_NOWRITE; omode = NC_NOWRITE | NC_PNETCDF; if(ret != NC_NOERR) { (void) printf("Could not open %s: %s\n", fname, nc_strerror(ret)); exit(1); } /* (void) printf("reopen id = %d for filename %s\n", */ /* id, fname); */ /* NC */ /* (void) printf("NC "); */ assert( nc_inq(id, &(cdesc->num_dims), &(cdesc->num_vars), &(cdesc->num_attrs), &(cdesc->xtendim) ) == NC_NOERR); assert((size_t) cdesc->num_dims == num_dims); assert(cdesc->num_attrs == 1); assert(cdesc->num_vars == NUM_TESTVARS); /* (void) printf("done\n"); */ /* GATTR */ /* (void) printf("GATTR "); */ assert( nc_inq_attname(id, NC_GLOBAL, 0, adesc->mnem) == 0); assert(strcmp("TITLE",adesc->mnem) == 0); assert( nc_inq_att(id, NC_GLOBAL, adesc->mnem, &(adesc->type), &(adesc->len))== NC_NOERR); assert( adesc->type == NC_CHAR ); assert( adesc->len == strlen(fname) ); assert( nc_get_att_text(id, NC_GLOBAL, "TITLE", buf)== NC_NOERR); buf[adesc->len] = 0; assert( strcmp(fname, buf) == 0); /* VAR */ /* (void) printf("VAR "); */ assert( cdesc->num_vars == NUM_TESTVARS ); for(ii = 0; ii < cdesc->num_vars; ii++, tvp++ ) { int jj; assert( nc_inq_var(id, ii, vdesc->mnem, &(vdesc->type), &(vdesc->ndims), vdesc->dims, &(vdesc->num_attrs)) == NC_NOERR); if(strcmp(tvp->mnem , vdesc->mnem) != 0) { (void) printf("attr %d mnem mismatch %s, %s\n", ii, tvp->mnem, vdesc->mnem); continue; } if(tvp->type != vdesc->type) { (void) printf("attr %d type mismatch %d, %d\n", ii, (int)tvp->type, (int)vdesc->type); continue; } for(jj = 0; jj < vdesc->ndims; jj++ ) { if(tvp->dims[jj] != vdesc->dims[jj] ) { (void) printf( "inconsistent dim[%d] for variable %d: %d != %d\n", jj, ii, tvp->dims[jj], vdesc->dims[jj] ); continue; } } /* VATTR */ /* (void) printf("VATTR\n"); */ for(jj=0; jj<vdesc->num_attrs; jj++ ) { assert( nc_inq_attname(id, ii, jj, adesc->mnem) == NC_NOERR); if( strcmp(adesc->mnem, reqattr[jj]) != 0 ) { (void) printf("var %d attr %d mismatch %s != %s\n", ii, jj, adesc->mnem, reqattr[jj] ); break; } } if( nc_inq_att(id, ii, reqattr[0], &(adesc->type), &(adesc->len)) != -1) { assert( adesc->type == NC_CHAR ); assert( adesc->len == strlen(tvp->units) ); assert( nc_get_att_text(id,ii,reqattr[0],buf)== NC_NOERR); buf[adesc->len] = 0; assert( strcmp(tvp->units, buf) == 0); } if( nc_inq_att(id, ii, reqattr[1], &(adesc->type), &(adesc->len)) != -1) { assert( adesc->type == NC_DOUBLE ); assert( adesc->len == 1 ); assert( nc_get_att_double(id, ii, reqattr[1], &got.dbl)== NC_NOERR); chkgot(adesc->type, got, tvp->validmin); } if( nc_inq_att(id, ii, reqattr[2], &(adesc->type), &(adesc->len)) != -1) { assert( adesc->type == NC_DOUBLE ); assert( adesc->len == 1 ); assert( nc_get_att_double(id, ii, reqattr[2], &got.dbl)== NC_NOERR); chkgot(adesc->type, got, tvp->validmax); } if( nc_inq_att(id, ii, reqattr[3], &(adesc->type), &(adesc->len)) != -1) { assert( adesc->type == NC_DOUBLE ); assert( adesc->len ==1 ); assert( nc_get_att_double(id, ii, reqattr[3], &got.dbl)== NC_NOERR); chkgot(adesc->type, got, tvp->scalemin); } if( nc_inq_att(id, ii, reqattr[4], &(adesc->type), &(adesc->len)) != -1) { assert( adesc->type == NC_DOUBLE ); assert( adesc->len == 1 ); assert( nc_get_att_double(id, ii, reqattr[4], &got.dbl)== NC_NOERR); chkgot(adesc->type, got, tvp->scalemax); } if( nc_inq_att(id, ii, reqattr[5], &(adesc->type), &(adesc->len))== NC_NOERR) { assert( adesc->type == NC_CHAR ); assert( adesc->len == strlen(tvp->fieldnam) ); assert( nc_get_att_text(id,ii,reqattr[5],buf)== NC_NOERR); buf[adesc->len] = 0; assert( strcmp(tvp->fieldnam, buf) == 0); } } /* (void) printf("fill_seq "); */ check_fill_seq(id); /* (void) printf("Done\n"); */ assert( nc_get_var1_double(id, Double_id, indices[0], &got.dbl)== NC_NOERR); /* (void) printf("got val = %f\n", got.dbl ); */ assert( nc_get_var1_double(id, Double_id, indices[1], &got.dbl)== NC_NOERR); /* (void) printf("got val = %f\n", got.dbl ); */ assert( nc_get_var1_float(id, Float_id, indices[2], &got.fl[0])== NC_NOERR); /* (void) printf("got val = %f\n", got.fl[0] ); */ assert( nc_get_var1_int(id, Long_id, indices[3], &got.in[0])== NC_NOERR); /* (void) printf("got val = %d\n", got.in[0] ); */ assert( nc_get_var1_short(id, Short_id, indices[4], &got.sh[0])== NC_NOERR); /* (void) printf("got val = %d\n", got.sh[0] ); */ assert( nc_get_var1_text(id, Char_id, indices[5], &got.by[0]) == NC_NOERR); /* (void) printf("got NC_CHAR val = %c (0x%02x) \n", */ /* got.by[0] , got.by[0]); */ assert( nc_get_var1_text(id, Char_id, indices[6], &got.by[0]) == NC_NOERR); /* (void) printf("got NC_CHAR val = %c (0x%02x) \n", */ /* got.by[0], got.by[0] ); */ (void) memset(buf,0,sizeof(buf)); assert( nc_get_vara_text(id, Char_id, s_start, s_edges, buf) == NC_NOERR); /* (void) printf("got NC_CHAR val = \"%s\"\n", buf); */ assert( nc_get_var1_schar(id, Byte_id, indices[5], (signed char *)&got.by[0])== NC_NOERR); /* (void) printf("got val = %c (0x%02x) \n", got.by[0] , got.by[0]); */ assert( nc_get_var1_schar(id, Byte_id, indices[6], (signed char *)&got.by[0])== NC_NOERR); /* (void) printf("got val = %c (0x%02x) \n", got.by[0], got.by[0] ); */ (void) memset(buf,0,sizeof(buf)); assert( nc_get_vara_schar(id, Byte_id, s_start, s_edges, (signed char *)buf)== NC_NOERR ); /* (void) printf("got val = \"%s\"\n", buf); */ { double dbuf[NUM_RECS * SIZE_1 * SIZE_2]; assert(nc_get_var_double(id, Float_id, dbuf) == NC_NOERR); /* (void) printf("got vals = %f ... %f\n", dbuf[0], */ /* dbuf[NUM_RECS * SIZE_1 * SIZE_2 -1] ); */ } ret = nc_close(id); /* (void) printf("re nc_close ret = %d\n", ret); */ MPI_Finalize(); return 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); }
int ne_put_loadbal_param_cc(int neid, int *num_int_nodes, int *num_bor_nodes, int *num_ext_nodes, int *num_int_elems, int *num_bor_elems, int *num_node_cmaps, int *num_elem_cmaps ) { char *func_name="ne_put_loadbal_param_cc"; int status; int iproc, varid, dimid_npf, dimid[3]; int num_proc, num_proc_in_f; int varid_nm[3], varid_em[2]; int varid_idx[7] = {0, 0, 0, 0, 0, 0, 0}; size_t start[1], ltempsv; char ftype[2]; int oldfill; int num_int_elem = 0, num_int_node = 0, num_bor_elem = 0; int num_bor_node = 0, num_ext_node = 0; int num_n_cmaps = 0, num_e_cmaps = 0; int nmstat; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* Get the processor information from the file */ if (ne_get_init_info(neid, &num_proc, &num_proc_in_f, ftype) != EX_NOERR) { exerrval = EX_MSG; sprintf(errmsg, "Error: Unable to get processor info from file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* * Get the dimension ID for the number of processors storing * information in this file. */ if ((status = nc_inq_dimid(neid, DIM_NUM_PROCS_F, &dimid_npf)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_PROCS_F, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Put NetCDF file into define mode */ if ((status = nc_redef(neid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to put file id %d into define mode", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Set the fill mode */ if ((status = nc_set_fill(neid, NC_NOFILL, &oldfill)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to put file ID %d into no-fill mode", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the file version */ if ((status=ne_put_version(neid)) < 0) return (status); /* Output the file type */ if (nc_inq_varid(neid, VAR_FILE_TYPE, &varid) != NC_NOERR) { if ((status = nc_def_var(neid, VAR_FILE_TYPE, NC_INT, 0, NULL, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define file type in file ID %d", neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* Define the status variables for the nodal vectors */ if (nc_inq_varid(neid, VAR_INT_N_STAT, &varid) != NC_NOERR) { if ((status = nc_def_var(neid, VAR_INT_N_STAT, NC_INT, 1, &dimid_npf, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_INT_N_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* Set the dimension for status vectors */ if (nc_inq_varid(neid, VAR_BOR_N_STAT, &varid) != NC_NOERR) { if ((status = nc_def_var(neid, VAR_BOR_N_STAT, NC_INT, 1, &dimid_npf, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_BOR_N_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } if (nc_inq_varid(neid, VAR_EXT_N_STAT, &varid) != NC_NOERR) { if ((status = nc_def_var(neid, VAR_EXT_N_STAT, NC_INT, 1, &dimid_npf, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_EXT_N_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* Define the variable IDs for the elemental status vectors */ if (nc_inq_varid(neid, VAR_INT_E_STAT, &varid) != NC_NOERR) { if ((status = nc_def_var(neid, VAR_INT_E_STAT, NC_INT, 1, &dimid_npf, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_INT_E_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } if (nc_inq_varid(neid, VAR_BOR_E_STAT, &varid) != NC_NOERR) { if ((status = nc_def_var(neid, VAR_BOR_E_STAT, NC_INT, 1, &dimid_npf, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: Failed to define variable \"%s\" in file ID %d", VAR_BOR_E_STAT, neid); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* Get the variable ID for the nodal status vectors */ if ((status = nc_inq_varid(neid, VAR_INT_N_STAT, &varid_nm[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_INT_N_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_inq_varid(neid, VAR_BOR_N_STAT, &varid_nm[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_BOR_N_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_inq_varid(neid, VAR_EXT_N_STAT, &varid_nm[2])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_EXT_N_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* Get the variable IDs for the elemental status vectors */ if ((status = nc_inq_varid(neid, VAR_INT_E_STAT, &varid_em[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_INT_E_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_inq_varid(neid, VAR_BOR_E_STAT, &varid_em[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_BOR_E_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* mms: NEW STUFF HERE */ /* ** first need to loop through the processors in this ** file and get the counts of the element and cmap lists */ for(iproc=0; iproc < num_proc_in_f; iproc++) { num_int_elem += num_int_elems[iproc]; num_int_node += num_int_nodes[iproc]; num_bor_elem += num_bor_elems[iproc]; num_bor_node += num_bor_nodes[iproc]; num_ext_node += num_ext_nodes[iproc]; num_e_cmaps += num_elem_cmaps[iproc]; num_n_cmaps += num_node_cmaps[iproc]; } /* Define variable for the internal element information */ if (num_int_elem > 0) { ltempsv = num_int_elem; if ((status = nc_def_dim(neid, DIM_NUM_INT_ELEMS, ltempsv, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to dimension \"%s\" in file id %d", DIM_NUM_INT_ELEMS, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_ELEM_MAP_INT, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_ELEM_MAP_INT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_ELEM_MAP_INT_IDX, NC_INT, 1, &dimid_npf, &varid_idx[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_ELEM_MAP_INT_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_int_elem > 0)" */ /* Define variable for the border element information */ if (num_bor_elem > 0) { ltempsv = num_bor_elem; if ((status = nc_def_dim(neid, DIM_NUM_BOR_ELEMS, ltempsv, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to dimension \"%s\" in file id %d", DIM_NUM_BOR_ELEMS, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_ELEM_MAP_BOR, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_ELEM_MAP_BOR, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_ELEM_MAP_BOR_IDX, NC_INT, 1, &dimid_npf, &varid_idx[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_ELEM_MAP_BOR_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_bor_elem > 0)" */ if (num_int_node > 0) { /* Define variable for vector of internal FEM node IDs */ ltempsv = num_int_node; if ((status = nc_def_dim(neid, DIM_NUM_INT_NODES, ltempsv, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to dimension \"%s\" in file id %d", DIM_NUM_INT_NODES, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_NODE_MAP_INT, NC_INT, 1, &dimid[0], &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_NODE_MAP_INT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_NODE_MAP_INT_IDX, NC_INT, 1, &dimid_npf, &varid_idx[2])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_NODE_MAP_INT_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_int_node > 0)" */ if (num_bor_node > 0) { /* Define variable for vector of border FEM node IDs */ ltempsv = num_bor_node; if ((status = nc_def_dim(neid, DIM_NUM_BOR_NODES, ltempsv, &dimid[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to dimension \"%s\" in file id %d", DIM_NUM_BOR_NODES, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_NODE_MAP_BOR, NC_INT, 1, &dimid[1], &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_NODE_MAP_BOR, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_NODE_MAP_BOR_IDX, NC_INT, 1, &dimid_npf, &varid_idx[3])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_NODE_MAP_BOR_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_bor_node > 0)" */ if (num_ext_node > 0) { /* Define dimension for vector of external FEM node IDs */ ltempsv = num_ext_node; if ((status = nc_def_dim(neid, DIM_NUM_EXT_NODES, ltempsv, &dimid[2])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to dimension \"%s\" in file id %d", DIM_NUM_EXT_NODES, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_NODE_MAP_EXT, NC_INT, 1, &dimid[2], &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_NODE_MAP_EXT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_NODE_MAP_EXT_IDX, NC_INT, 1, &dimid_npf, &varid_idx[4])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_NODE_MAP_EXT_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_ext_node > 0)" */ /* Output the communication map dimensions */ if (num_n_cmaps > 0) { ltempsv = num_n_cmaps; if ((status = nc_def_dim(neid, DIM_NUM_N_CMAPS, ltempsv, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension \"%s\" in file ID %d", DIM_NUM_N_CMAPS, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* Add variables for communication maps */ if ((status = nc_def_var(neid, VAR_N_COMM_IDS, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_N_COMM_IDS, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_N_COMM_STAT, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_N_COMM_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_N_COMM_INFO_IDX, NC_INT, 1, &dimid_npf, &varid_idx[5])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_N_COMM_INFO_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_n_cmaps > 0)" */ if (num_e_cmaps > 0) { ltempsv = num_e_cmaps; if ((status = nc_def_dim(neid, DIM_NUM_E_CMAPS, ltempsv, &dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension \"%s\" in file ID %d", DIM_NUM_E_CMAPS, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* Add variables for elemental communication maps */ if ((status = nc_def_var(neid, VAR_E_COMM_IDS, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_E_COMM_IDS, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } if ((status = nc_def_var(neid, VAR_E_COMM_STAT, NC_INT, 1, dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_E_COMM_STAT, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } /* and the index variable */ if ((status = nc_def_var(neid, VAR_E_COMM_INFO_IDX, NC_INT, 1, &dimid_npf, &varid_idx[6])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define variable \"%s\" in file ID %d", VAR_E_COMM_INFO_IDX, neid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ne_leavedef(neid, func_name); return (EX_FATAL); } } /* End "if (num_e_cmaps > 0)" */ /* Leave define mode */ if (ne_leavedef(neid, func_name) != EX_NOERR) return (EX_FATAL); /* need to reset these counters */ num_int_elem = 0; num_int_node = 0; num_bor_elem = 0; num_bor_node = 0; num_ext_node = 0; num_n_cmaps = 0; num_e_cmaps = 0; /* Update the status vectors */ for(iproc=0; iproc < num_proc_in_f; iproc++) { start[0] = iproc; if (num_int_nodes[iproc] > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(neid, varid_nm[0], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output status int node map in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (num_bor_nodes[iproc] > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(neid, varid_nm[1], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output status bor node map in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (num_ext_nodes[iproc] > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(neid, varid_nm[2], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output status ext node map in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (num_int_elems[iproc] > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(neid, varid_em[0], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output status int elem map in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (num_bor_elems[iproc] > 0) nmstat = 1; else nmstat = 0; if ((status = nc_put_var1_int(neid, varid_em[1], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output status bor elem map in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* now fill the index variables */ if (varid_idx[0] > 0) { /* increment to the next starting position */ num_int_elem += num_int_elems[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[0], start, &num_int_elem)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (varid_idx[1] > 0) { /* increment to the next starting position */ num_bor_elem += num_bor_elems[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[1], start, &num_bor_elem)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output bor elem map index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (varid_idx[2] > 0) { /* increment to the next starting position */ num_int_node += num_int_nodes[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[2], start, &num_int_node)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int node map index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (varid_idx[3] > 0) { /* increment to the next starting position */ num_bor_node += num_bor_nodes[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[3], start, &num_bor_node)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output bor node map index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (varid_idx[4] > 0) { /* increment to the next starting position */ num_ext_node += num_ext_nodes[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[4], start, &num_ext_node)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output ext node map index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (varid_idx[5] > 0) { /* increment to the next starting position */ num_n_cmaps += num_node_cmaps[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[5], start, &num_n_cmaps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output node comm map index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (varid_idx[6] > 0) { /* increment to the next starting position */ num_e_cmaps += num_elem_cmaps[iproc]; if ((status = nc_put_var1_int(neid, varid_idx[6], start, &num_e_cmaps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output elem cmap index in file ID %d", neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } } /* End "for(iproc=0; iproc < num_proc_in_f; iproc++)" */ return (EX_NOERR); }