1 /*
2  * Copyright(C) 1999-2020 National Technology & Engineering Solutions
3  * of Sandia, LLC (NTESS).  Under the terms of Contract DE-NA0003525 with
4  * NTESS, the U.S. Government retains certain rights in this software.
5  *
6  * See packages/seacas/LICENSE for details
7  */
8 /*****************************************************************************
9  *
10  * exggv - ex_get_glob_vars
11  *
12  * entry conditions -
13  *   input parameters:
14  *       int     exoid                   exodus file id
15  *       int     time_step               time step number
16  *       int     num_glob_vars           number of global vars in file
17  *
18  * exit conditions -
19  *       float*  glob_var_vals           array of global variable values
20  *
21  * revision history -
22  *
23  *
24  *****************************************************************************/
25 
26 #include "exodusII.h"     // for ex_err, etc
27 #include "exodusII_int.h" // for ex__comp_ws, EX_FATAL, etc
28 
29 /*!
30  Internal function. Do not use in client code.
31  */
32 
ex__get_glob_vars(int exoid,int time_step,int num_glob_vars,void * glob_var_vals)33 int ex__get_glob_vars(int exoid, int time_step, int num_glob_vars, void *glob_var_vals)
34 {
35   int    varid;
36   int    status;
37   size_t start[2], count[2];
38   char   errmsg[MAX_ERR_LENGTH];
39 
40   EX_FUNC_ENTER();
41   if (ex__check_valid_file_id(exoid, __func__) == EX_FATAL) {
42     EX_FUNC_LEAVE(EX_FATAL);
43   }
44 
45   /* inquire previously defined variable */
46   if ((status = nc_inq_varid(exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
47     snprintf(errmsg, MAX_ERR_LENGTH, "Warning: failed to locate global variables in file id %d",
48              exoid);
49     ex_err_fn(exoid, __func__, errmsg, status);
50     EX_FUNC_LEAVE(EX_WARN);
51   }
52 
53   /* read values of global variables */
54   start[0] = --time_step;
55   start[1] = 0;
56 
57   count[0] = 1;
58   count[1] = num_glob_vars;
59 
60   if (ex__comp_ws(exoid) == 4) {
61     status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
62   }
63   else {
64     status = nc_get_vara_double(exoid, varid, start, count, glob_var_vals);
65   }
66 
67   if (status != NC_NOERR) {
68     snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get global variable values from file id %d",
69              exoid);
70     ex_err_fn(exoid, __func__, errmsg, status);
71     EX_FUNC_LEAVE(EX_FATAL);
72   }
73   EX_FUNC_LEAVE(EX_NOERR);
74 }
75