matlab版本GPS程序 to Java之----------JuliaDays

本项目将开源的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);

	}

}

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值