/* * Copyright (c) 2006 Sandia Corporation. Under the terms of Contract * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement * retains certain rights in this software. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * * Neither the name of Sandia Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include #include #include "exodusII.h" #include "exodusII_int.h" /*! \fn{int ex_inquire (int exoid, int req_info, int *ret_int, void *ret_float, char *ret_char)} The function ex_inquire() is used to inquire values of certain data entities in an exodus file. Memory must be allocated for the returned values before this function is invoked.query database. \sa ex_inquire_int(). \return In case of an error, ex_inquire() returns a negative number; a warning will return a positive number. Possible causes of errors include: - data file not properly opened with call to ex_create() or ex_open(). - requested information not stored in the file. - invalid request flag. \param[in] exoid exodus file ID returned from a previous call to ex_create() or ex_open(). \param[in] req_info A flag which designates what information is requested. It must be one of the following constants in the table below. \param[out] ret_int Returned integer, if an integer value is requested (according to \c req_info); otherwise, supply a dummy argument. \param[out] ret_float Returned float, if a float value is requested (according to \c req_info); otherwise, supply a dummy argument. This argument is always a float even if the database IO and/or CPU word size is a double. \param[out] ret_char Returned character string, if a character value is requested (according to \c req_info); otherwise, supply a dummy argument.
\c EX_INQ_API_VERS The exodus API version number is returned in \c ret_float and an undotted version number is returned in \c ret_int. The API version number reflects the release of the function library (i.e., function names, argument list, etc.). The API and LIB version numbers are synchronized and will always match. Initially, it was thought that maintaining the two versions separately would be a benefit, but that was more confusing than helpful, so the numbers were made the same.
\c EX_INQ_DB_VERS The exodus database version number is returned in \c ret_float and an ``undotted'' version number is returned in \c ret_int. The database version number reflects the version of the library that was used to \e write the file pointed to by \c exoid.
\c EX_INQ_LIB_VERS The exodus library version number is returned in \c ret_float and an undotted version number is returned in \c ret_int. The API library version number reflects the version number of the exodus library linked with this application.
\c EX_INQ_TITLE The title stored in the database is returned in \c ret_char.
\c EX_INQ_DIM The dimensionality, or number of coordinates per node (1, 2 or 3), of the database is returned in \c ret_int.
\c EX_INQ_NODES The number of nodes is returned in \c ret_int.
\c EX_INQ_ELEM The number of elements is returned in \c ret_int.
\c EX_INQ_ELEM_BLK The number of element blocks is returned in \c ret_int.
\c EX_INQ_NODE_SETS The number of node sets is returned in \c ret_int.
\c EX_INQ_NS_NODE_LEN The length of the concatenated node sets node list is returned in \c ret_int.
\c EX_INQ_NS_DF_LEN The length of the concatenated node sets distribution list is returned in \c ret_int.
\c EX_INQ_SIDE_SETS The number of side sets is returned in \c ret_int.
\c EX_INQ_SS_ELEM_LEN The length of the concatenated side sets element list is returned in \c ret_int.
\c EX_INQ_SS_DF_LEN The length of the concatenated side sets distribution factor list is returned in \c ret_int.
\c EX_INQ_SS_NODE_LEN The aggregate length of all of the side sets node lists is returned in \c ret_int.
\c EX_INQ_EB_PROP The number of integer properties stored for each element block is returned in \c ret_int; this number includes the property named \c ID.
\c EX_INQ_NS_PROP The number of integer properties stored for each node set is returned in \c ret_int; this number includes the property named \c ID.
\c EX_INQ_SS_PROP The number of integer properties stored for each side set is returned in \c ret_int; this number includes the property named \c ID.
\c EX_INQ_QA The number of QA records is returned in \c ret_int.
\c EX_INQ_INFO The number of information records is returned in \c ret_int.
\c EX_INQ_TIME The number of time steps stored in the database is returned in \c ret_int.
\c EX_INQ_EDGE_BLK The number of edge blocks is returned in \c ret_int.
\c EX_INQ_EDGE_MAP The number of edge maps is returned in \c ret_int.
\c EX_INQ_EDGE_PROP The number of properties stored per edge blockis returned in \c ret_int.
\c EX_INQ_EDGE_SETS The number of edge sets is returned in \c ret_int.
\c EX_INQ_EDGE The number of edges is returned in \c ret_int.
\c EX_INQ_FACE The number of faces is returned in \c ret_int.
\c EX_INQ_EB_PROP The number of element block properties is returned in \c ret_int.
\c EX_INQ_ELEM_MAP The number of element maps is returned in \c ret_int.
\c EX_INQ_ELEM_SETS The number of element sets is returned in \c ret_int.
\c EX_INQ_ELS_DF_LEN The length of the concatenated element set distribution factor list is returned in \c ret_int.
\c EX_INQ_ELS_LEN The length of the concatenated element set element list is returned in \c ret_int.
\c EX_INQ_ELS_PROP The number of properties stored per elem set is returned in \c ret_int.
\c EX_INQ_EM_PROP The number of element map properties is returned in \c ret_int.
\c EX_INQ_ES_DF_LEN The length of the concatenated edge set distribution factor list is returned in \c ret_int.
\c EX_INQ_ES_LEN The length of the concatenated edge set edge list is returned in \c ret_int.
\c EX_INQ_ES_PROP The number of properties stored per edge set is returned in \c ret_int.
\c EX_INQ_FACE_BLK The number of face blocks is returned in \c ret_int.
\c EX_INQ_FACE_MAP The number of face maps is returned in \c ret_int.
\c EX_INQ_FACE_PROP The number of properties stored per face block is returned in \c ret_int.
\c EX_INQ_FACE_SETS The number of face sets is returned in \c ret_int.
\c EX_INQ_FS_DF_LEN The length of the concatenated face set distribution factor list is returned in \c ret_int.
\c EX_INQ_FS_LEN The length of the concatenated face set face list is returned in \c ret_int.
\c EX_INQ_FS_PROP The number of properties stored per face set is returned in \c ret_int.
\c EX_INQ_NM_PROP The number of node map properties is returned in \c ret_int.
\c EX_INQ_NODE_MAP The number of node maps is returned in \c ret_int.
\c EX_INQ_COORD_FRAMES The number of coordinate frames is returned in \c ret_int.
As an example, the following will return the number of element block properties stored in the exodus file : \code #include "exodusII.h" int error, exoid, num_props; float fdum; char *cdum; \comment{determine the number of element block properties} error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum); ...Another way to get the same information num_props = ex_inquire_int(exoid, EX_INQ_EB_PROP); \endcode */ /*! \cond INTERNAL */ static int ex_get_dimension_value(int exoid, int *var, int default_value, const char *dimension_name, int missing_ok) { int status; char errmsg[MAX_ERR_LENGTH]; size_t idum; int dimid; if ((status = nc_inq_dimid( exoid, dimension_name, &dimid)) != NC_NOERR) { *var = default_value; if ( missing_ok ) { return (EX_NOERR); } else { exerrval = status; sprintf( errmsg, "Error: failed to retrieve dimension %s for file id %d", dimension_name, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } if ((status = nc_inq_dimlen( exoid, dimid, &idum)) != NC_NOERR) { *var = default_value; exerrval = status; sprintf( errmsg, "Error: failed to retrieve value for dimension %s for file id %d", dimension_name, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *var = (int)idum; return (EX_NOERR); } static int ex_get_concat_set_len(int exoid, int *set_length, const char *set_name, ex_entity_type set_type, const char *set_num_dim, const char *set_stat_var, const char *set_size_root, int missing_ok) { int i; int status; char errmsg[MAX_ERR_LENGTH]; size_t idum; int dimid, varid; size_t num_sets; int *stat_vals = NULL; int *ids = NULL; *set_length = 0; /* default return value */ if ((status = nc_inq_dimid (exoid, set_num_dim, &dimid)) == NC_NOERR) { if ((status = nc_inq_dimlen (exoid, dimid, &num_sets)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of %s sets in file id %d", set_name, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (!(ids = malloc(num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for %s set ids for file id %d", set_name, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ex_get_ids (exoid, set_type, ids) == EX_FATAL) { sprintf(errmsg, "Error: failed to get %s set ids in file id %d", set_name, exoid); ex_err("ex_inquire",errmsg,exerrval); free(ids); return (EX_FATAL); } /* Allocate space for stat array */ if (!(stat_vals = malloc((int)num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; free (ids); sprintf(errmsg, "Error: failed to allocate memory for %s set status array for file id %d", set_name, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } /* get variable id of status array */ if ((status = nc_inq_varid (exoid, set_stat_var, &varid)) == NC_NOERR) { /* if status array exists, use it, otherwise assume, object exists to be backward compatible */ if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) { exerrval = status; free (ids); free(stat_vals); sprintf(errmsg, "Error: failed to get %s set status array from file id %d", set_name, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } else /* default: status is true */ for(i=0;i