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