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