function [times, Pass_Times, depths, Pass_Depths, cs] =  ...
       dinocat(CatalogServer, get_archive, Time, Depth, ranges)

%
% This function passes time and depth information to getfunction
%

% The preceding empty line is important.

if exist(get_archive) == 2
  eval(get_archive)
else
  disp('Metadata not found!')
  return
end

Pass_Times = [];
times = [];
Pass_Depths = [];
depths = [];
cs = [];

BaseTime = Time(1);   % == das basetime
BeginTime = max(Time(1), ranges(4,1));   
EndTime = min(Time(2), ranges(4,2));    

BeginYear = floor(BeginTime);
StartYear = BeginYear;

Constraint = ['time'];
eval(['loaddods(''', CatalogServer, '?', Constraint,''')'])
ntime = length(time);

if ntime ~= Ntime
  disp('Can not resolve TimeRange. Error in archive.m file');
  return
end

if isleap(BeginYear)
  DaysInYear = 366;
else
  DaysInYear = 365;
end

%timestep = abs(diff(Time(2),Time(1))) / (Ntime -1);

for i = 1:ntime
  timetemp(i,1) = BaseTime + time(i,1) / DaysInYear;
  if (timetemp(i,1) >= BeginTime) & (timetemp(i,1) <= EndTime)
    times = [times; timetemp(i,1)];
    Pass_Times = [Pass_Times; i-1];
  end
end 

%Depth in sigma. Depending on bathymetry and elevation, each location has it's own depth value. 
%sigma = [0 -0.01 -0.04 -0.1 -0.2 -0.3 -0.4 -0.5 -0.6 -0.7 -0.8 -0.9 -1];
depthstep = abs(diff(Depth(2),Depth(1))) / (Ndepth -1);
BaseDepth = Depth(1);    % on the sea surface
StartDepth = BaseDepth;  
BeginDepth = max(Depth(1), ranges(3,1));
EndDepth = min(Depth(2), ranges(3,2));

%depthstep = abs(diff(Depth(2),Depth(1))) / (Ndepth - 1);
for j = 1:Ndepth
  depthtemp(j,1) = StartDepth;
  if (depthtemp(j,1) >= BeginDepth) & (depthtemp(j,1) <= EndDepth)
    depths = [depths; depthtemp(j,1)];
    Pass_Depths = [Pass_Depths; j-1];
  end 
  if j < Ndepth
%    StartDepth = StartDepth + sigma(j+1);
    StartDepth = StartDepth + depthstep;
  end
end


  

