function [cal, dev_cal, wl]=process_cal_acs111(fnam, channel, T, Tcal);

[t,dat,wla,wlc,itemp,xtemp]=rd_wetview_acs111(fnam);

tmp = xlsread('Sullivan_etal_2006_instrumentspecific.xls');
opts = optimset('fminsearch');      
opts = optimset(opts,'MaxIter',20000000); 
opts = optimset(opts,'MaxFunEvals',20000);
opts = optimset(opts,'TolX',1e-8);
opts = optimset(opts,'TolFun',1e-8);
tmp = xlsread('Sullivan_etal_2006_instrumentspecific.xls');

if channel=='c'
    phi_T=interp1(tmp(:,1),tmp(:,2),wlc,'linear');
    for i=1:length(wlc)
       cal_75=prctile(dat(:,i),75);
       cal_15=prctile(dat(:,i),15);
       I=find(dat(:,i)>=cal_15 & dat(:,i)<=cal_75);
       cal(i)=mean(dat(I,i));
       dev_cal(i)=cal_75-cal_15;
    end
    wl=wlc;
elseif channel=='a'
    phi_T=interp1(tmp(:,1),tmp(:,2),wla,'linear');
    for i=1+82:length(wla)+82
       cal_75=prctile(dat(:,i),75);
       cal_15=prctile(dat(:,i),15);
       I=find(dat(:,i)>=cal_15 & dat(:,i)<=cal_75);
       cal(i-82)=mean(dat(I,i));
       dev_cal(i-82)=cal_75-cal_15;
    end
    wl=wla;
end


I = find(wl>=710 & wl<=750);  % spectral srange for optimization (710 to 750nm)   
delT = 0;
offset = 0;
[x1] = fminsearch(@f_T, [delT, offset], opts, cal(I), phi_T(I), wl);
II=find(isfinite(phi_T)==0);
phi_T(II)=0;
cal=cal-x1(1).*phi_T;

