int ex_put_partial_node_set (int exoid, ex_entity_id node_set_id, int64_t start_node_num, int64_t num_nodes, const 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, "Error: no node sets specified in file id %d", exoid); ex_err("ex_put_partial_node_set",errmsg,exerrval); return (EX_FATAL); } /* 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: no data allowed for NULL node set %"PRId64" in file id %d", node_set_id, exoid); ex_err("ex_put_partial_node_set",errmsg,EX_NULLENTITY); return (EX_WARN); } else { sprintf(errmsg, "Error: failed to locate node set id %"PRId64" in VAR_NS_IDS array in file id %d", node_set_id, exoid); ex_err("ex_put_partial_node_set",errmsg,exerrval); return (EX_FATAL); } } /* inquire id's of previously defined dimensions */ 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 set %"PRId64" in file id %d", node_set_id, exoid); ex_err("ex_put_partial_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_put_partial_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) { fprintf(stderr, "ERROR: Invalid input to function ex_get_partial_node_set!\n"); return -1; } if (num_nodes < 0) { fprintf(stderr, "ERROR: Invalid number of nodes in nodes set!\n"); return -1; } /* start_node_num now starts at 1, not 0 */ if ((start_node_num + num_nodes - 1) > num_nodes_in_set) { fprintf(stderr, "ERROR: request larger than number of nodes in set!\n"); return -1; } /* inquire if variable for node set node list has been defined */ if ((status = nc_inq_varid (exoid, VAR_NODE_NS(node_set_id_ndx), &node_list_id)) != NC_NOERR) { /* variable doesn't exist */ exerrval = status; sprintf(errmsg, "Error: failed to locate node set %"PRId64" node list in file id %d", node_set_id, exoid); ex_err("ex_put_partial_node_set",errmsg,exerrval); return (EX_FATAL); } /* write out the node list array */ start[0] = --start_node_num; count[0] = num_nodes; if (count[0] == 0) start[0] = 0; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, node_list_id, start, count, node_set_node_list); } else { status = nc_put_vara_int(exoid, node_list_id, start, count, node_set_node_list); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store node set %"PRId64" node list in file id %d", node_set_id, exoid); ex_err("ex_put_partial_node_set",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_put_processor_node_maps(int exoid, void_int *node_mapi, void_int *node_mapb, void_int *node_mape, int proc_id ) { const char *func_name="ex_put_processor_node_maps"; int status, varid, dimid; char ftype[2]; size_t start[1], count[1]; int64_t varidx[2]; int nmstat; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* Get the file type */ if (ex_get_file_type(exoid, ftype) != EX_NOERR) { exerrval = EX_MSG; sprintf(errmsg, "Error: unable to find file type for file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the status of this node map */ if ((status = nc_inq_varid(exoid, VAR_INT_N_STAT, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" from file ID %d", VAR_INT_N_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ftype[0] == 'p') start[0] = 0; else start[0] = proc_id; if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get status for \"%s\" from file %d", VAR_INT_N_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Write out the internal node-number map */ if (nmstat == 1) { /* get the index */ if (ex_get_idx(exoid, VAR_NODE_MAP_INT_IDX, varidx, proc_id) == -1) { exerrval = status; sprintf(errmsg, "Error: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_INT_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* check if I need to get the dimension */ if (varidx[1] == -1) { if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_NODES, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_NODES, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_INT_NODES, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = count[0]; } if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_INT, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_NODE_MAP_INT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, node_mapi); } else { status = nc_put_vara_int(exoid, varid, start, count, node_mapi); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable \"%s\" in file ID %d", VAR_NODE_MAP_INT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (nmstat == 1)" */ /* Get the status of this node map */ if ((status = nc_inq_varid(exoid, VAR_BOR_N_STAT, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" from file ID %d", VAR_BOR_N_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ftype[0] == 'p') start[0] = 0; else start[0] = proc_id; if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get status for \"%s\" from file %d", VAR_BOR_N_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (nmstat == 1) { /* Write out the border node-number map */ /* get the index */ if (ex_get_idx(exoid, VAR_NODE_MAP_BOR_IDX, varidx, proc_id) == -1) { exerrval = status; sprintf(errmsg, "Error: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_BOR_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* check if I need to get the dimension */ if (varidx[1] == -1) { if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_NODES, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_NODES, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_BOR_NODES, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = count[0]; } if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_BOR, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_NODE_MAP_BOR, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the map */ start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, node_mapb); } else { status = nc_put_vara_int(exoid, varid, start, count, node_mapb); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable \"%s\" in file ID %d", VAR_NODE_MAP_BOR, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (nmstat == 1)" */ /* Get the status of this node map */ if ((status = nc_inq_varid(exoid, VAR_EXT_N_STAT, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" from file ID %d", VAR_EXT_N_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ftype[0] == 'p') start[0] = 0; else start[0] = proc_id; if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get status for \"%s\" from file %d", VAR_EXT_N_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (nmstat == 1) { /* Write out the external node-number map */ if (ex_get_idx(exoid, VAR_NODE_MAP_EXT_IDX, varidx, proc_id) == -1) { exerrval = status; sprintf(errmsg, "Error: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_EXT_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* check if I need to get the dimension */ if (varidx[1] == -1) { if ((status = nc_inq_dimid(exoid, DIM_NUM_EXT_NODES, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_EXT_NODES, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_EXT_NODES, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = count[0]; } if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_EXT, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_NODE_MAP_EXT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the map */ start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, node_mape); } else { status = nc_put_vara_int(exoid, varid, start, count, node_mape); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable \"%s\" in file ID %d", VAR_NODE_MAP_EXT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (nmstat == 1)" */ return (EX_NOERR); }
int ex_put_n_elem_conn (int exoid, ex_entity_id elem_blk_id, int64_t start_elem_num, int64_t num_elems, const void_int *connect) { int numelbdim, nelnoddim, connid, elem_blk_id_ndx, status; size_t num_elem_this_blk, num_nod_per_elem, start[2], count[2]; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */ if ((elem_blk_id_ndx = ex_id_lkup(exoid, EX_ELEM_BLOCK, elem_blk_id)) == -1) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: connectivity array not allowed for NULL element block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg,EX_MSG); return (EX_WARN); } else { sprintf(errmsg, "Error: failed to locate element block id %"PRId64" in %s array in file id %d", elem_blk_id,VAR_ID_EL_BLK, exoid); ex_err("ex_put_n_elem_conn",errmsg,exerrval); return (EX_FATAL); } } /* inquire id's of previously defined dimensions */ if ((status = nc_inq_dimid (exoid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx), &numelbdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of elements in block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg, exerrval); return(EX_FATAL); } if ((status = nc_inq_dimlen(exoid, numelbdim, &num_elem_this_blk)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of elements in block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg,exerrval); return(EX_FATAL); } if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_PER_EL(elem_blk_id_ndx), &nelnoddim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of nodes/elem in block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg,exerrval); return(EX_FATAL); } if ((status = nc_inq_dimlen (exoid, nelnoddim, &num_nod_per_elem)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of nodes/elem in block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg,exerrval); return(EX_FATAL); } if ((status = nc_inq_varid (exoid, VAR_CONN(elem_blk_id_ndx), &connid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate connectivity array for element block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg, exerrval); return(EX_FATAL); } /* do some error checking */ if (num_elem_this_blk < (start_elem_num + num_elems - 1)) { exerrval = status; sprintf(errmsg, "Error: requested connectivity from too many elements in block, %"PRId64, elem_blk_id); ex_err("ex_put_n_elem_conn",errmsg, exerrval); return(EX_FATAL); } /* write out the connectivity array */ start[0] = --start_elem_num; start[1] = 0; count[0] = num_elems; count[1] = num_nod_per_elem; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, connid, start, count, connect); } else { status = nc_put_vara_int(exoid, connid, start, count, connect); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to write connectivity array for block %"PRId64" in file id %d", elem_blk_id, exoid); ex_err("ex_put_n_elem_conn",errmsg, exerrval); return(EX_FATAL); } return (EX_NOERR); }
int ex_put_node_cmap(int exoid, ex_entity_id map_id, void_int *node_ids, void_int *proc_ids, int processor ) { const char *func_name="ex_put_node_cmap"; int map_idx, varid, dimid, status; size_t start[1], count[1], ret_val; int64_t varidx[2]; int value; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* get the index for the comm map information variables */ if (ex_get_idx(exoid, 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, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the index for this map_id */ if ((map_idx=ne_id_lkup(exoid, VAR_N_COMM_IDS, varidx, map_id)) == -1) { sprintf(errmsg, "Error: failed to find index for variable \"%s\" in file ID %d", VAR_N_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* * Find out if this is a NULL comm map by checking it's entry in * the status vector. */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &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); } start[0] = map_idx; if ((status = nc_get_var1_int(exoid, varid, start, &value)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to get variable \"%s\" from file ID %d", VAR_N_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (value == 0) return(EX_NOERR); /* NULL set */ /* now I need to get the comm map data index */ if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) { exerrval = status; sprintf(errmsg, "Error: failed to find index variable, \"%s\", in file ID %d", VAR_N_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* check if I need to get the dimension of the cmap data */ if (varidx[1] == -1) { /* Get the size of the comm maps */ if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get dimension ID for \"%s\" in file ID %d", DIM_NCNT_CMAP, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, &ret_val)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NCNT_CMAP, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = ret_val; } /* "if (varidx[1]==-1)" */ start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; /* Output the node IDs for this comm map */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_NIDS, &varid )) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_NIDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, node_ids); } else { status = nc_put_vara_int(exoid, varid, start, count, node_ids); } if (status != NC_NOERR) { fprintf(stderr, "Start, Count = %lu\t%lu\n", (unsigned long)start[0], (unsigned long)count[0]); exerrval = status; sprintf(errmsg, "Error: failed to output vector \"%s\" in file ID %d", VAR_N_COMM_NIDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the processor IDs for this map */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_PROC, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, proc_ids); } else { status = nc_put_vara_int(exoid, varid, start, count, proc_ids); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable \"%s\" in file ID %d", VAR_N_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
NcValues* NcVar::values( void ) const { int ndims = num_dims(); size_t crnr[NC_MAX_DIMS]; size_t edgs[NC_MAX_DIMS]; for (int i = 0; i < ndims; i++) { crnr[i] = 0; edgs[i] = get_dim(i)->size(); } NcValues* valp = get_space(); int status; switch (type()) { case ncFloat: status = NcError::set_err( nc_get_vara_float(the_file->id(), the_id, crnr, edgs, (float *)valp->base()) ); break; case ncDouble: status = NcError::set_err( nc_get_vara_double(the_file->id(), the_id, crnr, edgs, (double *)valp->base()) ); break; case ncInt64: status = NcError::set_err( nc_put_vara_longlong(the_file->id(), the_id, crnr, edgs, (long long *)valp->base()) ); break; case ncUInt64: status = NcError::set_err( nc_put_vara_ulonglong(the_file->id(), the_id, crnr, edgs, (unsigned long long *)valp->base()) ); break; case ncInt: status = NcError::set_err( nc_get_vara_int(the_file->id(), the_id, crnr, edgs, (int *)valp->base()) ); break; case ncShort: status = NcError::set_err( nc_get_vara_short(the_file->id(), the_id, crnr, edgs, (short *)valp->base()) ); break; case ncByte: status = NcError::set_err( nc_get_vara_schar(the_file->id(), the_id, crnr, edgs, (signed char *)valp->base()) ); break; case ncChar: status = NcError::set_err( nc_get_vara_text(the_file->id(), the_id, crnr, edgs, (char *)valp->base()) ); break; case ncNoType: default: return 0; } if (status != NC_NOERR) return 0; return valp; }
int ex_put_cmap_params_cc(int exoid, void_int *node_cmap_ids, void_int *node_cmap_node_cnts, void_int *node_proc_ptrs, void_int *elem_cmap_ids, void_int *elem_cmap_elem_cnts, void_int *elem_proc_ptrs ) { const char *func_name="ex_put_cmap_params_cc"; size_t num_n_comm_maps, num_e_comm_maps, num_procs_in_file; int status, icm, n_varid[2], e_varid[2], iproc; int varid, n_dimid[1], e_dimid[1]; int n_varid_idx, e_varid_idx; int num_icm; size_t start[1], count[1]; size_t ecnt_cmap, ncnt_cmap; long long nl_ecnt_cmap, nl_ncnt_cmap; void_int *n_var_idx = NULL; void_int *e_var_idx = NULL; int nmstat; char errmsg[MAX_ERR_LENGTH]; int format; int index_type, bulk_type; /*-----------------------------Execution begins-----------------------------*/ exerrval = 0; /* clear error code */ /* See if using NC_FORMAT_NETCDF4 format... */ nc_inq_format(exoid, &format); if ((ex_int64_status(exoid) & EX_BULK_INT64_DB) || (format == NC_FORMAT_NETCDF4)) { index_type = NC_INT64; } else { index_type = NC_INT; } if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { bulk_type = NC_INT64; } else { bulk_type = NC_INT; } /* Get the number of processors in the file */ if ((status = nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &n_dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get dimension ID for \"%s\" in file ID %d", DIM_NUM_PROCS_F, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_procs_in_file)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_PROCS_F, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* * since I cannot get variables while in define mode, I need to * get the cmap information index variables before I go into * define mode */ /* Check to see if there are nodal communications maps in the file */ if (nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &n_dimid[0]) != NC_NOERR) { num_n_comm_maps = 0; } else { if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_n_comm_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in \ file ID %d", DIM_NUM_N_CMAPS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (num_n_comm_maps > 0) { /* Get the variable ID for the comm map index vector */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_INFO_IDX, &n_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* allocate space for the index variable */ if (index_type == NC_INT64) { n_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long)); } else { n_var_idx = malloc((num_procs_in_file + 1) * sizeof(int)); } if (!n_var_idx) { exerrval = EX_MSG; sprintf(errmsg, "Error: insufficient memory to read index variable from file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* and set the last value of the index */ /* get the communication map info index */ if (index_type == NC_INT64) { ((long long*)n_var_idx)[0] = 0; status = nc_get_var_longlong(exoid, n_varid_idx, &((long long*)n_var_idx)[1]); } else { ((int*)n_var_idx)[0] = 0; status = nc_get_var_int(exoid, n_varid_idx, &((int*)n_var_idx)[1]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get variable \"%s\" from file ID %d", VAR_N_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* "if (num_n_comm_maps > 0)" */ /* Check to see if there are elemental communications maps in the file */ if ((status = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &e_dimid[0])) != NC_NOERR) { num_e_comm_maps = 0; } else { if ((status = nc_inq_dimlen(exoid, e_dimid[0], &num_e_comm_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find length of dimension \"%s\" in \ file ID %d", DIM_NUM_E_CMAPS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } if (num_e_comm_maps > 0) { /* Get the variable ID for the comm map index vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_INFO_IDX, &e_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* allocate space for the index variable */ if (index_type == NC_INT64) { e_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long)); } else { e_var_idx = malloc((num_procs_in_file + 1) * sizeof(int)); } if (!e_var_idx) { exerrval = EX_MSG; sprintf(errmsg, "Error: insufficient memory to read index variable from file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* get the communication map info index */ if (index_type == NC_INT64) { ((long long*)e_var_idx)[0] = 0; status = nc_get_var_longlong(exoid, e_varid_idx, &((long long*)e_var_idx)[1]); } else { ((int*)e_var_idx)[0] = 0; status = nc_get_var_int(exoid, e_varid_idx, &((int*)e_var_idx)[1]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get variable \"%s\" from file ID %d", VAR_E_COMM_INFO_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* "if (num_e_comm_maps >0)" */ /* Put NetCDF file into define mode */ if ((status = nc_redef(exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to put file ID %d into define mode", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* * Add dimensions for the size of the number of nodal * communication maps. */ if (num_n_comm_maps > 0) { /* add the communications data index variable */ if ((status = nc_def_var(exoid, VAR_N_COMM_DATA_IDX, index_type, 1, n_dimid, &n_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* now add up all of the nodal communications maps */ ncnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { if (index_type == NC_INT64) { num_icm = ((int64_t*)n_var_idx)[iproc+1] - ((int64_t*)n_var_idx)[iproc]; } else { num_icm = ((int*)n_var_idx)[iproc+1] - ((int*)n_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { if (ex_int64_status(exoid) & EX_BULK_INT64_API) { ncnt_cmap += ((int64_t*)node_cmap_node_cnts)[((int64_t*)node_proc_ptrs)[iproc]+icm]; } else { ncnt_cmap += ((int*)node_cmap_node_cnts)[((int*)node_proc_ptrs)[iproc]+icm]; } } } if ((status = nc_def_dim(exoid, DIM_NCNT_CMAP, ncnt_cmap, &n_dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension for \"%s\" of size %"ST_ZU" in file ID %d", DIM_NCNT_CMAP, ncnt_cmap, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Define variables for the nodal IDS and processor vectors */ if ((status = nc_def_var(exoid, VAR_N_COMM_NIDS, bulk_type, 1, n_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_NIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_N_COMM_PROC, NC_INT, 1, n_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_N_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); } /* End "if (num_n_comm_maps > 0)" */ /* * Add dimensions for the size of the number of elemental * communication maps. */ if (num_e_comm_maps > 0) { /* add the communications data index variable */ if ((status = nc_def_var(exoid, VAR_E_COMM_DATA_IDX, index_type, 1, e_dimid, &e_varid_idx)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_DATA_IDX, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* now add up all of the nodal communications maps */ ecnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { if (index_type == NC_INT64) { num_icm = ((int64_t*)e_var_idx)[iproc+1] - ((int64_t*)e_var_idx)[iproc]; } else { num_icm = ((int*)e_var_idx)[iproc+1] - ((int*)e_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { if (ex_int64_status(exoid) & EX_BULK_INT64_API) { ecnt_cmap += ((int64_t*)elem_cmap_elem_cnts)[((int64_t*)elem_proc_ptrs)[iproc]+icm]; } else { ecnt_cmap += ((int*)elem_cmap_elem_cnts)[((int*)elem_proc_ptrs)[iproc]+icm]; } } } /* Add dimensions for elemental communications maps */ if ((status = nc_def_dim(exoid, DIM_ECNT_CMAP, ecnt_cmap, &e_dimid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add dimension for \"%s\" in file ID %d", DIM_ECNT_CMAP, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } /* Define variables for the element IDS and processor vectors */ if ((status = nc_def_var(exoid, VAR_E_COMM_EIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_EIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_E_COMM_PROC, NC_INT, 1, e_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_PROC, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); if ((status = nc_def_var(exoid, VAR_E_COMM_SIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to add variable \"%s\" in file ID %d", VAR_E_COMM_SIDS, exoid); ex_err(func_name, errmsg, exerrval); /* Leave define mode before returning */ ex_leavedef(exoid, func_name); return (EX_FATAL); } ex_compress_variable(exoid, varid, 1); } /* End "if (num_e_comm_maps > 0)" */ /* Exit define mode */ ex_leavedef(exoid, func_name); /* Set the status of the nodal communication maps */ if (num_n_comm_maps > 0) { /* need to get the two "n_comm_*" variable ids */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &n_varid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the comm map IDs vector */ if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &n_varid[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_N_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* reset the index variable */ nl_ncnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { size_t proc_ptr; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { proc_ptr = ((int64_t*)node_proc_ptrs)[iproc]; } else { proc_ptr = ((int*)node_proc_ptrs)[iproc]; } if (index_type == NC_INT64) { num_icm = ((int64_t*)n_var_idx)[iproc+1] - ((int64_t*)n_var_idx)[iproc]; } else { num_icm = ((int*)n_var_idx)[iproc+1] - ((int*)n_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { size_t cnt; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { cnt = ((int64_t*)node_cmap_node_cnts)[proc_ptr+icm]; } else { cnt = ((int*)node_cmap_node_cnts)[proc_ptr+icm]; } if (index_type == NC_INT64) { start[0] = ((int64_t*)n_var_idx)[iproc] + icm; } else { start[0] = ((int*)n_var_idx)[iproc] + icm; } if (cnt > 0) { nmstat = 1; } else { nmstat = 0; } if ((status = nc_put_var1_int(exoid, n_varid[0], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* increment to the next starting position */ nl_ncnt_cmap += cnt; /* fill the data index variable */ status = nc_put_var1_longlong(exoid, n_varid_idx, start, &nl_ncnt_cmap); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "for(icm=0; icm < num_icm; icm++)" */ if (num_icm > 0) { /* Output the nodal comm map IDs */ if (index_type == NC_INT64) { start[0] = ((int64_t*)n_var_idx)[iproc]; } else { start[0] = ((int*)n_var_idx)[iproc]; } count[0] = num_icm; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_vara_longlong(exoid, n_varid[1], start, count, &((long long*)node_cmap_ids)[proc_ptr]); } else { status = nc_put_vara_int(exoid, n_varid[1], start, count, &((int*)node_cmap_ids)[proc_ptr]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */ /* free up memory for index */ free(n_var_idx); } /* End "if (num_n_comm_maps > 0)" */ /* Set the status of the elemental communication maps */ if (num_e_comm_maps > 0) { /* need to get the two "e_comm_*" variables" */ /* Get variable ID for elemental status vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &e_varid[0])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the variable ID for the elemental comm map IDs vector */ if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &e_varid[1])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find variable ID for \"%s\" in file ID %d", VAR_E_COMM_IDS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* reset the index variable */ nl_ecnt_cmap = 0; for(iproc=0; iproc < num_procs_in_file; iproc++) { size_t proc_ptr; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { proc_ptr = ((int64_t*)elem_proc_ptrs)[iproc]; } else { proc_ptr = ((int*)elem_proc_ptrs)[iproc]; } if (index_type == NC_INT64) { num_icm = ((int64_t*)e_var_idx)[iproc+1] - ((int64_t*)e_var_idx)[iproc]; } else { num_icm = ((int*)e_var_idx)[iproc+1] - ((int*)e_var_idx)[iproc]; } for(icm=0; icm < num_icm; icm++) { size_t cnt; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { cnt = ((int64_t*)elem_cmap_elem_cnts)[proc_ptr+icm]; } else { cnt = ((int*)elem_cmap_elem_cnts)[proc_ptr+icm]; } if (index_type == NC_INT64) { start[0] = ((int64_t*)e_var_idx)[iproc] + icm; } else { start[0] = ((int*)e_var_idx)[iproc] + icm; } if (cnt > 0) { nmstat = 1; } else { nmstat = 0; } if ((status = nc_put_var1_int(exoid, e_varid[0], start, &nmstat)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: unable to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* increment to the next starting position */ nl_ecnt_cmap += cnt; /* fill the data index variable */ status = nc_put_var1_longlong(exoid, e_varid_idx, start, &nl_ecnt_cmap); if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output int elem map index in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "for(icm=0; icm < num_icm; icm++)" */ if (num_icm > 0) { /* Output the elemental comm map IDs */ if (index_type == NC_INT64) { start[0] = ((int64_t*)e_var_idx)[iproc]; } else { start[0] = ((int*)e_var_idx)[iproc]; } count[0] = num_icm; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { status = nc_put_vara_longlong(exoid, e_varid[1], start, count, &((long long*)elem_cmap_ids)[proc_ptr]); } else { status = nc_put_vara_int(exoid, e_varid[1], start, count, &((int*)elem_cmap_ids)[proc_ptr]); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to output variable in file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */ free(e_var_idx); } /* End "if (num_e_comm_maps > 0)" */ return (EX_NOERR); }
int ex_put_partial_set (int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t offset, int64_t num_to_put, 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; size_t start[1], count[1]; 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_MSG); 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) { start[0] = offset-1; count[0] = num_to_put; if (count[0] == 0) start[0] = 0; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, entry_list_id, start, count, set_entry_list); } else { status = nc_put_vara_int(exoid, entry_list_id, start, count, 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 ) { start[0] = offset-1; count[0] = num_to_put; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, extra_list_id, start, count, set_extra_list); } else { status = nc_put_vara_int(exoid, extra_list_id, start, count, 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); }
/*! * writes a map; this is a vector of integers of length number of mesh * objects of that type (element, node, face, edge) */ int ex_put_partial_num_map (int exoid, ex_entity_type map_type, ex_entity_id map_id, int64_t ent_start, int64_t ent_count, const void_int *map) { int status; int dimid, varid, map_ndx, map_exists; size_t start[1]; size_t num_maps, num_mobj, count[1]; int cur_num_maps; char errmsg[MAX_ERR_LENGTH]; const char* dnumentries; const char* dnummaps; const char* vmapids; const char* vmap; exerrval = 0; /* clear error code */ switch ( map_type ) { case EX_NODE_MAP: dnumentries = DIM_NUM_NODES; dnummaps = DIM_NUM_NM; vmapids = VAR_NM_PROP(1); break; case EX_EDGE_MAP: dnumentries = DIM_NUM_EDGE; dnummaps = DIM_NUM_EDM; vmapids = VAR_EDM_PROP(1); break; case EX_FACE_MAP: dnumentries = DIM_NUM_FACE; dnummaps = DIM_NUM_FAM; vmapids = VAR_FAM_PROP(1); break; case EX_ELEM_MAP: dnumentries = DIM_NUM_ELEM; dnummaps = DIM_NUM_EM; vmapids = VAR_EM_PROP(1); break; default: exerrval = EX_BADPARAM; sprintf( errmsg, "Error: Bad map type (%d) specified for file id %d", map_type, exoid ); ex_err( "ex_put_num_map", errmsg, exerrval ); return (EX_FATAL); } /* Make sure the file contains entries */ if (nc_inq_dimid (exoid, dnumentries, &dimid) != NC_NOERR ) { return (EX_NOERR); } /* first check if any maps are specified */ if ((status = nc_inq_dimid (exoid, dnummaps, &dimid)) != NC_NOERR ) { exerrval = status; sprintf(errmsg, "Error: no %ss specified in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } /* Check for duplicate map id entry */ ex_id_lkup(exoid,map_type,map_id); if (exerrval == EX_LOOKUPFAIL) { /* did not find the map id */ map_exists = 0; /* Map is being defined */ } else { map_exists = 1; /* A portion of this map has already been written */ } /* Check for duplicate map id entry */ if (!map_exists) { /* Get number of maps initialized for this file */ if ((status = nc_inq_dimlen(exoid,dimid,&num_maps)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of %ss in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } /* Keep track of the total number of maps defined using a counter stored in a linked list keyed by exoid. NOTE: ex_get_file_item is used to find the number of element maps for a specific file and returns that value. */ cur_num_maps = ex_get_file_item(exoid, ex_get_counter_list(map_type)); if (cur_num_maps >= (int)num_maps) { exerrval = EX_FATAL; sprintf(errmsg, "Error: exceeded number of %ss (%"ST_ZU") specified in file id %d", ex_name_of_object(map_type),num_maps,exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } /* NOTE: ex_inc_file_item is used to find the number of element maps for a specific file and returns that value incremented. */ cur_num_maps = ex_inc_file_item(exoid, ex_get_counter_list(map_type)); } else { map_ndx = ex_id_lkup(exoid,map_type,map_id); cur_num_maps = map_ndx-1; } /* determine number of elements */ if ((status = nc_inq_dimid(exoid, dnumentries, &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: couldn't determine number of mesh objects in file id %d", exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, &num_mobj)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of mesh objects in file id %d", exoid); ex_err("ex_put_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; sprintf(errmsg, "Error: start count is invalid in file id %d", exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } if (ent_count < 0) { exerrval = EX_FATAL; sprintf(errmsg, "Error: Invalid count value in file id %d", exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } if (ent_start+ent_count-1 > num_mobj) { exerrval = EX_FATAL; sprintf(errmsg, "Error: start+count-1 is larger than mesh object count in file id %d", exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } /* write out information to previously defined variable */ /* first get id of variable */ if ((status = nc_inq_varid (exoid, vmapids, &varid)) == -1) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s ids in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } /* then, write out map id */ if (!map_exists) { start[0] = cur_num_maps; { if ((status = nc_put_var1_longlong(exoid, varid, start, (long long*)&map_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s id %"PRId64" in file id %d", ex_name_of_object(map_type),map_id,exoid); ex_err("ex_put_num_map",errmsg,exerrval); return (EX_FATAL); } } } switch ( map_type ) { case EX_NODE_MAP: vmap = VAR_NODE_MAP(cur_num_maps+1); break; case EX_EDGE_MAP: vmap = VAR_EDGE_MAP(cur_num_maps+1); break; case EX_FACE_MAP: vmap = VAR_FACE_MAP(cur_num_maps+1); break; case EX_ELEM_MAP: vmap = VAR_ELEM_MAP(cur_num_maps+1); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized map type in switch: %d in file id %d", map_type,exoid); ex_err("ex_putt_partial_one_attr",errmsg,EX_MSG); return (EX_FATAL); } /* locate variable array in which to store the map */ if ((status = nc_inq_varid(exoid,vmap, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s %"PRId64" in file id %d", ex_name_of_object(map_type),map_id,exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } /* write out the map */ start[0] = ent_start-1; count[0] = ent_count; if (count[0] == 0) start[0] = 0; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, map); } else { status = nc_put_vara_int(exoid, varid, start, count, map); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store %s in file id %d", ex_name_of_object(map_type),exoid); ex_err("ex_put_partial_num_map",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_put_processor_elem_maps(int exoid, void_int *elem_mapi, void_int *elem_mapb, int processor) { const char *func_name = "ex_put_processor_elem_maps"; char ftype[2]; int status, dimid, varid; size_t start[1], count[1]; int64_t varidx[2]; int nmstat; char errmsg[MAX_ERR_LENGTH]; /*-----------------------------Execution begins-----------------------------*/ ex_check_valid_file_id(exoid); /* Get the file type */ if (ex_get_file_type(exoid, ftype) != EX_NOERR) { exerrval = EX_MSG; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Get the status of the internal element map */ if ((status = nc_inq_varid(exoid, VAR_INT_E_STAT, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_INT_E_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ftype[0] == 's') { start[0] = processor; } else { start[0] = 0; } if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", VAR_INT_E_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (nmstat == 1) { /* get the index */ if (ex_get_idx(exoid, VAR_ELEM_MAP_INT_IDX, varidx, processor) == -1) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_ELEM_MAP_INT_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (varidx[1] == -1) { /* Get the size of the internal element map */ if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_ELEMS, &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_ELEMS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_INT_ELEMS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = count[0]; } if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_INT, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_ELEM_MAP_INT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the map */ start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, elem_mapi); } else { status = nc_put_vara_int(exoid, varid, start, count, elem_mapi); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", VAR_ELEM_MAP_INT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (nmstat == 1)" */ /* Get the status of the border element map */ if ((status = nc_inq_varid(exoid, VAR_BOR_E_STAT, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_BOR_E_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (ftype[0] == 's') { start[0] = processor; } else { start[0] = 0; } if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file %d", VAR_BOR_E_STAT, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (nmstat == 1) { /* get the index */ if (ex_get_idx(exoid, VAR_ELEM_MAP_BOR_IDX, varidx, processor) == -1) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_ELEM_MAP_BOR_IDX, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if (varidx[1] == -1) { /* Get the size of the border element map */ if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_ELEMS, &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_ELEMS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_BOR_ELEMS, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } varidx[1] = count[0]; } if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_BOR, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", VAR_ELEM_MAP_BOR, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } /* Output the map */ start[0] = varidx[0]; count[0] = varidx[1] - varidx[0]; if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { status = nc_put_vara_longlong(exoid, varid, start, count, elem_mapb); } else { status = nc_put_vara_int(exoid, varid, start, count, elem_mapb); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", VAR_ELEM_MAP_BOR, exoid); ex_err(func_name, errmsg, exerrval); return (EX_FATAL); } } /* End "if (nmstat == 1)" */ return (EX_NOERR); }