FileWriterCDFISTP.cc 2.78 KB
/**
 * FileWriterCDFISTP.cc
 *
 *  Created on: 28 feb. 2022
 *      Author: AKKA
 */

#include "FileWriterCDFISTP.hh"
#include "FileWriterCDF.hh"
#include "TimeUtil.hh"

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

#include <sstream>
#include <cstring>
#include <stdlib.h>
#include <boost/cast.hpp>

#define CDF_TIME_VAR "AMDA_TIME"

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

				using namespace AMDA::Info;

				FileWriterCDFISTP::FileWriterCDFISTP(AMDA::Parameters::ParameterManager& pParameterManager) :
					FileWriterCDF(pParameterManager)
				{
				}

				FileWriterCDFISTP::~FileWriterCDFISTP(void)
				{
					closeFile();
				}

				std::string FileWriterCDFISTP::getExtension(void)
				{
					return "cdf";
				}

				
				bool FileWriterCDFISTP::writeTimeData(std::string /* paramId */, double data, OutputFormatTime /* timeFormat */, bool isFirstParam)
				{
					if (_cdfid == NULL)
						return false;

					if (!isFirstParam)
						return true;
					
					std::stringstream isoTime;
					TimeUtil::formatTimeDateInIso(data, isoTime);

					isoTime << "000000";

					char epString[TT2000_0_STRING_LEN + 1];
					memset(&epString, 0, sizeof(epString));
					if (!isoTime.str().empty())
						strncpy(epString, isoTime.str().c_str(), TT2000_0_STRING_LEN);

					long long epochTime = parseTT2000(epString);

					return writeOneData(CDF_TIME_VAR, 0, &epochTime);
				}

				/*bool FileWriterCDFISTP::writeMissionInfo(MissionInfoSPtr missionInfo, long varNum)
				{
					if (missionInfo == nullptr) {
						std::cout <<  std::endl << std::endl << std::endl <<  "FER - HAHAHAHA" << std::endl << std::endl << std::endl<< std::endl;
						addAttribute("Source_name", "unk>Unknown mission", GLOBAL_SCOPE);
						return false;
					}

					std::vector<std::pair<std::string,std::string>> infoMap = missionInfo->getInfoMap();
					
					for (auto info : infoMap)
						std::cout <<  std::endl << std::endl << std::endl  << "FER - " << &info << std::cout <<  std::endl << std::endl << std::endl << std::endl;
					//for (auto info : infoMap)
					//	if(info.first == "MISSION_NAME")
					//		addAttribute(info.first + ">" + info["MISSION_DESCRIPTION"]);

						//write info about mission

						//        std::vector<std::pair<std::string,std::string>> infoMap = missionInfo->getInfoMap();
						//
						//                for (auto info : infoMap)
						//                                addAttribute(info.first, info.second, VARIABLE_SCOPE, varNum);
						//                                        return true;
						//                                        }
					return true; 
				}*/
			} /* namespace FileWriter */
		} /* namespace Download */
	} /* namespace ParamOutputImpl */
} /* namespace AMDA */