%---------------------------------------------------------------------
% templateBPRTimeSeries.m
% General:  pGenerate time series plot of all sensors on BPRs
% Input:    none
% Output:   PNG file showing time series supplots 
% Calls:    getData
% Modify Date/Author:  20100629, R.Jenkyns
%---------------------------------------------------------------------

close all; clear all;
tic  

% Enter start date and end date for desired time series using Oracle
% timestamp data type
startdate='28-Jun-2010 12:00:00 AM';
enddate='28-June-2010 11:59:59 PM';

% Sensor IDs: If you do not know your sensor id
% refer to the Device Listing at http://dmas.uvic.ca/, and select the device to get a list
% of sensors and their ids
    
%      e.g.,  for deviceID 12501
     deviceID=12501; 
     neptune(1).sensorID=4176; % seafloor pressure
     neptune(2).sensorID=4175; % housing temperature
     neptune(3).sensorID=1570; % p-sensor temp

% Retrieve entire time series and basic metadata for each sensor
% NOTES: 
% a) Data will only be returned for NEPTUNE Canada devices and sensors that have
% completed commissioning. 
% b) If your time series is too long, you may experience out of memory errors.  
 [neptune,meta,nd]=getData(neptune,startdate,enddate,deviceID,getEnv); 

% For subsampled data, use additional arguments:
% subsampletype options: 1=Averaged Data, 2=Decimated Data, 3=Min/Max Data
% subsampleperiod options (seconds): 3600 for hourly, 86400 for daily, 604800 for
% weekly
% [neptune,meta]=getData(neptune,startdate,enddate,deviceID,env,subsampletype,subsampleperiod)

% Create a plot of the results if data returned
if ~nd
    figure(1);
    clf;
    plotScalarTimeSeriesGaps2(neptune,meta, length(neptune),1)
    
    % Save as a PNG. Coderunner requires that plots are saved as an image
    % format in order to display on the UI.
    ds=datestr(neptune(1).time(1),30);
     
    % Generate dataproduct filename
    fileroot=[meta.deviceCode,'_',ds];
     
    % export the figure as a PNG
    filename=[fileroot,'.png'];
    print('-dpng','-r300',fileroot)
end
