<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>ecat7ml.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.4 --> <div id="top"> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">ecat7ml.c</div> </div> </div> <div class="contents"> <a href="ecat7ml_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/******************************************************************************</span> <a name="l00002"></a>00002 <span class="comment"></span> <a name="l00003"></a>00003 <span class="comment"> Copyright (c) 2003-2007 Turku PET Centre</span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> Library: ecat7ml.c</span> <a name="l00006"></a>00006 <span class="comment"> Description: Reading and writing ECAT 7.x matrix list.</span> <a name="l00007"></a>00007 <span class="comment"></span> <a name="l00008"></a>00008 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00009"></a>00009 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span> <a name="l00010"></a>00010 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00011"></a>00011 <span class="comment"> version 2.1 of the License, or (at your option) any later version.</span> <a name="l00012"></a>00012 <span class="comment"></span> <a name="l00013"></a>00013 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00014"></a>00014 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00015"></a>00015 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</span> <a name="l00016"></a>00016 <span class="comment"> See the GNU Lesser General Public License for more details:</span> <a name="l00017"></a>00017 <span class="comment"> http://www.gnu.org/copyleft/lesser.html</span> <a name="l00018"></a>00018 <span class="comment"></span> <a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU Lesser General Public License</span> <a name="l00020"></a>00020 <span class="comment"> along with this library/program; if not, write to the Free Software</span> <a name="l00021"></a>00021 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </span> <a name="l00022"></a>00022 <span class="comment"></span> <a name="l00023"></a>00023 <span class="comment"> Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi/</span> <a name="l00024"></a>00024 <span class="comment"></span> <a name="l00025"></a>00025 <span class="comment"> Modification history:</span> <a name="l00026"></a>00026 <span class="comment"> 2003-07-21 Vesa Oikonen</span> <a name="l00027"></a>00027 <span class="comment"> First created.</span> <a name="l00028"></a>00028 <span class="comment"> 2004-06-20 VO</span> <a name="l00029"></a>00029 <span class="comment"> ecat7PrintMatlist(): blkNr is printed correctly (+1).</span> <a name="l00030"></a>00030 <span class="comment"> 2004-06-27 VO</span> <a name="l00031"></a>00031 <span class="comment"> Included ecat7DeleteLateFrames().</span> <a name="l00032"></a>00032 <span class="comment"> 2007-02-27 VO</span> <a name="l00033"></a>00033 <span class="comment"> Added functions ecat7GetMatrixBlockSize() and ecat7GetPlaneAndFrameNr().</span> <a name="l00034"></a>00034 <span class="comment"> 2007-03-13 VO</span> <a name="l00035"></a>00035 <span class="comment"> Added functions ecat7GetNums() and ecat7GatherMatlist().</span> <a name="l00036"></a>00036 <span class="comment"> 2007-17-07 Harri Merisaari</span> <a name="l00037"></a>00037 <span class="comment"> fixed for ANSI</span> <a name="l00038"></a>00038 <span class="comment"></span> <a name="l00039"></a>00039 <span class="comment">******************************************************************************/</span> <a name="l00040"></a>00040 <span class="preprocessor">#include <stdio.h></span> <a name="l00041"></a>00041 <span class="preprocessor">#include <stdlib.h></span> <a name="l00042"></a>00042 <span class="preprocessor">#include <math.h></span> <a name="l00043"></a>00043 <span class="preprocessor">#include <ctype.h></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <string.h></span> <a name="l00045"></a>00045 <span class="preprocessor">#include <unistd.h></span> <a name="l00046"></a>00046 <span class="preprocessor">#include <time.h></span> <a name="l00047"></a>00047 <span class="comment">/*****************************************************************************/</span> <a name="l00048"></a>00048 <span class="preprocessor">#include <swap.h></span> <a name="l00049"></a>00049 <span class="preprocessor">#include "<a class="code" href="img_8h.html">include/img.h</a>"</span> <a name="l00050"></a>00050 <span class="preprocessor">#include "<a class="code" href="ecat7_8h.html">include/ecat7.h</a>"</span> <a name="l00051"></a>00051 <span class="comment">/*****************************************************************************/</span> <a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="comment">/*****************************************************************************/</span> <a name="l00059"></a><a class="code" href="ecat7_8h.html#a0826a19efcf80e53e28473189d07949e">00059</a> <span class="keywordtype">void</span> <a class="code" href="ecat7ml_8c.html#a0826a19efcf80e53e28473189d07949e">ecat7InitMatlist</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *mlist) { <a name="l00060"></a>00060 mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>=mlist-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>=0; mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>=NULL; <a name="l00061"></a>00061 } <a name="l00062"></a>00062 <span class="comment">/*****************************************************************************/</span> <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="comment">/*****************************************************************************/</span> <a name="l00070"></a><a class="code" href="ecat7_8h.html#a570804c248c25f15c172568043a8f0a5">00070</a> <span class="keywordtype">void</span> <a class="code" href="ecat7ml_8c.html#a570804c248c25f15c172568043a8f0a5">ecat7EmptyMatlist</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *mlist) { <a name="l00071"></a>00071 <span class="keywordflow">if</span>(mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>>0) free((<span class="keywordtype">char</span>*)(mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>)); <a name="l00072"></a>00072 mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>=mlist-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>=0; <a name="l00073"></a>00073 } <a name="l00074"></a>00074 <span class="comment">/*****************************************************************************/</span> <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="comment">/*****************************************************************************/</span> <a name="l00086"></a><a class="code" href="ecat7_8h.html#a0304c6b68597ab6fe00bb35a44c19dcb">00086</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#a0304c6b68597ab6fe00bb35a44c19dcb">ecat7ReadMatlist</a>(FILE *fp, <a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml) { <a name="l00087"></a>00087 <span class="keywordtype">int</span> i, err=0, little; <a name="l00088"></a>00088 <span class="keywordtype">int</span> blk=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>, next_blk=0, nr_free, prev_blk, nr_used; <a name="l00089"></a>00089 <span class="keywordtype">size_t</span> sn; <a name="l00090"></a>00090 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> dirbuf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4]; <a name="l00091"></a>00091 <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">"ecat7ReadMatlist(fp, mlist)\n"</span>); <a name="l00094"></a>00094 <span class="keywordflow">if</span>(fp==NULL) <span class="keywordflow">return</span>(1); <a name="l00095"></a>00095 little=little_endian(); <a name="l00096"></a>00096 <span class="comment">/* Make sure that matrix list is empty */</span> <a name="l00097"></a>00097 <a class="code" href="ecat7ml_8c.html#a570804c248c25f15c172568043a8f0a5">ecat7EmptyMatlist</a>(ml); <a name="l00098"></a>00098 <span class="comment">/* Seek the first list block */</span> <a name="l00099"></a>00099 fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2); <a name="l00100"></a>00100 <span class="keywordflow">do</span> { <a name="l00101"></a>00101 <span class="comment">/* Read the data block */</span> <a name="l00102"></a>00102 <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">" reading dirblock %d\n"</span>, blk); <a name="l00103"></a>00103 sn=fread(dirbuf, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4, fp); <span class="keywordflow">if</span>(sn<<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4) <span class="keywordflow">return</span>(3); <a name="l00104"></a>00104 <span class="comment">/* Allocate (more) memory for one block */</span> <a name="l00105"></a>00105 <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>==0) { <a name="l00106"></a>00106 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>=<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4; <a name="l00107"></a>00107 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>=(<a class="code" href="structECAT7__MatDir.html">ECAT7_MatDir</a>*)malloc(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>*<span class="keyword">sizeof</span>(<a class="code" href="structECAT7__MatDir.html">ECAT7_MatDir</a>)); <a name="l00108"></a>00108 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a><(ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>+<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4)) { <a name="l00109"></a>00109 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>+=<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4; <a name="l00110"></a>00110 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>=(<a class="code" href="structECAT7__MatDir.html">ECAT7_MatDir</a>*)realloc(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>, <span class="keyword">sizeof</span>(<a class="code" href="structECAT7__MatDir.html">ECAT7_MatDir</a>)*ml-><a class="code" href="structECAT7__MATRIXLIST.html#a855b56b21e23a8088863987c9e440a4e">matrixSpace</a>); <a name="l00111"></a>00111 } <a name="l00112"></a>00112 <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>==NULL) <span class="keywordflow">return</span>(4); <a name="l00113"></a>00113 <span class="comment">/* Byte order conversion for ints in little endian platforms */</span> <a name="l00114"></a>00114 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00115"></a>00115 <span class="comment">/* Read "header" integers */</span> <a name="l00116"></a>00116 nr_free = dirbuf[0]; <a name="l00117"></a>00117 next_blk = dirbuf[1]; <a name="l00118"></a>00118 prev_blk = dirbuf[2]; <a name="l00119"></a>00119 nr_used = dirbuf[3]; <a name="l00120"></a>00120 <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>>1) printf(<span class="stringliteral">"nr_free=%d next_blk=%d prev_blk=%d nr_used=%d\n"</span>, nr_free, next_blk, prev_blk, nr_used); <a name="l00121"></a>00121 <span class="keywordflow">for</span>(i=4; i<<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4; i+=4) <span class="keywordflow">if</span>(dirbuf[i]>0) { <a name="l00122"></a>00122 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>=dirbuf[i]; <a name="l00123"></a>00123 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>=dirbuf[i+1]; <a name="l00124"></a>00124 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#aed143081e768d276a1eaf275e116b259">endblk</a>=dirbuf[i+2]; <a name="l00125"></a>00125 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>=dirbuf[i+3]; <a name="l00126"></a>00126 <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>>3) { <a name="l00127"></a>00127 printf(<span class="stringliteral">"matnum=%d strtblk=%d endblk=%d matstat=%d matrixNr=%d\n"</span>, <a name="l00128"></a>00128 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>, <a name="l00129"></a>00129 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#aed143081e768d276a1eaf275e116b259">endblk</a>, ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>, <a name="l00130"></a>00130 ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>); <a name="l00131"></a>00131 } <a name="l00132"></a>00132 ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>++; <a name="l00133"></a>00133 } <a name="l00134"></a>00134 blk=next_blk; <a name="l00135"></a>00135 <span class="comment">/* Seek the next list block */</span> <a name="l00136"></a>00136 fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) err=1; <a name="l00137"></a>00137 } <span class="keywordflow">while</span>(err==0 && feof(fp)==0 && blk!=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>); <a name="l00138"></a>00138 <span class="keywordflow">if</span>(err) {<a class="code" href="ecat7ml_8c.html#a570804c248c25f15c172568043a8f0a5">ecat7EmptyMatlist</a>(ml); <span class="keywordflow">return</span>(5);} <a name="l00139"></a>00139 <span class="keywordflow">return</span>(0); <a name="l00140"></a>00140 } <a name="l00141"></a>00141 <span class="comment">/*****************************************************************************/</span> <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="comment">/*****************************************************************************/</span> <a name="l00149"></a><a class="code" href="ecat7_8h.html#ad50b3297af530071a5f115c14f40c701">00149</a> <span class="keywordtype">void</span> <a class="code" href="ecat7ml_8c.html#ad50b3297af530071a5f115c14f40c701">ecat7PrintMatlist</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml) { <a name="l00150"></a>00150 <span class="keywordtype">int</span> i; <a name="l00151"></a>00151 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a> matval; <a name="l00152"></a>00152 <a name="l00153"></a>00153 printf(<span class="stringliteral">" matrix pl fr gate bed startblk blknr status\n"</span>); <a name="l00154"></a>00154 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) { <a name="l00155"></a>00155 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &matval); <a name="l00156"></a>00156 printf(<span class="stringliteral">"%4d %8d %3d %3d %3d %3d %8d %5d "</span>, i+1, ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, <a name="l00157"></a>00157 matval.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>, matval.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>, matval.<a class="code" href="structECAT7__Matval.html#a0f094bb9f2d880fa875ecc6110ace13b">gate</a>, matval.<a class="code" href="structECAT7__Matval.html#af1f94ed7c49267bed701b8a0fa690ecd">bed</a>, <a name="l00158"></a>00158 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>, 1+ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#aed143081e768d276a1eaf275e116b259">endblk</a>-ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>); <a name="l00159"></a>00159 <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>==1) printf(<span class="stringliteral">"read/write\n"</span>); <a name="l00160"></a>00160 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>==0) printf(<span class="stringliteral">"not ready\n"</span>); <a name="l00161"></a>00161 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>==-1) printf(<span class="stringliteral">"deleted\n"</span>); <a name="l00162"></a>00162 <span class="keywordflow">else</span> printf(<span class="stringliteral">"%d\n"</span>, ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>); <a name="l00163"></a>00163 } <a name="l00164"></a>00164 <span class="keywordflow">return</span>; <a name="l00165"></a>00165 } <a name="l00166"></a>00166 <span class="comment">/*****************************************************************************/</span> <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="comment">/*****************************************************************************/</span> <a name="l00184"></a><a class="code" href="ecat7_8h.html#a8f97f2b4eb5bea323738dc3687e773b8">00184</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#a8f97f2b4eb5bea323738dc3687e773b8">ecat7EnterMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matrix_id, <span class="keywordtype">int</span> block_nr) { <a name="l00185"></a>00185 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0, dirblk, little, busy=1, nxtblk=0, oldsize; <a name="l00186"></a>00186 <span class="comment">/*unsigned*/</span> <span class="keywordtype">int</span> dirbuf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4]; <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">"ecat7EnterMatrix(fp, %d, %d)\n"</span>, matrix_id, block_nr); <a name="l00189"></a>00189 <span class="comment">/* Check the input */</span> <a name="l00190"></a>00190 <span class="keywordflow">if</span>(fp==NULL || matrix_id<1 || block_nr<1) <span class="keywordflow">return</span>(-1); <a name="l00191"></a>00191 <span class="comment">/* Is this a little endian machine? */</span> <a name="l00192"></a>00192 little=little_endian(); <a name="l00193"></a>00193 <span class="comment">/* Read first directory record block */</span> <a name="l00194"></a>00194 dirblk=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>; <a name="l00195"></a>00195 fseek(fp, (dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <a name="l00196"></a>00196 <span class="keywordflow">if</span>(ftell(fp)!=(dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(-2); <a name="l00197"></a>00197 <span class="keywordflow">if</span>(fread(dirbuf, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4, fp) != <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4) <span class="keywordflow">return</span>(-3); <a name="l00198"></a>00198 <span class="comment">/* Byte order conversion for ints in little endian platforms */</span> <a name="l00199"></a>00199 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00200"></a>00200 <span class="comment">/* Read through the existing directory records */</span> <a name="l00201"></a>00201 <span class="keywordflow">while</span>(busy) { <a name="l00202"></a>00202 <span class="comment">/* Go through the directory entries in this record */</span> <a name="l00203"></a>00203 <span class="keywordflow">for</span>(i=4, nxtblk=dirblk+1; i<<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4; i+=4) { <a name="l00204"></a>00204 oldsize=dirbuf[i+2]-dirbuf[i+1]+1; <a name="l00205"></a>00205 <span class="keywordflow">if</span>(dirbuf[i]==0) { <span class="comment">/* Check for end of matrix list */</span> <a name="l00206"></a>00206 busy=0; <span class="keywordflow">break</span>; <a name="l00207"></a>00207 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dirbuf[i]==matrix_id) { <span class="comment">/* Maybe this matrix already exists? */</span> <a name="l00208"></a>00208 <span class="comment">/* yes it does; is old data smaller? */</span> <a name="l00209"></a>00209 <span class="keywordflow">if</span>(oldsize<block_nr) { <a name="l00210"></a>00210 <span class="comment">/* it was smaller, so do not use it, but mark it deleted */</span> <a name="l00211"></a>00211 dirbuf[i] = 0xFFFFFFFF; dirbuf[i+3]=-1; <a name="l00212"></a>00212 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00213"></a>00213 fseek(fp, (dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <a name="l00214"></a>00214 <span class="keywordflow">if</span>(ftell(fp)!=(dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(-6); <a name="l00215"></a>00215 <span class="keywordflow">if</span>(fwrite(dirbuf, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4, fp) != <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4) <span class="keywordflow">return</span>(-7); <a name="l00216"></a>00216 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00217"></a>00217 nxtblk=dirbuf[i+2]+1; <a name="l00218"></a>00218 } <span class="keywordflow">else</span> { <span class="comment">/* old matrix size is ok */</span> <a name="l00219"></a>00219 nxtblk=dirbuf[i+1]; dirbuf[0]++; dirbuf[3]--; busy=0; <a name="l00220"></a>00220 <span class="keywordflow">break</span>; <a name="l00221"></a>00221 } <a name="l00222"></a>00222 } <span class="keywordflow">else</span> { <span class="comment">/* this is not the same matrix */</span> <a name="l00223"></a>00223 <span class="comment">/* But is deleted and of same or smaller size? */</span> <a name="l00224"></a>00224 <span class="keywordflow">if</span>(dirbuf[i+3]==-1 && block_nr<=oldsize) { <a name="l00225"></a>00225 <span class="comment">/* yes it was, so lets recycle it */</span> <a name="l00226"></a>00226 dirbuf[i]=matrix_id; <a name="l00227"></a>00227 nxtblk=dirbuf[i+1]; dirbuf[0]++; dirbuf[3]--; busy=0; <a name="l00228"></a>00228 <span class="keywordflow">break</span>; <a name="l00229"></a>00229 } <a name="l00230"></a>00230 <span class="comment">/* nothing to be done with this entry */</span> <a name="l00231"></a>00231 nxtblk=dirbuf[i+2]+1; <a name="l00232"></a>00232 } <a name="l00233"></a>00233 } <span class="comment">/* next entry in this record */</span> <a name="l00234"></a>00234 <span class="keywordflow">if</span>(!busy) <span class="keywordflow">break</span>; <span class="comment">/* stop reading existing records */</span> <a name="l00235"></a>00235 <span class="comment">/* Read the next directory record */</span> <a name="l00236"></a>00236 <span class="keywordflow">if</span>(dirbuf[1]!=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>) { <a name="l00237"></a>00237 <span class="comment">/* There are more records left to read */</span> <a name="l00238"></a>00238 dirblk=dirbuf[1]; <a name="l00239"></a>00239 fseek(fp, (dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <a name="l00240"></a>00240 <span class="keywordflow">if</span>(ftell(fp)!=(dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(-9); <a name="l00241"></a>00241 <span class="keywordflow">if</span>(fread(dirbuf, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4, fp) != <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4) <span class="keywordflow">return</span>(-10); <a name="l00242"></a>00242 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00243"></a>00243 } <span class="keywordflow">else</span> { <a name="l00244"></a>00244 <span class="comment">/* No more records to read, so lets write a new empty one */</span> <a name="l00245"></a>00245 dirbuf[1]=nxtblk; <span class="comment">/* write a pointer to the new one */</span> <a name="l00246"></a>00246 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00247"></a>00247 fseek(fp, (dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <a name="l00248"></a>00248 <span class="keywordflow">if</span>(ftell(fp)!=(dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(-11); <a name="l00249"></a>00249 <span class="keywordflow">if</span>(fwrite(dirbuf, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4, fp) != <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4) <span class="keywordflow">return</span>(-12); <a name="l00250"></a>00250 <span class="comment">/* and then initiate the contents of the next one, but do not write it */</span> <a name="l00251"></a>00251 dirbuf[0]=31; dirbuf[1]=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>; dirbuf[2]=dirblk; <a name="l00252"></a>00252 dirbuf[3]=0; dirblk=nxtblk; <a name="l00253"></a>00253 <span class="keywordflow">for</span>(i=4; i<<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4; i++) dirbuf[i]=0; <a name="l00254"></a>00254 } <a name="l00255"></a>00255 } <span class="comment">/* next directory record */</span> <a name="l00256"></a>00256 dirbuf[i]=matrix_id; <a name="l00257"></a>00257 dirbuf[i+1]=nxtblk; <a name="l00258"></a>00258 dirbuf[i+2]=nxtblk+block_nr; <a name="l00259"></a>00259 dirbuf[i+3]=1; <span class="comment">/* mark the entry as read/write */</span> <a name="l00260"></a>00260 dirbuf[0]--; <a name="l00261"></a>00261 dirbuf[3]++; <a name="l00262"></a>00262 <span class="keywordflow">if</span>(little) swawbip(dirbuf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <a name="l00263"></a>00263 fseek(fp, (dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <a name="l00264"></a>00264 <span class="keywordflow">if</span>(ftell(fp)!=(dirblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(-15); <a name="l00265"></a>00265 <span class="keywordflow">if</span>(fwrite(dirbuf, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4, fp) != <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4) <span class="keywordflow">return</span>(-16); <a name="l00266"></a>00266 <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">"returning %d from ecat7EnterMatrix()\n"</span>, nxtblk); <a name="l00267"></a>00267 <span class="keywordflow">return</span>(nxtblk); <a name="l00268"></a>00268 } <a name="l00269"></a>00269 <span class="comment">/*****************************************************************************/</span> <a name="l00270"></a>00270 <a name="l00271"></a>00271 <span class="comment">/*****************************************************************************/</span> <a name="l00282"></a><a class="code" href="ecat7_8h.html#acad3263ebf24cf2e10d7c43491810481">00282</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#acad3263ebf24cf2e10d7c43491810481">ecat7_val_to_id</a>(<span class="keywordtype">int</span> frame, <span class="keywordtype">int</span> plane, <span class="keywordtype">int</span> gate, <span class="keywordtype">int</span> data, <span class="keywordtype">int</span> bed) { <a name="l00283"></a>00283 <span class="keywordflow">return</span>( <a name="l00284"></a>00284 ((bed & 0xF) << 12) | <span class="comment">/* bed */</span> <a name="l00285"></a>00285 (frame & 0x1FF) | <span class="comment">/* frame */</span> <a name="l00286"></a>00286 ((gate & 0x3F) << 24) | <span class="comment">/* gate */</span> <a name="l00287"></a>00287 ((plane & 0xFF) << 16) | <span class="comment">/* plane low */</span> <a name="l00288"></a>00288 ((plane & 0x300) << 1) | <span class="comment">/* plane high */</span> <a name="l00289"></a>00289 ((data & 0x3) << 30) | <span class="comment">/* data low */</span> <a name="l00290"></a>00290 ((data & 0x4) << 9) <span class="comment">/* data high */</span> <a name="l00291"></a>00291 ); <a name="l00292"></a>00292 } <a name="l00299"></a><a class="code" href="ecat7_8h.html#a4cf0dc3b586a1c62d177f21b5e8e2328">00299</a> <span class="keywordtype">void</span> <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(<span class="keywordtype">int</span> matrix_id, <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a> *matval) { <a name="l00300"></a>00300 matval-><a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a> = matrix_id & 0x1FF; <a name="l00301"></a>00301 matval-><a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a> = ((matrix_id >> 16) & 0xFF) + ((matrix_id >> 1) & 0x300); <a name="l00302"></a>00302 matval-><a class="code" href="structECAT7__Matval.html#a0f094bb9f2d880fa875ecc6110ace13b">gate</a> = (matrix_id >> 24) & 0x3F; <a name="l00303"></a>00303 matval-><a class="code" href="structECAT7__Matval.html#ae3967b7e2d0ff84fd86c71a8e898cbee">data</a> = ((matrix_id >> 30) & 0x3) + ((matrix_id >> 9) & 0x4); <a name="l00304"></a>00304 matval-><a class="code" href="structECAT7__Matval.html#af1f94ed7c49267bed701b8a0fa690ecd">bed</a> = (matrix_id >> 12) & 0xF; <a name="l00305"></a>00305 } <a name="l00306"></a>00306 <span class="comment">/*****************************************************************************/</span> <a name="l00307"></a>00307 <a name="l00308"></a>00308 <span class="comment">/*****************************************************************************/</span> <a name="l00314"></a><a class="code" href="ecat7_8h.html#a4c5fe6841c5c02db200f5aa92d652014">00314</a> <span class="keywordtype">void</span> <a class="code" href="ecat7ml_8c.html#a4c5fe6841c5c02db200f5aa92d652014">ecat7SortMatlistByPlane</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml) { <a name="l00315"></a>00315 <span class="keywordtype">int</span> i, j; <a name="l00316"></a>00316 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a> mv1, mv2; <a name="l00317"></a>00317 <a class="code" href="structECAT7__MatDir.html">ECAT7_MatDir</a> tmpMatdir; <a name="l00318"></a>00318 <a name="l00319"></a>00319 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>-1; i++) { <a name="l00320"></a>00320 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &mv1); <a name="l00321"></a>00321 <span class="keywordflow">for</span>(j=i+1; j<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; j++) { <a name="l00322"></a>00322 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[j].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &mv2); <a name="l00323"></a>00323 <span class="keywordflow">if</span>(mv2.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a><mv1.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>||(mv2.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>==mv1.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>&&mv2.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a><mv1.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>)) { <a name="l00324"></a>00324 tmpMatdir=ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i]; <a name="l00325"></a>00325 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i]=ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[j]; <a name="l00326"></a>00326 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[j]=tmpMatdir; <a name="l00327"></a>00327 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &mv1); <a name="l00328"></a>00328 } <a name="l00329"></a>00329 } <a name="l00330"></a>00330 } <a name="l00331"></a>00331 } <a name="l00332"></a>00332 <span class="comment">/*****************************************************************************/</span> <a name="l00333"></a>00333 <a name="l00334"></a>00334 <span class="comment">/*****************************************************************************/</span> <a name="l00340"></a><a class="code" href="ecat7_8h.html#a1005274d31eb31ae483b5740dae6af1e">00340</a> <span class="keywordtype">void</span> <a class="code" href="ecat7ml_8c.html#a1005274d31eb31ae483b5740dae6af1e">ecat7SortMatlistByFrame</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml) { <a name="l00341"></a>00341 <span class="keywordtype">int</span> i, j; <a name="l00342"></a>00342 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a> mv1, mv2; <a name="l00343"></a>00343 <a class="code" href="structECAT7__MatDir.html">ECAT7_MatDir</a> tmpMatdir; <a name="l00344"></a>00344 <a name="l00345"></a>00345 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>-1; i++) { <a name="l00346"></a>00346 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &mv1); <a name="l00347"></a>00347 <span class="keywordflow">for</span>(j=i+1; j<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; j++) { <a name="l00348"></a>00348 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[j].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &mv2); <a name="l00349"></a>00349 <span class="keywordflow">if</span>(mv2.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a><mv1.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>||(mv2.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>==mv1.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>&&mv2.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a><mv1.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>)) { <a name="l00350"></a>00350 tmpMatdir=ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i]; <a name="l00351"></a>00351 ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i]=ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[j]; ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[j]=tmpMatdir; <a name="l00352"></a>00352 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &mv1); <a name="l00353"></a>00353 } <a name="l00354"></a>00354 } <a name="l00355"></a>00355 } <a name="l00356"></a>00356 } <a name="l00357"></a>00357 <span class="comment">/*****************************************************************************/</span> <a name="l00358"></a>00358 <a name="l00359"></a>00359 <span class="comment">/*****************************************************************************/</span> <a name="l00366"></a><a class="code" href="ecat7_8h.html#ae366d8f1a8202f053debfdbe2a8c6be7">00366</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#ae366d8f1a8202f053debfdbe2a8c6be7">ecat7CheckMatlist</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml) { <a name="l00367"></a>00367 <span class="keywordtype">int</span> i; <a name="l00368"></a>00368 <a name="l00369"></a>00369 <span class="keywordflow">if</span>(ml==NULL) <span class="keywordflow">return</span>(1); <a name="l00370"></a>00370 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>!=1) <span class="keywordflow">return</span>(1); <a name="l00371"></a>00371 <span class="keywordflow">return</span>(0); <a name="l00372"></a>00372 } <a name="l00373"></a>00373 <span class="comment">/*****************************************************************************/</span> <a name="l00374"></a>00374 <a name="l00375"></a>00375 <span class="comment">/*****************************************************************************/</span> <a name="l00383"></a><a class="code" href="ecat7_8h.html#adcf9c5b0fb57d5b49ccb8b38c6e3d987">00383</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#adcf9c5b0fb57d5b49ccb8b38c6e3d987">ecat7DeleteLateFrames</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml, <span class="keywordtype">int</span> frame_nr) { <a name="l00384"></a>00384 <span class="keywordtype">int</span> i, del_nr=0; <a name="l00385"></a>00385 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a> matval; <a name="l00386"></a>00386 <a name="l00387"></a>00387 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) { <a name="l00388"></a>00388 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &matval); <a name="l00389"></a>00389 <span class="keywordflow">if</span>(matval.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>>frame_nr) {del_nr++; ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#afd8e5952a79ce23167afc5ccca3735f9">status</a>=-1;} <a name="l00390"></a>00390 } <a name="l00391"></a>00391 <span class="keywordflow">return</span>(del_nr); <a name="l00392"></a>00392 } <a name="l00393"></a>00393 <span class="comment">/*****************************************************************************/</span> <a name="l00394"></a>00394 <a name="l00395"></a>00395 <span class="comment">/*****************************************************************************/</span> <a name="l00409"></a><a class="code" href="ecat7_8h.html#a233c8c21f8ef8975c4cf486c6137a53d">00409</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#a233c8c21f8ef8975c4cf486c6137a53d">ecat7GetPlaneAndFrameNr</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *mlist, <a class="code" href="structecat7__mainheader.html">ECAT7_mainheader</a> *h, <span class="keywordtype">int</span> *plane_nr, <span class="keywordtype">int</span> *frame_nr) { <a name="l00410"></a>00410 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a> matval; <a name="l00411"></a>00411 <span class="keywordtype">int</span> m, plane, frame, prev_plane, prev_frame, fnr, pnr; <a name="l00412"></a>00412 <a name="l00413"></a>00413 <span class="comment">/* Check input */</span> <a name="l00414"></a>00414 <span class="keywordflow">if</span>(mlist==NULL) <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55baf8f3d89c25483639f6cbce4f6b08c1f8">STATUS_FAULT</a>; <a name="l00415"></a>00415 <span class="keywordflow">if</span>(plane_nr!=NULL) *plane_nr=0; <a name="l00416"></a>00416 <span class="keywordflow">if</span>(frame_nr!=NULL) *frame_nr=0; <a name="l00417"></a>00417 <a name="l00418"></a>00418 <span class="comment">/* Sort matrices by plane so that following computation works */</span> <a name="l00419"></a>00419 <a class="code" href="ecat7ml_8c.html#a4c5fe6841c5c02db200f5aa92d652014">ecat7SortMatlistByPlane</a>(mlist); <a name="l00420"></a>00420 <a name="l00421"></a>00421 prev_plane=plane=-1; prev_frame=frame=-1; <a name="l00422"></a>00422 fnr=pnr=0; <a name="l00423"></a>00423 <span class="keywordflow">for</span>(m=0; m<mlist-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; m++) { <a name="l00424"></a>00424 <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[m].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, &matval); <a name="l00425"></a>00425 plane=matval.<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>; <a name="l00426"></a>00426 <span class="keywordflow">if</span>(h-><a class="code" href="structecat7__mainheader.html#a7df83de0bdabd7ebf190e1a58bfc2e20">num_frames</a>>=h-><a class="code" href="structecat7__mainheader.html#a45cd434d5473194ffdbb27c99d9d7e6a">num_gates</a>) <a name="l00427"></a>00427 frame=matval.<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>; <a name="l00428"></a>00428 <span class="keywordflow">else</span> <a name="l00429"></a>00429 frame=matval.<a class="code" href="structECAT7__Matval.html#a0f094bb9f2d880fa875ecc6110ace13b">gate</a>; <a name="l00430"></a>00430 <span class="keywordflow">if</span>(plane!=prev_plane) { <a name="l00431"></a>00431 fnr=1; pnr++; <a name="l00432"></a>00432 } <span class="keywordflow">else</span> { <a name="l00433"></a>00433 fnr++; <a name="l00434"></a>00434 <span class="keywordflow">if</span>(prev_frame>0 && frame!=prev_frame+1) <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55bad6498890650ae8d01e69f43514eb4fed">STATUS_MISSINGMATRIX</a>; <a name="l00435"></a>00435 } <a name="l00436"></a>00436 prev_plane=plane; prev_frame=frame; <a name="l00437"></a>00437 } <span class="comment">/* next matrix */</span> <a name="l00438"></a>00438 <span class="keywordflow">if</span>(fnr*pnr != mlist-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>) <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55bad6498890650ae8d01e69f43514eb4fed">STATUS_MISSINGMATRIX</a>; <a name="l00439"></a>00439 <span class="keywordflow">if</span>(plane_nr!=NULL) *plane_nr=pnr; <a name="l00440"></a>00440 <span class="keywordflow">if</span>(frame_nr!=NULL) *frame_nr=fnr; <a name="l00441"></a>00441 <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55ba7e4a42e3b6dd63708c64cf3db6f69566">STATUS_OK</a>; <a name="l00442"></a>00442 } <a name="l00443"></a>00443 <span class="comment">/*****************************************************************************/</span> <a name="l00444"></a>00444 <a name="l00445"></a>00445 <span class="comment">/*****************************************************************************/</span> <a name="l00455"></a><a class="code" href="ecat7_8h.html#a24438ca2c1691deba0e4101d8fadb1c8">00455</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#a24438ca2c1691deba0e4101d8fadb1c8">ecat7GetMatrixBlockSize</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *mlist, <span class="keywordtype">int</span> *blk_nr) { <a name="l00456"></a>00456 <span class="keywordtype">int</span> m, prev_blk, blk; <a name="l00457"></a>00457 <a name="l00458"></a>00458 <span class="comment">/* Check input */</span> <a name="l00459"></a>00459 <span class="keywordflow">if</span>(mlist==NULL) <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55baf8f3d89c25483639f6cbce4f6b08c1f8">STATUS_FAULT</a>; <a name="l00460"></a>00460 <span class="keywordflow">if</span>(blk_nr!=NULL) *blk_nr=0; <a name="l00461"></a>00461 <a name="l00462"></a>00462 <span class="comment">/* Calculate the size of first data matrix */</span> <a name="l00463"></a>00463 m=0; prev_blk=blk=mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[m].<a class="code" href="structECAT7__MatDir.html#aed143081e768d276a1eaf275e116b259">endblk</a> - mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[m].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>; <a name="l00464"></a>00464 <span class="keywordflow">for</span>(m=1; m<mlist-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; m++) { <a name="l00465"></a>00465 blk=mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[m].<a class="code" href="structECAT7__MatDir.html#aed143081e768d276a1eaf275e116b259">endblk</a> - mlist-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[m].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>; <a name="l00466"></a>00466 <span class="keywordflow">if</span>(blk!=prev_blk) <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55bae8ce9dbf165d2c5fdb9c4609c01d94e5">STATUS_VARMATSIZE</a>; <a name="l00467"></a>00467 <span class="keywordflow">else</span> prev_blk=blk; <a name="l00468"></a>00468 } <a name="l00469"></a>00469 <span class="keywordflow">if</span>(blk_nr!=NULL) *blk_nr=blk; <a name="l00470"></a>00470 <span class="keywordflow">return</span> <a class="code" href="img_8h.html#a06fc87d81c62e9abb8790b6e5713c55ba7e4a42e3b6dd63708c64cf3db6f69566">STATUS_OK</a>; <a name="l00471"></a>00471 } <a name="l00472"></a>00472 <span class="comment">/*****************************************************************************/</span> <a name="l00473"></a>00473 <a name="l00474"></a>00474 <span class="comment">/*****************************************************************************/</span> <a name="l00489"></a><a class="code" href="ecat7_8h.html#a4eeccd90124f09c4c68c31a4c9c05b78">00489</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#a4eeccd90124f09c4c68c31a4c9c05b78">ecat7GetNums</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml, <a class="code" href="structecat7__mainheader.html">ECAT7_mainheader</a> *mh, FILE *fp, <span class="keywordtype">short</span> <span class="keywordtype">int</span> *num_planes, <a name="l00490"></a>00490 <span class="keywordtype">short</span> <span class="keywordtype">int</span> *num_frames, <span class="keywordtype">short</span> <span class="keywordtype">int</span> *num_gates, <span class="keywordtype">short</span> <span class="keywordtype">int</span> *num_bed_pos) { <a name="l00491"></a>00491 <span class="keywordtype">int</span> i, nmax, ret=0; <a name="l00492"></a>00492 <a class="code" href="structecat7__imageheader.html">ECAT7_imageheader</a> ih; <a name="l00493"></a>00493 <a class="code" href="structecat7__scanheader.html">ECAT7_scanheader</a> sh; <a name="l00494"></a>00494 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a>* matval; <a name="l00495"></a>00495 <a name="l00496"></a>00496 <span class="keywordflow">if</span>(ml==NULL) <span class="keywordflow">return</span>(1); <a name="l00497"></a>00497 <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a><1) <span class="keywordflow">return</span>(2); <a name="l00498"></a>00498 <a name="l00499"></a>00499 <span class="comment">/* Allocate memory for matrix values */</span> <a name="l00500"></a>00500 matval = (<a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a>*)calloc(ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>,<span class="keyword">sizeof</span>(<a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a>)); <a name="l00501"></a>00501 <span class="keywordflow">if</span>(matval == NULL) <span class="keywordflow">return</span>(3); <a name="l00502"></a>00502 <a name="l00503"></a>00503 <span class="comment">/* And get the matrix values */</span> <a name="l00504"></a>00504 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, matval+i); <a name="l00505"></a>00505 <a name="l00506"></a>00506 <span class="comment">/* Planes */</span> <a name="l00507"></a>00507 <span class="keywordflow">if</span>(num_planes!=NULL) { <a name="l00508"></a>00508 nmax=matval[0].<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>; <a name="l00509"></a>00509 <span class="keywordflow">for</span>(i=1; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].plane>nmax) nmax=matval[i].<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>; <a name="l00510"></a>00510 *num_planes=nmax; <a name="l00511"></a>00511 } <a name="l00512"></a>00512 <span class="comment">/* Frames */</span> <a name="l00513"></a>00513 <span class="keywordflow">if</span>(num_frames!=NULL) { <a name="l00514"></a>00514 nmax=matval[0].<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>; <a name="l00515"></a>00515 <span class="keywordflow">for</span>(i=1; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].frame>nmax) nmax=matval[i].<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>; <a name="l00516"></a>00516 *num_frames=nmax; <a name="l00517"></a>00517 } <a name="l00518"></a>00518 <span class="comment">/* Gates */</span> <a name="l00519"></a>00519 <span class="keywordflow">if</span>(num_gates!=NULL) { <a name="l00520"></a>00520 nmax=matval[0].<a class="code" href="structECAT7__Matval.html#a0f094bb9f2d880fa875ecc6110ace13b">gate</a>; <a name="l00521"></a>00521 <span class="keywordflow">for</span>(i=1; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].gate>nmax) nmax=matval[i].<a class="code" href="structECAT7__Matval.html#a0f094bb9f2d880fa875ecc6110ace13b">gate</a>; <a name="l00522"></a>00522 *num_gates=nmax; <a name="l00523"></a>00523 } <a name="l00524"></a>00524 <span class="comment">/* Beds */</span> <a name="l00525"></a>00525 <span class="keywordflow">if</span>(num_bed_pos!=NULL) { <a name="l00526"></a>00526 nmax=matval[0].<a class="code" href="structECAT7__Matval.html#af1f94ed7c49267bed701b8a0fa690ecd">bed</a>; <a name="l00527"></a>00527 <span class="keywordflow">for</span>(i=1; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].bed>nmax) nmax=matval[i].<a class="code" href="structECAT7__Matval.html#af1f94ed7c49267bed701b8a0fa690ecd">bed</a>; <a name="l00528"></a>00528 *num_bed_pos=nmax; <a name="l00529"></a>00529 } <a name="l00530"></a>00530 <a name="l00531"></a>00531 <span class="comment">/* Check the num_planes from the first subheader in 3D formats */</span> <a name="l00532"></a>00532 <span class="keywordflow">if</span>(num_planes!=NULL && *num_planes<=1) <span class="keywordflow">switch</span>(mh-><a class="code" href="structecat7__mainheader.html#a1914b3a0ebf3077d090752d6ef66c757">file_type</a>) { <a name="l00533"></a>00533 <span class="keywordflow">case</span> <a class="code" href="ecat7_8h.html#a0ea1caf9e41509e4d119d229d9636445">ECAT7_VOLUME8</a>: <a name="l00534"></a>00534 <span class="keywordflow">case</span> <a class="code" href="ecat7_8h.html#a6e003b3310c339d2cdac5b64cbdca3f1">ECAT7_VOLUME16</a>: <a name="l00535"></a>00535 ret=<a class="code" href="ecat7r_8c.html#ac96bedc17610a5a05d95ce7742d44b5c">ecat7ReadImageheader</a>(fp, ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[0].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>, &ih); <a name="l00536"></a>00536 <span class="keywordflow">if</span>(ret!=0) { <a name="l00537"></a>00537 free(matval); <a name="l00538"></a>00538 <span class="keywordflow">return</span>(5); <a name="l00539"></a>00539 } <a name="l00540"></a>00540 <span class="keywordflow">if</span>(ih.<a class="code" href="structecat7__imageheader.html#acabca0e942a462b769c59804250b9a1c">num_dimensions</a>>2 && ih.<a class="code" href="structecat7__imageheader.html#a7d4bc496c4aa5581d41dff3e5b40a231">z_dimension</a>>1) *num_planes=ih.<a class="code" href="structecat7__imageheader.html#a7d4bc496c4aa5581d41dff3e5b40a231">z_dimension</a>; <a name="l00541"></a>00541 <span class="keywordflow">break</span>; <a name="l00542"></a>00542 <span class="keywordflow">case</span> <a class="code" href="ecat7_8h.html#a432546d341581f2754964e808b368116">ECAT7_3DSCAN</a>: <a name="l00543"></a>00543 <span class="keywordflow">case</span> <a class="code" href="ecat7_8h.html#a4b13fe4c981f8d1ebf6f99baceb3730d">ECAT7_3DSCAN8</a>: <a name="l00544"></a>00544 <span class="keywordflow">case</span> <a class="code" href="ecat7_8h.html#a6c8af4dc922ee29e79c8490da33eea76">ECAT7_3DSCANFIT</a>: <a name="l00545"></a>00545 ret=<a class="code" href="ecat7r_8c.html#a37414b52ef395686b6a81d6229d13143">ecat7ReadScanheader</a>(fp, ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[0].<a class="code" href="structECAT7__MatDir.html#a599cd12bfc8ff972afaef41a2cb57aa8">strtblk</a>, &sh); <a name="l00546"></a>00546 <span class="keywordflow">if</span>(ret!=0) { <a name="l00547"></a>00547 free(matval); <a name="l00548"></a>00548 <span class="keywordflow">return</span>(5); <a name="l00549"></a>00549 } <a name="l00550"></a>00550 <span class="keywordflow">for</span>(i=0, *num_planes=0; i<64; i++) *num_planes+=sh.<a class="code" href="structecat7__scanheader.html#a714bae4e56b451926ceeb0de19222ad7">num_z_elements</a>[i]; <a name="l00551"></a>00551 <span class="keywordflow">break</span>; <a name="l00552"></a>00552 } <a name="l00553"></a>00553 free(matval); <a name="l00554"></a>00554 <span class="keywordflow">return</span>(0); <a name="l00555"></a>00555 } <a name="l00556"></a>00556 <span class="comment">/*****************************************************************************/</span> <a name="l00557"></a>00557 <a name="l00558"></a>00558 <span class="comment">/*****************************************************************************/</span> <a name="l00572"></a><a class="code" href="ecat7_8h.html#ad061c624a2cc95af6b54e6fdebdfc64d">00572</a> <span class="keywordtype">int</span> <a class="code" href="ecat7ml_8c.html#ad061c624a2cc95af6b54e6fdebdfc64d">ecat7GatherMatlist</a>(<a class="code" href="structECAT7__MATRIXLIST.html">ECAT7_MATRIXLIST</a> *ml, <span class="keywordtype">short</span> <span class="keywordtype">int</span> do_planes, <span class="keywordtype">short</span> <span class="keywordtype">int</span> do_frames, <a name="l00573"></a>00573 <span class="keywordtype">short</span> <span class="keywordtype">int</span> do_gates, <span class="keywordtype">short</span> <span class="keywordtype">int</span> do_beds) { <a name="l00574"></a>00574 <span class="keywordtype">int</span> i, ncurr, n; <a name="l00575"></a>00575 <a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a>* matval; <a name="l00576"></a>00576 <a name="l00577"></a>00577 <span class="keywordflow">if</span>(ml==NULL) <span class="keywordflow">return</span>(1); <a name="l00578"></a>00578 <span class="keywordflow">if</span>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a><1) <span class="keywordflow">return</span>(0); <a name="l00579"></a>00579 <a name="l00580"></a>00580 <span class="comment">/* Allocate memory for matrix values */</span> <a name="l00581"></a>00581 matval = (<a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a>*)calloc(ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>,<span class="keyword">sizeof</span>(<a class="code" href="structECAT7__Matval.html">ECAT7_Matval</a>)); <a name="l00582"></a>00582 <span class="keywordflow">if</span>(matval == NULL) <span class="keywordflow">return</span>(3); <a name="l00583"></a>00583 <a name="l00584"></a>00584 <span class="comment">/* And get the matrix values */</span> <a name="l00585"></a>00585 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <a class="code" href="ecat7ml_8c.html#a4cf0dc3b586a1c62d177f21b5e8e2328">ecat7_id_to_val</a>(ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>, matval+i); <a name="l00586"></a>00586 <a name="l00587"></a>00587 <span class="comment">/* Planes */</span> <a name="l00588"></a>00588 <span class="keywordflow">if</span>(do_planes!=0) { <a name="l00589"></a>00589 ncurr=1; <a name="l00590"></a>00590 <span class="keywordflow">while</span>(ncurr <= ml->matrixNr) { <a name="l00591"></a>00591 <span class="comment">/* Find any matrix with this number? */</span> <a name="l00592"></a>00592 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].plane==ncurr) {n=1; <span class="keywordflow">break</span>;} <a name="l00593"></a>00593 <span class="comment">/* If yes, then go on to the next matrix number */</span> <a name="l00594"></a>00594 <span class="keywordflow">if</span>(n==1) {ncurr++; <span class="keywordflow">continue</span>;} <a name="l00595"></a>00595 <span class="comment">/* If not, then subtract 1 from all matrix numbers that are larger */</span> <a name="l00596"></a>00596 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <a name="l00597"></a>00597 <span class="keywordflow">if</span>(matval[i].plane>ncurr) { <a name="l00598"></a>00598 <span class="comment">/*printf(" plane %d -> plane %d\n", matval[i].plane, matval[i].plane-1);*/</span> <a name="l00599"></a>00599 matval[i].<a class="code" href="structECAT7__Matval.html#a041cdbab82513cac692f52c4e7364093">plane</a>--; n++; <a name="l00600"></a>00600 } <a name="l00601"></a>00601 <span class="comment">/* If no larger values were found any more, then quit */</span> <a name="l00602"></a>00602 <span class="keywordflow">if</span>(n<1) <span class="keywordflow">break</span>; <a name="l00603"></a>00603 } <a name="l00604"></a>00604 } <a name="l00605"></a>00605 <a name="l00606"></a>00606 <span class="comment">/* Frames */</span> <a name="l00607"></a>00607 <span class="keywordflow">if</span>(do_frames!=0) { <a name="l00608"></a>00608 ncurr=1; <a name="l00609"></a>00609 <span class="keywordflow">while</span>(ncurr <= ml->matrixNr) { <a name="l00610"></a>00610 <span class="comment">/* Find any matrix with this number? */</span> <a name="l00611"></a>00611 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].frame==ncurr) {n=1; <span class="keywordflow">break</span>;} <a name="l00612"></a>00612 <span class="comment">/* If yes, then go on to the next matrix number */</span> <a name="l00613"></a>00613 <span class="keywordflow">if</span>(n==1) {ncurr++; <span class="keywordflow">continue</span>;} <a name="l00614"></a>00614 <span class="comment">/* If not, then subtract 1 from all matrix numbers that are larger */</span> <a name="l00615"></a>00615 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <a name="l00616"></a>00616 <span class="keywordflow">if</span>(matval[i].frame>ncurr) {matval[i].<a class="code" href="structECAT7__Matval.html#afc531f65c0b1b58cbcffb947df62400b">frame</a>--; n++;} <a name="l00617"></a>00617 <span class="comment">/* If no larger values were found any more, then quit */</span> <a name="l00618"></a>00618 <span class="keywordflow">if</span>(n<1) <span class="keywordflow">break</span>; <a name="l00619"></a>00619 } <a name="l00620"></a>00620 } <a name="l00621"></a>00621 <a name="l00622"></a>00622 <span class="comment">/* Gates */</span> <a name="l00623"></a>00623 <span class="keywordflow">if</span>(do_gates!=0) { <a name="l00624"></a>00624 ncurr=1; <a name="l00625"></a>00625 <span class="keywordflow">while</span>(ncurr <= ml->matrixNr) { <a name="l00626"></a>00626 <span class="comment">/* Find any matrix with this number? */</span> <a name="l00627"></a>00627 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].gate==ncurr) {n=1; <span class="keywordflow">break</span>;} <a name="l00628"></a>00628 <span class="comment">/* If yes, then go on to the next matrix number */</span> <a name="l00629"></a>00629 <span class="keywordflow">if</span>(n==1) {ncurr++; <span class="keywordflow">continue</span>;} <a name="l00630"></a>00630 <span class="comment">/* If not, then subtract 1 from all matrix numbers that are larger */</span> <a name="l00631"></a>00631 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <a name="l00632"></a>00632 <span class="keywordflow">if</span>(matval[i].gate>ncurr) {matval[i].<a class="code" href="structECAT7__Matval.html#a0f094bb9f2d880fa875ecc6110ace13b">gate</a>--; n++;} <a name="l00633"></a>00633 <span class="comment">/* If no larger values were found any more, then quit */</span> <a name="l00634"></a>00634 <span class="keywordflow">if</span>(n<1) <span class="keywordflow">break</span>; <a name="l00635"></a>00635 } <a name="l00636"></a>00636 } <a name="l00637"></a>00637 <a name="l00638"></a>00638 <span class="comment">/* Beds */</span> <a name="l00639"></a>00639 <span class="keywordflow">if</span>(do_beds!=0) { <a name="l00640"></a>00640 ncurr=1; <a name="l00641"></a>00641 <span class="keywordflow">while</span>(ncurr <= ml->matrixNr) { <a name="l00642"></a>00642 <span class="comment">/* Find any matrix with this number? */</span> <a name="l00643"></a>00643 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <span class="keywordflow">if</span>(matval[i].bed==ncurr) {n=1; <span class="keywordflow">break</span>;} <a name="l00644"></a>00644 <span class="comment">/* If yes, then go on to the next matrix number */</span> <a name="l00645"></a>00645 <span class="keywordflow">if</span>(n==1) {ncurr++; <span class="keywordflow">continue</span>;} <a name="l00646"></a>00646 <span class="comment">/* If not, then subtract 1 from all matrix numbers that are larger */</span> <a name="l00647"></a>00647 <span class="keywordflow">for</span>(i=0, n=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) <a name="l00648"></a>00648 <span class="keywordflow">if</span>(matval[i].bed>ncurr) {matval[i].<a class="code" href="structECAT7__Matval.html#af1f94ed7c49267bed701b8a0fa690ecd">bed</a>--; n++;} <a name="l00649"></a>00649 <span class="comment">/* If no larger values were found any more, then quit */</span> <a name="l00650"></a>00650 <span class="keywordflow">if</span>(n<1) <span class="keywordflow">break</span>; <a name="l00651"></a>00651 } <a name="l00652"></a>00652 } <a name="l00653"></a>00653 <a name="l00654"></a>00654 <span class="comment">/* Write matrix values (possibly changed) into matrix list */</span> <a name="l00655"></a>00655 <span class="keywordflow">for</span>(i=0; i<ml-><a class="code" href="structECAT7__MATRIXLIST.html#af3e725f10fb1d8e7768330b26cd37691">matrixNr</a>; i++) ml-><a class="code" href="structECAT7__MATRIXLIST.html#a691b0a0862d05c2eb983930022a908a7">matdir</a>[i].<a class="code" href="structECAT7__MatDir.html#a496411c7ccf25471dd7e7af220160ffd">id</a>=<a class="code" href="ecat7ml_8c.html#acad3263ebf24cf2e10d7c43491810481">ecat7_val_to_id</a>( <a name="l00656"></a>00656 matval[i].frame, matval[i].plane, <a name="l00657"></a>00657 matval[i].gate, matval[i].data, <a name="l00658"></a>00658 matval[i].bed); <a name="l00659"></a>00659 free(matval); <a name="l00660"></a>00660 <span class="keywordflow">return</span>(0); <a name="l00661"></a>00661 } <a name="l00662"></a>00662 <span class="comment">/*****************************************************************************/</span> <a name="l00663"></a>00663 <a name="l00664"></a>00664 <span class="comment">/*****************************************************************************/</span> <a name="l00665"></a>00665 </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated on Mon Aug 8 2011 by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>