FileWriterCDF.hh 5.68 KB
/**
 * FileWriterCDF.hh
 *
 *  Created on: 08 oct. 2014
 *      Author: AKKA
 */

#ifndef FILEWRITERCDF_HH_
#define FILEWRITERCDF_HH_

#include "FileWriter.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"

#include "cdf.h"

#include <map>

namespace AMDA {
namespace ParamOutputImpl {
namespace Download {
namespace FileWriter {

using namespace AMDA::Info;

/**
 * @class FileWriterCDF
 * @brief Implementation of FileWriter for CDF file format.
 * @details
 */
class FileWriterCDF : public FileWriter
{
public:
	/*
	 * structure used to store variable info
	 */
	typedef struct
	{
		long varNum;
		long recNum;
		long type;
		long dim1Size;
		long dim2Size;
	} ParamCDFVar;

	/*
	 * @brief Constructor
	 */
	FileWriterCDF(AMDA::Parameters::ParameterManager& pParameterManager);

	/*
	 * @brief Destructor
	 */
	virtual ~FileWriterCDF(void);

	/*
	 * @overload FileWriter::getExtension - method to get file format extension
	 */
	virtual std::string getExtension(void);

	/*
	 * @overload FileWriter::createNewFile - Create a new CDF file
	 */
	virtual bool createNewFile(std::string filePath);

	/*
	 * @overload FileWriter::closeFile - Close current opened CDF file
	 */
	virtual void closeFile(void);

	/*
	 * @overload FileWriter::addParameter - Add an output parameter in CDF file
	 */
	virtual bool addParameter(ParamProperties* paramProp, AMDA::Common::ParameterIndexComponentList &indexList,
			FileDataType type, bool isFirstParam, int dim1Size = 1, int dim2Size = 1);

	/*
	 * @overload FileWriter::isInfoInSeparateFile - Function use to know if info must be write in a separate file
	 */
	virtual bool isInfoInSeparateFile(bool onlyOneInterval, OutputStructure outputStructure);

	/*
	 * @overload FileWriter::writeError - Write an error message in the CDF file
	 */
	virtual bool writeError(std::string msg);

	/*
	 * @overload FileWriter::writeAMDAInfo - Write an AMDA info bloc for CDF file
	 */
	virtual bool writeAMDAInfo(std::string version, std::string createdby, std::string acknowledgement);

	/*
	 * @overload FileWriter::writeRequestInfo - Write a request info bloc for CDF file
	 */
	virtual bool writeRequestInfo(std::string structure, std::string timeFormat,
			int timeResolution, std::string outputParams, std::string ttPath);

	/*
	 * @overload FileWriter::writeParamsInfo - Write a parameter info bloc for CDF file
	 */
	virtual bool writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
			std::string currentParamId = "");

	/*
	 * @overload FileWriter::writeIntervalInfo - Write an interval info bloc for CDF file
	 */
	virtual bool writeIntervalInfo(std::string startTime, std::string stopTime);

	/*
	 * @overload FileWriter::writeTimeData - Write a time data in the CDF file
	 */
	virtual bool writeTimeData(std::string paramId, double data, OutputFormatTime timeFormat, bool isFirstParam);

	/*
	 * @overload FileWriter::writeFloatData - Write a float data in the CDF file
	 */
	virtual bool writeFloatData(std::string paramId, int varIndex, float data, bool precision);

	/*
	 * @overload FileWriter::writeShortData - Write a short data in the CDF file
	 */
	virtual bool writeShortData(std::string paramId, int varIndex, short data, bool precision);

	/*
	 * @overload FileWriter::writeIntData - Write a int data in the CDF file
	 */
	virtual bool writeIntData(std::string paramId, int varIndex, int data, bool precision);

	/*
	 * @overload FileWriter::writeDoubleData - Write a double data in the CDF file
	 */
	virtual bool writeDoubleData(std::string paramId, int varIndex, double data, bool precision);

	/*
	 * @overload FileWriter::writeLongDoubleData - Write a long double data in the CDF file
	 */
	virtual bool writeLongDoubleData(std::string paramId, int varIndex, long double data, bool precision);

	/*
	 * @overload FileWriter::writeLogicalData - Write a logical data in the CDF file
	 */
	virtual bool writeLogicalData(std::string paramId, int varIndex, AMDA::Parameters::LogicalData data, bool precision);

	/*
	 * @overload FileWriter::goToNextRecord - Prepare CDF writer to write the next record
	 */
	virtual bool goToNextRecord(std::string paramId);

	/*
	 * @overload FileWriter::finalize - Finalize CDF file write.
	 */
	virtual bool finalize(bool isInfoFile = false);

protected:
	/*
	 * @brief Write one data in the CDF file
	 */
	bool writeOneData(std::string paramId, int varIndex, void *data);

	/*
	 * @brief Add a parameter in the CDF file
	 */
	bool addCDFParameter(std::string outputId, AMDA::Common::ParameterIndexComponentList &indexList,
			FileDataType type, int dim1Size, int dim2Size);

	/*
	 * @brief Create a variable in the CDF file
	 */
	bool createCDFVar(const char *name, FileDataType type, long varDim1Size, long varDim2Size,
			ParamCDFVar& cdfVar);

	/*
	 * @brief Add an attribute in the CDF file
	 */
	bool addAttribute(std::string attName, std::string attVal,
			long scope, long varNum = 0);

	/*
	 * @brief Write mission info attributes in the CDF file
	 */
	bool writeMissionInfo(MissionInfoSPtr missionInfo, long varNum);

	/*
	 * @brief Write instrument info attributes in the CDF file
	 */
	bool writeInstrumentInfo(InstrumentInfoSPtr instrumentInfo, long varNum);

	/*
	 * @brief Write dataset info attributes in the CDF file
	 */
	bool writeDatasetInfo(DataSetInfoSPtr datasetInfo, long varNum);

	/*
	 * @brief Write parameter info attributes in the CDF file
	 */
	bool writeParameterInfo(ParamInfoSPtr parameterInfo, long varNum);

private:
	/*
	 * @brief CDF identifier
	 */
	CDFid _cdfid;

	/*
	 * @brief Map of CDF var info
	 */
	std::map<std::string,ParamCDFVar> _cdfVarMap;
};

} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */

#endif /* FILEWRITERCDF_HH_ */