Home > wafo > spec > mkdspec.m

mkdspec

PURPOSE ^

Make a directional spectrum

SYNOPSIS ^

Snew=mkdspec(S,D,plotflag)

DESCRIPTION ^

  MKDSPEC Make a directional spectrum
          frequency spectrum times spreading function
 
  CALL:  Snew=mkdspec(S,D,plotflag)
   
        Snew = directional spectrum (spectrum struct)
        S    = frequency spectrum (spectrum struct)
                   (default jonswap)  
        D    = spreading function (special struct)
                   (default spreading([],'cos2s'))
        plotflag = 1: plot the spectrum, else: do not plot (default 0)   
 
  Creates a directional spectrum through multiplication of a frequency
  spectrum and a spreading function: S(w,theta)=S(w)*D(w,theta)
   
  The spreading structure must contain the following fields:
    .S (size [np 1] or [np nf])  and  .theta (length np)  
  optional fields: .w (length nf), .note (memo) .phi (rotation-azymuth)   
   
  NB! S.w and D.w (if any) must be identical.
 
  Example: S=jonswap
           D=spreading(linspace(-pi,pi,51),'cos2s')
           Snew=mkdspec(S,D,1) 
   
  See also  spreading, rotspec, jonswap, torsethaugen

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function Snew=mkdspec(S,D,plotflag)
002 % MKDSPEC Make a directional spectrum
003 %         frequency spectrum times spreading function
004 %
005 % CALL:  Snew=mkdspec(S,D,plotflag)
006 %  
007 %       Snew = directional spectrum (spectrum struct)
008 %       S    = frequency spectrum (spectrum struct)
009 %                  (default jonswap)  
010 %       D    = spreading function (special struct)
011 %                  (default spreading([],'cos2s'))
012 %       plotflag = 1: plot the spectrum, else: do not plot (default 0)   
013 %
014 % Creates a directional spectrum through multiplication of a frequency
015 % spectrum and a spreading function: S(w,theta)=S(w)*D(w,theta)
016 %  
017 % The spreading structure must contain the following fields:
018 %   .S (size [np 1] or [np nf])  and  .theta (length np)  
019 % optional fields: .w (length nf), .note (memo) .phi (rotation-azymuth)   
020 %  
021 % NB! S.w and D.w (if any) must be identical.
022 %
023 % Example: S=jonswap
024 %          D=spreading(linspace(-pi,pi,51),'cos2s')
025 %          Snew=mkdspec(S,D,1) 
026 %  
027 % See also  spreading, rotspec, jonswap, torsethaugen  
028   
029 
030 % Tested on: Matlab 5.3
031 % History:
032 % revised by jr 31.03.2001 - Field added: norm. 
033 % by es 23.11.1999
034   
035 if nargin<1
036   Snew=demospec;
037   return
038 end
039 if isempty(S)
040   S=jonswap;
041 end
042 if nargin<2|isempty(D)
043   D=spreading([],'cos2s');
044 end
045 if nargin<3
046   plotflag=0;
047 end
048 
049 Snew=createspec('dir');
050 Snew.w=S.w;
051 Snew.tr=S.tr;
052 Snew.h=S.h;
053 Snew.phi =D.phi;
054 Snew.norm=S.norm;
055 Snew.note=S.note;
056 if isfield(D,'note')
057   Snew.note=[Snew.note,'; ',D.note];
058 end
059 Snew.date=datestr(now);
060 Snew.theta=D.theta;
061 S.S=S.S(:);
062 if ~isfield(D,'w')|isempty(D.w)|length(D.w)==1
063   Snew.S=D.S(:)*S.S';
064 else
065   if length(S.w)~=length(D.w)
066     error('S.w and D.w must be identical!')
067   elseif any(abs(S.w-D.w)>1e-10)
068     error('S.w and D.w must be identical!')
069   end    
070   Snew.S=D.S.*S.S(:,ones(1,length(D.theta)))';
071 end
072 
073 if plotflag==1
074   wspecplot(Snew)
075 end
076

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003