NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/gregorian_string.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function gtime_str=gregorian_string(julian)
2 %GREGORIAN  Converts Julian day numbers to corresponding
3 %       Gregorian calendar dates.  Although formally,
4 %       Julian days start and end at noon, here Julian days
5 %       start and end at midnight for simplicity.
6 %     
7 %       In this convention, Julian day 2440000 begins at
8 %       0000 hours, May 23, 1968.
9 %
10 %     Usage: [gtime_string]=gregorian(julian)
11 %
12 %        julian... input decimal Julian day number
13 %
14 %        gtime is a string of the form 'DD MMM YYYY'
15 %               
16 %          i.e.   gtime_str= '01 JAN 1992'
17 %
18 % THIS IS RICH SIGNELL'S ROUTINE GREGORIAN, MODIFIED BY B. BLANTON
19 % TO OUTPUT A STRING DATE IN CELLSTR FORMAT, ACCEPTS VECTOR INPUT
20  
21 %        yr........ year (e.g., 1979)
22 %        mo........ month (1-12)
23 %        d........ corresponding Gregorian day (1-31)
24 %        h........ decimal hours
25 %
26       julian=julian+5.e-9;    % kludge to prevent roundoff error on seconds
27
28 %      if you want Julian Days to start at noon...
29 %      h=rem(julian,1)*24+12;
30 %      i=(h >= 24);
31 %      julian(i)=julian(i)+1;
32 %      h(i)=h(i)-24;
33
34       secs=rem(julian,1)*24*3600;
35
36       j = floor(julian) - 1721119;
37       in = 4*j -1;
38       y = floor(in/146097);
39       j = in - 146097*y;
40       in = floor(j/4);
41       in = 4*in +3;
42       j = floor(in/1461);
43       d = floor(((in - 1461*j) +4)/4);
44       in = 5*d -3;
45       m = floor(in/153);
46       d = floor(((in - 153*m) +5)/5);
47       y = y*100 +j;
48       mo=m-9;
49       yr=y+1;
50       i=(m<10);
51       mo(i)=m(i)+3;
52       yr(i)=y(i);
53       [hour,min,sec]=s2hms(secs);
54      
55       yr=yr(:);
56       mo=mo(:);
57       d=d(:);
58       hour=hour(:);
59       min=min(:);
60       sec=sec(:);
61      
62       months=str2mat('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
63      
64       for i=1:length(yr)
65          if d(i)<10
66             gtime_str(i)={['0' int2str(d(i)) ' ' months(mo(i),:) ' ' int2str(yr(i)) ' H=' int2str(hour(i))]};
67          else
68             gtime_str(i)={[int2str(d(i)) ' ' months(mo(i),:) ' ' int2str(yr(i)) ' H=' int2str(hour(i))]};
69          end
70       end
71    
72      
Note: See TracBrowser for help on using the browser.