40#include <libdap/InternalErr.h>
58#include "HDF5CFGeoCF1D.h"
59#include "HDF5CFGeoCFProj.h"
66using namespace HDF5CF;
69void gen_dap_onevar_dds(DDS &dds,
const HDF5CF::Var* var,
const hid_t file_id,
const string & filename)
72 BESDEBUG(
"h5",
"Coming to gen_dap_onevar_dds() "<<endl);
73 const vector<HDF5CF::Dimension *>& dims = var->
getDimensions();
78 DMR * dmr = HDF5RequestHandler::get_dmr_64bit_int();
82 D4Group* root_grp = dmr->root();
89 string error_message =
"Cannot allocate the HDF5CFInt64: " + error_message;
90 throw InternalErr(__FILE__, __LINE__, error_message);
92 sca_int64->set_is_dap4(
true);
93 map_cfh5_var_attrs_to_dap4_int64(var,sca_int64);
94 root_grp->add_var_nocopy(sca_int64);
97 else if(H5UINT64 == var->
getType()) {
103 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFInt64.");
105 sca_uint64->set_is_dap4(
true);
106 map_cfh5_var_attrs_to_dap4_int64(var,sca_uint64);
107 root_grp->add_var_nocopy(sca_uint64);
113 else if (H5FSTRING == var->
getType() || H5VSTRING == var->
getType()) {
119 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFStr.");
121 dds.add_var(sca_str);
133 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFByte.");
135 dds.add_var(sca_uchar);
147 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFInt16.");
149 dds.add_var(sca_int16);
159 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFUInt16.");
161 dds.add_var(sca_uint16);
171 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFInt32.");
173 dds.add_var(sca_int32);
183 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFUInt32.");
185 dds.add_var(sca_uint32);
195 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFFloat32.");
197 dds.add_var(sca_float32);
207 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFFloat64.");
209 dds.add_var(sca_float64);
215 throw InternalErr(__FILE__, __LINE__,
"unsupported data type.");
224 bool dap4_int64 =
false;
226 DMR * dmr = HDF5RequestHandler::get_dmr_64bit_int();
235 D4Group* root_grp = dmr->root();
238 bt->transform_to_dap4(root_grp,root_grp);
245 if(
true == dap4_int64) {
248 else if(var->
getType() == H5UINT64)
254#define HANDLE_CASE(tid,type) \
256 bt = new (type)(var->getNewName(),var->getFullPath()); \
274 HANDLE_CASE(H5FSTRING, Str)
276 HANDLE_CASE(H5VSTRING, Str)
279 throw InternalErr(__FILE__, __LINE__,
"unsupported data type.");
284 vector<HDF5CF::Dimension*>::const_iterator it_d;
285 vector<size_t> dimsizes;
286 dimsizes.resize(var->
getRank());
287 for (
int i = 0; i < var->
getRank(); i++)
288 dimsizes[i] = (dims[i])->getSize();
297 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFStr.");
300 for (it_d = dims.begin(); it_d != dims.end(); ++it_d) {
301 if (
"" == (*it_d)->getNewName())
302 ar->append_dim((*it_d)->getSize());
304 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
308 if(dap4_int64 ==
true) {
309 DMR * dmr = HDF5RequestHandler::get_dmr_64bit_int();
310 D4Group* root_grp = dmr->root();
312 BaseType* d4_var = ar->h5cfdims_transform_to_dap4_int64(root_grp);
314 map_cfh5_var_attrs_to_dap4_int64(var,d4_var);
315 root_grp->add_var_nocopy(d4_var);
332 return (((
"_FillValue" == attr->getNewName()) && (var->
getType() != attr->getType())) ?
true :
false);
339 BESDEBUG(
"h5",
"Coming to gen_dap_special_oneobj_das() "<<endl);
340 if (attr->getCount() != 1)
throw InternalErr(__FILE__, __LINE__,
"FillValue attribute can only have one element.");
342 H5DataType var_dtype = var->
getType();
343 if ((
true == HDF5RequestHandler::get_fillvalue_check())
344 && (
false == is_fvalue_valid(var_dtype, attr))) {
345 string msg =
"The attribute value is out of the range.\n";
346 msg +=
"The variable name: " + var->
getNewName() +
"\n";
347 msg +=
"The attribute name: " + attr->getNewName() +
"\n";
348 msg +=
"The error occurs inside the gen_dap_special_oneobj_das function in h5commoncfdap.cc.";
349 throw InternalErr(msg);
351 string print_rep = HDF5CFDAPUtil::print_attr(attr->getType(), 0, (
void*) (&(attr->getValue()[0])));
352 at->append_attr(attr->getNewName(), HDF5CFDAPUtil::print_type(var_dtype), print_rep);
359 BESDEBUG(
"h5",
"Coming to is_fvalue_valid() "<<endl);
360 bool ret_value =
true;
362 switch (attr->getType()) {
364 signed char final_fill_value = *((
signed char*) ((
void*) (&(attr->getValue()[0]))));
365 if ((var_dtype == H5UCHAR) && (final_fill_value<0))
371 short final_fill_value = *((
short*) ((
void*) (&(attr->getValue()[0]))));
372 if ((var_dtype == H5UCHAR) &&(final_fill_value > 255 || final_fill_value < 0))
376 else if ((var_dtype == H5UINT16) && (final_fill_value < 0))
381 unsigned short final_fill_value = *((
unsigned short*) ((
void*) (&(attr->getValue()[0]))));
382 if ((var_dtype == H5UCHAR) &&(final_fill_value > 255)) {
385 else if ((var_dtype == H5INT16) && (final_fill_value >32767)){
398 unsigned char final_fill_value = *((
unsigned char*)((
void*)(&(attr->getValue()[0]))));
399 if(var_dtype == H5CHAR) {
400 if(final_fill_value >127)
420 if (attr->getCount() != 1)
421 throw InternalErr(__FILE__,__LINE__,
"FillValue attribute can only have one element.");
423 H5DataType var_dtype = var->
getType();
428 unsigned char final_fill_value = *((
unsigned char*)((
void*)(&(attr->getValue()[0]))));
429 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
436 short final_fill_value = *((
short*)((
void*)(&(attr->getValue()[0]))));
437 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
442 short final_fill_value = *((
short*)((
void*)(&(attr->getValue()[0]))));
443 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
448 unsigned short final_fill_value = *((
unsigned short*)((
void*)(&(attr->getValue()[0]))));
449 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
455 int final_fill_value = *((
int*)((
void*)(&(attr->getValue()[0]))));
456 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
461 unsigned int final_fill_value = *((
unsigned int*)((
void*)(&(attr->getValue()[0]))));
462 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
467 float final_fill_value = *((
float*)((
void*)(&(attr->getValue()[0]))));
470 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
475 double final_fill_value = *((
double*)((
void*)(&(attr->getValue()[0]))));
476 print_rep = HDF5CFDAPUtil::print_attr(var_dtype,0,(
void*)&final_fill_value);
480 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
483 at->append_attr(attr->getNewName(), HDF5CFDAPUtil::print_type(var_dtype), print_rep);
491 BESDEBUG(
"h5",
"Coming to gen_dap_oneobj_das() "<<endl);
493 if (H5INT64 == attr->getType() || H5UINT64 == attr->getType()) {
498 else if ((H5FSTRING == attr->getType()) || (H5VSTRING == attr->getType())) {
499 gen_dap_str_attr(at, attr);
507 size_t mem_dtype_size = (attr->getBufSize()) / (attr->getCount());
508 H5DataType mem_dtype = HDF5CFDAPUtil::get_mem_dtype(attr->getType(), mem_dtype_size);
510 for (
unsigned int loc = 0; loc < attr->getCount(); loc++) {
511 string print_rep = HDF5CFDAPUtil::print_attr(mem_dtype, loc, (
void*) &(attr->getValue()[0]));
512 at->append_attr(attr->getNewName(), HDF5CFDAPUtil::print_type(attr->getType()), print_rep);
524 bool special_attr_handling = need_special_attribute_handling(attr, var);
525 if (
true == special_attr_handling) {
526 gen_dap_special_oneobj_das(at, attr, var);
533 size_t mem_dtype_size = (attr->getBufSize()) / (attr->getCount());
534 H5DataType mem_dtype = HDF5CFDAPUtil::get_mem_dtype(attr->getType(), mem_dtype_size);
536 for (
unsigned int loc = 0; loc < attr->getCount(); loc++) {
537 string print_rep = HDF5CFDAPUtil::print_attr(mem_dtype, loc, (
void*) &(attr->getValue()[0]));
538 at->append_attr(attr->getNewName(), HDF5CFDAPUtil::print_type(attr->getType()), print_rep);
546void gen_dap_onevar_dmr(libdap::D4Group* d4_grp,
const HDF5CF::Var* var,
const hid_t file_id,
const string & filename) {
548 BESDEBUG(
"h5",
"Coming to gen_dap_onevar_dmr() "<<endl);
550 const vector<HDF5CF::Dimension *>& dims = var->
getDimensions();
558 sca_str->set_is_dap4(
true);
559 map_cfh5_var_attrs_to_dap4(var,sca_str);
563 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFStr.");
565 d4_grp->add_var_nocopy(sca_str);
574 sca_uchar->set_is_dap4(
true);
575 map_cfh5_var_attrs_to_dap4(var,sca_uchar);
579 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFByte.");
581 d4_grp->add_var_nocopy(sca_uchar);
588 sca_char->set_is_dap4(
true);
589 map_cfh5_var_attrs_to_dap4(var,sca_char);
593 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFByte.");
595 d4_grp->add_var_nocopy(sca_char);
603 sca_int16->set_is_dap4(
true);
604 map_cfh5_var_attrs_to_dap4(var,sca_int16);
609 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFInt16.");
611 d4_grp->add_var_nocopy(sca_int16);
618 sca_uint16->set_is_dap4(
true);
619 map_cfh5_var_attrs_to_dap4(var,sca_uint16);
623 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFUInt16.");
625 d4_grp->add_var_nocopy(sca_uint16);
632 sca_int32->set_is_dap4(
true);
633 map_cfh5_var_attrs_to_dap4(var,sca_int32);
637 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFInt32.");
639 d4_grp->add_var_nocopy(sca_int32);
646 sca_uint32->set_is_dap4(
true);
647 map_cfh5_var_attrs_to_dap4(var,sca_uint32);
651 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFUInt32.");
653 d4_grp->add_var_nocopy(sca_uint32);
660 sca_int64->set_is_dap4(
true);
661 map_cfh5_var_attrs_to_dap4(var,sca_int64);
665 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFInt64.");
667 d4_grp->add_var_nocopy(sca_int64);
674 sca_uint64->set_is_dap4(
true);
675 map_cfh5_var_attrs_to_dap4(var,sca_uint64);
679 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFUInt64.");
681 d4_grp->add_var_nocopy(sca_uint64);
688 sca_float32->set_is_dap4(
true);
689 map_cfh5_var_attrs_to_dap4(var,sca_float32);
693 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFFloat32.");
695 d4_grp->add_var_nocopy(sca_float32);
702 sca_float64->set_is_dap4(
true);
703 map_cfh5_var_attrs_to_dap4(var,sca_float64);
707 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFFloat64.");
709 d4_grp->add_var_nocopy(sca_float64);
713 throw InternalErr(__FILE__, __LINE__,
"unsupported data type.");
723#define HANDLE_CASE(tid,type) \
725 bt = new (type)(var->getNewName(),var->getFullPath()); \
747 HANDLE_CASE(H5FSTRING, Str)
749 HANDLE_CASE(H5VSTRING, Str)
752 throw InternalErr(__FILE__, __LINE__,
"unsupported data type.");
756 vector<HDF5CF::Dimension*>::const_iterator it_d;
757 vector<size_t> dimsizes;
758 dimsizes.resize(var->
getRank());
759 for (
int i = 0; i < var->
getRank(); i++)
760 dimsizes[i] = (dims[i])->getSize();
769 throw InternalErr(__FILE__, __LINE__,
"Cannot allocate the HDF5CFStr.");
772 for (it_d = dims.begin(); it_d != dims.end(); ++it_d) {
773 if (
"" == (*it_d)->getNewName())
774 ar->append_dim((*it_d)->getSize());
776 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
780 ar->set_is_dap4(
true);
781 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_grp);
782 map_cfh5_var_attrs_to_dap4(var,d4_var);
783 d4_grp->add_var_nocopy(d4_var);
798 BESDEBUG(
"h5",
"Coming to gen_dap_str_attr() "<<endl);
799 const vector<size_t>& strsize = attr->getStrSize();
801 unsigned int temp_start_pos = 0;
802 bool is_cset_ascii = attr->getCsetType();
803 for (
unsigned int loc = 0; loc < attr->getCount(); loc++) {
804 if (strsize[loc] != 0) {
805 string tempstring(attr->getValue().begin() + temp_start_pos,
806 attr->getValue().begin() + temp_start_pos + strsize[loc]);
807 temp_start_pos += strsize[loc];
815 if ((attr->getNewName() !=
"origname") && (attr->getNewName() !=
"fullnamepath") && (
true == is_cset_ascii))
817 at->append_attr(attr->getNewName(),
"String", tempstring);
827void add_cf_grid_cvs(DDS & dds, EOS5GridPCType cv_proj_code,
float cv_point_lower,
float cv_point_upper,
828 float cv_point_left,
float cv_point_right,
const vector<HDF5CF::Dimension*>& dims)
833 if (HE5_GCTP_SNSOID == cv_proj_code || HE5_GCTP_LAMAZ == cv_proj_code || HE5_GCTP_PS == cv_proj_code) {
836 vector<HDF5CF::Dimension*>::const_iterator it_d;
837 string dim0name = dims[0]->getNewName();
838 int dim0size = dims[0]->getSize();
839 string dim1name = dims[1]->getNewName();
840 int dim1size = dims[1]->getSize();
843 BaseType *bt_dim0 = NULL;
844 BaseType *bt_dim1 = NULL;
855 ar_dim0 =
new HDF5CFGeoCF1D(HE5_GCTP_SNSOID, cv_point_upper, cv_point_lower, dim0size, dim0name, bt_dim0);
856 ar_dim0->append_dim(dim0size, dim0name);
858 ar_dim1 =
new HDF5CFGeoCF1D(HE5_GCTP_SNSOID, cv_point_left, cv_point_right, dim1size, dim1name, bt_dim1);
859 ar_dim1->append_dim(dim1size, dim1name);
860 dds.add_var(ar_dim0);
861 dds.add_var(ar_dim1);
865 if (bt_dim0)
delete bt_dim0;
866 if (bt_dim1)
delete bt_dim1;
867 if (ar_dim0)
delete ar_dim0;
868 if (ar_dim1)
delete ar_dim1;
869 throw InternalErr(__FILE__, __LINE__,
"Unable to allocate the HDFEOS2GeoCF1D instance.");
872 if (bt_dim0)
delete bt_dim0;
873 if (bt_dim1)
delete bt_dim1;
874 if (ar_dim0)
delete ar_dim0;
875 if (ar_dim1)
delete ar_dim1;
881void add_cf_grid_mapinfo_var(DDS & dds,
const EOS5GridPCType grid_proj_code,
const unsigned short g_suffix)
886 string cf_projection_base =
"eos_cf_projection";
889 if(HE5_GCTP_SNSOID == grid_proj_code) {
892 dummy_proj_cf =
new HDF5CFGeoCFProj(cf_projection_base, cf_projection_base);
893 dds.add_var(dummy_proj_cf);
897 stringstream t_suffix_ss;
898 t_suffix_ss << g_suffix;
899 string cf_projection_name = cf_projection_base +
"_" + t_suffix_ss.str();
900 dummy_proj_cf =
new HDF5CFGeoCFProj(cf_projection_name, cf_projection_name);
901 dds.add_var(dummy_proj_cf);
903 if (dummy_proj_cf)
delete dummy_proj_cf;
909void add_cf_grid_cv_attrs(DAS & das,
const vector<HDF5CF::Var*>& vars, EOS5GridPCType cv_proj_code,
910 float ,
float ,
float ,
float ,
911 const vector<HDF5CF::Dimension*>& dims,
const vector<double> &eos5_proj_params,
const unsigned short g_suffix)
913void add_cf_grid_cv_attrs(DAS & das,
const vector<HDF5CF::Var*>& vars, EOS5GridPCType cv_proj_code,
914 const vector<HDF5CF::Dimension*>& dims,
const vector<double> &eos5_proj_params,
const unsigned short g_suffix)
919 if (HE5_GCTP_SNSOID == cv_proj_code || HE5_GCTP_PS == cv_proj_code || HE5_GCTP_LAMAZ== cv_proj_code) {
921 string dim0name = (dims[0])->getNewName();
922 int dim0size = dims[0]->getSize();
923 string dim1name = (dims[1])->getNewName();
924 int dim1size = dims[1]->getSize();
927 AttrTable *at = das.get_table(dim0name);
929 at = das.add_table(dim0name,
new AttrTable);
930 at->append_attr(
"standard_name",
"String",
"projection_y_coordinate");
932 string long_name =
"y coordinate of projection ";
933 at->append_attr(
"long_name",
"String", long_name);
936 at->append_attr(
"units",
"string",
"meter");
938 at->append_attr(
"_CoordinateAxisType",
"string",
"GeoY");
940 at = das.get_table(dim1name);
941 if (!at) at = das.add_table(dim1name,
new AttrTable);
943 at->append_attr(
"standard_name",
"String",
"projection_x_coordinate");
945 long_name =
"x coordinate of projection ";
946 at->append_attr(
"long_name",
"String", long_name);
949 at->append_attr(
"units",
"string",
"meter");
952 at->append_attr(
"_CoordinateAxisType",
"string",
"GeoX");
955 string cf_projection_base =
"eos_cf_projection";
956 string cf_projection;
957 if(HE5_GCTP_SNSOID == cv_proj_code)
958 cf_projection = cf_projection_base;
960 stringstream t_suffix_ss;
961 t_suffix_ss << g_suffix;
962 cf_projection = cf_projection_base +
"_" + t_suffix_ss.str();
964 add_cf_projection_attrs(das,cv_proj_code,eos5_proj_params,cf_projection);
968 add_cf_grid_mapping_attr(das, vars, cf_projection, dim0name, dim0size, dim1name, dim1size);
975void add_cf_projection_attrs(DAS &das,EOS5GridPCType cv_proj_code,
const vector<double> &eos5_proj_params,
const string& cf_projection) {
977 AttrTable* at = das.get_table(cf_projection);
979 at = das.add_table(cf_projection,
new AttrTable);
981 if (HE5_GCTP_SNSOID == cv_proj_code) {
982 at->append_attr(
"grid_mapping_name",
"String",
"sinusoidal");
983 at->append_attr(
"longitude_of_central_meridian",
"Float64",
"0.0");
984 at->append_attr(
"earth_radius",
"Float64",
"6371007.181");
985 at->append_attr(
"_CoordinateAxisTypes",
"string",
"GeoX GeoY");
987 else if (HE5_GCTP_PS == cv_proj_code) {
993 double vert_lon_pole = HE5_EHconvAng(eos5_proj_params[4],HE5_HDFE_DMS_DEG);
996 double lat_true_scale = HE5_EHconvAng(eos5_proj_params[5],HE5_HDFE_DMS_DEG);
999 double fe = eos5_proj_params[6];
1002 double fn = eos5_proj_params[7];
1004 at->append_attr(
"grid_mapping_name",
"String",
"polar_stereographic");
1006 ostringstream s_vert_lon_pole;
1007 s_vert_lon_pole << vert_lon_pole;
1011 at->append_attr(
"straight_vertical_longitude_from_pole",
"Float64", s_vert_lon_pole.str());
1012 ostringstream s_lat_true_scale;
1013 s_lat_true_scale << lat_true_scale;
1015 at->append_attr(
"standard_parallel",
"Float64", s_lat_true_scale.str());
1018 at->append_attr(
"false_easting",
"Float64",
"0.0");
1022 at->append_attr(
"false_easting",
"Float64",s_fe.str());
1027 at->append_attr(
"false_northing",
"Float64",
"0.0");
1031 at->append_attr(
"false_northing",
"Float64",s_fn.str());
1035 if(lat_true_scale >0)
1036 at->append_attr(
"latitude_of_projection_origin",
"Float64",
"+90.0");
1038 at->append_attr(
"latitude_of_projection_origin",
"Float64",
"-90.0");
1041 at->append_attr(
"_CoordinateAxisTypes",
"string",
"GeoX GeoY");
1048 else if(HE5_GCTP_LAMAZ == cv_proj_code) {
1049 double lon_proj_origin = HE5_EHconvAng(eos5_proj_params[4],HE5_HDFE_DMS_DEG);
1050 double lat_proj_origin = HE5_EHconvAng(eos5_proj_params[5],HE5_HDFE_DMS_DEG);
1051 double fe = eos5_proj_params[6];
1052 double fn = eos5_proj_params[7];
1054 at->append_attr(
"grid_mapping_name",
"String",
"lambert_azimuthal_equal_area");
1056 ostringstream s_lon_proj_origin;
1057 s_lon_proj_origin << lon_proj_origin;
1058 at->append_attr(
"longitude_of_projection_origin",
"Float64", s_lon_proj_origin.str());
1060 ostringstream s_lat_proj_origin;
1061 s_lat_proj_origin << lat_proj_origin;
1063 at->append_attr(
"latitude_of_projection_origin",
"Float64", s_lat_proj_origin.str());
1067 at->append_attr(
"false_easting",
"Float64",
"0.0");
1071 at->append_attr(
"false_easting",
"Float64",s_fe.str());
1076 at->append_attr(
"false_northing",
"Float64",
"0.0");
1080 at->append_attr(
"false_northing",
"Float64",s_fn.str());
1083 at->append_attr(
"_CoordinateAxisTypes",
"string",
"GeoX GeoY");
1094void add_cf_grid_mapping_attr(DAS &das,
const vector<HDF5CF::Var*>& vars,
const string& cf_projection,
1095 const string & dim0name, hsize_t dim0size,
const string &dim1name, hsize_t dim1size)
1099 cerr<<
"dim0name is "<<dim0name <<endl;
1100 cerr<<
"dim1name is "<<dim1name <<endl;
1101 cerr<<
"dim0size is "<<dim0size <<endl;
1102 cerr<<
"dim1size is "<<dim1size <<endl;
1106 vector<HDF5CF::Var *>::const_iterator it_v;
1107 for (it_v = vars.begin(); it_v != vars.end(); ++it_v) {
1109 if ((*it_v)->getRank() > 1) {
1110 bool has_dim0 =
false;
1111 bool has_dim1 =
false;
1112 const vector<HDF5CF::Dimension*>& dims = (*it_v)->getDimensions();
1113 for (vector<HDF5CF::Dimension *>::const_iterator j = dims.begin(); j != dims.end(); ++j) {
1114 if ((*j)->getNewName() == dim0name && (*j)->getSize() == dim0size)
1116 else if ((*j)->getNewName() == dim1name && (*j)->getSize() == dim1size)
1120 if (
true == has_dim0 &&
true == has_dim1) {
1121 AttrTable *at = das.get_table((*it_v)->getNewName());
1122 if (!at) at = das.add_table((*it_v)->getNewName(),
new AttrTable);
1125 at->append_attr(
"grid_mapping",
"String", cf_projection);
1133void add_ll_valid_range(AttrTable* at,
bool is_lat) {
1134 if(
true == is_lat) {
1135 at->append_attr(
"valid_min",
"Float64",
"-90.0");
1136 at->append_attr(
"valid_max",
"Float64",
"90.0");
1139 at->append_attr(
"valid_min",
"Float64",
"-180.0");
1140 at->append_attr(
"valid_max",
"Float64",
"180.0");
1146bool need_attr_values_for_dap4(
const HDF5CF::Var *var) {
1147 bool ret_value =
false;
1148 if((HDF5RequestHandler::get_dmr_64bit_int()!=NULL) &&
1156void map_cfh5_var_attrs_to_dap4_int64(
const HDF5CF::Var *var,BaseType* d4_var) {
1158 vector<HDF5CF::Attribute *>::const_iterator it_ra;
1159 for (it_ra = var->getAttributes().begin();
1160 it_ra != var->getAttributes().end(); ++it_ra) {
1163 size_t mem_dtype_size = ((*it_ra)->getBufSize()) / ((*it_ra)->getCount());
1164 H5DataType mem_dtype = HDF5CFDAPUtil::get_mem_dtype((*it_ra)->getType(), mem_dtype_size);
1166 string dap2_attrtype = HDF5CFDAPUtil::print_type(mem_dtype);
1168 D4Attribute *d4_attr =
new D4Attribute((*it_ra)->getNewName(),dap4_attrtype);
1169 if(dap4_attrtype == attr_str_c) {
1170 if(
"coordinates" == (*it_ra)->getNewName()) {
1171 bool chg_coor_value =
false;
1172 if((
true == HDF5RequestHandler::get_enable_coord_attr_add_path())
1173 &&(
true == var->getCoorAttrAddPath()))
1174 chg_coor_value =
true;
1176 handle_coor_attr_for_int64_var((*it_ra),var->
getFullPath(),tempstring,chg_coor_value);
1177 d4_attr->add_value(tempstring);
1180 const vector<size_t>& strsize = (*it_ra)->getStrSize();
1181 unsigned int temp_start_pos = 0;
1182 for (
unsigned int loc = 0; loc < (*it_ra)->getCount(); loc++) {
1183 if (strsize[loc] != 0) {
1184 string tempstring((*it_ra)->getValue().begin() + temp_start_pos,
1185 (*it_ra)->getValue().begin() + temp_start_pos + strsize[loc]);
1186 temp_start_pos += strsize[loc];
1190 d4_attr->add_value(tempstring);
1197 for (
unsigned int loc = 0; loc < (*it_ra)->getCount(); loc++) {
1198 string print_rep = HDF5CFDAPUtil::print_attr(mem_dtype, loc, (
void*) &((*it_ra)->getValue()[0]));
1199 d4_attr->add_value(print_rep);
1202 d4_var->attributes()->add_attribute_nocopy(d4_attr);
1205 D4Attribute *d4_attr =
new D4Attribute(
"origname",attr_str_c);
1206 d4_attr->add_value(var->
getName());
1207 d4_var->attributes()->add_attribute_nocopy(d4_attr);
1208 d4_attr =
new D4Attribute(
"fullnamepath",attr_str_c);
1210 d4_var->attributes()->add_attribute_nocopy(d4_attr);
1215void check_update_int64_attr(
const string & obj_name,
const HDF5CF::Attribute * attr) {
1216 if(attr->getType() == H5INT64 || attr->getType() == H5UINT64) {
1218 DMR * dmr = HDF5RequestHandler::get_dmr_64bit_int();
1220 string dap2_attrtype = HDF5CFDAPUtil::print_type(attr->getType());
1222 D4Attribute *d4_attr =
new D4Attribute(attr->getNewName(),dap4_attrtype);
1223 for (
unsigned int loc = 0; loc < attr->getCount(); loc++) {
1224 string print_rep = HDF5CFDAPUtil::print_attr(attr->getType(), loc, (
void*) &(attr->getValue()[0]));
1225 d4_attr->add_value(print_rep);
1227 D4Group * root_grp = dmr->root();
1228 D4Attribute *d4_hg_container;
1229 if(root_grp->attributes()->empty() ==
true){
1234 d4_hg_container =
new D4Attribute;
1235 d4_hg_container->set_name(
"HDF5_GLOBAL_integer_64");
1236 d4_hg_container->set_type(attr_container_c);
1237 root_grp->attributes()->add_attribute_nocopy(d4_hg_container);
1243 d4_hg_container = root_grp->attributes()->get(
"HDF5_GLOBAL_integer_64");
1244 if(obj_name !=
"") {
1245 string test_obj_name =
"HDF5_GLOBAL_integer_64."+obj_name;
1250 D4Attribute *d4_container = root_grp->attributes()->get(test_obj_name);
1256 if(d4_container == NULL) {
1257 d4_container =
new D4Attribute;
1258 d4_container->set_name(obj_name);
1259 d4_container->set_type(attr_container_c);
1268 d4_container->attributes()->add_attribute_nocopy(d4_attr);
1273 if(d4_hg_container->attributes()->get(obj_name)==NULL)
1274 d4_hg_container->attributes()->add_attribute_nocopy(d4_container);
1278 d4_hg_container->attributes()->add_attribute_nocopy(d4_attr);
1285void handle_coor_attr_for_int64_var(
const HDF5CF::Attribute *attr,
const string &var_path,
string &tempstring,
bool chg_coor_value) {
1287 string tempstring2(attr->getValue().begin(),attr->getValue().end());
1288 if(
true == chg_coor_value) {
1290 vector<string>cvalue_vec;
1291 HDF5CFUtil::Split_helper(cvalue_vec,tempstring2,sep);
1292 for (
int i = 0; i<cvalue_vec.size();i++) {
1293 HDF5CFUtil::cha_co(cvalue_vec[i],var_path);
1294 string t_str = get_cf_string(cvalue_vec[i]);
1298 tempstring += sep+t_str;
1302 tempstring = tempstring2;
1308void map_cfh5_var_attrs_to_dap4(
const HDF5CF::Var *var,BaseType* d4_var) {
1310 vector<HDF5CF::Attribute *>::const_iterator it_ra;
1311 for (it_ra = var->getAttributes().begin();
1312 it_ra != var->getAttributes().end(); ++it_ra) {
1314 D4Attribute *d4_attr = gen_dap4_attr((*it_ra));
1315 d4_var->attributes()->add_attribute_nocopy(d4_attr);
1320void map_cfh5_grp_attr_to_dap4(libdap::D4Group *d4_grp,
const HDF5CF::Attribute *attr) {
1322 D4Attribute *d4_attr = gen_dap4_attr(attr);
1323 d4_grp->attributes()->add_attribute_nocopy(d4_attr);
1328void map_cfh5_attr_container_to_dap4(libdap::D4Attribute *d4_con,
const HDF5CF::Attribute *attr) {
1330 D4Attribute *d4_attr = gen_dap4_attr(attr);
1331 d4_con->attributes()->add_attribute_nocopy(d4_attr);
1338 D4AttributeType dap4_attrtype = HDF5CFDAPUtil::print_type_dap4(attr->getType());
1339 D4Attribute *d4_attr =
new D4Attribute(attr->getNewName(),dap4_attrtype);
1340 if(dap4_attrtype == attr_str_c) {
1342 const vector<size_t>& strsize = attr->getStrSize();
1344if(strsize.size() == 0)
1345cerr<<
"vector string size is 0"<<endl;
1346for(
int i = 0; i<strsize.size(); i++)
1347cerr<<
"attr size is "<<strsize[i] <<endl;
1349 unsigned int temp_start_pos = 0;
1350 bool is_cset_ascii = attr->getCsetType();
1351 for (
unsigned int loc = 0; loc < attr->getCount(); loc++) {
1352 if (strsize[loc] != 0) {
1353 string tempstring(attr->getValue().begin() + temp_start_pos,
1354 attr->getValue().begin() + temp_start_pos + strsize[loc]);
1355 temp_start_pos += strsize[loc];
1356 if ((attr->getNewName() !=
"origname") && (attr->getNewName() !=
"fullnamepath") && (
true == is_cset_ascii))
1358 d4_attr->add_value(tempstring);
1364 for (
unsigned int loc = 0; loc < attr->getCount(); loc++) {
1365 string print_rep = HDF5CFDAPUtil::print_attr(attr->getType(), loc, (
void*) &(attr->getValue()[0]));
1366 d4_attr->add_value(print_rep);
1374void add_gm_oneproj_var_dap4_attrs(BaseType *var,EOS5GridPCType cv_proj_code,
const vector<double> &eos5_proj_params) {
1376 if (HE5_GCTP_SNSOID == cv_proj_code) {
1378 add_var_dap4_attr(var,
"grid_mapping_name",attr_str_c,
"sinusoidal");
1379 add_var_dap4_attr(var,
"longitude_of_central_meridian",attr_float64_c,
"0.0");
1380 add_var_dap4_attr(var,
"earth_radius", attr_float64_c,
"6371007.181");
1381 add_var_dap4_attr(var,
"_CoordinateAxisTypes", attr_str_c,
"GeoX GeoY");
1384 else if (HE5_GCTP_PS == cv_proj_code) {
1390 double vert_lon_pole = HE5_EHconvAng(eos5_proj_params[4],HE5_HDFE_DMS_DEG);
1393 double lat_true_scale = HE5_EHconvAng(eos5_proj_params[5],HE5_HDFE_DMS_DEG);
1396 double fe = eos5_proj_params[6];
1399 double fn = eos5_proj_params[7];
1401 add_var_dap4_attr(var,
"grid_mapping_name",attr_str_c,
"polar_stereographic");
1403 ostringstream s_vert_lon_pole;
1404 s_vert_lon_pole << vert_lon_pole;
1409 add_var_dap4_attr(var,
"straight_vertical_longitude_from_pole", attr_float64_c, s_vert_lon_pole.str());
1411 ostringstream s_lat_true_scale;
1412 s_lat_true_scale << lat_true_scale;
1413 add_var_dap4_attr(var,
"standard_parallel", attr_float64_c, s_lat_true_scale.str());
1416 add_var_dap4_attr(var,
"false_easting",attr_float64_c,
"0.0");
1420 add_var_dap4_attr(var,
"false_easting",attr_float64_c,s_fe.str());
1424 add_var_dap4_attr(var,
"false_northing",attr_float64_c,
"0.0");
1428 add_var_dap4_attr(var,
"false_northing",attr_float64_c,s_fn.str());
1431 if(lat_true_scale >0)
1432 add_var_dap4_attr(var,
"latitude_of_projection_origin",attr_float64_c,
"+90.0");
1434 add_var_dap4_attr(var,
"latitude_of_projection_origin",attr_float64_c,
"-90.0");
1436 add_var_dap4_attr(var,
"_CoordinateAxisTypes", attr_str_c,
"GeoX GeoY");
1443 else if(HE5_GCTP_LAMAZ == cv_proj_code) {
1445 double lon_proj_origin = HE5_EHconvAng(eos5_proj_params[4],HE5_HDFE_DMS_DEG);
1446 double lat_proj_origin = HE5_EHconvAng(eos5_proj_params[5],HE5_HDFE_DMS_DEG);
1447 double fe = eos5_proj_params[6];
1448 double fn = eos5_proj_params[7];
1450 add_var_dap4_attr(var,
"grid_mapping_name", attr_str_c,
"lambert_azimuthal_equal_area");
1452 ostringstream s_lon_proj_origin;
1453 s_lon_proj_origin << lon_proj_origin;
1454 add_var_dap4_attr(var,
"longitude_of_projection_origin", attr_float64_c, s_lon_proj_origin.str());
1456 ostringstream s_lat_proj_origin;
1457 s_lat_proj_origin << lat_proj_origin;
1459 add_var_dap4_attr(var,
"latitude_of_projection_origin", attr_float64_c, s_lat_proj_origin.str());
1462 add_var_dap4_attr(var,
"false_easting",attr_float64_c,
"0.0");
1466 add_var_dap4_attr(var,
"false_easting",attr_float64_c,s_fe.str());
1470 add_var_dap4_attr(var,
"false_northing",attr_float64_c,
"0.0");
1474 add_var_dap4_attr(var,
"false_northing",attr_float64_c,s_fn.str());
1477 add_var_dap4_attr(var,
"_CoordinateAxisTypes", attr_str_c,
"GeoX GeoY");
1483void add_cf_grid_cv_dap4_attrs(D4Group *d4_root,
const string& cf_projection,
1484 const vector<HDF5CF::Dimension*>& dims)
1487 string dim0name = (dims[0])->getNewName();
1488 hsize_t dim0size = dims[0]->getSize();
1489 string dim1name = (dims[1])->getNewName();
1490 hsize_t dim1size = dims[1]->getSize();
1493 Constructor::Vars_iter vi = d4_root->var_begin();
1494 Constructor::Vars_iter ve = d4_root->var_end();
1495 for (; vi != ve; vi++) {
1496 if((*vi)->is_vector_type()) {
1497 Array *t_a =
dynamic_cast<Array*
>(*vi);
1498 if(t_a->dimensions() >1) {
1499 Array::Dim_iter dim_i = t_a->dim_begin();
1500 Array::Dim_iter dim_e = t_a->dim_end();
1501 bool has_dim0 =
false;
1502 bool has_dim1 =
false;
1503 for(;dim_i !=dim_e;dim_i++) {
1504 if((*dim_i).name == dim0name && (*dim_i).size == dim0size)
1506 else if((*dim_i).name == dim1name && (*dim_i).size == dim1size)
1510 if(
true == has_dim0 &&
true == has_dim1)
1511 add_var_dap4_attr((*vi),
"grid_mapping",attr_str_c,cf_projection);
1520void add_gm_spcvs(libdap::D4Group *d4_root, EOS5GridPCType cv_proj_code,
float cv_point_lower,
float cv_point_upper,
1521 float cv_point_left,
float cv_point_right,
const std::vector<HDF5CF::Dimension*>& dims) {
1525 if (HE5_GCTP_SNSOID == cv_proj_code || HE5_GCTP_LAMAZ == cv_proj_code || HE5_GCTP_PS == cv_proj_code) {
1528 vector<HDF5CF::Dimension*>::const_iterator it_d;
1529 string dim0name = dims[0]->getNewName();
1530 int dim0size = dims[0]->getSize();
1531 string dim1name = dims[1]->getNewName();
1532 int dim1size = dims[1]->getSize();
1535 BaseType *bt_dim0 = NULL;
1536 BaseType *bt_dim1 = NULL;
1547 ar_dim0 =
new HDF5CFGeoCF1D(HE5_GCTP_SNSOID, cv_point_upper, cv_point_lower, dim0size, dim0name, bt_dim0);
1548 ar_dim0->append_dim(dim0size, dim0name);
1550 ar_dim0->set_is_dap4(
true);
1552 add_gm_spcvs_attrs(ar_dim0,
true);
1554 ar_dim1 =
new HDF5CFGeoCF1D(HE5_GCTP_SNSOID, cv_point_left, cv_point_right, dim1size, dim1name, bt_dim1);
1555 ar_dim1->append_dim(dim1size, dim1name);
1557 ar_dim1->set_is_dap4(
true);
1559 add_gm_spcvs_attrs(ar_dim1,
false);
1561 d4_root->add_var(ar_dim0);
1562 d4_root->add_var(ar_dim1);
1566 if (bt_dim0)
delete bt_dim0;
1567 if (bt_dim1)
delete bt_dim1;
1568 if (ar_dim0)
delete ar_dim0;
1569 if (ar_dim1)
delete ar_dim1;
1570 throw InternalErr(__FILE__, __LINE__,
"Unable to allocate the HDFEOS2GeoCF1D instance.");
1573 if (bt_dim0)
delete bt_dim0;
1574 if (bt_dim1)
delete bt_dim1;
1575 if (ar_dim0)
delete ar_dim0;
1576 if (ar_dim1)
delete ar_dim1;
1582void add_gm_spcvs_attrs(libdap::BaseType *var,
const bool is_dim0) {
1584 string standard_name;
1586 string COORAxisTypes;
1588 if (
true == is_dim0) {
1589 standard_name =
"projection_y_coordinate";
1590 long_name =
"y coordinate of projection ";
1591 COORAxisTypes =
"GeoY";
1594 standard_name =
"projection_x_coordinate";
1595 long_name =
"x coordinate of projection ";
1596 COORAxisTypes =
"GeoX";
1599 add_var_dap4_attr(var,
"standard_name", attr_str_c, standard_name);
1600 add_var_dap4_attr(var,
"long_name", attr_str_c, long_name);
1601 add_var_dap4_attr(var,
"units", attr_str_c,
"meter");
1602 add_var_dap4_attr(var,
"_CoordinateAxisType", attr_str_c, COORAxisTypes);
1607void add_grp_dap4_attr(D4Group *d4_grp,
const string& attr_name, D4AttributeType attr_type,
const string& attr_value){
1609 D4Attribute *d4_attr =
new D4Attribute(attr_name,attr_type);
1610 d4_attr->add_value(attr_value);
1611 d4_grp->attributes()->add_attribute_nocopy(d4_attr);
1615void add_var_dap4_attr(BaseType *var,
const string& attr_name, D4AttributeType attr_type,
const string& attr_value){
1617 D4Attribute *d4_attr =
new D4Attribute(attr_name,attr_type);
1618 d4_attr->add_value(attr_value);
1619 var->attributes()->add_attribute_nocopy(d4_attr);
1625string get_cf_string(
string & s) {
1628 return get_cf_string_helper(s);
1632 return get_cf_string_helper(s);
1636string get_cf_string_helper(
string & s) {
1638 if (
"" == s)
return s;
1639 string insertString(1,
'_');
1642 if (
true == isdigit(s[0])) s.insert(0, insertString);
1644 for (
unsigned int i = 0; i < s.length(); i++)
1645 if ((
false == isalnum(s[i])) && (s[i] !=
'_')) s[i] =
'_';
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
This class provides a way to map HDF5 byte to DAP byte for the CF option.
This class provides a way to map HDF5 float to DAP float for the CF option.
This class provides a way to map HDF5 64-bit floating-point(double) to DAP 64-bit floating-point for ...
This class provides a way to map HDF5 int16 to DAP int16 for the CF option.
This class provides a way to map HDF5 32-bit integer to DAP Int32 for the CF option.
This class provides a way to map HDF5 64-bit integer to DAP4 Int64 for the CF option.
This class provides a way to map HDF5 int8 to DAP int16 for the CF option.
This class provides a way to map HDF5 Str to DAP Str for the CF option.
This class provides a way to map HDF5 unsigned 16-bit integer to DAP uint16 for the CF option.
This class provides a way to map HDF5 unsigned 32-bit integer to DAP uint32 for the CF option.
This class provides a way to map HDF5 64-bit unsigned integer to DAP4 UInt64 for the CF option.
This file includes several helper functions for translating HDF5 to CF-compliant.
include the entry functions to execute the handlers
static string escattr(string s)
static D4AttributeType daptype_strrep_to_dap4_attrtype(std::string s)
This class represents one attribute.
This class represents one HDF5 dataset(CF variable)
int getRank() const
Get the dimension rank of this variable.
const std::string & getFullPath() const
Get the full path of this variable.
const std::string & getName() const
Get the original name of this variable.
H5DataType getType() const
Get the data type of this variable(Not HDF5 datatype id)
const std::vector< Dimension * > & getDimensions() const
Get the list of the dimensions.
int getCompRatio() const
Get the compression ratio of this dataset.
const std::string & getNewName() const
Get the new name of this variable.
Helper functions for generating DAS attributes and a function to check BES Key.
Map and generate DDS and DAS for the CF option for generic HDF5 products.