1 /*
2  * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract
3  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
4  * retains certain rights in this software.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *
13  *     * Redistributions in binary form must reproduce the above
14  *       copyright notice, this list of conditions and the following
15  *       disclaimer in the documentation and/or other materials provided
16  *       with the distribution.
17  *
18  *     * Neither the name of Sandia Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #include "exodusII.h"
37 #include "exodusII_int.h"
38 #include <string.h>
39 
40 /*!
41 
42 The function ex_put_coord_names() writes the names (\p
43 MAX_STR_LENGTH-characters in length) of the coordinate arrays to the
44 database. Memory must be allocated for the character strings before
45 this function is invoked.
46 
47 In case of an error, ex_put_coord_names() returns a negative number; a
48 warning will return a positive number.  Possible causes of errors
49 include:
50   -  data file not properly opened with call to ex_create() or ex_open()
51   -  data file opened for read only.
52   -  data file not initialized properly with call to ex_put_init().
53 
54 \param[in] exoid          exodus file ID returned from a previous call to ex_create() or ex_open().
55 \param[in] coord_names    Array containing \c num_dim names of length \p MAX_STR_LENGTH
56                           of the nodal coordinate arrays.
57 
58 The following coding will write the coordinate names to an
59 open exodus file :
60 
61 \code
62 int error, exoid;
63 
64 char *coord_names[3];
65 coord_names[0] = "xcoor";
66 coord_names[1] = "ycoor";
67 coord_names[2] = "zcoor";
68 
69 error = ex_put_coord_names (exoid, coord_names);
70 \endcode
71 
72  */
73 
ex_put_coord_names(int exoid,char * coord_names[])74 int ex_put_coord_names (int   exoid,
75                         char *coord_names[])
76 {
77   int status;
78   size_t i;
79   int ndimdim, varid;
80   size_t num_dim;
81   char errmsg[MAX_ERR_LENGTH];
82 
83   exerrval = 0; /* clear error code */
84 
85   if ((status = nc_inq_dimid(exoid, DIM_NUM_DIM, &ndimdim)) != NC_NOERR) {
86     exerrval = status;
87     sprintf(errmsg,
88 	    "Error: failed to locate number of dimensions in file id %d",
89 	    exoid);
90     ex_err("ex_put_coord_names",errmsg,exerrval);
91     return (EX_FATAL);
92   }
93 
94   if ((status = nc_inq_dimlen(exoid, ndimdim, &num_dim)) != NC_NOERR) {
95     exerrval = status;
96     sprintf(errmsg,
97             "Error: inquire failed to get number of dimensions in file id %d",
98 	    exoid);
99     ex_err("ex_put_coord_names",errmsg,exerrval);
100     return (EX_FATAL);
101   }
102 
103   if ((status = nc_inq_varid(exoid, VAR_NAME_COOR, &varid)) == -1) {
104     exerrval = status;
105     sprintf(errmsg,
106             "Error: failed to locate coordinate names in file id %d",
107 	    exoid);
108     ex_err("ex_put_coord_names",errmsg,exerrval);
109     return (EX_FATAL);
110   }
111 
112   /* write out coordinate names */
113   status = ex_put_names_internal(exoid, varid, num_dim, coord_names, EX_COORDINATE,
114 				 "", "ex_put_coord_names");
115 
116   return (status);
117 }
118