24 #ifndef CFORMAT_FACTORY
25 #define CFORMAT_FACTORY
51 std::vector<std::string> m_infos;
52 std::string class_name, m_variable, m_type;
53 CParameterNetCDF m_paramFile;
56 const char* m_paramPath;
62 class_name =
"Cformat : factory";
68 m_infos.push_back(
"char_float");
69 m_infos.push_back(
"float_float");
70 m_infos.push_back(
"float_double");
71 m_infos.push_back(
"double_double");
75 Cformat* create(
const int &number)
88 std::cerr<<class_name<<
" : "<<number<<
" refers to an unknown or incompatible format class"<<std::flush;
93 if (m_verbose){printf(
"%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
95 pFormat->m_verbose = m_verbose;
96 pFormat->m_type = m_type;
97 pFormat->m_name = m_variable;
103 Cformat* create(
const std::string &type)
108 if(type==m_infos[0])
return create(0);
109 else if(type==m_infos[1])
return create(1);
110 else if(type==m_infos[2])
return create(2);
111 else if(type==m_infos[3])
return create(3);
114 std::cerr<<class_name<<
" : "<<type<<
" refers to an unknown or incompatible correlation class"<<std::flush;
120 Cformat* create(CParameterNetCDF ¶mFile)
123 m_paramFile = paramFile;
125 paramFile.loadAttribute(
"type",m_type, &m_variable);
127 return create(m_type);
131 Cformat* create(
int argc,
char *argv[])
134 commandLine(argc,argv);
140 if(m_paramPath!=
"true")
143 NcFile file(m_paramPath,NcFile::ReadOnly);
145 if ( error = m_paramFile.setFile(&file) !=1 )
147 std::cerr<<
"Error while loading"<<m_paramPath<<
" parameter file"<<std::endl;
151 pFormat = create(m_paramFile);
153 if (pFormat == NULL){
return NULL;}
161 std::cout<<
" --format option : Command line\n";
162 std::cout<<
" --building!!\n";
174 void commandLine(
int argc,
char *argv[])
178 m_paramPath = cimg_option(
"-p",
"./parameters.nc",
"parameter, mesh or true");
180 m_verbose = cimg_option(
"-v",
false,0);
184 printf(
"Mode Verbose\n");
185 printf(
"%s : %s\n",class_name.c_str(),m_paramPath);
190 void stringSplit(std::string manyString, std::vector<std::string> value)
194 char *split=(
char*)(
" ,;");
196 cstr =
new char [manyString.size()+1];
197 strcpy(cstr,manyString.c_str());
198 ptr=strtok(cstr,split);
201 value.push_back(ptr);
202 ptr=strtok(NULL,split);
211 printf(
"\nclass %s\n",class_name.c_str());
212 for (
int i=0; i<m_infos.size(); i++)
215 printf(
"\t(%i) mode : %s\n",i,m_infos[i].c_str());