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