1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Purpose: Converts ida3 format xma data to netcdf4
// Usage: xma2netcdf <shot number>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstddef>
#include <netcdf>
#include <stdio.h>
#include <stddef.h>
#include "test_utilities.h"
using namespace std;
using namespace netCDF;
using namespace netCDF::exceptions;
int main()
{
try
{
NcFile ncFile("firstFile.cdf",NcFile::replace);
const int mem3Size(1000);
struct struct3{
double mem3[mem3Size];
};
NcCompoundType compoundType3(ncFile.addCompoundType("compoundType_3",sizeof(struct3)));
vector<int> mem3Shape(1);mem3Shape[0]=mem3Size;
compoundType3.addMember("member3",ncDouble,offsetof(struct3,mem3),mem3Shape);
NcDim timeDim = ncFile.addDim("time");
NcDim pfCoilDim = ncFile.addDim("pfCoil");
vector<NcDim> dimVector(2);
dimVector[1]=timeDim;
dimVector[0]=pfCoilDim;
NcVar var_3 = ncFile.addVar("var_3", compoundType3,dimVector);
// set the fill value
struct3 fillValue;
for(int j=0;j<mem3Size;j++)fillValue.mem3[j]=0;
#if 1
//var_3.setFill(true,&fillValue);
// set the chunking;
vector<size_t> chunksize(2);
chunksize[0]=2;
chunksize[1]=100;
var_3.setChunking(NcVar::nc_CHUNKED,chunksize);
// set the compression
bool enableShuffleFilter(true),enableDeflateFilter(true);
int deflateLevel(1);
var_3.setCompression(enableShuffleFilter,enableDeflateFilter,deflateLevel);
// set checksum
var_3.setChecksum(NcVar::nc_FLETCHER32);
#endif
struct3 dummyStruct;
for(int j=0;j<mem3Size;j++)
dummyStruct.mem3[j]=j*j+1;
for(int j=mem3Size/2;j<mem3Size;j++)
dummyStruct.mem3[j]=0.;
struct3 dummyStruct2;
for(int j=0;j<mem3Size;j++)
dummyStruct2.mem3[j]=-1./(j*j*j+1);
vector<size_t> index(2);
for (int i=0; i< 100;i++) {
index[1]=i;
index[0]=0;
var_3.putVar(index,&dummyStruct);
index[0]=1;
var_3.putVar(index,&dummyStruct2);
}
}
catch (NcException& e)
{
cout << "unknown error"<<endl;
e.what();
return e.errorCode();
}
}
|