%NY_Tides.m
%
%Program to do a tidal analysis on the available pressure data from the NY
%Bight.  Requires the input of a station, and runs Rich Signell's "t_tide.m"
%program.
%
%Soupy Alexander, 03/07/02

%The tidal information is saved to a file; this file was modified for relevent
%information and appearance in wordpad

%Select a station to use.
station = input('Station to analyze? ');

%Pull the proper file for analysis - using hourly averaged data (naturally)
if station == 'A';
    file_name = netcdf('5952tcp-a1h.nc','nowrite');
elseif station == 'B';
    file_name = netcdf('5972p-a1h.nc','nowrite');
elseif station == 'C';
    file_name = netcdf('5992tcp-a1h.nc','nowrite');
elseif station == 'D';
    file_name = netcdf('6012tcp-a1h.nc','nowrite');
elseif station == 'E';
    file_name = netcdf('6032tcp-a1h.nc','nowrite');
elseif station == 'F';
    file_name = netcdf('6042pt-a1h.nc','nowrite');
else error('Not a valid station.  Remember to use a capital letter in single quotes');
end

%Pull out the data of interest (time, pressure, latitude)
t = file_name{'time'}(:);
t2 = file_name{'time2'}(:);

%Combine the two time vectors into one julian day vector
time = singleJD(t,t2);

%Station F is in dbar, needs to be converted to mbar
%Station B has bad data gaps, need to select out particular data
if station == 'F'
    pres_raw = file_name{'P_1'}(:);
    pres = 100.*pres_raw;
elseif station == 'B';
    pres = file_name{'P_4023'}(:);
    start_index = value2Index(time,julian([2000 1 24 00 00 00]));
    end_index = value2Index(time,julian([2000 4 16 00 00 00]));
    time = time(start_index:end_index);
    pres = pres(start_index:end_index);
else
pres = file_name{'P_4023'}(:);
end

pres = ridfill_nan(pres);

lat = file_name{'lat'}(:);


%Determine the start time
greg_start = gregorian(min(time));
start_time = [greg_start(1),greg_start(2),greg_start(3),greg_start(4),...
        greg_start(5),greg_start(6)];

%Set up the output file name
out_name = ['tide' station];

[name,freq,tidecon,xout] = t_tide(pres,'start time',start_time,...
    'latitude',lat,'output',out_name);
