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

📄 runadcp.m

📁 一个研究声多普勒计程仪很好的工具箱
💻 M
字号:
function theResult = runadcp(numRawFile,rawdata1,rawdata2,rawcdf,theFilledFile,theMaskFile,...
   theNewADCPFile,trimFile);

%%function [theResult] = runadcp(numRawFile,rawdata1,rawdata2,rawcdf,theFilledFile,theMaskFile,...
%		theNewADCPFile,trimFile);

%%Runs the important ADCP functions in the following order:
% rdi2cdf.m
% fixEns.m
% runmask.m
% goodends.m
% trimbins.m
% 
%%Ocassionally the program will display some results in figures and
% stops to ask if it is ok to continue. If the program seems to be waiting
% and you are unsure what to do, check the matlab command window for
% a message!
%%Type 'pause off' prior to running function if would like to run unattended.
%
%%If you do not wish to run rdi2cdf.m, to create the first netcdf file 
%from this data than, you must have an existing netcdf file and type 
%in the first 2 inputs in the command line.  
%i.e. theResult = runADCP('999wh.000','999wh.cdf').
%
%Although you will be prompted for the INPUT files, be sure to have all 
%%of them accessable before beginning.
%
%%INPUTS:
%		rawdata =  RDI ADCP binary output file (*.000)
%		rawcdf = the Netcdf file created directly from the binary ADCP file
%		theFilledFile = the raw Netcdf file which has filled in place holders
%        for any missing ensemble numbers
%		theMaskFile = identical in size and structure to the cdf file 
%			containing 0's if the data is good and 1's if it is bad
%		theNewADCPFile = the "masked" data file after initial filtering
%		trimFile = the last file created by trimming the bad ensembles
%
%If file names are not given, they will be requested.
%
%%
%%OUTPUTS:
%%		theResult = is the trimFile, the last file created

% Written by Jessica M. Cote
% for the U.S. Geological Survey
% Coastal and Marine Geology Program
% Woods Hole, MA
% http://woodshole.er.usgs.gov/
% Please report bugs to jcote@usgs.gov
%
%Sub-programs
%	Rdi2cdf.m
%   fixEns.m
%   fappend.m
%	Starbeam directory
%	runmask.m (incorporates all masking functions)
%
% updated 02-Apr-2003 - WIll not run Trimbins if data is orientated downward (ALR)
% updated 08-Aug-2001 - uses fappend.m to concatenate multiple binary files (ALR)
% updated 10-Jul-2001  -added ability to use one or two binary ADCP files (ALR)
% updated 09-Jul-2001 - fixed getinfo field bug for Matlab 6.0 R.12 (ALR)
% updated 09-Jul-2001 - fixed capitalization problems so UNIX won't crash (ALR)
% updated 19-Dec-2000 15:28:48 (ALR)  added fixEns.m function
% updated 15-Oct-1999 09:31:48   

if nargin < 1, help(mfilename), end

if running(batch)
   numRawFile = get(batch);
   eval(['numRawFile = ' numRawFile ';'])
   rawdata1 = get(batch);
   eval(['rawdata1 = ' rawdata1 ';'])
   rawdata2 = get(batch);
   eval(['rawdata2 = ' rawdata2 ';'])
   rawcdf = get(batch);
   eval(['rawcdf = ' rawcdf ';'])
   theFilledFile = get(batch);
   eval(['theFilledFile = ' theFilledFile ';'])
   theMaskFile = get(batch);
   eval(['theMaskFile = ' theMaskFile ';'])
   theNewADCPFile = get(batch);
   eval(['theNewADCPFile = ' theNewADCPFile ';'])
   trimFile = get(batch);
   eval(['trimFile = ' trimFile ';'])
   
else
   
if nargin < 1, numRawFile = ''; end   
if nargin < 2, rawdata1 = ''; end
if nargin < 3, rawdata2 = ''; endif nargin < 4, rawcdf = '';, end
if nargin < 5, theFilledFile = ''; end
if nargin < 6, theMaskFile = ''; end
if nargin < 7, theNewADCPFile = ''; end
if nargin < 8, trimFile = ''; end

end


if isempty(numRawFile),numRawFile = menu('How many bianry files used?','1','2'); endif isempty(rawdata1), rawdata1 = '*'; end
if isempty(rawdata2), rawdata2 = '*'; end
if isempty(theNewADCPFile), theNewADCPFile = '*'; end
if isempty(trimFile), trimFile = '*'; end
% Get ADCP raw data filename.
switch numRawFile
case 1
   if any(rawdata1 == '*')
      [theFile, thePath] = uigetfile('*.000', 'Select Binary ADCP File:');
      if ~any(theFile), return, end
      if thePath(end) ~= filesep, thePath(end+1) = filesep; end      rawdata1 = [thePath theFile];
      rawdata = rawdata1; clear rawdata1 rawdata2   end
    if running(batch)
       rawdata = rawdata1;
       clear rawdata1 rawdata2
    end
end

switch numRawFile
case 2
   if any(rawdata1 == '*')
      [theFile1, thePath1] = uigetfile('*.000', 'Select 1st Binary ADCP File:');
      if ~any(theFile1), return, end
      if thePath1(end) ~= filesep, thePath1(end+1) = filesep; end      %rawdata1 = [thePath1 theFile1];   end
   
   if any(rawdata2 == '*')      [theFile2, thePath2] = uigetfile('*.000', 'Select 2nd Binary ADCP File:');
      if ~any(theFile2), return, end      if thePath2(end) ~= filesep, thePath2(end+1) = filesep; end      %rawdata2 = [thePath2 theFile2];   end
   
   if running(batch)
      theFile1 = rawdata1;
      theFile2 = rawdata2;
      thePath1 = pwd;
   end
   
%If there are two binary files that make up the dataset, concatonate them now
  if exist(theFile2)
     theFile = [theFile1(1:5) 'all.000'];
     fappend(theFile,theFile1,theFile2);
     thePath = thePath1;
     if thePath(end) ~= filesep, thePath(end+1) = filesep; end
     rawdata = [thePath theFile];
     clear rawdata1 rawdata2 theFile1 thePath1 theFile2 thePath2 ss w
  end
end

% Get ADCP netcdf filename if not given
if isempty(rawcdf)
   [PATH,NAME,EXT,VER] = fileparts(rawdata);
   [theFile, thePath] = uiputfile([NAME '.cdf'],...
      'Save Netcdf ADCP File As (or press cancel to use an existing file):');   if ~any(theFile), 
      [theFile, thePath] = uigetfile([NAME '.cdf'], 'Use the Existing Netcdf ADCP File:');
   end   if ~any(theFile), return, end   if thePath(end) ~= filesep, thePath(end+1) = filesep; end		rawcdf = [thePath theFile];end

if ~isempty(rawcdf) & isequal(exist(rawcdf),0)
disp(['Converting RDI data file to netcdf'])
disp('You will be asked for some inputs from the mooring log')
disp(' ')
   rdi2cdf(rawdata,rawcdf);
   if ~running(batch)
   	disp('In the following figure quickly review the data');
		disp('Then click "Done" on the Starbeam menu, and hit enter');
      pause(5)
      
      starbeam(rawcdf);
		pause 
   end
elseif isequal(exist(rawcdf),2)
   disp(' ')
   disp('Rdi2cdf.m was skipped.')
   disp(['Use existing netcdf file ' rawcdf ]);
   disp(' ')  
else
   return
end

%Check for missing ensemble numbers 
if isempty(theFilledFile)
   [PATH,NAME,EXT,VER] = fileparts(theFilledFile);
   [theFile, thePath] = uiputfile([NAME '.cdf'],...
      'Save Netcdf ADCP Fill File As:');   if ~any(theFile), return, end   if thePath(end) ~= filesep, thePath(end+1) = filesep; end   theFilledFile = [thePath theFile];
end

[missEnsNo] = fixEns(rawcdf,theFilledFile);

if missEnsNo ~= 0
   rawcdf = theFilledFile;
   disp('')
   disp(['Using new filled file ' theFilledFile])
end

%find out if beam or earth
F = netcdf(rawcdf,'nowrite');   
coord = F.transform(:);

%Give mask file a name
switch coord
   
case 'BEAM'
	if any(theMaskFile == '*') 
  	 	mask='*.msk';
  		[theFile, thePath] = uiputfile(mask, 'Create Mask File As:');		if ~any(theFile), return, end		if thePath(end) ~= filesep, thePath(end+1) = filesep; end		theMaskFile = [thePath theFile];	end

	% Get ADCP filename.
	if any(theNewADCPFile == '*')		[theFile, thePath] = uiputfile('*M.cdf', 'Save masked ADCP File As:');		if ~any(theFile), return, end		if thePath(end) ~= filesep, thePath(end+1) = filesep; end		theNewADCPFile = [thePath theFile];	end
	%Mask the data file based on RDI criteria
	disp('')
	disp('Running mask functions to remove bad data points')
   disp('')
   
	[theNewADCPFile, theMaskFile] = runmask(rawcdf,theMaskFile,theNewADCPFile);
   
case 'EARTH'
   disp('')
	disp('Data in Earth coordinates, Masking was not performed')
	disp('')
   theNewADCPFile = rawcdf; 
end

   
%Find the first and last good ensemble and trim the data record
[minens, maxens, nens, trimFile] = goodends(theNewADCPFile,theMaskFile,trimFile);

%find out if up or down
F = netcdf(rawcdf,'nowrite');   
orientation = F.orientation(:);

switch orientation
    
case 'UP'
    close(F)
    
if running(batch)
   ButtonName = get(batch)
   eval(['ButtonName = ' ButtonName ';'])
else
%User must have RDI surface program to run trimbins without a depth input.
ButtonName=questdlg('Do you have the RDI surface program?', ...
   'Defining Water Depth');
end
                       
     switch ButtonName,
        case 'No', 
           if running(batch)
              MSL = get(batch);
              eval(['MSL = ' MSL ';'])
              Dstd = get(batch);
              eval(['Dstd = ' Dstd ';'])
           else
              disp('User must input the water depth information')
	           Depth_Information.mean_sea_level.value = {0};
   	        Depth_Information.mean_sea_level.units = {'meters'};
      	     Depth_Information.half_the_tidal_range.value = {0};
         	  Depth_Information.half_the_tidal_range.units = {'meters'};
	           Depth_Information = uigetinfo(Depth_Information');	
           
   	        %check units
      	     infoD = getinfo(Depth_Information,'mean_sea_level');
              unitD = getinfo(infoD,'units');
         	  infoT = getinfo(Depth_Information,'half_the_tidal_range');
              unitT = getinfo(infoT,'units');
              
           
	           	if ~isequal(unitD,'meters') | ~isequal(unitT,'meters')
            	  	disp('User error!! Depth Information must be in meters')
              		pause(3)
                    Depth_Information = uigetinfo(Depth_Information)
               end
           
         	  	infoMSL = getinfo(Depth_Information,'mean_sea_level');
                MSL = getinfo(infoMSL,'value');
           		infoDstd = getinfo(Depth_Information,'half_the_tidal_range');
                Dstd = getinfo(infoDstd,'value');
             end %if batch
           
             % [MSL, Dstd] = trimbins(rawdata,trimFile,MSL,Dstd);
             [MSL, Dstd] = trimbins(1,rawdata,'',trimFile,MSL,Dstd);
           
       case 'Yes',
          [MSL, Dstd] = trimbins(1,rawdata,'',trimFile);
           
       case 'Cancel',
         disp('TrimBins was not run due to lack of depth information');
         
      end % switch
      
  case 'DOWN'
      close(F)
   disp('')
	disp('Data is orientated downward. Trimbins.m was not run')
	disp('')
end

%Scan data for bins out of water based on depth+tidal variation

theResult = trimFile;

⌨️ 快捷键说明

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