#define MICHLIB_NOSOURCE #include "ncfilew.h" MString NCFileW::CreateFile(NCFileW::Type stype, const MString& name, int compression, size_t nx, size_t ny) { if(stype == UNKNOWN) return "Can't determine file type"; compress = compression; const float node_offset = 0.0; Open(name); if(!*this) return "Can't create netcdf file " + name + ": " + ErrMessage(); AddAtt("node_offset", node_offset); switch(stype) { case(PSET): { AddDim("i", nx); AddVar("x", NC_FLOAT, "i"); AddVar("y", NC_FLOAT, "i"); break; } case(GPSET): { AddDim("i", nx); AddVar("longitude", NC_FLOAT, "i"); AddVar("latitude", NC_FLOAT, "i"); break; } case(RGRID): { AddDim("x", nx); AddDim("y", ny); AddVar("x", NC_FLOAT, "x"); AddVar("y", NC_FLOAT, "y"); break; } case(GRGRID): { AddDim("longitude", nx); AddDim("latitude", ny); AddVar("longitude", NC_FLOAT, "longitude"); AddVar("latitude", NC_FLOAT, "latitude"); break; } case(GRID): { AddDim("x", nx); AddDim("y", ny); AddVar("x", NC_FLOAT, "y", "x"); AddVar("y", NC_FLOAT, "y", "x"); break; } case(GGRID): { AddDim("longitude", nx); AddDim("latitude", ny); AddVar("longitude", NC_FLOAT, "latitude", "longitude"); AddVar("latitude", NC_FLOAT, "latitude", "longitude"); break; } case(UNKNOWN): return "Can't determine file type"; } if(IsGeoType(stype)) { SetComp("longitude", compress); SetComp("latitude", compress); AddAtt("longitude", "standard_name", "longitude"); AddAtt("longitude", "long_name", "Longitude"); AddAtt("latitude", "standard_name", "latitude"); AddAtt("latitude", "long_name", "Latitude"); } else { SetComp("x", compress); SetComp("y", compress); AddAtt("x", "long_name", "x-coordinate"); AddAtt("y", "long_name", "y-coordinate"); } if(!*this) return "Can't set grid in the netcdf file " + name + ": " + ErrMessage(); type = stype; return ""; } MString NCFileW::AddVariable(const MString& name, const MString& stname, const MString& lname, const MString& units, const MString& comment) { if(type == UNKNOWN) return "File not opened"; if(Is1DType(type)) AddVar(name, NC_FLOAT, "i"); else if(IsGeoType(type)) AddVar(name, NC_FLOAT, "latitude", "longitude"); else AddVar(name, NC_FLOAT, "y", "x"); SetComp(name, compress); if(stname.Exist()) AddAtt(name, "standard_name", stname); if(lname.Exist()) AddAtt(name, "long_name", lname); if(units.Exist()) AddAtt(name, "units", units); if(comment.Exist()) AddAtt(name, "comment", comment); AddAtt(name, "_FillValue", fill); if(!*this) return "Can't add variable " + name + ": " + ErrMessage(); return ""; }