FileLoaderNetCDF.h 2.41 KB
#ifndef FILELOADERNETCDF_H
#define FILELOADERNETCDF_H

#include "FileLoaderAbstract.h"
#include "netcdf.h"

namespace TREPS
{
	namespace File
	{
		//netCDF dimension
		typedef struct
		{
			//dimension id
			int         id;
			//dimension is unlimited?
			bool        isUnlimited;
			//dimension length
			size_t      length;
		} t_NetCDFDim;

		//NetCDF dimension list
		typedef list<t_NetCDFDim> t_NetCDFDimList;

		//NetCDF variable information
		typedef struct
		{
			//variable id
			int             id;
			//variable name
			char            name[NC_MAX_NAME+1];
			//variable type
			nc_type         type;
			//variable type size
			size_t          typeSize;
			//variable value size - always = 1 except for type NC_CHAR = string size
			int             valSize;
			//variable number of value by record
			int             nbValByRecord;
			//variable is a field (ie depends to the unlimited dimension)
			bool            isField;
			//list of variable dimensions
			t_NetCDFDimList dims;
			//sttributes
			map<string,string> attributes;
		} t_NetCDFVar;

		//NetCDF variables list
		typedef list<t_NetCDFVar> t_NetCDFVarList;

		class FileLoaderNetCDFClass : public FileLoaderAbstractClass
		{
			public :
				FileLoaderNetCDFClass(void);
			
				~FileLoaderNetCDFClass(void);

				//open a NetCDF file
				bool open(const char *file_path);

				//close a NetCDF file
				bool close(void);

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

				//get file format
				t_FileFormat getFormat(void);

				//detect frames
				t_StringList getFrames(const t_FieldList *fields);

				//detect fields
				t_FieldList getFields(long int nbRecords);

				//get number of records in netCDF file
				long int getNbRecords(void);

				//add NetCDF specific vectors
				void addSpecificFormatVectors(const t_FieldList *fields, t_VectorList &vectors);

				//get global attributes
				map<string,string> getAttributes(void);
	
				//get data
				bool getData(int start, int limit, DataRecordListClass *data, int &total);

			private :
				//NetCDF identifier
				int ncid;

				//get CDF variables list
				t_NetCDFVarList getVarList(void);

				//get a variable type
				void getFieldType(nc_type type, t_FieldType &fieldType, t_TimeFormat &timeformat);

				//extract data
				string extractValToStr(void *pt, const t_NetCDFVar *var);
		};
	}
}

#endif