075-RTKlib中关于结构体gtime_t

  RTKlib中关于结构体gtime_t的一些记录:
  该结构体的定义:

typedef struct {        /* time struct */
    time_t time;        /* time (s) expressed by standard time_t */
    double sec;         /* fraction of second under 1 s */
} gtime_t;

  其实该结构体储存的是自1970年1月1日0时0分0秒至目标时间的秒数time及不足整秒sec,结构体time_t为一个64位的整型。下面给出一个例子:

int main()
{
	double ep_[6];
	ep_[0] = 2019; ep_[1] = 2; ep_[2] = 27;
	ep_[3] = 11; ep_[4] = 7; ep_[5] = 15.23;
	double *ep;
	ep = &ep_[0];
	gtime_t t;
	t = epoch2time(ep);
	printf("%d \t", t.time);
	printf("%f \n", t.sec);
	system("pause");
	return 0;
}

输出结果:

  另外,还需记录一下epoch2time函数,定义如下:

extern gtime_t epoch2time(const double *ep)
{
	/* 平年每月的第一天的年积日*/
    const int doy[]={1,32,60,91,121,152,182,213,244,274,305,335};
    gtime_t time={0};
    int days,sec,year=(int)ep[0],mon=(int)ep[1],day=(int)ep[2];
    
    if (year<1970||2099<year||mon<1||12<mon) return time;
    
    /* leap year if year%4==0 in 1901-2099 */
    days=(year-1970)*365+(year-1969)/4+doy[mon-1]+day-2+(year%4==0&&mon>=3?1:0);
    sec=(int)floor(ep[5]);
    time.time=(time_t)days*86400+(int)ep[3]*3600+(int)ep[4]*60+sec;
    time.sec=ep[5]-sec;
    return time;
}

  着重说明一下天数的求解,

days=(year-1970)*365+(year-1969)/4+doy[mon-1]+day-2+(year%4==0&&mon>=3?1:0);

  先举一个例子,例如我们要求2019年1月2日0时0分10秒到2019年1月1日0时0分0秒的秒数,1月2日的年积日为2,但是我们求解时肯定是1月2日之前那一天的年积日换算成秒数,然后加上1月2日经过的秒数。
  那么我们求解某一时刻A至起点所经过的秒数,所要求解的年积日就是A前一天的年积日。所以对于doy[mon-1]+day-2就比较容易理解。例如我们要知道2.11至起点的秒数,那我们要求的年积日是2.10的,doy(2-1)+11-2=41。
  对于(year%4==0&&mon>=3?1:0),当这一年为闰年且月份大于3时,得出的结果等于1,即闰年2月之后的某一天要加一天。
  对于(year-1970)*365+(year-1969)/4,当求解1972年(闰年)的时间时,(year%4==0&&mon>=3?1:0)起到加一天的作用,当求解1973年的时间时,(year-1970)*365将1972年当成365天计算了,(year-1969)/4补充了这一天。对于其他年份也是如此。值得注意的是,time.time=(time_t)days*86400+(int)ep[3]*3600+(int)ep[4]*60+sec;days进行了取整。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值