function adr2cdf(advFile, cdfFile, DataType, minBurst, maxBurst); % ADR2CDF - Converts Sontek ADV files to netCDF format % adr2cdf(infile, outfile, DataType, minBurst, maxBurst); % % where: % advFile = input Sontek ADV file (ex: 'CA1001.adr') % cdfFile = netCDF file name (ex: 'C1001.cdf') % DataType = 'Burst' | 'Stats' | 'Both' % minBusrt = Burst number at which to start converting % maxBurst = Burst number at which to stop converting % % note that if both stats and bursts are requested, time will only be % stored as a [burst sample] shape % % Version 2-Apr-2004 % Add batch capability % Version 15-Mar-2004 % will not work with multiple sampling schemes % generated time stamps for each sample when burst data is requested % removed pressure normalization, fixed conversion to frequency % Version 04-Dec-2003 % Proposed changes % 1) acommodate the three different sampling schemes... record and use the % sample rate in each burst header % Written by Andree L. Ramsey % Heavily based on adr2mat.m written by Jingping Xu % for the U.S. Geological Survey % Marine and Coastal Program % Woods Hole Center, Woods Hole, MA % http://woodshole.er.usgs.gov/ % Please report bugs to aramsey@usgs.gov % % netCDF attributes and variable names follow EPIC conventions % % information on netCDF may be obtained at % http://www.unidata.ucar.edu % it's free!! % % % need valid ranges for CTD data % Someone please check CTD data- seems good to me % Someone please check OBS data - seems good to me % what about addtional samples per burst? Can have three sets? Need test % data % add batch ability when all processing files are completed for ADVToolbox prog_ver = 'Beta Limited Burst Version 15-Mar-2004'; disp(['adr2cdf_beta_burst.m version ',prog_ver]); tic if running(batch) advFile = get(batch); eval(['advFile = ' advFile ';']) cdfFile = get(batch); eval(['cdfFile = ' cdfFile ';']) DataType = get(batch); eval(['DataType = ' DataType ';']) minBurst = get(batch); eval(['minBurst = ' minBurst ';']) maxBurst = get(batch); eval(['maxBurst = ' maxBurst ';']) % def = {'0','01-jan-2003','01-jan-2004','0','0','0','0'}; batchline = get(batch); eval(['metadata{1} = ' batchline ';']) % mooring number batchline = get(batch); eval(['metadata{2} = ' batchline ';']) % deployment date batchline = get(batch); eval(['metadata{3} = ' batchline ';']) % recovery date batchline = get(batch); eval(['metadata{4} = ' batchline ';']) % Longitude, decimal degrees, W is negative batchline = get(batch); eval(['metadata{5} = ' batchline ';']) % Latitude, decimal degrees batchline = get(batch); eval(['metadata{6} = ' batchline ';']) % Magnetic Var. batchline = get(batch); eval(['metadata{7} = ' batchline ';']) % Probe offset, m else % Open file and determine file size if nargin < 1, help(mfilename), end if nargin < 1, advFile = ''; end if nargin < 2, cdfFile = ''; end if nargin < 3, DataType = []; end if nargin < 4, minBurst = ''; end if nargin < 5, maxBurst = ''; end end if isempty(advFile), advFile = '*'; end if isempty(cdfFile), cdfFile = '*'; end % Get raw ADV filename. if any(advFile == '*') [theFile, thePath] = uigetfile(advFile, 'Select ADV Data File:'); if ~any(theFile), return, end if thePath(end) ~= filesep, thePath(end+1) = filesep; end advFile = [thePath theFile]; end if isempty(DataType), % Choice to create a stats only flie, a data only file, or both DataType = menu('What type of file do you want to create?','Statistics Only','Burst Data Only','Burst and Statistics Data'); % DataType = 1 is stats only; DataType = 2 is burst data only; DataType = 3 is both if DataType == 1 disp(' ') disp('Only the statistics data will be converted') elseif DataType == 2 disp(' ') disp('Only the burst data will be converted') elseif DataType ==3 disp(' ') disp('Both the burst and the statistics data will be converted') end elseif ischar(DataType), switch DataType, case 'Stats', DataType = 1; case 'Burst', DataType = 2; otherwise, DataType = 3; end end [path,name,ext,ver]=fileparts(advFile); % Get ADV netCDF filename. switch DataType case 1 if any(cdfFile == '*') suggest=[name 's.cdf']; [theFile, thePath] = uiputfile(suggest, 'Save ADV netCDF Statistics File As:'); if ~any(theFile), return, end if thePath(end) ~= filesep, thePath(end+1) = filesep; end cdfFile = [thePath theFile]; end case 2 if any(cdfFile == '*') suggest=[name 'b.cdf']; [theFile, thePath] = uiputfile(suggest, 'Save ADV netCDF Burst File As:'); if ~any(theFile), return, end if thePath(end) ~= filesep, thePath(end+1) = filesep; end cdfFile = [thePath theFile]; end case 3 if any(cdfFile == '*') suggest=[name '.cdf']; [theFile, thePath] = uiputfile(suggest, 'Save ADV netCDF Whole Data File As:'); if ~any(theFile), return, end if thePath(end) ~= filesep, thePath(end+1) = filesep; end cdfFile = [thePath theFile]; end end %end switch fid=fopen(advFile); fseek(fid,0,1); filesize=ftell(fid); disp(sprintf('The file is %d bytes',filesize)) fseek(fid,0,-1); %rewind file %Create netCDF file nc=netcdf(cdfFile,'clobber'); %Read and write global attributes from the hardware config block (441 bytes) % Hardware Configuration (24 bytes) nc.CreationDate = datestr(now); nc.cpuSoftWareVerNum = (fread(fid,1,'uchar')) * 0.1; nc.dspSoftWareVerNum = (fread(fid,1,'uchar')) * 0.1; nc.Inst_Type = 'Sontek ADV'; a = fread(fid,6,'char'); ADVType = {'10MHz_5cm','10MHz_10cm','OCEAN'}; %Using Jingping's code, this seems to be reading incorrectly %nc.ADVType = ADVType{1+a(1)}; SensorOrientation = {'down','up','side'}; nc.SensorOrietnation = SensorOrientation{1+a(2)}; CompassInstalled = {'No','Yes'}; nc.CompassInstalled = CompassInstalled{1+a(3)}; RecorderInstalled = {'No','Yes'}; nc.RecorderInstalled = RecorderInstalled{1+a(4)}; TempInstalled = {'No','Yes'}; nc.TempInstalled = TempInstalled{1+a(5)}; PressInstalled = {'No','Yes'}; nc.PressInstalled = PressInstalled{1+a(6)}; clear PressInstalled TempInstalled RecorderInstalled CompassInstalled SensorOrientation ADVType a nc.PressScale = fread(fid,1,'int32'); nc.PressOffset = fread(fid,1,'int32'); nc.CompassOffset = fread(fid,1,'int16'); nc.PressFreqOffset = fread(fid,1,'char'); a = fread(fid,2,'char'); ExtSensorInstalled = {'None','Standard','OBS_Ch1','OBS_Ch2','OBS_Ch3'}; nc.ExtSenosrInstalled = ExtSensorInstalled{1+a(1)}; ExtPressInstalled = {'Paros','Druck','ParosFreq'}; nc.ExtPressInstalled = ExtPressInstalled{a(2)}; clear ExtPressInstalled ExtSensorInstalled a nc.PressScale_2 = fread(fid,1,'int16'); a = fread(fid,1,'char'); CTDInstalled = {'MicroCat CTD','LISST'}; nc.CTDInstalled = CTDInstalled{a}; clear CTDInstalled a % Probe Confirguration (164 bytes) fseek(fid,10,0); a=fread(fid,[1,6],'char'); a(a==0)=[]; nc.SerialNum=char(a); % This is from adr2mat.m written by Jingping Xu ProbeConfiguration = {'Down XYZ 5cm','Down XYZ 5cm','Up XYZ 5cm','Side XYZ 5cm',... 'Down XZ 5cm','Up XZ 5cm','Side XY 5cm','Cable XYZ 5cm',... 'Down XYZ 10cm','Up XYZ 10cm','Side XYZ 10cm',... 'Down XZ 10cm','Up XZ 10cm','Side XY 10cm','Cable XYZ 10cm',... 'Ocean Probe','Micro Down XYZ 5cm','Micro Up XYZ 5cm',... 'Micro Side XYZ 5cm','Micro Down XZ 5cm','Micro Up XZ 5cm',... 'Micro Sdie XY 5cm','Micro Cable XYZ 5cm'}; ProbeIndex = [0 1 2 3 4 5 6 10 17 18 19 20 21 22 26 41 81 82 83 84 85 86 90]; a=fread(fid,2,'char'); index=find(ProbeIndex==a(1)); nc.ProbeConfiguration=ProbeConfiguration{index}; clear ProbeIndex a index ProbeConfiguration fseek(fid,102,0); nc.xfercoeff=fread(fid,[3,3],'float32'); nc.xmtrecdist=fread(fid,1,'float32'); nc.calcw=fread(fid,1,'float32'); % Deployment Parameters (253 bytes) nc.ConfigType = fread(fid,1,'uchar'); nc.ConfigVer = fread(fid,1,'uchar'); Nbytes = fread(fid,1,'uint16'); clear Nbytes % Skip Configuration time fseek(fid,8,0); nc.Temp = fread(fid,1,'int16') * 0.1; %degrees Celcius nc.Salinity = fread(fid,1,'int16') * 0.1; %ppt nc.CW = fread(fid,1,'int16') * 0.1; %m/s a = fread(fid,1,'uchar'); TempMode = {'User Value','Measured'}; nc.TempMode = TempMode{a+1}; nc.VelRangeIndex = fread(fid,1,'uchar'); a = fread(fid,1,'char'); SyncMode = {'Diable','Start','Sample'}; nc.SyncMode = SyncMode{a+1}; a = fread(fid,1,'char'); CoordSystem = {'Beam','XYZ','ENU'}; nc.CoordSystem = CoordSystem{a+1}; SampleRate = fread(fid,[1,3],'uint16') *0.01; %Hz nc.SampleRate = SampleRate; nc.BurstInterval = fread(fid,[1,3],'uint16'); %seconds nSamples = fread(fid,[1,3],'uint16'); nc.SamplesPerBurst = nSamples; clear CoordSystem SyncMode TempMode a %recored data for sampling 1 recordedData = fread(fid,1,'uchar'); recdata = dec2bin(recordedData); b = '00000000'; b(8-length(recdata)+1:8) = recdata; rflag = str2num(b(:)); bitsize = [0 3 4 0 0 4 6 4]; BytesPerSample = 8+sum(bitsize(rflag>0)); b = fliplr(b); fseek(fid,1,0); %%%%% Don't know if this is needed or not?? %recorded data for sampling 2 %recordedData = fread(fid,1,'uchar'); %recdata = dec2bin(recordedData); %b = '00000000'; %b(8-length(recdata)+1:8) = recdata; %rflag = str2num(b(:)); %bitsize = [0 3 4 0 0 4 6 4]; %BytesPerSample2 = 8+sum(bitsize(rflag>0)); fseek(fid,1,0); %recorded data for sampling 3 %recordedData = fread(fid,1,'uchar'); %recdata = dec2bin(recordedData); %b = '00000000'; %b(8-length(recdata)+1:8) = recdata; %rflag = str2num(b(:)); %bitsize = [0 3 4 0 0 4 6 4]; %BytesPerSample3 = 8+sum(bitsize(rflag>0)); %BytesPerSample = BytesPerSample1 + BytesPerSample2 + BytesPerSample3; a = fread(fid,1,'char'); OutMode = {'Auto','Polled'}; nc.OutMode = OutMode {a+1}; a = fread(fid,1,'char'); OutFormat = {'Binary','Ascii'}; nc.OutFormat = OutFormat {a+1}; a = fread(fid,1,'char'); RecorderEnabled = {'Disabled','Enabled'}; nc.RecorderEnabled = RecorderEnabled {a+1}; a = fread(fid,1,'char'); RecorderMode = {'Normal Mode','Buffer Mode'}; nc.RecorderMode = RecorderMode {a+1}; a = fread(fid,1,'char'); DeploymentMode = {'Disabled','Enabled'}; nc.DeploymentMode = DeploymentMode {a+1}; clear DeploymentMode RecorderMode RecorderEnabled OutFormat OutMode a DeploymentName = char(fread(fid,[1,9],'char')); DN = cellstr(DeploymentName);newDN = DN{:}; %gets rid of blank spaces nc.DeploymentName = newDN; clear newDN DN DeploymentName year = fread(fid,1,'int16'); day = fread(fid,1,'char'); month = fread(fid,1,'char'); minute = fread(fid,1,'char'); hour = fread(fid,1,'char'); hs = fread(fid,1,'char'); sec = fread(fid,1,'char'); nc.BeginDeployment = [day month year hour minute sec hs]; clear year day month minute hour hs sec Comment1 = char(fread(fid,[1,60],'char')); c1 = cellstr(Comment1);newc1 = c1{:}; %gets rid of blanks spaces Comment2 = char(fread(fid,[1,60],'char')); c2 = cellstr(Comment2);newc2 = c2{:}; %gets rid of blank spaces Comment3 = char(fread(fid,[1,60],'char')); c3 = cellstr(Comment3);newc3 = c3{:}; %gets rid of blanks spaces nc.ADRComments = [newc1 newc2 newc3]; clear Comment* c1 c2 c3 newc* AutoSleep = fread(fid,1,'char'); clear AutoSleep fseek(fid,7,0); %skip spare if ~running(batch) %% User Input Metadta % Get Mooring Information prompt = {'Enter 4-digit mooring number:',... 'Enter the deployment date (dd-mmm-yyyy):',... 'Enter the recovery date (dd-mmm-yyyy):',... 'Enter the Longitude (decimal degrees):',... 'Enter the Latitude (decimal degrees):',... 'Enter the magnetic variation at the mooring location in degrees',... 'Enter the distance between the ADV probe and the sea bed in meters:'}; def = {'0','01-jan-2003','01-jan-2004','0','0','0','0'}; title = 'Input metadata from the mooring data'; lineNo = 1; metadata = inputdlg(prompt,title,lineNo,def); nc.Mooring = metadata{1}; nc.Deployment_date = metadata{2}; nc.Recovery_date = metadata{3}; nc.Longitude = str2num(metadata{4}); nc.Latitude = str2num(metadata{5}); nc.mag_var = str2num(metadata{6}); nc.probe_offset = str2num(metadata{7}); else nc.Mooring = metadata{1}; nc.Deployment_date = metadata{2}; nc.Recovery_date = metadata{3}; nc.Longitude = metadata{4}; nc.Latitude = metadata{5}; nc.mag_var = metadata{6}; nc.probe_offset = metadata{7}; end %% Define dimensions tBursts = floor((filesize-441)/(BytesPerSample*nSamples(1))); disp(['There are approximately ',num2str(tBursts),' bursts in the file']) disp(['Each burst contains ',num2str(nSamples(1)),' samples']) % Marinna changed this section to accommodate partial bursts and batch input if exist('minBurst')~=1, minBurst = []; burstdim=1; else burstdim=0; end if exist('maxBurst')~=1, maxBurst = []; burstdim=1; else burstdim=0; end if ~isempty(minBurst) & ~isempty(maxBurst) nBursts = (maxBurst - minBurst) + 1; disp([num2str(nBursts),' bursts will be processed']) else nBursts = floor((filesize-441)/(BytesPerSample*nSamples(1))); minBurst = 1; maxBurst = nBursts; disp([num2str(nBursts),' bursts will be processed']) end disp(sprintf('Writing bursts %d to %d to %s', minBurst, maxBurst, cdfFile)) disp('Now defining netCDF file, this may take some time...') if burstdim, % user wants all the bursts nc('burst') = nBursts; % this will take the time to write the entire filespace to disk first else % yser wants only part of the bursts nc('burst') = 0; % this is faster if only a subset of the bursts are desired end nc('sample') = nSamples(1); nc('axis') = 3; clear tBursts %% Define Variables and attributes nc{'burstNum'} = ncfloat('burst'); nc{'burstNum'}.units = ncchar('counts'); nc{'burstNum'}.samplerate = SampleRate; nc{'burstNum'}.sampleperburst = nSamples; % removed by Marinna % nc{'time'} = ncdouble('burst'); % nc{'time'}.units = ncchar('decimal days'); % nc{'time'}.long_name = ncchar('JULIAN DAYS'); % nc{'time'}.FillValue_ = ncdouble(1e+035); % nc{'time'}.epic_code = nclong(627); % nc{'time'}.valid_min = nclong(0); switch DataType case 1 % added by Marinna nc{'time'} = ncdouble('burst'); nc{'time'}.units = ncchar('decimal days'); nc{'time'}.long_name = ncchar('JULIAN DAYS'); nc{'time'}.FillValue_ = ncdouble(1e+035); nc{'time'}.epic_code = nclong(627); nc{'time'}.valid_min = nclong(0); nc{'time2'} = ncdouble('burst'); nc{'time2'}.FORTRAN_format = ncchar('F10.2'); nc{'time2'}.units = ncchar('msec'); nc{'time2'}.type = ncchar('UNEVEN'); nc{'time2'}.long_name = ncchar('msec since 0:00 GMT'); nc{'time2'}.FillValue_ = ncdouble(1e+035); nc{'time2'}.epic_code = nclong(624); nc{'time2'}.valid_min = nclong(0); nc{'MeanAmp'} = ncfloat('burst','axis'); nc{'MeanAmp'}.long_name = ncchar('Mean Amplitude for Burst'); nc{'MeanAmp'}.units = ncchar('counts'); nc{'MeanAmp'}.valid_range = ncfloat([-32768 32767]); nc{'MeanAmp'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanCorr'} = ncfloat('burst','axis'); nc{'MeanCorr'}.long_name = ncchar('Mean Correlation for Burst'); nc{'MeanCorr'}.units = ncchar('counts'); nc{'MeanCorr'}.valid_range = ncfloat([-32768 32768]); nc{'MeanCorr'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanHeading'} = ncfloat('burst'); nc{'MeanHeading'}.long_name = ncchar('Mean Heading for Burst'); nc{'MeanHeading'}.units = ncchar('degrees'); nc{'MeanHeading'}.valid_range = ncfloat([0 359.9999]); nc{'MeanHeading'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanPitch'} = ncfloat('burst'); nc{'MeanPitch'}.long_name = ncchar('Mean Pitch for Burst'); nc{'MeanPitch'}.units = ncchar('degrees'); nc{'MeanPitch'}.valid_range = ncfloat([-20 20]); nc{'MeanPitch'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanRoll'} = ncfloat('burst'); nc{'MeanRoll'}.long_name = ncchar('Mean Roll for Burst'); nc{'MeanRoll'}.units = ncchar('degrees'); nc{'MeanRoll'}.valid_range = ncfloat([-20 20]); nc{'MeanRoll'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanTemperature'} = ncfloat('burst'); nc{'MeanTemperature'}.units = ncchar('degrees'); nc{'MeanTemperature'}.long_name = ncchar('Mean Transducer Temperature for Burst'); nc{'MeanTemperature'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanTemperature'}.valid_range = ncfloat([-5 40]); nc{'MeanPressure'} = ncfloat('burst'); nc{'MeanPressure'}.long_name = ncchar('Mean Pressure for Burst'); nc{'MeanPressure'}.units = ncchar('counts'); nc{'MeanPressure'}.valid_range = ncfloat([0 4095]); nc{'MeanPressure'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanVelx'} = ncfloat('burst'); nc{'MeanVelx'}.long_name = ncchar('Mean velocity in instrument coordinate x for Burst'); nc{'MeanVelx'}.units = ncchar('cm s-1'); nc{'MeanVelx'}.valid_range = ncfloat([-32768 32767]); nc{'MeanVelx'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanVely'} = ncfloat('burst'); nc{'MeanVely'}.long_name = ncchar('Mean velocity in instrument coordinate y for Burst'); nc{'MeanVely'}.units = ncchar('cm s-1'); nc{'MeanVely'}.valid_range = ncfloat([-32768 32767]); nc{'MeanVely'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanVelz'} = ncfloat('burst'); nc{'MeanVelz'}.long_name = ncchar('Mean velocity in instrument coordinate z for Burst'); nc{'MeanVelz'}.units = ncchar('cm s-1'); nc{'MeanVelz'}.valid_range = ncfloat([-32768 32767]); nc{'MeanVelz'}.FillValue_ = ncfloat(1.0e+035); nc{'StdAmp'} = ncfloat('burst','axis'); nc{'StdAmp'}.long_name = ncchar('Amplitude Standard Deviation for Burst'); nc{'StdAmp'}.units = ncchar('counts'); nc{'StdAmp'}.valid_range = ncfloat([-32768 32767]); nc{'StdAmp'}.FillValue_ = ncfloat(1.0e+035); nc{'StdCorr'} = ncfloat('burst','axis'); nc{'StdCorr'}.long_name = ncchar('Correlation Standard Deviation for Burst'); nc{'StdCorr'}.units = ncchar('counts'); nc{'StdCorr'}.valid_range = ncfloat([-32768 32768]); nc{'StdCorr'}.FillValue_ = ncfloat(1.0e+035); nc{'StdHeading'} = ncfloat('burst'); nc{'StdHeading'}.long_name = ncchar('Heading Standard Deviation for Burst'); nc{'StdHeading'}.units = ncchar('degrees'); nc{'StdHeading'}.valid_range = ncfloat([0 359.9999]); nc{'StdHeading'}.FillValue_ = ncfloat(1.0e+035); nc{'StdPitch'} = ncfloat('burst'); nc{'StdPitch'}.long_name = ncchar('Pitch Standard Deviation for Burst'); nc{'StdPitch'}.units = ncchar('degrees'); nc{'StdPitch'}.valid_range = ncfloat([-20 20]); nc{'StdPitch'}.FillValue_ = ncfloat(1.0e+035); nc{'StdRoll'} = ncfloat('burst'); nc{'StdRoll'}.long_name = ncchar('Roll Standard Deviation for Burst'); nc{'StdRoll'}.units = ncchar('degrees'); nc{'StdRoll'}.valid_range = ncfloat([-20 20]); nc{'StdRoll'}.FillValue_ = ncfloat(1.0e+035); nc{'StdTemperature'} = ncfloat('burst'); nc{'StdTemperature'}.units = ncchar('degrees'); nc{'StdTemperature'}.long_name = ncchar('Transducer Temperature Standard Deviation for Burst'); nc{'StdTemperature'}.FillValue_ = ncfloat(1.0e+035); nc{'StdTemperature'}.valid_range = ncfloat([-5 40]); nc{'StdPressure'} = ncfloat('burst'); nc{'StdPressure'}.long_name = ncchar('Pressure Standard Deviation for Burst'); nc{'StdPressure'}.units = ncchar('counts'); nc{'StdPressure'}.valid_range = ncfloat([0 4095]); nc{'StdPressure'}.FillValue_ = ncfloat(1.0e+035); nc{'StdVelx'} = ncfloat('burst'); nc{'StdVelx'}.long_name = ncchar('Velocity Std Deviation in instrument coordinate x for Burst'); nc{'StdVelx'}.units = ncchar('cm s-1'); nc{'StdVelx'}.valid_range = ncfloat([-32768 32767]); nc{'StdVelx'}.FillValue_ = ncfloat(1.0e+035); nc{'StdVely'} = ncfloat('burst'); nc{'StdVely'}.long_name = ncchar('Velocity Std Deviation in instrument coordinate y for Burst'); nc{'StdVely'}.units = ncchar('cm s-1'); nc{'StdVely'}.valid_range = ncfloat([-32768 32767]); nc{'StdVely'}.FillValue_ = ncfloat(1.0e+035); nc{'StdVelz'} = ncfloat('burst'); nc{'StdVelz'}.long_name = ncchar('Velocity Std Deviation in instrument coordinate z for Burst'); nc{'StdVelz'}.units = ncchar('cm s-1'); nc{'StdVelz'}.valid_range = ncfloat([-32768 32767]); nc{'StdVelz'}.FillValue_ = ncfloat(1.0e+035); nc{'soundspd'} = ncfloat('burst'); nc{'soundspd'}.long_name = ncchar('sound velocity (m/s)'); nc{'soundspd'}.units = ncchar('m s-1'); nc{'soundspd'}.FillValue_ = ncfloat(1.0e+035); nc{'soundspd'}.epic_code = nclong(80); nc{'soundspd'}.valid_range = nclong([1400 1600]); case 2 % added by Marinna nc{'time'} = ncdouble('burst','sample'); nc{'time'}.units = ncchar('decimal days'); nc{'time'}.long_name = ncchar('JULIAN DAYS'); nc{'time'}.FillValue_ = ncdouble(1e+035); nc{'time'}.epic_code = nclong(627); nc{'time'}.valid_min = nclong(0); nc{'time2'} = ncdouble('burst','sample'); nc{'time2'}.FORTRAN_format = ncchar('F10.2'); nc{'time2'}.units = ncchar('msec'); nc{'time2'}.type = ncchar('UNEVEN'); nc{'time2'}.long_name = ncchar('msec since 0:00 GMT'); nc{'time2'}.FillValue_ = ncdouble(1e+035); nc{'time2'}.epic_code = nclong(624); nc{'time2'}.valid_min = nclong(0); nc{'Vx'} = ncfloat('burst','sample'); nc{'Vx'}.units = ncchar('cm s-1'); nc{'Vx'}.long_name = ncchar('velocity in instrument coordinate x'); nc{'Vx'}.FillValue_ = nclong(1.0e+035); nc{'Vx'}.valid_range = ncfloat([-32768 32767]); nc{'Vy'} = ncfloat('burst','sample'); nc{'Vy'}.units = ncchar('cm s-1'); nc{'Vy'}.long_name = ncchar('velocity in instrument coordinate y'); nc{'Vy'}.FillValue_ = nclong(1.0e+035); nc{'Vy'}.valid_range = ncfloat([-32768 32767]); nc{'Vz'} = ncfloat('burst','sample'); nc{'Vz'}.units = ncchar('cm s-1'); nc{'Vz'}.long_name = ncchar('velocity in instrument coordinate z'); nc{'Vz'}.FillValue_ = nclong(1.0e+035); nc{'Vz'}.valid_range = ncfloat([-32768 32767]); nc{'amp'} = ncfloat('burst','sample','axis'); nc{'amp'}.units = ncchar(''); nc{'amp'}.long_name = ncchar('Beam amplitude'); nc{'amp'}.FillValue_ = ncfloat(1.0e+035); nc{'amp'}.valid_range = ncfloat([-32768 32767]); nc{'corr'} = ncfloat('burst','sample','axis'); nc{'corr'}.units = ncchar(''); nc{'corr'}.long_name = ncchar('Beam correlation'); nc{'corr'}.FillValue_ = ncfloat(1.0e+035); nc{'corr'}.valid_range = ncfloat([-32768 32767]); nc{'heading'} = ncfloat('burst','sample'); nc{'heading'}.units = ncchar('degrees'); nc{'heading'}.long_name = ncchar('INST Heading'); nc{'heading'}.epic_code = nclong(1215); nc{'heading'}.FillValue_ = ncfloat(1.0e+035); nc{'heading'}.valid_range = ncfloat([0 359.9999]); nc{'pitch'} = ncfloat('burst','sample'); nc{'pitch'}.units = ncchar('degrees'); nc{'pitch'}.long_name = ncchar('INST Pitch'); nc{'pitch'}.epic_code = nclong(1216); nc{'pitch'}.FillValue_ = ncfloat(1.0e+035); nc{'pitch'}.valid_range = ncfloat([-20 20]); nc{'roll'} = ncfloat('burst','sample'); nc{'roll'}.units = ncchar('degrees'); nc{'roll'}.long_name = ncchar('INST roll'); nc{'roll'}.epic_code = nclong(1217); nc{'roll'}.FillValue_ = ncfloat(1.0e+035); nc{'roll'}.valid_range = ncfloat([-20 20]); nc{'temperature'} = ncfloat('burst','sample'); nc{'temperature'}.units = ncchar('degrees'); nc{'temperature'}.long_name = ncchar('ADV Transducer Temperature'); nc{'temperature'}.epic_code = nclong(20); nc{'temperature'}.FillValue_ = ncfloat(1.0e+035); nc{'temperature'}.valid_range = ncfloat([-5 40]); nc{'pressure'} = ncfloat('burst','sample'); nc{'pressure'}.long_name = ncchar('PRESSURE'); nc{'pressure'}.units = ncchar('counts'); nc{'pressure'}.epic_code = nclong(1); nc{'pressure'}.valid_range = ncfloat([0 4095]); nc{'pressure'}.FillValue_ = ncfloat(1.0e+035); nc{'extsensor1'} = ncfloat('burst','sample'); nc{'extsensor1'}.units = ncchar('counts'); nc{'extsensor1'}.long_name = ncchar('raw data from external sensor channel 1'); nc{'extsensor1'}.valid_range = ncfloat([0 10000]); nc{'extsensor1'}.FillValue_ = ncfloat(1.0e+035); nc{'extsensor2'} = ncfloat('burst','sample'); nc{'extsensor2'}.units = ncchar('counts'); nc{'extsensor2'}.long_name = ncchar('raw data from external sensor channel 2'); nc{'extsensor2'}.valid_range = ncfloat([0 10000]); nc{'extsensor2'}.FillValue_ = ncfloat(1.0e+035); nc{'extpress'} = ncfloat('burst','sample'); nc{'extpress'}.long_name = ncchar('raw data from external pressure sensor'); nc{'extpress'}.units = ncchar('counts'); nc{'extpress'}.valid_range = ncfloat([0 10000]); nc{'extpress'}.FillValue_ = ncfloat(1.0e+035); nc{'extpressfreq'} = ncfloat('burst','sample'); nc{'extpressfreq'}.long_name = ncchar('pressure frequency'); nc{'extpressfreq'}.units = ncchar('Hz'); nc{'extpressfreq'}.epic_code = nclong(1); nc{'extpressfreq'}.valid_range = ncfloat([10000 40000]); nc{'extpressfreq'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_temp'} = ncfloat('burst'); nc{'CTD_temp'}.long_name = ncchar('CTD Temperature Probe'); nc{'CTD_temp'}.units = ncchar('Degrees Celcius'); nc{'CTD_temp'}.valid_range = ncfloat([-5 40]); nc{'CTD_temp'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_cond'} = ncfloat('burst'); nc{'CTD_cond'}.long_name = ncchar('CTD Conductivity Probe'); nc{'CTD_cond'}.units = ncchar('siemens'); %nc{'CTD_cond'}.valid_range = ncfloat([ ]); NEED nc{'CTD_cond'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_press'} = ncfloat('burst'); nc{'CTD_press'}.long_name = ncchar('CTD Pressure Sensor'); nc{'CTD_press'}.units = ncchar('dbar'); %nc{'CTD_press'}.valid_range = ncfloat([ ]); NEED nc{'CTD_press'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_sal'} = ncfloat('burst'); nc{'CTD_sal'}.long_name = ncchar('CTD Salinity Reading'); nc{'CTD_sal'}.units = ncchar('PSU'); %nc{'CTD_sal'}.valid_range = ncfloat([ ]); NEED nc{'CTD_sal'}.FillValue_ = ncfloat(1.0e+035); case 3 % added by Marinna nc{'time'} = ncdouble('burst','sample'); nc{'time'}.units = ncchar('decimal days'); nc{'time'}.long_name = ncchar('JULIAN DAYS'); nc{'time'}.FillValue_ = ncdouble(1e+035); nc{'time'}.epic_code = nclong(627); nc{'time'}.valid_min = nclong(0); nc{'time2'} = ncdouble('burst','sample'); nc{'time2'}.FORTRAN_format = ncchar('F10.2'); nc{'time2'}.units = ncchar('msec'); nc{'time2'}.type = ncchar('UNEVEN'); nc{'time2'}.long_name = ncchar('msec since 0:00 GMT'); nc{'time2'}.FillValue_ = ncdouble(1e+035); nc{'time2'}.epic_code = nclong(624); nc{'time2'}.valid_min = nclong(0); nc{'Vx'} = ncfloat('burst','sample'); nc{'Vx'}.units = ncchar('cm s-1'); nc{'Vx'}.long_name = ncchar('velocity in instrument coordinate x'); nc{'Vx'}.FillValue_ = nclong(1.0e+035); nc{'Vx'}.valid_range = ncfloat([-32768 32767]); nc{'Vy'} = ncfloat('burst','sample'); nc{'Vy'}.units = ncchar('cm s-1'); nc{'Vy'}.long_name = ncchar('velocity in instrument coordinate y'); nc{'Vy'}.FillValue_ = nclong(1.0e+035); nc{'Vy'}.valid_range = ncfloat([-32768 32767]); nc{'Vz'} = ncfloat('burst','sample'); nc{'Vz'}.units = ncchar('cm s-1'); nc{'Vz'}.long_name = ncchar('velocity in instrument coordinate z'); nc{'Vz'}.FillValue_ = nclong(1.0e+035); nc{'Vz'}.valid_range = ncfloat([-32768 32767]); nc{'amp'} = ncfloat('burst','sample','axis'); nc{'amp'}.units = ncchar(''); nc{'amp'}.long_name = ncchar('Beam amplitude'); nc{'amp'}.FillValue_ = ncfloat(1.0e+035); nc{'amp'}.valid_range = ncfloat([-32768 32767]); nc{'corr'} = ncfloat('burst','sample','axis'); nc{'corr'}.units = ncchar(''); nc{'corr'}.long_name = ncchar('Beam correlation'); nc{'corr'}.FillValue_ = ncfloat(1.0e+035); nc{'corr'}.valid_range = ncfloat([-32768 32767]); nc{'heading'} = ncfloat('burst','sample'); nc{'heading'}.units = ncchar('degrees'); nc{'heading'}.long_name = ncchar('INST Heading'); nc{'heading'}.epic_code = nclong(1215); nc{'heading'}.FillValue_ = ncfloat(1.0e+035); nc{'heading'}.valid_range = ncfloat([0 359.9999]); nc{'pitch'} = ncfloat('burst','sample'); nc{'pitch'}.units = ncchar('degrees'); nc{'pitch'}.long_name = ncchar('INST Pitch'); nc{'pitch'}.epic_code = nclong(1216); nc{'pitch'}.FillValue_ = ncfloat(1.0e+035); nc{'pitch'}.valid_range = ncfloat([-20 20]); nc{'roll'} = ncfloat('burst','sample'); nc{'roll'}.units = ncchar('degrees'); nc{'roll'}.long_name = ncchar('INST roll'); nc{'roll'}.epic_code = nclong(1217); nc{'roll'}.FillValue_ = ncfloat(1.0e+035); nc{'roll'}.valid_range = ncfloat([-20 20]); nc{'temperature'} = ncfloat('burst','sample'); nc{'temperature'}.units = ncchar('degrees'); nc{'temperature'}.long_name = ncchar('ADV Transducer Temperature'); nc{'temperature'}.epic_code = nclong(20); nc{'temperature'}.FillValue_ = ncfloat(1.0e+035); nc{'temperature'}.valid_range = ncfloat([-5 40]); nc{'pressure'} = ncfloat('burst','sample'); nc{'pressure'}.long_name = ncchar('PRESSURE'); nc{'pressure'}.units = ncchar('counts'); nc{'pressure'}.epic_code = nclong(1); nc{'pressure'}.valid_range = ncfloat([0 4095]); nc{'pressure'}.FillValue_ = ncfloat(1.0e+035); nc{'extsensor1'} = ncfloat('burst','sample'); nc{'extsensor1'}.units = ncchar('counts'); nc{'extsensor1'}.long_name = ncchar('raw data from external sensor channel 1'); nc{'extsensor1'}.valid_range = ncfloat([0 10000]); nc{'extsensor1'}.FillValue_ = ncfloat(1.0e+035); nc{'extsensor2'} = ncfloat('burst','sample'); nc{'extsensor2'}.units = ncchar('counts'); nc{'extsensor2'}.long_name = ncchar('raw data from external sensor channel 2'); nc{'extsensor2'}.valid_range = ncfloat([0 10000]); nc{'extsensor2'}.FillValue_ = ncfloat(1.0e+035); nc{'extpress'} = ncfloat('burst','sample'); nc{'extpress'}.long_name = ncchar('raw data from external pressure sensor'); nc{'extpress'}.units = ncchar('counts'); nc{'extpress'}.valid_range = ncfloat([0 10000]); nc{'extpress'}.FillValue_ = ncfloat(1.0e+035); nc{'extpressfreq'} = ncfloat('burst','sample'); nc{'extpressfreq'}.long_name = ncchar('pressure frequency'); nc{'extpressfreq'}.units = ncchar('Hz'); nc{'extpressfreq'}.epic_code = nclong(1); nc{'extpressfreq'}.valid_range = ncfloat([10000 40000]); nc{'extpressfreq'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_temp'} = ncfloat('burst'); nc{'CTD_temp'}.long_name = ncchar('CTD Temperature Probe'); nc{'CTD_temp'}.units = ncchar('Degrees Celcius'); nc{'CTD_temp'}.valid_range = ncfloat([-5 40]); nc{'CTD_temp'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_cond'} = ncfloat('burst'); nc{'CTD_cond'}.long_name = ncchar('CTD Conductivity Probe'); nc{'CTD_cond'}.units = ncchar('siemens'); %nc{'CTD_cond'}.valid_range = ncfloat([ ]); NEED nc{'CTD_cond'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_press'} = ncfloat('burst'); nc{'CTD_press'}.long_name = ncchar('CTD Pressure Sensor'); nc{'CTD_press'}.units = ncchar('dbar'); %nc{'CTD_press'}.valid_range = ncfloat([ ]); NEED nc{'CTD_press'}.FillValue_ = ncfloat(1.0e+035); nc{'CTD_sal'} = ncfloat('burst'); nc{'CTD_sal'}.long_name = ncchar('CTD Salinity Reading'); nc{'CTD_sal'}.units = ncchar('PSU'); %nc{'CTD_sal'}.valid_range = ncfloat([ ]); NEED nc{'CTD_sal'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanAmp'} = ncfloat('burst','axis'); nc{'MeanAmp'}.long_name = ncchar('Mean Amplitude for Burst'); nc{'MeanAmp'}.units = ncchar('counts'); nc{'MeanAmp'}.valid_range = ncfloat([-32768 32767]); nc{'MeanAmp'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanCorr'} = ncfloat('burst','axis'); nc{'MeanCorr'}.long_name = ncchar('Mean Correlation for Burst'); nc{'MeanCorr'}.units = ncchar('counts'); nc{'MeanCorr'}.valid_range = ncfloat([-32768 32768]); nc{'MeanCorr'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanHeading'} = ncfloat('burst'); nc{'MeanHeading'}.long_name = ncchar('Mean Heading for Burst'); nc{'MeanHeading'}.units = ncchar('degrees'); nc{'MeanHeading'}.valid_range = ncfloat([0 359.9999]); nc{'MeanHeading'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanPitch'} = ncfloat('burst'); nc{'MeanPitch'}.long_name = ncchar('Mean Pitch for Burst'); nc{'MeanPitch'}.units = ncchar('degrees'); nc{'MeanPitch'}.valid_range = ncfloat([-20 20]); nc{'MeanPitch'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanRoll'} = ncfloat('burst'); nc{'MeanRoll'}.long_name = ncchar('Mean Roll for Burst'); nc{'MeanRoll'}.units = ncchar('degrees'); nc{'MeanRoll'}.valid_range = ncfloat([-20 20]); nc{'MeanRoll'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanTemperature'} = ncfloat('burst'); nc{'MeanTemperature'}.units = ncchar('degrees'); nc{'MeanTemperature'}.long_name = ncchar('Mean Transducer Temperature for Burst'); nc{'MeanTemperature'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanTemperature'}.valid_range = ncfloat([-5 40]); nc{'MeanPressure'} = ncfloat('burst'); nc{'MeanPressure'}.long_name = ncchar('Mean Pressure for Burst'); nc{'MeanPressure'}.units = ncchar('counts'); nc{'MeanPressure'}.valid_range = ncfloat([0 4095]); nc{'MeanPressure'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanVelx'} = ncfloat('burst'); nc{'MeanVelx'}.long_name = ncchar('Mean velocity in instrument coordinate x for Burst'); nc{'MeanVelx'}.units = ncchar('cm s-1'); nc{'MeanVelx'}.valid_range = ncfloat([-32768 32767]); nc{'MeanVelx'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanVely'} = ncfloat('burst'); nc{'MeanVely'}.long_name = ncchar('Mean velocity in instrument coordinate y for Burst'); nc{'MeanVely'}.units = ncchar('cm s-1'); nc{'MeanVely'}.valid_range = ncfloat([-32768 32767]); nc{'MeanVely'}.FillValue_ = ncfloat(1.0e+035); nc{'MeanVelz'} = ncfloat('burst'); nc{'MeanVelz'}.long_name = ncchar('Mean velocity in instrument coordinate z for Burst'); nc{'MeanVelz'}.units = ncchar('cm s-1'); nc{'MeanVelz'}.valid_range = ncfloat([-32768 32767]); nc{'MeanVelz'}.FillValue_ = ncfloat(1.0e+035); nc{'StdAmp'} = ncfloat('burst','axis'); nc{'StdAmp'}.long_name = ncchar('Amplitude Standard Deviation for Burst'); nc{'StdAmp'}.units = ncchar('counts'); nc{'StdAmp'}.valid_range = ncfloat([-32768 32767]); nc{'StdAmp'}.FillValue_ = ncfloat(1.0e+035); nc{'StdCorr'} = ncfloat('burst','axis'); nc{'StdCorr'}.long_name = ncchar('Correlation Standard Deviation for Burst'); nc{'StdCorr'}.units = ncchar('counts'); nc{'StdCorr'}.valid_range = ncfloat([-32768 32768]); nc{'StdCorr'}.FillValue_ = ncfloat(1.0e+035); nc{'StdHeading'} = ncfloat('burst'); nc{'StdHeading'}.long_name = ncchar('Heading Standard Deviation for Burst'); nc{'StdHeading'}.units = ncchar('degrees'); nc{'StdHeading'}.valid_range = ncfloat([0 359.9999]); nc{'StdHeading'}.FillValue_ = ncfloat(1.0e+035); nc{'StdPitch'} = ncfloat('burst'); nc{'StdPitch'}.long_name = ncchar('Pitch Standard Deviation for Burst'); nc{'StdPitch'}.units = ncchar('degrees'); nc{'StdPitch'}.valid_range = ncfloat([-20 20]); nc{'StdPitch'}.FillValue_ = ncfloat(1.0e+035); nc{'StdRoll'} = ncfloat('burst'); nc{'StdRoll'}.long_name = ncchar('Roll Standard Deviation for Burst'); nc{'StdRoll'}.units = ncchar('degrees'); nc{'StdRoll'}.valid_range = ncfloat([-20 20]); nc{'StdRoll'}.FillValue_ = ncfloat(1.0e+035); nc{'StdTemperature'} = ncfloat('burst'); nc{'StdTemperature'}.units = ncchar('degrees'); nc{'StdTemperature'}.long_name = ncchar('Transducer Temperature Standard Deviation for Burst'); nc{'StdTemperature'}.FillValue_ = ncfloat(1.0e+035); nc{'StdTemperature'}.valid_range = ncfloat([-5 40]); nc{'StdPressure'} = ncfloat('burst'); nc{'StdPressure'}.long_name = ncchar('Pressure Standard Deviation for Burst'); nc{'StdPressure'}.units = ncchar('counts'); nc{'StdPressure'}.valid_range = ncfloat([0 4095]); nc{'StdPressure'}.FillValue_ = ncfloat(1.0e+035); nc{'StdVelx'} = ncfloat('burst'); nc{'StdVelx'}.long_name = ncchar('Velocity Std Deviation in instrument coordinate x for Burst'); nc{'StdVelx'}.units = ncchar('cm s-1'); nc{'StdVelx'}.valid_range = ncfloat([-32768 32767]); nc{'StdVelx'}.FillValue_ = ncfloat(1.0e+035); nc{'StdVely'} = ncfloat('burst'); nc{'StdVely'}.long_name = ncchar('Velocity Std Deviation in instrument coordinate y for Burst'); nc{'StdVely'}.units = ncchar('cm s-1'); nc{'StdVely'}.valid_range = ncfloat([-32768 32767]); nc{'StdVely'}.FillValue_ = ncfloat(1.0e+035); nc{'StdVelz'} = ncfloat('burst'); nc{'StdVelz'}.long_name = ncchar('Velocity Std Deviation in instrument coordinate z for Burst'); nc{'StdVelz'}.units = ncchar('cm s-1'); nc{'StdVelz'}.valid_range = ncfloat([-32768 32767]); nc{'StdVelz'}.FillValue_ = ncfloat(1.0e+035); nc{'soundspd'} = ncfloat('burst'); nc{'soundspd'}.long_name = ncchar('sound velocity (m/s)'); nc{'soundspd'}.units = ncchar('m s-1'); nc{'soundspd'}.FillValue_ = ncfloat(1.0e+035); nc{'soundspd'}.epic_code = nclong(80); nc{'soundspd'}.valid_range = nclong([1400 1600]); end %end switch %Read and write data blocks (one data block for each sampling burst) % Burst Header Information (60 bytes) including date and time from the real-time clock % a time-series of samples collected during the burst, and % statistics calculated at the end of each burst, optional (36 bytes) % The size of the data block will depend on the data recording % parameters. % The end of the burst is a 2-byte checksum while ~feof(fid) % Reading Burst Header (60 bytes) fseek(fid,14,0); %skip to burst number BurstNumber = fread(fid,1,'uint32'); if isempty(BurstNumber) break; end % Test for complete burst if BurstNumber > maxBurst break; end % Place the data in NetCDF file without blanks or fill values for % skipped burst numbers all = 1:nBursts; count = minBurst:maxBurst; placement = find(count==BurstNumber); index = all(placement); if BurstNumber >= minBurst & BurstNumber <= maxBurst; nc{'burstNum'}(index) = BurstNumber; disp(['Now Reading Burst Number ',num2str(BurstNumber),'...']) y = fread(fid,1,'int16'); d = fread(fid,1,'char'); m = fread(fid,1,'char'); min = fread(fid,1,'char'); hour = fread(fid,1,'char'); hs = fread(fid,1,'char'); sec = fread(fid,1,'char'); % Marinna made changes here fseek(fid,2,0); %skip Velocity range index list and spare %fread(fid,2,'uint16'); %sample rate and samples per burst sampleinterval = 1/(fread(fid,1,'uint16').*0.01); % stored by Hydra in Hz*100, converted to sec here nsamplesthisburst = fread(fid,1,'uint16'); %samples per burst % expand time so there is a time stamp for every sample % assume that a burst is never going to be longer than a day time1 = ones(1,nsamplesthisburst).*julian([y m d 0 0 0]); % julian day time2 = (0:sampleinterval:((nsamplesthisburst.*sampleinterval)-sampleinterval)).*1000; % in msec from start of burst % time2 is the start of burst in milliseconds from the start of the julian day time2 = time2 + hour.*(3600*1000)+... % hours to milliseconds min.*(60*1000)+... % minutes to milliseconds sec.*(1000)+... % seconds to milliseconds hs.*10; % hundredths of seconds to milliseconds % but account for those bursts that extend over the day boundary rolloveridx = find(time2 >= 1000*60*60*24); % find amounts greater than the # of milliseconds in the day if ~isempty(rolloveridx), time2(rolloveridx) = time2(rolloveridx) - 1000*60*60*24; % we will add a day to time 1 for these time1(rolloveridx) = time1(rolloveridx) + 1; % these are technically in the next day end switch DataType case 1, % statistics only, we need time as the middle of the burst tjstart = time1(1)+time2(1)./(3600*24*1000); tjend = time1(end)+time2(end)./(3600*24*1000); tjmid = tjstart+(tjend-tjstart)/2; nc{'time'}(index) = floor(tjmid); nc{'time2'}(index) = (tjmid - floor(tjmid)).*(3600*24*1000); otherwise nc{'time'}(index,:) = time1; nc{'time2'}(index,:) = time2; end %clear y d m min hour hs sec fseek(fid,2,0); %skip coord system and recorded data nc{'soundspd'}(index) = fread(fid,1,'uint16')*0.1; %m/s nc{'brange'}(index) = fread(fid,1,'int16')*0.01; %cm/s nc{'vrange'}(index) = fread(fid,1,'int16')*0.01; %cm/s status = fread(fid,[1,20],'uchar')'; clear status %leave out of *.cdf file for now. Don't seem to need. % Reading Variables % Format to read variables is fread(fid,number of samples,precision,skip) % VELOCITY velx = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.01; %cm/s fseek(fid,-BytesPerSample*nSamples(1)+2,0); %rewind to get vel2 vely = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.01; %cm/s fseek(fid,-BytesPerSample*nSamples(1)+2,0); %rewind to get vel3 velz = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.01; %cm/s fseek(fid,-BytesPerSample*nSamples(1)+2,0); %rewind to get amp and corr nc{'Vx'}(index,:) = velx; nc{'Vy'}(index,:) = vely; nc{'Vz'}(index,:) = velz; mnvelx = mean(velx); stdvelx = std(velx); mnvely = mean(vely); stdvely = std(vely); mnvelz = mean(velz); stdvelz = std(velz); clear velx vely velz % AMPLITUDE AND CORRELATION if isequal(b(1),'1') for kk=1:6 ampcorr(:,kk) = fread(fid,nSamples(1),'uchar',BytesPerSample-1); fseek(fid,-BytesPerSample*nSamples(1)+1,0); %rewind to get Heading end nc{'amp'}(index,:,:) = ampcorr(:,1:3); %amplitude for beams 1-3, counts nc{'corr'}(index,:,:)= ampcorr(:,4:6); %Correlation for beams 1-3, counts else for kk=1:2 ampcorr(:,kk) = fread(fid,nSamples(1),'uchar',BytesPerSample-1); fseek(fid,-BytesPerSample*nSamples(1)+1,0); %rewind to get Heading end nc{'amp'}(index,:,:) = ampcorr(:,1); %Mean Amp nc{'corr'}(index,:,:) = ampcorr(:,2); %Mean Corr end clear ampcorr kk % HEADING, PITCH, ROLL if isequal(b(2),'1') nc{'heading'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.1; %heading degrees fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get Pitch nc{'pitch'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.1; %pitch degrees fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get Roll nc{'roll'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.1; %roll degrees fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get Temperature end % TEMPERATURE AND PRESSURE if isequal(b(3),'1') nc{'temperature'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2)*0.01; %temperature degrees C fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get Pressure nc{'pressure'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2); %pressure in counts fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get External Sensor Channel 1 end % EXTERNAL SENSORS if isequal(b(6),'1') nc{'extsensor1'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2); %external sensor channel 1 in counts fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get External Sensor Channel 2 nc{'extsensor2'}(index,:) = fread(fid,nSamples(1),'int16',BytesPerSample-2); %external sensor channel 2 in counts fseek(fid,-nSamples(1)*BytesPerSample+2,0); %rewind to get External Pressure end % EXTERNAL PRESSURE if isequal(b(7),'1') pcount = fread(fid,nSamples(1),'ubit24',(BytesPerSample-3)*8); % millidbars (paros)/milliHz (Druck/ParosFreq) % if the user put in the wrong pressure offset, fix it PressFreqOffset = nc.PressFreqOffset(:); [pcount, nfixed] = fixparosoverflow(pcount,PressFreqOffset); if nfixed > 0, disp(sprintf('fixed %d pressure samples for bit overflow',nfixed)); end nc{'extpress'}(index,:) = pcount; PressFreq = (PressFreqOffset.*1000000 + pcount).*0.001; % shift left 16 bits nc{'extpressfreq'}(index,:) = PressFreq; % millidbars (paros)/milliHz (Druck/ParosFreq) fseek(fid,-nSamples(1)*BytesPerSample+3,0); %rewind to get Statistics end % Skip to end of burst to check for statistics fseek(fid,BytesPerSample*(nSamples-1),0); % STATISTICS (Means and Standard Deviations) if isequal(b(5),'1') means = [fread(fid,[1,6],'uchar'),... fread(fid,[1,3],'int16'),... fread(fid,1,'int16'),... fread(fid,[1,1],'int32')]; stds = [fread(fid,[1,6],'uchar'),... fread(fid,[1,3],'int16'),... fread(fid,1,'int16'),... fread(fid,[1,1],'int16')]; nc{'MeanAmp'}(index,:) = means(1:3); %mean amplitude for beams 1-3, counts nc{'MeanCorr'}(index,:)= means(4:6); %mean correlation for beams 1-3, counts nc{'MeanHeading'}(index) = means(7)*0.1; %degrees nc{'MeanPitch'}(index) = means(8)*0.1; %degrees nc{'MeanRoll'}(index) = means(9)*0.1; %degrees nc{'MeanTemperature'}(index) = means(10)*0.01; %degrees nc{'MeanPressure'}(index) = means(11); %counts nc{'MeanVelx'}(index) = mnvelx; nc{'MeanVely'}(index) = mnvely; nc{'MeanVelz'}(index) = mnvelz; nc{'StdAmp'}(index,:) = stds(1:3); %std deviation amplitude for beams 1-3, counts nc{'StdCorr'}(index,:)= stds(4:6); %std deviation correlation for beams 1-3, counts nc{'StdHeading'}(index) = stds(7)*0.1; %degrees nc{'StdPitch'}(index) = stds(8)*0.1; %degrees nc{'StdRoll'}(index) = stds(9)*0.1; %degrees nc{'StdTemperature'}(index) = stds(10)*0.01; %degrees nc{'StdPressure'}(index) = stds(11); %counts nc{'StdVelx'}(index) = stdvelx; nc{'StdVely'}(index) = stdvely; nc{'StdVelz'}(index) = stdvelz; SoundSpeedStat = fread(fid,1,'uint16')*0.1; % meters per second clear SoundSpeedStat means stds mnvel* stdvel* end % CTD if isequal(b(8),'1') CTD = fread(fid,[1,4],'int32'); nc{'CTD_temp'}(index) = CTD(1)*0.0001; %degrees C nc{'CTD_cond'}(index) = CTD(2)*0.00001; %siemens nc{'CTD_press'}(index) = CTD(3)*0.001; %dbar nc{'CTD_sal'}(index) = CTD(4)*0.0001; %PSU clear CTD end % CHECKSUM - End of Sample fseek(fid,2,0); %checksum else burstsize = rflag(4)*38 + rflag(1)*16 + nSamples(1)*BytesPerSample + 60-18; fseek(fid,burstsize,0); end %end if BurstNumber >= minBurst & BurstNumber <= maxBurst loop end %end while ~feof(fid) loop %nc.StartTime = %nc.StopTime = nc.history = ['Converted to netCDF via MATLAB by adr2cdf.m ', prog_ver]; disp('Closing netCDF file, this may take some time...') fclose(fid); close (nc) disp(sprintf('Finished conversion of %d bursts in %f minutes', maxBurst-minBurst, toc/60))