bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
NCInt32.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of nc_handler, a data handler for the OPeNDAP data
4// server.
5
6// Copyright (c) 2002,2003 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This is free software; you can redistribute it and/or modify it under the
10// terms of the GNU Lesser General Public License as published by the Free
11// Software Foundation; either version 2.1 of the License, or (at your
12// option) any later version.
13//
14// This software is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17// License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25
26// (c) COPYRIGHT URI/MIT 1994-1996
27// Please read the full copyright statement in the file COPYRIGHT.
28//
29// Authors:
30// reza Reza Nekovei (reza@intcomm.net)
31
32// netCDF sub-class implementation for NCByte,...NCGrid.
33// The files are patterned after the subcalssing examples
34// Test<type>.c,h files.
35//
36// ReZa 3/27/99
37
38#include "config_nc.h"
39
40static char rcsid[] not_used = { "$Id$" };
41
42#include <netcdf.h>
43#include <libdap/InternalErr.h>
44
45#include "NCInt32.h"
46
47NCInt32::NCInt32(const string &n, const string &d) :
48 Int32(n, d)
49{
50}
51
52NCInt32::NCInt32(const NCInt32 &rhs) :
53 Int32(rhs)
54{
55}
56
57NCInt32::~NCInt32()
58{
59}
60
61NCInt32 &
62NCInt32::operator=(const NCInt32 &rhs)
63{
64 if (this == &rhs)
65 return *this;
66
67 dynamic_cast<NCInt32&> (*this) = rhs;
68
69 return *this;
70}
71
72BaseType *
73NCInt32::ptr_duplicate()
74{
75
76 return new NCInt32(*this);
77}
78
79bool NCInt32::read()
80{
81 if (read_p()) // nothing to do
82 return true;
83
84 int ncid, errstat;
85 errstat = nc_open(dataset().c_str(), NC_NOWRITE, &ncid); /* netCDF id */
86 if (errstat != NC_NOERR) {
87 string err = "Could not open the dataset's file (" + dataset() + ")";
88 throw Error(errstat, err);
89 }
90
91 int varid; /* variable Id */
92 errstat = nc_inq_varid(ncid, name().c_str(), &varid);
93 if (errstat != NC_NOERR)
94 throw Error(errstat, "Could not get variable ID.");
95
96 long lht;
97#if NETCDF_VERSION >= 4
98 errstat = nc_get_var(ncid, varid, &lht);
99#else
100 long int lng ;
101 size_t cor[MAX_NC_DIMS]; /* corner coordinates */
102 int num_dim; /* number of dim. in variable */
103 nc_type datatype; /* variable data type */
104 errstat = nc_inq_var(ncid, varid, (char *)0, &datatype, &num_dim, (int *)0,
105 (int *)0);
106 if( errstat != NC_NOERR )
107 {
108 throw Error(errstat,string("Could not read information about the variable `") + name() + string("'."));
109 }
110 if( datatype != NC_LONG )
111 {
112 throw InternalErr(__FILE__, __LINE__, "Entered NCInt32::read() with non-Int32 variable!");
113 }
114
115 for( int id = 0; id <= num_dim && id < MAX_NC_DIMS; id++ )
116 {
117 cor[id] = 0;
118 }
119
120 errstat = nc_get_var1_long( ncid, varid, cor, &lht ) ;
121#endif
122 if (errstat != NC_NOERR)
123 throw Error(errstat, string("Could not read the variable `") + name() + string("'."));
124
125 set_read_p(true);
126
127 dods_int32 intg32 = (dods_int32) lht;
128 val2buf(&intg32);
129
130 if (nc_close(ncid) != NC_NOERR)
131 throw InternalErr(__FILE__, __LINE__, "Could not close the dataset!");
132
133 return true;
134}
135
136// $Log: NCInt32.cc,v $
137// Revision 1.14 2005/04/19 23:16:18 jimg
138// Removed client side parts; the client library is now in libnc-dap.
139//
140// Revision 1.13 2005/04/08 17:08:47 jimg
141// Removed old 'virtual ctor' functions which have now been replaced by the
142// factory class code in libdap++.
143//
144// Revision 1.12 2005/03/31 00:04:51 jimg
145// Modified to use the factory class in libdap++ 3.5.
146//
147// Revision 1.11 2005/02/17 23:44:13 jimg
148// Modifications for processing of command line projections combined
149// with the limit stuff and projection info passed in from the API. I also
150// consolodated some of the code by moving d_source from various
151// classes to NCAccess. This may it so that DODvario() could be simplified
152// as could build_constraint() and store_projection() in NCArray.
153//
154// Revision 1.10 2005/01/26 23:25:51 jimg
155// Implemented a fix for Sequence access by row number when talking to a
156// 3.4 or earlier server (which contains a bug in is_end_of_rows()).
157//
158// Revision 1.9 2004/11/30 22:11:35 jimg
159// I replaced the flatten_*() functions with a flatten() method in
160// NCAccess. The default version of this method is in NCAccess and works
161// for the atomic types; constructors must provide a specialization.
162// Then I removed the code that copied the variables from vectors to
163// lists. The translation code in NCConnect was modified to use the
164// new method.
165//
166// Revision 1.8 2004/10/22 21:51:34 jimg
167// More massive changes: Translation of Sequences now works so long as the
168// Sequence contains only atomic types.
169//
170// Revision 1.7 2004/09/08 22:08:22 jimg
171// More Massive changes: Code moved from the files that clone the netCDF
172// function calls into NCConnect, NCAccess or nc_util.cc. Much of the
173// translation functions are now methods. The netCDF type classes now
174// inherit from NCAccess in addition to the DAP type classes.
175//
176// Revision 1.6 2003/12/08 18:06:37 edavis
177// Merge release-3-4 into trunk
178//
179// Revision 1.5 2003/09/25 23:09:36 jimg
180// Meerged from 3.4.1.
181//
182// Revision 1.4.8.2 2003/06/07 22:02:32 reza
183// Fixed char vs. byte and long vs. nclong error checks.
184//
185// Revision 1.4.8.1 2003/06/06 08:23:41 reza
186// Updated the servers to netCDF-3 and fixed error handling between client and server.
187//
188// Revision 1.4 2000/10/06 01:22:02 jimg
189// Moved the CVS Log entries to the ends of files.
190// Modified the read() methods to match the new definition in the dap library.
191// Added exception handlers in various places to catch exceptions thrown
192// by the dap library.
193//
194// Revision 1.3 1999/11/05 05:15:05 jimg
195// Result of merge woth 3-1-0
196//
197// Revision 1.1.2.1 1999/10/29 05:05:21 jimg
198// Reza's fixes plus the configure & Makefile update
199//
200// Revision 1.2 1999/10/21 13:19:06 reza
201// IMAP and other bug fixed for version3.
202//
203// Revision 1.1 1999/07/28 00:22:43 jimg
204// Added
205//
206// Revision 1.8.2.1 1999/05/27 17:43:23 reza
207// Fixed bugs in string changes
208//
209// Revision 1.8 1999/05/07 23:45:32 jimg
210// String --> string fixes
211//
212// Revision 1.7 1999/03/30 05:20:56 reza
213// Added support for the new data types (Int16, UInt16, and Float32).
214//
215// Revision 1.6 1998/08/06 16:33:23 jimg
216// Fixed misuse of the read(...) member function. Return true if more data
217// is to be read, false is if not and error if an error is detected
218//
219// Revision 1.5 1996/09/17 17:06:32 jimg
220// Merge the release-2-0 tagged files (which were off on a branch) back into
221// the trunk revision.
222//
223// Revision 1.4.4.3 1996/09/17 00:26:26 jimg
224// Merged changes from a side branch which contained various changes from
225// Reza and Charles.
226// Removed ncdump and netexec since ncdump is now in its own directory and
227// netexec is no longer used.
228//
229// Revision 1.4.4.2 1996/07/10 21:44:11 jimg
230// Changes for version 2.06. These fixed lingering problems from the migration
231// from version 1.x to version 2.x.
232// Removed some (but not all) warning generated with gcc's -Wall option.
233//
234// Revision 1.4.4.1 1996/06/25 22:04:33 jimg
235// Version 2.0 from Reza.
236//
237// Revision 1.4 1995/07/09 21:33:47 jimg
238// Added copyright notice.
239//
240// Revision 1.3 1995/06/23 13:47:43 reza
241// Added scalar read and the constraint "point".
242//
243// Revision 1.2 1995/03/16 16:56:36 reza
244// Updated for the new DAP. All the read_val mfunc. and their memory management
245// are now moved to their parent class.
246// Data transfers are now in binary while DAS and DDS are still sent in ASCII.
247//
248// Revision 1.1 1995/02/10 04:57:34 reza
249// Added read and read_val functions.