⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runpropgncode.m

📁 水声模型 很不错的东西
💻 M
字号:
function [Status, ErrStr] = RunPropgnCode(Obj, Freq, RMin, RMax, DeltaR,  ZRx, ZSource, FName, AppendFile, PropgnCode, Title, ...
    ManualEnvEdit, ExtraParams)
%
%Alec J Duncan, 
%Centre for Marine Science and Technology, 
%Curtin University of Technology,
%Kent Street, Bentley, Western Australia
%a.duncan@cmst.curtin.edu.au
%
%May 2002
%
%Creates the necessary input files and runs Scooter and Fields, or Kraken(c) and Field to generate an ascii shade file
%
%Freq - frequency (Hz)
%RMin - minimum receiver range (m)
%RMax - maximum receiver range (m)
%DeltaR - receiver range step (m)
%ZRx - vector of receiver depths (m)
%ZSource - source depth (m)
%FName - file name for output file including path but excluding extension.  The following files may be
%        generated: 
%        FName.env  actual environment file used by Scooter
%        FName.flp  input file used by Fields
%        FName.asc  ascii shade file
%        FName.prn  file to log program messages
%        FName.brc  bottom reflection coefficient file (bounce)
%AppendFile - 1 to append .asc file to an existing file of the same name, 0 to create new file
%PropgnCode  - determines acoustic propagation code to be run:
%     'Scooter'   fast-field program
%     'Kraken'    normal mode code
%     'Krakenc'   Complex arithmetic normal mode code
%     'Bounce'    Seabed reflection coefficient calculation
%     'Bellhop'   Gaussian bean tracing program - requires additional information in ExtraParams structure

UsePltrth = 0;    %1 to compute bottom reflection coefft using plotrth.exe, 0 to use BRCFILE generated directly by bounce.exe

Status = 1;
ErrStr = 'OK';
EnvFile = fopen([FName '.env'], 'wt');
if EnvFile <= 0
   Status = 0;
   ErrStr = ['couldn''t open environment file: '  FName '.env'];
end

if Status
    switch PropgnCode
    case {'Kraken', 'Krakenc', 'Scooter'},
        FlpFile = fopen([FName '.flp'], 'wt');
   	    if FlpFile <= 0
   	        Status = 0;
	        ErrStr = ['couldn''t open .flp file: '  FName '.flp'];
	    end
    case 'Bellhop'
        EnvFile2 = fopen([FName '_2.env'], 'wt');
   	    if EnvFile2 <= 0
   	        Status = 0;
	        ErrStr = ['couldn''t open .env file: '  FName '2.env'];
	    end
    case 'GreensFn',
        FlpFile = [];
    end
end

if Status
   lExecCmd('Reset');
   switch PropgnCode
   case {'Scooter', 'GreensFn'}
	   %Set up the required input files
      WriteToScooterFiles(Obj, Freq, RMin, RMax, DeltaR,  ZRx, ZSource, EnvFile, FlpFile, Title);
      fclose(EnvFile);
      if ManualEnvEdit	
         lEditFile([FName '.env']);
      end
      if ~isempty(FlpFile)
         fclose(FlpFile);
         if ManualEnvEdit	
            lEditFile([FName '.flp']);
         end
      end
      

      
   case {'Kraken', 'Krakenc'},
      switch PropgnCode
      case 'Kraken'
         ExtraParams.ExhaustiveSearch =0;
      end
      
      WriteToKrakenFiles(Obj, Freq, RMin, RMax, DeltaR,  ZRx, ZSource, EnvFile, FlpFile, Title, ...
         ExtraParams.ExhaustiveSearch);
      fclose(FlpFile);
      fclose(EnvFile);
      if ManualEnvEdit
         lEditFile([FName '.env']);
         lEditFile([FName '.flp']);
      end
    
   case 'Bounce',
      WriteToBounceFiles(Obj, Freq, EnvFile, Title, UsePltrth);
      fclose(EnvFile);
      if ManualEnvEdit	
         lEditFile([FName '.env']);
      end

   case 'Bellhop',
      WriteToBounceFiles(Obj, Freq, EnvFile, Title, UsePltrth);  %Need to run bounce to get bottom reflection coefft
      fclose(EnvFile);
      WriteToBellhopFiles(Obj, Freq, RMin, RMax, DeltaR,  ZRx, ZSource, EnvFile2, ExtraParams, Title);
      fclose(EnvFile2);
      
      if ManualEnvEdit	
         lEditFile([FName '.env']);
         lEditFile([FName '_2.env']);
      end

   end
   
    
   
   DirInfo = Obj.DirInfo;
   LogName = [FName '.prn'];
   
   switch PropgnCode
   case 'Scooter',
	   %Run Scooter
   	   if AppendFile
	   	   CmdString = ['"' DirInfo.Scooter 'scooter.exe" < "' FName '.env"  >> "' LogName '"'];
	   else
   	       CmdString = ['"' DirInfo.Scooter 'scooter.exe" < "' FName '.env"  > "' LogName '"'];
	   end
       lExecCmd(CmdString);
   	      
      
   	   CmdString = ['copy GRNFIL "' FName '.grn" >> "' LogName '"'];  %Do this to keep Greens function file
       lExecCmd(CmdString);

       %Run Fields to produce shade file
      
	   CmdString = ['"' DirInfo.Scooter 'fields.exe" < "' FName '.flp" >> "' LogName '"'];
       lExecCmd(CmdString);
            
       lExecCmd('del GRNFIL');
       lExecCmd('Execute');
       
   case 'GreensFn',
	   %Run Scooter, but not fields
 	  CmdString = ['"' DirInfo.Scooter 'scooter.exe" < "' FName '.env"  > "' LogName '"'];
   
      lExecCmd(CmdString);
   	      
   	  CmdString = ['copy GRNFIL "' FName '.grn" >> "' LogName '"'];  %Do this to keep Greens function file
      lExecCmd(CmdString);
               
   	  lExecCmd('del GRNFIL');
      lExecCmd('Execute');
      
   case {'Kraken', 'Krakenc'},
       switch PropgnCode
       case 'Kraken',
		   if AppendFile
	   		   CmdString = ['"' DirInfo.Kraken 'kraken.exe" < "' FName '.env"  >> "' LogName '"'];
		   else
	   		   CmdString = ['"' DirInfo.Kraken 'kraken.exe" < "' FName '.env"  > "' LogName '"'];
           end
            
       case 'Krakenc',
		   if AppendFile
	   		   CmdString = ['"' DirInfo.Kraken 'krakenc.exe" < "' FName '.env"  >> "' LogName '"'];
		   else
	   		   CmdString = ['"' DirInfo.Kraken 'krakenc.exe" < "' FName '.env"  > "' LogName '"'];
           end
       end
       lExecCmd(CmdString);
       
   	   CmdString = ['copy MODFIL1 "' FName '.mod" >> "' LogName '"'];  %Do this to keep mode file
       lExecCmd(CmdString);
       
       %Run Field to produce shade file
	   CmdString = ['"' DirInfo.Kraken 'field.exe" < "' FName '.flp" >> "' LogName '"'];
       lExecCmd(CmdString);
   
   	   lExecCmd('del MODFIL1');
       lExecCmd('Execute');

   case {'Bounce', 'Bellhop'},
	   CmdString = ['"' DirInfo.Kraken 'bounce.exe" < "' FName '.env"  > "' LogName '"'];
       lExecCmd(CmdString);
        
      if UsePltrth
          %Convert this into a bellhop compatible file
          %plotrth.exe does most of this, but generates a whole lot of unwanted stuff at the
          %start of the file that has to be stripped out
	      CmdString = ['"' DirInfo.Kraken 'plotrth.exe" >> "' FName '.tmp"'];
          lExecCmd(CmdString);
      
          lExecCmd('Execute');
       
          %Strip out the garbage
          lStripGarbage(FName);
       
          lExecCmd('Reset');
          lExecCmd('del IRCFIL');
          lExecCmd('del plotrth.plp');
	      CmdString = ['del "' FName '.tmp"'];
          lExecCmd(CmdString);
      else
          CmdString = ['copy BRCFIL "' FName '.brc" >> "' LogName '"'];
          lExecCmd(CmdString); 
       
          lExecCmd('del IRCFIL');
      end
       
      switch PropgnCode
      case 'Bounce'
         lExecCmd('del BRCFIL');
         lExecCmd('Execute');
         
      case 'Bellhop',
           if UsePltrth
               %Put the bottom reflection coefft file in the right place
               CmdString = ['copy "' FName '.brc" BRCFIL  >> "' LogName '"'];
               lExecCmd(CmdString);
           end
               
           if ExtraParams.UseBathyFile
               CmdString = ['copy "' ExtraParams.BathyFName '" BTYFIL  >> "' LogName '"'];
               lExecCmd(CmdString);
           end

           %Run Bellhop
  	        CmdString = ['"' DirInfo.Bellhop 'bellhop.exe" < "' FName '_2.env" >> "' LogName '"'];
           lExecCmd(CmdString);
           lExecCmd('del BRCFIL');
           if ExtraParams.UseBathyFile
               lExecCmd('del BTYFIL');
           end
            
           lExecCmd('Execute');

           FileInfo = dir('RAYFIL');  %Check if bellhop generated a ray file
           if ~isempty(FileInfo)
              lExecCmd('Reset');
	           CmdString = ['copy RAYFIL "' FName '.ray" >> "' LogName '"'];
              lExecCmd(CmdString);
              lExecCmd('del RAYFIL');
              lExecCmd('Execute');
           end
           
           FileInfo = dir('ARRFIL');  %Check if bellhop generated an amplitude-delay file
           if ~isempty(FileInfo)
              lExecCmd('Reset');
	          CmdString = ['copy ARRFIL "' FName '.arr" >> "' LogName '"'];
              lExecCmd(CmdString);
              lExecCmd('del ARRFIL');
              lExecCmd('Execute');
           end
           
       end
   end
   
   
   switch PropgnCode
   case {'Kraken', 'Krakenc', 'Scooter', 'Bellhop'},
       %Save shade file
       FileInfo = dir('SHDFIL');
	    if ~isempty(FileInfo)   %Need this test as Bellhop doesn't always generate a shade file
   
           if AppendFile
               CmdString = ['copy "' FName '.shd" + SHDFIL "' FName '.shd" >> "' LogName '"'];
           else
               CmdString = ['copy SHDFIL "' FName '.shd" >> "' LogName '"'];
           end
          lExecCmd('Reset');
          lExecCmd(CmdString);
   
          lExecCmd('del SHDFIL');
          lExecCmd('Execute');
       end
              
    end
    
    ErrLevel = ScanPrnForErrors(LogName);
    if ErrLevel == 0
       disp('No errors or warnings found in log (.prn) file');
    else
       disp('ERROR and/or WARNING message(s) found in log (.prn) file');
    end
    disp(' ');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function  lStripGarbage(FName);
InFile = fopen([FName '.tmp'], 'rt');
OutFile = fopen([FName '.brc'], 'wt');

Done = 0;

%Find the start of the data
while ~Done
    InStr = fgetl(InFile);
    if strcmp(InStr, 'TYPE xy');
        Done = 1;
    end
end

Count = 0;
Done = 0;
while ~Done
    InStr = fgetl(InFile);
    if strcmp(InStr, '&');
        Done = 1;
    else
        Count = Count+1;
    end
end

Done = 0;
while ~Done
    InStr = fgetl(InFile);
    if strcmp(InStr, 'TYPE xy');
        Done = 1;
    end
end

for ICount = 1:Count
    InStr = fgetl(InFile);
end

NPt = str2num(fgetl(InFile));
fprintf(OutFile, '%d\n', NPt);
for ICount = 1:NPt
    InStr = fgetl(InFile);
    fprintf(OutFile, '%s\n', InStr);
end

fclose(InFile);
fclose(OutFile);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function lEditFile(FName)
eval(['!notepad "' FName '"']);
uiwait(msgbox('Edit file, save it, then OK to continue'));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function lExecCmd(CmdStr)
%Executes the specified dos command string
%This is done by writing the string to a batch file and then executing the batch file
%to avoid problems with matlab's dos shell not being able to handle blanks in directory names
persistent Fid;

switch CmdStr
case 'Reset',
   Fid = fopen('CommandStr.bat', 'wt');
case 'Execute',
   fclose(Fid);
   !CommandStr.bat
otherwise,  
	fprintf(Fid, '%s\n', CmdStr);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -