function netcdf_pco2(mooringDirectory, ncFilename, mooring) % NETCDF_PCO2 - create a netcdf file from pCO2 data % % Use as: netcdf_pco2(mooringDirectory, ncFilename, mooring) % % Inputs: mooringDirectory = Root directory of mooring directory tree % for example '\\tsunami.shore.mbari.org\oasis\m1' % ncFilename = Name of the netcdf file to be created. The file % created adheres to the COARDS and MBARI conventions % mooring = Id for the mooring. Example: 'M1'. This string is used to search % for properties in \\tsunami.shore.mbari.org\oasis\cfg\mooring.properties % file. % Brian Schlining % 20 Jul 2000 %=========== % Open File %=========== outfile = netcdf(ncFilename, 'clobber'); % outfile is a netcdf object if isempty(outfile) error(['Unable to create ' ncFilename]); end % % Read the pco.data and pco.cal files raw = readflatfile(fullfile(mooringDirectory, 'data', 'pco2.data')); [buf i] = unique(raw(:,1)); raw = raw(i, :); rawTime = raw(:,1); rawData = raw(:,2); clear raw cal = readflatfile(fullfile(mooringDirectory, 'data', 'pco2.cal')); [buf i] = unique(cal(:,1)); cal = cal(i, :); calTime = cal(:,1); cal = cal(:,2); % Create a column of corrected data and a column of interpolated cal data % Interpolate cals to the same times as the data calI = interp1(calTime, cal, rawTime); % get corrected data calData = rawData - calI; calData(find(isnan(calData))) = -999; %================================================================= % Construct Netcdf schema for a single microcat on eqpac moorings %================================================================= [Year Month Day] = datevec(now); dateS = sprintf('%02i/%02i/%04i', Month, Day, Year); outfile.conventions = 'MBARI/timeSeries/mooring/pco2'; outfile.creationDate = dateS; outfile.lastModified = dateS; if nargin < 3 mooring = upper(input('Enter mooring ID: ')); % Needed to specify mooring location end fprintf(1,'Creating netcdf schema') outfile.mooring = mooring; outfile.description = 'pCO2 data'; % Give location based on user input %try % prop = readProperties('g:\cfg\mooring.properties'); %catch % prop = readProperties('\\tsunami.shore.mbari.org\oasis\cfg\mooring.properties'); %end prop = readProperties(fullfile([getOasisPath 'cfg'], 'mooring.properties')); lon = str2num(getProperty(prop, [lower(mooring) '.longitude'])); if lon < 0 lonS = [num2str(abs(lon)) 'W']; else lonS = [num2str(lon) 'E']; end lat = str2num(getProperty(prop, [lower(mooring) '.latitude'])); if lat < 0 latS = [num2str(abs(lat)) 'S']; else latS = [num2str(lat) 'N']; end outfile.longitude = lonS; outfile.latitude = latS; outfile.waterDepth = getProperty(prop, [lower(mooring) '.waterdepth']); outfile.keywords = 'pCO2'; outfile.instumentType = 'pCO2 Can'; outfile('latitude') = 1; % Dimension outfile{'latitude'} = ncdouble('latitude'); % Specify Co-ordinate variable dimensions outfile{'latitude'}.long_name = 'Latitude'; outfile{'latitude'}.units = 'degrees_north'; outfile{'latitude'}(:) = lat; outfile('longitude') = 1; % Dimension outfile{'longitude'} = ncdouble('longitude'); % Specify Co-ordinate variable dimensions outfile{'longitude'}.long_name = 'Longitude'; outfile{'longitude'}.units = 'degrees_east'; outfile{'longitude'}(:) = lon; outfile('depth') = 1; % Dimension outfile{'depth'} = ncdouble('depth'); % Specify Co-ordinate variable dimensions outfile{'depth'}.long_name = 'Depth'; outfile{'depth'}.units = 'meters'; outfile{'depth'}.positive = 'down'; outfile{'depth'}(:) = 0; outfile('time') = 0; % Define Unlimited dimension outfile{'time'} = ncdouble('time'); outfile{'time'}.long_name = 'time GMT'; outfile{'time'}.units = 'seconds since 1970-01-01 00:00:00'; % outfile{'raw'} = ncfloat('time','depth','longitude','latitude'); % outfile{'raw'}.long_name = 'uncalibrated pCO2'; % outfile{'raw'}.units = 'microatm'; % outfile{'raw'}.symbol = 'pCO2u'; % outfile{'raw'}.FillValue_ = -999; % outfile{'raw'}.missing_value = -999; outfile{'pco2'} = ncfloat('time','depth','longitude','latitude'); outfile{'pco2'}.long_name = 'calibrated pCO2'; outfile{'pco2'}.units = 'microatm'; outfile{'pco2'}.symbol = 'pCO2'; outfile{'pco2'}.FillValue_ = -999; outfile{'pco2'}.missing_value = -999; outfile{'time'}(1:length(rawTime)) = rawTime./1000; % outfile{'raw'}(:) = rawData; outfile{'pco2'}(:) = calData; ncquit(outfile)