31 const char *HDFEOS2::File::_geodim_x_names[] = {
"XDim",
"LonDim",
"nlon"};
34 const char *HDFEOS2::File::_geodim_y_names[] = {
"YDim",
"LatDim",
"nlat"};
37 const char *HDFEOS2::File::_latfield_names[] = {
38 "Latitude",
"Lat",
"YDim",
"LatCenter"
42 const char *HDFEOS2::File::_lonfield_names[] = {
43 "Longitude",
"Lon",
"XDim",
"LonCenter"
48 const char *HDFEOS2::File::_geogrid_names[] = {
"location"};
50 using namespace HDFEOS2;
54 template<
typename T,
typename U,
typename V,
typename W,
typename X>
55 static void _throw5(
const char *fname,
int line,
int numarg,
56 const T &a1,
const U &a2,
const V &a3,
const W &a4,
60 ss << fname <<
":" << line <<
":";
61 for (
int i = 0; i < numarg; ++i) {
64 case 0: ss << a1;
break;
65 case 1: ss << a2;
break;
66 case 2: ss << a3;
break;
67 case 3: ss << a4;
break;
68 case 4: ss << a5;
break;
71 throw Exception(ss.str());
77 #define throw1(a1) _throw5(__FILE__, __LINE__, 1, a1, 0, 0, 0, 0)
78 #define throw2(a1, a2) _throw5(__FILE__, __LINE__, 2, a1, a2, 0, 0, 0)
79 #define throw3(a1, a2, a3) _throw5(__FILE__, __LINE__, 3, a1, a2, a3, 0, 0)
80 #define throw4(a1, a2, a3, a4) _throw5(__FILE__, __LINE__, 4, a1, a2, a3, a4, 0)
81 #define throw5(a1, a2, a3, a4, a5) _throw5(__FILE__, __LINE__, 5, a1, a2, a3, a4, a5)
83 #define assert_throw0(e) do { if (!(e)) throw1("assertion failure"); } while (false)
84 #define assert_range_throw0(e, ge, l) assert_throw0((ge) <= (e) && (e) < (l))
89 template<
typename T>
void operator()(T *ptr)
99 for (vector<GridDataset *>::const_iterator i = grids.begin();
100 i != grids.end(); ++i){
108 for (vector<SwathDataset *>::const_iterator i = swaths.begin();
109 i != swaths.end(); ++i){
116 for (vector<PointDataset *>::const_iterator i = points.begin();
117 i != points.end(); ++i){
124 File * File::Read(
const char *path, int32 mygridfd, int32 myswathfd)
throw(Exception)
127 File *file =
new File(path);
130 file->gridfd = mygridfd;
131 file->swathfd = myswathfd;
135 if ((file->gridfd = GDopen(const_cast<char *>(file->path.c_str()),
136 DFACC_READ)) == -1) {
138 throw2(
"grid open", path);
142 vector<string> gridlist;
143 if (!Utility::ReadNamelist(file->path.c_str(), GDinqgrid, gridlist)) {
145 throw2(
"grid namelist", path);
149 for (vector<string>::const_iterator i = gridlist.begin();
150 i != gridlist.end(); ++i)
151 file->grids.push_back(GridDataset::Read(file->gridfd, *i));
160 if ((file->swathfd = SWopen(const_cast<char *>(file->path.c_str()),
163 throw2(
"swath open", path);
167 vector<string> swathlist;
168 if (!Utility::ReadNamelist(file->path.c_str(), SWinqswath, swathlist)){
170 throw2(
"swath namelist", path);
174 for (vector<string>::const_iterator i = swathlist.begin();
175 i != swathlist.end(); ++i)
176 file->swaths.push_back(SwathDataset::Read(file->swathfd, *i));
187 vector<string> pointlist;
188 if (!Utility::ReadNamelist(file->path.c_str(), PTinqpoint, pointlist)){
190 throw2(
"point namelist", path);
192 for (vector<string>::const_iterator i = pointlist.begin();
193 i != pointlist.end(); ++i)
194 file->points.push_back(PointDataset::Read(-1, *i));
197 if(file->grids.size() == 0 && file->swaths.size() == 0
198 && file->points.size() == 0) {
199 Exception e(
"Not an HDF-EOS2 file");
200 e.setFileType(
false);
211 string File::get_geodim_x_name()
213 if(!_geodim_x_name.empty())
214 return _geodim_x_name;
215 _find_geodim_names();
216 return _geodim_x_name;
222 string File::get_geodim_y_name()
224 if(!_geodim_y_name.empty())
225 return _geodim_y_name;
226 _find_geodim_names();
227 return _geodim_y_name;
237 string File::get_latfield_name()
239 if(!_latfield_name.empty())
240 return _latfield_name;
241 _find_latlonfield_names();
242 return _latfield_name;
245 string File::get_lonfield_name()
247 if(!_lonfield_name.empty())
248 return _lonfield_name;
249 _find_latlonfield_names();
250 return _lonfield_name;
257 string File::get_geogrid_name()
259 if(!_geogrid_name.empty())
260 return _geogrid_name;
261 _find_geogrid_name();
262 return _geogrid_name;
270 void File::_find_geodim_names()
272 set<string> geodim_x_name_set;
273 for(
size_t i = 0; i<
sizeof(_geodim_x_names) /
sizeof(
const char *); i++)
274 geodim_x_name_set.insert(_geodim_x_names[i]);
276 set<string> geodim_y_name_set;
277 for(
size_t i = 0; i<
sizeof(_geodim_y_names) /
sizeof(
const char *); i++)
278 geodim_y_name_set.insert(_geodim_y_names[i]);
280 const size_t gs = grids.size();
281 const size_t ss = swaths.size();
282 for(
size_t i=0; ;i++)
284 Dataset *dataset=
NULL;
286 dataset =
static_cast<Dataset*
>(grids[i]);
288 dataset =
static_cast<Dataset*
>(swaths[i-gs]);
292 const vector<Dimension *>& dims = dataset->getDimensions();
293 for(vector<Dimension*>::const_iterator it = dims.begin();
294 it != dims.end(); ++it)
296 if(geodim_x_name_set.find((*it)->getName()) != geodim_x_name_set.end())
297 _geodim_x_name = (*it)->getName();
298 else if(geodim_y_name_set.find((*it)->getName()) != geodim_y_name_set.end())
299 _geodim_y_name = (*it)->getName();
304 if(_geodim_x_name.empty())
305 _geodim_x_name = _geodim_x_names[0];
306 if(_geodim_y_name.empty())
307 _geodim_y_name = _geodim_y_names[0];
315 void File::_find_latlonfield_names()
317 set<string> latfield_name_set;
318 for(
size_t i = 0; i<
sizeof(_latfield_names) /
sizeof(
const char *); i++)
319 latfield_name_set.insert(_latfield_names[i]);
321 set<string> lonfield_name_set;
322 for(
size_t i = 0; i<
sizeof(_lonfield_names) /
sizeof(
const char *); i++)
323 lonfield_name_set.insert(_lonfield_names[i]);
325 const size_t gs = grids.size();
326 const size_t ss = swaths.size();
327 for(
size_t i=0; ;i++)
329 Dataset *dataset =
NULL;
330 SwathDataset *sw =
NULL;
332 dataset =
static_cast<Dataset*
>(grids[i]);
336 dataset =
static_cast<Dataset*
>(sw);
341 const vector<Field *>& fields = dataset->getDataFields();
342 for(vector<Field*>::const_iterator it = fields.begin();
343 it != fields.end(); ++it)
345 if(latfield_name_set.find((*it)->getName()) != latfield_name_set.end())
346 _latfield_name = (*it)->getName();
347 else if(lonfield_name_set.find((*it)->getName()) != lonfield_name_set.end())
348 _lonfield_name = (*it)->getName();
353 const vector<Field *>& geofields = dataset->getDataFields();
354 for(vector<Field*>::const_iterator it = geofields.begin();
355 it != geofields.end(); ++it)
357 if(latfield_name_set.find((*it)->getName()) != latfield_name_set.end())
358 _latfield_name = (*it)->getName();
359 else if(lonfield_name_set.find((*it)->getName()) != lonfield_name_set.end())
360 _lonfield_name = (*it)->getName();
366 if(_latfield_name.empty())
367 _latfield_name = _latfield_names[0];
368 if(_lonfield_name.empty())
369 _lonfield_name = _lonfield_names[0];
377 void File::_find_geogrid_name()
379 set<string> geogrid_name_set;
380 for(
size_t i = 0; i<
sizeof(_geogrid_names) /
sizeof(
const char *); i++)
381 geogrid_name_set.insert(_geogrid_names[i]);
383 const size_t gs = grids.size();
384 const size_t ss = swaths.size();
385 for(
size_t i=0; ;i++)
389 dataset =
static_cast<Dataset*
>(grids[i]);
391 dataset =
static_cast<Dataset*
>(swaths[i-gs]);
395 if(geogrid_name_set.find(dataset->getName()) != geogrid_name_set.end())
396 _geogrid_name = dataset->getName();
398 if(_geogrid_name.empty())
399 _geogrid_name =
"location";
403 void File::check_onelatlon_grids() {
406 string LATFIELDNAME = this->get_latfield_name();
407 string LONFIELDNAME = this->get_lonfield_name();
410 string GEOGRIDNAME =
"location";
419 for(vector<GridDataset *>::const_iterator i = this->grids.begin();
420 i != this->grids.end(); ++i){
423 for(vector<Field *>::const_iterator j =
424 (*i)->getDataFields().begin();
425 j != (*i)->getDataFields().end(); ++j) {
426 if((*i)->getName()==GEOGRIDNAME){
427 if((*j)->getName()==LATFIELDNAME){
431 if((*j)->getName()==LONFIELDNAME){
439 if(((*j)->getName()==LATFIELDNAME)||((*j)->getName()==LONFIELDNAME)){
440 (*i)->ownllflag =
true;
448 if(morellcount ==0 && onellcount ==2)
449 this->onelatlon =
true;
453 void File::handle_one_grid_zdim(GridDataset* gdset) {
456 string DIMXNAME = this->get_geodim_x_name();
457 string DIMYNAME = this->get_geodim_y_name();
459 bool missingfield_unlim_flag =
false;
460 Field *missingfield_unlim =
NULL;
467 set<string> tempdimlist;
468 pair<set<string>::iterator,
bool> tempdimret;
470 for (vector<Field *>::const_iterator j =
471 gdset->getDataFields().begin();
472 j != gdset->getDataFields().end(); ++j) {
475 if ((*j)->getRank()==1){
479 if(((*j)->getDimensions())[0]->getName()!=DIMXNAME && ((*j)->getDimensions())[0]->getName()!=DIMYNAME){
481 tempdimret = tempdimlist.insert(((*j)->getDimensions())[0]->getName());
486 if(tempdimret.second ==
true) {
493 if((*j)->getName() ==
"Time")
509 for (vector<Dimension *>::const_iterator j =
510 gdset->getDimensions().begin(); j!= gdset->getDimensions().end();++j){
513 if((*j)->getName()!=DIMXNAME && (*j)->getName()!=DIMYNAME){
516 if((tempdimlist.find((*j)->getName())) == tempdimlist.end()){
519 Field *missingfield =
new Field();
520 missingfield->name = (*j)->getName();
521 missingfield->rank = 1;
524 missingfield->type = DFNT_INT32;
527 Dimension *dim =
new Dimension((*j)->getName(),(*j)->getSize());
530 missingfield->dims.push_back(dim);
536 int missingdimsize[1];
537 missingdimsize[0]= (*j)->getSize();
538 if(0 == (*j)->getSize()) {
540 missingfield_unlim_flag =
true;
541 missingfield_unlim = missingfield;
546 missingfield->fieldtype = 4;
554 gdset->datafields.push_back(missingfield);
563 if(
true == missingfield_unlim_flag) {
564 for (vector<Field *>::const_iterator i =
565 gdset->getDataFields().begin();
566 i != gdset->getDataFields().end(); ++i) {
568 for (vector<Dimension *>::const_iterator j =
569 gdset->getDimensions().begin(); j!= gdset->getDimensions().end();++j){
571 if((*j)->getName() == (missingfield_unlim->getDimensions())[0]->getName()) {
572 if((*j)->getSize()!= 0) {
573 Dimension *dim = missingfield_unlim->getDimensions()[0];
574 dim->dimsize = (*j)->getSize();
575 missingfield_unlim_flag =
false;
580 if(
false == missingfield_unlim_flag)
583 if(
false == missingfield_unlim_flag)
591 void File::handle_one_grid_latlon(GridDataset* gdset)
throw(Exception)
595 string DIMXNAME = this->get_geodim_x_name();
596 string DIMYNAME = this->get_geodim_y_name();
598 string LATFIELDNAME = this->get_latfield_name();
599 string LONFIELDNAME = this->get_lonfield_name();
603 if(gdset->ownllflag) {
606 for (vector<Field *>::const_iterator j =
607 gdset->getDataFields().begin();
608 j != gdset->getDataFields().end(); ++j) {
610 if((*j)->getName() == LATFIELDNAME) {
621 if((*j)->getRank() > 2)
622 throw3(
"The rank of latitude is greater than 2",
623 gdset->getName(),(*j)->getName());
625 if((*j)->getRank() != 1) {
629 (*j)->ydimmajor = gdset->getCalculated().isYDimMajor();
635 int32 projectioncode = gdset->getProjection().getCode();
636 if(projectioncode == GCTP_GEO || projectioncode ==GCTP_CEA) {
637 (*j)->condenseddim =
true;
647 if((*j)->condenseddim) {
651 for (vector<Dimension *>::const_iterator k =
652 (*j)->getDimensions().begin(); k!= (*j)->getDimensions().end();++k){
653 if((*k)->getName() == DIMYNAME) {
661 for (vector<Dimension *>::const_iterator k =
662 (*j)->getDimensions().begin(); k!= (*j)->getDimensions().end();++k){
663 if((*k)->getName() == DIMYNAME) {
675 else if ((*j)->getName() == LONFIELDNAME) {
684 if((*j)->getRank() >2)
685 throw3(
"The rank of Longitude is greater than 2",gdset->getName(),(*j)->getName());
687 if((*j)->getRank() != 1) {
690 (*j)->ydimmajor = gdset->getCalculated().isYDimMajor();
695 int32 projectioncode = gdset->getProjection().getCode();
696 if(projectioncode == GCTP_GEO || projectioncode ==GCTP_CEA) {
697 (*j)->condenseddim =
true;
706 if((*j)->condenseddim) {
710 for (vector<Dimension *>::const_iterator k =
711 (*j)->getDimensions().begin(); k!= (*j)->getDimensions().end();++k){
712 if((*k)->getName() == DIMXNAME) {
719 for (vector<Dimension *>::const_iterator k =
720 (*j)->getDimensions().begin(); k!= (*j)->getDimensions().end();++k){
721 if((*k)->getName() == DIMXNAME) {
738 Field *latfield =
new Field();
739 Field *lonfield =
new Field();
741 latfield->name = LATFIELDNAME;
742 lonfield->name = LONFIELDNAME;
749 latfield->type = DFNT_FLOAT64;
750 lonfield->type = DFNT_FLOAT64;
753 latfield->fieldtype = 1;
756 lonfield->fieldtype = 2;
760 latfield->ydimmajor = gdset->getCalculated().isYDimMajor();
761 lonfield->ydimmajor = latfield->ydimmajor;
764 int xdimsize = gdset->getInfo().getX();
765 int ydimsize = gdset->getInfo().getY();
770 bool dmajor=(gdset->getProjection().getCode()==GCTP_LAMAZ)? gdset->getCalculated().DetectFieldMajorDimension()
771 : latfield->ydimmajor;
775 Dimension *dimlaty =
new Dimension(DIMYNAME,ydimsize);
776 latfield->dims.push_back(dimlaty);
777 Dimension *dimlony =
new Dimension(DIMYNAME,ydimsize);
778 lonfield->dims.push_back(dimlony);
779 Dimension *dimlatx =
new Dimension(DIMXNAME,xdimsize);
780 latfield->dims.push_back(dimlatx);
781 Dimension *dimlonx =
new Dimension(DIMXNAME,xdimsize);
782 lonfield->dims.push_back(dimlonx);
785 Dimension *dimlatx =
new Dimension(DIMXNAME,xdimsize);
786 latfield->dims.push_back(dimlatx);
787 Dimension *dimlonx =
new Dimension(DIMXNAME,xdimsize);
788 lonfield->dims.push_back(dimlonx);
789 Dimension *dimlaty =
new Dimension(DIMYNAME,ydimsize);
790 latfield->dims.push_back(dimlaty);
791 Dimension *dimlony =
new Dimension(DIMYNAME,ydimsize);
792 lonfield->dims.push_back(dimlony);
798 upleft =
const_cast<float64 *
>(gdset->getInfo().getUpLeft());
799 lowright =
const_cast<float64 *
>(gdset->getInfo().getLowRight());
802 int32 projectioncode = gdset->getProjection().getCode();
803 if(((
int)lowright[0]>180000000) && ((
int)upleft[0]>-1)) {
806 if(projectioncode == GCTP_GEO)
807 lonfield->speciallon =
true;
818 if(((
int)(lowright[0]/1000)==0) &&((
int)(upleft[0]/1000)==0)
819 && ((
int)(upleft[1]/1000)==0) && ((
int)(lowright[1]/1000)==0)) {
820 if(projectioncode == GCTP_GEO){
821 lonfield->specialformat = 1;
822 latfield->specialformat = 1;
831 if(((
int)(lowright[0])==0) &&((
int)(upleft[0])==0)
832 && ((
int)(upleft[1])==0) && ((
int)(lowright[1])==0)) {
833 if(projectioncode == GCTP_GEO){
834 lonfield->specialformat = 2;
835 latfield->specialformat = 2;
836 gdset->addfvalueattr =
true;
847 if(((
int)(lowright[0])==-1) &&((
int)(upleft[0])==-1)
848 && ((
int)(upleft[1])==-1) && ((
int)(lowright[1])==-1)) {
849 lonfield->specialformat = 3;
850 latfield->specialformat = 3;
851 lonfield->condenseddim =
true;
852 latfield->condenseddim =
true;
857 if(GCTP_SOM == projectioncode) {
858 lonfield->specialformat = 4;
859 latfield->specialformat = 4;
865 if(projectioncode == GCTP_GEO || projectioncode ==GCTP_CEA) {
866 lonfield->condenseddim =
true;
867 latfield->condenseddim =
true;
874 string check_eos_geo_cache_key =
"H4.EnableEOSGeoCacheFile";
875 bool enable_eos_geo_cache_key =
false;
877 if(
true == enable_eos_geo_cache_key) {
909 params =
const_cast<float64 *
>(gdset->getProjection().getParam());
912 for(
int ipar = 0; ipar<13;ipar++)
922 string cache_fpath =
"/tmp/"+cache_fname;
923 int result = stat(cache_fpath.c_str(), &st);
925 int actual_file_size = st.st_size;
926 cerr<<
"HDF-EOS2 actual_file_size is "<<actual_file_size <<endl;
927 int expected_file_size = 0;
928 if(gdset->getProjection().getCode() == GCTP_SOM)
929 expected_file_size = xdimsize*ydimsize*2*
sizeof(
double)*
NBLOCK;
930 else if(gdset->getProjection().getCode() == GCTP_CEA ||
931 gdset->getProjection().getCode() == GCTP_GEO)
932 expected_file_size = (xdimsize+ydimsize)*
sizeof(double);
934 expected_file_size = xdimsize*ydimsize*2*
sizeof(double);
936 cerr<<
"HDF-EOS2 expected_file_size is "<<expected_file_size <<endl;
937 if(actual_file_size != expected_file_size){
938 cerr<<
"field_cache is 1 "<<endl;
939 lonfield->field_cache = 1;
940 latfield->field_cache = 1;
943 cerr<<
"field cache is 2 "<<endl;
944 lonfield->field_cache = 2;
945 latfield->field_cache = 2;
961 gdset->datafields.push_back(latfield);
962 gdset->datafields.push_back(lonfield);
970 if(lonfield->condenseddim) {
974 for (vector<Dimension *>::const_iterator j =
975 lonfield->getDimensions().begin(); j!= lonfield->getDimensions().end();++j){
977 if((*j)->getName() == DIMXNAME) {
981 if((*j)->getName() == DIMYNAME) {
987 for (vector<Dimension *>::const_iterator j =
988 lonfield->getDimensions().begin(); j!= lonfield->getDimensions().end();++j){
990 if((*j)->getName() == DIMXNAME){
994 if((*j)->getName() == DIMYNAME){
1005 void File::handle_onelatlon_grids() throw(Exception) {
1008 string DIMXNAME = this->get_geodim_x_name();
1009 string DIMYNAME = this->get_geodim_y_name();
1010 string LATFIELDNAME = this->get_latfield_name();
1011 string LONFIELDNAME = this->get_lonfield_name();
1015 string GEOGRIDNAME =
"location";
1018 map<string,string>temponelatlondimcvarlist;
1021 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1022 i != this->grids.end(); ++i){
1026 (*i)->setDimxName(DIMXNAME);
1027 (*i)->setDimyName(DIMYNAME);
1030 if((*i)->getName()==GEOGRIDNAME) {
1035 (*i)->lonfield->fieldtype = 2;
1036 (*i)->latfield->fieldtype = 1;
1039 if((*i)->lonfield->rank >2 || (*i)->latfield->rank >2)
1040 throw2(
"Either the rank of lat or the lon is greater than 2",(*i)->getName());
1041 if((*i)->lonfield->rank !=(*i)->latfield->rank)
1042 throw2(
"The rank of the latitude is not the same as the rank of the longitude",(*i)->getName());
1045 if((*i)->lonfield->rank != 1) {
1049 (*i)->lonfield->ydimmajor = (*i)->getCalculated().isYDimMajor();
1050 (*i)->latfield->ydimmajor = (*i)->lonfield->ydimmajor;
1055 int32 projectioncode = (*i)->getProjection().getCode();
1056 if(projectioncode == GCTP_GEO || projectioncode ==GCTP_CEA) {
1057 (*i)->lonfield->condenseddim =
true;
1058 (*i)->latfield->condenseddim =
true;
1065 if((*i)->lonfield->condenseddim) {
1071 for (vector<Dimension *>::const_iterator j =
1072 (*i)->lonfield->getDimensions().begin(); j!= (*i)->lonfield->getDimensions().end();++j){
1073 if((*j)->getName() == DIMXNAME) {
1075 (*i)->lonfield->getName());
1077 if((*j)->getName() == DIMYNAME) {
1079 (*i)->latfield->getName());
1086 for (vector<Dimension *>::const_iterator j =
1087 (*i)->lonfield->getDimensions().begin(); j!= (*i)->lonfield->getDimensions().end();++j){
1088 if((*j)->getName() == DIMXNAME) {
1090 (*i)->lonfield->getName());
1092 if((*j)->getName() == DIMYNAME) {
1094 (*i)->latfield->getName());
1102 (*i)->lonfield->getName());
1104 (*i)->latfield->getName());
1106 temponelatlondimcvarlist = (*i)->dimcvarlist;
1114 for(vector<GridDataset *>::const_iterator i = this->grids.begin();
1115 i != this->grids.end(); ++i){
1117 string templatlonname1;
1118 string templatlonname2;
1120 if((*i)->getName() != GEOGRIDNAME) {
1122 map<string,string>::iterator tempmapit;
1125 tempmapit = temponelatlondimcvarlist.find(DIMXNAME);
1126 if(tempmapit != temponelatlondimcvarlist.end())
1127 templatlonname1= tempmapit->second;
1129 throw2(
"cannot find the dimension field of XDim", (*i)->getName());
1134 tempmapit = temponelatlondimcvarlist.find(DIMYNAME);
1135 if(tempmapit != temponelatlondimcvarlist.end())
1136 templatlonname2= tempmapit->second;
1138 throw2(
"cannot find the dimension field of YDim", (*i)->getName());
1146 void File::handle_grid_dim_cvar_maps() throw(Exception) {
1149 string DIMXNAME = this->get_geodim_x_name();
1151 string DIMYNAME = this->get_geodim_y_name();
1153 string LATFIELDNAME = this->get_latfield_name();
1155 string LONFIELDNAME = this->get_lonfield_name();
1160 string GEOGRIDNAME =
"location";
1174 vector <string> tempfieldnamelist;
1175 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1176 i != this->grids.end(); ++i) {
1177 for (vector<Field *>::const_iterator j = (*i)->getDataFields().begin();
1178 j!= (*i)->getDataFields().end(); ++j) {
1188 map<string,string>tempncvarnamelist;
1189 string tempcorrectedlatname, tempcorrectedlonname;
1191 int total_fcounter = 0;
1193 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1194 i != this->grids.end(); ++i){
1199 for (vector<Field *>::const_iterator j =
1200 (*i)->getDataFields().begin();
1201 j != (*i)->getDataFields().end(); ++j)
1203 (*j)->newname = tempfieldnamelist[total_fcounter];
1207 if((*j)->fieldtype!=0) {
1209 tempncvarnamelist.insert(make_pair((*j)->getName(), (*j)->newname));
1212 if((this->onelatlon)&&(((*i)->getName())==GEOGRIDNAME)) {
1213 if((*j)->getName()==LATFIELDNAME)
1214 tempcorrectedlatname = (*j)->newname;
1215 if((*j)->getName()==LONFIELDNAME)
1216 tempcorrectedlonname = (*j)->newname;
1221 (*i)->ncvarnamelist = tempncvarnamelist;
1222 tempncvarnamelist.clear();
1228 if(this->onelatlon) {
1229 for(vector<GridDataset *>::const_iterator i = this->grids.begin();
1230 i != this->grids.end(); ++i){
1232 if((*i)->getName()!=GEOGRIDNAME){
1240 map<string,string>tempndimnamelist;
1243 vector <string>tempalldimnamelist;
1244 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1245 i != this->grids.end(); ++i)
1246 for (map<string,string>::const_iterator j =
1247 (*i)->dimcvarlist.begin(); j!= (*i)->dimcvarlist.end();++j)
1254 int total_dcounter = 0;
1255 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1256 i != this->grids.end(); ++i){
1258 for (map<string,string>::const_iterator j =
1259 (*i)->dimcvarlist.begin(); j!= (*i)->dimcvarlist.end();++j){
1262 if((DIMXNAME == (*j).first || DIMYNAME == (*j).first) && (
true==(this->onelatlon)))
1269 (*i)->ndimnamelist = tempndimnamelist;
1270 tempndimnamelist.clear();
1275 void File::handle_grid_coards() throw(Exception) {
1278 string DIMXNAME = this->get_geodim_x_name();
1279 string DIMYNAME = this->get_geodim_y_name();
1280 string LATFIELDNAME = this->get_latfield_name();
1281 string LONFIELDNAME = this->get_lonfield_name();
1285 string GEOGRIDNAME =
"location";
1289 vector<Dimension*> correcteddims;
1290 string tempcorrecteddimname;
1293 map<string,string> tempnewxdimnamelist;
1296 map<string,string> tempnewydimnamelist;
1299 Dimension *correcteddim;
1301 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1302 i != this->grids.end(); ++i){
1303 for (vector<Field *>::const_iterator j =
1304 (*i)->getDataFields().begin();
1305 j != (*i)->getDataFields().end(); ++j) {
1310 if((*j)->getName()==LATFIELDNAME && (*j)->getRank()==2 &&(*j)->condenseddim) {
1312 string templatdimname;
1313 map<string,string>::iterator tempmapit;
1316 tempmapit = (*i)->ncvarnamelist.find(LATFIELDNAME);
1317 if(tempmapit != (*i)->ncvarnamelist.end())
1318 templatdimname= tempmapit->second;
1320 throw2(
"cannot find the corrected field of Latitude", (*i)->getName());
1322 for(vector<Dimension *>::const_iterator k =(*j)->getDimensions().begin();
1323 k!=(*j)->getDimensions().end();++k){
1327 if((*k)->getName()==DIMYNAME) {
1328 correcteddim =
new Dimension(templatdimname,(*k)->getSize());
1329 correcteddims.push_back(correcteddim);
1330 (*j)->setCorrectedDimensions(correcteddims);
1334 (*j)->iscoard =
true;
1335 (*i)->iscoard =
true;
1337 this->iscoard =
true;
1340 correcteddims.clear();
1344 else if((*j)->getName()==LONFIELDNAME && (*j)->getRank()==2 &&(*j)->condenseddim){
1346 string templondimname;
1347 map<string,string>::iterator tempmapit;
1350 tempmapit = (*i)->ncvarnamelist.find(LONFIELDNAME);
1351 if(tempmapit != (*i)->ncvarnamelist.end())
1352 templondimname= tempmapit->second;
1354 throw2(
"cannot find the corrected field of Longitude", (*i)->getName());
1356 for(vector<Dimension *>::const_iterator k =(*j)->getDimensions().begin();
1357 k!=(*j)->getDimensions().end();++k){
1361 if((*k)->getName()==DIMXNAME) {
1362 correcteddim =
new Dimension(templondimname,(*k)->getSize());
1363 correcteddims.push_back(correcteddim);
1364 (*j)->setCorrectedDimensions(correcteddims);
1369 (*j)->iscoard =
true;
1370 (*i)->iscoard =
true;
1372 this->iscoard =
true;
1373 correcteddims.clear();
1377 else if(((*j)->getRank()==1) &&((*j)->getName()==LONFIELDNAME) ) {
1379 string templondimname;
1380 map<string,string>::iterator tempmapit;
1383 tempmapit = (*i)->ncvarnamelist.find(LONFIELDNAME);
1384 if(tempmapit != (*i)->ncvarnamelist.end())
1385 templondimname= tempmapit->second;
1387 throw2(
"cannot find the corrected field of Longitude", (*i)->getName());
1389 correcteddim =
new Dimension(templondimname,((*j)->getDimensions())[0]->getSize());
1390 correcteddims.push_back(correcteddim);
1391 (*j)->setCorrectedDimensions(correcteddims);
1392 (*j)->iscoard =
true;
1393 (*i)->iscoard =
true;
1395 this->iscoard =
true;
1396 correcteddims.clear();
1398 if(((((*j)->getDimensions())[0]->getName()!=DIMXNAME))
1399 &&((((*j)->getDimensions())[0]->getName())!=DIMYNAME)){
1400 throw3(
"the dimension name of longitude should not be ",
1401 ((*j)->getDimensions())[0]->getName(),(*i)->getName());
1403 if((((*j)->getDimensions())[0]->getName())==DIMXNAME) {
1412 else if(((*j)->getRank()==1) &&((*j)->getName()==LATFIELDNAME) ) {
1414 string templatdimname;
1415 map<string,string>::iterator tempmapit;
1418 tempmapit = (*i)->ncvarnamelist.find(LATFIELDNAME);
1419 if(tempmapit != (*i)->ncvarnamelist.end())
1420 templatdimname= tempmapit->second;
1422 throw2(
"cannot find the corrected field of Latitude", (*i)->getName());
1424 correcteddim =
new Dimension(templatdimname,((*j)->getDimensions())[0]->getSize());
1425 correcteddims.push_back(correcteddim);
1426 (*j)->setCorrectedDimensions(correcteddims);
1428 (*j)->iscoard =
true;
1429 (*i)->iscoard =
true;
1431 this->iscoard =
true;
1432 correcteddims.clear();
1434 if(((((*j)->getDimensions())[0]->getName())!=DIMXNAME)
1435 &&((((*j)->getDimensions())[0]->getName())!=DIMYNAME))
1436 throw3(
"the dimension name of latitude should not be ",
1437 ((*j)->getDimensions())[0]->getName(),(*i)->getName());
1438 if((((*j)->getDimensions())[0]->getName())==DIMXNAME){
1453 if(
true == this->onelatlon){
1456 if(
true == this->iscoard){
1459 string tempcorrectedxdimname;
1460 string tempcorrectedydimname;
1462 if((
int)(tempnewxdimnamelist.size())!= 1)
1463 throw1(
"the corrected dimension name should have only one pair");
1464 if((
int)(tempnewydimnamelist.size())!= 1)
1465 throw1(
"the corrected dimension name should have only one pair");
1467 map<string,string>::iterator tempdimmapit = tempnewxdimnamelist.begin();
1468 tempcorrectedxdimname = tempdimmapit->second;
1469 tempdimmapit = tempnewydimnamelist.begin();
1470 tempcorrectedydimname = tempdimmapit->second;
1472 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1473 i != this->grids.end(); ++i){
1476 map<string,string>::iterator tempmapit;
1477 tempmapit = (*i)->ndimnamelist.find(DIMXNAME);
1478 if(tempmapit != (*i)->ndimnamelist.end()) {
1482 throw2(
"cannot find the corrected dimension name", (*i)->getName());
1483 tempmapit = (*i)->ndimnamelist.find(DIMYNAME);
1484 if(tempmapit != (*i)->ndimnamelist.end()) {
1488 throw2(
"cannot find the corrected dimension name", (*i)->getName());
1493 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1494 i != this->grids.end(); ++i){
1497 string tempcorrectedxdimname;
1498 string tempcorrectedydimname;
1501 map<string,string>::iterator tempdimmapit;
1502 map<string,string>::iterator tempmapit;
1503 tempdimmapit = tempnewxdimnamelist.find((*i)->getName());
1504 if(tempdimmapit != tempnewxdimnamelist.end())
1505 tempcorrectedxdimname = tempdimmapit->second;
1507 throw2(
"cannot find the corrected COARD XDim dimension name", (*i)->getName());
1508 tempmapit = (*i)->ndimnamelist.find(DIMXNAME);
1509 if(tempmapit != (*i)->ndimnamelist.end()) {
1513 throw2(
"cannot find the corrected dimension name", (*i)->getName());
1515 tempdimmapit = tempnewydimnamelist.find((*i)->getName());
1516 if(tempdimmapit != tempnewydimnamelist.end())
1517 tempcorrectedydimname = tempdimmapit->second;
1519 throw2(
"cannot find the corrected COARD YDim dimension name", (*i)->getName());
1521 tempmapit = (*i)->ndimnamelist.find(DIMYNAME);
1522 if(tempmapit != (*i)->ndimnamelist.end()) {
1526 throw2(
"cannot find the corrected dimension name", (*i)->getName());
1534 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1535 i != this->grids.end(); ++i){
1536 for (map<string,string>::const_iterator j =
1537 (*i)->dimcvarlist.begin(); j!= (*i)->dimcvarlist.end();++j){
1542 if((this->iscoard||(*i)->iscoard) && (*j).first !=DIMXNAME && (*j).first !=DIMYNAME) {
1543 string tempnewdimname;
1544 map<string,string>::iterator tempmapit;
1547 tempmapit = (*i)->ncvarnamelist.find((*j).second);
1548 if(tempmapit != (*i)->ncvarnamelist.end())
1549 tempnewdimname= tempmapit->second;
1551 throw3(
"cannot find the corrected field of ", (*j).second,(*i)->getName());
1554 tempmapit =(*i)->ndimnamelist.find((*j).first);
1555 if(tempmapit != (*i)->ndimnamelist.end())
1558 throw3(
"cannot find the corrected dimension name of ", (*j).first,(*i)->getName());
1565 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1566 i != this->grids.end(); ++i){
1568 for (vector<Field *>::const_iterator j =
1569 (*i)->getDataFields().begin();
1570 j != (*i)->getDataFields().end(); ++j) {
1573 if((*j)->iscoard ==
false) {
1576 for(vector<Dimension *>::const_iterator k=(*j)->getDimensions().begin();k!=(*j)->getDimensions().end();++k){
1579 map<string,string>::iterator tempmapit;
1582 tempmapit = (*i)->ndimnamelist.find((*k)->getName());
1583 if(tempmapit != (*i)->ndimnamelist.end())
1584 tempcorrecteddimname= tempmapit->second;
1586 throw4(
"cannot find the corrected dimension name", (*i)->getName(),(*j)->getName(),(*k)->getName());
1587 correcteddim =
new Dimension(tempcorrecteddimname,(*k)->getSize());
1588 correcteddims.push_back(correcteddim);
1590 (*j)->setCorrectedDimensions(correcteddims);
1591 correcteddims.clear();
1600 void File::update_grid_field_corrected_dims() throw(Exception) {
1603 vector<Dimension*> correcteddims;
1604 string tempcorrecteddimname;
1606 Dimension *correcteddim;
1609 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1610 i != this->grids.end(); ++i){
1612 for (vector<Field *>::const_iterator j =
1613 (*i)->getDataFields().begin();
1614 j != (*i)->getDataFields().end(); ++j) {
1617 if((*j)->iscoard ==
false) {
1620 for(vector<Dimension *>::const_iterator k=(*j)->getDimensions().begin();k!=(*j)->getDimensions().end();++k){
1623 map<string,string>::iterator tempmapit;
1626 tempmapit = (*i)->ndimnamelist.find((*k)->getName());
1627 if(tempmapit != (*i)->ndimnamelist.end())
1628 tempcorrecteddimname= tempmapit->second;
1630 throw4(
"cannot find the corrected dimension name", (*i)->getName(),(*j)->getName(),(*k)->getName());
1631 correcteddim =
new Dimension(tempcorrecteddimname,(*k)->getSize());
1632 correcteddims.push_back(correcteddim);
1634 (*j)->setCorrectedDimensions(correcteddims);
1635 correcteddims.clear();
1642 void File::handle_grid_cf_attrs() throw(Exception) {
1649 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1650 i != this->grids.end(); ++i){
1651 for (vector<Field *>::const_iterator j =
1652 (*i)->getDataFields().begin();
1653 j != (*i)->getDataFields().end(); ++j) {
1656 if((*j)->fieldtype == 0) {
1657 string tempcoordinates=
"";
1658 string tempfieldname=
"";
1659 string tempcorrectedfieldname=
"";
1661 for(vector<Dimension *>::const_iterator k=(*j)->getDimensions().begin();
1662 k!=(*j)->getDimensions().end();++k){
1665 map<string,string>::iterator tempmapit;
1666 map<string,string>::iterator tempmapit2;
1669 tempmapit = ((*i)->dimcvarlist).find((*k)->getName());
1670 if(tempmapit != ((*i)->dimcvarlist).end())
1671 tempfieldname = tempmapit->second;
1673 throw4(
"cannot find the dimension field name",
1674 (*i)->getName(),(*j)->getName(),(*k)->getName());
1677 tempmapit2 = ((*i)->ncvarnamelist).find(tempfieldname);
1678 if(tempmapit2 != ((*i)->ncvarnamelist).end())
1679 tempcorrectedfieldname = tempmapit2->second;
1681 throw4(
"cannot find the corrected dimension field name",
1682 (*i)->getName(),(*j)->getName(),(*k)->getName());
1685 tempcoordinates= tempcorrectedfieldname;
1687 tempcoordinates = tempcoordinates +
" "+tempcorrectedfieldname;
1690 (*j)->setCoordinates(tempcoordinates);
1694 if((*j)->fieldtype == 1) {
1695 string tempunits =
"degrees_north";
1696 (*j)->setUnits(tempunits);
1698 if((*j)->fieldtype == 2) {
1699 string tempunits =
"degrees_east";
1700 (*j)->setUnits(tempunits);
1707 if((*j)->fieldtype == 4) {
1708 string tempunits =
"level";
1709 (*j)->setUnits(tempunits);
1713 if((*j)->fieldtype == 5) {
1714 string tempunits =
"days since 1900-01-01 00:00:00";
1715 (*j)->setUnits(tempunits);
1723 if (
true == (*i)->addfvalueattr) {
1724 if((((*j)->getFillValue()).empty()) && ((*j)->getType()==DFNT_FLOAT32 )) {
1725 float tempfillvalue =
HUGE;
1726 (*j)->addFillValue(tempfillvalue);
1727 (*j)->setAddedFillValue(
true);
1735 void File::handle_grid_SOM_projection() throw(Exception) {
1744 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
1745 i != this->grids.end(); ++i){
1746 if (GCTP_SOM == (*i)->getProjection().getCode()) {
1752 for(vector<Dimension *>::const_iterator j=(*i)->getDimensions().begin();
1753 j!=(*i)->getDimensions().end();++j){
1756 if(
NBLOCK == (*j)->getSize()) {
1760 if ((*j)->getName().compare(0,3,
"SOM") == 0) {
1761 som_dimname = (*j)->getName();
1767 if(
""== som_dimname)
1768 throw4(
"Wrong number of block: The number of block of MISR SOM Grid ",
1769 (*i)->getName(),
" is not ",
NBLOCK);
1771 map<string,string>::iterator tempmapit;
1774 string cor_som_dimname;
1775 tempmapit = (*i)->ndimnamelist.find(som_dimname);
1776 if(tempmapit != (*i)->ndimnamelist.end())
1777 cor_som_dimname = tempmapit->second;
1779 throw2(
"cannot find the corrected dimension name for ", som_dimname);
1782 string cor_som_cvname;
1785 for (vector<Field *>::iterator j = (*i)->datafields.begin();
1786 j != (*i)->datafields.end(); ++j) {
1790 if (1 == (*j)->fieldtype || 2 == (*j)->fieldtype) {
1792 Dimension *newdim =
new Dimension(som_dimname,
NBLOCK);
1793 Dimension *newcor_dim =
new Dimension(cor_som_dimname,
NBLOCK);
1794 vector<Dimension *>::iterator it_d;
1796 it_d = (*j)->dims.begin();
1797 (*j)->dims.insert(it_d,newdim);
1799 it_d = (*j)->correcteddims.begin();
1800 (*j)->correcteddims.insert(it_d,newcor_dim);
1808 if ( 4 == (*j)->fieldtype) {
1809 cor_som_cvname = (*j)->newname;
1811 (*i)->datafields.erase(j);
1828 for (vector<Field *>::const_iterator j = (*i)->getDataFields().begin();
1829 j != (*i)->getDataFields().end(); ++j) {
1831 if ( 0 == (*j)->fieldtype) {
1833 string temp_coordinates = (*j)->coordinates;
1836 found = temp_coordinates.find(cor_som_cvname);
1840 if (temp_coordinates.size() >cor_som_cvname.size())
1841 temp_coordinates.erase(found,cor_som_cvname.size()+1);
1843 temp_coordinates.erase(found,cor_som_cvname.size());
1845 else if (found != string::npos)
1846 temp_coordinates.erase(found-1,cor_som_cvname.size()+1);
1848 throw4(
"cannot find the coordinate variable ",cor_som_cvname,
1849 "from ",temp_coordinates);
1851 (*j)->setCoordinates(temp_coordinates);
1860 int File::obtain_dimmap_num(
int numswath)
throw(Exception) {
1864 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
1865 i != this->swaths.end(); ++i){
1866 tempnumdm += (*i)->get_num_map();
1878 bool fakedimmap =
false;
1882 if((this->swaths[0]->getName()).find(
"atml2")!=string::npos){
1888 for (vector<Field *>::const_iterator j =
1889 this->swaths[0]->getGeoFields().begin();
1890 j != this->swaths[0]->getGeoFields().end(); ++j) {
1891 if((*j)->getName() ==
"Latitude" || (*j)->getName() ==
"Longitude") {
1892 if ((*j)->getType() == DFNT_UINT16 ||
1893 (*j)->getType() == DFNT_INT16)
1894 (*j)->type = DFNT_FLOAT32;
1903 for (vector<Field *>::const_iterator j =
1904 this->swaths[0]->getDataFields().begin();
1905 j != this->swaths[0]->getDataFields().end(); ++j) {
1920 if(((*j)->getName()).find(
"Latitude") != string::npos){
1922 if ((*j)->getType() == DFNT_UINT16 ||
1923 (*j)->getType() == DFNT_INT16)
1924 (*j)->type = DFNT_FLOAT32;
1926 (*j)->fieldtype = 1;
1929 if((*j)->getRank() != 2)
1930 throw2(
"The lat/lon rank must be 2 for Java clients to work",
1933 (((*j)->getDimensions())[0])->getName(),(*j)->getName());
1937 if(((*j)->getName()).find(
"Longitude")!= string::npos) {
1939 if((*j)->getType() == DFNT_UINT16 ||
1940 (*j)->getType() == DFNT_INT16)
1941 (*j)->type = DFNT_FLOAT32;
1943 (*j)->fieldtype = 2;
1944 if((*j)->getRank() != 2)
1945 throw2(
"The lat/lon rank must be 2 for Java clients to work",
1948 (((*j)->getDimensions())[1])->getName(), (*j)->getName());
1960 if(
true == fakedimmap)
1969 void File::create_swath_latlon_dim_cvar_map(
int numdm)
throw(Exception){
1984 bool lat_in_geofields =
false;
1985 bool lon_in_geofields =
false;
1987 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
1988 i != this->swaths.end(); ++i){
1990 int tempgeocount = 0;
1991 for (vector<Field *>::const_iterator j =
1992 (*i)->getGeoFields().begin();
1993 j != (*i)->getGeoFields().end(); ++j) {
1997 if((*j)->getName()==
"Latitude" ){
1998 if((*j)->getRank() > 2)
1999 throw2(
"Currently the lat/lon rank must be 1 or 2 for Java clients to work",
2002 lat_in_geofields =
true;
2016 for(vector<SwathDataset::DimensionMap *>::const_iterator
2017 l=(*i)->getDimensionMaps().begin(); l!=(*i)->getDimensionMaps().end();++l){
2021 if(((*j)->getDimensions()[0])->getName() == (*l)->getGeoDimension()) {
2027 (*j)->fieldtype = 1;
2031 if((*j)->getName()==
"Longitude"){
2032 if((*j)->getRank() > 2)
2033 throw2(
"Currently the lat/lon rank must be 1 or 2 for Java clients to work",
2038 lon_in_geofields =
true;
2039 if((*j)->getRank() == 1) {
2049 (((*j)->getDimensions())[1])->getName(),
"Longitude");
2053 for(vector<SwathDataset::DimensionMap *>::const_iterator
2054 l=(*i)->getDimensionMaps().begin(); l!=(*i)->getDimensionMaps().end();++l){
2059 if(((*j)->getDimensions()[1])->getName() ==
2060 (*l)->getGeoDimension()) {
2062 (*l)->getDataDimension(),
"Longitude");
2067 (*j)->fieldtype = 2;
2070 if(tempgeocount == 2)
2076 if (lat_in_geofields ^ lon_in_geofields)
2077 throw1(
"Latitude and longitude must be both under Geolocation fields or Data fields");
2080 if (!lat_in_geofields && !lon_in_geofields) {
2082 bool lat_in_datafields =
false;
2083 bool lon_in_datafields =
false;
2085 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2086 i != this->swaths.end(); ++i){
2088 int tempgeocount = 0;
2089 for (vector<Field *>::const_iterator j =
2090 (*i)->getDataFields().begin();
2091 j != (*i)->getDataFields().end(); ++j) {
2097 if((*j)->getName()==
"Latitude" ){
2098 if((*j)->getRank() > 2) {
2099 throw2(
"Currently the lat/lon rank must be 1 or 2 for Java clients to work",
2102 lat_in_datafields =
true;
2111 (((*j)->getDimensions())[0])->getName(),
"Latitude");
2117 for(vector<SwathDataset::DimensionMap *>::const_iterator
2118 l=(*i)->getDimensionMaps().begin(); l!=(*i)->getDimensionMaps().end();++l){
2122 if(((*j)->getDimensions()[0])->getName() == (*l)->getGeoDimension()) {
2128 (*j)->fieldtype = 1;
2132 if((*j)->getName()==
"Longitude"){
2134 if((*j)->getRank() > 2) {
2135 throw2(
"Currently the lat/lon rank must be 1 or 2 for Java clients to work",
2141 lon_in_datafields =
true;
2142 if((*j)->getRank() == 1) {
2152 (((*j)->getDimensions())[1])->getName(),
"Longitude");
2155 for(vector<SwathDataset::DimensionMap *>::const_iterator
2156 l=(*i)->getDimensionMaps().begin(); l!=(*i)->getDimensionMaps().end();++l){
2159 if(((*j)->getDimensions()[1])->getName() == (*l)->getGeoDimension()) {
2161 (*l)->getDataDimension(),
"Longitude");
2166 (*j)->fieldtype = 2;
2169 if(tempgeocount == 2)
2175 if (lat_in_datafields ^ lon_in_datafields)
2176 throw1(
"Latitude and longitude must be both under Geolocation fields or Data fields");
2193 void File:: create_swath_nonll_dim_cvar_map() throw(Exception)
2196 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2197 i != this->swaths.end(); ++i){
2214 pair<set<string>::iterator,
bool> tempdimret;
2215 for(map<string,string>::const_iterator j = (*i)->dimcvarlist.begin();
2216 j!= (*i)->dimcvarlist.end();++j){
2217 tempdimret = (*i)->nonmisscvdimlist.insert((*j).first);
2224 for (vector<Field *>::const_iterator j =
2225 (*i)->getGeoFields().begin();
2226 j != (*i)->getGeoFields().end(); ++j) {
2228 if((*j)->getRank()==1) {
2229 if((*i)->nonmisscvdimlist.find((((*j)->getDimensions())[0])->getName()) == (*i)->nonmisscvdimlist.end()){
2230 tempdimret = (*i)->nonmisscvdimlist.insert((((*j)->getDimensions())[0])->getName());
2231 if((*j)->getName() ==
"Time")
2232 (*j)->fieldtype = 5;
2242 if(((((*j)->getDimensions())[0])->getName())==(*j)->getName()){
2243 (*j)->oriname = (*j)->getName();
2246 (*j)->specialcoard =
true;
2250 (*j)->fieldtype = 3;
2260 for (vector<Field *>::const_iterator j =
2261 (*i)->getDataFields().begin();
2262 j != (*i)->getDataFields().end(); ++j) {
2264 if((*j)->getRank()==1) {
2265 if((*i)->nonmisscvdimlist.find((((*j)->getDimensions())[0])->getName()) == (*i)->nonmisscvdimlist.end()){
2266 tempdimret = (*i)->nonmisscvdimlist.insert((((*j)->getDimensions())[0])->getName());
2267 if((*j)->getName() ==
"Time")
2268 (*j)->fieldtype = 5;
2275 if(((((*j)->getDimensions())[0])->getName())==(*j)->getName()){
2276 (*j)->oriname = (*j)->getName();
2278 (*j)->specialcoard =
true;
2282 (*j)->fieldtype = 3;
2292 bool missingfield_unlim_flag =
false;
2293 Field *missingfield_unlim =
NULL;
2295 for (vector<Dimension *>::const_iterator j =
2296 (*i)->getDimensions().begin(); j!= (*i)->getDimensions().end();++j){
2298 if(((*i)->nonmisscvdimlist.find((*j)->getName())) == (*i)->nonmisscvdimlist.end()){
2301 Field *missingfield =
new Field();
2310 missingfield->name = (*j)->getName();
2311 missingfield->rank = 1;
2312 missingfield->type = DFNT_INT32;
2313 Dimension *dim =
new Dimension((*j)->getName(),(*j)->getSize());
2316 missingfield->dims.push_back(dim);
2322 int missingdimsize[1];
2323 missingdimsize[0]= (*j)->getSize();
2325 if(0 == (*j)->getSize()) {
2327 missingfield_unlim_flag =
true;
2328 missingfield_unlim = missingfield;
2332 missingfield->fieldtype = 4;
2334 (*i)->geofields.push_back(missingfield);
2336 (missingfield->getDimensions())[0]->getName(), missingfield->name);
2341 if(
true == missingfield_unlim_flag) {
2342 for (vector<Field *>::const_iterator j =
2343 (*i)->getDataFields().begin();
2344 j != (*i)->getDataFields().end(); ++j) {
2346 for (vector<Dimension *>::const_iterator k =
2347 (*j)->getDimensions().begin(); k!= (*j)->getDimensions().end();++k){
2349 if((*k)->getName() == (missingfield_unlim->getDimensions())[0]->getName()) {
2350 if((*k)->getSize()!= 0) {
2351 Dimension *dim = missingfield_unlim->getDimensions()[0];
2352 dim->dimsize = (*k)->getSize();
2353 missingfield_unlim_flag =
false;
2358 if(
false == missingfield_unlim_flag)
2361 if(
false == missingfield_unlim_flag)
2366 (*i)->nonmisscvdimlist.clear();
2374 void File::handle_swath_dim_cvar_maps(
int tempnumdm)
throw(Exception) {
2377 vector <string> tempfieldnamelist;
2378 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2379 i != this->swaths.end(); ++i) {
2382 for (vector<Field *>::const_iterator j =
2383 (*i)->getGeoFields().begin();
2384 j != (*i)->getGeoFields().end(); ++j) {
2388 for (vector<Field *>::const_iterator j = (*i)->getDataFields().begin();
2389 j!= (*i)->getDataFields().end(); ++j) {
2396 int total_fcounter = 0;
2401 map<string,string>tempncvarnamelist;
2402 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2403 i != this->swaths.end(); ++i){
2406 for (vector<Field *>::const_iterator j =
2407 (*i)->getGeoFields().begin();
2408 j != (*i)->getGeoFields().end(); ++j)
2411 (*j)->newname = tempfieldnamelist[total_fcounter];
2415 if((*j)->fieldtype!=0) {
2420 for (vector<Field *>::const_iterator j =
2421 (*i)->getDataFields().begin();
2422 j != (*i)->getDataFields().end(); ++j)
2424 (*j)->newname = tempfieldnamelist[total_fcounter];
2428 if((*j)->fieldtype!=0) {
2436 vector <string>tempalldimnamelist;
2438 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2439 i != this->swaths.end(); ++i)
2440 for (map<string,string>::const_iterator j =
2441 (*i)->dimcvarlist.begin(); j!= (*i)->dimcvarlist.end();++j)
2447 int total_dcounter = 0;
2449 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2450 i != this->swaths.end(); ++i){
2451 for (map<string,string>::const_iterator j =
2452 (*i)->dimcvarlist.begin(); j!= (*i)->dimcvarlist.end();++j){
2459 vector<Dimension*> correcteddims;
2460 string tempcorrecteddimname;
2461 Dimension *correcteddim;
2463 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2464 i != this->swaths.end(); ++i){
2467 for (vector<Field *>::const_iterator j =
2468 (*i)->getGeoFields().begin();
2469 j != (*i)->getGeoFields().end(); ++j) {
2471 for(vector<Dimension *>::const_iterator k=(*j)->getDimensions().begin();k!=(*j)->getDimensions().end();++k){
2473 map<string,string>::iterator tempmapit;
2475 if(tempnumdm == 0) {
2478 tempmapit = (*i)->ndimnamelist.find((*k)->getName());
2479 if(tempmapit != (*i)->ndimnamelist.end())
2480 tempcorrecteddimname= tempmapit->second;
2482 throw4(
"cannot find the corrected dimension name",
2483 (*i)->getName(),(*j)->getName(),(*k)->getName());
2485 correcteddim =
new Dimension(tempcorrecteddimname,(*k)->getSize());
2489 bool isdimmapname =
false;
2492 for(vector<SwathDataset::DimensionMap *>::const_iterator
2493 l=(*i)->getDimensionMaps().begin(); l!=(*i)->getDimensionMaps().end();++l){
2496 if((*k)->getName() == (*l)->getGeoDimension()) {
2498 isdimmapname =
true;
2500 string temprepdimname = (*l)->getDataDimension();
2503 tempmapit = (*i)->ndimnamelist.find(temprepdimname);
2504 if(tempmapit != (*i)->ndimnamelist.end())
2505 tempcorrecteddimname= tempmapit->second;
2507 throw4(
"cannot find the corrected dimension name", (*i)->getName(),
2508 (*j)->getName(),(*k)->getName());
2512 bool ddimsflag =
false;
2513 for(vector<Dimension *>::const_iterator m=(*i)->getDimensions().begin();
2514 m!=(*i)->getDimensions().end();++m) {
2515 if((*m)->getName() == temprepdimname) {
2517 correcteddim =
new Dimension(tempcorrecteddimname,(*m)->getSize());
2523 throw4(
"cannot find the corrected dimension size", (*i)->getName(),
2524 (*j)->getName(),(*k)->getName());
2528 if(
false == isdimmapname) {
2530 tempmapit = (*i)->ndimnamelist.find((*k)->getName());
2531 if(tempmapit != (*i)->ndimnamelist.end())
2532 tempcorrecteddimname= tempmapit->second;
2534 throw4(
"cannot find the corrected dimension name",
2535 (*i)->getName(),(*j)->getName(),(*k)->getName());
2537 correcteddim =
new Dimension(tempcorrecteddimname,(*k)->getSize());
2542 correcteddims.push_back(correcteddim);
2544 (*j)->setCorrectedDimensions(correcteddims);
2545 correcteddims.clear();
2549 for (vector<Field *>::const_iterator j =
2550 (*i)->getDataFields().begin();
2551 j != (*i)->getDataFields().end(); ++j) {
2553 for(vector<Dimension *>::const_iterator k=
2554 (*j)->getDimensions().begin();k!=(*j)->getDimensions().end();++k){
2556 if(tempnumdm == 0) {
2558 map<string,string>::iterator tempmapit;
2560 tempmapit = (*i)->ndimnamelist.find((*k)->getName());
2561 if(tempmapit != (*i)->ndimnamelist.end())
2562 tempcorrecteddimname= tempmapit->second;
2564 throw4(
"cannot find the corrected dimension name", (*i)->getName(),
2565 (*j)->getName(),(*k)->getName());
2567 correcteddim =
new Dimension(tempcorrecteddimname,(*k)->getSize());
2570 map<string,string>::iterator tempmapit;
2571 bool isdimmapname =
false;
2573 for(vector<SwathDataset::DimensionMap *>::const_iterator l=
2574 (*i)->getDimensionMaps().begin(); l!=(*i)->getDimensionMaps().end();++l){
2577 if((*k)->getName() == (*l)->getGeoDimension()) {
2578 isdimmapname =
true;
2580 string temprepdimname = (*l)->getDataDimension();
2583 tempmapit = (*i)->ndimnamelist.find(temprepdimname);
2584 if(tempmapit != (*i)->ndimnamelist.end())
2585 tempcorrecteddimname= tempmapit->second;
2587 throw4(
"cannot find the corrected dimension name",
2588 (*i)->getName(),(*j)->getName(),(*k)->getName());
2592 bool ddimsflag =
false;
2593 for(vector<Dimension *>::const_iterator m=
2594 (*i)->getDimensions().begin();m!=(*i)->getDimensions().end();++m) {
2597 if((*m)->getName() == temprepdimname) {
2598 correcteddim =
new Dimension(tempcorrecteddimname,(*m)->getSize());
2604 throw4(
"cannot find the corrected dimension size",
2605 (*i)->getName(),(*j)->getName(),(*k)->getName());
2613 tempmapit = (*i)->ndimnamelist.find((*k)->getName());
2614 if(tempmapit != (*i)->ndimnamelist.end())
2615 tempcorrecteddimname= tempmapit->second;
2617 throw4(
"cannot find the corrected dimension name",
2618 (*i)->getName(),(*j)->getName(),(*k)->getName());
2620 correcteddim =
new Dimension(tempcorrecteddimname,(*k)->getSize());
2624 correcteddims.push_back(correcteddim);
2626 (*j)->setCorrectedDimensions(correcteddims);
2627 correcteddims.clear();
2634 void File::handle_swath_cf_attrs() throw(Exception) {
2644 for (vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2645 i != this->swaths.end(); ++i){
2648 for (vector<Field *>::const_iterator j =
2649 (*i)->getGeoFields().begin();
2650 j != (*i)->getGeoFields().end(); ++j) {
2653 if((*j)->fieldtype == 0) {
2654 string tempcoordinates=
"";
2655 string tempfieldname=
"";
2656 string tempcorrectedfieldname=
"";
2658 for(vector<Dimension *>::const_iterator
2659 k=(*j)->getDimensions().begin();k!=(*j)->getDimensions().end();++k){
2662 map<string,string>::iterator tempmapit;
2663 map<string,string>::iterator tempmapit2;
2666 tempmapit = ((*i)->dimcvarlist).find((*k)->getName());
2667 if(tempmapit != ((*i)->dimcvarlist).end())
2668 tempfieldname = tempmapit->second;
2670 throw4(
"cannot find the dimension field name",(*i)->getName(),
2671 (*j)->getName(),(*k)->getName());
2674 tempmapit2 = ((*i)->ncvarnamelist).find(tempfieldname);
2675 if(tempmapit2 != ((*i)->ncvarnamelist).end())
2676 tempcorrectedfieldname = tempmapit2->second;
2678 throw4(
"cannot find the corrected dimension field name",
2679 (*i)->getName(),(*j)->getName(),(*k)->getName());
2682 tempcoordinates= tempcorrectedfieldname;
2684 tempcoordinates = tempcoordinates +
" "+tempcorrectedfieldname;
2687 (*j)->setCoordinates(tempcoordinates);
2692 if((*j)->fieldtype == 1) {
2693 string tempunits =
"degrees_north";
2694 (*j)->setUnits(tempunits);
2698 if((*j)->fieldtype == 2) {
2699 string tempunits =
"degrees_east";
2700 (*j)->setUnits(tempunits);
2707 if((*j)->fieldtype == 4) {
2708 string tempunits =
"level";
2709 (*j)->setUnits(tempunits);
2714 if((*j)->fieldtype == 5) {
2715 string tempunits =
"days since 1900-01-01 00:00:00";
2716 (*j)->setUnits(tempunits);
2722 if((((*j)->getFillValue()).empty()) &&
2723 ((*j)->getType()==DFNT_FLOAT32 || (*j)->getType()==DFNT_FLOAT64)) {
2724 float tempfillvalue = -9999.0;
2725 (*j)->addFillValue(tempfillvalue);
2726 (*j)->setAddedFillValue(
true);
2731 for (vector<Field *>::const_iterator j =
2732 (*i)->getDataFields().begin();
2733 j != (*i)->getDataFields().end(); ++j) {
2736 if((*j)->fieldtype == 0) {
2737 string tempcoordinates=
"";
2738 string tempfieldname=
"";
2739 string tempcorrectedfieldname=
"";
2741 for(vector<Dimension *>::const_iterator k
2742 =(*j)->getDimensions().begin();k!=(*j)->getDimensions().end();++k){
2745 map<string,string>::iterator tempmapit;
2746 map<string,string>::iterator tempmapit2;
2749 tempmapit = ((*i)->dimcvarlist).find((*k)->getName());
2750 if(tempmapit != ((*i)->dimcvarlist).end())
2751 tempfieldname = tempmapit->second;
2753 throw4(
"cannot find the dimension field name",(*i)->getName(),
2754 (*j)->getName(),(*k)->getName());
2757 tempmapit2 = ((*i)->ncvarnamelist).find(tempfieldname);
2758 if(tempmapit2 != ((*i)->ncvarnamelist).end())
2759 tempcorrectedfieldname = tempmapit2->second;
2761 throw4(
"cannot find the corrected dimension field name",
2762 (*i)->getName(),(*j)->getName(),(*k)->getName());
2765 tempcoordinates= tempcorrectedfieldname;
2767 tempcoordinates = tempcoordinates +
" "+tempcorrectedfieldname;
2770 (*j)->setCoordinates(tempcoordinates);
2773 if(((*j)->fieldtype == 3)||((*j)->fieldtype == 4)) {
2774 string tempunits =
"level";
2775 (*j)->setUnits(tempunits);
2780 if((*j)->fieldtype == 5) {
2781 string tempunits =
"days since 1900-01-01 00:00:00";
2782 (*j)->setUnits(tempunits);
2789 if((((*j)->getFillValue()).empty()) &&
2790 ((*j)->getType()==DFNT_FLOAT32 || (*j)->getType()==DFNT_FLOAT64)) {
2791 float tempfillvalue = -9999.0;
2792 (*j)->addFillValue(tempfillvalue);
2793 (*j)->setAddedFillValue(
true);
2802 void File::Prepare(
const char *path)
throw(Exception)
2810 int numgrid = this->grids.size();
2811 int numswath = this->swaths.size();
2814 throw2(
"the number of grid is less than 0", path);
2820 string DIMXNAME = this->get_geodim_x_name();
2822 string DIMYNAME = this->get_geodim_y_name();
2824 string LATFIELDNAME = this->get_latfield_name();
2826 string LONFIELDNAME = this->get_lonfield_name();
2830 string GEOGRIDNAME =
"location";
2835 check_onelatlon_grids();
2838 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
2839 i != this->grids.end(); ++i) {
2840 handle_one_grid_zdim(*i);
2844 if (
true == this->onelatlon)
2845 handle_onelatlon_grids();
2847 for (vector<GridDataset *>::const_iterator i = this->grids.begin();
2848 i != this->grids.end(); ++i) {
2852 (*i)->setDimxName(DIMXNAME);
2853 (*i)->setDimyName(DIMYNAME);
2856 handle_one_grid_latlon(*i);
2861 handle_grid_dim_cvar_maps();
2864 handle_grid_coards();
2867 update_grid_field_corrected_dims();
2870 handle_grid_cf_attrs();
2873 handle_grid_SOM_projection();
2879 for(vector<GridDataset *>::const_iterator i = this->grids.begin();
2880 i != this->grids.end(); ++i){
2881 (*i)->SetScaleType((*i)->name);
2890 int tempnumdm = obtain_dimmap_num(numswath);
2893 create_swath_latlon_dim_cvar_map(tempnumdm);
2896 create_swath_nonll_dim_cvar_map();
2899 handle_swath_dim_cvar_maps(tempnumdm);
2903 handle_swath_cf_attrs();
2906 for(vector<SwathDataset *>::const_iterator i = this->swaths.begin();
2907 i != this->swaths.end(); ++i)
2908 (*i)->SetScaleType((*i)->name);
2916 void correct_unlimited_missing_zdim(GridDataset* gdset)
throw(Exception) {
2918 for (vector<Field *>::const_iterator j =
2919 gdset->getDataFields().begin();
2920 j != gdset->getDataFields().end(); ++j) {
2923 if ((*j)->getRank()==1 && (*j)->){
2933 bool File::check_special_1d_grid() throw(Exception) {
2935 int numgrid = this->grids.size();
2936 int numswath = this->swaths.size();
2939 if (numgrid != 1 || numswath != 0)
2944 string DIMXNAME = this->get_geodim_x_name();
2945 string DIMYNAME = this->get_geodim_y_name();
2947 if(DIMXNAME !=
"XDim" || DIMYNAME !=
"YDim")
2950 int var_dimx_size = 0;
2951 int var_dimy_size = 0;
2953 GridDataset *mygrid = (this->grids)[0];
2955 int field_xydim_flag = 0;
2956 for (vector<Field *>::const_iterator i = mygrid->getDataFields().begin();
2957 i!= mygrid->getDataFields().end(); ++i) {
2959 if((*i)->name ==
"XDim"){
2961 var_dimx_size = ((*i)->getDimensions())[0]->getSize();
2963 if((*i)->name ==
"YDim"){
2965 var_dimy_size = ((*i)->getDimensions())[0]->getSize();
2968 if(2==field_xydim_flag)
2972 if(field_xydim_flag !=2)
2976 int xdimsize = mygrid->getInfo().getX();
2977 int ydimsize = mygrid->getInfo().getY();
2979 if(var_dimx_size != xdimsize || var_dimy_size != ydimsize)
2998 void Dataset::SetScaleType(
const string EOS2ObjName)
throw(Exception) {
3006 vector<string> modis_multi_scale_type;
3007 modis_multi_scale_type.push_back(
"L1B");
3008 modis_multi_scale_type.push_back(
"GEO");
3009 modis_multi_scale_type.push_back(
"BRDF");
3010 modis_multi_scale_type.push_back(
"0.05Deg");
3011 modis_multi_scale_type.push_back(
"Reflectance");
3012 modis_multi_scale_type.push_back(
"MOD17A2");
3013 modis_multi_scale_type.push_back(
"North");
3014 modis_multi_scale_type.push_back(
"South");
3015 modis_multi_scale_type.push_back(
"MOD_Swath_Sea_Ice");
3016 modis_multi_scale_type.push_back(
"MOD_Grid_MOD15A2");
3017 modis_multi_scale_type.push_back(
"MODIS_NACP_LAI");
3019 vector<string> modis_div_scale_type;
3022 modis_div_scale_type.push_back(
"VI");
3023 modis_div_scale_type.push_back(
"1km_2D");
3024 modis_div_scale_type.push_back(
"L2g_2d");
3025 modis_div_scale_type.push_back(
"CMG");
3026 modis_div_scale_type.push_back(
"MODIS SWATH TYPE L2");
3031 string modis_eq_scale_type =
"LST";
3032 string modis_divequ_scale_group =
"MODIS_Grid";
3033 string modis_div_scale_group =
"MOD_Grid";
3037 string modis_equ_scale_group =
"MODIS_Grid_1km_2D";
3039 if(EOS2ObjName==
"mod05" || EOS2ObjName==
"mod06" || EOS2ObjName==
"mod07"
3040 || EOS2ObjName==
"mod08" || EOS2ObjName==
"atml2")
3056 if(EOS2ObjName.find(
"MOD")==0 || EOS2ObjName.find(
"mod")==0)
3058 size_t pos = EOS2ObjName.rfind(modis_eq_scale_type);
3059 if(pos != string::npos &&
3060 (pos== (EOS2ObjName.length()-modis_eq_scale_type.length())))
3066 for(
unsigned int k=0; k<modis_multi_scale_type.size(); k++)
3068 pos = EOS2ObjName.rfind(modis_multi_scale_type[k]);
3069 if (pos !=string::npos &&
3070 (pos== (EOS2ObjName.length()-modis_multi_scale_type[k].length())))
3077 for(
unsigned int k=0; k<modis_div_scale_type.size(); k++)
3079 pos = EOS2ObjName.rfind(modis_div_scale_type[k]);
3080 if (pos != string::npos &&
3081 (pos==(EOS2ObjName.length()-modis_div_scale_type[k].length()))){
3087 if (EOS2ObjName !=
"MODIS_Grid_1km_2D")
3094 pos = EOS2ObjName.find(modis_divequ_scale_group);
3099 size_t eq_scale_pos = EOS2ObjName.find(modis_equ_scale_group);
3100 if (0 == eq_scale_pos)
3106 size_t div_scale_pos = EOS2ObjName.find(modis_div_scale_group);
3109 if ( 0 == div_scale_pos)
3116 if (EOS2ObjName ==
"VIP_CMG_GRID")
3125 for_each(this->dims.begin(), this->dims.end(), delete_elem());
3126 for_each(this->correcteddims.begin(), this->correcteddims.end(), delete_elem());
3132 for_each(this->dims.begin(), this->dims.end(), delete_elem());
3133 for_each(this->datafields.begin(), this->datafields.end(),
3135 for_each(this->attrs.begin(), this->attrs.end(), delete_elem());
3139 void Dataset::ReadDimensions(int32 (*entries)(int32, int32, int32 *),
3140 int32 (*inq)(int32,
char *, int32 *),
3141 vector<Dimension *> &dims)
throw(Exception)
3151 if ((numdims = entries(this->datasetid, HDFE_NENTDIM, &bufsize)) == -1)
3152 throw2(
"dimension entry", this->name);
3156 vector<char> namelist;
3157 vector<int32> dimsize;
3159 namelist.resize(bufsize + 1);
3160 dimsize.resize(numdims);
3163 if (inq(this->datasetid, &namelist[0], &dimsize[0]) == -1)
3164 throw2(
"inquire dimension", this->name);
3166 vector<string> dimnames;
3172 for (vector<string>::const_iterator i = dimnames.begin();
3173 i != dimnames.end(); ++i) {
3174 Dimension *dim =
new Dimension(*i, dimsize[count]);
3175 dims.push_back(dim);
3182 void Dataset::ReadFields(int32 (*entries)(int32, int32, int32 *),
3183 int32 (*inq)(int32,
char *, int32 *, int32 *),
3185 (int32,
char *, int32 *, int32 *, int32 *,
char *),
3187 (int32,
char *, int32 *, int32 *, int32 *, VOIDP),
3188 intn (*getfill)(int32,
char *, VOIDP),
3190 vector<Field *> &fields)
throw(Exception)
3194 int32 numfields = 0;
3201 if ((numfields = entries(this->datasetid, geofield ?
3202 HDFE_NENTGFLD : HDFE_NENTDFLD, &bufsize)) == -1)
3203 throw2(
"field entry", this->name);
3207 if (numfields > 0) {
3208 vector<char> namelist;
3210 namelist.resize(bufsize + 1);
3213 if (inq(this->datasetid, &namelist[0],
NULL,
NULL) == -1)
3214 throw2(
"inquire field", this->name);
3216 vector<string> fieldnames;
3221 for (vector<string>::const_iterator i = fieldnames.begin();
3222 i != fieldnames.end(); ++i) {
3223 Field *field =
new Field();
3232 if ((fldinfo(this->datasetid,
3233 const_cast<char *>(field->name.c_str()),
3234 &field->rank, dimsize, &field->type, dimlist)) == -1){
3236 throw3(
"field info", this->name, field->name);
3239 vector<string> dimnames;
3243 if ((
int)dimnames.size() != field->rank) {
3245 throw4(
"field rank", dimnames.size(), field->rank,
3248 for (
int k = 0; k < field->rank; ++k) {
3249 Dimension *dim =
new Dimension(dimnames[k], dimsize[k]);
3250 field->dims.push_back(dim);
3255 field->filler.resize(DFKNTsize(field->type));
3256 if (getfill(this->datasetid,
3257 const_cast<char *>(field->name.c_str()),
3258 &field->filler[0]) == -1)
3259 field->filler.clear();
3262 fields.push_back(field);
3268 void Dataset::ReadAttributes(int32 (*inq)(int32,
char *, int32 *),
3269 intn (*attrinfo)(int32,
char *, int32 *, int32 *),
3270 intn (*readattr)(int32,
char *, VOIDP),
3271 vector<Attribute *> &attrs)
throw(Exception)
3280 if ((numattrs = inq(this->datasetid,
NULL, &bufsize)) == -1)
3281 throw2(
"inquire attribute", this->name);
3285 vector<char> namelist;
3287 namelist.resize(bufsize + 1);
3290 if (inq(this->datasetid, &namelist[0], &bufsize) == -1)
3291 throw2(
"inquire attribute", this->name);
3293 vector<string> attrnames;
3298 for (vector<string>::const_iterator i = attrnames.begin();
3299 i != attrnames.end(); ++i) {
3300 Attribute *attr =
new Attribute();
3307 if (attrinfo(this->datasetid, const_cast<char *>
3308 (attr->name.c_str()), &attr->type, &count) == -1) {
3310 throw3(
"attribute info", this->name, attr->name);
3313 attr->count = count/DFKNTsize(attr->type);
3314 attr->value.resize(count);
3321 if (readattr(this->datasetid,
3322 const_cast<char *>(attr->name.c_str()),
3323 &attr->value[0]) == -1) {
3325 throw3(
"read attribute", this->name, attr->name);
3329 attrs.push_back(attr);
3335 GridDataset::~GridDataset()
3337 if (this->datasetid != -1){
3338 GDdetach(this->datasetid);
3343 GridDataset * GridDataset::Read(int32 fd,
const string &gridname)
3346 GridDataset *grid =
new GridDataset(gridname);
3349 if ((grid->datasetid = GDattach(fd, const_cast<char *>(gridname.c_str())))
3352 throw2(
"attach grid", gridname);
3358 Info &info = grid->info;
3359 if (GDgridinfo(grid->datasetid, &info.xdim, &info.ydim, info.upleft,
3360 info.lowright) == -1) {
3362 throw2(
"grid info", gridname);
3368 Projection &proj = grid->proj;
3369 if (GDprojinfo(grid->datasetid, &proj.code, &proj.zone, &proj.sphere,
3370 proj.param) == -1) {
3372 throw2(
"projection info", gridname);
3374 if (GDpixreginfo(grid->datasetid, &proj.pix) == -1) {
3376 throw2(
"pixreg info", gridname);
3378 if (GDorigininfo(grid->datasetid, &proj.origin) == -1){
3380 throw2(
"origin info", gridname);
3386 grid->ReadDimensions(GDnentries, GDinqdims, grid->dims);
3389 grid->ReadFields(GDnentries, GDinqfields, GDfieldinfo, GDreadfield,
3390 GDgetfillvalue,
false, grid->datafields);
3393 grid->ReadAttributes(GDinqattrs, GDattrinfo, GDreadattr, grid->attrs);
3403 GridDataset::Calculated & GridDataset::getCalculated()
const
3405 if (this->calculated.grid !=
this)
3406 this->calculated.grid =
this;
3407 return this->calculated;
3410 bool GridDataset::Calculated::isYDimMajor() throw(Exception)
3412 this->DetectMajorDimension();
3413 return this->ydimmajor;
3417 bool GridDataset::Calculated::isOrthogonal() throw(Exception)
3420 this->ReadLongitudeLatitude();
3421 return this->orthogonal;
3425 int GridDataset::Calculated::DetectFieldMajorDimension() throw(Exception)
3430 for (vector<Field *>::const_iterator i =
3431 this->grid->getDataFields().begin();
3432 i != this->grid->getDataFields().end(); ++i) {
3434 int xdimindex = -1, ydimindex = -1, index = 0;
3437 for (vector<Dimension *>::const_iterator j =
3438 (*i)->getDimensions().begin();
3439 j != (*i)->getDimensions().end(); ++j) {
3440 if ((*j)->getName() == this->grid->dimxname)
3442 else if ((*j)->getName() == this->grid->dimyname)
3446 if (xdimindex == -1 || ydimindex == -1)
3449 int major = ydimindex < xdimindex ? 1 : 0;
3460 else if (ym != major)
3461 throw2(
"inconsistent XDim, YDim order", this->grid->getName());
3467 throw2(
"lack of data fields", this->grid->getName());
3472 void GridDataset::Calculated::DetectMajorDimension() throw(Exception)
3480 for (vector<Field *>::const_iterator i =
3481 this->grid->getDataFields().begin();
3482 i != this->grid->getDataFields().end(); ++i) {
3484 int xdimindex = -1, ydimindex = -1, index = 0;
3487 for (vector<Dimension *>::const_iterator j =
3488 (*i)->getDimensions().begin();
3489 j != (*i)->getDimensions().end(); ++j) {
3490 if ((*j)->getName() == this->grid->dimxname)
3492 else if ((*j)->getName() == this->grid->dimyname)
3496 if (xdimindex == -1 || ydimindex == -1)
3501 if(this->grid->getProjection().getCode() == GCTP_LAMAZ)
3504 major = ydimindex < xdimindex ? 1 : 0;
3515 else if (ym != major)
3516 throw2(
"inconsistent XDim, YDim order", this->grid->getName());
3521 throw2(
"lack of data fields", this->grid->getName());
3522 this->ydimmajor = ym != 0;
3531 static bool IsDisjoint(
const vector<Field *> &l,
3532 const vector<Field *> &r)
3534 for (vector<Field *>::const_iterator i = l.begin(); i != l.end(); ++i)
3536 if (find(r.begin(), r.end(), *i) != r.end())
3544 static bool IsDisjoint(vector<pair<Field *, string> > &l,
const vector<Field *> &r)
3546 for (vector<pair<Field *, string> >::const_iterator i =
3547 l.begin(); i != l.end(); ++i) {
3548 if (find(r.begin(), r.end(), i->first) != r.end())
3555 static bool IsSubset(
const vector<Field *> &s,
const vector<Field *> &b)
3557 for (vector<Field *>::const_iterator i = s.begin(); i != s.end(); ++i)
3559 if (find(b.begin(), b.end(), *i) == b.end())
3566 static bool IsSubset(vector<pair<Field *, string> > &s,
const vector<Field *> &b)
3568 for (vector<pair<Field *, string> >::const_iterator i
3569 = s.begin(); i != s.end(); ++i) {
3570 if (find(b.begin(), b.end(), i->first) == b.end())
3578 SwathDataset::~SwathDataset()
3580 if (this->datasetid != -1) {
3581 SWdetach(this->datasetid);
3584 for_each(this->dimmaps.begin(), this->dimmaps.end(), delete_elem());
3585 for_each(this->indexmaps.begin(), this->indexmaps.end(),
3588 for_each(this->geofields.begin(), this->geofields.end(),
3595 SwathDataset * SwathDataset::Read(int32 fd,
const string &swathname)
3598 SwathDataset *swath =
new SwathDataset(swathname);
3601 if ((swath->datasetid = SWattach(fd,
3602 const_cast<char *>(swathname.c_str())))
3605 throw2(
"attach swath", swathname);
3611 swath->ReadDimensions(SWnentries, SWinqdims, swath->dims);
3614 swath->ReadFields(SWnentries, SWinqdatafields, SWfieldinfo, SWreadfield,
3615 SWgetfillvalue,
false, swath->datafields);
3618 swath->ReadFields(SWnentries, SWinqgeofields, SWfieldinfo, SWreadfield,
3619 SWgetfillvalue,
true, swath->geofields);
3622 swath->ReadAttributes(SWinqattrs, SWattrinfo, SWreadattr, swath->attrs);
3625 swath->set_num_map(swath->ReadDimensionMaps(swath->dimmaps));
3628 swath->ReadIndexMaps(swath->indexmaps);
3639 int SwathDataset::ReadDimensionMaps(vector<DimensionMap *> &dimmaps)
3642 int32 nummaps, bufsize;
3645 if ((nummaps = SWnentries(this->datasetid, HDFE_NENTMAP, &bufsize)) == -1)
3646 throw2(
"dimmap entry", this->name);
3657 vector<char> namelist;
3658 vector<int32> offset, increment;
3660 namelist.resize(bufsize + 1);
3661 offset.resize(nummaps);
3662 increment.resize(nummaps);
3663 if (SWinqmaps(this->datasetid, &namelist[0], &offset[0], &increment[0])
3665 throw2(
"inquire dimmap", this->name);
3667 vector<string> mapnames;
3670 for (vector<string>::const_iterator i = mapnames.begin();
3671 i != mapnames.end(); ++i) {
3672 vector<string> parts;
3674 if (parts.size() != 2)
3675 throw3(
"dimmap part", parts.size(),
3678 DimensionMap *dimmap =
new DimensionMap(parts[0], parts[1],
3681 dimmaps.push_back(dimmap);
3689 void SwathDataset::ReadIndexMaps(vector<IndexMap *> &indexmaps)
3692 int32 numindices, bufsize;
3694 if ((numindices = SWnentries(this->datasetid, HDFE_NENTIMAP, &bufsize)) ==
3696 throw2(
"indexmap entry", this->name);
3697 if (numindices > 0) {
3699 vector<char> namelist;
3701 namelist.resize(bufsize + 1);
3702 if (SWinqidxmaps(this->datasetid, &namelist[0],
NULL) == -1)
3703 throw2(
"inquire indexmap", this->name);
3705 vector<string> mapnames;
3707 for (vector<string>::const_iterator i = mapnames.begin();
3708 i != mapnames.end(); ++i) {
3709 IndexMap *indexmap =
new IndexMap();
3710 vector<string> parts;
3712 if (parts.size() != 2)
3713 throw3(
"indexmap part", parts.size(),
3715 indexmap->geo = parts[0];
3716 indexmap->data = parts[1];
3721 SWdiminfo(this->datasetid,
3722 const_cast<char *>(indexmap->geo.c_str())))
3724 throw3(
"dimension info", this->name, indexmap->geo);
3725 indexmap->indices.resize(dimsize);
3726 if (SWidxmapinfo(this->datasetid,
3727 const_cast<char *>(indexmap->geo.c_str()),
3728 const_cast<char *>(indexmap->data.c_str()),
3729 &indexmap->indices[0]) == -1)
3730 throw4(
"indexmap info", this->name, indexmap->geo,
3734 indexmaps.push_back(indexmap);
3740 PointDataset::~PointDataset()
3744 PointDataset * PointDataset::Read(int32 ,
const string &pointname)
3747 PointDataset *point =
new PointDataset(pointname);
3753 bool Utility::ReadNamelist(
const char *path,
3754 int32 (*inq)(
char *,
char *, int32 *),
3755 vector<string> &names)
3757 char *fname =
const_cast<char *
>(path);
3761 if ((numobjs = inq(fname,
NULL, &bufsize)) == -1)
return false;
3763 vector<char> buffer;
3764 buffer.resize(bufsize + 1);
3765 if (inq(fname, &buffer[0], &bufsize) == -1)
return false;
static bool insert_map(std::map< std::string, std::string > &m, std::string key, std::string val)
This is a safer way to insert and update a c++ map value. Otherwise, the local testsuite at The HDF G...
static void Handle_NameClashing(std::vector< std::string > &newobjnamelist)
General routines to handle name clashings.
static std::string get_int_str(int)
static std::string get_double_str(double, int, int)
#define throw1(a1)
The followings are convenient functions to throw exceptions with different.
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
From a string separated by a separator to a list of string, for example, split "ab,c" to {"ab","c"}.
#define throw3(a1, a2, a3)
static std::string get_CF_string(std::string s)
Change special characters to "_".
static bool check_beskeys(const std::string &key)
Check the BES key. This function will check a BES key specified at the file h4.conf.in. If the key's value is either true or yes. The handler claims to find a key and will do some operations. Otherwise, will do different operations. For example, One may find a line H4.EnableCF=true at h4.conf.in. That means, the HDF4 handler will handle the HDF4 files by following CF conventions.
#define throw4(a1, a2, a3, a4)