// Purpose: Converts ida3 format xma data to netcdf4 // Usage: xma2netcdf #include #include #include #include #include #include #include #include "test_utilities.h" using namespace std; using namespace netCDF; using namespace netCDF::exceptions; struct struct3{ int mem1; double mem2; short mem3[3]; }; int main() { try { cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"< b1(10); vector b2(10); vector b3(10); vector a1(10); vector a2(10); vector a3(10); vector a4(10); vector a5(10); vector a6(10); vector a7(10); vector a8(10); vector a9(10); initializeVector(a1); initializeVector(a2); initializeVector(a3); initializeVector(a4); initializeVector(a5); initializeVector(a6); initializeVector(a7); initializeVector(a8); initializeVector(a9); cout < vecSize(2); vecSize[0]=6,vecSize[1]=3; NcCompoundType compoundType1(ncFile.addCompoundType("compoundType_1",sizeof(struct1))); NcCompoundType compoundType2(ncFile.addCompoundType("compoundType_2",sizeof(struct2))); cout <<" ----------- passed\n"; cout <NcType && NcType::getTypeClass()"; NcType dummyType(compoundType2); if(compoundType2.getTypeClass() != NcType::nc_COMPOUND) throw NcException("NcException","Error in test 8.1",__FILE__,__LINE__); if(dummyType.getTypeClass() != NcType::nc_COMPOUND) throw NcException("NcException","Error in test 8.2",__FILE__,__LINE__); if(compoundType2.getTypeClass() != NcCompoundType::nc_COMPOUND) throw NcException("NcException","Error in test 8.3",__FILE__,__LINE__); if(dummyType.getTypeClass() != NcCompoundType::nc_COMPOUND) throw NcException("NcException","Error in test 8.4",__FILE__,__LINE__); cout <<" ----------- passed\n"; cout < memberShape; memberShape =compoundType2.getMemberShape(0); if(memberShape.size() != 0)throw NcException("NcException","Error in test 11.1",__FILE__,__LINE__); memberShape =compoundType2.getMemberShape(1); if(memberShape.size() != 0)throw NcException("NcException","Error in test 11.2",__FILE__,__LINE__); memberShape =compoundType2.getMemberShape(2); if(memberShape.size() != 2)throw NcException("NcException","Error in test 11.3",__FILE__,__LINE__); if(memberShape[0] != 6) throw NcException("NcException","Error in test 11.4",__FILE__,__LINE__); if(memberShape[1] != 3) throw NcException("NcException","Error in test 11.5",__FILE__,__LINE__); cout <<" ----------- passed\n"; cout < vecSize(2); vecSize[0]=6,vecSize[1]=3; NcCompoundType compoundType3(ncFile.addCompoundType("compoundType_3",sizeof(struct3))); compoundType3.addMember("member1",ncInt,offsetof(struct3,mem1)); compoundType3.addMember("member2",ncDouble,offsetof(struct3,mem2)); vector mem3Shape(1);mem3Shape[0]=3; compoundType3.addMember("member3",ncShort,offsetof(struct3,mem3),mem3Shape); NcDim dim3 = ncFile.addDim("dim3",2); NcVar var_3 = ncFile.addVar("var_3", compoundType3,dim3); struct3 dummyStruct; dummyStruct.mem1=1; dummyStruct.mem2=-1.23456; dummyStruct.mem3[0]=1; dummyStruct.mem3[1]=-6; dummyStruct.mem3[2]=20; struct3 dummyFill ; dummyFill.mem1=94; dummyFill.mem2=95; dummyFill.mem3[0]=96; dummyFill.mem3[1]=97; dummyFill.mem3[2]=98; struct3 dummyStruct2[2]; dummyStruct2[0].mem1=1; dummyStruct2[0].mem2=-1.23456; dummyStruct2[0].mem3[0]=1; dummyStruct2[0].mem3[1]=-6; dummyStruct2[0].mem3[2]=20; var_3.setFill(true,&dummyFill); vector index(1);index[0]=1; //var_3.putVar(&dummyStruct2); var_3.putVar(index,&dummyStruct); NcVar var_4(ncFile.getVar("var_3")); if(var_4.isNull()) throw NcException("NcException","Error in test 28.1",__FILE__,__LINE__); struct3 dummyStruct3[2]; var_4.getVar(dummyStruct3); if(dummyStruct3[1].mem1 != 1) throw NcException("NcException","Error in test 28.2",__FILE__,__LINE__); if(dummyStruct3[1].mem2 != -1.23456) throw NcException("NcException","Error in test 28.3",__FILE__,__LINE__); if(dummyStruct3[1].mem3[0] != 1) throw NcException("NcException","Error in test 28.4",__FILE__,__LINE__); if(dummyStruct3[1].mem3[1] != -6) throw NcException("NcException","Error in test 28.5",__FILE__,__LINE__); if(dummyStruct3[1].mem3[2] != 20) throw NcException("NcException","Error in test 28.6",__FILE__,__LINE__); if(dummyStruct3[0].mem1 != 94) throw NcException("NcException","Error in test 28.7",__FILE__,__LINE__); if(dummyStruct3[0].mem2 != 95) throw NcException("NcException","Error in test 28.8",__FILE__,__LINE__); if(dummyStruct3[0].mem3[0] != 96) throw NcException("NcException","Error in test 28.9",__FILE__,__LINE__); if(dummyStruct3[0].mem3[1] != 97) throw NcException("NcException","Error in test 28.10",__FILE__,__LINE__); if(dummyStruct3[0].mem3[2] != 98) throw NcException("NcException","Error in test 28.11",__FILE__,__LINE__); } cout <<" ----------- passed\n"; cout < mem1Shape(1);mem1Shape[0]=2; compoundType4.addMember("member1",vlenType13,offsetof(struct10,mem1),mem1Shape); compoundType4.addMember("member2",ncDouble,offsetof(struct10,mem2)); // finally define a variable containing this new compound type NcDim dim13 = ncFile.addDim("dim13",2); NcVar var_13 = ncFile.addVar("var_13", compoundType4,dim13); // here we populate a single entry. struct10 dummyData2; short int* vlenPointer; // vlenPointer = new short int[3]; vlenPointer = (short int*) malloc(3*sizeof(short int)); vlenPointer[0] = 1; vlenPointer[1] = 31; vlenPointer[2] = -20; dummyData2.mem1[0]; dummyData2.mem1[0].p = vlenPointer; dummyData2.mem1[0].len=3; // vlenPointer = new short int[2]; vlenPointer = (short int*) malloc(2*sizeof(short int)); vlenPointer[0] = 73; vlenPointer[1] = 64; dummyData2.mem1[1].p=vlenPointer; dummyData2.mem1[1].len=2; dummyData2.mem2=20.1234; // ...and put the data into the netCDF file vector index(1);index[0]=1; var_13.putVar(index,&dummyData2); nc_free_vlen(&dummyData2.mem1[0]); nc_free_vlen(&dummyData2.mem1[1]); // delete [] dummyData; } cout <<" ----------- passed\n"; } catch (NcException& e) { cout << "unknown error"<