function aqd2nc(cdfFile,OutFile,metadata) % function aqd2nc('cdfFile','OutFile') % % Function to take raw aquadopp 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. Once data are in netCDF, you can plot to % determine when the first and last good ensembles are. % % Required input: % 'cdfFile' - Raw Netcdf data file base name (.cdf) % 'OutFile' - base name for output data file - use mooring number % good_ens - vector of good ensembles [first_good last_good] based on in % and out of water times if nargin<1 help(mfilename) return end autonan_on cdf = netcdf([cdfFile,'.cdf']); % cdf = autonan(cdf,1); %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); start = datenum2julian(datenum(cdf.Deployment_date(:))); finish = datenum2julian(datenum(cdf.Recovery_date(:))); ind = find(jd>=start&jd<=finish); gtime = gregorian(jd); N = ind(end); n = (find(diff(gtime(:,6))>0, 1 ) | find(diff(gtime(:,5))>0, 1 )); 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); end end if exist('AnaInp2','var') varname = 'NEP2_56';f{varname} = ncfloat('time');Aobj = f{varname}; Aobj(1:N) = opchan2(:,1); atts = att(cdf{'AnalogInput2'}); % Aobj.long_name = ncchar('Nephylometer'); for i = 1:length(atts),copy(atts{i},Aobj),end; if isfield(metadata.AnalogInput1,'cals') if ~isempty(metadata.AnalogInput1.cals.NTUcoef) Aobj.units = ncchar('NTU'); else Aobj.units = ncchar('volts'); end end 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); end end add_minmaxvalues(f) autonan_off disp(['Data written to ' OutFile '-cal.nc']) close(cdf) close(f)