41static char rcsid[] not_used ={
"$Id$"};
44#include <libdap/InternalErr.h>
46#include "NCRequestHandler.h"
50NCInt16::NCInt16(
const string &n,
const string &d) :
Int16(n, d)
63NCInt16::operator=(
const NCInt16 &rhs)
68 dynamic_cast<NCInt16&
>(*this) = rhs;
76NCInt16::ptr_duplicate(){
78 return new NCInt16(*
this);
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() +
"'.");
100 size_t cor[MAX_NC_DIMS];
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(
"'."));
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)!");
113 if (datatype != NC_SHORT)
114 throw InternalErr(__FILE__, __LINE__,
"Entered NCInt16::read() with non-Int16 variable (NC.PromoteByteToShort not set)!");
117 for (
int id = 0;
id <= num_dim &&
id < MAX_NC_DIMS;
id++) {
121 if (NCRequestHandler::get_promote_byte_to_short()) {
123 errstat = nc_get_var1_schar(ncid,varid, cor, &tmp);
128 errstat = nc_get_var1_short(ncid, varid, cor, &sht);
130 if (errstat != NC_NOERR)
131 throw Error(errstat,
string(
"Could not read the variable `") + name() +
string(
"'."));
135 dods_int16 intg16 = (dods_int16) sht;
138 if (nc_close(ncid) != NC_NOERR)
139 throw InternalErr(__FILE__, __LINE__,
"Could not close the dataset!");