function [nstd1,Astd1,Sstd1] = std_id(k,Tr,Pr);

% gets mean area and standard deviation for the set k of 
% standards, as well as Tr and Pr from stand.dat
% called by profiles.m to calculate concentrations.
% k comes from std_nums.txt

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% function [nstd1,Astd1,Sstd1] = std_id(k,n_all);
%%
%% input parameters k list standard numbers
%% Tr is the lab temperature for the stds
%% Pr is the lab pressure
%% returns nstd1,2 - vector of moles for each standard size 
%%	   Astd1,2 - vector of mean peak areas for each standard size
%%	   Sstd1,2 - vector of standard deviation of peak area 
%%
%% 11april97 sww; Modified 9/4/98 by Ledwell for Polarstern 98 cruise
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

load const.mat		% const.mat loads values for:	
			% VL = volume of large sample loop
			% VS = volume of 5-ml sample loop
			% f1,2 = mixing ratio in standard 1,2
         % conv = conv=1E15*273.15/(22400*1013); 
         % must mulitply conv by P/T of the lab

n_all = [n1S n1L; n2S n2L];	% fmoles @ STP for std 1, 2
% load in standard data file; this file contains three columns:
% standard number, standard id, and peak area

load stand.txt
ns = stand(:,1);	% sequence number for standards
id=stand(:,2);		% identifying code for standard
			% This is a change from previous cruises, in order
			% 4-digit number:
         % 1st digit = standard (1 or 2)
			% 2nd digit = number of large loops injected
			% 3rd digit = number of super (5 ml) loops
          % 4th digit = trap number (1 or 2)           
As=stand(:,3);		% area for the standards

y1 = 0; y2 = 0;
szk = size(k,2);
Astd1=[]; Sstd1=[]; nstd1=[]; areas1=[]; cnt1=[];
for i = 1:szk
  ind_a = find(ns == k(i));    	%% ind_a: index of standard number k1(i) in 
  %% the full standard data number list
  charid = num2str(id(ind_a));
  type = str2num(charid(1));
  disp(int2str(k(i)));
  numS = str2num(charid(3));
  numL = str2num(charid(2));
  trap = str2num(charid(4));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% trap 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  if trap == 2
    y1 = 1; 
    vol = (numS*n_all(type,1) + numL*n_all(type,2))*(Pr/1013)*273.15/(Tr+273.15);
    f = find(nstd1 == vol);
    if isempty(f)
      nstd1 = [nstd1 vol];
      ind_b = size(nstd1,2);		%% ind_b: index of standard volume vol in
					%% the current list of volumes (nstd1)
      cnt1(ind_b) = 1;
    else
      ind_b = f;
      cnt1(ind_b) = cnt1(ind_b) +1;	%% cnt: number of standards with volume vol
    end
    areas1(cnt1(ind_b), ind_b) = As(ind_a);

    else
       error(['Error in standard number ',num2str(k(i)),': trap number must be 2'])
    end
end

if y1 == 1
% areas1
  for j = 1:size(cnt1,2)
    Astd1(j) = mean(areas1(1:cnt1(j),j));
    Sstd1(j) = std(areas1(1:cnt1(j),j));
  end
  [nstd1,h] = sort(nstd1);
  Astd1 = Astd1(h);
  Sstd1 = Sstd1(h);
end
