/mattlib/VirgoTools/getdataME.m

http://github.com/tobin/lentickle · Objective C · 142 lines · 128 code · 14 blank · 0 comment · 25 complexity · 6f1fbf3a4f764bd8b24bae782322796d MD5 · raw file

  1. % [dat, t] = getdataME(file, t0, dt, chan, [fSamp]);
  2. %
  3. % This function gets data from a frame file.
  4. %
  5. % ARGUMENTS
  6. % file : frame file (GWF or FFL), or cell array of file names to try
  7. % t0 : GPS starting time
  8. % dt : data duration, in seconds
  9. % chan : channel name, or cell array of names
  10. % fSamp : desired sampling frequency (optional)
  11. %
  12. % RETURNS
  13. % dat : data vector
  14. % t : time vector (optional)
  15. %
  16. % The defalut FFL files are added to the file list, so an empty
  17. % file argument will usually work.
  18. %
  19. % If fSamp is not specified, the sample rate of the first channel is
  20. % used for all channels.
  21. %
  22. % The time vector returned starts from t0 modulo 1000.
  23. %
  24. % Example:
  25. % % Get Pr_B8_DC, downsampled to 1kHz, and plot the result.
  26. % [dB8, tB8] = getdataME([], 795398359, 20, 'Pr_B8_DC', 1000);
  27. % plot(tB8, dB8)
  28. %
  29. % % Get more channels, at the rate of Pr_B8_DC (10kHz).
  30. % chanB8 = {'Pr_B8_DC' 'Pr_B8_d1_DC' 'Pr_B8_d1_ACp' 'Pr_B8_d1_ACq'};
  31. % [dB8, tB8] = getdataME([], 795398355, 10, chanB8);
  32. % plot(tB8, dB8)
  33. %
  34. % **** derived from Mmgetdata.m by M. Mantovani ****
  35. % Created: Thu Mar 17 17:43:44 CET 2005
  36. function [dat, t] = getdataME(file, t0, dt, chan, varargin)
  37. % prevent warning messages while loading
  38. warning('off', 'frgetvect:info');
  39. % Fixed parameters
  40. frameRate = 1.0; % frames per second...always 1
  41. % if file is not a cell, make it one
  42. if ~iscell(file)
  43. if isstr(file)
  44. if strcmp(file, 'trend')
  45. file = {'/virgoData/ffl/trend.ffl'};
  46. else
  47. file = {file};
  48. end
  49. elseif isempty(file)
  50. file = {};
  51. else
  52. error(['Invalid chan argument. Must be string ' ...
  53. 'or cell array of strings.'])
  54. end
  55. end
  56. % add default FFL files
  57. fileList = {file{:}, ...
  58. '/virgoData/ffl/raw.ffl', ... % main FFL file
  59. '/virgoData/ffl/raw_bak.ffl'}; % backup FFL file
  60. % if chan is not a cell, make it one
  61. if isstr(chan)
  62. chan = {chan};
  63. elseif ~iscell(chan)
  64. error('Invalid chan argument. Must be string or cell array of strings.')
  65. end
  66. Nchan = length(chan);
  67. if Nchan == 0
  68. dat = [];
  69. t = [];
  70. return
  71. end
  72. % compute fSamp
  73. if ~isempty(varargin)
  74. fSamp = varargin{1};
  75. else
  76. fSamp = [];
  77. end
  78. % get first data and prepare fSamp
  79. t_start = floor(t0 - 0.1);
  80. nframes = frameRate * ceil(t0 + dt - t_start + 0.1);
  81. for n = 1:length(fileList)
  82. if ~isstr(fileList{n})
  83. error('Invalid file name.');
  84. elseif ~isstr(chan{1})
  85. error('Invalid channel name #1.');
  86. end
  87. dat1 = frgetvect(fileList{n}, chan{1}, t_start, nframes);
  88. if ~isempty(dat1)
  89. file = fileList{n};
  90. break
  91. end
  92. end
  93. if isempty(dat1)
  94. error(['Unable to get data for ' chan{1}])
  95. end
  96. fChan = size(dat1, 1) * frameRate / nframes;
  97. if isempty(fSamp)
  98. fSamp = fChan;
  99. end
  100. % first and last sample to include in output
  101. n0 = floor((t0 - t_start) * fSamp) + 1;
  102. n1 = floor((t0 + dt - t_start) * fSamp);
  103. dat = zeros(n1 - n0 + 1, Nchan);
  104. if fChan == fSamp
  105. dat(:, 1) = dat1(n0:n1);
  106. else
  107. dat2 = resample(dat1, fSamp, fChan);
  108. dat(:, 1) = dat2(n0:n1);
  109. end
  110. % get data more and resample
  111. for n = 2:Nchan
  112. if ~isstr(chan{n})
  113. error('Invalid channel name #%d.', n);
  114. end
  115. dat1 = frgetvect(file, chan{n}, t_start, nframes);
  116. fChan = size(dat1, 1) * frameRate / nframes;
  117. if fChan == fSamp
  118. dat(:, n) = dat1(n0:n1);
  119. else
  120. dat2 = resample(dat1, fSamp, fChan);
  121. dat(:, n) = dat2(n0:n1);
  122. end
  123. end
  124. % set time vector
  125. if nargout == 2
  126. % t = mod(t_start, 1000) + (n0:n1)' / fSamp;
  127. t = t_start + (n0:n1)' / fSamp;
  128. end