0001 function [n, npw, ts, wave] = plx_waves(filename, ch, u)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if(nargin ~= 3)
0017 disp('3 input arguments are required')
0018 return
0019 end
0020
0021 n = 0;
0022 npw = 0;
0023 ts = 0;
0024 wave = 0;
0025
0026 if(isempty(filename))
0027 [fname, pathname] = uigetfile('*.plx', 'Select a plx file');
0028 filename = strcat(pathname, fname);
0029 end
0030
0031 fid = fopen(filename, 'r');
0032 if(fid == -1)
0033 disp('cannot open file');
0034 return
0035 end
0036
0037 disp(strcat('file = ', filename));
0038
0039
0040 header = fread(fid, 64, 'int32');
0041 freq = header(35);
0042 ndsp = header(36);
0043 nevents = header(37);
0044 nslow = header(38);
0045 npw = header(39);
0046 npr = header(40);
0047 tscounts = fread(fid, [5, 130], 'int32');
0048 wfcounts = fread(fid, [5, 130], 'int32');
0049 evcounts = fread(fid, [1, 512], 'int32');
0050
0051
0052 fseek(fid, 1020*ndsp + 296*nevents + 296*nslow, 'cof');
0053
0054 record = 0;
0055 wave = zeros(npw, 1);
0056 wf = zeros(npw, 1);
0057
0058
0059 while feof(fid) == 0
0060 type = fread(fid, 1, 'int16');
0061 upperbyte = fread(fid, 1, 'int16');
0062 timestamp = fread(fid, 1, 'int32');
0063 channel = fread(fid, 1, 'int16');
0064 unit = fread(fid, 1, 'int16');
0065 nwf = fread(fid, 1, 'int16');
0066 nwords = fread(fid, 1, 'int16');
0067 toread = nwords;
0068 if toread > 0
0069 wf = fread(fid, [toread, 1], 'int16');
0070 end
0071 if toread > 0
0072 if type == 1
0073 if channel == ch
0074 if unit == u
0075 n = n + 1;
0076 ts(n) = timestamp/freq;
0077 wave(:, n) = wf;
0078 end
0079 end
0080 end
0081 end
0082
0083 record = record + 1;
0084 if feof(fid) == 1
0085 break
0086 end
0087
0088 end
0089 disp(strcat('number of waveforms = ', num2str(n)));
0090
0091 fclose(fid);