function [vUsedList] = pmc_SelectStationsInOperation(vList, fDatenum);
% function [vUsedList] = pmc_SelectStationsInOperation(vList, fDatenum)
% ---------------------------------------------------------------------
% Selects all stations which are in operation at a given data.
%
% Input parameters:
%   vList           List of stations (from import_sc)
%   fDatenum        Date (and Time) in Matlab datenum-format
%
% Output parameters:
%   vUsedList       List of stations (which are in operation at fDatenum)
%
% Copyright (C) 2005 by Danijel Schorlemmer & Jochen Woessner
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the
% Free Software Foundation, Inc.,
% 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

vUsedList = [];
for nCnt = 1:length(vList)
  rStation = vList(nCnt);
  % Select stations in operation at fDatenum
  if station_in_operation(rStation, fDatenum)
    % Apply additional selection criteria
    if station_be_used(rStation)
      vUsedList = [vUsedList; rStation];
    end;
  end;
end;

% Helper functions

function [bInOnTime] = station_in_operation(rStation, fDatenum);

bInOnTime = 0;
for nCnt = 1:length(rStation.mOnTime(:,1))
  vOnTime = rStation.mOnTime(nCnt,:);
  if (fDatenum >= vOnTime(1)) & (fDatenum <= vOnTime(2))
    bInOnTime = 1;
  end;
end;

% ---

function [bUsed] = station_be_used(rStation)

bUsed = 1;

% Personal communication with Egill Hauksson (SMTC of AZ not in use)
if strcmp(rStation.sName, 'SMTC')
  bUsed = 0;
end;
