function ocr3000ToNetCDF (deployment,configfile) %function ssds_netcdf_multwavelengths_test (netCDF_path, fileroot, mooring, rad_name, files, suffixes) %script for producing netcdf files that are compatible with Mike McCann's %ssds framework. Creates a single netcdf file for all 5 ocr3000s on M0- 9 %selected wavelengths for each. % % % Created by Seth M. Bushinsky(sethb@mbari.org) December 2006 %%BASE_DIR = regexprep(pwd, 'cimt', ''); % Assume user is in their cimt dir BASE_DIR = '/u/ssdsadmin/dev/DPforSSDS/'; % Add dods and netcdf to path if necessary if(isempty (strfind(path, 'netcdf_toolbox'))), % loaddap should be in the default matlab path (/usr/local/DODS_ml/bin) % The old unsupported toolbox addpath([BASE_DIR 'mexcdf/snctools']); addpath([BASE_DIR 'mexcdf/netcdf_toolbox/netcdf']); addpath([BASE_DIR 'mexcdf/netcdf_toolbox/netcdf/nctype']); addpath([BASE_DIR 'mexcdf/netcdf_toolbox/netcdf/ncutility']); % mexnc for x86_a64 - Important: add this last so that it's first addpath([BASE_DIR 'mexnc']); end % set up some useful constants rad_name = 'ocr3000'; %basePath = pwd; prop = readProperties(configfile); mooring.name = getProperty(prop, 'mooring'); radiometer_names = getProperty(prop, [mooring.name '.radiometers']); suffixes = {'_mean', '_median'}; %suffixTitles = {'Mean', 'Median'}; netCDF_path = MBARI_path(getProperty(prop, 'netCDF_path')); netCDF_path = [netCDF_path '/' deployment]; delim = ','; coms = strfind(radiometer_names,delim); first = 1; for v = 1:length(coms)+1, if v == length(coms)+1, radiometers{v} = radiometer_names(first:end); radiometers{v} = radiometers{v}(find(~isspace(radiometers{v}))); else radiometers{v} = radiometer_names(first:coms(v)-1); first = coms(v)+1; radiometers{v} = radiometers{v}(find(~isspace(radiometers{v}))); end end disp('writing netcdf files for ssds'); wavelengths= [410 440 490 510 550 610 650 670 700]; %creates a new file ssds_nc_filename = [netCDF_path '/ssds_netcdf/test/' mooring.name ... '_' rad_name '_ssds.nc']; disp(['Opening file for writing: ' ssds_nc_filename]); ssds_nc_file = netcdf(ssds_nc_filename, 'clobber'); %Initialize dimensions ssds_nc_file('latitude') = 1; ssds_nc_file('longitude') = 1; %Initialize variables, copies lat and lon from original netcdf ssds_nc_file{'latitude'} = ncdouble('latitude'); ssds_nc_file{'latitude'}.units = 'degrees North'; ssds_nc_file{'longitude'} = ncdouble('longitude'); ssds_nc_file{'longitude'}.units = 'degrees East'; warning off all %matching to specific wavelength(int32) generates error message for rad =1:length(radiometers), for suf = 1:length(suffixes), fileroot = [char(radiometers(rad)) char(suffixes(suf))]; %opens and reads the netcdf file being used for plotting nc_filename = ([netCDF_path '/' fileroot '.nc']); fid = fopen(nc_filename); if(fid == -1) close; nc_filename = [netCDF_path '/' mooring.name '_ocr_' fileroot '.nc']; fid = fopen(nc_filename); if (fid == -1) close; return end end fclose(fid); %opens the netcdf file according to the radiometer name and suffix nc_file = netcdf(nc_filename); ssds_nc_file{'latitude'}(:) = nc_file{'latitude'}(:); ssds_nc_file{'longitude'}(:) = nc_file{'longitude'}(:); %finds the variable with multiple dimensions - contains the %radiometer data for vars = length(ncnames(var(nc_file))) : -1 : 1, var_dims = length(dim(nc_file{vars})); if(var_dims > 1) var_name = char(ncnames(nc_file{vars})); break; end end %new_times is the record of instrument times that are not already %written to the ssds_netcdf file new_times = nc_file{'time'}(1:end); %gets all of the wavelengths into spectra spectra = squeeze(nc_file{var_name}(1:end,:)); if isempty(spectra), break, end %searches the time record, removes any time stamps that do not %increase. Does this until there are no negative or 0 increases- %makes the time series monotonic y = diff([0;new_times]); w = find(y>=0); mono_time = new_times(w); mono_spectra = spectra(w,:); neg = 1; while (isempty(neg)==0), q = diff([0;mono_time]); w = find(q>0); neg = find(q<=0); mono_time = mono_time(w); mono_spectra = mono_spectra(w,:); end ssds_nc_file(['time_' fileroot]) = length(mono_time); ssds_nc_file(['depth_' fileroot]) = 1; ssds_nc_file{['time_' fileroot]} = ncdouble(['time_' fileroot]); ssds_nc_file{['time_' fileroot]}.units = 'seconds since 1970-01-01 00:00:00'; ssds_nc_file{['time_' fileroot]}.long_name = 'time GMT'; ssds_nc_file{['time_' fileroot]}(:) = mono_time; ssds_nc_file{['depth_' fileroot]} = ncfloat (['depth_' fileroot]); ssds_nc_file{['depth_' fileroot]}.units = 'meters'; ssds_nc_file{['depth_' fileroot]}(:) = nc_file{'depth'}(:); if size(spectra)==[1 1], ssds_nc_file{fileroot} = ncfloat(['time_' fileroot], ['depth_' fileroot],'latitude', 'longitude'); ssds_nc_file{fileroot}.units = nc_file{var_name}.units(:); ssds_nc_file{fileroot} = [var_name char(suffixes(suf)) '_' wavelength_name] ssds_nc_file{fileroot} = spectra; else for lambda = 1:length(wavelengths), wavelength_name = num2str(wavelengths(lambda)); %finds the wavelength index that matches 'lambda'. selects that %wavelength out of spectra. wave_index = find(int32(nc_file{'wavelength'}(:))==wavelengths(lambda)); spectra_wave = mono_spectra(:,wave_index); if isempty(spectra_wave), break, else %writes the new data and times to the ssds_nc_file ssds_nc_file{[fileroot '_' wavelength_name]} = ncfloat(['time_' fileroot], ['depth_' fileroot],'latitude', 'longitude'); ssds_nc_file{[fileroot '_' wavelength_name]}.units = nc_file{var_name}.units(:); ssds_nc_file{[fileroot '_' wavelength_name]}.long_name = [var_name char(suffixes(suf)) '_' wavelength_name]; ssds_nc_file{[fileroot '_' wavelength_name]}(:) = spectra_wave; end end end close(nc_file); end end derived_vars = {'chl_490_Kd_0_10_mean'; 'Kd_0_10_mean'}; for rad =1:length(derived_vars), fileroot = char(derived_vars(rad)); %opens and reads the netcdf file being used for plotting nc_filename = ([netCDF_path '/' fileroot '.nc']); fid = fopen(nc_filename); if(fid == -1) close; nc_filename = [netCDF_path '/' mooring.name '_ocr_' fileroot '.nc']; fid = fopen(nc_filename); if (fid == -1) close; return end end fclose(fid); %opens the netcdf file according to the radiometer name and suffix nc_file = netcdf(nc_filename); %finds the variable with multiple dimensions - contains the %radiometer data for vars = length(ncnames(var(nc_file))) : -1 : 1, var_dims = length(dim(nc_file{vars})); if(var_dims > 1) var_name = char(ncnames(nc_file{vars})); break; end end %new_times is the record of instrument times that are not already %written to the ssds_netcdf file new_times = nc_file{'time'}(1:end); %gets all of the wavelengths into spectra spectra = squeeze(nc_file{var_name}(1:end,:)); if isempty(spectra), break, end %searches the time record, removes any time stamps that do not %increase. Does this until there are no negative or 0 increases- %makes the time series monotonic y = diff([0;new_times]); w = find(y>=0); mono_time = new_times(w); mono_spectra = spectra(w,:); neg = 1; while (isempty(neg)==0), q = diff([0;mono_time]); w = find(q>0); neg = find(q<=0); mono_time = mono_time(w); mono_spectra = mono_spectra(w,:); end ssds_nc_file(['time_' fileroot]) = length(mono_time); ssds_nc_file(['depth_' fileroot]) = 1; ssds_nc_file{['time_' fileroot]} = ncdouble(['time_' fileroot]); ssds_nc_file{['time_' fileroot]}.units = 'seconds since 1970-01-01 00:00:00'; ssds_nc_file{['time_' fileroot]}.long_name = 'time GMT'; ssds_nc_file{['time_' fileroot]}(:) = mono_time; ssds_nc_file{['depth_' fileroot]} = ncfloat (['depth_' fileroot]); ssds_nc_file{['depth_' fileroot]}.units = 'meters'; ssds_nc_file{['depth_' fileroot]}(:) = nc_file{'depth'}(:); if wavelength_name = '490'; %finds the wavelength index that matches 'lambda'. selects that %wavelength out of spectra. wave_index = find(int32(nc_file{'wavelength'}(:))==wavelengths(lambda)); spectra_wave = mono_spectra(:,wave_index); if isempty(spectra_wave), break, else %writes the new data and times to the ssds_nc_file ssds_nc_file{[fileroot '_' wavelength_name]} = ncfloat(['time_' fileroot], ['depth_' fileroot],'latitude', 'longitude'); ssds_nc_file{[fileroot '_' wavelength_name]}.units = 'W m-2'; ssds_nc_file{[fileroot '_' wavelength_name]}.long_name = [var_name char(suffixes(suf)) '_' wavelength_name]; ssds_nc_file{[fileroot '_' wavelength_name]}(:) = spectra_wave; end close(nc_file); end close(ssds_nc_file); disp('ocr3000ToNetCDF() done.'); return;