% get_pressures_lite.m
% MEZ 10/14/2014
% read EPICS vacuum data from Y arm and GV7 cap 
%
tic; % start data retrieval timer
duration =  3600 * 2 * 60 ; % seconds
% duration =  3600 * 36 ; % seconds
matstart = now - (duration+120)/(3600*24); % matlab date corresponding to gps start
gpsstart =    gps('now') - duration - 120;   % GPS sec
% 120 s buffer seems to avoid errors seeking recent data not yet written 
daterun = now;
clear press; 
press = get_data({...
    'LVE-EY:Y1_723BTORR','LVE-BY:Y26_990BTORR', 'LVE-BY:Y24_984BTORR', ...
    'LVE-MY:Y1_753BTORR','LVE-BY:Y16_970BTORR', 'LVE-BY:Y14_964BTORR', ...
    'LVE-BY:Y12_958BTORR', 'LVE-LY:Y4_624BTORR'...
    },'raw', gpsstart, duration);
%
clear capdat; 
capdat = get_data({...
    'LVE-MY:Y6_758TORR','LVE-MY:Y2_754BTORR', 'LVE-MY:Y2_754ATORR', ...
    'LVE-MY:Y3_755ATORR','LVE-MY:Y4_756TORR', 'LVE-MY:Y5_757TORR' ...
    },'raw', gpsstart, duration); 
%
clear tempdat; 
tempdat = get_data({...
    'LVE-BY:Y27_BT_TEMP_C','LVE-BY:Y24_BT_TEMP_C', 'LVE-BY:Y21_BT_TEMP_C', ...
    'LVE-BY:Y17_BT_TEMP_C','LVE-BY:Y14_BT_TEMP_C', 'LVE-BY:Y11_BT_TEMP_C'...
    },'raw', gpsstart, duration); 
% decimate from raw 16 Hz to 1 Hz
for j=1:max((size(press)))
    press(j).data = decimate(press(j).data, 16);
    press(j).rate = press(j).rate/16;
end
%
for j=1:max((size(capdat)))
    capdat(j).data = decimate(capdat(j).data, 16);
    capdat(j).rate = capdat(j).rate/16;
end
%
for j=1:max((size(tempdat)))
    tempdat(j).data = decimate(tempdat(j).data, 16);
    tempdat(j).rate = tempdat(j).rate/16;
end
toc % report elapsed time required to retrieve & decimate data
filename=['/data/zucker/pressure',num2str(gpsstart),'.mat'];
save(filename); % save everything
%


