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