int main(int argc, char **argv) { /* create tst_classic_fills.nc */ printf("\n*** Testing fill values.\n"); printf("*** testing empty fill values of a string var..."); { #define STRING_VAR_NAME "The_String" #define NDIMS_STRING 1 #define FILLVALUE_LEN 1 /* There is 1 string, the empty one. */ #define DATA_START 2 /* Real data here. */ int ncid, varid, dimid, varid_in; const char *missing_val[FILLVALUE_LEN] = {""}; const char *missing_val_in[FILLVALUE_LEN]; const char *data_out[1] = {"The evil that men do lives after them; " "the good is oft interred with their bones."}; char **data_in; size_t index = DATA_START; int i; /* Create file with a 1D string var. Set its fill value to the * empty string. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, "rec", NC_UNLIMITED, &dimid)) ERR; if (nc_def_var(ncid, STRING_VAR_NAME, NC_STRING, NDIMS_STRING, &dimid, &varid)) ERR; if (nc_put_att_string(ncid, varid, "_FillValue", FILLVALUE_LEN, missing_val)) ERR; /* Check it out. */ if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR; if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR; if (strcmp(missing_val[0], missing_val_in[0])) ERR; if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR; /* Write one string, leaving some blank records which will then * get the fill value. */ if (nc_put_var1_string(ncid, varid_in, &index, data_out)) ERR; /* Get all the data from the variable. */ if (!(data_in = malloc((DATA_START + 1) * sizeof(char *)))) ERR; if (nc_get_var_string(ncid, varid_in, data_in)) ERR; /* First there should be fill values, then the data value we * wrote. */ for (i = 0; i < DATA_START; i++) if (strcmp(data_in[i], "")) ERR; if (strcmp(data_in[DATA_START], data_out[0])) ERR; /* Close everything up. */ if (nc_close(ncid)) ERR; /* Now re-open file, read data, and check values again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR; if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR; if (strcmp(missing_val[0], missing_val_in[0])) ERR; if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR; if (nc_close(ncid)) ERR; free(data_in); } SUMMARIZE_ERR; printf("*** testing non-empty fill values of a string var..."); { #define STRING_VAR_NAME2 "CASSIUS" #define FILLVALUE_LEN2 1 /* There is 1 string in the fillvalue array. */ #define DATA_START2 9 /* Real data starts here. */ int ncid, varid, dimid, varid_in; const char *missing_val[FILLVALUE_LEN2] = {"I know that virtue to be in you, Brutus"}; const char *missing_val_in[FILLVALUE_LEN2]; const char *data_out[1] = {"The evil that men do lives after them; " "the good is oft interred with their bones."}; char **data_in; size_t index = DATA_START2; int i; /* Create file with a 1D string var. Set its fill value to the * a non-empty string. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, "rec", NC_UNLIMITED, &dimid)) ERR; if (nc_def_var(ncid, STRING_VAR_NAME2, NC_STRING, NDIMS_STRING, &dimid, &varid)) ERR; if (nc_put_att_string(ncid, varid, "_FillValue", FILLVALUE_LEN2, missing_val)) ERR; /* Check it out. */ if (nc_inq_varid(ncid, STRING_VAR_NAME2, &varid_in)) ERR; if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR; if (strcmp(missing_val[0], missing_val_in[0])) ERR; if (nc_free_string(FILLVALUE_LEN2, (char **)missing_val_in)) ERR; /* Write one string, leaving some blank records which will then * get the fill value. */ if (nc_put_var1_string(ncid, varid_in, &index, data_out)) ERR; /* Get all the data from the variable. */ if (!(data_in = malloc((DATA_START2 + 1) * sizeof(char *)))) ERR; if (nc_get_var_string(ncid, varid_in, data_in)) ERR; /* First there should be fill values, then the data value we * wrote. */ for (i = 0; i < DATA_START2; i++) if (strcmp(data_in[i], missing_val[0])) ERR; if (strcmp(data_in[DATA_START2], data_out[0])) ERR; /* Close everything up. */ if (nc_close(ncid)) ERR; /* Now re-open file, read data, and check values again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_varid(ncid, STRING_VAR_NAME2, &varid_in)) ERR; if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR; if (strcmp(missing_val[0], missing_val_in[0])) ERR; if (nc_free_string(FILLVALUE_LEN2, (char **)missing_val_in)) ERR; if (nc_close(ncid)) ERR; free(data_in); } SUMMARIZE_ERR; printf("*** testing fill values of one var..."); { #define V1_NAME "v1" #define MAX_VALS 10 int ncid, varid, rec_id, dims[2]; static int rec[1] = {1}; size_t start[2] = {0, 0}; size_t count[2] = {1, MAX_VALS}; char vals[MAX_VALS]; int i; if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; /* Define dimensions and two vars, a 1D coordinate var for * unlimited dimension, and a 2D var which uses the unlimited * dimension. */ if (nc_def_dim(ncid, "rec", NC_UNLIMITED, &dims[0])) ERR; if (nc_def_dim(ncid, "len", MAX_VALS, &dims[1])) ERR; if (nc_def_var(ncid, "rec", NC_INT, 1, dims, &rec_id)) ERR; if (nc_def_var(ncid, V1_NAME, NC_CHAR, 2, dims, &varid)) ERR; /* Extend record dimension by 1. */ if (nc_put_vara_int(ncid, rec_id, start, count, rec)) ERR; /* Read the other variable; it must have only fill values. */ if (nc_get_vara_text(ncid, 1, start, count, vals)) ERR; for (i = 0; i < MAX_VALS; i++) if(vals[i] != NC_FILL_CHAR) ERR; if (nc_close(ncid)) ERR; /* Now re-open file, read data, and check values again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; /* Read the other variable; it must have only fill values. */ if (nc_get_vara_text(ncid, 1, start, count, vals)) ERR; for (i = 0; i < MAX_VALS; i++) if(vals[i] != NC_FILL_CHAR) ERR; if(nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing fill values of lots of vars..."); { int ncid; /* netCDF id */ #define NVALS 10 /* values per fixed-size variable or record */ #define NFIXVARS 6 /* number of fixed-size vars, one of each type */ #define NRECVARS 6 /* number of record vars, one of each type */ #define RANK_REC 1 #define RANK_FIXVARS 1 #define RANK_RECVARS 2 /* dimension ids */ int rec_dim; int len_dim; /* dimension lengths */ size_t rec_len = NC_UNLIMITED; size_t len_len = NVALS; /* variable ids */ int rec_id; int fixvar_ids[NFIXVARS]; int recvar_ids[NRECVARS]; int rec_dims[RANK_REC]; int fixvar_dims[RANK_FIXVARS]; int recvar_dims[RANK_RECVARS]; int fixvar, recvar, i; char *fnames[] = {"c", "b", "s", "i", "f", "d"}; char *rnames[] = {"cr", "br", "sr", "ir", "fr", "dr"}; nc_type types[] = {NC_CHAR, NC_BYTE, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE}; /*if (nc_set_default_format(format + 1, NULL)) ERR;*/ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; /* define dimensions */ if (nc_def_dim(ncid, "rec", rec_len, &rec_dim)) ERR; if (nc_def_dim(ncid, "len", len_len, &len_dim)) ERR; rec_dims[0] = rec_dim; if (nc_def_var(ncid, "rec", NC_INT, RANK_REC, rec_dims, &rec_id)) ERR; /* define fixed and record variables of all 6 primitive types */ fixvar_dims[0] = len_dim; for (fixvar = 0; fixvar < NFIXVARS; fixvar++) if (nc_def_var(ncid, fnames[fixvar], types[fixvar], RANK_FIXVARS, fixvar_dims, &fixvar_ids[fixvar])) ERR; recvar_dims[0] = rec_dim; recvar_dims[1] = len_dim; for (recvar = 0; recvar < NRECVARS; recvar++) if (nc_def_var(ncid, rnames[recvar], types[recvar], RANK_RECVARS, recvar_dims, &recvar_ids[recvar])) ERR; /* leave define mode */ if (nc_enddef(ncid)) ERR; { /* store rec */ static size_t rec_start[RANK_REC]; static size_t rec_count[RANK_REC]; static int rec[] = {1}; rec_len = 1; /* number of records of rec data */ rec_start[0] = 0; rec_count[0] = rec_len; if (nc_put_vara_int(ncid, rec_id, rec_start, rec_count, rec)) ERR; } if (nc_close(ncid)) ERR; /* Now re-open file, read data, and check values */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; /* Check that fixed-size variables are full of fill values */ for (fixvar = 0; fixvar < NFIXVARS; fixvar++) { int varid; nc_type type; if (nc_inq_varid(ncid, fnames[fixvar], &varid)) ERR; if (nc_inq_vartype(ncid, varid, &type)) ERR; switch(type) { case NC_CHAR: { char vals[NVALS]; if (nc_get_var_text(ncid, varid, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_CHAR) ERR; } break; case NC_BYTE: { signed char vals[NVALS]; if (nc_get_var_schar(ncid, varid, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_BYTE) ERR; } break; case NC_SHORT: { short vals[NVALS]; if (nc_get_var_short(ncid, varid, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_SHORT) ERR; } break; case NC_INT: { int vals[NVALS]; if (nc_get_var_int(ncid, varid, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_INT) ERR; } break; case NC_FLOAT: { float vals[NVALS]; if (nc_get_var_float(ncid, varid, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_FLOAT) ERR; } break; case NC_DOUBLE: { double vals[NVALS]; if (nc_get_var_double(ncid, varid, vals)) ERR; for (i = 0; i < NVALS; i++) if (vals[i] != NC_FILL_DOUBLE) ERR; } break; default: ERR; } } /* Read record, check record variables have only fill values */ for (recvar = 0; recvar < NRECVARS; recvar++) { int varid; nc_type type; size_t start[] = {0, 0}; size_t count[] = {1, NVALS}; if (nc_inq_varid(ncid, rnames[recvar], &varid)) ERR; if (nc_inq_vartype(ncid, varid, &type)) ERR; switch(type) { case NC_CHAR: { char vals[NVALS]; if (nc_get_vara_text(ncid, varid, start, count, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_CHAR) ERR; } break; case NC_BYTE: { signed char vals[NVALS]; if (nc_get_vara_schar(ncid, varid, start, count, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_BYTE) ERR; } break; case NC_SHORT: { short vals[NVALS]; if (nc_get_vara_short(ncid, varid, start, count, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_SHORT) ERR; } break; case NC_INT: { int vals[NVALS]; if (nc_get_vara_int(ncid, varid, start, count, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_INT) ERR; } break; case NC_FLOAT: { float vals[NVALS]; if (nc_get_vara_float(ncid, varid, start, count, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_FLOAT) ERR; } break; case NC_DOUBLE: { double vals[NVALS]; if (nc_get_vara_double(ncid, varid, start, count, vals)) ERR; for (i = 0; i < NVALS; i++) if(vals[i] != NC_FILL_DOUBLE) ERR; } break; default: ERR; } } if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; FINAL_RESULTS; return 0; }
/* Both read and write will be tested */ int test_pio(int flag) { /* MPI stuff. */ int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; /* Netcdf-4 stuff. */ int ncid; int nvid,uvid; int rvid; unsigned m,k,j,i; /* two dimensional integer data test */ int dimids[NDIMS1]; size_t start[NDIMS1]; size_t count[NDIMS1]; int *data; int *tempdata; int *rdata; int *temprdata; /* four dimensional integer data test, time dimension is unlimited.*/ int dimuids[NDIMS2]; size_t ustart[NDIMS2]; size_t ucount[NDIMS2]; int *udata; int *tempudata; int *rudata; int *temprudata; /* Initialize MPI. */ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); /* Create a parallel netcdf-4 file. */ if (nc_create_par(file_name, facc_type, comm, info, &ncid)) ERR; /* The first case is two dimensional variables, no unlimited dimension */ /* Create two dimensions. */ if (nc_def_dim(ncid, "d1", DIMSIZE2, dimids)) ERR; if (nc_def_dim(ncid, "d2", DIMSIZE, &dimids[1])) ERR; /* Create one var. */ if (nc_def_var(ncid, "v1", NC_INT, NDIMS1, dimids, &nvid)) ERR; if (nc_enddef(ncid)) ERR; /* Set up slab for this process. */ start[0] = 0; start[1] = mpi_rank * DIMSIZE/mpi_size; count[0] = DIMSIZE2; count[1] = DIMSIZE/mpi_size; /* start parallel netcdf4 */ if (nc_var_par_access(ncid, nvid, flag)) ERR; if (!(data = malloc(sizeof(int)*count[1]*count[0]))) ERR; tempdata = data; for (j = 0; j < count[0]; j++){ for (i = 0; i < count[1]; i++) { *tempdata = mpi_rank * (j + 1); tempdata++; } } /* Write two dimensional integer data */ if (nc_put_vara_int(ncid, nvid, start, count, data)) ERR; free(data); /* Case 2: create four dimensional integer data, one dimension is unlimited. */ /* Create four dimensions. */ if (nc_def_dim(ncid, "ud1", NC_UNLIMITED, dimuids)) ERR; if (nc_def_dim(ncid, "ud2", DIMSIZE3, &dimuids[1])) ERR; if (nc_def_dim(ncid, "ud3", DIMSIZE2, &dimuids[2])) ERR; if (nc_def_dim(ncid, "ud4", DIMSIZE, &dimuids[3])) ERR; /* Create one var. */ if (nc_def_var(ncid, "uv1", NC_INT, NDIMS2, dimuids, &uvid)) ERR; if (nc_enddef(ncid)) ERR; /* Set up selection parameters */ ustart[0] = 0; ustart[1] = 0; ustart[2] = 0; ustart[3] = DIMSIZE*mpi_rank/mpi_size; ucount[0] = TIMELEN; ucount[1] = DIMSIZE3; ucount[2] = DIMSIZE2; ucount[3] = DIMSIZE/mpi_size; /* Access parallel */ if (nc_var_par_access(ncid, uvid, flag)) ERR; /* Create phony data. */ if (!(udata = malloc(ucount[0]*ucount[1]*ucount[2]*ucount[3]*sizeof(int)))) ERR; tempudata = udata; for( m=0; m<ucount[0];m++) for( k=0; k<ucount[1];k++) for (j=0; j<ucount[2];j++) for (i=0; i<ucount[3]; i++) { *tempudata = (1+mpi_rank)*2*(j+1)*(k+1)*(m+1); tempudata++; } /* Write slabs of phoney data. */ if (NC_INDEPENDENT == flag) { int res; res = nc_put_vara_int(ncid, uvid, ustart, ucount, udata); if(res != NC_ECANTEXTEND) ERR; } else { if (nc_put_vara_int(ncid, uvid, ustart, ucount, udata)) ERR; } free(udata); /* Close the netcdf file. */ if (nc_close(ncid)) ERR; if (nc_open_par(file_name, facc_type_open, comm, info, &ncid)) ERR; /* Case 1: read two-dimensional variables, no unlimited dimension */ /* Set up slab for this process. */ start[0] = 0; start[1] = mpi_rank * DIMSIZE/mpi_size; count[0] = DIMSIZE2; count[1] = DIMSIZE/mpi_size; if (nc_inq_varid(ncid, "v1", &rvid)) ERR; if (nc_var_par_access(ncid, rvid, flag)) ERR; if (!(rdata = malloc(sizeof(int)*count[1]*count[0]))) ERR; if (nc_get_vara_int(ncid, rvid, start, count, rdata)) ERR; temprdata = rdata; for (j=0; j<count[0];j++){ for (i=0; i<count[1]; i++){ if(*temprdata != mpi_rank*(j+1)) { ERR_RET; break; } temprdata++; } } free(rdata); /* Case 2: read four dimensional data, one dimension is unlimited. */ /* set up selection parameters */ ustart[0] = 0; ustart[1] = 0; ustart[2] = 0; ustart[3] = DIMSIZE*mpi_rank/mpi_size; ucount[0] = TIMELEN; ucount[1] = DIMSIZE3; ucount[2] = DIMSIZE2; ucount[3] = DIMSIZE/mpi_size; /* Inquiry the data */ /* (NOTE: This variable isn't written out, when access is independent) */ if (NC_INDEPENDENT != flag) { if (nc_inq_varid(ncid, "uv1", &rvid)) ERR; /* Access the parallel */ if (nc_var_par_access(ncid, rvid, flag)) ERR; if (!(rudata = malloc(ucount[0]*ucount[1]*ucount[2]*ucount[3]*sizeof(int)))) ERR; temprudata = rudata; /* Read data */ if (nc_get_vara_int(ncid, rvid, ustart, ucount, rudata)) ERR; for(m = 0; m < ucount[0]; m++) for(k = 0; k < ucount[1]; k++) for(j = 0; j < ucount[2]; j++) for(i = 0; i < ucount[3]; i++) { if(*temprudata != (1+mpi_rank)*2*(j+1)*(k+1)*(m+1)) ERR_RET; temprudata++; } free(rudata); } /* Close the netcdf file. */ if (nc_close(ncid)) ERR; return 0; }
/* test different hyperslab settings */ int test_pio_hyper(int flag){ /* MPI stuff. */ int mpi_size, mpi_rank; int res = NC_NOERR; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; /* Netcdf-4 stuff. */ int ncid; int nvid; int rvid; int j, i; /* two dimensional integer data test */ int dimids[NDIMS1]; size_t start[NDIMS1], count[NDIMS1]; int *data; int *tempdata; int *rdata; int *temprdata; int count_atom; /* Initialize MPI. */ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if(mpi_size == 1) return 0; /* Create a parallel netcdf-4 file. */ /* nc_set_log_level(NC_TURN_OFF_LOGGING); */ /* nc_set_log_level(4);*/ if (nc_create_par(file_name, facc_type, comm, info, &ncid)) ERR; /* The case is two dimensional variables, no unlimited dimension */ /* Create two dimensions. */ if (nc_def_dim(ncid, "d1", DIMSIZE2, dimids)) ERR; if (nc_def_dim(ncid, "d2", DIMSIZE, &dimids[1])) ERR; /* Create one var. */ if (nc_def_var(ncid, "v1", NC_INT, NDIMS1, dimids, &nvid)) ERR; if (nc_enddef(ncid)) ERR; /* hyperslab illustration for 3-processor case -------- |aaaacccc| |aaaacccc| |bbbb | |bbbb | -------- */ /* odd number of processors should be treated differently */ if(mpi_size%2 != 0) { count_atom = DIMSIZE*2/(mpi_size+1); if(mpi_rank <= mpi_size/2) { start[0] = 0; start[1] = mpi_rank*count_atom; count[0] = DIMSIZE2/2; count[1] = count_atom; } else { start[0] = DIMSIZE2/2; start[1] = (mpi_rank-mpi_size/2-1)*count_atom; count[0] = DIMSIZE2/2; count[1] = count_atom; } } else { count_atom = DIMSIZE*2/mpi_size; if(mpi_rank < mpi_size/2) { start[0] = 0; start[1] = mpi_rank*count_atom; count[0] = DIMSIZE2/2; count[1] = count_atom; } else { start[0] = DIMSIZE2/2; start[1] = (mpi_rank-mpi_size/2)*count_atom; count[0] = DIMSIZE2/2; count[1] = count_atom; } } if (nc_var_par_access(ncid, nvid, flag)) ERR; data = malloc(sizeof(int)*count[1]*count[0]); tempdata = data; for (j=0; j<count[0];j++){ for (i=0; i<count[1]; i++){ *tempdata = mpi_rank*(j+1); tempdata ++; } } if (nc_put_vara_int(ncid, nvid, start, count, data)) ERR; free(data); /* Close the netcdf file. */ if (nc_close(ncid)) ERR; if (nc_open_par(file_name, facc_type_open, comm, info, &ncid)) ERR; /* Inquiry the variable */ if (nc_inq_varid(ncid, "v1", &rvid)) ERR; if (nc_var_par_access(ncid, rvid, flag)) ERR; rdata = malloc(sizeof(int)*count[1]*count[0]); /* Read the data with the same slab settings */ if (nc_get_vara_int(ncid, rvid, start, count, rdata)) ERR; temprdata = rdata; for (j=0; j<count[0];j++){ for (i=0; i<count[1]; i++){ if(*temprdata != mpi_rank*(j+1)) { res = -1; break; } temprdata++; } } free(rdata); if(res == -1) ERR_RET; /* Close the netcdf file. */ if (nc_close(ncid)) ERR; return 0; }
int ex_get_partial_num_map(int exoid, ex_entity_type map_type, ex_entity_id map_id, int64_t ent_start, int64_t ent_count, void_int *map) { int dimid, var_id, id_ndx, status; size_t num_mobj, start[1], count[1]; char errmsg[MAX_ERR_LENGTH]; const char *dim_map_size; const char *dim_num_maps; switch (map_type) { case EX_NODE_MAP: dim_map_size = DIM_NUM_NODES; dim_num_maps = DIM_NUM_NM; break; case EX_EDGE_MAP: dim_map_size = DIM_NUM_EDGE; dim_num_maps = DIM_NUM_EDM; break; case EX_FACE_MAP: dim_map_size = DIM_NUM_FACE; dim_num_maps = DIM_NUM_FAM; break; case EX_ELEM_MAP: dim_map_size = DIM_NUM_ELEM; dim_num_maps = DIM_NUM_EM; break; default: exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "Bad map type (%d) specified", map_type); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } exerrval = 0; /* clear error code */ /* See if file contains any elements...*/ if (nc_inq_dimid(exoid, dim_map_size, &dimid) != NC_NOERR) { return (EX_NOERR); } if ((status = nc_inq_dimlen(exoid, dimid, &num_mobj)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of mesh objects in file id %d", exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } /* Check input parameters for a valid range of numbers */ if (ent_start <= 0 || ent_start > num_mobj) { exerrval = EX_FATAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: start count is invalid in file id %d", exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } if (ent_count < 0) { exerrval = EX_FATAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid count value in file id %d", exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } if (ent_start + ent_count - 1 > num_mobj) { exerrval = EX_FATAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: start+count-1 is larger than element count in file id %d", exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } /* first check if any maps have been defined */ if ((status = nc_inq_dimid(exoid, dim_num_maps, &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss defined in file id %d", ex_name_of_object(map_type), exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_WARN); } /* Lookup index of element map id property array */ id_ndx = ex_id_lkup(exoid, map_type, map_id); if (exerrval != 0) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d", ex_name_of_object(map_type), map_id, exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } /* inquire id's of previously defined dimensions and variables */ if ((status = nc_inq_varid(exoid, ex_name_of_map(map_type, id_ndx), &var_id)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " in file id %d", ex_name_of_object(map_type), map_id, exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } /* read in the map */ start[0] = ent_start - 1; count[0] = ent_count; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_get_vara_longlong(exoid, var_id, start, count, map); } else { status = nc_get_vara_int(exoid, var_id, start, count, map); } if (status == -1) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s in file id %d", ex_name_of_object(map_type), exoid); ex_err("ex_get_partial_num_map", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_get_n_node_set (int exoid, ex_entity_id node_set_id, int64_t start_node_num, int64_t num_nodes, void_int *node_set_node_list) { int dimid, node_list_id, node_set_id_ndx, status; size_t num_nodes_in_set, start[1], count[1]; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* first check if any node sets are specified */ if ((status = nc_inq_dimid (exoid, DIM_NUM_NS, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Warning: no node sets defined in file id %d", exoid); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_WARN); } /* Lookup index of node set id in VAR_NS_IDS array */ if ((node_set_id_ndx = ex_id_lkup(exoid, EX_NODE_SET, node_set_id)) < 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: node set %"PRId64" is NULL in file id %d", node_set_id,exoid); ex_err("ex_get_n_node_set",errmsg,EX_MSG); return (EX_WARN); } else { sprintf(errmsg, "Error: failed to locate node set %"PRId64" in %s in file id %d", node_set_id,VAR_NS_IDS,exoid); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } } /* inquire id's of previously defined dimensions and variables */ if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(node_set_id_ndx), &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of nodes in node set %"PRId64" in file id %d", node_set_id,exoid); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, &num_nodes_in_set)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of nodes in set %"PRId64" in file id %d", node_set_id, exoid); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } /* Check input parameters for a valid range of numbers */ if (start_node_num < 0 || start_node_num > num_nodes_in_set) { exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Invalid input"); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } if (num_nodes < 0) { exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Invalid number of nodes in nodes set!"); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } /* start_node_num now starts at 1, not 0 */ if ((start_node_num + num_nodes - 1) > num_nodes_in_set) { exerrval = EX_BADPARAM; sprintf(errmsg, "Error: request larger than number of nodes in set!"); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_varid (exoid, VAR_NODE_NS(node_set_id_ndx), &node_list_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate node set %"PRId64" node list in file id %d", node_set_id,exoid); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } /* read in the node list array */ start[0] = --start_node_num; count[0] = num_nodes; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_get_vara_longlong(exoid, node_list_id, start, count, node_set_node_list); } else { status = nc_get_vara_int(exoid, node_list_id, start, count, node_set_node_list); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get node set node list in file id %d", exoid); ex_err("ex_get_n_node_set",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_get_object_truth_vector (int exoid, ex_entity_type obj_type, ex_entity_id entity_id, int num_var, int *var_vec) { int statust; int varid, tabid, i, status, ent_ndx; size_t num_var_db = 0; size_t start[2], count[2]; char errmsg[MAX_ERR_LENGTH]; const char* routine = "ex_get_object_truth_vector"; /* * The ent_type and the var_name are used to build the netcdf * variables name. Normally this is done via a macro defined in * exodusII_int.h */ const char* ent_type = NULL; const char* var_name = NULL; exerrval = 0; /* clear error code */ switch (obj_type) { case EX_EDGE_BLOCK: status = ex_get_dimension(exoid, DIM_NUM_EDG_VAR, "edge variables", &num_var_db, &varid, routine); statust = nc_inq_varid(exoid, VAR_EBLK_TAB, &tabid); var_name = "vals_edge_var"; ent_type = "eb"; break; case EX_FACE_BLOCK: status = ex_get_dimension(exoid, DIM_NUM_FAC_VAR, "face variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_FBLK_TAB, &tabid); var_name = "vals_face_var"; ent_type = "fb"; break; case EX_ELEM_BLOCK: status = ex_get_dimension(exoid, DIM_NUM_ELE_VAR, "element variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_ELEM_TAB, &tabid); var_name = "vals_elem_var"; ent_type = "eb"; break; case EX_NODE_SET: status = ex_get_dimension(exoid, DIM_NUM_NSET_VAR, "nodeset variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_NSET_TAB, &tabid); var_name = "vals_nset_var"; ent_type = "ns"; break; case EX_EDGE_SET: status = ex_get_dimension(exoid, DIM_NUM_ESET_VAR, "edgeset variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_ESET_TAB, &tabid); var_name = "vals_eset_var"; ent_type = "es"; break; case EX_FACE_SET: status = ex_get_dimension(exoid, DIM_NUM_FSET_VAR, "faceset variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_FSET_TAB, &tabid); var_name = "vals_fset_var"; ent_type = "fs"; break; case EX_SIDE_SET: status = ex_get_dimension(exoid, DIM_NUM_SSET_VAR, "sideset variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_SSET_TAB, &tabid); var_name = "vals_sset_var"; ent_type = "ss"; break; case EX_ELEM_SET: status = ex_get_dimension(exoid, DIM_NUM_ELSET_VAR, "elemset variables", &num_var_db, &varid, routine); statust = nc_inq_varid (exoid, VAR_ELSET_TAB, &tabid); var_name = "vals_elset_var"; ent_type = "es"; break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Invalid variable type %d specified in file id %d", obj_type, exoid); ex_err(routine,errmsg,exerrval); return (EX_WARN); } if (status != NC_NOERR) { exerrval = status; return (EX_WARN); } /* Determine index of entity_id in id array */ ent_ndx = ex_id_lkup(exoid,obj_type,entity_id); if (exerrval != 0) { if (exerrval != EX_NULLENTITY) { sprintf(errmsg, "Error: failed to locate %s id %"PRId64" in id variable in file id %d", ex_name_of_object(obj_type), entity_id, exoid); ex_err(routine,errmsg,exerrval); return (EX_FATAL); } } /* If this is a null entity, then 'ent_ndx' will be negative. * We don't care in this routine, so make it positive and continue... */ if (ent_ndx < 0) ent_ndx = -ent_ndx; if ((int)num_var_db != num_var) { exerrval = EX_FATAL; sprintf(errmsg, "Error: # of variables doesn't match those defined in file id %d", exoid); ex_err("ex_get_object_truth_vector",errmsg,exerrval); return (EX_FATAL); } if (statust != NC_NOERR) { /* since truth vector isn't stored in the data file, derive it dynamically */ for (i=0; i<num_var; i++) { /* NOTE: names are 1-based */ if (nc_inq_varid(exoid, ex_catstr2(var_name, i+1, ent_type, ent_ndx), &tabid) != NC_NOERR) { /* variable doesn't exist; put a 0 in the truth vector */ var_vec[i] = 0; } else { /* variable exists; put a 1 in the truth vector */ var_vec[i] = 1; } } } else { /* read in the truth vector */ start[0] = ent_ndx-1; start[1] = 0; count[0] = 1; count[1] = num_var; status = nc_get_vara_int(exoid, tabid, start, count, var_vec); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get truth vector from file id %d", exoid); ex_err("ex_get_object_truth_vector",errmsg,exerrval); return (EX_FATAL); } } return (EX_NOERR); }
int ex_get_partial_id_map ( int exoid, ex_entity_type map_type, int64_t start_entity_num, int64_t num_entities, void_int* map ) { int dimid, mapid, status; size_t i; size_t num_entries; size_t start[1], count[1]; char errmsg[MAX_ERR_LENGTH]; const char* dnumentries; const char* vmap; const char* tname; 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_get_partial_id_map", errmsg, exerrval ); return (EX_FATAL); } exerrval = 0; /* clear error code */ /* See if any entries are stored in this file */ if (nc_inq_dimid(exoid, dnumentries,&dimid) != NC_NOERR) { return (EX_NOERR); } if (nc_inq_varid (exoid, vmap, &mapid) != NC_NOERR) { if ((status = nc_inq_dimlen(exoid, dimid, &num_entries)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of %ss in file id %d", tname, exoid); ex_err("ex_get_partial_id_map",errmsg,exerrval); return (EX_FATAL); } /* generate default map of 1..n, where n is num_entries */ if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { int64_t *lmap = (int64_t*)map; for (i=0; i < num_entities; i++) { lmap[i] = start_entity_num+i; } } else { int *lmap = (int*)map; for (i=0; i<num_entities; i++) { lmap[i] = start_entity_num+i; } } return (EX_NOERR); } start[0] = start_entity_num-1; count[0] = num_entities; /* read in the id map */ if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_get_vara_longlong(exoid, mapid, start, count, map); } else { status = nc_get_vara_int(exoid, mapid, start, count, map); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get %s id map in file id %d", tname, exoid); ex_err("ex_get_partial_id_map",errmsg,exerrval); return (EX_FATAL); } return(EX_NOERR); }
int ne_get_node_cmap(int neid, int map_id, int *node_ids, int *proc_ids, int processor ) { char *func_name="ne_get_node_cmap"; int map_idx, dimid, varid[2], status; size_t start[1], count[1]; size_t varidx[2]; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* get the cmap information variables index */ if (ne_get_idx(neid, VAR_N_COMM_INFO_IDX, varidx, processor) == -1) { sprintf(errmsg, "Error: failed to find index variable, \"%s\", in file ID %d", VAR_N_COMM_INFO_IDX, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* * no need to check if the second index is -1 that is handled * in ne_id_lkup, where the dimension must be looked up anyways */ /* Get the index of the nodal comm map with the given ID */ if ((map_idx=ne_id_lkup(neid, VAR_N_COMM_IDS, varidx, map_id)) < 0) { exerrval = EX_MSG; sprintf(errmsg, "Error: failed to find nodal comm map with ID %d in file ID %d", map_id, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* get the cmap data variables index for this map */ if (ne_get_idx(neid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) { sprintf(errmsg, "Error: failed to find index variable, \"%s\", in file ID %d", VAR_N_COMM_DATA_IDX, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (varidx[1] == -1) { /* Get the dimension of this nodal communication map */ if ((status = nc_inq_dimid(neid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find dimension ID for \"%s\" in file ID %d", DIM_NCNT_CMAP, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(neid, dimid,count)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NCNT_CMAP, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = count[0]; } /* Get the variable ID for the nodal comm map node IDs */ if ((status = nc_inq_varid(neid, VAR_N_COMM_NIDS, &varid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_NIDS, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the nodal comm map processor IDs */ if ((status = nc_inq_varid(neid, VAR_N_COMM_PROC, &varid[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_PROC, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the nodal comm map node IDs */ start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; status = nc_get_vara_int(neid, varid[0], start, count, node_ids); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get variable \"%s\" from file ID %d", VAR_N_COMM_NIDS, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the nodal comm map processor IDs */ status = nc_get_vara_int(neid, varid[1], start, count, proc_ids); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get variable \"%s\" from file ID %d", VAR_N_COMM_PROC, neid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }