Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_init_info.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2022 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 /* Function(s) contained in this file:
11 * ex_put_init_info()
12 *****************************************************************************
13 * This function writes information about the processors for which the
14 * decomposition was performed.
15 *****************************************************************************
16 * Variable Index:
17 * exoid - The NetCDF ID of an already open NemesisI file.
18 * num_proc - The number of processors in the decomposition.
19 * num_proc_in_f - The number of processors the file contains
20 * information for.
21 * ftype - The type of Nemesis file.
22 */
23 /*****************************************************************************/
24 /*****************************************************************************/
25 /*****************************************************************************/
26
27 #include <exodusII.h>
28 #include <exodusII_int.h>
29
30 /*!
31 * \ingroup ModelDescription
32 * \undoc
33 */
34 int ex_put_init_info(int exoid, int num_proc, int num_proc_in_f, const char *ftype)
35 {
36 int dimid, varid;
37 int ltempsv;
38 int lftype;
39 int status;
40 char errmsg[MAX_ERR_LENGTH];
41 /*-----------------------------Execution begins-----------------------------*/
42
43 EX_FUNC_ENTER();
44 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
45 EX_FUNC_LEAVE(EX_FATAL);
46 }
47
48 /* Check the file type */
49 if (!ftype) {
50 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: NULL file type input for file ID %d", exoid);
51 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
52
53 EX_FUNC_LEAVE(EX_FATAL);
54 }
55
56 /* Set the file type */
57 if (ftype[0] == 'p' || ftype[0] == 'P') {
58 lftype = 0;
59 }
60 else if (ftype[0] == 's' || ftype[0] == 'S') {
61 lftype = 1;
62 }
63 else {
64 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file type requested for file ID %d", exoid);
65 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
66
67 EX_FUNC_LEAVE(EX_FATAL);
68 }
69
70 /* Put file into define mode */
71 if ((status = exi_redef(exoid, __func__)) != NC_NOERR) {
72 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file ID %d into define mode", exoid);
73 ex_err_fn(exoid, __func__, errmsg, status);
74 EX_FUNC_LEAVE(EX_FATAL);
75 }
76
77 /* Define dimension for the number of processors */
78 if (nc_inq_dimid(exoid, DIM_NUM_PROCS, &dimid) != NC_NOERR) {
79 ltempsv = num_proc;
80 if ((status = nc_def_dim(exoid, DIM_NUM_PROCS, ltempsv, &dimid)) != NC_NOERR) {
81 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d",
82 DIM_NUM_PROCS, exoid);
83 ex_err_fn(exoid, __func__, errmsg, status);
84 /* Leave define mode before returning */
85 exi_leavedef(exoid, __func__);
86
87 EX_FUNC_LEAVE(EX_FATAL);
88 }
89 }
90
91 /* If this is a parallel file then the status vectors are size 1 */
92 if (nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &dimid) != NC_NOERR) {
93 ltempsv = num_proc_in_f;
94 if ((status = nc_def_dim(exoid, DIM_NUM_PROCS_F, ltempsv, &dimid)) != NC_NOERR) {
95 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d",
96 DIM_NUM_PROCS_F, exoid);
97 ex_err_fn(exoid, __func__, errmsg, status);
98
99 /* Leave define mode before returning */
100 exi_leavedef(exoid, __func__);
101
102 EX_FUNC_LEAVE(EX_FATAL);
103 }
104 }
105
106 /* Output the file type */
107 if (nc_inq_varid(exoid, VAR_FILE_TYPE, &varid) != NC_NOERR) {
108 if ((status = nc_def_var(exoid, VAR_FILE_TYPE, NC_INT, 0, NULL, &varid)) != NC_NOERR) {
109 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define file type in file ID %d", exoid);
110 ex_err_fn(exoid, __func__, errmsg, status);
111
112 /* Leave define mode before returning */
113 exi_leavedef(exoid, __func__);
114
115 EX_FUNC_LEAVE(EX_FATAL);
116 }
117
118 if (exi_leavedef(exoid, __func__) != EX_NOERR) {
119 EX_FUNC_LEAVE(EX_FATAL);
120 }
121
122 if ((status = nc_put_var1_int(exoid, varid, NULL, &lftype)) != NC_NOERR) {
123 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to output file type variable in file ID %d",
124 exoid);
125 ex_err_fn(exoid, __func__, errmsg, status);
126
127 EX_FUNC_LEAVE(EX_FATAL);
128 }
129 }
130 else {
131 if (exi_leavedef(exoid, __func__) != EX_NOERR) {
132 EX_FUNC_LEAVE(EX_FATAL);
133 }
134 }
135
136 EX_FUNC_LEAVE(EX_NOERR);
137 }