


Convert Modified Julian dates to Gregorian dates. [year,month,day,hour,minu,sec,dayweek,dategreg] = julian2greg(MJD) DESCRIPTION: Convert Modified Julian date to Gregorian dates. INPUT: MJD = list of Modified Julian Dates OUTPUT: year = Gregorian year month = Gregorian month day = Gregorian day hour = Gregorian hour minu = Gregorian minute sec = Gregorian second dayweek = day of the week for the returned date dategreg = vector of Gregorian dates in the format (D, M, Y, H, M S) EXAMPLE USAGE [year,month,day,hour,minu,sec,dayweek,dategreg] = mjulian2greg(MJD) Author(s): Geoff Cowles (University of Massachusetts Dartmouth) Karen Amoudry (National Oceanography Centre, Liverpool) Revision history: 2013-09-03 (KJA) Major updates to original version (kept intact in comments at the bottom of this version). The original version frequently generated incorrect times due to rounding errors, with time vectors containing 'impossible' times such as [2008,2,1,0,59,60], or incorrectly rounded times such as [2008,2,1,2,0,1]. The 'impossible' times occasionally caused crashes when used in FVCOM input files. This updated version uses Matlab's inhouse date manipulation functions by accounting for the offset between the origins of Modified Julian Time (1858 11 17 00:00:00) and Matlab datenum time (0000 01 01 00:00:00). ==========================================================================


0001 function [year,month,day,hour,minu,sec,dayweek,dategreg] = mjulian2greg(MJD) 0002 % Convert Modified Julian dates to Gregorian dates. 0003 % 0004 % [year,month,day,hour,minu,sec,dayweek,dategreg] = julian2greg(MJD) 0005 % 0006 % DESCRIPTION: 0007 % Convert Modified Julian date to Gregorian dates. 0008 % 0009 % INPUT: 0010 % MJD = list of Modified Julian Dates 0011 % 0012 % OUTPUT: 0013 % year = Gregorian year 0014 % month = Gregorian month 0015 % day = Gregorian day 0016 % hour = Gregorian hour 0017 % minu = Gregorian minute 0018 % sec = Gregorian second 0019 % dayweek = day of the week for the returned date 0020 % dategreg = vector of Gregorian dates in the format (D, M, Y, H, M S) 0021 % 0022 % EXAMPLE USAGE 0023 % [year,month,day,hour,minu,sec,dayweek,dategreg] = mjulian2greg(MJD) 0024 % 0025 % Author(s): 0026 % Geoff Cowles (University of Massachusetts Dartmouth) 0027 % Karen Amoudry (National Oceanography Centre, Liverpool) 0028 % 0029 % Revision history: 0030 % 2013-09-03 (KJA) Major updates to original version (kept intact in 0031 % comments at the bottom of this version). The original version 0032 % frequently generated incorrect times due to rounding errors, with time 0033 % vectors containing 'impossible' times such as [2008,2,1,0,59,60], or 0034 % incorrectly rounded times such as [2008,2,1,2,0,1]. The 'impossible' 0035 % times occasionally caused crashes when used in FVCOM input files. This 0036 % updated version uses Matlab's inhouse date manipulation functions by 0037 % accounting for the offset between the origins of Modified Julian Time 0038 % (1858 11 17 00:00:00) and Matlab datenum time (0000 01 01 00:00:00). 0039 % 0040 %========================================================================== 0041 0042 global ftbverbose 0043 report = false; 0044 if(ftbverbose); report = true; end 0045 subname = 'mjulian2greg'; 0046 if(report); fprintf('\n'); end 0047 if(report); fprintf(['begin : ' subname '\n']); end 0048 0049 % Calculate the offset between the origins of Modified Julian Time and 0050 % Matlab datenum time. 0051 MJD_base=datenum(1858,11,17,0,0,0); 0052 0053 % Convert from MJD to Gregorian time 0054 [year,month,day,hour,minu,sec] = datevec(MJD+MJD_base); 0055 0056 % Calculate the day of the week 0057 [~,dayweek] = weekday(MJD+MJD_base,'long'); 0058 0059 % Convert to dategreg format (D, M, Y, H, M S) 0060 dategreg = [day, month, year, hour, minu, sec]; 0061 0062 if(report); fprintf(['end : ' subname '\n']); end; 0063 0064 %% Original version of mjulian2greg.m 0065 %This function converts Modified Julian dates to Gregorian dates. 0066 0067 %[year,month,day,hour,minu,sec,dayweek,dategreg] = julian2greg(MJD+2400000.5);