#include "quality.h"
string error_file;
static char errorBuffer[CURL_ERROR_SIZE];
static string buffer;
struct FtpFile {
const char *filename;
FILE *stream;
};
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}
int writer(char *data, size_t size, size_t nmemb, string *buffer)
{
int result = 0;
if (buffer != NULL)
{
buffer->append(data, size * nmemb);
result = size * nmemb;
}
return result;
}
string present_data()
{
int year, month;
year=year_time();
month=month_time();
string s;
stringstream out;
out << year;
s = out.str();
stringstream out1;
if (month<10)
{
out1 << '0';
}
out1 << month;
s += out1.str();
return s;
}
string last_data()
{
int year, month;
month=month_time_last();
if (month==12)
{
year=(year_time())-1;
}
else
{
year=year_time();
}
string s;
stringstream out;
out << year;
s = out.str();
stringstream out1;
if (month<10)
{
out1 << '0';
}
out1 << month;
s += out1.str();
return s;
}
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
string short_data_present()
{
int year, month;
year=year_time_short();
month=month_time();
string s;
stringstream out;
out << year;
s = out.str();
stringstream out1;
if (month<10)
{
out1 << 0;
}
out1 << month;
s += out1.str();
return s;
}
string short_data_last()
{
int year, month;
month=month_time_last();
if (month==12)
{
year=(year_time_short())-1;
}
else
{
year=year_time_short();
}
string s;
stringstream out;
out << year;
s = out.str();
stringstream out1;
if (month<10)
{
out1 << '0';
}
out1 << month;
s += out1.str();
return s;
}
void file_wright(string str, string outfile_name)
{
ofstream outfile(outfile_name.c_str());
for(int j=0; j<(str.size()); j++)
outfile.put( str[j] );
outfile.close();
}
void data_file_download(string url_name, string outputfile)
{
CURLcode result;
CURL *curl = curl_easy_init();
error_file+="File'";
if(curl)
{
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_URL, url_name.c_str());
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
result = curl_easy_perform(curl);
if (result == CURLE_OK)
{
FILE *output_to = fopen(outputfile.c_str(), "wb");//outputfile.c_str()
if(output_to && curl)
{
curl_easy_cleanup(curl);
error_file+=url_name+"'download\n0\n";
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url_name.c_str()); // urlname.c_str()
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_to);
curl_easy_perform(curl);
if(curl) curl_easy_cleanup(curl);
if(output_to) fclose(output_to);
}
if(output_to)
{
fclose(output_to);
}
}
else
{
if(curl) curl_easy_cleanup(curl);
error_file+=url_name+"'download\n1\n";
}
}
else
{
if(curl) curl_easy_cleanup(curl);
error_file+=url_name+"'download\n1\n";
}
if(curl) curl_easy_cleanup(curl);
}
void data_file_downloadftp(string url_name, string outputfile)
{
CURLcode result;
struct FtpFile ftpfile={outputfile.c_str(), NULL};
CURL *curl = curl_easy_init();
error_file+="File'";
if(curl) // && output_to
{
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_URL, url_name.c_str()); // urlname.c_str()
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
result = curl_easy_perform(curl);
if (result == CURLE_OK)
{
if(curl)
{
curl_easy_cleanup(curl);
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url_name.c_str()); // urlname.c_str()
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(CURLE_OK != result)
{
error_file+=url_name+"'download\n1\n";;
}
else
{
error_file+=url_name+"'download\n0\n";
}
}
}
else
{
if(curl) curl_easy_cleanup(curl);
error_file+=url_name+"'download\n1\n";
if(ftpfile.stream)
fclose(ftpfile.stream);
curl_global_cleanup();
}
}
else
{
error_file+=url_name+"'download\n1\n";
if(ftpfile.stream)
fclose(ftpfile.stream);
curl_global_cleanup();
}
if(ftpfile.stream)
fclose(ftpfile.stream);
curl_global_cleanup();
}
void FileName_Dir::visitNode(TiXmlNode * root, int level, FileName_Dir str)
{
string temp;
if(root)
{
for (TiXmlNode *node = root->FirstChild(); node; node=node->NextSibling())
{
TiXmlNode* node_Name=node->FirstChild("Name");
if (node_Name)
{
node_Name=node_Name->FirstChild();
TiXmlPrinter printer;
node_Name->Accept(&printer);
temp=printer.CStr();
if (temp == "filenameAceMag\n")
{
TiXmlNode* node_V1=node->FirstChild("Value");
if(node_V1)
{
node_V1=node_V1->FirstChild();
TiXmlPrinter printer1;
node_V1->Accept(&printer1);
File_Name_ACEMAG=str.File_Name_ACEMAG+printer1.CStr();
}
temp="";
str.File_Name_ACEMAG=File_Name_ACEMAG;
}
else if (temp=="filenameAceSwepam\n")
{
TiXmlNode* node_V2=node->FirstChild("Value");
if(node_V2)
{
node_V2=node_V2->FirstChild();
TiXmlPrinter printer2;
node_V2->Accept(&printer2);
File_Name_ACESWEPAM=str.File_Name_ACESWEPAM+printer2.CStr();
}
temp="";
str.File_Name_ACESWEPAM=File_Name_ACESWEPAM;
}
else if (temp=="filenameDst\n")
{
TiXmlNode* node_V3=node->FirstChild("Value");
if(node_V3)
{
node_V3=node_V3->FirstChild();
TiXmlPrinter printer3;
node_V3->Accept(&printer3);
File_Name_DST=str.File_Name_DST+printer3.CStr();
}
temp="";
str.File_Name_DST=File_Name_DST;
}
else if (temp=="filenameKp\n")
{
TiXmlNode* node_V4=node->FirstChild("Value");
if(node_V4)
{
node_V4=node_V4->FirstChild();
TiXmlPrinter printer4;
node_V4->Accept(&printer4);
File_Name_KP=str.File_Name_KP+printer4.CStr();
}
temp="";
str.File_Name_KP=File_Name_KP;
}
else if (temp=="filenameOutfile\n")
{
TiXmlNode* node_V5=node->FirstChild("Value");
if(node_V5)
{
node_V5=node_V5->FirstChild();
TiXmlPrinter printer5;
node_V5->Accept(&printer5);
File_Name_OUTPUT=str.File_Name_OUTPUT+printer5.CStr();
}
temp="";
str.File_Name_OUTPUT=File_Name_OUTPUT;
}
else{}
}
TiXmlNode* node_Dir=node->FirstChild("Input");
if(node_Dir)
{
TiXmlNode* node_D=node_Dir->FirstChild("File_Name");
if (node_D)
{
node_D=node_D->FirstChild();
TiXmlPrinter printer;
node_D->Accept(&printer);
File_Dir_INPUT=str.File_Dir_INPUT+printer.CStr();
}
str.File_Dir_INPUT=File_Dir_INPUT;
}
TiXmlNode* node_Dir1=node->FirstChild("Output");
if(node_Dir1)
{
TiXmlNode* node_D1=node_Dir1->FirstChild("File_Name");
if (node_D1)
{
node_D1=node_D1->FirstChild();
TiXmlPrinter printer;
node_D1->Accept(&printer);
File_Dir_OUTPUT=str.File_Dir_OUTPUT+printer.CStr();
}
str.File_Dir_OUTPUT=File_Dir_OUTPUT;
}
str.File_Name_ACEMAG=File_Name_ACEMAG;
str.File_Name_ACESWEPAM=File_Name_ACESWEPAM;
str.File_Name_DST=File_Name_DST;
str.File_Name_KP=File_Name_KP;
str.File_Name_OUTPUT=File_Name_OUTPUT;
str.File_Dir_OUTPUT=File_Dir_OUTPUT;
str.File_Dir_INPUT=File_Dir_INPUT;
visitNode(node,level+1,str);
}
}
}
void FileName_Dir::Name_show()
{
cout<0)
{File_Name_ACEMAG=File_Name_ACEMAG.substr(0,i);}
else
{File_Name_ACEMAG="";}
i=0;
i=File_Name_ACESWEPAM.find("\n");
if(i>0)
{File_Name_ACESWEPAM=File_Name_ACESWEPAM.substr(0,i);}
else
{File_Name_ACESWEPAM="";}
i=0;
i=File_Name_DST.find("\n");
if(i>0)
{File_Name_DST=File_Name_DST.substr(0,i);}
else
{File_Name_DST="";}
i=0;
i=File_Name_KP.find("\n");
if(i>0)
{File_Name_KP=File_Name_KP.substr(0,i);}
else
{File_Name_KP="";}
i=0;
i=File_Name_OUTPUT.find("\n");
if(i>0)
{File_Name_OUTPUT=File_Name_OUTPUT.substr(0,i);}
else
{File_Name_OUTPUT="";}
}
void FileName_Dir::Dir_corect()
{
int j=File_Dir_INPUT.find("\n");
if(j>0)
{File_Dir_INPUT=File_Dir_INPUT.substr(0,j);}
else
{File_Dir_INPUT="";}
j=0;
j=File_Dir_OUTPUT.find("\n");
if(j>0)
{File_Dir_OUTPUT=File_Dir_OUTPUT.substr(0,j);}
else
{File_Dir_OUTPUT="";}
}
string file_read(string name)
{
char ch;
string str;
ifstream infile(name.c_str());
while(infile)
{
infile.get(ch);
if(ch==':')
str+=' ';
else
str+=ch;
}
infile.close();
return str;
}
TiXmlDocument loadData(char* pFilename)
{
TiXmlDocument doc(pFilename);
bool loadOk = doc.LoadFile();
if (!loadOk)
{
error_file+="\nOrderFileReading\nOderFileRead\n1\n\n";
exit(1);
}
else
{
error_file+="\nOrderFileReading\nOderFileRead\n0\n\n";
return doc;
}
}
string file_eraze(string str)
{
int k1=str.find("#-------------------------------------------------------------------------");
if (k1>0)
{
str.erase(0,k1);
int k2=str.find("2");
str.erase(0,k2);
}
int b1=str.find("[");
int b2=str.length();
if (b1>0)
{
str.erase(b1-1,b2);
}
return str;
}
void InputData_analysis::data_analysis(string str)
{
error_file+="\nFileAnalysis\n";
string substr1, substr2;
substr2="";
while(substr2!="\n")
{
substr2=str.substr(NumberOfSymbols,1);
NumberOfSymbols++;
}
if (NumberOfSymbols==73)
{
error_file+="FileStructure\n0\n";
Month=atoi(str.substr(5,2).c_str());
int testmonth1=month_time();
int testmonth2=month_time_last();
if (Month==testmonth1)
{
error_file+="FileDate\n0\n";
DataName="SWEPAM1";
}
else if (Month==testmonth2)
{
error_file+="FileDate\n0\n";
DataName="SWEPAM2";
}
else
{
error_file+="FileDate\n1\n";
}
}
else if (NumberOfSymbols==86)
{
error_file+="FileStructure\n0\n";;
Month=atoi(str.substr(5,2).c_str());
int testmonth1=month_time();
int testmonth2=month_time_last();
if (Month==testmonth1)
{
error_file+="FileDate\n0\n";
DataName="MAG1";
}
else if (Month==testmonth2)
{
error_file+="FileDate\n0\n";
DataName="MAG2";
}
else
{
error_file+="FileDate\n1\n";
}
}
else if (NumberOfSymbols>120 && NumberOfSymbols<125)
{
error_file+="FileStructure\n0\n";
Month=atoi(str.substr(5,2).c_str());
int testmonth1=month_time();
int testmonth2=month_time_last();
if (Month==testmonth1)
{
error_file+="FileDate\n0\n";
DataName="DST1";
}
else if (Month==testmonth2)
{
error_file+="FileDate\n0\n";
DataName="DST2";
}
else
{
error_file+="FileDate\n1\n";
}
}
else if (NumberOfSymbols<=63)
{
error_file+="FileStructure\n0\n";
Month=atoi(str.substr(2,2).c_str());
int testmonth1=month_time();
int testmonth2=month_time_last();
if (Month==testmonth1)
{
error_file+="FileDate\n0\n";
DataName="KP1";
}
else if (Month==testmonth2)
{
error_file+="FileDate\n0\n";
DataName="KP2";
}
else
{
error_file+="FileDate\n1\n";
}
}
else
{
error_file+="FileStructure\n1\n";
}
error_file+="\n";
}
int DST_files_download(string outputfile_name)
{
int controll=0;
InputData_analysis dst_data[2];
string url_name, filename1, filename2, dst_out_str1, dst_out_str2, s, s1;
s=present_data();
s1=short_data_present();
filename1="Dst_present.txt";
error_file+="\nDSTFileDownload\n";
url_name="http://wdc.kugi.kyoto-u.ac.jp/dst_realtime/";
url_name+=s+"/dst"+s1+".for.request";
data_file_downloadftp(url_name, filename1);
error_file+="\n";
ifstream infile(filename1.c_str());
if(infile)
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n0\n\n";
dst_out_str1=file_read(filename1);
dst_out_str1=file_eraze(dst_out_str1);
dst_data[0].data_analysis(dst_out_str1);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n1\n\n";
controll++;
}
infile.close();
s="";
s1="";
s=last_data();
s1=short_data_last();
url_name ="";
url_name="http://wdc.kugi.kyoto-u.ac.jp/dst_realtime/";
url_name+=s+"/dst"+s1+".for.request";
filename2="Dst_last.txt";
error_file+="\nDSTFile2Download\n";
data_file_downloadftp(url_name, filename2);
error_file+="\n";
ifstream infile1(filename2.c_str());
if(infile1)
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n0\n\n";
dst_out_str2=file_read(filename2);
dst_out_str2=file_eraze(dst_out_str2);
dst_data[1].data_analysis(dst_out_str2);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n1\n\n";
controll++;
}
infile1.close();
if(controll==0 && dst_data[1].get_dataname()=="DST2" && dst_data[0].get_dataname()=="DST1")
{
dst_out_str2+=dst_out_str1;
controll=FileStructureAnalysis3(dst_out_str2);
file_wright(dst_out_str2,outputfile_name);
}
remove(filename1.c_str());
remove(filename2.c_str());
return controll;
}
int KP_files_download(string outputfile_name)
{
int controll=0;
InputData_analysis kp_data[2];
string url_name, filename1, filename2, kp_out_str1, kp_out_str2;
error_file+="\nKPFileDownload\n";
url_name = "http://www-app3.gfz-potsdam.de/kp_index/qlyymm.wdc";
filename1="Kp_present.txt";
data_file_downloadftp(url_name, filename1);
error_file+="\n";
ifstream infile(filename1.c_str());
if(infile)
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n0\n\n";
kp_out_str1=file_read(filename1);
kp_data[0].data_analysis(kp_out_str1);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n1\n\n";
controll++;
}
infile.close();
url_name ="";
url_name="http://www-app3.gfz-potsdam.de/kp_index/pqlyymm.wdc";
filename2="KP_last.txt";
error_file+="\nKPFile2Download\n";
data_file_downloadftp(url_name, filename2);
error_file+="\n";
ifstream infile1(filename2.c_str());
if(infile1)
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n0\n\n";
kp_out_str2=file_read(filename2);
kp_data[1].data_analysis(kp_out_str2);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n1\n\n";
controll++;
}
infile1.close();
if(controll==0 )
{
if(kp_data[1].get_dataname()==kp_data[0].get_dataname())
{
controll=FileStructureAnalysis3(kp_out_str2);
file_wright(kp_out_str2, outputfile_name);
}
else
{
int lastsymbol=kp_out_str2.size();
kp_out_str2.erase(lastsymbol-1,lastsymbol);
kp_out_str2+=kp_out_str1;
controll=FileStructureAnalysis3(kp_out_str2);
file_wright(kp_out_str2, outputfile_name);
}
}
remove(filename1.c_str());
remove(filename2.c_str());
return controll;
}
int ACEMAG_files_download(string outputfile_name)
{
int controll=0;
InputData_analysis mag_data[2];
string url_name, filename1, filename2, mag_out_str1, mag_out_str2, s;
s=present_data();
error_file+="\nAceMagFileDownload\n";
url_name="ftp://ftp.swpc.noaa.gov/pub/lists/ace2/";
url_name+=s+"_ace_mag_1h.txt";
filename1="MAG_present.txt";
data_file_downloadftp(url_name, filename1);
error_file+="\n";
ifstream infile(filename1.c_str());
if(infile)
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n0\n\n";
mag_out_str1=file_read(filename1);
mag_out_str1=file_eraze(mag_out_str1);
mag_data[0].data_analysis(mag_out_str1);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n1\n\n";
controll++;
}
infile.close();
s="";
s=last_data();
url_name ="";
url_name="ftp://ftp.swpc.noaa.gov/pub/lists/ace2/";
url_name+=s+"_ace_mag_1h.txt";
filename2="MAG_last.txt";
error_file+="\nAceMagFile2Download\n";
data_file_downloadftp(url_name, filename2);
error_file+="\n";
ifstream infile1(filename2.c_str());
if(infile1)
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n0\n\n";
mag_out_str2=file_read(filename2);
mag_out_str2=file_eraze(mag_out_str2);
mag_data[1].data_analysis(mag_out_str2);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n1\n\n";
controll++;
}
infile1.close();
if(controll==0 && mag_data[1].get_dataname()=="MAG2" && mag_data[0].get_dataname()=="MAG1")
{
int lastsymbol=mag_out_str2.size();
mag_out_str2.erase(lastsymbol-1,lastsymbol);
mag_out_str2+=mag_out_str1;
controll=FileStructureAnalysis3(mag_out_str2);
string temp ="# Modified Seconds\n# UT Date Time Julian of the ---------------- GSM Coordinates ---------------\n# YR MO DA HHMM Day Day S Bx By Bz Bt Lat. Long.\n#------------------------------------------------------------------------------------\n";
temp+=mag_out_str2;
file_wright(temp,outputfile_name);
}
remove(filename1.c_str());
remove(filename2.c_str());
return controll;
}
int ACESWEPAM_files_download(string outputfile_name)
{
int controll=0;
InputData_analysis swepam_data[2];
string url_name, filename1, filename2, swepam_out_str1, swepam_out_str2, s;
s=present_data();
error_file+="\nAceSwepamFileDownload\n";
url_name="ftp://ftp.swpc.noaa.gov/pub/lists/ace2/";
url_name+=s+"_ace_swepam_1h.txt";
filename1="SWEPAM_present.txt";
data_file_downloadftp(url_name, filename1);
error_file+="\n";
ifstream infile(filename1.c_str());
if(infile)
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n0\n\n";
swepam_out_str1=file_read(filename1);
swepam_out_str1=file_eraze(swepam_out_str1);
swepam_data[0].data_analysis(swepam_out_str1);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename1;
error_file+="'read\n1\n\n";
controll++;
}
infile.close();
s="";
s=last_data();
url_name ="";
url_name="ftp://ftp.swpc.noaa.gov/pub/lists/ace2/";
url_name+=s+"_ace_swepam_1h.txt";
filename2="SWEPAM_last.txt";
error_file+="\nAceMagFile2Download\n";
data_file_downloadftp(url_name, filename2);
error_file+="\n";
ifstream infile1(filename2.c_str());
if(infile1)
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n0\n\n";
swepam_out_str2=file_read(filename2);
swepam_out_str2=file_eraze(swepam_out_str2);
swepam_data[1].data_analysis(swepam_out_str2);
}
else
{
error_file+="\nFileRead\n'";
error_file+=filename2;
error_file+="'read\n1\n\n";
controll++;
}
infile1.close();
if(controll==0 && swepam_data[1].get_dataname()=="SWEPAM2" && swepam_data[0].get_dataname()=="SWEPAM1")
{
int lastsymbol=swepam_out_str2.size();
swepam_out_str2.erase(lastsymbol-1,lastsymbol);
swepam_out_str2+=swepam_out_str1;
controll=FileStructureAnalysis3(swepam_out_str2);
string temp = "# Modified Seconds ------------- Solar Wind -----------\n# UT Date Time Julian of the Proton Bulk Ion\n# YR MO DA HHMM Day Day S Density Speed Temperature\n#-------------------------------------------------------------------------\n";
temp+=swepam_out_str2;
file_wright(temp,outputfile_name);
}
remove(filename1.c_str());
remove(filename2.c_str());
return controll;
}
int month_time()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int month;
month=1+tk->tm_mon;
return month;
}
int year_time()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int year;
year=1900+tk->tm_year;
return year;
}
int day_time()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int day;
day=tk->tm_mday;
return day;
}
int yearday_time()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int day;
day=tk->tm_yday;
return day;
}
int hour_time()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int hour;
hour=tk->tm_hour;
return hour;
}
int min_time()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int min;
min=tk->tm_min;
return min;
}
int month_time_last()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int month;
month=tk->tm_mon;
if (month==0)
{
month=12;
}
return month;
}
int year_time_short()
{
time_t t;
tm *tk;
time(&t);
tk=gmtime(&t);
int year;
year=-100+tk->tm_year;
return year;
}
string InputData_analysis::get_dataname()
{
return DataName;
}
int InputData_analysis::get_numberOFSymbols()
{
return NumberOfSymbols;
}
void CongFileCreation(string output, string filenames_file)
{
string filesnames;
filesnames="=======================================================================\n";
filesnames+="CONFIG FILE FOR FARM MODELLING PROCESSOR\n";
filesnames+="-----------------------------------------------------------------------\n";
filesnames+="EXPLANATION OF PARAMETERS:\n";
filesnames+=" KY - NUMBER OF THE OUTPUT AMONG THE MAIN INPUTS (1..12)\n";
filesnames+=" LT - LEAD TIME\n";
filesnames+=" UFLAG - WHICH INPUTS (INCL. ADDITIONAL) TO USE\n";
filesnames+=" LMAX - MAXIMAL LAGS FOR EACH INPUT (INCL. ADDITIONAL)\n";
filesnames+=" DT - CADENCE FOR EACH INPUT (INCL. ADDITIONAL)\n";
filesnames+=" UF - FILL VALUES FOR EACH INPUT (INCL. ADDITIONAL)\n";
filesnames+=" UN - NAMES OF THE MAIN INPUTS\n";
filesnames+=" UU - UNITS OF THE MAIN INPUTS\n";
filesnames+=" FNRES - MODEL FILENAMES, 12 (IN)\n";
filesnames+=" FNCOV - COVARIANCE MATRIX FILENAMES, 12 (IN)\n";
filesnames+=" FMDAT - FORMAT OF THE OUTPUT FILE\n";
filesnames+=" FMDATH - FORMAT OF THE HEADER OF THE OUTPUT FILE\n";
filesnames+="INPUT FILES:\n";
filesnames+=" FNMAG - ACE/MAG\n";
filesnames+=" FNSWEPAM - ACE/SWEPAM\n";
filesnames+=" FNKP - KP AND AP\n";
filesnames+=" FNDST - DST\n";
filesnames+="OUTPUT FILES:\n";
filesnames+=" FNDAT - FORECAST IN ASCII FORMAT\n";
filesnames+=" FNMET - METADATA IN XML FORMAT\n";
filesnames+="-----------------------------------------------------------------------\n";
filesnames+="THE ADDITIONAL INPUTS ARE:\n";
filesnames+=" 13.SINE WITH HALF-A-DAY PERIOD\n";
filesnames+=" 14.COSINE WITH HALF-A-DAY PERIOD\n";
filesnames+=" 15.SINE WITH HALF-A-YEAR PERIOD\n";
filesnames+=" 16.COSINE WITH HALF-A-YEAR PERIOD\n";
filesnames+="-----------------------------------------------------------------------\n";
filesnames+="NOTE:\n";
filesnames+=" THE FIRST HOUR OF EACH DAY STARTS AT UT MIDNIGHT\n";
filesnames+="=======================================================================\n";
filesnames+="&FARM_FOR\n";
filesnames+=" KY=12\n";
filesnames+=" LT=3\n";
filesnames+=" UFLAG=1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1\n";
filesnames+=" LMAX=9*24,3*648,4*0\n";
filesnames+=" DT=9*1,3,1,3,4*1\n";
filesnames+=" UF=6*-999.9,-1.E5,2*-9999.9,99.,9999.,0.,4*9.\n";
filesnames+=" UN='Bt','Btheta','Bphi','Bx','By','Bz','T','n','V','Kp','Dst','ap'\n";
filesnames+=" UU=6*'nT','K','p/cc','km/s','*10',2*'nT'\n";
filesnames+=" FNRES='1203.res','','','','','','','','','','',''\n";
filesnames+=" FNCOV='1203.cov','','','','','','','','','','',''\n";
filesnames+=" FMDAT='(2(1X,I6),1X,I4,2(1X,I2),1X,I3,1X,I2,1X,5X,F6.0,1(1X,7X,F6.0))'\n";
filesnames+=" FMDATH='(4X,\"HOY\",3X,\"HTND\",1X,\"YYYY\",1X,\"MM\",1X,\"DD\",1X,\"DOY\",1X,\"HH\",1X,A11,1(1X,\"FC+\",I2.2,\"H\",A7))'\n";
filesnames+=output;
file_wright(filesnames,filenames_file);
}
int FileStructureAnalysis3(string fileInstring)
{
error_file+="\nFileStructureAnalysis2\n";
int controll=0;
string substr, temp;
substr="";
int counter=1;
int stopCount=fileInstring.size();
temp=fileInstring.substr(counter,1);
while(counterFileStructureRowMissing\n1\n";
controll++;
}
if(substr=="\n")
{
temp=substr;
counter++;
}
else
{
temp=substr;
counter++;
}
}
if(controll==0)
{
error_file+="FileStructureRowMissing\n0\n";
}
error_file+="\n";
return controll;
}
int FileStructureAnalysis2(string fileInstring)
{
int controll=0;
error_file+="\nFileStructureAnalysis2\n";
string substr, temp;
substr="";
int counter=1;
int stopCount=fileInstring.size();
int NumberOfRows=0;
int NumberOfSymbols=0;
temp=fileInstring.substr(counter,1);
while(counterFileStructureRowMissing\n1\n";
controll++;
}
if(substr=="\n")
{
NumberOfRows++;
temp=substr;
counter++;
}
else
{
temp=substr;
counter++;
}
if(NumberOfRows==30)
{
NumberOfSymbols++;
}
}
if(controll==0)
{
error_file+="FileStructureRowMissing\n0\n";
}
if (NumberOfSymbols==73 || NumberOfSymbols==86)
{
error_file+="FileStructure\n0\n";
}
else
{
error_file+="FileStructure\n1\n";
controll++;
}
error_file+="\n";
return controll;
}
int FilesInXmlTest(string inputfilename)
{
int controll_parameter=0;
string str_data;
ifstream infile(inputfilename.c_str());
if(infile)
{
error_file+="\nFileRead\n'";
error_file+=inputfilename;
error_file+="'read\n0\n\n";
str_data=file_read(inputfilename);
controll_parameter=FileStructureAnalysis2(str_data);
}
else
{
error_file+="\nFileRead\n'";
error_file+=inputfilename;
error_file+="'read\n1\n\n";
controll_parameter++;
}
infile.close();
return controll_parameter;
}
string FileTimeForm()
{
string FileTimeToString="";
int year, day, hour, minutes;
year=year_time();
day=yearday_time();
hour=hour_time();
minutes=min_time();
stringstream out;
out << year;
FileTimeToString += out.str();
FileTimeToString += "_";
stringstream out1;
if (day<100)
{
out1 << '0';
}
if(day<10)
{
out1 << '0';
}
out1 << day;
FileTimeToString += out1.str();
FileTimeToString += "_";
stringstream out2;
if (hour<10)
{
out2 << '0';
}
out2 << hour;
FileTimeToString += out2.str();
FileTimeToString += "_";
stringstream out3;
if (minutes<10)
{
out3 << '0';
}
out3 << minutes;
FileTimeToString += out3.str();
return FileTimeToString;
}