function [Z_new,cval] = f_oc412_spec_scale(Z,vv);
% Make nonlinear scale for Alexandrium data.
% Olga Kosnyreva, AOPE/WHOI, Jan 2003

%*************************
% Data normalization.
%*************************
coefCoenf = 0;
valueCoenfZero = 0;
%coefCoenf = 0.005; % confidential coefficient 
%valueCoenfZero = 0; % confidential coefficient for 'zero'.
count = 0;
for i = 1:1:length(vv)-1
   count = count+1;
   if count==1
      % Specify new values - area for contour lines (zero line).
      r_cont = find(Z(:)<=vv(i)+valueCoenfZero & Z(:)>=0);
      Z(r_cont) = Z(r_cont) / vv(i+1);
      % Specify new values - area between contour lines.
      r_betwCont = find(Z(:)>vv(i)+valueCoenfZero & Z(:)<vv(i+1)*(1-coefCoenf));
      Z(r_betwCont) = 0.5;
   elseif count==length(vv)-1
      % Specify new values - area for contour lines.
      r_cont = find(Z(:)<=vv(i)*(1+coefCoenf) & Z(:)>=vv(i)*(1-coefCoenf) );
      Z(r_cont) = (Z(r_cont) / vv(i+1)) * (count-1);
      % Specify new values - area between contour lines.
      r_betwCont = find(Z(:)>vv(i)*(1+coefCoenf));
      Z(r_betwCont) = (count-1) +0.5;
      %Z(r_betwCont) = count;
   else
      % Specify new values - area for contour lines.
      r_cont = find(Z(:)<=vv(i)*(1+coefCoenf) & Z(:)>=vv(i)*(1-coefCoenf) );
      Z(r_cont) = (Z(r_cont) / vv(i+1)) * (count-1);
      %Z(r_cont) = count-1;
      % Specify new values - area between contour lines.
      r_betwCont = find(Z(:)>vv(i)*(1+coefCoenf) & Z(:)<vv(i+1)*(1-coefCoenf));
      Z(r_betwCont) = (count-1) +0.5;
   end
end
Z_new=Z;
% Contour line values (Normalized data).
qmin = 0;
qmax = length(vv)-1;
dq = 1;
cval=qmin:dq:qmax;
