gps week sec shift peking time

本文介绍了一种将GPS时间转换为北京时间的方法。通过定义特定的数据结构和编写相关函数,可以实现从GPS时间到北京时间的准确转换。考虑到两者之间存在8小时的时间差,文中详细解释了如何进行这种转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


const static double gpst0[]={1980,1, 6,0,0,0}; /* gps time reference */

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;
}


static void Time2Selfstr(gtime_t t,u1 *ymd,u1 *hour,u1 *min,u1 *sec,u4 n)
{
    double ep[6];

    if (n<0) n=0; else if (n>12) n=12;
    if (1.0-t.sec<0.5/pow(10.0,n)) {t.time++; t.sec=0.0;};
    time2epoch(t,ep);
    sprintf(ymd,"%04.0f%02.0f%02.0f",ep[0],ep[1],ep[2]);
    //sprintf(hour,"%02.0f",(ep[3]+8) >= 25 ? (ep[3]+8-24) : (ep[3]+8));//beijing time xg@2017-9-29
    sprintf(hour,"%02.0f",ep[3]);
    sprintf(min,"%02.0f",ep[4]);
    sprintf(sec,"%0*.*f",n <= 0 ? 2 : n + 3, n <= 0 ? 0 : n, ep[5]);
}
/*
gps time to peking time
*/
extern gtime_t gpst2pktime(int week, double sec)
{
    gtime_t t=epoch2time(gpst0);
    
    if (sec<-1E9||1E9<sec) sec=0.0;
    t.time+=86400*7*week+(int)sec+28800;
    t.sec=sec-(int)sec;
    return t;
}



void Get_LocalTime(u1 *buff,int len,u2 type)
{
 	gtime_t time;
	u2 week = 0;
	u4 sec = 0;
    char ymd[10];
    char hour[10];
    char min[10];
    char zsec[10];

    if(type == LOG_RANGE)
    {
		memcpy(&week,buff+14,2);//all is gps time about rangeb
		memcpy(&sec,buff+16,4);
		memset(ymd,0,sizeof(ymd));
        memset(hour,0,sizeof(hour));
        memset(min,0,sizeof(min));
        sec = sec * 0.001;
		time = gpst2pktime(week,sec);
		Time2Selfstr(time,ymd,hour,min,zsec,3);
     if(f_live == 0)//when minutes is 00
        {
            if(atoi(min) == 0 && atof(zsec) == 0.0) //when time is 00.00
                f_live = 3;//enable create a new file to store

            if((atoi(zsec)!=f_timekeeping) && (atoi(zsec)%SYNCTIME==0))
            {
                sync();//sync once -store data
            }
            f_timekeeping = atoi(zsec);
        }
   if(atoi(ymd)>19800106 && f_live == 3) //when the app is started at first or when minutes is 00
        {
            memcpy(f_ymd,ymd,8);
            memcpy(f_hour,hour,2);
            memcpy(f_min,min,2);
            memcpy(f_sec,zsec,10);
            f_live = 0;
        }
    }
}

关键点在于北京时间比utc时间晚8个小时,也就是8*60*60=28800s,所以如果用utc时间算北京时间的话还需要加上28800s这个差值,总体来说,都是用s换算成年月日时分秒的。

转载于:https://my.oschina.net/u/2252538/blog/1550241

### 关于Peking_data.mat数据文件的信息及其处理 #### 数据集概述 ADHD-200样本提供了丰富的静止状态fMRI和解剖学数据,这些数据来源于多个独立成像站点。具体而言,在该数据库中包含了来自不同年龄段参与者的脑部影像资料以及详细的伴随表型信息,如诊断情况、症状严重程度评分等[^1]。 对于特定提到的`Peking_data.mat`文件,这属于ADHD-200项目的一部分,通常存储有经过预处理后的功能性磁共振图像(fMRI)数据以及其他辅助信息。这类`.mat`格式的数据文件是由MATLAB软件所使用的二进制文件形式来保存矩阵变量和其他复杂结构化数据对象。 #### 获取与加载数据 为了访问并操作此类型的MAT文件中的内容,可以采用如下Python代码片段作为示范: ```python import scipy.io as sio # 加载 .mat 文件 data = sio.loadmat('path_to_Peking_data/Peking_data.mat') # 查看字典键名以了解其内部结构 print(data.keys()) ``` 上述脚本利用SciPy库实现了对MAT文件的有效读取,并将其转换为易于分析的形式。通过打印出`keys()`可以获得关于当前数据集中存在的各个字段名称的知识,从而为进一步探索提供方向指引。 #### 处理方法建议 针对此类神经影像数据集的一般性处理流程可能涉及以下几个方面的工作: - **质量控制**:执行必要的质控措施确保原始扫描的质量满足后续研究需求; - **标准化变换**:将个体大脑映射到标准空间以便跨被试比较; - **特征提取**:计算感兴趣区域内的活动模式或其他统计量度; - **数据分析**:应用机器学习算法挖掘潜在规律或差异点; 值得注意的是,在实际工作中应当依据具体的科研目标调整相应的技术路线。同时也要注意遵循伦理准则及法律法规的要求妥善保管个人信息安全。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值