gctl_toolkits/archive/grad1d/grad1d.cpp
2024-09-10 20:25:18 +08:00

88 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "data_func.h"
#include "grad_h.h"
#include "grad_v.h"
void disp_help()
{
cout<<"grad1d 0.0.1 - calculate horizontal and vertical gradient data for 1-D data"<<endl<<endl
<<"usage: grad1d input-file -h|-v [-o output-file]"<<endl
<<" -h calculate horizontal gradient"<<endl
<<" -v calculate vertical gradient"<<endl
<<" -o specify output-file's name. '_gradh|_gradv will be attached at the end of the input"<<endl
<<" file's name as an output name if -o is absent"<<endl<<endl
<<"example: grad1d in.dat -h -o out.dat"<<endl;
}
int main(int argc, char const *argv[])
{
if (argc==1)
{
disp_help();
}
else if (argc==2)
{
cout<<"unsufficient arguments, program stopped..."<<endl;
return 0;
}
else if (argc==3)
{
if (!strcmp(argv[2],HORIZATION))
{
string temp = argv[1];
temp+="_gradh.dat";
const char* outname = temp.c_str();
if(cal_1d_h(argv[1],outname)) return 0;
}
else if (!strcmp(argv[2],VERTICAL))
{
string temp = argv[1];
temp+="_gradv.dat";
const char* outname = temp.c_str();
if(cal_1d_v(argv[1],outname)) return 0;
}
else cout<<argv[2]<<" not found, program stopped..."<<endl;
}
else if (argc==4&&!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],HORIZATION))
{
cout<<"No output name, program stopped..."<<endl;
return 0;
}
else if (argc==4&&!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],VERTICAL))
{
cout<<"No output name, program stopped..."<<endl;
return 0;
}
else if (argc==4)
{
if (!strcmp(argv[3],OUTPUT))
{
cout<<argv[2]<<" not found, program stopped..."<<endl;
return 0;
}
else if (!strcmp(argv[2],HORIZATION)||!strcmp(argv[2],VERTICAL))
{
cout<<argv[3]<<" not found, program stopped..."<<endl;
return 0;
}
else
{
cout<<argv[2]<<" "<<argv[3]<<" not found, program stopped..."<<endl;
return 0;
}
}
else if (argc>4)
{
if (!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],HORIZATION))
{
if(cal_1d_h(argv[1],argv[4])) return 0;
}
else if (!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],VERTICAL))
{
if(cal_1d_v(argv[1],argv[4])) return 0;
}
else if (!strcmp(argv[2],VERTICAL)||!strcmp(argv[2],HORIZATION)) cout<<argv[3]<<" not found, program stopped..."<<endl;
else if (!strcmp(argv[3],OUTPUT)) cout<<argv[2]<<" not found, program stopped..."<<endl;
else cout<<argv[2]<<" "<<argv[3]<<" not found, program stopped..."<<endl;
}
return 0;
}