function flaq4C3(filenameS,samples,concentration)

% flaq4C3.m
% script to acquire data from Liquid Robotics digital C3's  for fluorometer intercalibration 
% digital C3's connectoed to a keyspan 4 port serial to usb 
% Luke Beatman; September 27, 2010

global s1 s2
% open user desiganted filename; if exists, append, if not create new
isfile = exist(filenameS,'file');
if isfile
  fid1 = fopen(filenameS,'at');
else
  fid1 = fopen(filenameS,'wt');
  fprintf(fid1,'%s\n','MBARI fluorometer intercalibration data file in preperation for October 2010 CANON cruises');
  fprintf(fid1,'%s\n',['Concentration Value for samples:' concentration]);
  fprintf(fid1,'%s\n','');
  fprintf(fid1,'%s\n','Column 1:YYYYMMDD');
  fprintf(fid1,'%s\n','Column 2:HHMMSS');
  fprintf(fid1,'%s\n','Column 3:Absolute Julian Day(matlab datenum)');
  fprintf(fid1,'%s\n','Column 4:RFU from Turner C3 s/n 2300244');
  fprintf(fid1,'%s\n','Column 5:Temperature from Turner C3 s/n 2300244');
  fprintf(fid1,'%s\n','Column 6:Pressure from Turner C3 s/n 2300244');
  fprintf(fid1,'%s\n','Column 7:RFU from Turner C3 s/n 2300241');
  fprintf(fid1,'%s\n','Column 8:Temperature from Turner C3 s/n 2300241');
  fprintf(fid1,'%s\n','Column 9:Pressure from Turner C3 s/n 2300241');
  fprintf(fid1,'%s\n','');
  fprintf(fid1,'%s\n','');
end

% open com port for communication with Turner C3 s/n 2300244
s1 = serial('com4');
set(s1,'inputbuffersize',200);
set(s1,'BaudRate',9600);
fopen(s1);
if s1.bytesavailable > 0
   junkstr = fread(s1,s1.bytesavailable);
end

% open com port for communication with Turner C3 s/n 2300241
s2 = serial('com6');
set(s2,'inputbuffersize',200);
set(s2,'BaudRate',9600);
fopen(s2);
if s2.bytesavailable > 0
   junkstr = fread(s2,s2.bytesavailable);
end
disp('Pausing data acquisition for initialization of Fuorometers')
pause(130)
%while go
for j = 1:samples
  %staledat = fread(s1,s1.bytesavailable);
  [dateS_inst,timeS_inst,absjday_inst,chlarfu_244,press_244,temp_244] = read_C3(s1);
  [dateS_inst,timeS_inst,absjday_inst,chlarfu_241,press_241,temp_241] = read_C3(s2);
  dttmS = datestr(now,'yyyymmddHHMMSS');
  absdecjday = datenum(str2num(dttmS(1:4)),str2num(dttmS(5:6)),str2num(dttmS(7:8)),str2num(dttmS(9:10)),str2num(dttmS(11:12)),str2num(dttmS(13:14)));
  dateS = dttmS(1:8);
  timeS = dttmS(9:14);
  fprintf(fid1,'%s,%s,%14.7f,%6.4f,%6.4f,%6.4f,%6.4f,%6.4f,%6.4f\n',dateS,timeS,absdecjday,chlarfu_244,temp_244,press_244,chlarfu_241,temp_241,press_241);
  fprintf('%s,%s,%14.7f,%6.4f,%6.4f,%6.4f,%6.4f,%6.4f,%6.4f\n',dateS,timeS,absdecjday,chlarfu_244,temp_244,press_244,chlarfu_241,temp_241,press_241);
  %pause(3)
end
fclose(fid1);
 