GNSS数据下载——GAMP GOOD修改

首先很感谢周老师开源的数据下载程序,但是对于做导航相关的同学来说,我有一个想法~

输入观测文件,通过读取观测文件的头文件起始时间和结束时间,就下到对应天数的产品

(我是懒狗,其实对于我个人来说,我不需要过多的产品,只需要自己喜欢的产品即可,并且所有产品下载到一个文件里就好了)

1、头文件读取

static bool readobshead(const std::string& filename,std::vector<int>&start_time,int &doy){
    std::vector<int>last_time= {0,0,0,0,0,0};
    doy = 0;
    std::fstream obsfile(filename);
    if (!obsfile.is_open()) {
        std::cerr << "Failed to open obs file: " << filename << std::endl;
        return false;
    }
    std::string str_line = "";
    std::istringstream temp(str_line);
    while (getline(obsfile, str_line)) {
        if(str_line.find("TIME OF FIRST OBS") != std::string::npos)
        {
            std::istringstream iss(str_line);
            iss >> start_time[0] >> start_time[1]  >> start_time[2]
                    >> start_time[3]  >> start_time[4] >>start_time[5] ;
            continue;
        }

        if (str_line.find("TIME OF LAST OBS") != std::string::npos) {
            std::istringstream iss(str_line);
            iss >> last_time[0] >> last_time[1] >> last_time[2]
                >> last_time[3] >> last_time[4] >> last_time[5];
            continue;
        }
        if (str_line.find("END OF HEADER") != std::string::npos) {
            break;
        }
    }
    doy = daysPassed(start_time,last_time);
    if(doy != 0){
        return true;
    }else{
        return false;
    }
}

很简单的头文件读取,输出文件的路径,计算起始时间和doy也就是年积日

2、通过起始时间和结束时间让其支持跨天

static int daysPassed(const std::vector<int>& start_time,const std::vector<int> & end_time) {

    // 判断是否跨天
    if (start_time[0] == end_time[0] && start_time[1] == end_time[1] && start_time[2] == end_time[2]) {
        return 1; // 同一天
    } else {
        return end_time[2] - start_time[2] + 1; // 跨天
    }
}

3、判断是不是观测文件(这里按照文件末尾是不是o与O进行判断)

static bool endsWithO(const std::string& filename) {
    if (!filename.empty()) {
        char lastChar = filename.back(); // 获取文件名的最后一个字符
        return (lastChar == 'O' || lastChar == 'o');
    }
    return false;
}

4、通过观测文件路径推断出此文件的所外路径

也就是D:data\o推断出D:data,数据下载到这个路径下

static std::string extractFolderPath(const std::string& filepath) {
    // 寻找最后一个 '\' 字符的位置
    size_t found = filepath.find_last_of("\\");
    if (found != std::string::npos) {
        // 返回路径部分
        return filepath.substr(0, found);
    } else {
        // 如果没有找到 '\' 字符,返回空字符串
        return "";
    }
}

5、修改程序的主入口程序

这样我们就可以支持下载多个观测文件的数据啦,同时也不影响原先配置文件

int main(int argc, char * argv[]) {
    if (argc < 2) {
        std::cout << std::endl;
        Logger::Trace(TEXPORT, "* Usage: run_GOOD GOOD_cfg.yaml [file1] [file2] ... [fileN]");
        std::cout << std::endl;
        return -1;
    }

    Logger::Trace(TEXPORT, "GAMP II: intelliGent Analysis system for Multi-sensor integrated navigation and Positioning v2.0");
    Logger::Trace(TEXPORT, "===================================================================================================");

    for (int i = 1; i < argc; ++i) {
        std::string cfgfile = argv[i];
        bool readobs = endsWithO(cfgfile);

        Logger::Trace(TEXPORT, "* Now, we are running GAMP II - GOOD (GNSS Observations and prOducts Downloader) for file: " + cfgfile + "\n");

        if (readobs) {
            std::vector<int> start_time = {0, 0, 0, 0, 0, 0};
            int doy = 0;
            readobshead(cfgfile, start_time, doy);
            std::string outpath = extractFolderPath(cfgfile);
            Config::runobs(outpath, start_time, doy);
        } else {
            Config::run(cfgfile);
        }
    }
#if (defined(_WIN32) && defined(_DEBUG))  /* for Windows */
    std::cout << std::endl << "Press any key to exit!" << std::endl;
    getchar();
#endif
    return 0;
}

6、增加从obs文件读取的run

让所有文件输出到一个文件夹里

void Config::runobs(const std::string out_file,const std::vector<int> &time, const int &doy)
{
    prcopt_t popt;
    ftpopt_t fopt;
    /* initialization */
    init(&popt, &fopt);

    /* read configure file to get processing information */
    Readobsyaml(out_file,time,doy, &popt, &fopt);

    /* data downloading for GNSS further processing */
    if (fopt.ftpdownloading)
    {
        FtpUtil ftp;
        std::string obsdirmain = popt.obsdir;
        std::string navdirmain = popt.navdir;
        std::string iondirmain = popt.iondir;
        std::string ztddirmain = popt.ztddir;
        for (int i = 0; i < popt.ndays; i++)
        {
            int yyyy, doy;
            GTime::time2yrdoy(popt.ts, yyyy, doy);
            std::string syyyy = CString::int2str(yyyy, 4);
            std::string sdoy = CString::int2str(doy, 3);
            std::string dir, sep;
            sep.push_back((char)FILEPATHSEP);
            /* creat new observation sub-directory */
            if (fopt.getobs)
            {
                dir = obsdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.obsdir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            /* creat new NAV sub-directory */
            if (fopt.getnav)
            {
                dir = navdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.navdir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            /* creat new ORB sub-directory */
            if (fopt.getorbclk)
            {
                dir = navdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.orbdir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }
            /* creat new CLK sub-directory */
            if (fopt.getorbclk)
            {
                dir = navdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.clkdir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            /* creat new OSB sub-directory */
            if (fopt.getdsb)
            {
                dir = navdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.biadir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }
            /* creat new OSB sub-directory */
            if (fopt.getosb)
            {
                dir = navdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.biadir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }
            /* creat new eop sub-directory */
            if (fopt.geteop)
            {
                dir = navdirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.eopdir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            /* creat new ION sub-directory */
            if (fopt.getion)
            {
                dir = iondirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.iondir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            /* creat new ZTD sub-directory */
            if (fopt.gettrp)
            {
                dir = ztddirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.ztddir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            if (fopt.getobx)
            {
                dir = iondirmain + sep + syyyy + sep + sdoy;
                CString::trim(dir);
                popt.obxdir = dir;
                if (access(dir.c_str(), 0) == -1)
                {
                    /* If the directory does not exist, creat it */
#ifdef _WIN32   /* for Windows */
                    std::string cmd = "mkdir " + dir;
#else           /* for Linux or Mac */
                    std::string cmd = "mkdir -p " + dir;
#endif
                    std::system(cmd.c_str());
                }
            }

            /* the main entry of FTP downloader */
            ftp.FtpDownload(&popt, &fopt);

            popt.ts = GTime::TimeAdd(popt.ts, 86400.0);
        }
    }
} /* end of run */

7、从观测文件获取时间,并设定自己喜欢的产品(这是按个人要求设计的,我不需要对流层文件所以没有放进去)并且我建立了一个public的文件夹,产品都放到这里面了

bool Config::Readobsyaml(const std::string out_file,const std::vector<int> &time, const int &doy, prcopt_t* popt, ftpopt_t* fopt)
{
    std::string sep;
    sep.push_back((char)FILEPATHSEP);

        popt->maindir = out_file;

        popt->navdir = popt->maindir+ sep +"public";

        popt->orbdir = popt->maindir + sep +"public";

        popt->clkdir = popt->maindir + sep +"public";

        popt->eopdir = popt->maindir + sep +"public";

        popt->obxdir = popt->maindir + sep +"public";

        popt->biadir = popt->maindir + sep +"public";

        popt->iondir = popt->maindir + sep +"public";

        popt->ztddir = popt->maindir+ sep +"public";

        popt->tbldir = popt->maindir + sep +"public";

        popt->logdir = popt->maindir + sep +"public";

        popt->logfil = popt->logdir + sep +"public";

        popt->dir3party = popt->maindir + sep +"thirdparty";

        std::vector<double> ep;
        ep.push_back(time[1]);
        ep.push_back(time[2]);
        ep.push_back(time[3]);
        ep.push_back(0);
        ep.push_back(0);
        ep.push_back(0);
        popt->ts = GTime::ymdhms2time(ep);
        popt->ts = GTime::yrdoy2time(time[0], time[1]);
        popt->ndays = doy;

        fopt->printinfo4wget = true;

        fopt->ftpdownloading = true;
        fopt->ftpfrom ="whu";

        fopt->navtype = "daily";
        fopt->navsys = "mixed3";
        fopt->navfrom = "igs";

        fopt->orbclkfrom = "gfz";

        fopt->eopfrom ="igs";
        fopt->obxfrom = "whu";
        fopt->dsbfrom = "cas";
        fopt->osbfrom = "cas";
        fopt->ionfrom = "cas+cod";

    return true;
}

8、修改初始化程序

对于做PPP的同学来说这写其实都必须要,我个人喜欢长文件,大家也可以自己改为短文、件

void Config::init(prcopt_t* popt, ftpopt_t* fopt)
{
    /* time settings */
    popt->ts = { 0 };                            /* start time for processing */
    popt->ndays = 1;                             /* number of consecutive days */

    /* FTP downloading settings */
    fopt->minus_add_1day = false;                 /* (0:off  1:on) the day before and after the current day for precise satellite orbit and clock
                                                    products downloading */
    fopt->merge_sp3files = true;                /* (0: off  1: on) to merge three consecutive sp3 files into one file */
    fopt->printinfo4wget = false;                /* (0:off  1:on) print the information generated by 'wget' */

    /* initialization for FTP options */
    fopt->ftpdownloading = false;                /* the master switch for data downloading, 0:off  1:on, only for data downloading */
    fopt->getobs = false;                        /* (0:off  1:on) IGS observation (RINEX version 2.xx, short name 'd') */
    fopt->l2s4obs = 1;                           /* valid only for the observation files with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->getnav = true;                        /* (0:off  1:on) broadcast ephemeris */
    fopt->l2s4nav = 2;                           /* valid only for the navigation files with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->getorbclk = true;                     /* (0:off  1:on) precise orbit 'sp3' and precise clock 'clk' */
    fopt->l2s4oc = 2;                            /* valid only for the precise orbit and clock files with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->geteop = true;                        /* (0:off  1:on) earth rotation parameter */
    fopt->l2s4eop = 2;                           /* valid only for EOP file with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->getobx = true;                        /* (0:off  1:on) ORBEX (ORBit EXchange format) for satellite attitude information */
    fopt->getsnx = false;                        /* (0:off  1:on) IGS weekly SINEX */
    fopt->l2s4snx = 2;                           /* valid only for IGS weekly SINEX files with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->getdsb = true;                        /* (0:off  1:on) differential code/signal bias (DCB/DSB) */
    fopt->getosb = true;                        /* (0:off  1:on) observable-specific signal bias (OSB) */
    fopt->getion = true;                        /* (0:off  1:on) global ionosphere map (GIM) */
    fopt->l2s4ion = 2;                           /* valid only for the ionosphere files with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->getroti = false;                       /* (0:off  1:on) rate of TEC index (ROTI) */
    fopt->gettrp = false;                        /* (0:off  1:on) CODE and/or IGS tropospheric product */
    fopt->l2s4trp = 2;                           /* valid only for the troposphere files with long name, 0: long name, 1: short name, 2: long and short name */
    fopt->getatx = false;                        /* (0:off  1:on) ANTEX format antenna phase center correction */
} /* end of init */

9、程序

程序

程序下载

链接:https://pan.baidu.com/s/1tCx_Bx_KXitLuVXi09q-NA?pwd=1234 
提取码:1234 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值