function VEL = AWAC2nc(CDFFile,outFile,metadata,varargin) % function AWAC2nc('CDFFile','OutFile',metadata,[good_ens]) % % Function to take raw AWAC profile data already in netCDF format, % perform rotations, correct pressure data and write to EPIC netCDF. % Data can be in either beam, earth or XYZ coordinates. Must do aqd2cdf % first to get raw data from binary to Matlab, and then translate raw % data into a netCDF file. You must have deployment and recovery times % entered into the metadata file in order to crop the bad data before and % after deployment, otherwise all data will be kept. % % Required input: % 'cdfFile' - Raw Netcdf data file base name (.cdf) without extension % 'OutFile' - base name for output data file - use mooring number % 'metadata' - metadata from the run script % Optional Input % good_ens - a vector of the first and last good ensembles to trim the % data by. If left empty, the deployment date and recovery date will % be used. % Program written in Matlab R2007 % Program updated in Matlab R2010a % Program ran on Apple MacIntosh OS 10.6.7 % % "Although this program has been used by the USGS, no warranty, % expressed or implied, is made by the USGS or the United States % Government as to the accuracy and functioning of the program % and related program material nor shall the fact of distribution % constitute any such warranty, and no responsibility is assumed % by the USGS in connection therewith." if nargin<1 help(mfilename) return end if nargin>3 good_ens = varargin; end autonan_on cdf = netcdf([CDFFile,'.cdf'],'nowrite'); %first determine if timeseries is not conintuous, an indication in the %aquadopp that the battery level was too low and it shut down and began %intermittent start/stop cycle, as battery power recharged. Although %data beyond this point is theoretically good, we'll cut it off for the %Best Basic Version to have a continuous timeseries time = cdf{'time'}(:); time2 = cdf{'time2'}(:); jd = time + (time2/86400000); deploy = datenum2julian(datenum(cdf.Deployment_date(:),0)); recover = datenum2julian(datenum(cdf.Recovery_date(:),0)); indx = find(jd>=deploy & jd<=recover); gtime = gregorian(jd); N = length(time); n = min(find(diff(gtime(:,6))>0)); if n1 %i.e., we have sed conc data as well varname = 'Sed1_981';f{varname} = ncfloat('time');Aobj = f{varname}; Aobj(1:N) = opchan1(:,2); Aobj.long_name = ncchar('Sediment Concentration'); for i = 1:length(atts),copy(atts{i},Aobj),end; Aobj.units = ncchar(metadata.AnalogInput1.cals.SEDcoefUnits); Aobj.sensor_depth = Wdepth - Aobj.initial_sensor_height; end end if exist('AnaInp2','var') varname = 'NEP2_56';f{varname} = ncfloat('time');Aobj = f{varname}; Aobj(1:N) = opchan2(:,1); Aobj.long_name = ncchar('Nephylometer'); atts = att(cdf{'AnalogInput2'}); for i = 1:length(atts),copy(atts{i},Aobj),end; if ~isempty(metadata.AnalogInput2.cals.NTUcoef) Aobj.units = ncchar('NTU'); else Aobj.units = ncchar('volts'); end Aobj.sensor_depth = Wdepth - Aobj.initial_sensor_height; if size(opchan2,2)>1 %i.e., we have sed conc data as well varname = 'Sed2_981';f{varname} = ncfloat('time');Aobj = f{varname}; Aobj(1:N) = opchan2(:,2); Aobj.long_name = ncchar('Sediment Concentration'); for i = 1:length(atts),copy(atts{i},Aobj),end; Aobj.units = ncchar(metadata.AnalogInput2.cals.SEDcoefUnits); Aobj.sensor_depth = Wdepth - Aobj.initial_sensor_height; end end add_fillvalues(f,theFillValue) % add_minmaxvalues(f) autonan_off disp(['Data written to ' outFile '-cal.nc']) close(cdf) close(f)