// 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; int main() { try { NcFile ncFile("firstFile.cdf",NcFile::replace); NcGroup groupA(ncFile.addGroup("groupA")); NcGroup groupA0(ncFile.addGroup("groupA0")); NcGroup groupB(groupA.addGroup("groupB")); NcGroup groupC(groupA.addGroup("groupC")); NcDim dim1 = ncFile.addDim("dim1",10); NcDim dim2 = ncFile.addDim("dim2"); NcDim dim3 = ncFile.addDim("dim3",13); NcDim dim4 = groupB.addDim("dim4",14); NcDim dim5 = groupB.addDim("dim5",15); NcDim dim6 = groupB.addDim("dim6",16); NcDim dim7 = groupB.addDim("dim7",17); NcVar var_1 = ncFile.addVar("var_1", ncInt,dim1); NcVar var_2 = ncFile.addVar("var_2", ncInt,dim1); NcVar var_3 = ncFile.addVar("var_3", ncInt,dim1); NcVar var_4 = ncFile.addVar("var_4", ncInt,dim1); NcVar var_5 = ncFile.addVar("var_5", ncInt,dim1); NcVar var_6 = ncFile.addVar("var_6", ncInt,dim1); NcVar var_7 = ncFile.addVar("var_7", ncInt,dim1); NcVar var_8 = ncFile.addVar("var_8", ncInt,dim1); NcVar var_9 = ncFile.addVar("var_9", ncInt,dim1); NcVar varA_1 = groupA.addVar("varA_1", ncByte,dim1); NcVar varA_2 = groupA.addVar("varA_2", ncByte,dim1); NcVar varA0_1 = groupA0.addVar("varA0_1",ncByte,dim1); NcVar varA0_2 = groupA0.addVar("varA0_2",ncByte,dim1); NcVar varA0_3 = groupA0.addVar("varA0_3",ncByte,dim1); NcVar varB_1 = groupB.addVar("varB_1", ncByte,dim1); NcVar varB_2 = groupB.addVar("varB_2", ncByte,dim1); NcVar varB_3 = groupB.addVar("varB_3", ncByte,dim1); NcVar varB_4 = groupB.addVar("varB_4", ncByte,dim1); NcVar varC_1 = groupC.addVar("varC_1", ncByte,dim1); NcVar varC_2 = groupC.addVar("varC_2", ncByte,dim1); NcVar varC_3 = groupC.addVar("varC_3", ncByte,dim1); NcVar varC_4 = groupC.addVar("varC_4", ncByte,dim1); NcVar varC_5 = groupC.addVar("varC_5", ncByte,dim1); vector a1(10),b1(10); vector a2(10),b2(10); vector a3(10),b3(10); vector a4(10),b4(10); vector a5(10),b5(10); vector a6(10),b6(10); vector a7(10),b7(10); vector a8(10),b8(10); vector a9(10),b9(10); initializeVector(a1); initializeVector(a2); initializeVector(a3); initializeVector(a4); initializeVector(a5); initializeVector(a6); initializeVector(a7); initializeVector(a8); initializeVector(a9); for(int i=0; i bb(1); bb[0]=5; var_2.setChunking(NcVar::nc_CHUNKED,bb); var_2.setEndianness(NcVar::nc_ENDIAN_LITTLE); var_2.setCompression(false,true,9); // put variables of different type into the same variable type: requires conversion. var_1.putVar(&a1[0]); var_2.putVar(&a2[0]); var_3.putVar(&a3[0]); var_4.putVar(&a4[0]); var_5.putVar(&a5[0]); var_6.putVar(&a6[0]); var_7.putVar(&a7[0]); var_8.putVar(&a8[0]); var_9.putVar(&a9[0]); // get variable out vector index(1);index[0]=5; vector index2(1);index2[0]=4; var_1.getVar(&b1[0]); // var_2.getVar(&b2[0]); // var_2.getVar(index,&b2[0]); var_2.getVar(index,index2,&b2[0]); for(int i=0; i a1x(10); initializeVector(a1x); NcVarAtt attA7_1 = var_2.putAtt("att7_1",ncUint,size_t(10), &a1x[0]); cout << "varAtt variable name ="<