-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
772 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function aa = adjust_canada_spec(aa) | ||
|
||
aa.efold = aa.ef; | ||
|
||
for ii = 1:size(aa.ef,2); | ||
dum = 0; | ||
nfreq = size(aa.freq,1); | ||
for jj = nfreq:-1:1 | ||
dum = dum + aa.efold(jj,ii).*aa.bw(jj,ii); | ||
if dum == aa.hsb(ii).^2/16 | ||
aa.ef(1:jj,ii) = 0; | ||
break | ||
elseif dum > aa.hsb(ii).^2/16 | ||
aa.ef(1:jj+1,ii) = 0; | ||
break | ||
end | ||
end | ||
|
||
aa.hs(ii) = 4.0*sqrt(sum(aa.ef(:,ii).*aa.bw(:,ii))); | ||
ip = find(aa.ef(:,ii) == max(aa.ef(:,ii))); | ||
|
||
if length(ip) > 1 | ||
if ip(1) == ip(2)-1 | ||
ip = ip(1); | ||
else | ||
ip = ip(2); | ||
end | ||
end | ||
if ip < 12 | ||
ip = 12; | ||
end | ||
|
||
aa.tp(ii) = 1.0/aa.freq(ip,ii); | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
function frf_2_onlns(cdip,ndbc,year,mon) | ||
|
||
if isunix | ||
%cdir = '/mnt/CHL_WIS_1/CDIP/'; | ||
cdir = '/home/thesser1/NODC/'; | ||
else | ||
cdir = 'X:\CDIP\'; | ||
end | ||
if ischar(cdip) | ||
cdipc = cdip; | ||
else | ||
if cdip < 100 | ||
cdipc = ['0',num2str(cdip)]; | ||
else | ||
cdipc = num2str(cdip); | ||
end | ||
end | ||
if ischar(ndbc) | ||
ndbcc = ndbc; | ||
else | ||
ndbcc = num2str(ndbc); | ||
end | ||
if ischar(year) | ||
yearc = year; | ||
else | ||
yearc = num2str(year); | ||
end | ||
mont = ['jan';'feb';'mar';'apr';'may';'jun';'jul';'aug';'sep';'oct'; ... | ||
'nov';'dec']; | ||
if ischar(mon) | ||
monnc = mon; | ||
monn = str2num(mon); | ||
monc = mont(monn,:); | ||
else | ||
if mon < 10 | ||
monnc = ['0',num2str(mon)]; | ||
else | ||
monnc = num2str(mon); | ||
end | ||
monc = mont(mon,:); | ||
end | ||
if isunix | ||
fname = ['waverdr3630_',yearc,'_',monnc,'.spec']; | ||
cdiry = [cdir,fname]; | ||
else | ||
cdiry = [cdir,'spc_',yearc,'\',cdipc,'\',monc,'\01\']; | ||
end | ||
if exist(cdiry,'file') | ||
if isunix | ||
%ndbcd = ['/mnt/CHL_WIS_1/NDBC_CDIP']; | ||
ndbcd = ['/home/thesser1/NDBC/']; | ||
ndbct = [ndbcd,yearc,'/',monc,'/']; | ||
else | ||
ndbcd = ['X:\NDBC_CDIP\']; | ||
ndbct = [ndbcd,yearc,'\',monc,'\']; | ||
end | ||
|
||
|
||
nfile = [ndbct,'n',ndbcc,'_',yearc,'_',monnc,'.onlns']; | ||
if exist(nfile,'file') | ||
return | ||
end | ||
|
||
[aa]= read_frf_spc(cdir,fname); | ||
% if status == 0 | ||
% return | ||
% end | ||
time = num2str(aa.date); | ||
bb1(:,1) = str2num(time(:,1:4)); | ||
bb1(:,2) = str2num(time(:,5:6)); | ||
bb1(:,3) = str2num(time(:,7:8)); | ||
bb1(:,4) = str2num(time(:,9:10)); | ||
bb1(:,5) = str2num(time(:,11:12)); | ||
[latd,latm,lats] = ddeg2dms(aa.lat); | ||
[lond,lonm,lons] = ddeg2dms(aa.lon); | ||
loc = [latd,abs(latm),round(abs(lats)),lond,abs(lonm),round(abs(lons))]; | ||
bb1(:,6:11) = repmat(loc,size(bb1,1),1); | ||
bb1(:,12) = aa.dep; | ||
bb1(:,13:15) = -99.99; | ||
bb1(:,16) = -999.9; | ||
bb1(:,17:18) = -99.99; | ||
bb1(:,19) = -999.9; | ||
|
||
ab.c11 = aa.ef; | ||
ab.a0 = aa.ef./pi; | ||
if any(strcmp('a1',fieldnames(aa))) | ||
ab.a1=aa.a1;ab.a2=aa.a2; | ||
ab.b1 = aa.b1;ab.b2 = aa.b2; | ||
end | ||
ab.df = aa.bw(:,1); | ||
ab.freq = aa.freq(:,1);ab.dep = aa.dep; | ||
bb2 = convert_2_onlns(ab); | ||
bb = horzcat(bb1,bb2); | ||
create_onlns(ndbcc,yearc,monnc,bb,ndbct); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function aa = read_canada_csv(fdir,fname) | ||
|
||
fid = fopen([fdir,fname]); | ||
|
||
data = textscan(fid,'%s%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f', ... | ||
'headerlines',2,'delimiter',','); | ||
|
||
aa.station = data{1}{1}; | ||
for jj = 1:length(data{2}) | ||
date = data{2}{jj}; | ||
mon(jj,:) = date(1:2); | ||
day(jj,:) = date(4:5); | ||
year(jj,:) = date(7:10); | ||
hour(jj,:) = date(12:13); | ||
minu(jj,:) = date(15:16); | ||
end | ||
aa.date = [year,mon,day,hour,minu]; | ||
aa.date(:,13:14) = '00'; | ||
aa.date = str2num(aa.date); | ||
|
||
aa.timemat = datenum(str2num(year),str2num(mon),str2num(day),... | ||
str2num(hour),str2num(minu),0); | ||
|
||
aa.qflag = data{3}; | ||
aa.lat = data{4}; | ||
aa.lon = data{5}; | ||
aa.dep = data{6}; | ||
|
||
|
||
fclose(fid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function [neighborIds neighborDistances] = kNearestNeighbors(dataMatrix, queryMatrix, k) | ||
%-------------------------------------------------------------------------- | ||
% Program to find the k - nearest neighbors (kNN) within a set of points. | ||
% Distance metric used: Euclidean distance | ||
% | ||
% Usage: | ||
% [neighbors distances] = kNearestNeighbors(dataMatrix, queryMatrix, k); | ||
% dataMatrix (N x D) - N vectors with dimensionality D (within which we search for the nearest neighbors) | ||
% queryMatrix (M x D) - M query vectors with dimensionality D | ||
% k (1 x 1) - Number of nearest neighbors desired | ||
% | ||
% Example: | ||
% a = [1 1; 2 2; 3 2; 4 4; 5 6]; | ||
% b = [1 1; 2 1; 6 2]; | ||
% [neighbors distances] = kNearestNeighbors(a,b,2); | ||
% | ||
% Output: | ||
% neighbors = | ||
% 1 2 | ||
% 1 2 | ||
% 4 3 | ||
% | ||
% distances = | ||
% 0 1.4142 | ||
% 1.0000 1.0000 | ||
% 2.8284 3.0000 | ||
%-------------------------------------------------------------------------- | ||
|
||
neighborIds = zeros(size(queryMatrix,1),k); | ||
neighborDistances = neighborIds; | ||
|
||
numDataVectors = size(dataMatrix,1); | ||
numQueryVectors = size(queryMatrix,1); | ||
for i=1:numQueryVectors, | ||
dist = sum((repmat(queryMatrix(i,:),numDataVectors,1)-dataMatrix).^2,2); | ||
[sortval sortpos] = sort(dist,'ascend'); | ||
neighborIds(i,:) = sortpos(1:k); | ||
neighborDistances(i,:) = sqrt(sortval(1:k)); | ||
end |
Oops, something went wrong.