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