FileWriterNetCDF.h 1.8 KB
#ifndef FILEWRITERNETCDF_H
#define FILEWRITERNETCDF_H

#include "netcdf.h"

#include "FileWriterAbstract.h"

namespace TREPS
{
	namespace File
	{
		class FileWriterNetCDFClass : public FileWriterAbstractClass
		{
			public :
				FileWriterNetCDFClass(void);

				~FileWriterNetCDFClass(void);

				//create NetCDF file and add general attributes
				bool init(const char *file_path, const map<string,string> *attributes);

				//write fields and data to NetCDF file
				bool writeData(const DataRecordListClass *data, t_TimeFormat timeFormat,
							const char *timePattern, const t_FieldList *fields);

				//save NetCDF file
				bool save(void);

				//close NetCDF file
				bool close(void);

				//test if the file is opened
				bool isOpened(void);

			private :
				//NetCDF identifier
				int ncid;

				//get NetCDF variable definition
				bool getNetCDFVarTypeDef(const t_Field *field, const DataRecordListClass *data, nc_type &ncType, long &numElts);

				//write a dimension in NetCDF file
				bool writeDim(const t_Dimension *dim, int &dimid);

				//write an unlimited dim in NetCDF file
				bool writeUnlimitedDim(t_TimeFormat timeFormat, const char *timePattern, int &unlimitedDimId);

				//write a field in NetCDF file
				bool writeField(const t_Field *field, const DataRecordListClass *data, int unlimitedDimId);

				//write field data in NetCDF file
				bool writeFieldData(const t_Field *field, const DataRecordListClass *data,
							int typeSize, long numElts, int varId);

				//convert data to NetCDF buffer
				bool convertData(const t_Field *field, DataRecordClass *record, const char *key,
							nc_type ncType, long numElts, void *buffer);

				//bool writeData(const t_Field *field, DataRecordClass *record, const char *key, nc_type ncType,
				//		long numElts, int varId, const size_t index[]);
		};
	}
}

#endif