#ifndef _FUNC_H #define _FUNC_H #include "struct.h" class func { public: func(); ~func(); int run(char*,char*,char*,double,int,double,double,int,int); int readgrd(char*); int readxyz(char*,double,double); int readxyz(char*); int changeToSph(char*); int outmsh(char*,double); private: posi* topo; int M,N; int posi_num; PosiList list_posi; PosiList::iterator ip; }; func::func() { topo = NULL; } func::~func() { if(topo!=NULL) delete[] topo; if(!list_posi.empty()) list_posi.clear(); } int func::run(char* filename,char* mshname,char* refsys,double factor,int type,double dx,double dy,int input_N,int input_M) { if (type == 1) { readgrd(filename); } else if (type == 2) { if (input_N==-1) { readxyz(filename,dx,dy); } else { readxyz(filename); M = input_M; N = input_N; } } if(strcmp(refsys,"NULL")) changeToSph(refsys); outmsh(mshname,factor); return 0; } int func::readgrd(char* inname) { double xmin,xmax,ymin,ymax,zmin,zmax; double dx,dy; string head_info = ""; ifstream infile(inname); if (!infile) { cout< "<>head_info; if (head_info!="DSAA") { cout< "<>N>>M>>xmin>>xmax>>ymin>>ymax>>zmin>>zmax; dx = (xmax-xmin)/(N-1); dy = (ymax-ymin)/(M-1); posi_num = M*N; topo = new posi [posi_num]; for (int i = 0; i < posi_num; ++i) { topo[i].id = i+1; infile>>topo[i].z; topo[i].alti = topo[i].z; topo[i].x = xmin + dx*(i%N); topo[i].y = ymin + dy*(i/N); } infile.close(); return 0; } } } int func::readxyz(char* inname,double dx,double dy) { int count; posi temp_posi; string line; stringstream sline; double xmax,ymax; double xmin,ymin; ifstream infile(inname); if (!infile) { cout< "<> temp_posi.x >> temp_posi.y >> temp_posi.z; list_posi.push_back(temp_posi); count++; if (temp_posi.x>xmax) xmax = temp_posi.x; if (temp_posi.y>ymax) ymax = temp_posi.y; if (temp_posi.x "<> temp_posi.x >> temp_posi.y >> temp_posi.z; list_posi.push_back(temp_posi); count++; } } infile.close(); posi_num = list_posi.size(); topo = new posi [posi_num]; count = 0; for(ip=list_posi.begin();ip!=list_posi.end();++ip) { temp_posi = *ip; topo[count].id = temp_posi.id; topo[count].x = temp_posi.x; topo[count].y = temp_posi.y; topo[count].z = temp_posi.z; topo[count].alti = topo[count].z; count++; } return 0; } } int func::changeToSph(char* refer) { double refr,refR; if (!strcmp(refer,"WGS84")) { refr = WGS84_PoleRadius; refR = WGS84_EquatorRadius; } else if (!strcmp(refer,"EarthR")) { refr = EarthRadius; refR = EarthRadius; } else if (2 != sscanf(refer,"%lf/%lf",&refr,&refR)) { cout << BOLDRED <<"==> "<< RESET <<" wrong reference system: "< "<=2;i--) { for(int j=N;j>=2;j--) { outfile<