int ex_put_eb_info_global(int exoid, void_int *el_blk_ids, void_int *el_blk_cnts) { int varid, status; char errmsg[MAX_ERR_LENGTH]; EX_FUNC_ENTER(); ex_check_valid_file_id(exoid, __func__); /* Find the variable ID for the element block IDs */ if ((status = nc_inq_varid(exoid, VAR_ELBLK_IDS_GLOBAL, &varid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_ELBLK_IDS_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Output the global element block IDs */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, varid, el_blk_ids); } else { status = nc_put_var_int(exoid, varid, el_blk_ids); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", VAR_ELBLK_IDS_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Find the variable ID for the element block counts */ if ((status = nc_inq_varid(exoid, VAR_ELBLK_CNT_GLOBAL, &varid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_ELBLK_CNT_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Output the global element block counts */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, varid, el_blk_cnts); } else { status = nc_put_var_int(exoid, varid, el_blk_cnts); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", VAR_ELBLK_CNT_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } EX_FUNC_LEAVE(EX_NOERR); }
int ex_put_set (int exoid, ex_entity_type set_type, ex_entity_id set_id, const void_int *set_entry_list, const void_int *set_extra_list) { int dimid, status; int entry_list_id, extra_list_id, set_id_ndx; char errmsg[MAX_ERR_LENGTH]; char* entryptr = NULL; char* extraptr = NULL; exerrval = 0; /* clear error code */ /* first check if any sets are specified */ if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: no %ss defined in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } /* Lookup index of set id in VAR_*S_IDS array */ set_id_ndx = ex_id_lkup(exoid, set_type,set_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no data allowed for NULL %s %"PRId64" in file id %d", ex_name_of_object(set_type),set_id,exoid); ex_err("ex_put_set",errmsg,EX_NULLENTITY); return (EX_WARN); } else { sprintf(errmsg, "Error: failed to locate %s id %"PRId64" in VAR_*S_IDS array in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* setup more pointers based on set_type */ if (set_type == EX_NODE_SET) { entryptr = VAR_NODE_NS(set_id_ndx); extraptr = NULL; } else if (set_type == EX_EDGE_SET) { entryptr = VAR_EDGE_ES(set_id_ndx); extraptr = VAR_ORNT_ES(set_id_ndx); } else if (set_type == EX_FACE_SET) { entryptr = VAR_FACE_FS(set_id_ndx); extraptr = VAR_ORNT_FS(set_id_ndx); } else if (set_type == EX_SIDE_SET) { entryptr = VAR_ELEM_SS(set_id_ndx); extraptr = VAR_SIDE_SS(set_id_ndx); } else if (set_type == EX_ELEM_SET) { entryptr = VAR_ELEM_ELS(set_id_ndx); extraptr = NULL; } /* inquire id's of previously defined variables */ if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate entry list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } /* only do for edge, face and side sets */ if (extraptr) { if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate extra list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* write out the entry list and extra list arrays */ if (set_entry_list != NULL) { if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, entry_list_id, set_entry_list); } else { status = nc_put_var_int(exoid, entry_list_id, set_entry_list); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store entry list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* only do for edge, face and side sets */ if (extraptr && set_extra_list != NULL ) { if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, extra_list_id, set_extra_list); } else { status = nc_put_var_int(exoid, extra_list_id, set_extra_list); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store extra list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* warn if extra data was sent in for node sets and elem sets */ if ((set_type == EX_NODE_SET || set_type == EX_ELEM_SET) && set_extra_list != NULL) { sprintf(errmsg, "Warning: extra list was ignored for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id, exoid); ex_err("ex_put_set",errmsg,EX_MSG); return(EX_WARN); } return (EX_NOERR); }
int ex_put_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, const void_int *values) { int oldfill = 0; int temp; int num_props, i, propid, dimid, dims[1], status; int found = EX_FALSE; int int_type; size_t num_obj; char * name; char tmpstr[MAX_STR_LENGTH + 1]; char errmsg[MAX_ERR_LENGTH]; EX_FUNC_ENTER(); ex_check_valid_file_id(exoid, __func__); /* check if property has already been created */ num_props = ex_get_num_props(exoid, obj_type); /* inquire id of previously defined dimension (number of objects) */ status = ex_get_dimension(exoid, ex_dim_num_objects(obj_type), ex_name_of_object(obj_type), &num_obj, &dimid, __func__); if (status != NC_NOERR) { EX_FUNC_LEAVE(status); } for (i = 1; i <= num_props; i++) { switch (obj_type) { case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break; case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break; case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break; case EX_NODE_SET: name = VAR_NS_PROP(i); break; case EX_EDGE_SET: name = VAR_ES_PROP(i); break; case EX_FACE_SET: name = VAR_FS_PROP(i); break; case EX_ELEM_SET: name = VAR_ELS_PROP(i); break; case EX_SIDE_SET: name = VAR_SS_PROP(i); break; case EX_ELEM_MAP: name = VAR_EM_PROP(i); break; case EX_FACE_MAP: name = VAR_FAM_PROP(i); break; case EX_EDGE_MAP: name = VAR_EDM_PROP(i); break; case EX_NODE_MAP: name = VAR_NM_PROP(i); break; default: snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type, exoid); ex_err(__func__, errmsg, EX_BADPARAM); EX_FUNC_LEAVE(EX_FATAL); } if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property array id in file id %d", exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(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) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property name in file id %d", exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } if (strcmp(tmpstr, prop_name) == 0) { found = EX_TRUE; break; } } /* if property array has not been created, create it */ if (!found) { /* put netcdf file into define mode */ if ((status = nc_redef(exoid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode", exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* create a variable with a name xx_prop#, where # is the new number */ /* of properties */ switch (obj_type) { case EX_ELEM_BLOCK: name = VAR_EB_PROP(num_props + 1); break; case EX_FACE_BLOCK: name = VAR_FA_PROP(num_props + 1); break; case EX_EDGE_BLOCK: name = VAR_ED_PROP(num_props + 1); break; case EX_NODE_SET: name = VAR_NS_PROP(num_props + 1); break; case EX_EDGE_SET: name = VAR_ES_PROP(num_props + 1); break; case EX_FACE_SET: name = VAR_FS_PROP(num_props + 1); break; case EX_ELEM_SET: name = VAR_ELS_PROP(num_props + 1); break; case EX_SIDE_SET: name = VAR_SS_PROP(num_props + 1); break; case EX_ELEM_MAP: name = VAR_EM_PROP(num_props + 1); break; case EX_FACE_MAP: name = VAR_FAM_PROP(num_props + 1); break; case EX_EDGE_MAP: name = VAR_EDM_PROP(num_props + 1); break; case EX_NODE_MAP: name = VAR_NM_PROP(num_props + 1); break; default: snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type, exoid); ex_err(__func__, errmsg, EX_BADPARAM); goto error_ret; /* Exit define mode and return */ } dims[0] = dimid; nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */ int_type = NC_INT; if (ex_int64_status(exoid) & EX_IDS_INT64_DB) { int_type = NC_INT64; } if ((status = nc_def_var(exoid, name, int_type, 1, dims, &propid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create property array variable in file id %d", exoid); ex_err(__func__, errmsg, status); goto error_ret; /* Exit define mode and return */ } nc_set_fill(exoid, oldfill, &temp); /* default: nofill */ /* store property name as attribute of property array variable */ if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, strlen(prop_name) + 1, prop_name)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property name %s in file id %d", prop_name, exoid); ex_err(__func__, errmsg, status); goto error_ret; /* Exit define mode and return */ } /* leave define mode */ if ((status = nc_enddef(exoid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to leave define mode in file id %d", exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } } /* put num_obj values in property array */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, propid, values); } else { status = nc_put_var_int(exoid, propid, values); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property values in file id %d", exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } EX_FUNC_LEAVE(EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: nc_set_fill(exoid, oldfill, &temp); /* default: nofill */ if ((status = nc_enddef(exoid)) != NC_NOERR) { /* exit define mode */ snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid); ex_err(__func__, errmsg, status); } EX_FUNC_LEAVE(EX_FATAL); }
int ex_put_map(int exoid, const void_int *elem_map) { int numelemdim, dims[1], mapid, status; int map_int_type; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* inquire id's of previously defined dimensions */ /* determine number of elements. Return if zero... */ if (nc_inq_dimid(exoid, DIM_NUM_ELEM, &numelemdim) != NC_NOERR) { return (EX_NOERR); } /* put netcdf 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("ex_put_map", errmsg, exerrval); return (EX_FATAL); } /* create a variable array in which to store the element map */ dims[0] = numelemdim; map_int_type = NC_INT; if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) { map_int_type = NC_INT64; } if ((status = nc_def_var(exoid, VAR_MAP, map_int_type, 1, dims, &mapid)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: element map already exists in file id %d", exoid); ex_err("ex_put_map", errmsg, exerrval); } else { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create element map array in file id %d", exoid); ex_err("ex_put_map", errmsg, exerrval); } goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, mapid, 1); /* leave define mode */ if ((status = nc_enddef(exoid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition in file id %d", exoid); ex_err("ex_put_map", errmsg, exerrval); return (EX_FATAL); } /* write out the element order map */ if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_var_longlong(exoid, mapid, elem_map); } else { status = nc_put_var_int(exoid, mapid, elem_map); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store element map in file id %d", exoid); ex_err("ex_put_map", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef(exoid) != NC_NOERR) /* exit define mode */ { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid); ex_err("ex_put_map", errmsg, exerrval); } return (EX_FATAL); }
/*! \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 main(int argc, char **argv) { #ifdef USE_PARALLEL MPI_Init(&argc, &argv); #endif int ncid, dimids[3]; int char_varid, byte_varid, ubyte_varid, short_varid, int_varid, float_varid, double_varid; int ushort_varid, uint_varid, int64_varid, uint64_varid; int i, j; unsigned char ubyte_out[DIM1_LEN][DIM2_LEN] = {{1, 128, 255},{1, 128, 255}}; signed char byte_in[DIM1_LEN][DIM2_LEN], byte_out[DIM1_LEN][DIM2_LEN] = {{-127, 1, 127},{-127, 1, 127}}; unsigned short ushort_out[DIM1_LEN][DIM2_LEN] = {{110, 128, 255},{110, 128, 255}}; short short_in[DIM1_LEN][DIM2_LEN], short_out[DIM1_LEN][DIM2_LEN] = {{-110, -128, 255},{-110, -128, 255}}; int int_in[DIM1_LEN][DIM2_LEN], int_out[DIM1_LEN][DIM2_LEN] = {{0, 128, 255},{0, 128, 255}}; float float_in[DIM1_LEN][DIM2_LEN], float_out[DIM1_LEN][DIM2_LEN] = {{-.1, 9999.99, 100.001},{-.1, 9999.99, 100.001}}; double double_in[DIM1_LEN][DIM2_LEN], double_out[DIM1_LEN][DIM2_LEN] = {{0.02, .1128, 1090.1},{0.02, .1128, 1090.1}}; unsigned int uint_in[DIM1_LEN][DIM2_LEN], uint_out[DIM1_LEN][DIM2_LEN] = {{0, 128, 255},{0, 128, 255}}; long long int64_in[DIM1_LEN][DIM2_LEN], int64_out[DIM1_LEN][DIM2_LEN] = {{-111, 777, 100},{-111, 777, 100}}; unsigned long long uint64_in[DIM1_LEN][DIM2_LEN]; unsigned long long uint64_out[DIM1_LEN][DIM2_LEN] = {{0, 10101, 9999999},{0, 10101, 9999999}}; char char_out[DIM1_LEN][DIM2_LEN][DIM3_LEN] = {{"lalala", "lololo", "lelele"}, {"lalala", "lololo", "lelele"}}; /*nc_set_log_level(4);*/ printf("\n*** Testing netcdf-4 variable functions.\n"); printf("*** testing netcdf-4 varids inq on netcdf-3 file..."); { int nvars_in, varids_in[2]; /* Create a netcdf-3 file with one dim and two vars. */ if (nc_create(FILE_NAME, 0, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; if (nc_def_dim(ncid, DIM3_NAME, DIM3_LEN, &dimids[2])) ERR; if (nc_def_var(ncid, VAR_BYTE_NAME, NC_BYTE, 2, dimids, &byte_varid)) ERR; if (nc_def_var(ncid, VAR_CHAR_NAME, NC_CHAR, 3, dimids, &char_varid)) ERR; if (nc_close(ncid)) ERR; /* Open the file and make sure nc_inq_varids yeilds correct * result. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR; if (nvars_in != 2 || varids_in[0] != 0 || varids_in[1] != 1) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing simple variables..."); { /* Create a file with a variable of each type. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; if (nc_def_dim(ncid, DIM3_NAME, DIM3_LEN, &dimids[2])) ERR; if (nc_def_var(ncid, VAR_BYTE_NAME, NC_BYTE, 2, dimids, &byte_varid)) ERR; if (nc_def_var(ncid, VAR_CHAR_NAME, NC_CHAR, 3, dimids, &char_varid)) ERR; if (nc_def_var(ncid, VAR_SHORT_NAME, NC_SHORT, 2, dimids, &short_varid)) ERR; if (nc_def_var(ncid, VAR_INT_NAME, NC_INT, 2, dimids, &int_varid)) ERR; if (nc_def_var(ncid, VAR_FLOAT_NAME, NC_FLOAT, 2, dimids, &float_varid)) ERR; if (nc_def_var(ncid, VAR_DOUBLE_NAME, NC_DOUBLE, 2, dimids, &double_varid)) ERR; if (nc_def_var(ncid, VAR_UBYTE_NAME, NC_UBYTE, 2, dimids, &ubyte_varid)) ERR; if (nc_def_var(ncid, VAR_USHORT_NAME, NC_USHORT, 2, dimids, &ushort_varid)) ERR; if (nc_def_var(ncid, VAR_UINT_NAME, NC_UINT, 2, dimids, &uint_varid)) ERR; if (nc_def_var(ncid, VAR_INT64_NAME, NC_INT64, 2, dimids, &int64_varid)) ERR; if (nc_def_var(ncid, VAR_UINT64_NAME, NC_UINT64, 2, dimids, &uint64_varid)) ERR; if (nc_put_var_schar(ncid, byte_varid, (signed char *)byte_out)) ERR; if (nc_put_var_text(ncid, char_varid, (char *)char_out)) ERR; if (nc_put_var_short(ncid, short_varid, (short *)short_out)) ERR; if (nc_put_var_int(ncid, int_varid, (int *)int_out)) ERR; if (nc_put_var_float(ncid, float_varid, (float *)float_out)) ERR; if (nc_put_var_double(ncid, double_varid, (double *)double_out)) ERR; if (nc_put_var_ubyte(ncid, ubyte_varid, (unsigned char *)ubyte_out)) ERR; if (nc_put_var_ushort(ncid, ushort_varid, (unsigned short *)ushort_out)) ERR; if (nc_put_var_uint(ncid, uint_varid, (unsigned int *)uint_out)) ERR; if (nc_put_var_longlong(ncid, int64_varid, (long long *)int64_out)) ERR; if (nc_put_var_ulonglong(ncid, uint64_varid, (unsigned long long *)uint64_out)) ERR; if (nc_close(ncid)) ERR; /* Open the file and check metadata. */ { nc_type xtype_in; int ndims_in, dimids_in[10], natts_in, varid_in; char name_in[NC_MAX_NAME+1]; if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims_in, dimids_in, &natts_in)) ERR; if (strcmp(name_in, VAR_BYTE_NAME) || xtype_in != NC_BYTE || ndims_in != 2 || natts_in != 0 || dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR; if (nc_inq_varid(ncid, VAR_BYTE_NAME, &varid_in)) ERR; if (varid_in != 0) ERR; if (nc_inq_varid(ncid, VAR_CHAR_NAME, &varid_in)) ERR; if (varid_in != 1) ERR; if (nc_inq_varid(ncid, VAR_SHORT_NAME, &varid_in)) ERR; if (varid_in != 2) ERR; if (nc_inq_varname(ncid, 0, name_in)) ERR; if (strcmp(name_in, VAR_BYTE_NAME)) ERR; if (nc_inq_varname(ncid, 1, name_in)) ERR; if (strcmp(name_in, VAR_CHAR_NAME)) ERR; if (nc_inq_varname(ncid, 2, name_in)) ERR; if (strcmp(name_in, VAR_SHORT_NAME)) ERR; if (nc_inq_vartype(ncid, 0, &xtype_in)) ERR; if (xtype_in != NC_BYTE) ERR; if (nc_inq_vartype(ncid, 1, &xtype_in)) ERR; if (xtype_in != NC_CHAR) ERR; if (nc_inq_vartype(ncid, 2, &xtype_in)) ERR; if (xtype_in != NC_SHORT) ERR; if (nc_close(ncid)) ERR; } /* Open the file and check data. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_get_var_schar(ncid, byte_varid, (signed char *)byte_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != byte_out[i][j]) ERR; if (nc_get_var_short(ncid, short_varid, (short *)short_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (short_in[i][j] != short_out[i][j]) ERR; if (nc_get_var_int(ncid, int_varid, (int *)int_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (int_in[i][j] != int_out[i][j]) ERR; if (nc_get_var_float(ncid, float_varid, (float *)float_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (float_in[i][j] != float_out[i][j]) ERR; if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != double_out[i][j]) ERR; if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != double_out[i][j]) ERR; if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != double_out[i][j]) ERR; if (nc_get_var_uint(ncid, uint_varid, (unsigned int *)uint_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (uint_in[i][j] != uint_out[i][j]) ERR; if (nc_get_var_longlong(ncid, int64_varid, (long long *)int64_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (int64_in[i][j] != int64_out[i][j]) ERR; if (nc_get_var_ulonglong(ncid, uint64_varid, (unsigned long long *)uint64_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (uint64_in[i][j] != uint64_out[i][j]) ERR; if (nc_close(ncid)) ERR; /* Open the file and read everything as double. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_get_var_double(ncid, byte_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)byte_out[i][j]) ERR; if (nc_get_var_double(ncid, ubyte_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)ubyte_out[i][j]) ERR; if (nc_get_var_double(ncid, short_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)short_out[i][j]) ERR; if (nc_get_var_double(ncid, ushort_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)ushort_out[i][j]) ERR; if (nc_get_var_double(ncid, int_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)int_out[i][j]) ERR; if (nc_get_var_double(ncid, uint_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)uint_out[i][j]) ERR; if (nc_get_var_double(ncid, float_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)float_out[i][j]) ERR; if (nc_get_var_double(ncid, int64_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)int64_out[i][j]) ERR; if (nc_get_var_double(ncid, uint64_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)uint64_out[i][j]) ERR; if (nc_close(ncid)) ERR; /* Open the file and read everything as NC_BYTE. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_get_var_schar(ncid, byte_varid, (signed char *)byte_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)byte_out[i][j]) ERR; if (nc_get_var_schar(ncid, ubyte_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)ubyte_out[i][j]) ERR; if (nc_get_var_schar(ncid, short_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)short_out[i][j]) ERR; if (nc_get_var_schar(ncid, ushort_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)ushort_out[i][j]) ERR; if (nc_get_var_schar(ncid, int_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)int_out[i][j]) ERR; if (nc_get_var_schar(ncid, uint_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)uint_out[i][j]) ERR; if (nc_get_var_schar(ncid, float_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)float_out[i][j]) ERR; if (nc_get_var_schar(ncid, int64_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)int64_out[i][j]) ERR; if (nc_get_var_schar(ncid, uint64_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)uint64_out[i][j]) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; #define DEFLATE_LEVEL_4 4 printf("*** testing simple variables with deflation..."); { /* Create a file with a variable of each type. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; if (nc_def_dim(ncid, DIM3_NAME, DIM3_LEN, &dimids[2])) ERR; if (nc_def_var(ncid, VAR_BYTE_NAME, NC_BYTE, 2, dimids, &byte_varid)) ERR; if (nc_def_var_deflate(ncid, byte_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_CHAR_NAME, NC_CHAR, 3, dimids, &char_varid)) ERR; if (nc_def_var_deflate(ncid, byte_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_SHORT_NAME, NC_SHORT, 2, dimids, &short_varid)) ERR; if (nc_def_var_deflate(ncid, short_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_INT_NAME, NC_INT, 2, dimids, &int_varid)) ERR; if (nc_def_var_deflate(ncid, int_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_FLOAT_NAME, NC_FLOAT, 2, dimids, &float_varid)) ERR; if (nc_def_var_deflate(ncid, float_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_DOUBLE_NAME, NC_DOUBLE, 2, dimids, &double_varid)) ERR; if (nc_def_var_deflate(ncid, double_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_UBYTE_NAME, NC_UBYTE, 2, dimids, &ubyte_varid)) ERR; if (nc_def_var_deflate(ncid, ubyte_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_USHORT_NAME, NC_USHORT, 2, dimids, &ushort_varid)) ERR; if (nc_def_var_deflate(ncid, ushort_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_UINT_NAME, NC_UINT, 2, dimids, &uint_varid)) ERR; if (nc_def_var_deflate(ncid, uint_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_INT64_NAME, NC_INT64, 2, dimids, &int64_varid)) ERR; if (nc_def_var_deflate(ncid, int64_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_def_var(ncid, VAR_UINT64_NAME, NC_UINT64, 2, dimids, &uint64_varid)) ERR; if (nc_def_var_deflate(ncid, uint64_varid, 0, 1, DEFLATE_LEVEL_4)) ERR; if (nc_put_var_schar(ncid, byte_varid, (signed char *)byte_out)) ERR; if (nc_put_var_text(ncid, char_varid, (char *)char_out)) ERR; if (nc_put_var_short(ncid, short_varid, (short *)short_out)) ERR; if (nc_put_var_int(ncid, int_varid, (int *)int_out)) ERR; if (nc_put_var_float(ncid, float_varid, (float *)float_out)) ERR; if (nc_put_var_double(ncid, double_varid, (double *)double_out)) ERR; if (nc_put_var_ubyte(ncid, ubyte_varid, (unsigned char *)ubyte_out)) ERR; if (nc_put_var_ushort(ncid, ushort_varid, (unsigned short *)ushort_out)) ERR; if (nc_put_var_uint(ncid, uint_varid, (unsigned int *)uint_out)) ERR; if (nc_put_var_longlong(ncid, int64_varid, (long long *)int64_out)) ERR; if (nc_put_var_ulonglong(ncid, uint64_varid, (unsigned long long *)uint64_out)) ERR; if (nc_close(ncid)) ERR; /* Open the file and check metadata. */ { nc_type xtype_in; int ndims_in, dimids_in[10], natts_in, varid_in; char name_in[NC_MAX_NAME+1]; if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims_in, dimids_in, &natts_in)) ERR; if (strcmp(name_in, VAR_BYTE_NAME) || xtype_in != NC_BYTE || ndims_in != 2 || natts_in != 0 || dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR; if (nc_inq_varid(ncid, VAR_BYTE_NAME, &varid_in)) ERR; if (varid_in != 0) ERR; if (nc_inq_varid(ncid, VAR_CHAR_NAME, &varid_in)) ERR; if (varid_in != 1) ERR; if (nc_inq_varid(ncid, VAR_SHORT_NAME, &varid_in)) ERR; if (varid_in != 2) ERR; if (nc_inq_varname(ncid, 0, name_in)) ERR; if (strcmp(name_in, VAR_BYTE_NAME)) ERR; if (nc_inq_varname(ncid, 1, name_in)) ERR; if (strcmp(name_in, VAR_CHAR_NAME)) ERR; if (nc_inq_varname(ncid, 2, name_in)) ERR; if (strcmp(name_in, VAR_SHORT_NAME)) ERR; if (nc_inq_vartype(ncid, 0, &xtype_in)) ERR; if (xtype_in != NC_BYTE) ERR; if (nc_inq_vartype(ncid, 1, &xtype_in)) ERR; if (xtype_in != NC_CHAR) ERR; if (nc_inq_vartype(ncid, 2, &xtype_in)) ERR; if (xtype_in != NC_SHORT) ERR; if (nc_close(ncid)) ERR; } /* Open the file and check data. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_get_var_schar(ncid, byte_varid, (signed char *)byte_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != byte_out[i][j]) ERR; if (nc_get_var_short(ncid, short_varid, (short *)short_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (short_in[i][j] != short_out[i][j]) ERR; if (nc_get_var_int(ncid, int_varid, (int *)int_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (int_in[i][j] != int_out[i][j]) ERR; if (nc_get_var_float(ncid, float_varid, (float *)float_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (float_in[i][j] != float_out[i][j]) ERR; if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != double_out[i][j]) ERR; if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != double_out[i][j]) ERR; if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != double_out[i][j]) ERR; if (nc_get_var_uint(ncid, uint_varid, (unsigned int *)uint_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (uint_in[i][j] != uint_out[i][j]) ERR; if (nc_get_var_longlong(ncid, int64_varid, (long long *)int64_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (int64_in[i][j] != int64_out[i][j]) ERR; if (nc_get_var_ulonglong(ncid, uint64_varid, (unsigned long long *)uint64_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (uint64_in[i][j] != uint64_out[i][j]) ERR; if (nc_close(ncid)) ERR; /* Open the file and read everything as double. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_get_var_double(ncid, byte_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)byte_out[i][j]) ERR; if (nc_get_var_double(ncid, ubyte_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)ubyte_out[i][j]) ERR; if (nc_get_var_double(ncid, short_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)short_out[i][j]) ERR; if (nc_get_var_double(ncid, ushort_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)ushort_out[i][j]) ERR; if (nc_get_var_double(ncid, int_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)int_out[i][j]) ERR; if (nc_get_var_double(ncid, uint_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)uint_out[i][j]) ERR; if (nc_get_var_double(ncid, float_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)float_out[i][j]) ERR; if (nc_get_var_double(ncid, int64_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)int64_out[i][j]) ERR; if (nc_get_var_double(ncid, uint64_varid, (double *)double_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (double_in[i][j] != (double)uint64_out[i][j]) ERR; if (nc_close(ncid)) ERR; /* Open the file and read everything as NC_BYTE. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_get_var_schar(ncid, byte_varid, (signed char *)byte_in)) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)byte_out[i][j]) ERR; if (nc_get_var_schar(ncid, ubyte_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)ubyte_out[i][j]) ERR; if (nc_get_var_schar(ncid, short_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)short_out[i][j]) ERR; if (nc_get_var_schar(ncid, ushort_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)ushort_out[i][j]) ERR; if (nc_get_var_schar(ncid, int_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)int_out[i][j]) ERR; if (nc_get_var_schar(ncid, uint_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)uint_out[i][j]) ERR; if (nc_get_var_schar(ncid, float_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)float_out[i][j]) ERR; if (nc_get_var_schar(ncid, int64_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)int64_out[i][j]) ERR; if (nc_get_var_schar(ncid, uint64_varid, (signed char *)byte_in) != NC_ERANGE) ERR; for (i = 0; i < DIM1_LEN; i++) for (j = 0; j < DIM2_LEN; j++) if (byte_in[i][j] != (signed char)uint64_out[i][j]) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; #define NDIMS4 1 #define NVARS4 1 #define DIM4_NAME "treaty_of_paris_1783" #define DIM4_LEN 5 #define VAR_NAME4 "John_Adams" #define DEFLATE_LEVEL 6 printf("*** testing netcdf-4 simple variable define..."); { int dimids[NDIMS4], dimids_in[NDIMS4]; int varid, varids_in[NVARS4]; int ndims, nvars, natts, unlimdimid; nc_type xtype_in; char name_in[NC_MAX_NAME + 1]; int shuffle_in, deflate_in, deflate_level; /* Create a netcdf-4 file with one dim and one var. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM4_NAME, DIM4_LEN, &dimids[0])) ERR; if (dimids[0] != 0) ERR; if (nc_def_var(ncid, VAR_NAME4, NC_INT64, NDIMS4, dimids, &varid)) ERR; if (nc_def_var_deflate(ncid, varid, 0, 1, DEFLATE_LEVEL)) ERR; if (varid != 0) ERR; /* Check stuff. */ if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS4 || nvars != NVARS4 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_varids(ncid, &nvars, varids_in)) ERR; if (nvars != NVARS4) ERR; if (varids_in[0] != 0) ERR; if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, VAR_NAME4) || xtype_in != NC_INT64 || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in, &deflate_level)) ERR; if (shuffle_in ||!deflate_in || deflate_level != DEFLATE_LEVEL) ERR; if (nc_close(ncid)) ERR; /* Open the file and check the same stuff. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS4 || nvars != NVARS4 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_varids(ncid, &nvars, varids_in)) ERR; if (nvars != NVARS4) ERR; if (varids_in[0] != 0) ERR; if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, VAR_NAME4) || xtype_in != NC_INT64 || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in, &deflate_level)) ERR; if (shuffle_in ||!deflate_in || deflate_level != DEFLATE_LEVEL) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; #define NDIMS5 1 #define NVARS5 5 #define DIM5_NAME "treaty_of_paris_1783" #define DIM5_LEN 5 printf("*** testing netcdf-4 less simple variable define..."); { int dimids[NDIMS5], dimids_in[NDIMS5]; int varid[NVARS5], varids_in[NVARS5]; int ndims, nvars, natts, unlimdimid; nc_type xtype_in; char name_in[NC_MAX_NAME + 1]; char var_name[NVARS5][NC_MAX_NAME + 1] = {"Jean-Pierre_Blanchard", "Madame_Blanchard", "Giffard", "Stanislas_Charles_Henri_Dupuy_de_Lome", "Charles_F_Ritchel"}; int shuffle_in, deflate_in, deflate_level_in; int deflate_level[NVARS5]; int i; /* Set up options for this var. */ for (i = 0; i < NVARS5; i++) deflate_level[i] = i; /* Create a netcdf-4 file with one dim and two vars. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM5_NAME, DIM5_LEN, &dimids[0])) ERR; if (dimids[0] != 0) ERR; for (i = 0; i < NVARS5; i++) { if (nc_def_var(ncid, var_name[i], NC_INT64, NDIMS5, dimids, &varid[i])) ERR; if (varid[i] != i) ERR; if (nc_def_var_deflate(ncid, varid[i], 1, 1, deflate_level[i])) ERR; } /* Check stuff. */ if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS5 || nvars != NVARS5 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_varids(ncid, &nvars, varids_in)) ERR; if (nvars != NVARS5) ERR; for (i = 0; i < NVARS5; i++) { if (varids_in[i] != i) ERR; if (nc_inq_var(ncid, i, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, var_name[i]) || xtype_in != NC_INT64 || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, varid[i], &shuffle_in, &deflate_in, &deflate_level_in)) ERR; if (!shuffle_in || !deflate_in || deflate_level_in != deflate_level[i]) ERR; } if (nc_close(ncid)) ERR; /* Open the file and check the same stuff. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS5 || nvars != NVARS5 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_varids(ncid, &nvars, varids_in)) ERR; if (nvars != NVARS5) ERR; for (i = 0; i < NVARS5; i++) { if (varids_in[i] != i) ERR; if (nc_inq_var(ncid, i, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, var_name[i]) || xtype_in != NC_INT64 || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, varid[i], &shuffle_in, &deflate_in, &deflate_level_in)) ERR; if (!shuffle_in || !deflate_in || deflate_level_in != deflate_level[i]) ERR; } if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; #define NVARS 5 #define NDIMS 1 #define DIM6_NAME "airship_cross_sectional_area" #define DIM6_LEN 100 #define TEN_K_M2 10000.0 #define INCREMENT 1000.0 printf("*** testing more complex netcdf-4 variable defines..."); { int dimids[NDIMS], dimids_in[NDIMS]; int varid[NVARS], varids_in[NVARS]; int ndims, nvars, natts, unlimdimid; char var_name[NVARS][50] = {"Jean-Pierre_Blanchard", "Madame_Blanchard", "Giffard", "Stanislas_Charles_Henri_Dupuy_de_Lome", "Charles_F_Ritchel"}; double data[DIM6_LEN]; nc_type xtype_in; char name_in[NC_MAX_NAME + 1]; int shuffle_in, deflate_in, deflate_level_in; int fletcher32_in; int i; /* Create some phoney data. */ for (i = 1, data[0] = TEN_K_M2; i < DIM6_LEN; i++) data[i] = data[i - 1] + INCREMENT; /* Create a netcdf-4 file with one dim and 5 NC_DOUBLE vars. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM6_NAME, DIM6_LEN, &dimids[0])) ERR; for (i = 0; i < NVARS; i++) { if (nc_def_var(ncid, var_name[i], NC_DOUBLE, NDIMS, dimids, &varid[i])) ERR; if (nc_def_var_deflate(ncid, varid[i], 0, 1, 0)) ERR; if (nc_def_var_fletcher32(ncid, varid[i], 1)) ERR; } /* Check stuff. */ if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS || nvars != NVARS || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_varids(ncid, &nvars, varids_in)) ERR; if (nvars != NVARS) ERR; for (i = 0; i < NVARS; i++) if (varids_in[i] != i) ERR; for (i = 0; i < NVARS; i++) { if (nc_inq_var(ncid, i, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, var_name[i]) || xtype_in != NC_DOUBLE || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, varid[i], &shuffle_in, &deflate_in, &deflate_level_in)) ERR; if (shuffle_in || !deflate_in || deflate_level_in != 0) ERR; if (nc_inq_var_fletcher32(ncid, varid[i], &fletcher32_in)) ERR; if (!fletcher32_in) ERR; } if (nc_close(ncid)) ERR; /* Open the file and check the same stuff. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS || nvars != NVARS || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_varids(ncid, &nvars, varids_in)) ERR; if (nvars != NVARS) ERR; for (i = 0; i < NVARS; i++) if (varids_in[i] != i) ERR; for (i = 0; i < NVARS; i++) { if (nc_inq_var(ncid, i, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, var_name[i]) || xtype_in != NC_DOUBLE || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, varid[i], &shuffle_in, &deflate_in, &deflate_level_in)) ERR; if (shuffle_in || !deflate_in || deflate_level_in != 0) ERR; if (nc_inq_var_fletcher32(ncid, varid[i], &fletcher32_in)) ERR; if (!fletcher32_in) ERR; } if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; #define DIM7_LEN 2 #define DIM7_NAME "dim_7_from_Indiana" #define VAR7_NAME "var_7_from_Idaho" #define NDIMS 1 printf("*** testing fill values..."); { int dimids[NDIMS], dimids_in[NDIMS]; size_t index[NDIMS]; int varid, ndims, natts; nc_type xtype_in; char name_in[NC_MAX_NAME + 1]; int shuffle_in, deflate_in, deflate_level_in; int fletcher32_in, no_fill; unsigned short ushort_data = 42, ushort_data_in, fill_value_in; /* Create a netcdf-4 file with one dim and 1 NC_USHORT var. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR; if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids, &varid)) ERR; /* Check stuff. */ if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, VAR7_NAME) || xtype_in != NC_USHORT || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in, &deflate_level_in)) ERR; if (shuffle_in || deflate_in) ERR; if (nc_inq_var_fletcher32(ncid, 0, &fletcher32_in)) ERR; if (fletcher32_in) ERR; if (nc_inq_var_fill(ncid, 0, &no_fill, &fill_value_in)) ERR; if (no_fill || fill_value_in != NC_FILL_USHORT) ERR; /* Write the second of two values. */ index[0] = 1; if (nc_put_var1_ushort(ncid, 0, index, &ushort_data)) ERR; /* Get the first value, and make sure we get the default fill * value for USHORT. */ index[0] = 0; if (nc_get_var1_ushort(ncid, 0, index, &ushort_data_in)) ERR; if (ushort_data_in != NC_FILL_USHORT) ERR; if (nc_close(ncid)) ERR; /* Open the file and check the same stuff. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; /* Check stuff. */ if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR; if (strcmp(name_in, VAR7_NAME) || xtype_in != NC_USHORT || ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR; if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in, &deflate_level_in)) ERR; if (shuffle_in || deflate_in) ERR; if (nc_inq_var_fletcher32(ncid, 0, &fletcher32_in)) ERR; if (fletcher32_in) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing more fill values..."); { int dimids[NDIMS]; size_t index[NDIMS]; int varid; int no_fill; unsigned short ushort_data = 42, ushort_data_in, fill_value_in; /* Create a netcdf-4 file with one dim and 1 NC_USHORT var. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR; if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids, &varid)) ERR; if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR; /* Check stuff. */ if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR; if (!no_fill) ERR; /* Write the second of two values. */ index[0] = 1; if (nc_put_var1_ushort(ncid, varid, index, &ushort_data)) ERR; /* Get the first value, and make sure we get the default fill * value for USHORT. */ index[0] = 0; if (nc_get_var1_ushort(ncid, varid, index, &ushort_data_in)) ERR; if (nc_close(ncid)) ERR; /* Open the file and check the same stuff. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; /* Check stuff. */ if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR; if (!no_fill) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing lots of variables..."); #define DIM_A_NAME "x" #define DIM_A_LEN 10 #define NUM_VARS 2000 #define MAX_VARNAME 10 { /* This simple test failed on HDF5 1.7.58, but passes just fine * on 1.8.0 alpha5... */ int ncid, dimids[1], i; char varname[MAX_VARNAME]; int varids[NUM_VARS]; /* Create a file with three dimensions. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM_A_NAME, DIM_A_LEN, &dimids[0])) ERR; /* Create a large number of variables. */ for (i = 0; i < NUM_VARS; i++) { sprintf(varname, "a_%d", i); if (nc_def_var(ncid, varname, NC_FLOAT, 1, dimids, &varids[i])) ERR; } if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; #define NC3_CLASSIC_FILE "tst_pres_temp_4D_classic.nc" #define NC3_64BIT_OFFSET_FILE "tst_pres_temp_4D_64bit_offset.nc" #define NC3_NETCDF4_FILE "tst_pres_temp_4D_netcdf4.nc" #define NC3_NETCDF4_CLASSIC_FILE "tst_pres_temp_4D_netcdf4_classic.nc" printf("*** testing 4D example file in classic format..."); if (create_4D_example(NC3_CLASSIC_FILE, NC_CLOBBER)) ERR; if (check_4D_example(NC3_CLASSIC_FILE, NC_FORMAT_CLASSIC)) ERR; SUMMARIZE_ERR; printf("*** testing 4D example file in 64-bit offset format..."); if (create_4D_example(NC3_64BIT_OFFSET_FILE, NC_CLOBBER|NC_64BIT_OFFSET)) ERR; if (check_4D_example(NC3_64BIT_OFFSET_FILE, NC_FORMAT_64BIT)) ERR; SUMMARIZE_ERR; printf("*** testing 4D example file in netCDF-4/HDF5 format..."); if (create_4D_example(NC3_NETCDF4_FILE, NC_CLOBBER|NC_NETCDF4)) ERR; if (check_4D_example(NC3_NETCDF4_FILE, NC_FORMAT_NETCDF4)) ERR; SUMMARIZE_ERR; printf("*** testing 4D example file in netCDF-4/HDF5 format with classic model rules..."); if (create_4D_example(NC3_NETCDF4_CLASSIC_FILE, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL)) ERR; if (check_4D_example(NC3_NETCDF4_CLASSIC_FILE, NC_FORMAT_NETCDF4_CLASSIC)) ERR; SUMMARIZE_ERR; FINAL_RESULTS; #ifdef USE_PARALLEL MPI_Finalize(); #endif }
int ex_put_ns_param_global(int exoid, void_int *global_ids, void_int *node_cnts, void_int *df_cnts) { const char *func_name = "ex_put_ns_param_global"; int varid, status; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* Get the variable ID for the vector of global node set IDs */ if ((status = nc_inq_varid(exoid, VAR_NS_IDS_GLOBAL, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_NS_IDS_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the vector of global node set IDs */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, varid, global_ids); } else { status = nc_put_var_int(exoid, varid, global_ids); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" to file ID %d", VAR_NS_IDS_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the vector of global node-set node counts */ if ((status = nc_inq_varid(exoid, VAR_NS_NODE_CNT_GLOBAL, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_NS_NODE_CNT_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the vector of global node counts in each global node set */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, varid, node_cnts); } else { status = nc_put_var_int(exoid, varid, node_cnts); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put variable \"%s\" in file ID %d", VAR_NS_NODE_CNT_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the number of dist. factors in each node set */ if ((status = nc_inq_varid(exoid, VAR_NS_DF_CNT_GLOBAL, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_NS_DF_CNT_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the vector of dist. factor counts */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, varid, df_cnts); } else { status = nc_put_var_int(exoid, varid, df_cnts); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", VAR_NS_DF_CNT_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_put_concat_sets (int exoid, ex_entity_type set_type, const struct ex_set_specs* set_specs) { int status; int temp; const void_int *num_entries_per_set = set_specs->num_entries_per_set; const void_int *num_dist_per_set = set_specs->num_dist_per_set; const void_int *sets_entry_index = set_specs->sets_entry_index; const void_int *sets_dist_index = set_specs->sets_dist_index; const void *sets_dist_fact = set_specs->sets_dist_fact; size_t i, num_df, num_entry; int cur_num_sets, num_sets; int dimid, varid, set_id_ndx, dims[1]; int *set_stat = NULL; int set_int_type, int_size; const float *flt_dist_fact = NULL; const double *dbl_dist_fact = NULL; char errmsg[MAX_ERR_LENGTH]; char* idsptr = NULL; char* statptr = NULL; char* numdfptr = NULL; char* factptr = NULL; char* elemptr = NULL; char* extraptr = NULL; ex_inquiry ex_inq_val; exerrval = 0; /* clear error code */ int_size = sizeof(int); if (ex_int64_status(exoid) & EX_BULK_INT64_API) { int_size = sizeof(int64_t); } /* setup pointers based on set_type NOTE: there is another block that sets more stuff later ... */ if (set_type == EX_NODE_SET) { ex_inq_val = EX_INQ_NODE_SETS; idsptr = VAR_NS_IDS; statptr = VAR_NS_STAT; } else if (set_type == EX_EDGE_SET) { ex_inq_val = EX_INQ_EDGE_SETS; idsptr = VAR_ES_IDS; statptr = VAR_ES_STAT; } else if (set_type == EX_FACE_SET) { ex_inq_val = EX_INQ_FACE_SETS; idsptr = VAR_FS_IDS; statptr = VAR_FS_STAT; } else if (set_type == EX_SIDE_SET) { ex_inq_val = EX_INQ_SIDE_SETS; idsptr = VAR_SS_IDS; statptr = VAR_SS_STAT; } else if (set_type == EX_ELEM_SET) { ex_inq_val = EX_INQ_ELEM_SETS; 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 sets are specified */ if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &temp)) != NC_NOERR) { if (status == NC_EBADDIM) { exerrval = status; sprintf(errmsg, "Error: no %ss defined for file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to locate %ss defined in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } return (EX_FATAL); } /* inquire how many sets are to be stored */ num_sets = ex_inquire_int(exoid, ex_inq_val); if (num_sets < 0) { sprintf(errmsg, "Error: failed to get number of %ss defined for file id %d", ex_name_of_object(set_type), exoid); /* use error val from inquire */ ex_err("ex_put_concat_sets",errmsg,exerrval); return (EX_FATAL); } /* Fill out set status array */ /* First, allocate space for the status list */ if (!(set_stat= malloc(num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for %s status array in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); return (EX_FATAL); } if (int_size == sizeof(int64_t)) { for (i=0;i<num_sets;i++) { set_stat[i] = (((int64_t*)num_entries_per_set)[i] == 0) ? 0 : 1; } } else { for (i=0;i<num_sets;i++) { set_stat[i] = (((int*)num_entries_per_set)[i] == 0) ? 0 : 1; } } /* Next, get variable id of status array */ 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_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } status = nc_put_var_int(exoid, varid, set_stat); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s status array to file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_concat_set",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } /* 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_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } /* create set definitions */ for (i=0; i<num_sets; i++) { int64_t set_id; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { set_id = ((int64_t*)set_specs->sets_ids)[i]; } else { set_id = ((int*)set_specs->sets_ids)[i]; } /* 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 is used to find the number of sets of type 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_concat_sets",errmsg,exerrval); goto error_ret; } /* NOTE: ex_inc_file_item is used to find the number of sets 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) { elemptr = 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) { elemptr = 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) { elemptr = 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) { elemptr = 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) { elemptr = VAR_ELEM_ELS(set_id_ndx); extraptr = NULL; numdfptr = DIM_NUM_DF_ELS(set_id_ndx); factptr = VAR_FACT_ELS(set_id_ndx); } /* define dimension for number of entries per set */ if (set_stat[i] == 0) /* Is this a NULL set? */ continue; /* Do not create anything for NULL sets! */ if (int_size == sizeof(int)) { status = nc_def_dim(exoid, ex_dim_num_entries_in_object(set_type, set_id_ndx), ((int*)num_entries_per_set)[i], &dimid); } else { status = nc_def_dim(exoid, ex_dim_num_entries_in_object(set_type, set_id_ndx), ((int64_t*)num_entries_per_set)[i], &dimid); } if (status != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; sprintf(errmsg, "Error: %s entry count %"PRId64" already defined in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to define number of entries for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } goto error_ret; } /* create element list variable for set */ set_int_type = NC_INT; if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { set_int_type = NC_INT64; } dims[0] = dimid; if ((status = nc_def_var(exoid,elemptr,set_int_type,1,dims, &temp)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; sprintf(errmsg, "Error: element list already exists for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to create element list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 1); /* create extra list variable for set (only for edge, face and side sets) */ if (extraptr) { if ((status = nc_def_var(exoid,extraptr,set_int_type,1,dims, &temp)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; sprintf(errmsg, "Error: extra list already exists for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to create extra list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 1); } /* define dimension for number of dist factors per set */ /* NOTE: only define df count if the dist factors exist! */ if (int_size == sizeof(int64_t)) { num_df = ((int64_t*)num_dist_per_set)[i]; num_entry = ((int64_t*)num_entries_per_set)[i]; } else { num_df = ((int*)num_dist_per_set)[i]; num_entry = ((int*)num_entries_per_set)[i]; } if (num_df > 0) { if (set_type == EX_NODE_SET) { if (num_df != num_entry) { exerrval = EX_FATAL; sprintf(errmsg, "Error: # dist fact (%"ST_ZU") not equal to # nodes (%"ST_ZU") in node set %"PRId64" file id %d", num_df, num_entry, set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* resuse dimid from entry lists */ } else { if ((status = nc_def_dim(exoid, numdfptr, num_df, &dimid)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; sprintf(errmsg, "Error: %s df count %"PRId64" already defined in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to define %s df count for set %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } goto error_ret; } } /* create distribution factor list variable for set */ dims[0] = dimid; if ((status = nc_def_var(exoid, factptr, nc_flt_code(exoid), 1, dims, &temp)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; sprintf(errmsg, "Error: dist factor list already exists for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to create dist factor list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 2); } /* end define dist factors */ } /* 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_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } /* Next, fill out set ids array */ /* first get id of set ids array variable */ if ((status = nc_inq_varid(exoid, idsptr, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s ids array in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } /* then, write out set id list */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, varid, set_specs->sets_ids); } else { status = nc_put_var_int(exoid, varid, set_specs->sets_ids); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s id array in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } /* If the sets_entry_index is passed in as a NULL pointer, then * the user only wants us to define the sets and not populate * the data structures. */ if (sets_entry_index == 0) { ex_safe_free(set_stat); return(EX_NOERR); } /* Now, use ExodusII call to store sets */ for (i=0; i<num_sets; i++) { int64_t set_id; size_t df_ndx; if (set_stat[i] == 0) /* Is this a NULL set? */ continue; /* Do not create anything for NULL sets! */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { set_id = ((int64_t*)set_specs->sets_ids)[i]; } else { set_id = ((int*)set_specs->sets_ids)[i]; } if (ex_int64_status(exoid) & EX_BULK_INT64_API) { int64_t* extra_list = NULL; /* set extra list */ if (set_type == EX_EDGE_SET || set_type == EX_FACE_SET || set_type == EX_SIDE_SET) extra_list = &(((int64_t*)set_specs->sets_extra_list)[((int64_t*)sets_entry_index)[i]]); status = ex_put_set(exoid, set_type, set_id, &(((int64_t*)set_specs->sets_entry_list)[((int64_t*)sets_entry_index)[i]]), extra_list); } else { int* extra_list = NULL; /* set extra list */ if (set_type == EX_EDGE_SET || set_type == EX_FACE_SET || set_type == EX_SIDE_SET) extra_list = &(((int*)set_specs->sets_extra_list)[((int*)sets_entry_index)[i]]); status = ex_put_set(exoid, set_type, set_id, &(((int*)set_specs->sets_entry_list)[((int*)sets_entry_index)[i]]), extra_list); } if (status != NC_NOERR) { ex_safe_free(set_stat); return(EX_FATAL); /* error will be reported by subroutine */ } if (int_size == sizeof(int)) { num_df = ((int*)num_dist_per_set)[i]; df_ndx = ((int*)sets_dist_index)[i]; } else { num_df = ((int64_t*)num_dist_per_set)[i]; df_ndx = ((int64_t*)sets_dist_index)[i]; } if (ex_comp_ws(exoid) == sizeof(float)) { flt_dist_fact = sets_dist_fact; if (num_df > 0) { /* store dist factors if required */ if (ex_put_set_dist_fact(exoid, set_type, set_id, &(flt_dist_fact[df_ndx])) == -1) { sprintf(errmsg, "Error: failed to store %s %"PRId64" dist factors for file id %d", ex_name_of_object(set_type), set_id,exoid); /* use error val from exodusII routine */ ex_err("ex_put_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } } } else if (ex_comp_ws(exoid) == sizeof(double)) { dbl_dist_fact = sets_dist_fact; if (num_df) { /* only store if they exist */ if (ex_put_set_dist_fact(exoid, set_type, set_id, &(dbl_dist_fact[df_ndx])) == -1) { sprintf(errmsg, "Error: failed to store %s %"PRId64" dist factors for file id %d", ex_name_of_object(set_type), set_id,exoid); /* use error val from exodusII routine */ ex_err("ex_put_concat_sets",errmsg,exerrval); ex_safe_free(set_stat); return (EX_FATAL); } } } else { /* unknown floating point word size */ exerrval = EX_BADPARAM; sprintf(errmsg, "Error: unsupported floating point word size %d for file id %d", ex_comp_ws(exoid), exoid); ex_err("ex_put_concat_sets", errmsg, exerrval); ex_safe_free(set_stat); return (EX_FATAL); } } ex_safe_free(set_stat); return(EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: ex_safe_free(set_stat); 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_concat_sets",errmsg,exerrval); } return (EX_FATAL); }
int ex_put_id_map (int exoid, ex_entity_type map_type, const void_int *map) { int dimid, mapid, status, dims[1]; int map_int_type; char errmsg[MAX_ERR_LENGTH]; const char* tname; const char* dnumentries; const char* vmap; exerrval = 0; /* clear error code */ switch ( map_type ) { case EX_NODE_MAP: tname = "node"; dnumentries = DIM_NUM_NODES; vmap = VAR_NODE_NUM_MAP; break; case EX_EDGE_MAP: tname = "edge"; dnumentries = DIM_NUM_EDGE; vmap = VAR_EDGE_NUM_MAP; break; case EX_FACE_MAP: tname = "face"; dnumentries = DIM_NUM_FACE; vmap = VAR_FACE_NUM_MAP; break; case EX_ELEM_MAP: tname = "element"; dnumentries = DIM_NUM_ELEM; vmap = VAR_ELEM_NUM_MAP; break; default: exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad map type (%d) specified for file id %d", map_type, exoid ); ex_err( "ex_put_id_map", errmsg, exerrval ); return (EX_FATAL); } /* Make sure the file contains entries */ if (nc_inq_dimid (exoid, dnumentries, &dimid) != NC_NOERR) { return (EX_NOERR); } /* put netcdf file into define mode */ if (nc_inq_varid (exoid, vmap, &mapid) != NC_NOERR) { if ((status = nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to put file id %d into define mode", exoid); ex_err("ex_put_id_map",errmsg,exerrval); return (EX_FATAL); } /* create a variable array in which to store the id map */ dims[0] = dimid; /* Check type to be used for maps... */ map_int_type = NC_INT; if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) { map_int_type = NC_INT64; } if ((status = nc_def_var(exoid, vmap, map_int_type, 1, dims, &mapid)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { exerrval = status; sprintf(errmsg, "Error: %s numbering map already exists in file id %d", tname, exoid); ex_err("ex_put_id_map",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to create %s id map in file id %d", tname, exoid); ex_err("ex_put_id_map",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, mapid, 1); /* leave define mode */ if ((status = nc_enddef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to complete definition in file id %d", exoid); ex_err("ex_put_id_map",errmsg,exerrval); return (EX_FATAL); } } /* write out the entity numbering map */ if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_var_longlong(exoid, mapid, map); } else { status = nc_put_var_int(exoid, mapid, map); } if (status!= NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s numbering map in file id %d", tname, exoid); ex_err("ex_put_id_map",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef (exoid) != NC_NOERR) /* exit define mode */ { sprintf(errmsg, "Error: failed to complete definition for file id %d", exoid); ex_err("ex_put_id_map",errmsg,exerrval); } return (EX_FATAL); }
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_ss_param_global(int exoid, void_int *global_ids, void_int *side_cnts, void_int *df_cnts) { int varid; int status; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ EX_FUNC_ENTER(); ex_check_valid_file_id(exoid, __func__); /* Get the variable ID for the vector of global side set IDs */ if ((status = nc_inq_varid(exoid, VAR_SS_IDS_GLOBAL, &varid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_SS_IDS_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Output the vector of global side set IDs */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, varid, global_ids); } else { status = nc_put_var_int(exoid, varid, global_ids); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" to file ID %d", VAR_SS_IDS_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Get the variable ID for the vector of global side-set side counts */ if ((status = nc_inq_varid(exoid, VAR_SS_SIDE_CNT_GLOBAL, &varid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_SS_SIDE_CNT_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Output the vector of global side counts in each global side set */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, varid, side_cnts); } else { status = nc_put_var_int(exoid, varid, side_cnts); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put variable \"%s\" in file ID %d", VAR_SS_SIDE_CNT_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Get the variable ID for the number of dist. factors in each side set */ if ((status = nc_inq_varid(exoid, VAR_SS_DF_CNT_GLOBAL, &varid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_SS_DF_CNT_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Output the vector of dist. factor counts */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, varid, df_cnts); } else { status = nc_put_var_int(exoid, varid, df_cnts); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", VAR_SS_DF_CNT_GLOBAL, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } EX_FUNC_LEAVE(EX_NOERR); }
/*! * writes the parameters used to describe an element block * \param exoid exodus file id * \param elem_blk_id element block id * \param elem_type element type string * \param num_elem_this_blk number of elements in the element blk * \param num_nodes_per_elem number of nodes per element block * \param num_attr_this_blk number of attributes * \param define_maps if != 0, write maps, else don't */ int ex_put_concat_elem_block (int exoid, const void_int* elem_blk_id, char *elem_type[], const void_int* num_elem_this_blk, const void_int* num_nodes_per_elem, const void_int* num_attr_this_blk, int define_maps) { int i, varid, dimid, dims[2], strdim, *eb_array; int temp; int iblk; int status; int num_elem_blk; int map_int_type, conn_int_type; size_t length; int cur_num_elem_blk, nelnoddim, numelbdim, numattrdim, connid, numelemdim, numnodedim; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* first check if any element blocks are specified * OK if zero... */ if (nc_inq_dimid(exoid, DIM_NUM_EL_BLK, &dimid) != NC_NOERR) { return (EX_NOERR); } /* Get number of element blocks defined for this file */ if ((status = nc_inq_dimlen(exoid,dimid,&length)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of element blocks in file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } num_elem_blk = length; /* Fill out the element block status array */ if (!(eb_array = malloc(num_elem_blk*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for element block status array in file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } if (ex_int64_status(exoid) & EX_IDS_INT64_API) { for (i=0;i<num_elem_blk;i++) { eb_array[i] = (((int64_t*)num_elem_this_blk)[i] == 0) ? 0 : 1; } } else { for (i=0;i<num_elem_blk;i++) { eb_array[i] = (((int*)num_elem_this_blk)[i] == 0) ? 0 : 1; } } /* Next, get variable id of status array */ if ((status = nc_inq_varid(exoid, VAR_STAT_EL_BLK, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate element block status in file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } status = nc_put_var_int(exoid, varid, eb_array); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store element block status array to file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } /* Next, fill out ids array */ /* first get id of ids array variable */ if ((status = nc_inq_varid(exoid, VAR_ID_EL_BLK, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate element block ids array in file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } /* then, write out id list */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, varid, elem_blk_id); } else { status = nc_put_var_int(exoid, varid, elem_blk_id); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store element block id array in file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } /* 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_concat_elem_block",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 place file id %d into define mode",exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } conn_int_type = NC_INT; if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { conn_int_type = NC_INT64; } map_int_type = NC_INT; if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) { map_int_type = NC_INT64; } /* Iterate over element blocks ... */ for (iblk = 0; iblk < num_elem_blk; iblk++) { ex_entity_id eb_id; size_t num_elem; size_t num_npe; size_t num_attr; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { eb_id = ((int64_t*)elem_blk_id)[iblk]; num_elem = ((int64_t*)num_elem_this_blk)[iblk]; num_npe = ((int64_t*)num_nodes_per_elem)[iblk]; num_attr = ((int64_t*)num_attr_this_blk)[iblk]; } else { eb_id = ((int*)elem_blk_id)[iblk]; num_elem = ((int*)num_elem_this_blk)[iblk]; num_npe = ((int*)num_nodes_per_elem)[iblk]; num_attr = ((int*)num_attr_this_blk)[iblk]; } cur_num_elem_blk=ex_get_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK)); if (cur_num_elem_blk >= num_elem_blk) { exerrval = EX_FATAL; sprintf(errmsg, "Error: exceeded number of element blocks (%d) defined in file id %d", num_elem_blk,exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; } /* NOTE: ex_inc_file_item is used to find the number of element blocks for a specific file and returns that value incremented. */ cur_num_elem_blk=ex_inc_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK)); if (eb_array[iblk] == 0) /* Is this a NULL element block? */ continue; /* define some dimensions and variables*/ if ((status = nc_def_dim(exoid, DIM_NUM_EL_IN_BLK(cur_num_elem_blk+1), num_elem, &numelbdim)) != NC_NOERR) { exerrval = status; if (status == NC_ENAMEINUSE) { /* duplicate entry */ sprintf(errmsg, "Error: element block %"PRId64" already defined in file id %d", eb_id,exoid); } else { sprintf(errmsg, "Error: failed to define number of elements/block for block %"PRId64" file id %d", eb_id,exoid); } ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_EL(cur_num_elem_blk+1), num_npe, &nelnoddim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of nodes/element for block %"PRId64" in file id %d", eb_id,exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* element connectivity array */ dims[0] = numelbdim; dims[1] = nelnoddim; if ((status = nc_def_var (exoid, VAR_CONN(cur_num_elem_blk+1), conn_int_type, 2, dims, &connid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create connectivity array for block %"PRId64" in file id %d", eb_id,exoid); ex_err("ex_put_concat_elem_block",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(elem_type[iblk])+1, (void*)elem_type[iblk])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store element type name %s in file id %d", elem_type[iblk],exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* element attribute array */ if (num_attr > 0) { if ((status = nc_def_dim (exoid, DIM_NUM_ATT_IN_BLK(cur_num_elem_blk+1), num_attr, &numattrdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of attributes in block %"PRId64" in file id %d", eb_id,exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* Attribute names... */ dims[0] = numattrdim; dims[1] = strdim; if ((status = nc_def_var(exoid, VAR_NAME_ATTRIB(cur_num_elem_blk+1), NC_CHAR, 2, dims, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define element attribute name array in file id %d",exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } eb_array[iblk] = temp; dims[0] = numelbdim; dims[1] = numattrdim; if ((status = nc_def_var(exoid, VAR_ATTRIB(cur_num_elem_blk+1), nc_flt_code(exoid), 2, dims, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define attributes for element block %"PRId64" in file id %d", eb_id,exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } } /* Define the element map here to avoid a later redefine call */ if (define_maps != 0) { if (nc_inq_varid(exoid, VAR_ELEM_NUM_MAP, &temp) != NC_NOERR) { /* Map does not exist */ /* Possible to have zero elements but >0 element blocks. * Only define map if there are nonzero elements */ if (nc_inq_dimid(exoid, DIM_NUM_ELEM, &numelemdim) == NC_NOERR) { dims[0] = numelemdim; if ((status = nc_def_var(exoid, VAR_ELEM_NUM_MAP, map_int_type, 1, dims, &temp)) != NC_NOERR) { exerrval = status; if (status == NC_ENAMEINUSE) { sprintf(errmsg, "Error: element numbering map already exists in file id %d", exoid); } else { sprintf(errmsg, "Error: failed to create element numbering map in file id %d", exoid); } ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 1); } } /* Do the same for the node numbering map */ if (nc_inq_varid(exoid, VAR_NODE_NUM_MAP, &temp) != NC_NOERR) { /* Map does not exist */ if ((nc_inq_dimid(exoid, DIM_NUM_NODES, &numnodedim)) == NC_NOERR) { dims[0] = numnodedim; if ((status = nc_def_var(exoid, VAR_NODE_NUM_MAP, map_int_type, 1, dims, &temp)) != NC_NOERR) { exerrval = status; if (status == NC_ENAMEINUSE) { sprintf(errmsg, "Error: node numbering map already exists in file id %d", exoid); } else { sprintf(errmsg, "Error: failed to create node numbering map array in file id %d", exoid); } ex_err("ex_put_concat_elem_block",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 1); } } } /* leave define mode */ if ((status = nc_enddef(exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to complete element block definition in file id %d", exoid); ex_err("ex_put_concat_elem_block",errmsg,exerrval); return (EX_FATAL); } { /* Write dummy attribute name. Without this we get corruption in the * attribute name. */ size_t start[2], count[2]; char *text = ""; count[0] = 1; start[1] = 0; count[1] = strlen(text)+1; for (iblk = 0; iblk < num_elem_blk; iblk++) { size_t num_attr; if (eb_array[iblk] == 0) /* Is this a NULL element block? */ continue; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { num_attr = ((int64_t*)num_attr_this_blk)[iblk]; } else { num_attr = ((int*)num_attr_this_blk)[iblk]; } for (i = 0; i < num_attr; i++) { start[0] = i; nc_put_vara_text(exoid, eb_array[iblk], start, count, text); } } } free(eb_array); 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_concat_elem_block",errmsg,exerrval); } return (EX_FATAL); }
int ex_put_eb_info_global(int exoid, void_int *el_blk_ids, void_int *el_blk_cnts ) { const char *func_name="ex_put_eb_info_global"; int varid, status; char errmsg[MAX_ERR_LENGTH]; /* Find the variable ID for the element block IDs */ if ((status = nc_inq_varid(exoid, VAR_ELBLK_IDS_GLOBAL, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_ELBLK_IDS_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the global element block IDs */ if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_var_longlong(exoid, varid, el_blk_ids); } else { status = nc_put_var_int(exoid, varid, el_blk_ids); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable \"%s\" in file ID %d", VAR_ELBLK_IDS_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Find the variable ID for the element block counts */ if ((status = nc_inq_varid(exoid, VAR_ELBLK_CNT_GLOBAL, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_ELBLK_CNT_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the global element block counts */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_var_longlong(exoid, varid, el_blk_cnts); } else { status = nc_put_var_int(exoid, varid, el_blk_cnts); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable \"%s\" in file ID %d", VAR_ELBLK_CNT_GLOBAL, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }