function [stat_val]=cvt_o60_DOmgL(iname, oname) % cvt_o60_DOmgl - Seabirds and other sensors acquire and store data a ml/L, % for what Neil G. needs (models comparisons), mg/L is better. The YSI's % acquire and store mg/L, which I've called DO, since EPIC doesn't have a % name for it. This program converts Oxygen data (O_60) that's in ml/L to % mg/L. % % usage status_retruned=cvt_o60_DOmgL(input_cdfname, output_name) % both arguments are strings or char variables % returns 0 if there's a problem, otherwise 1 % % emontgomery@usgs.gov 3/2/11 %%% START USGS BOILERPLATE ------------- % Use of this program is self-described. % Programs written in Matlab- as early as 7.2.0.232 (R2006a) and % most recent modifications in v7.8.0 (R2009a) % Programs ran on PC with Windows XP Professional OS, and RHEL4 linux. % % "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." %%% END USGS BOILERPLATE -------------- if nargin ~= 2; help mfilename; return; end stat_val=0; if ~exist(iname,'file') [filename, pathname] = uigetfile('*.*', 'Pick a netcdf file for input'); iname=[pathname '/' filename]; oname=[filename '_DO']; % writes to CWD end nc=netcdf(iname); outc=netcdf(oname,'clobber'); varnms=ncnames(var(nc)); if isempty(find(strcmp(varnms,'O_60'))); disp('no O_60 variable to convert'); stat_val=1; else % prepare the file by copying everything % then make and populate the new variable % first set the coordinates (this sets up for being able to create the % new DO variable by the ncfloat() command outc('time') = 0; outc('depth') = 1; outc('lon') = 1; outc('lat') = 1; % copy global atts gatts=att(nc); for i = 1 : length(gatts); copy(gatts{i},outc); end % then copy all the data variables and those attributes for i=1:length(varnms) eval(['copy(nc{''' char(varnms(i)) '''},outc,1,1);']); end % now create the new variable outc{'DO'}=ncfloat('time','depth','lat','lon'); % copy the attributes copy(nc{'O_60'},outc{'DO'},0,1); % do the conversion and put the new data in the variable tmpDO=nc{'O_60'}(:)/.75497; %conversion factor from N. Ganju outc{'DO'}(:)=tmpDO; % modify the attributes outc{'DO'}.units(:)=('mg/L'); outc{'DO'}.long_name(:)='dissolved oxygen in seawater (mg/L)'; outc{'DO'}.note=ncchar('computed from O_60: (ml/L) / .75497 = mg/L'); outc{'DO'}.epic_code=[]; %remove this attribute stat_val=1; end close(nc) close (outc)