68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#include "xyz2shc.h"
|
|
|
|
int XYZ2SHC::ReadXyz(char* file_para,double given_dev){
|
|
char filename[1024];
|
|
int order[4];
|
|
|
|
//同时读取文件名和读入列
|
|
if (5 != sscanf(file_para,"%[^+]+d%d,%d,%d,%d",filename,&order[0],&order[1],&order[2],&order[3])){
|
|
if (4 != sscanf(file_para,"%[^+]+d%d,%d,%d",filename,&order[0],&order[1],&order[2])){
|
|
//直接将file_para赋值给filename
|
|
strcpy(filename,file_para);
|
|
order[0] = 0;
|
|
order[1] = 1;
|
|
order[2] = 2;
|
|
order[3] = -1;
|
|
}
|
|
else order[3] = -1;
|
|
}
|
|
|
|
ifstream infile;
|
|
if (open_infile(infile,filename)) return -1;
|
|
|
|
double temp_d;
|
|
_1dArray temp_row;
|
|
obspoint temp_obs;
|
|
string temp_str;
|
|
stringstream temp_ss;
|
|
|
|
temp_row.reserve(100);
|
|
while (getline(infile,temp_str)){
|
|
if (*(temp_str.begin()) == '#')
|
|
continue;
|
|
|
|
if (!temp_row.empty())
|
|
temp_row.clear();
|
|
|
|
temp_ss = str2ss(temp_str);
|
|
while (temp_ss >> temp_d)
|
|
temp_row.push_back(temp_d);
|
|
|
|
temp_obs.phi = temp_row[order[0]];
|
|
//注意经度范围为0~360
|
|
if (temp_obs.phi < 0){
|
|
temp_obs.phi += 360.0;
|
|
}
|
|
|
|
temp_obs.theta = temp_row[order[1]];
|
|
//注意讲纬度转换为余纬度
|
|
temp_obs.theta = 90.0 - temp_obs.theta;
|
|
|
|
temp_obs.rad = BDL_MAX; //注意我们这里暂时不需要半径信息
|
|
temp_obs.val = temp_row[order[2]];
|
|
|
|
//默认读入数据不包含dev
|
|
if (order[3] == -1) temp_obs.dev = given_dev;
|
|
else temp_obs.dev = temp_row[order[3]];
|
|
|
|
obs_point_.push_back(temp_obs);
|
|
}
|
|
infile.close();
|
|
|
|
obs_num_ = obs_point_.size();
|
|
if (obs_num_ == 0){
|
|
cerr << BOLDRED << "error ==> " << RESET << "fail to read observations: " << file_para << endl;
|
|
return -1;
|
|
}
|
|
else return 0;
|
|
} |