function full_time = fromepoch(second)
% @(#)fromepoch.m	1.1 98/03/05
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [YY MM DD hh mm ss ] = fromepoch(second )
%
%   Function to convert time in seconds from the epoch [1970 01 01] to 
%   the form YYMMDDHHMMSS
%
%   Parameters:  sec = number of seconds from epoch [1970 01 01].
%                [YY,MM,DD,hh,mm,ss]: returned matrix.
%
%   Denot Vincent Eiscat Group.1994
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  secs=second;
  seconds_in_year = 31536000;
  years = 1;
  while ( secs > seconds_in_year )
        if ( rem(1969+years,4) == 0 )
           seconds_in_year = 31622400;
        else
           seconds_in_year = 31536000;
        end
        secs = secs - seconds_in_year;
        years = years + 1;
  end
  years = 1969 + years;
        
%  substract_secs = 0;
%  for iyear = 1:(years-1970)
%      if ( rem(1969+iyear,4) == 0 )
%           substract_secs = substract_secs + 31622400;
%      else
%           substract_secs = substract_secs + 31536000;
%      end
%  end
%  sec = second - substract_secs;

sec = secs;
% Define the number of days each month, depending on if it is leap year or not.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  day_per_month = [0 31 28 31 30 31 30 31 31 30 31 30 31];
  if rem(years,4) == 0
     day_per_month(3)=29;      % works up to 2100 !
  end  
  cum_days = cumsum( day_per_month );

% Re-reference the time information.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  minutes = floor( sec/60.0 );
  houres = floor( minutes/60.0 );
  days = floor( houres/24.0 ) + 1;
  YYY = rem( years, 100 );
  MMM = min(find( cum_days > days )) - 1;
  DDD = days - cum_days( MMM );
  hhh = houres - (days-1)*24;
  mmm = minutes - hhh*60 - (days-1)*24*60;
  sss = sec - mmm*60 - hhh*60*60 - (days-1)*24*60*60;

full_time =[YYY MMM DDD hhh mmm sss];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

