/* * FileReaderNetCDF.hh * * Created on: Feb 08, 2018 * Author: AKKA */ #ifndef FILEREADERNETCDF_HH_ #define FILEREADERNETCDF_HH_ #include "FileReaderAbstract.hh" #include "netcdf.h" #include namespace AMDA { namespace LocalFileInterface { /* * @brief Implementation of the class FileReaderAbstract to load a netCDF file format */ class FileReaderNetCDF : public FileReaderAbstract { public: /* * @brief Constructor */ FileReaderNetCDF(); /* * @brief Destructor */ virtual ~FileReaderNetCDF(); /* * @brief Open a netCDF file */ virtual bool open(std::string filePath); /* * @brief Close the netCDF file */ virtual bool close(void); /* * @brief Test if a netCDF file is currently opened */ virtual bool isOpened(void); /* * @brief Get the id of the time param to use. */ virtual std::string getTimeParamId(void); /* * @brief Get a param type and a param size in the netCDF file */ virtual bool getParamInfo(std::string& paramId, LocalParamType& paramType, int& dim1Size, int& dim2Size); /* * @brief Get the index of the nearest record of time (the higher one) in the netCDF file */ virtual int getRecordIndex(std::string& timeId, double time); /* * @brief Get a param packet from the netCDF file */ virtual FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId, int recordIndex, double stopTime, LocalParamDataPacket *packet); /* * @brief Get an information */ virtual bool getInfo(const char* pInfoName, std::vector& res); private: struct NetCDFDim { int id; char name[NC_MAX_NAME+1]; size_t length; bool isUnlimited; }; struct NetCDFAtt { int id; char name[NC_MAX_NAME+1]; size_t length; nc_type type; }; struct NetCDFVar { int id; char name[NC_MAX_NAME+1]; std::vector dimids; std::vector atts; nc_type type; void* buffer; int valuesize; }; struct NetCDFFile { int id; std::vector dims; std::vector vars; std::vector atts; }; NetCDFFile _file; void resetFile(); bool loadNetCDFFileInfo(); int getNbVarRecords(const NetCDFVar& var); int getNbVarValuesByRecord(const NetCDFVar& var); bool loadData(NetCDFVar& var); std::string getErrorMessage(int status); }; } /* LocalFileInterface */ } /* AMDA */ #endif /* FILEREADERNETCDF_HH_ */