CMS WIS to txt for spectragen.m

From CIRPwiki
Revision as of 19:07, 26 January 2012 by Rdsajkch (talk | contribs) (Created page with "function[] = CMS_WIS_to_txt_for_spectragen() %This function creates the .txt file used in the spectra generator of % CMS Wave. It prompts the user to select all the desired WIS...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

function[] = CMS_WIS_to_txt_for_spectragen() %This function creates the .txt file used in the spectra generator of % CMS Wave. It prompts the user to select all the desired WIS output files, % specify the depth of the station, and whether or not to average the data % series. The data and user inputs are manipulated into the format used by % CMS Wave file import for spectra generation. Currently the output file % is saved in the active directory of matlab. This can be changed by % adding in desired destination in the definition of variable 'outfile' on % line 56. % % % Created: 26 JAN 2012 % Author: Kevin Hodgens, USACE, SAJ, kevin.c.hodgens@usace.army.mil % Modified: DD MMM YYYY by _____ % Notes: changes include....n/a


[filename,path,filter] = uigetfile('C:\*.onlns','Select the WIS files to include','multiselect','on');


Data = []; for i = 1:length(filename(1,:))

   [time,sta,Lat,Long,ws,wdir,non1,non2,non3,Hs,Tp,foo2,foo3,non4,Dp,dir2] = textread([path filename{i}],'%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n','delimiter',' ');
   Data = [Data;[time,Dp,Hs,Tp]];

end depth = input('What depth is the WIS station? (Remember CMS uses positive values for depth)');


% save('WIS_63422_1980to1999.mat','Data','depth') Turn this on if you wish % to archive the data in a matlab data file


avg_on = input('Would you like to average the time series? 1 = Yes'); if avg_on

   int = input('How many hours in the interval? ex. "6"');
   count = 0;
   for i = 1:int:length(Data(:,1))
       count = count +1;
       mD(count,1) = Data(i+5,1);
       mD(count,2:4) = mean(Data(i:i+5,2:4));
   end
   mind = [1:length(mD)]';

else

   mD = Data;
   mind = 1:length(Data(:,1));

end


Gamma = 3.3*ones(mind(end),1);%Set Gamma to 3.3 as advised by Lihwa Lin nn = 50*ones(mind(end),1);%Set nn to 50 as advised by Lihwa Lin


%Set up output matrix matrix(1:mind(end),[1,16]) = zeros(mind(end),2); matrix(1:mind(end),2) = -1*ones(mind(end),1); matrix(1:mind(end),[3,9:14,17:18]) = 999*ones(mind(end),9); matrix(1:mind(end),4) = mind; matrix(1:length(mD(:,1)),[5:8,15]) = [mD(:,2:4),Gamma,nn]; matrix(1:mind(end),19) = depth*ones(mind(end),1); text(1,1:20) = {' ', 'METHOD', 'OPTION', 'TIME', 'INDEX', 'ANGLE(1)', 'HS(1)', 'TP(1)', 'GAMMA(1)', 'ANGLE(2)', 'HS(2)', 'TP(2)', 'GAMMA(2)', 'WIND', 'FETCH', 'NN(1)', 'NN(2)', 'STDDEV(1)', 'STDDEV(2)', 'DEPTH'};


outfile = 'CMS_spectra_import_file.txt';%Add in specific directory if you please... fid = fopen(outfile,'w');


fprintf(fid,'%s\r\n','SPECTRAL TABLE'); fclose('all'); fid = fopen(outfile,'a'); for j = 1:20

   if j == 20
       fprintf(fid,'%s\r\n',text{1,j});
   else
       fprintf(fid,'%s\t',text{1,j});
   end

end


for i = 1:mind(end)

   for j = 1:20
       if j == 1
           fprintf(fid,'%s\t',);
       elseif j == 20
           fprintf(fid,'%f\r\n',matrix(i,j-1));
       else
           fprintf(fid,'%f\t',matrix(i,j-1));
       end
   end

end fclose('all');