function tides(theYears, dataDirectory, plotDirectory, SiteA, siteB) % % tides(theYears, dataDirectory, plotDirectory, SiteA, siteB) % % Function which goes through the MBLT data files and performs the tidal % analysis on current/pressure data. Individual deployment results are % created for theYears (cXXXX.txt or pXXXX.txt) and comparison tables of % the major tides are created for each site/depth (SITE_TIDE). %Soupy Alexander, 10/31/03 %Set up the empties - Pressure pS2 = []; pM2 = []; pN2 = []; pO1 = []; pK1 = []; %Empties - PCM S2_5 = []; M2_5 = []; N2_5 = []; O1_5 = []; K1_5 = []; S2_10 = []; M2_10 = []; N2_10 = []; O1_10 = []; K1_10 = []; S2_1 = []; M2_1 = []; N2_1 = []; O1_1 = []; K1_1 = []; %Empties - ADCP S2_a5 = []; M2_a5 = []; N2_a5 = []; O1_a5 = []; K1_a5 = []; S2_a15 = []; M2_a15 = []; N2_a15 = []; O1_a15 = []; K1_a15 = []; S2_a1 = []; M2_a1 = []; N2_a1 = []; O1_a1 = []; K1_a1 = []; %Load in the site A data for indexFile = 1:length(siteA) fileVars = siteA(indexFile).theVars; if strmatch('P_4023', fileVars) theFile = netcdf(fullfile(dataDirectory, siteA(indexFile).fileList), 'nowrite'); fileTime = singlejd(theFile{'time'}(:), theFile{'time2'}(:)); theData = theFile{'P_4023'}(:); bads = find(theData > 1e5); theData(bads) = NaN; fileTimeI = min(fileTime):1/24:max(fileTime); fileDataI = smart_interp(fileTime, theData, fileTimeI, 4); theLat = theFile{'lat'}(:); fileName = siteA(indexFile).fileList; moorNumber = fileName(1:4); startGreg = gregorian(min(fileTimeI)); endGreg = gregorian(max(fileTimeI)); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileDataI, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['p' moorNumber '.txt'])); else [name, freq, tidecon, xout] = t_tide(fileDataI, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) pS2 = [pS2; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) pM2 = [pM2; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) pN2 = [pN2; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) pO1 = [pO1; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) pK1 = [pK1; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; end elseif strmatch('u_1205', fileVars) theFile = netcdf(fullfile(dataDirectory, siteA(indexFile).fileList), 'nowrite'); fileDepth = theFile{'depth'}(:); fileTime = singlejd(theFile{'time'}(:), theFile{'time2'}(:)); fileLat = theFile{'lat'}(:); fileU = theFile{'u_1205'}(:); fileV = theFile{'v_1206'}(:); bads = find(fileU > 1e5); fileU(bads) = NaN; bads = find(fileV > 1e5); fileV(bads) = NaN; fileCurr = fileU + i*fileV; fileName = siteA(indexFile).fileList; moorNumber = fileName(1:4); startGreg = gregorian(min(fileTime)); endGreg = gregorian(max(fileTime)); if length(fileDepth) == 1 if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurr, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurr, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end if fileDepth < 10 inTide = strmatch('S2', name); if ~isempty(inTide) S2_5 = [S2_5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_5 = [M2_5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_5 = [N2_5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_5 = [O1_5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_5 = [K1_5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end elseif fileDepth > 10 & fileDepth < 25 inTide = strmatch('S2', name); if ~isempty(inTide) S2_10 = [S2_10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_10 = [M2_10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_10 = [N2_10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_10 = [O1_10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_10 = [K1_10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end elseif fileDepth > 25 inTide = strmatch('S2', name); if ~isempty(inTide) S2_1 = [S2_1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_1 = [M2_1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_1 = [N2_1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_1 = [O1_1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_1 = [K1_1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end end else surfDepth = value2index(fileDepth, 5); fileCurrHit = fileCurr(:,surfDepth); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '_5.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) S2_a5 = [S2_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_a5 = [M2_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_a5 = [N2_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_a5 = [O1_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_a5 = [K1_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end midDepth = value2index(fileDepth, 15); fileCurrHit = fileCurr(:,surfDepth); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '_15.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) S2_a15 = [S2_a15; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_a15 = [M2_a15; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_a15 = [N2_a15; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_a15 = [O1_a15; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_a15 = [K1_a15; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end deepDepth = find(fileDepth == max(fileDepth)); fileCurrHit = fileCurr(:,surfDepth); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '_1.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) S2_a1 = [S2_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_a1 = [M2_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_a1 = [N2_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_a1 = [O1_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_a1 = [K1_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end end end end tideList = {'S2'; 'M2'; 'N2'; 'O1'; 'K1'}; for indexTide = 1:length(tideList) eval(['targTide = p' tideList{indexTide} ';']); [junk, I] = unique(targTide(:,1)); targTide = targTide(I,:); fID = fopen(fullfile(plotDirectory, ['a_' lower(tideList{indexTide}) '.txt']), 'w'); fprintf(fID, ['Site A, ' upper(tideList{indexTide}) ' Tidal Analysis of Pressure\n\n']); fprintf(fID, ['Mooring Number\tStart Time\tEnd Time\tAmplitude\tAmp. Error\tPhase\tPhaseError\n']); for index = 1:length(targTide) fprintf(fID, [num2str(targTide(index,1), '%.0f') '\t' ... num2str(julian2datenum(targTide(index,2)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(julian2datenum(targTide(index,3)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(targTide(index,4), '%.2f') '\t' ... num2str(targTide(index,5), '%.2f') '\t' ... num2str(targTide(index,6), '%.2f') '\t' ... num2str(targTide(index,7), '%.2f') '\n']); end fclose(fID); for indexDepth = [5 10 1] eval(['targTide = ' tideList{indexTide} '_' num2str(indexDepth) ';']); [junk, I] = unique(targTide(:,1)); targTide = targTide(I,:); fID = fopen(fullfile(plotDirectory, ['a_' lower(tideList{indexTide}) '_' ... num2str(indexDepth) '.txt']), 'w'); fprintf(fID, ['Site A, ' upper(tideList{indexTide}) ' Tidal Analysis of Current, ' ... num2str(indexDepth)]); if indexDepth == 5 fprintf(fID, ' mbs\n\n'); else fprintf(fID, ' mab\n\n'); end fprintf(fID, ['Mooring Number\tStart Time\tEnd Time\tMaj. Axis\tMaj. Error\tMin. Axis\tMin. Error\tInclination\tInc. Error\tPhase\tPhase Error\n']); for index = 1:length(targTide) fprintf(fID, [num2str(targTide(index,1), '%.0f') '\t' ... num2str(julian2datenum(targTide(index,2)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(julian2datenum(targTide(index,3)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(targTide(index,4), '%.2f') '\t' ... num2str(targTide(index,5), '%.2f') '\t' ... num2str(targTide(index,6), '%.2f') '\t' ... num2str(targTide(index,7), '%.2f') '\t' ... num2str(targTide(index,8), '%.2f') '\t' ... num2str(targTide(index,9), '%.2f') '\t' ... num2str(targTide(index,10), '%.2f') '\t' ... num2str(targTide(index,11), '%.2f') '\n']); end fclose(fID); end for indexDepth = [5 15 1] eval(['targTide = ' tideList{indexTide} '_a' num2str(indexDepth) ';']); [junk, I] = unique(targTide(:,1)); targTide = targTide(I,:); fID = fopen(fullfile(plotDirectory, ['a_' lower(tideList{indexTide}) '_a' ... num2str(indexDepth) '.txt']), 'w'); if indexDepth == 5 | indexDepth == 15 fprintf(fID, ['Site A, ' upper(tideList{indexTide}) ' Tidal Analysis of Current, ' ... num2str(indexDepth)]); fprintf(fID, ' mbs\n\n'); else fprintf(fID, ['Site A, ' upper(tideList{indexTide}) ' Tidal Analysis of Current, ' ... 'Deepest Bin Available\n\n']); end fprintf(fID, ['Mooring Number\tStart Time\tEnd Time\tMaj. Axis\tMaj. Error\tMin. Axis\tMin. Error\tInclination\tInc. Error\tPhase\tPhase Error\n']); for index = 1:length(targTide) fprintf(fID, [num2str(targTide(index,1), '%.0f') '\t' ... num2str(julian2datenum(targTide(index,2)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(julian2datenum(targTide(index,3)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(targTide(index,4), '%.2f') '\t' ... num2str(targTide(index,5), '%.2f') '\t' ... num2str(targTide(index,6), '%.2f') '\t' ... num2str(targTide(index,7), '%.2f') '\t' ... num2str(targTide(index,8), '%.2f') '\t' ... num2str(targTide(index,9), '%.2f') '\t' ... num2str(targTide(index,10), '%.2f') '\t' ... num2str(targTide(index,11), '%.2f') '\n']); end fclose(fID); end end %Set up the empties - Pressure pS2 = []; pM2 = []; pN2 = []; pO1 = []; pK1 = []; %Empties - ADCP S2_a5 = []; M2_a5 = []; N2_a5 = []; O1_a5 = []; K1_a5 = []; S2_a10 = []; M2_a10 = []; N2_a10 = []; O1_a10 = []; K1_a10 = []; S2_a1 = []; M2_a1 = []; N2_a1 = []; O1_a1 = []; K1_a1 = []; %Load in the site B data for indexFile = 1:length(siteB) fileVars = siteB(indexFile).theVars; if strmatch('P_4023', fileVars) theFile = netcdf(fullfile(dataDirectory, siteB(indexFile).fileList), 'nowrite'); fileTime = singlejd(theFile{'time'}(:), theFile{'time2'}(:)); theData = theFile{'P_4023'}(:); bads = find(theData > 1e5); theData(bads) = NaN; if isempty(theData) continue end fileTimeI = min(fileTime):1/24:max(fileTime); fileDataI = smart_interp(fileTime, theData, fileTimeI, 4); theLat = theFile{'lat'}(:); fileName = siteB(indexFile).fileList; moorNumber = fileName(1:4); startGreg = gregorian(min(fileTimeI)); endGreg = gregorian(max(fileTimeI)); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileDataI, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['p' moorNumber '.txt'])); else [name, freq, tidecon, xout] = t_tide(fileDataI, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) pS2 = [pS2; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) pM2 = [pM2; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) pN2 = [pN2; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) pO1 = [pO1; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) pK1 = [pK1; [str2num(moorNumber) min(fileTimeI) max(fileTimeI) tidecon(inTide,:)]]; end elseif strmatch('u_1205', fileVars) theFile = netcdf(fullfile(dataDirectory, siteB(indexFile).fileList), 'nowrite'); fileDepth = theFile{'depth'}(:); fileTime = singlejd(theFile{'time'}(:), theFile{'time2'}(:)); fileLat = theFile{'lat'}(:); fileU = theFile{'u_1205'}(:); fileV = theFile{'v_1206'}(:); bads = find(fileU > 1e5); fileU(bads) = NaN; bads = find(fileV > 1e5); fileV(bads) = NaN; fileCurr = fileU + i*fileV; fileName = siteB(indexFile).fileList; moorNumber = fileName(1:4); startGreg = gregorian(min(fileTime)); endGreg = gregorian(max(fileTime)); surfDepth = value2index(fileDepth, 5); fileCurrHit = fileCurr(:,surfDepth); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '_5.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) S2_a5 = [S2_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_a5 = [M2_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_a5 = [N2_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_a5 = [O1_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_a5 = [K1_a5; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end midDepth = value2index(fileDepth, 10); fileCurrHit = fileCurr(:,surfDepth); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '_10.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) S2_a10 = [S2_a10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_a10 = [M2_a10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_a10 = [N2_a10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_a10 = [O1_a10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_a10 = [K1_a10; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end deepDepth = find(fileDepth == max(fileDepth)); fileCurrHit = fileCurr(:,surfDepth); if any(ismember(theYears, [startGreg(1) endGreg(1)])) [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', ... fullfile(plotDirectory, ['c' moorNumber '_1.txt'])); else [name, freq, tidecon, xout] = t_tide(fileCurrHit, 'interval', 1, 'start time', ... gregorian(min(fileTimeI)), 'latitude', theLat, 'output', 'none'); end inTide = strmatch('S2', name); if ~isempty(inTide) S2_a1 = [S2_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('M2', name); if ~isempty(inTide) M2_a1 = [M2_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('N2', name); end if ~isempty(inTide) N2_a1 = [N2_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; inTide = strmatch('O1', name); end if ~isempty(inTide) O1_a1 = [O1_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end inTide = strmatch('K1', name); if ~isempty(inTide) K1_a1 = [K1_a1; ... [str2num(moorNumber) min(fileTime) max(fileTime) tidecon(inTide,:)]]; end end end tideList = {'S2'; 'M2'; 'N2'; 'O1'; 'K1'}; for indexTide = 1:length(tideList) eval(['targTide = p' tideList{indexTide} ';']); [junk, I] = unique(targTide(:,1)); targTide = targTide(I,:); fID = fopen(fullfile(plotDirectory, ['b_' lower(tideList{indexTide}) '.txt']), 'w'); fprintf(fID, ['Site B, ' upper(tideList{indexTide}) ' Tidal Analysis of Pressure\n\n']); fprintf(fID, ['Mooring Number\tStart Time\tEnd Time\tAmplitude\tAmp. Error\tPhase\tPhaseError\n']); for index = 1:size(targTide,1) fprintf(fID, [num2str(targTide(index,1), '%.0f') '\t' ... num2str(julian2datenum(targTide(index,2)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(julian2datenum(targTide(index,3)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(targTide(index,4), '%.2f') '\t' ... num2str(targTide(index,5), '%.2f') '\t' ... num2str(targTide(index,6), '%.2f') '\t' ... num2str(targTide(index,7), '%.2f') '\n']); end fclose(fID); for indexDepth = [5 10 1] eval(['targTide = ' tideList{indexTide} '_a' num2str(indexDepth) ';']); [junk, I] = unique(targTide(:,1)); targTide = targTide(I,:); fID = fopen(fullfile(plotDirectory, ['b_' lower(tideList{indexTide}) '_a' ... num2str(indexDepth) '.txt']), 'w'); if indexDepth == 5 | indexDepth == 10 fprintf(fID, ['Site B, ' upper(tideList{indexTide}) ' Tidal Analysis of Current, ' ... num2str(indexDepth)]); fprintf(fID, ' mbs\n\n'); else fprintf(fID, ['Site B, ' upper(tideList{indexTide}) ' Tidal Analysis of Current, ' ... 'Deepest Bin Available\n\n']); end fprintf(fID, ['Mooring Number\tStart Time\tEnd Time\tMaj. Axis\tMaj. Error\tMin. Axis\tMin. Error\tInclination\tInc. Error\tPhase\tPhase Error\n']); for index = 1:length(targTide) fprintf(fID, [num2str(targTide(index,1), '%.0f') '\t' ... num2str(julian2datenum(targTide(index,2)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(julian2datenum(targTide(index,3)) - datenum('30-Dec-1899'), '%.6f') '\t' ... num2str(targTide(index,4), '%.2f') '\t' ... num2str(targTide(index,5), '%.2f') '\t' ... num2str(targTide(index,6), '%.2f') '\t' ... num2str(targTide(index,7), '%.2f') '\t' ... num2str(targTide(index,8), '%.2f') '\t' ... num2str(targTide(index,9), '%.2f') '\t' ... num2str(targTide(index,10), '%.2f') '\t' ... num2str(targTide(index,11), '%.2f') '\n']); end fclose(fID); end end