%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function eco_netCDF_store(c_time, prop, p, ecodata, netCDF_path, ... units, n_samples, dataset, suffix) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Store data in a netCDF file mooring.name = getProperty(prop, 'mooring'); for ecodata_index = 1:length(ecodata), ncfilename = [netCDF_path '/' p.ecotype '.nc']; ncfile = netcdf(ncfilename, 'write'); % Check to see if file has any records, if not then index=0, otherwise % get the last time.. if(size(ncfile,2)==0 || isempty(ncfile{'time'}(end))), lastTime(ecodata_index) = 0; else lastTime(ecodata_index) = ncfile{'time'}(end); end start_index = size(c_time,2); %Number of columns while start_index >= 1 ... && lastTime(ecodata_index) >= c_time(ecodata_index,start_index), start_index = start_index - 1; %From the last to the first find where to begin writing. end if start_index >= 1, if(lastTime(ecodata_index) == 0), % if the netCDF file is empty then add attributes close(ncfile) ncfile = netcdf(ncfilename, 'clobber'); %Initialize Attributes ncfile.waterdepth = getProperty(prop, [mooring.name '.waterdepth']); ncfile.waterdepth_units = getProperty(prop, [mooring.name '.waterdepth_units']); [Year Month Day] = datevec(now); dateS = sprintf('%02i/%02i/%04i', Month, Day, Year); ncfile.creationdate = dateS; %datestr(now) ncfile.mooring = mooring.name; % Initialize Dimensions ncfile('time') = 0; % Dimension 'time' is the Record Dimension ncfile{'time'} = nclong('time'); % Varaible 'time' stored as double ncfile{'time'}.long_name = getProperty(prop, 'time.long_name'); ncfile{'time'}.units = getProperty(prop, 'time.units'); ncfile.latitude = str2num(getProperty(prop, [mooring.name '.latitude'])); ncfile.latitude = str2num(getProperty(prop, [mooring.name '.longitude'])); ncfile.depth = str2num(getProperty(prop, [channel '.depth'])); % Initialize Variables %ncfile{ecodata} = ncfloat('time','depth','latitude','longitude','wavelength'); ncfile{ecodata} = ncfloat('time','wavelength'); ncfile{ecodata}.long_name = getProperty(prop, 'ecodata.long_name'); ncfile{ecodata}.units = getProperty(prop, 'ecodata.units'); ncfile{ecodata}.FillValue_ = -9999; ncfile{ecodata}.missing_value = -9999; ncfile{'sample_count'} = ncshort('time'); ncfile{'sample_count'}.long_name = 'samples per measurement'; end %if(lastTime(ecodata_index) == 0) [Year Month Day] = datevec(now); dateS = sprintf('%02i/%02i/%04i', Month, Day, Year); ncfile.lastmodified = dateS; nc_index = length(ncfile{'time'}(:)); for time_index = start_index : -1 : 1, ncfile{'time'}(nc_index) = c_time(ecodata_index,time_index); %ncfile{ecodata}(nc_index,1,1,1,:) = squeeze(dataset(ecodata_index,:,time_index)); ncfile{ecodata}(nc_index,:) = squeeze(dataset(ecodata_index,:,time_index)); ncfile{'sample_count'}(nc_index) = n_samples(ecodata_index,time_index); nc_index = nc_index + 1; end %time_index = start_index : -1 : 1 end %start_index >= 1 close(ncfile); end %ecodata_index = 1:length(ecodata) return