39 #include "config_nc.h"
41 static char rcsid[] not_used ={
"$Id$"};
44 #include <InternalErr.h>
46 #include "NCRequestHandler.h"
50 NCInt16::NCInt16(
const string &n,
const string &d) : Int16(n, d)
54 NCInt16::NCInt16(
const NCInt16 &rhs) : Int16(rhs)
63 NCInt16::operator=(
const NCInt16 &rhs)
68 dynamic_cast<NCInt16&
>(*this) = rhs;
76 NCInt16::ptr_duplicate(){
81 bool NCInt16::read() {
86 errstat = nc_open(dataset().c_str(), NC_NOWRITE, &ncid);
87 if (errstat != NC_NOERR) {
88 string err =
"Could not open the dataset's file (" + dataset() +
")";
89 throw Error(errstat, err);
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() +
"'.");
99 #if NETCDF_VERSION >= 4
100 errstat = nc_get_var(ncid, varid, &sht);
102 size_t cor[MAX_NC_DIMS];
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(
"'."));
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)!");
115 if (datatype != NC_SHORT)
116 throw InternalErr(__FILE__, __LINE__,
"Entered NCInt16::read() with non-Int16 variable (NC.PromoteByteToShort not set)!");
119 for (
int id = 0;
id <= num_dim &&
id < MAX_NC_DIMS;
id++) {
123 errstat = nc_get_var1_short(ncid, varid, cor, &sht);
126 if (errstat != NC_NOERR)
127 throw Error(errstat,
string(
"Could not read the variable `") + name() +
string(
"'."));
131 dods_int16 intg16 = (dods_int16) sht;
134 if (nc_close(ncid) != NC_NOERR)
135 throw InternalErr(__FILE__, __LINE__,
"Could not close the dataset!");