bes  Updated for version 3.20.6
NCFloat32.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++ -*-
28 
29 // (c) COPYRIGHT URI/MIT 1994-1999
30 // Please read the full copyright statement in the file COPYRIGHT.
31 //
32 // Authors:
33 // reza Reza Nekovei (rnekovei@ieee.org)
34 
35 // netCDF sub-class implementation for NCByte,...NCGrid.
36 // The files are patterned after the subcalssing examples
37 // Test<type>.c,h files.
38 //
39 // ReZa 3/26/99
40 
41 #include "config_nc.h"
42 
43 static char rcsid[] not_used ={"$Id$"};
44 
45 #include <netcdf.h>
46 
47 #include <InternalErr.h>
48 
49 #include "NCFloat32.h"
50 
51 
52 NCFloat32::NCFloat32(const string &n, const string &d) : Float32(n, d)
53 {
54 }
55 
56 NCFloat32::NCFloat32(const NCFloat32 &rhs) : Float32(rhs)
57 {
58 }
59 
60 NCFloat32::~NCFloat32()
61 {
62 }
63 
64 NCFloat32 &
65 NCFloat32::operator=(const NCFloat32 &rhs)
66 {
67  if (this == &rhs)
68  return *this;
69 
70  dynamic_cast<NCFloat32&>(*this) = rhs;
71 
72 
73  return *this;
74 }
75 
76 BaseType *
77 NCFloat32::ptr_duplicate()
78 {
79  return new NCFloat32(*this); // Copy ctor calls duplicate to do the work
80 }
81 
82 
83 bool NCFloat32::read()
84 {
85  int varid; /* variable Id */
86  nc_type datatype; /* variable data type */
87  size_t cor[MAX_NC_DIMS]; /* corner coordinates */
88  int num_dim; /* number of dim. in variable */
89  dods_float32 flt32;
90  int id;
91 
92  if (read_p()) // nothing to do here
93  return true;
94 
95  int ncid, errstat;
96  errstat = nc_open(dataset().c_str(), NC_NOWRITE, &ncid); /* netCDF id */
97  if (errstat != NC_NOERR) {
98  string err = "Could not open the dataset's file (" + dataset() + ")";
99  throw Error(errstat, err);
100  }
101 
102  errstat = nc_inq_varid(ncid, name().c_str(), &varid);
103  if (errstat != NC_NOERR)
104  throw Error(errstat, "Could not get variable ID for '" + name() + "'.");
105 
106  errstat = nc_inq_var(ncid, varid, (char *) 0, &datatype, &num_dim, (int *) 0, (int *) 0);
107  if (errstat != NC_NOERR)
108  throw Error(errstat, string("Could not read information about the variable `") + name() + string("'."));
109 
110  for (id = 0; id <= num_dim && id < MAX_NC_DIMS; id++)
111  cor[id] = 0;
112 
113  if (datatype == NC_FLOAT) {
114  float flt;
115 
116  errstat = nc_get_var1_float(ncid, varid, cor, &flt);
117  if (errstat != NC_NOERR)
118  throw Error(errstat, string("Could not read the variable `") + name() + string("'."));
119 
120  set_read_p(true);
121 
122  flt32 = (dods_float32) flt;
123  val2buf(&flt32);
124 
125  if (nc_close(ncid) != NC_NOERR)
126  throw InternalErr(__FILE__, __LINE__, "Could not close the dataset!");
127  }
128  else
129  throw InternalErr(__FILE__, __LINE__, "Entered NCFloat32::read() with non-float variable!");
130 
131  return true;
132 }
133 
134 // $Log: NCFloat32.cc,v $
135 // Revision 1.14 2005/04/19 23:16:18 jimg
136 // Removed client side parts; the client library is now in libnc-dap.
137 //
138 // Revision 1.13 2005/04/08 17:08:47 jimg
139 // Removed old 'virtual ctor' functions which have now been replaced by the
140 // factory class code in libdap++.
141 //
142 // Revision 1.12 2005/03/31 00:04:51 jimg
143 // Modified to use the factory class in libdap++ 3.5.
144 //
145 // Revision 1.11 2005/02/17 23:44:13 jimg
146 // Modifications for processing of command line projections combined
147 // with the limit stuff and projection info passed in from the API. I also
148 // consolodated some of the code by moving d_source from various
149 // classes to NCAccess. This may it so that DODvario() could be simplified
150 // as could build_constraint() and store_projection() in NCArray.
151 //
152 // Revision 1.10 2005/01/26 23:25:51 jimg
153 // Implemented a fix for Sequence access by row number when talking to a
154 // 3.4 or earlier server (which contains a bug in is_end_of_rows()).
155 //
156 // Revision 1.9 2004/11/30 22:11:35 jimg
157 // I replaced the flatten_*() functions with a flatten() method in
158 // NCAccess. The default version of this method is in NCAccess and works
159 // for the atomic types; constructors must provide a specialization.
160 // Then I removed the code that copied the variables from vectors to
161 // lists. The translation code in NCConnect was modified to use the
162 // new method.
163 //
164 // Revision 1.8 2004/10/22 21:51:34 jimg
165 // More massive changes: Translation of Sequences now works so long as the
166 // Sequence contains only atomic types.
167 //
168 // Revision 1.7 2004/09/08 22:08:21 jimg
169 // More Massive changes: Code moved from the files that clone the netCDF
170 // function calls into NCConnect, NCAccess or nc_util.cc. Much of the
171 // translation functions are now methods. The netCDF type classes now
172 // inherit from NCAccess in addition to the DAP type classes.
173 //
174 // Revision 1.6 2003/12/08 18:06:37 edavis
175 // Merge release-3-4 into trunk
176 //
177 // Revision 1.5 2003/09/25 23:09:36 jimg
178 // Meerged from 3.4.1.
179 //
180 // Revision 1.4.8.1 2003/06/06 08:23:41 reza
181 // Updated the servers to netCDF-3 and fixed error handling between client and server.
182 //
183 // Revision 1.4 2000/10/06 01:22:02 jimg
184 // Moved the CVS Log entries to the ends of files.
185 // Modified the read() methods to match the new definition in the dap library.
186 // Added exception handlers in various places to catch exceptions thrown
187 // by the dap library.
188 //
189 // Revision 1.3 1999/11/05 05:15:05 jimg
190 // Result of merge woth 3-1-0
191 //
192 // Revision 1.1.2.1 1999/10/29 05:05:21 jimg
193 // Reza's fixes plus the configure & Makefile update
194 //
195 // Revision 1.2 1999/10/21 13:19:06 reza
196 // IMAP and other bug fixed for version3.
197 //
198 // Revision 1.1 1999/07/28 00:22:43 jimg
199 // Added
200 //
201 // Revision 1.3.2.1 1999/05/27 17:43:23 reza
202 // Fixed bugs in string changes
203 //
204 // Revision 1.3 1999/05/07 23:45:32 jimg
205 // String --> string fixes
206 //
207 // Revision 1.2 1999/04/09 17:11:56 jimg
208 // Fixed comments and copyright statement
209 //
210 // Revision 1.1 1999/03/30 21:12:06 reza
211 // Added the new types
212 
213 
Error
NCFloat32
Definition: NCFloat32.h:46