plx_waves.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/REC-html40/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Description of plx_waves</title>
  6. <meta name="keywords" content="plx_waves">
  7. <meta name="description" content="plx_waves(filename, channel, unit): Read waveform data from a .plx file">
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  9. <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  10. <meta name="robots" content="index, follow">
  11. <link type="text/css" rel="stylesheet" href="../../../m2html.css">
  12. <script type="text/javascript">
  13. if (top.frames.length == 0) { top.location = "../../../index.html"; };
  14. </script>
  15. </head>
  16. <body>
  17. <a name="_top"></a>
  18. <!-- ../../menu.html chronux_2_10 --><!-- ../menu.html dataio --><!-- menu.html ReadingPLXandDDTfilesinMatlab -->
  19. <h1>plx_waves
  20. </h1>
  21. <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  22. <div class="box"><strong>plx_waves(filename, channel, unit): Read waveform data from a .plx file</strong></div>
  23. <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  24. <div class="box"><strong>function [n, npw, ts, wave] = plx_waves(filename, ch, u) </strong></div>
  25. <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  26. <div class="fragment"><pre class="comment"> plx_waves(filename, channel, unit): Read waveform data from a .plx file
  27. [n, npw, ts, wave] = plx_waves(filename, channel, unit)
  28. INPUT:
  29. filename - if empty string, will use File Open dialog
  30. channel - 1-based channel number
  31. unit - unit number (0- invalid, 1-4 valid)
  32. OUTPUT:
  33. n - number of waveforms
  34. npw - number of points in each waveform
  35. ts - array of timestamps (in seconds)
  36. wave - array of waveforms [npw, n], raw a/d values</pre></div>
  37. <!-- crossreference -->
  38. <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  39. This function calls:
  40. <ul style="list-style-image:url(../../../matlabicon.gif)">
  41. </ul>
  42. This function is called by:
  43. <ul style="list-style-image:url(../../../matlabicon.gif)">
  44. </ul>
  45. <!-- crossreference -->
  46. <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  47. <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [n, npw, ts, wave] = plx_waves(filename, ch, u)</a>
  48. 0002 <span class="comment">% plx_waves(filename, channel, unit): Read waveform data from a .plx file</span>
  49. 0003 <span class="comment">%</span>
  50. 0004 <span class="comment">% [n, npw, ts, wave] = plx_waves(filename, channel, unit)</span>
  51. 0005 <span class="comment">%</span>
  52. 0006 <span class="comment">% INPUT:</span>
  53. 0007 <span class="comment">% filename - if empty string, will use File Open dialog</span>
  54. 0008 <span class="comment">% channel - 1-based channel number</span>
  55. 0009 <span class="comment">% unit - unit number (0- invalid, 1-4 valid)</span>
  56. 0010 <span class="comment">% OUTPUT:</span>
  57. 0011 <span class="comment">% n - number of waveforms</span>
  58. 0012 <span class="comment">% npw - number of points in each waveform</span>
  59. 0013 <span class="comment">% ts - array of timestamps (in seconds)</span>
  60. 0014 <span class="comment">% wave - array of waveforms [npw, n], raw a/d values</span>
  61. 0015
  62. 0016 <span class="keyword">if</span>(nargin ~= 3)
  63. 0017 disp(<span class="string">'3 input arguments are required'</span>)
  64. 0018 <span class="keyword">return</span>
  65. 0019 <span class="keyword">end</span>
  66. 0020
  67. 0021 n = 0;
  68. 0022 npw = 0;
  69. 0023 ts = 0;
  70. 0024 wave = 0;
  71. 0025
  72. 0026 <span class="keyword">if</span>(isempty(filename))
  73. 0027 [fname, pathname] = uigetfile(<span class="string">'*.plx'</span>, <span class="string">'Select a plx file'</span>);
  74. 0028 filename = strcat(pathname, fname);
  75. 0029 <span class="keyword">end</span>
  76. 0030
  77. 0031 fid = fopen(filename, <span class="string">'r'</span>);
  78. 0032 <span class="keyword">if</span>(fid == -1)
  79. 0033 disp(<span class="string">'cannot open file'</span>);
  80. 0034 <span class="keyword">return</span>
  81. 0035 <span class="keyword">end</span>
  82. 0036
  83. 0037 disp(strcat(<span class="string">'file = '</span>, filename));
  84. 0038
  85. 0039 <span class="comment">% read file header</span>
  86. 0040 header = fread(fid, 64, <span class="string">'int32'</span>);
  87. 0041 freq = header(35); <span class="comment">% frequency</span>
  88. 0042 ndsp = header(36); <span class="comment">% number of dsp channels</span>
  89. 0043 nevents = header(37); <span class="comment">% number of external events</span>
  90. 0044 nslow = header(38); <span class="comment">% number of slow channels</span>
  91. 0045 npw = header(39); <span class="comment">% number of points in wave</span>
  92. 0046 npr = header(40); <span class="comment">% number of points before threshold</span>
  93. 0047 tscounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
  94. 0048 wfcounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
  95. 0049 evcounts = fread(fid, [1, 512], <span class="string">'int32'</span>);
  96. 0050
  97. 0051 <span class="comment">% skip variable headers</span>
  98. 0052 fseek(fid, 1020*ndsp + 296*nevents + 296*nslow, <span class="string">'cof'</span>);
  99. 0053
  100. 0054 record = 0;
  101. 0055 wave = zeros(npw, 1);
  102. 0056 wf = zeros(npw, 1);
  103. 0057
  104. 0058 <span class="comment">% read data records</span>
  105. 0059 <span class="keyword">while</span> feof(fid) == 0
  106. 0060 type = fread(fid, 1, <span class="string">'int16'</span>);
  107. 0061 upperbyte = fread(fid, 1, <span class="string">'int16'</span>);
  108. 0062 timestamp = fread(fid, 1, <span class="string">'int32'</span>);
  109. 0063 channel = fread(fid, 1, <span class="string">'int16'</span>);
  110. 0064 unit = fread(fid, 1, <span class="string">'int16'</span>);
  111. 0065 nwf = fread(fid, 1, <span class="string">'int16'</span>);
  112. 0066 nwords = fread(fid, 1, <span class="string">'int16'</span>);
  113. 0067 toread = nwords;
  114. 0068 <span class="keyword">if</span> toread &gt; 0
  115. 0069 wf = fread(fid, [toread, 1], <span class="string">'int16'</span>);
  116. 0070 <span class="keyword">end</span>
  117. 0071 <span class="keyword">if</span> toread &gt; 0
  118. 0072 <span class="keyword">if</span> type == 1
  119. 0073 <span class="keyword">if</span> channel == ch
  120. 0074 <span class="keyword">if</span> unit == u
  121. 0075 n = n + 1;
  122. 0076 ts(n) = timestamp/freq;
  123. 0077 wave(:, n) = wf;
  124. 0078 <span class="keyword">end</span>
  125. 0079 <span class="keyword">end</span>
  126. 0080 <span class="keyword">end</span>
  127. 0081 <span class="keyword">end</span>
  128. 0082
  129. 0083 record = record + 1;
  130. 0084 <span class="keyword">if</span> feof(fid) == 1
  131. 0085 <span class="keyword">break</span>
  132. 0086 <span class="keyword">end</span>
  133. 0087
  134. 0088 <span class="keyword">end</span>
  135. 0089 disp(strcat(<span class="string">'number of waveforms = '</span>, num2str(n)));
  136. 0090
  137. 0091 fclose(fid);</pre></div>
  138. <hr><address>Generated on Fri 12-Aug-2011 11:36:15 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
  139. </body>
  140. </html>