// Purpose: Converts ida3 format xma data to netcdf4 // Usage: xma2netcdf #include #include #include #include #include #include using namespace std; using namespace netCDF; using namespace netCDF::exceptions; int main() { try { cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"< dimMap; multimap::iterator iter; // operations on ncFile dimMap = ncFile.getDims(); if( dimMap.size() != 3) throw NcException("NcException","Error in test 7.1",__FILE__,__LINE__); iter=dimMap.find("dim1"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.2",__FILE__,__LINE__); iter=dimMap.find("dim2"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.3",__FILE__,__LINE__); iter=dimMap.find("dim3"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.4",__FILE__,__LINE__); dimMap = ncFile.getDims(NcGroup::Current); if( dimMap.size() != 3) throw NcException("NcException","Error in test 7.5",__FILE__,__LINE__); iter=dimMap.find("dim1"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.6",__FILE__,__LINE__); iter=dimMap.find("dim2"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.7",__FILE__,__LINE__); iter=dimMap.find("dim3"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.8",__FILE__,__LINE__); dimMap = ncFile.getDims(NcGroup::Parents); if( dimMap.size() != 0) throw NcException("NcException","Error in test 7.9",__FILE__,__LINE__); dimMap = ncFile.getDims(NcGroup::Children); if( dimMap.size() != 4) throw NcException("NcException","Error in test 7.10",__FILE__,__LINE__); dimMap = ncFile.getDims(NcGroup::ParentsAndCurrent); if( dimMap.size() != 3) throw NcException("NcException","Error in test 7.11",__FILE__,__LINE__); iter=dimMap.find("dim1"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.12",__FILE__,__LINE__); iter=dimMap.find("dim2"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.13",__FILE__,__LINE__); iter=dimMap.find("dim3"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.14",__FILE__,__LINE__); dimMap = ncFile.getDims(NcGroup::All); if( dimMap.size() != 7) throw NcException("NcException","Error in test 7.15",__FILE__,__LINE__); iter=dimMap.find("dim1"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.16",__FILE__,__LINE__); iter=dimMap.find("dim2"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.17",__FILE__,__LINE__); iter=dimMap.find("dim3"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.18",__FILE__,__LINE__); iter=dimMap.find("dim4"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.19",__FILE__,__LINE__); iter=dimMap.find("dim5"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.20",__FILE__,__LINE__); iter=dimMap.find("dim6"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.21",__FILE__,__LINE__); iter=dimMap.find("dim7"); if( iter == dimMap.end()) throw NcException("NcException","Error in test 7.22",__FILE__,__LINE__); } cout <<" ----------- passed\n"; cout < dimSet; set::iterator iter; // operations on ncFile:dim2 dimSet = ncFile.getDims("dim2"); if( dimSet.size() != 1) throw NcException("NcException","Error in test 8.1",__FILE__,__LINE__); iter=dimSet.find(dim2); if( iter == dimSet.end()) throw NcException("NcException","Error in test 8.2",__FILE__,__LINE__); if( iter->getName() != "dim2")throw NcException("NcException","Error in test 8.3",__FILE__,__LINE__); dimSet = ncFile.getDims("dim2",NcGroup::Current); if( dimSet.count(dim2) != 1) throw NcException("NcException","Error in test 8.4",__FILE__,__LINE__); dimSet = ncFile.getDims("dim2",NcGroup::Parents); if( dimSet.count(dim2) != 0) throw NcException("NcException","Error in test 8.5",__FILE__,__LINE__); dimSet = ncFile.getDims("dim2",NcGroup::Children); if( dimSet.count(dim2) != 0) throw NcException("NcException","Error in test 8.6",__FILE__,__LINE__); dimSet = ncFile.getDims("dim2",NcGroup::ParentsAndCurrent); if( dimSet.count(dim2) != 1) throw NcException("NcException","Error in test 8.7",__FILE__,__LINE__); dimSet = ncFile.getDims("dim2",NcGroup::ChildrenAndCurrent); if( dimSet.count(dim2) != 1) throw NcException("NcException","Error in test 8.8",__FILE__,__LINE__); dimSet = ncFile.getDims("dim2",NcGroup::All); if( dimSet.count(dim2) != 1) throw NcException("NcException","Error in test 8.9",__FILE__,__LINE__); // operations on ncFile:dim6 dimSet = ncFile.getDims("dim6"); if( dimSet.size() != 0) throw NcException("NcException","Error in test 8.10",__FILE__,__LINE__); dimSet = ncFile.getDims("dim6",NcGroup::Current); if( dimSet.count(dim6) != 0) throw NcException("NcException","Error in test 8.11",__FILE__,__LINE__); dimSet = ncFile.getDims("dim6",NcGroup::Parents); if( dimSet.count(dim6) != 0) throw NcException("NcException","Error in test 8.12",__FILE__,__LINE__); dimSet = ncFile.getDims("dim6",NcGroup::Children); if( dimSet.count(dim6) != 1) throw NcException("NcException","Error in test 8.13",__FILE__,__LINE__); dimSet = ncFile.getDims("dim6",NcGroup::ParentsAndCurrent); if( dimSet.count(dim6) != 0) throw NcException("NcException","Error in test 8.14",__FILE__,__LINE__); dimSet = ncFile.getDims("dim6",NcGroup::ChildrenAndCurrent); if( dimSet.count(dim6) != 1) throw NcException("NcException","Error in test 8.15",__FILE__,__LINE__); dimSet = ncFile.getDims("dim6",NcGroup::All); if( dimSet.count(dim6) != 1) throw NcException("NcException","Error in test 8.16",__FILE__,__LINE__); // operations on groupB:dim1 dimSet = groupB.getDims("dim1"); if( dimSet.size() != 0) throw NcException("NcException","Error in test 8.17",__FILE__,__LINE__); dimSet = groupB.getDims("dim1",NcGroup::Current); if( dimSet.count(dim1) != 0) throw NcException("NcException","Error in test 8.18",__FILE__,__LINE__); dimSet = groupB.getDims("dim1",NcGroup::Parents); if( dimSet.count(dim1) != 1) throw NcException("NcException","Error in test 8.19",__FILE__,__LINE__); dimSet = groupB.getDims("dim1",NcGroup::Children); if( dimSet.count(dim1) != 0) throw NcException("NcException","Error in test 8.20",__FILE__,__LINE__); dimSet = groupB.getDims("dim1",NcGroup::ParentsAndCurrent); if( dimSet.count(dim1) != 1) throw NcException("NcException","Error in test 8.21",__FILE__,__LINE__); dimSet = groupB.getDims("dim1",NcGroup::ChildrenAndCurrent); if( dimSet.count(dim1) != 0) throw NcException("NcException","Error in test 8.22",__FILE__,__LINE__); dimSet = groupB.getDims("dim1",NcGroup::All); if( dimSet.count(dim1) != 1) throw NcException("NcException","Error in test 8.23",__FILE__,__LINE__); // operations on groupA:dim1 dimSet = groupA.getDims("dim1"); if( dimSet.size() != 0) throw NcException("NcException","Error in test 8.24",__FILE__,__LINE__); dimSet = groupA.getDims("dim1",NcGroup::Current); if( dimSet.count(dim1) != 0) throw NcException("NcException","Error in test 8.25",__FILE__,__LINE__); dimSet = groupA.getDims("dim1",NcGroup::Parents); if( dimSet.count(dim1) != 1) throw NcException("NcException","Error in test 8.26",__FILE__,__LINE__); dimSet = groupA.getDims("dim1",NcGroup::Children); if( dimSet.count(dim1) != 0) throw NcException("NcException","Error in test 8.27",__FILE__,__LINE__); dimSet = groupA.getDims("dim1",NcGroup::ParentsAndCurrent); if( dimSet.count(dim1) != 1) throw NcException("NcException","Error in test 8.28",__FILE__,__LINE__); dimSet = groupA.getDims("dim1",NcGroup::ChildrenAndCurrent); if( dimSet.count(dim1) != 0) throw NcException("NcException","Error in test 8.29",__FILE__,__LINE__); dimSet = groupA.getDims("dim1",NcGroup::All); if( dimSet.count(dim1) != 1) throw NcException("NcException","Error in test 8.30",__FILE__,__LINE__); } cout <<" ----------- passed\n"; cout <