本项目将开源的matlab的GPS程序转成java版本。matlab版本非原创,所有著作权归原作者所有。
matlab版本:
function jDays = JulianDay(utcTime)
% jDays = JulianDay(utcTime);
%
% input: utcTime [mx6] matrix [year,month,day,hours,minutes,seconds]
%
% output: totalDays in Julian Days [mx1] vector (real number of days)
%
% Valid input range: 1900 < year < 2100
%Algorithm from Meeus, (1991) Astronomical Algorithms,
%see http://www.geoastro.de/elevaz/basics/meeus.htm for online summary
% valid range 1900/3/1 to 2100/2/28
% but we limit inputs to 1901 through 2099, because it's simpler
%Author: Frank van Diggelen
%Open Source code for processing Android GNSS Measurements
% check inputs
if size(utcTime,2)~=6
error('utcTime must have 6 columns')
end
y = utcTime(:,1);
m = utcTime(:,2);
d = utcTime(:,3);
h = utcTime(:,4) + utcTime(:,5)/60 + utcTime(:,6)/3600;
%check that date is in valid range
if ( any(y<1901) || any (y>2099) )
error('utcTime(:,1) not in allowed range: 1900 < year < 2100')
end
i2 = m<=2; %index into months <=2
m(i2) = m(i2)+12;
y(i2) = y(i2)-1;
jDays = floor(365.25*y) + floor(30.6001*(m+1)) - 15 + 1720996.5 + d + h/24;
end %end of function JulianDay
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2016 Google Inc.
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
自己的java版本:
public class Julia_day{
public static double compute_Julia_day(String utcTime){
//input: utcTime [mx6] matrix [year,month,day,hours,minutes,seconds]
//output: totalDays in Julian Days [mx1] vector (real number of days)
//Valid input range: 1900 < year < 2100
//valid range 1900/3/1 to 2100/2/28
//but we limit inputs to 1901 through 2099, because it's simpler
//Algorithm from Meeus, (1991) Astronomical Algorithms,
//see http://www.geoastro.de/elevaz/basics/meeus.htm for online summary
//Author: Heng.Chen
//Open Source code for processing Android GNSS Measurements
//attention:we use ','to split utctime example 2018,10,03,20,11,25
double year,month,days,hours,minutes,seconds;
//int word_lenth=a.lenth;
int i2;
double jdays=0;
String [] utctime_split;
//check inputs
//if (word_lenth!=19)
//{
// System.out.println("utcTime must have 6 columns");
//}
utctime_split=utcTime.split(",");
year=Double.parseDouble(utctime_split[0]);
month=Double.parseDouble(utctime_split[1]);
days=Double.parseDouble(utctime_split[2]);
hours=Double.parseDouble(utctime_split[3]);
minutes=Double.parseDouble(utctime_split[4]);
seconds=Double.parseDouble(utctime_split[5]);
hours=hours+minutes/60.0+seconds/3600.0;
if(year<1901.0||year>2099)
{
System.out.println("year is not in allowed range from 1900 to 2100");
}
if(month<=2.0)
{
month=month+12;
year=year-1;
}
jdays = 365.25*year + 30.6001*(month+1) - 15 + 1720996.5 + days + hours/24;
return jdays;
}
public static void main(String [] args){
System.out.println("Hello world");
String utctime="2018,10,03,20,11,25";
double jdays= compute_Julia_day(utctime);
String result=String.valueOf(jdays);
System.out.println(result);
}
}