gctl_toolkits/archive/grid2xyz/surfer2dat/main.cpp

120 lines
2.6 KiB
C++
Raw Normal View History

2024-09-10 20:25:18 +08:00
#include "common.h"
void disp_help()
{
cout<<"surfer2dat 0.5 - convert surfer's grid file into .dat & .fie files"<<endl<<endl
<<"usage: surfer2dat input-file -e<input-file2>|-f<elevation|radius>|-d [-r<xmin>/<xmax>/<ymin>/<ymax>] [-o<output-file>]"<<endl
<<" -e specify each point's elevation or radius by input-file2 which should be as the same size as input-file"<<endl
<<" -f convert to .fie file, elevation or radius of the input data must be given"<<endl
<<" -d convert to .dat file"<<endl
<<" -r specify the interest area"<<endl
<<" -o specify the ouput-name, the input-file's name will be used if -o is absent"<<endl<<endl
<<"example: surfer2dat in.grd -d example_out"<<endl;
}
int main(int argc, char* argv[])
{
if (argc==1)
{
disp_help();
}
else if (argc==2)
{
cout<<"too few arguments, program stopped..."<<endl;
}
else
{
CON c;
int space_num;
string temp = "";
string input_name = "";
string input_name2 = "";
string output_name = "";
stringstream stemp;
int out_type = -1;
double range[4] = {MAX,MAX,MAX,MAX};
double topo = MAX;
input_name = argv[1];
for (int i = 2; i < argc; i++)
{
if (typeget(argv[i],OUTPUT,temp))//取得输出名
{
output_name = temp;
temp = "";
}
if (typeget(argv[i],ELE,temp))
{
if (temp=="")
{
cout<<"no input_name for '-e' command, program stopped..."<<endl;
return 0;
}
else
{
input_name2 = temp;
temp = "";
out_type = 1;
}
}
if (typeget(argv[i],FIE,temp))
{
if (temp=="")
{
cout<<"no input for '-f' command, program stopped..."<<endl;
return 0;
}
else
{
stemp.clear();
stemp.str(temp);
stemp>>topo;
out_type = 1;
}
}
if (!strcmp(argv[i],DAT)) out_type = 2;
if (typeget(argv[i],RANGE,temp))
{
replace_all(temp,"/"," ",space_num);
stemp.clear();
stemp.str(temp);
if (space_num==3)
{
stemp>>range[0]>>range[1]>>range[2]>>range[3];
if (range[0]>range[1])
{
cout<<"wrong x range, program stopped..."<<endl;
return 0;
}
else if (range[2]>range[3])
{
cout<<"wrong y range, program stopped..."<<endl;
return 0;
}
}
else
{
cout<<"insufficient attributes information, program stoped..."<<endl;
return 0;
}
}
}
if(output_name=="")
{
char* fullname;
int len = input_name.length();
fullname=(char *)malloc((len+1)*sizeof(char));
input_name.copy(fullname,len,0);
nameget(fullname,GRD,output_name);
}
if(c.run(input_name,input_name2,output_name,out_type,topo,range)) return 0;
}
return 0;
}