📄 xgpstime.m
字号:
% xgpstime.m
% Scope: This MATLAB program performs the following GPS time related
% transformation:
% 1) from (year, month, day) to (GPS week, GPS roll number, day of
% week)
% 2) from (GPS week, day of week, GPS roll number) to (day of week,
% day, month, year)
% 3) from (day of week, hour, minute, second) to (time of week)
% 4) from (time of week) to (day of week, hour, minute, second)
% Usage: xgpstime
% Inputs: - name of the output file if selected (the default is the screen)
% 1) For the (year, month, day) to (GPS week, GPS roll number, day of
% week):
% - year (1980 and greater)
% - month (1 to 12)
% - day (1 to 31)
% 2) For the (GPS week, day of week, GPS roll number) to
% (day of week, day, month, year):
% - GPS week (0 to 1023)
% - day of week (0 to 6)
% - GPS roll number (0 to ...)
% 3) For the (day of week, hour, minute, second) to (time of week):
% - day of week (0 to 6)
% - hour (0 to 23)
% - minute (0 to 59)
% - second (0 to 60)
% 4) For the (time of week) to (day of week, hour, minute, second):
% - time of week (0 to 604800)
% Outputs: - input/output data stored into the specified output file or
% displayed on screen
% Last update: 09/05/00
% Copyright (C) 1999-00 by LL Consulting. All Rights Reserved.
clear
trefgps = datenum(1980,1,6); % gps reference day
yes = 'y';
answer = yes;
disp(' ');
answer1 = input('Do you want to save the results? (y/n)[n] --> ','s');
disp(' ');
if (strcmp(answer1,yes) == 1)
f2 = input('Specify the output filename --> ','s');
disp(' ');
else
f2 = 1; % output to the screen
end
while (strcmp(answer,yes) == 1)
disp('Select: ');
disp(' 1 --> (year, month, day) to (GPS week, GPS roll number, day of week)');
disp(' 2 --> (GPS week, day of week, GPS roll number) to ')
disp(' (day of week, day, month, year)');
disp(' 3 --> (day of week, hour, minute, second) to time of week');
disp(' 4 --> time of week to (day of week, hour, minute, second)');
disp(' ');
select = input('Make the selection --> ');
disp(' ');
if (select == 1)
% Transformation from (year, month, day) to (GPS week, GPS roll number)
fprintf(f2,'***************************************************************\n\n');
year = input('Specify the year, e.g. 1999, --> ');
month = input('Specify the month, e.g. 1, --> ');
day = input('Specify the day, e.g. 28, --> ');
tdate = datenum(year,month,day);
gpsweek = mod(floor((tdate-trefgps)/7),1024);
gpsroll = floor(floor((tdate-trefgps)/7)/1024);
dow = (tdate - trefgps) - (gpsroll*1024 + gpsweek)*7;
disp(' ');
if (f2 ~= 1)
fprintf(f2,'year = %4.0f, month = %2.0f, day = %2.0f\n\n', year,month,day);
end
fprintf(f2,'gpsweeek = %4.0f, gps roll number = %3.0f, day of week = %3.0f\n\n',...
gpsweek, gpsroll,dow);
fprintf(f2,'***************************************************************\n\n');
elseif (select == 2)
% Transformation from (GPS week, day of week, GPS roll number) to
% (day of week, day, month, year)
fprintf(f2,'***************************************************************\n\n');
gpsweek = input('Specify the gps week (0 to 1023), e.g. 949, --> ');
dow = input('Specify day of week (0 to 6), e.g. 2, --> ');
gpsroll = input('Specify the gps roll number (0 to ...), e.g. 1, --> ');
temp = trefgps + (gpsweek + 1024*gpsroll)*7 + dow;
date1 = datestr(temp,1);
date2 = datestr(temp,8);
disp(' ');
if (f2 ~= 1)
fprintf(f2,'gpsweeek = %4.0f, day-of-week = %2.0f, gps roll number = %3.0f\n\n',...
gpsweek, dow, gpsroll);
end
fprintf(f2,'date = %s \n\n', [date2 ' ' date1]);
fprintf(f2,'***************************************************************\n\n');
elseif (select == 3)
% Transformation from (day of week, hour, minute, second) to time-of-week
fprintf(f2,'***************************************************************\n\n');
dow = input('Specify day of week (0 to 6), e.g. 2, --> ');
hour = input('Specify hour (0 to 23), e.g. 5, --> ');
min = input('Specify minute (0 to 59), e.g. 34, --> ');
sec = input('Specify second (0 to 60), e.g. 46, --> ');
tow = (dow*24 + hour)*3600 + min*60 + sec;
disp(' ');
if (f2 ~= 1)
fprintf(f2,'day of week = %3.0f, hour = %2.0f, min = %2.0f, sec = %2.0f\n\n',...
dow, hour, min, sec);
end
fprintf(f2,'time of week = %6.0f \n\n', tow);
fprintf(f2,'***************************************************************\n\n');
elseif (select == 4)
% Transformation from time-of-week to (day of week, hour, minute, second)
fprintf(f2,'***************************************************************\n\n');
tow = input('Specify time of week (0 to 604800), e.g. 43200, --> ');
dow = mod(floor(tow/86400),6);
hour = mod(floor(tow/3600),24);
min = mod(floor(tow/60),60);
sec = mod(tow,60);
disp(' ');
if (f2 ~= 1)
fprintf(f2,'time of week = %6.0f \n\n', tow);
end
fprintf(f2,'day of week = %3.0f, hour = %2.0f, min = %2.0f, sec = %2.0f\n\n',...
dow, hour, min, sec);
fprintf(f2,'***************************************************************\n\n');
else
disp('Selection is not in the designated range');
end
% Select another computation, if desired
answer = input('Do you want another computation? (y/n)[n] --> ','s');
disp(' ');
end
disp('End of the program XGPSTIME');
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -