% iGp_read_BESSY    - Script to read out data and plot mean/RMS/spectrum
%
% Copyright (c) 2012 Dimtel, Inc., All Rights Reserved
%
% $Id: iGp_read_BESSY.m,v 1.1 2013/01/04 09:56:12 dim Exp $
% $Date: 2013/01/04 09:56:12 $
% $Author: dim $
% $Revision: 1.1 $
% $Log: iGp_read_BESSY.m,v $
% Revision 1.1  2013/01/04 09:56:12  dim
% Created from iGp_read.m, added BBQR root, DCCT
%
%

vars=who;
for k=1:length(vars)
  if (~strcmp(vars{k}, 'sys') && ~strcmp(vars{k}, 'acq') && ...
      ~strcmp(vars{k}, 'acq_cnt') && ~strcmp(vars{k}, 'acq_unit'))
    clear(vars{k});
  end
end

prm.root='BBQR';

prm.debug = 1;
if (exist('sys', 'var'))
  prm.sys = sys;
else
  prm.sys = input('iGp12 device name [TEST]: ', 's');
end
if (isempty(prm.sys))
  prm.sys = 'TEST';
end

prm.fpga_rev = lcaGet(['BBQR:', prm.sys, ':REVISION']);

if (prm.fpga_rev >= 3.04)
  if(exist('acq_unit', 'var'))
    prm.acq_unit = acq_unit;
  else
    prm.acq_unit = input('Acquisition subsystem (BRAM or SRAM) [SRAM]: ', 's');
  end
  if (isempty(prm.acq_unit))
    prm.acq_unit = 'SRAM';
  end
end

%prm.dcct = 'MDIZ3T5G:current';

% Figure out the directory
prm.tm = datestr(now, 'HH:MM:SS');
prm.tm(3:4)=prm.tm(4:5); prm.tm(5:6)=prm.tm(7:8); prm.tm = prm.tm(1:6);
unix(['mkdir ', prm.tm]);

[status, prm] = iGp_gd(prm);

if (status && ~exist('acq_cnt', 'var'))
  disp(['Created data set [', prm.tm, ']. Plotting...']);
  eval(['cd ', prm.tm]);
  iGp_plt
  cd ..
end
