function output_array = ecobb_calibrate(input_array,p,prop) % ecobb_calibrate - Provide calibrated output data for the BB2F. % % Use as: output_array = ecobb_calibrate(input_array) % % Inputs: input_array = Array of raw counts data. % % Output: output_array = an array of raw and calibrated data elements. % % Example: % output_array = ecobb_calibrate(input_array) % Where Col(1)=datenum, Col(2)=reference, Col(3)=signal, and Col(4)=thermistor. % MC Harlan 21 Nov 2003 % rpm 27 May 2004 Modified to read cal from file. % Read the calibration constants from cal file disp(['Calibrations for device ', p.dev, ', ECOBB ', p.serial]) ANGLE=str2num(getProperty(prop,'calibration.ANGLE')); WAVELEN=str2num(getProperty(prop,'calibration.WAVELEN')); DARK_CNTS=str2num(getProperty(prop,'calibration.DARK_CNTS')); CAL_SW=str2num(getProperty(prop,'calibration.CAL_SW')); SCALE_FACTOR=str2num(getProperty(prop,'calibration.SCALE_FACTOR')); X=str2num(getProperty(prop,'calibration.X')); SAL=str2num(getProperty(prop,'calibration.SAL')); [rows,cols] = size(input_array); % returns the size of matrix X in separate variables. %t=zeros(rows,3); %fprintf(1,'rows=%d cols=%d\n', rows, cols); %output_array = [input_array,t];clear t;save i:\bog\matlab\ecobb.mat; output_array = input_array; % Calculations are from the WetLabs Scattering Meter ECO-BB User's Guide, % see \\tornado\diatom\CIMT\documentation\ECO % Volume scattering of water (Morel, 1974) Bw = (1.38 * (WAVELEN/500) ^ -4.32) * ((1 + (0.3 * SAL)/37)*10 ^ -4) * (1 + (cos(117))^2) * ((1 - 0.09) / (1 + 0.09)); for row = 1:rows raw_cnts = input_array(row, 8); % RANGE = 0 to 4120 counts B_117_700 = (raw_cnts - DARK_CNTS) * SCALE_FACTOR; % volume scatter coefficients, units are m-1 sr-1t Bp = B_117_700 - Bw; % Particle beta, scattering of particles. b_bp = 2 * pi * X * Bp; %Particulate backscattering coefficients (m-1) b_sw = 0.0029308 * (WAVELEN/500) ^ -4.24; % total scattering of seawater t_bbs = b_bp + (b_sw / 2.0); %Total backscattering coefficients bb(l) units m-1 output_array(row, cols+1) = t_bbs; output_array(row, cols+2) = B_117_700; output_array(row, cols+3) = Bp; end % assign variable names for output file sdn=output_array(:,1); % serial date number timestamp ecobbraw=output_array(:,8); % averaged raw backscatter counts siam_date=output_array(:,4); % SIAM style timestamp ecobbtempraw=output_array(:,5); % averaged raw thermistor counts otime=output_array(:,6); % OASIS style timestamp ecobbrefraw=output_array(:,7); % averaged raw reference light counts ecobbcal=output_array(:,9); %calibrated backscatter ecobbvol=output_array(:,10); %volume scattering coefficients ecobbpart=output_array(:,11); % volume scattering of particulates only jday=date2jul(sdn); year=datestr(sdn,10); date_time=datestr(sdn,0); hours=datestr(sdn,15); hour=(str2num(hours(:,1))*10)+str2num(hours(:,2)); min=(str2num(hours(:,4))*10)+str2num(hours(:,5)); jtime=jday+((hour/24) + ((min/60)/24)); pacific_date = sdn-(7/24); output_array(:, cols+4) = pacific_date; % write to output file if strcmp(p.otype,'plot') outfile=[p.ddir,'/ecobb_calibrated.csv'];t='w'; else outfile=[p.ddir,'/ecobb.csv'];t='at+'; end %if strcmp(p.otype,'plot') fid=fopen(outfile,t); if t=='w' fprintf(fid,'%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n','%date_time','sdn','siam_date','year','jday','otime','ecobbcal','ecobbvol','ecobbpart','ecobbraw','ecotempraw','ecorefraw','pacific_time' ); end [row col]=size(output_array); for J=1: row fprintf(fid,'%s,%f,%f,%s,%i,%f,%f,%f,%f,%f,%f,%f,%f\n',date_time(J,:),sdn(J,:),siam_date(J,:),num2str(year(J,:)),jday(J,:),otime(J,:),ecobbcal(J,:),ecobbvol(J,:),ecobbpart(J,:),ecobbraw(J,:),ecobbtempraw(J,:) ,ecobbrefraw(J,:),pacific_date(J,:)); end fclose(fid); % Write to log file fid=fopen([p.ldir,'/',p.log],'at+'); fprintf(fid,'%s\n',[' 4. ECOBB_CALIBRATE: ',p.ecotype,' angle=', num2str(ANGLE), ' wavelen=',num2str(WAVELEN), ' dark_cnts=',num2str(DARK_CNTS)]); fprintf(fid,'%s\n',[' cal_sw=',num2str(CAL_SW), ' scale_factor=',num2str(SCALE_FACTOR), ' x=',num2str(X), ' sal=',num2str(SAL) ]); fprintf(fid,'%s\n',[' Rows processed: ',num2str(rows), ' columns processed: ', num2str(cols) ]); fprintf(fid,'%s\n',[' Calibrated data file: ',outfile]); fclose(fid); return;