source: Roms_tools/air_sea/greg2.m @ 2

Last change on this file since 2 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 1.5 KB
Line 
1  function [gtime]=greg2(yd,yr)
2% GREG2: converts decimal yearday to standard Gregorian time.
3% [gtime]=GREG2(yd,yr) converts decimal yearday to corresponding
4% Gregorian calendar dates.  In this convention, Julian day 2440000
5% begins at 0000 UT May 23 1968.
6%
7%  INPUT:   yd - decimal yearday (e.g., 0000 UT Jan 1 is 0.0)
8%           yr - year (e.g., 1995)
9%
10%  OUTPUT:  gtime is a six component Gregorian time vector
11%                gtime=[year mo da hr mi sec]
12%           
13%     Example: [1995 01 01 12 00 00] = greg2(0.5, 1995)
14
15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16% 3/10/97: version 1.0
17% 4/7/99: version 1.2 (simplified by AA)
18% 8/5/99: version 2.0
19%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21js = julianmd(yr,01,01,00);
22julian = js + yd;
23julian=julian+5.e-9;  % kludge to prevent roundoff error on seconds
24
25%      if you want Julian Days to start at noon...
26%      h=rem(julian,1)*24+12;
27%      i=(h >= 24);
28%      julian(i)=julian(i)+1;
29%      h(i)=h(i)-24;  Otherwise,....
30
31secs=rem(julian,1)*24*3600;
32
33j = floor(julian) - 1721119;
34in = 4*j -1;
35y = floor(in/146097);
36j = in - 146097*y;
37in = floor(j/4);
38in = 4*in +3;
39j = floor(in/1461);
40d = floor(((in - 1461*j) +4)/4);
41in = 5*d -3;
42m = floor(in/153);
43d = floor(((in - 153*m) +5)/5);
44y = y*100 +j;
45mo=m-9;
46yr=y+1;
47i=(m<10);
48mo(i)=m(i)+3;
49yr(i)=y(i);
50[hour,min,sec]=s2hms(secs);
51gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];
52
53
Note: See TracBrowser for help on using the repository browser.