Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > ce1f17e7ec5e62f35dbe9f064c5f74d7 > files > 476

libtpcimgio-devel-1.5.10-4.fc15.i686.rpm

<!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>ecat7w.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&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;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&#160;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">ecat7w.c</div>  </div>
</div>
<div class="contents">
<a href="ecat7w_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-2008 Turku PET Centre</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">  Library file: ecat7w.c</span>
<a name="l00006"></a>00006 <span class="comment">  Description:  Functions for writing ECAT 7.x format.</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment">  This program is free software; you can redistribute it and/or modify it under</span>
<a name="l00009"></a>00009 <span class="comment">  the terms of the GNU General Public License as published by the Free Software</span>
<a name="l00010"></a>00010 <span class="comment">  Foundation; either version 2 of the License, or (at your option) any later</span>
<a name="l00011"></a>00011 <span class="comment">  version.</span>
<a name="l00012"></a>00012 <span class="comment"></span>
<a name="l00013"></a>00013 <span class="comment">  This program is distributed in the hope that it will be useful, but WITHOUT</span>
<a name="l00014"></a>00014 <span class="comment">  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span>
<a name="l00015"></a>00015 <span class="comment">  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</span>
<a name="l00016"></a>00016 <span class="comment"></span>
<a name="l00017"></a>00017 <span class="comment">  You should have received a copy of the GNU General Public License along with</span>
<a name="l00018"></a>00018 <span class="comment">  this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span>
<a name="l00019"></a>00019 <span class="comment">  Place, Suite 330, Boston, MA 02111-1307 USA.</span>
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment">  Turku PET Centre hereby disclaims all copyright interest in the program.</span>
<a name="l00022"></a>00022 <span class="comment">  Juhani Knuuti</span>
<a name="l00023"></a>00023 <span class="comment">  Director, Professor</span>
<a name="l00024"></a>00024 <span class="comment">  Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi/</span>
<a name="l00025"></a>00025 <span class="comment">  </span>
<a name="l00026"></a>00026 <span class="comment">  Modification history:</span>
<a name="l00027"></a>00027 <span class="comment">  2003-07-24 Vesa Oikonen</span>
<a name="l00028"></a>00028 <span class="comment">    First created.</span>
<a name="l00029"></a>00029 <span class="comment">  2003-09-04 VO</span>
<a name="l00030"></a>00030 <span class="comment">    Added support for 3D sinograms, ecat7WriteScanMatrix().</span>
<a name="l00031"></a>00031 <span class="comment">    Removed functions ecat7wFloat() and ecat7wInt().</span>
<a name="l00032"></a>00032 <span class="comment">  2003-11-30 VO</span>
<a name="l00033"></a>00033 <span class="comment">    For now, calls temp_roundf() instead of roundf().</span>
<a name="l00034"></a>00034 <span class="comment">  2004-01-07 VO</span>
<a name="l00035"></a>00035 <span class="comment">    ecat7WriteImageMatrix(): corrected img min&amp;max in header.</span>
<a name="l00036"></a>00036 <span class="comment">  2004-09-17 VO</span>
<a name="l00037"></a>00037 <span class="comment">    Changes in comment style.</span>
<a name="l00038"></a>00038 <span class="comment">    Removed code that was previously commented out.</span>
<a name="l00039"></a>00039 <span class="comment">  2004-12-28 VO</span>
<a name="l00040"></a>00040 <span class="comment">    Included function ecat7_is_scaling_needed().</span>
<a name="l00041"></a>00041 <span class="comment">    This function is applied to determine whether scal factor can be set to</span>
<a name="l00042"></a>00042 <span class="comment">    one in case that all pixel values are close to integers and small enough.</span>
<a name="l00043"></a>00043 <span class="comment">  2007-01-27 VO</span>
<a name="l00044"></a>00044 <span class="comment">    Unsigned char pointer was corrected to signed in ecat7WriteMatrixdata().</span>
<a name="l00045"></a>00045 <span class="comment">  2007-03-27 VO</span>
<a name="l00046"></a>00046 <span class="comment">    Added ecat7WritePolarmapMatrix().</span>
<a name="l00047"></a>00047 <span class="comment">  2007-09-02 VO</span>
<a name="l00048"></a>00048 <span class="comment">    Backup file extension changed from % to .bak.</span>
<a name="l00049"></a>00049 <span class="comment"></span>
<a name="l00050"></a>00050 <span class="comment">******************************************************************************/</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00057"></a>00057 <span class="comment">/*****************************************************************************/</span>
<a name="l00058"></a>00058 <span class="preprocessor">#include &quot;swap.h&quot;</span>
<a name="l00059"></a>00059 <span class="preprocessor">#include &quot;petc99.h&quot;</span>
<a name="l00060"></a>00060 <span class="preprocessor">#include &quot;<a class="code" href="ecat7_8h.html">include/ecat7.h</a>&quot;</span>
<a name="l00061"></a>00061 <span class="comment">/*****************************************************************************/</span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment">/*****************************************************************************/</span>
<a name="l00073"></a><a class="code" href="ecat7_8h.html#ae4ee4bf17962633b914d5c731ac7c321">00073</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#ae4ee4bf17962633b914d5c731ac7c321">ecat7WriteMainheader</a>(FILE *fp, <a class="code" href="structecat7__mainheader.html">ECAT7_mainheader</a> *h) {
<a name="l00074"></a>00074   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00075"></a>00075   <span class="keywordtype">int</span> little;
<a name="l00076"></a>00076 
<a name="l00077"></a>00077   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteMainheader()\n&quot;</span>);
<a name="l00078"></a>00078   <span class="comment">/* Check arguments */</span>
<a name="l00079"></a>00079   <span class="keywordflow">if</span>(fp==NULL || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00080"></a>00080   little=little_endian();
<a name="l00081"></a>00081   <span class="comment">/* Clear buf */</span>
<a name="l00082"></a>00082   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00083"></a>00083 
<a name="l00084"></a>00084   <span class="comment">/* Copy header contents into buffer and change byte order if necessary */</span>
<a name="l00085"></a>00085   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a71cb64edce706f383f3e68b9548b9ec3">magic_number</a>, 14);
<a name="l00086"></a>00086   memcpy(buf+14, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a229fda43a3abcdb4e055f2b5791823a8">original_file_name</a>, 32);
<a name="l00087"></a>00087   memcpy(buf+46, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a413498a0395e39c969bf7bf401cf023c">sw_version</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+46, 2);
<a name="l00088"></a>00088   memcpy(buf+48, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ae6537726ed92ab81d76c8985fff81244">system_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+48, 2);
<a name="l00089"></a>00089   memcpy(buf+50, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a1914b3a0ebf3077d090752d6ef66c757">file_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+50, 2);
<a name="l00090"></a>00090   memcpy(buf+52, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a03420554a59f09d747e217011f1859c0">serial_number</a>, 10);
<a name="l00091"></a>00091   memcpy(buf+62, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a1ad956ffc4f0dc8e9bd473bfa20e6b81">scan_start_time</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+62, 4);
<a name="l00092"></a>00092   memcpy(buf+66, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a1a6eea4ac705c0f84f755ac6cb12d69d">isotope_name</a>, 8);
<a name="l00093"></a>00093   memcpy(buf+74, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a9389f1b044165caf1a4b79007cb6cdfd">isotope_halflife</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+74, 4);
<a name="l00094"></a>00094   memcpy(buf+78, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ab353f8a8b1166323fe7798d81004a225">radiopharmaceutical</a>, 32);
<a name="l00095"></a>00095   memcpy(buf+110, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a5bcbe3f6bdf521d7bc709b79aa8359c0">gantry_tilt</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+110, 4);
<a name="l00096"></a>00096   memcpy(buf+114, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a81f5c30a8cfa68da62bd4121b4251e6f">gantry_rotation</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+114, 4);
<a name="l00097"></a>00097   memcpy(buf+118, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a8e0caba01dedd5e94dbd36d6db107149">bed_elevation</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+118, 4);
<a name="l00098"></a>00098   memcpy(buf+122, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ac39e16ca7d54c7c1ba069f3581700d16">intrinsic_tilt</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+122, 4);
<a name="l00099"></a>00099   memcpy(buf+126, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a6bb42a878ca6292118b2e591eff6b965">wobble_speed</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+126, 2);
<a name="l00100"></a>00100   memcpy(buf+128, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a637cb9f894c15a7ff4f147ac1810a80f">transm_source_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+128, 2);
<a name="l00101"></a>00101   memcpy(buf+130, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a1be6bc903aaef62d6cfac179b7b8a05b">distance_scanned</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+130, 4);
<a name="l00102"></a>00102   memcpy(buf+134, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a3dff6c0caf29b90298e542c6e76af2a1">transaxial_fov</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+134, 4);
<a name="l00103"></a>00103   memcpy(buf+138, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a5682114a0723ab5c3eb65ef673f85779">angular_compression</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+138, 2);
<a name="l00104"></a>00104   memcpy(buf+140, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a8b370daee9ea0f228870038831684a04">coin_samp_mode</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+140, 2);
<a name="l00105"></a>00105   memcpy(buf+142, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a97197dc85925d45fc1bf501c2edb94cc">axial_samp_mode</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+142, 2);
<a name="l00106"></a>00106   memcpy(buf+144, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ad5be044d585696c1f35bb8b63c26fec9">ecat_calibration_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+144, 4);
<a name="l00107"></a>00107   memcpy(buf+148, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a56bb68347079aca9062f24fe0fb24a63">calibration_units</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+148, 2);
<a name="l00108"></a>00108   memcpy(buf+150, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a9ee5c316fc447e305593efc25f51dc67">calibration_units_label</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+150, 2);
<a name="l00109"></a>00109   memcpy(buf+152, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a11ae37f7e7af8371b4884aff851dec2b">compression_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+152, 2);
<a name="l00110"></a>00110   memcpy(buf+154, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#af24db33af652c26d6b2b8a580f3515c4">study_type</a>, 12);
<a name="l00111"></a>00111   memcpy(buf+166, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a3ba61576ab7c202d8d9ba320ea352fe3">patient_id</a>, 16);
<a name="l00112"></a>00112   memcpy(buf+182, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a077ddc2daa174f716708c2077e9ea838">patient_name</a>, 32);
<a name="l00113"></a>00113   memcpy(buf+214, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ae87bc1bf2265ce23abe05b38a4f40fb8">patient_sex</a>, 1);
<a name="l00114"></a>00114   memcpy(buf+215, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#acd68a5818bdac5c729a43959b0cddfb7">patient_dexterity</a>, 1);
<a name="l00115"></a>00115   memcpy(buf+216, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ad308b992472cc20d57261aa792159cdd">patient_age</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+216, 4);
<a name="l00116"></a>00116   memcpy(buf+220, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ab0f4df121ec2ed3b4513f25030d7a041">patient_height</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+220, 4);
<a name="l00117"></a>00117   memcpy(buf+224, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a5b2180feb84eb042e654666703a068dd">patient_weight</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+224, 4);
<a name="l00118"></a>00118   memcpy(buf+228, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ab803645ef6896ad52033966c67ef985c">patient_birth_date</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+228, 4);
<a name="l00119"></a>00119   memcpy(buf+232, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a14b5bcdff318fa65d2d95126ebc550fc">physician_name</a>, 32);
<a name="l00120"></a>00120   memcpy(buf+264, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a973da5bf47d9376aff843b93e125156a">operator_name</a>, 32);
<a name="l00121"></a>00121   memcpy(buf+296, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a08d61531e0bfce977dd5542f175925d9">study_description</a>, 32);
<a name="l00122"></a>00122   memcpy(buf+328, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a8cb7331fc88e1dbd17e0f403f4d7ae8e">acquisition_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+328, 2);
<a name="l00123"></a>00123   memcpy(buf+330, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a1815f9e0d0083df1ba25af49d033d202">patient_orientation</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+330, 2);
<a name="l00124"></a>00124   memcpy(buf+332, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a2db57a2b51c8d87a9ab9ff09a811c556">facility_name</a>, 20);
<a name="l00125"></a>00125   memcpy(buf+352, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#aacea3a6d9b88add8710823f1c17acc37">num_planes</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+352, 2);
<a name="l00126"></a>00126   memcpy(buf+354, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a7df83de0bdabd7ebf190e1a58bfc2e20">num_frames</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+354, 2);
<a name="l00127"></a>00127   memcpy(buf+356, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a45cd434d5473194ffdbb27c99d9d7e6a">num_gates</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+356, 2);
<a name="l00128"></a>00128   memcpy(buf+358, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#acd90030d2317a4af5583431115b21a4a">num_bed_pos</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+358, 2);
<a name="l00129"></a>00129   memcpy(buf+360, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a8a6bbcaf85225c67f8bfa5e564318e79">init_bed_position</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+360, 4);
<a name="l00130"></a>00130   memcpy(buf+364, h-&gt;<a class="code" href="structecat7__mainheader.html#af66557399c7d155de452a077228fea71">bed_position</a>, 15*4); <span class="keywordflow">if</span>(little) swawbip(buf+364, 15*4);
<a name="l00131"></a>00131   memcpy(buf+424, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a786937fcd3117a9d287da4636e3c0f37">plane_separation</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+424, 4);
<a name="l00132"></a>00132   memcpy(buf+428, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ae649a9fa654b298d7d06d6cfd1648e9c">lwr_sctr_thres</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+428, 2);
<a name="l00133"></a>00133   memcpy(buf+430, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ae07a9464fb11913d993a7ce9aaac588f">lwr_true_thres</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+430, 2);
<a name="l00134"></a>00134   memcpy(buf+432, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a4f229882ef975488024b05405f56d3ba">upr_true_thres</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+432, 2);
<a name="l00135"></a>00135   memcpy(buf+434, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a957502542c1a109b52a59af75ebcb27e">user_process_code</a>, 10);
<a name="l00136"></a>00136   memcpy(buf+444, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#ab04f1792d0c7f628dd8e05c5a8f38363">acquisition_mode</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+444, 2);
<a name="l00137"></a>00137   memcpy(buf+446, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#abc625a3c1c4052d87e502bfca8599b8f">bin_size</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+446, 4);
<a name="l00138"></a>00138   memcpy(buf+450, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#aca100a7dd48d4b56c1ec7028716c6a68">branching_fraction</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+450, 4);
<a name="l00139"></a>00139   memcpy(buf+454, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a7d6f47d203ff147bd73cebe41167474c">dose_start_time</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+454, 4);
<a name="l00140"></a>00140   memcpy(buf+458, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a002205eea64b6f6be8a8c254c8a6b95f">dosage</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+458, 4);
<a name="l00141"></a>00141   memcpy(buf+462, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a0d4893dd1647140f775698b5649223d4">well_counter_corr_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+462, 4);
<a name="l00142"></a>00142   memcpy(buf+466, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#aa6bbc6d3bc1a60f51dd721db2c3be09d">data_units</a>, 32);
<a name="l00143"></a>00143   memcpy(buf+498, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#abb92c232a653327ce7a089be23f6df09">septa_state</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+498, 2);
<a name="l00144"></a>00144   memcpy(buf+500, &amp;h-&gt;<a class="code" href="structecat7__mainheader.html#a5766625b9e684946431b919aff7426b9">fill_cti</a>, 12);
<a name="l00145"></a>00145 
<a name="l00146"></a>00146   <span class="comment">/* Write main header */</span>
<a name="l00147"></a>00147   fseek(fp, 0*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=0*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(4);
<a name="l00148"></a>00148   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00149"></a>00149 
<a name="l00150"></a>00150   <span class="keywordflow">return</span>(0);
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 <span class="comment">/*****************************************************************************/</span>
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 <span class="comment">/*****************************************************************************/</span>
<a name="l00164"></a><a class="code" href="ecat7_8h.html#a492041a42e77c2958cdd06c17c3267e9">00164</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a492041a42e77c2958cdd06c17c3267e9">ecat7WriteImageheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__imageheader.html">ECAT7_imageheader</a> *h) {
<a name="l00165"></a>00165   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00166"></a>00166   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00167"></a>00167 
<a name="l00168"></a>00168   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteImageheader()\n&quot;</span>);
<a name="l00169"></a>00169   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00170"></a>00170   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00171"></a>00171   <span class="comment">/* Clear buf */</span>
<a name="l00172"></a>00172   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00173"></a>00173   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00174"></a>00174   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00175"></a>00175   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00176"></a>00176   
<a name="l00177"></a>00177   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00178"></a>00178   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00179"></a>00179   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#acabca0e942a462b769c59804250b9a1c">num_dimensions</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00180"></a>00180   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a37550f6ce6a114de12aa0d038f573230">x_dimension</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00181"></a>00181   memcpy(buf+6, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a217d17f8b1f921fad128ce923fa21c35">y_dimension</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+6, 2);
<a name="l00182"></a>00182   memcpy(buf+8, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a7d4bc496c4aa5581d41dff3e5b40a231">z_dimension</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+8, 2);
<a name="l00183"></a>00183   memcpy(buf+10, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a340a9f9df62d09e5ea8deefd64fec57d">x_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+10, 4);
<a name="l00184"></a>00184   memcpy(buf+14, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ad8fcacd511c334e938839c2a7730bbc3">y_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+14, 4);
<a name="l00185"></a>00185   memcpy(buf+18, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ab08e016d3c4fb780aeb1048398308254">z_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+18, 4);
<a name="l00186"></a>00186   memcpy(buf+22, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a7290c1acb6f8263f85492e3b5c44cdc9">recon_zoom</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+22, 4);
<a name="l00187"></a>00187   memcpy(buf+26, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a2e44d8de4b5809864432376f713968ec">scale_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+26, 4);
<a name="l00188"></a>00188   memcpy(buf+30, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ad599fd1c46c31b598fb2a6f376d562eb">image_min</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+30, 2);
<a name="l00189"></a>00189   memcpy(buf+32, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a08e876d5e60f96c5b90fc99eeedde10f">image_max</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+32, 2);
<a name="l00190"></a>00190   memcpy(buf+34, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a3f2c13786fd5e912c31f481f1b48cff3">x_pixel_size</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+34, 4);
<a name="l00191"></a>00191   memcpy(buf+38, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#aefd3bbd592bedba8d68dbec20d855586">y_pixel_size</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+38, 4);
<a name="l00192"></a>00192   memcpy(buf+42, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a404d5327064305a7a9dfe75831b29581">z_pixel_size</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+42, 4);
<a name="l00193"></a>00193   memcpy(buf+46, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ae75244f1e5532bb257095e7583ef79a3">frame_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+46, 4);
<a name="l00194"></a>00194   memcpy(buf+50, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a5fb0b8e2eec4391ed600f0efa4666631">frame_start_time</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+50, 4);
<a name="l00195"></a>00195   memcpy(buf+54, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ad5bd2f0c18209cb80d17c9ccabd44753">filter_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+54, 2);
<a name="l00196"></a>00196   memcpy(buf+56, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a94c84cc00c6100c166167eaf0d4d34c9">x_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+56, 4);
<a name="l00197"></a>00197   memcpy(buf+60, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a88478cdda647f217f81ba4fe753f8602">y_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+60, 4);
<a name="l00198"></a>00198   memcpy(buf+64, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#aa0599cfeedd3708b353ef027f281657d">z_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+64, 4);
<a name="l00199"></a>00199   memcpy(buf+68, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a8649bac62fab217d1b49131a6bbeaffa">num_r_elements</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+68, 4);
<a name="l00200"></a>00200   memcpy(buf+72, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a046f5ff250412ec423b6ee43b8cf1496">num_angles</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+72, 4);
<a name="l00201"></a>00201   memcpy(buf+76, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ac9bdf6594e830a86e04f92e8c5603225">z_rotation_angle</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+76, 4);
<a name="l00202"></a>00202   memcpy(buf+80, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a753cec72803431b0b3ecf130b2fee645">decay_corr_fctr</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+80, 4);
<a name="l00203"></a>00203   memcpy(buf+84, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a6e617bc2f7f9ddd225af3946198e2d06">processing_code</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+84, 4);
<a name="l00204"></a>00204   memcpy(buf+88, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a5f8654cf5e2a615ee18a0b2226ae2b36">gate_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+88, 4);
<a name="l00205"></a>00205   memcpy(buf+92, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#af2652b5447df30fa1198d34a2a6c1a81">r_wave_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+92, 4);
<a name="l00206"></a>00206   memcpy(buf+96, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a9562593e2089ae493975e4770c455038">num_accepted_beats</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+96, 4);
<a name="l00207"></a>00207   memcpy(buf+100, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#afbe5e1b92387d70242a64e0253c8d196">filter_cutoff_frequency</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+100, 4);
<a name="l00208"></a>00208   memcpy(buf+104, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a92cbc1f31172ccde80cfbc74763c6bc7">filter_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+104, 4);
<a name="l00209"></a>00209   memcpy(buf+108, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#aab3e31ea98f55be2dc136b6d38c6084c">filter_ramp_slope</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+108, 4);
<a name="l00210"></a>00210   memcpy(buf+112, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a09d1048e2e74c28630242ffa98270ed0">filter_order</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+112, 2);
<a name="l00211"></a>00211   memcpy(buf+114, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ac8b2021a00f2c1acd43213ae780e9993">filter_scatter_fraction</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+114, 4);
<a name="l00212"></a>00212   memcpy(buf+118, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a26a5abf25a440aee0f0adfe0eb5a781b">filter_scatter_slope</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+118, 4);
<a name="l00213"></a>00213   memcpy(buf+122, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ad5ed4d561b195452ddb325baab3adbb2">annotation</a>, 40);
<a name="l00214"></a>00214   memcpy(buf+162, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a5ab2348c59531dd764f4b659aaf4f75d">mt_1_1</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+162, 4);
<a name="l00215"></a>00215   memcpy(buf+166, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a0b84bc9d478661de5916723009b846c6">mt_1_2</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+166, 4);
<a name="l00216"></a>00216   memcpy(buf+170, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ac6112b47c4727d97a00927ec2cd66e08">mt_1_3</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+170, 4);
<a name="l00217"></a>00217   memcpy(buf+174, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a9aa22eb676327cd80cc852f1da66b2e9">mt_2_1</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+174, 4);
<a name="l00218"></a>00218   memcpy(buf+178, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a0387c09ae6ce5366bd9f557666807db1">mt_2_2</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+178, 4);
<a name="l00219"></a>00219   memcpy(buf+182, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a9f12cf3a77cbec5884db289e3f671b88">mt_2_3</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+182, 4);
<a name="l00220"></a>00220   memcpy(buf+186, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a93f68b4a932241c32442675541b5eafa">mt_3_1</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+186, 4);
<a name="l00221"></a>00221   memcpy(buf+190, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a3ff42a2285fff0e821df591aaf089491">mt_3_2</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+190, 4);
<a name="l00222"></a>00222   memcpy(buf+194, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#af571054289d88e95552f0a792667b84f">mt_3_3</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+194, 4);
<a name="l00223"></a>00223   memcpy(buf+198, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#af1a33983eb2c35e26f2ca2531b092d64">rfilter_cutoff</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+198, 4);
<a name="l00224"></a>00224   memcpy(buf+202, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ab3eaa110df4b571b92924dd94826f3c0">rfilter_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+202, 4);
<a name="l00225"></a>00225   memcpy(buf+206, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a2ffc2cb4c75c295a5e58af8592ce9a4c">rfilter_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+206, 2);
<a name="l00226"></a>00226   memcpy(buf+208, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a847e512ab018e42b37430b291f2a6e1b">rfilter_order</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+208, 2);
<a name="l00227"></a>00227   memcpy(buf+210, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a574df5d81d5b1ab3b5b0ada42c976dbe">zfilter_cutoff</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+210, 4);
<a name="l00228"></a>00228   memcpy(buf+214, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#aacfbdbd324b30a3b319eeca5bbeeee12">zfilter_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+214, 4);
<a name="l00229"></a>00229   memcpy(buf+218, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ae90d91c961a0ddaca2e1e3bbd77095c7">zfilter_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+218, 2);
<a name="l00230"></a>00230   memcpy(buf+220, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a8f7008e7dbfe7e4a7121c254375f0f47">zfilter_order</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+220, 2);
<a name="l00231"></a>00231   memcpy(buf+222, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ae68e680639ac505c93d21ec447481ebf">mt_1_4</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+222, 4);
<a name="l00232"></a>00232   memcpy(buf+226, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#adcd2dc3fbd8ded9a1ed5f8d1e85dbda8">mt_2_4</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+226, 4);
<a name="l00233"></a>00233   memcpy(buf+230, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ae3481c71f0ab8a1895d37fc7de71ed80">mt_3_4</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+230, 4);
<a name="l00234"></a>00234   memcpy(buf+234, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a26e3211da4e7bdee598a912f59bbd80c">scatter_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+234, 2);
<a name="l00235"></a>00235   memcpy(buf+236, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a060576c7efe995f93a17fb73881b6607">recon_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+236, 2);
<a name="l00236"></a>00236   memcpy(buf+238, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ae67f441f35e6b40499b03fca8a7d3d90">recon_views</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+238, 2);
<a name="l00237"></a>00237   memcpy(buf+240, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#a70ba01c4d16b5c5e5ad7b6a2143aba4c">fill_cti</a>, 87);
<a name="l00238"></a>00238   memcpy(buf+414, &amp;h-&gt;<a class="code" href="structecat7__imageheader.html#ac7858af3c6aeab6ee47867cba833e0a9">fill_user</a>, 48);
<a name="l00239"></a>00239 
<a name="l00240"></a>00240   <span class="comment">/* Write header */</span>
<a name="l00241"></a>00241   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>(4);
<a name="l00242"></a>00242   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00243"></a>00243 
<a name="l00244"></a>00244   <span class="keywordflow">return</span>(0);
<a name="l00245"></a>00245 }
<a name="l00246"></a>00246 <span class="comment">/*****************************************************************************/</span>
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 <span class="comment">/*****************************************************************************/</span>
<a name="l00258"></a><a class="code" href="ecat7_8h.html#ab8c55e6b9648b24ae5e52deac17ec095">00258</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#ab8c55e6b9648b24ae5e52deac17ec095">ecat7WriteAttenheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__attenheader.html">ECAT7_attenheader</a> *h) {
<a name="l00259"></a>00259   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00260"></a>00260   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00261"></a>00261 
<a name="l00262"></a>00262   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteAttenheader()\n&quot;</span>);
<a name="l00263"></a>00263   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00264"></a>00264   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00265"></a>00265   <span class="comment">/* Clear buf */</span>
<a name="l00266"></a>00266   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00267"></a>00267   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00268"></a>00268   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00269"></a>00269   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00270"></a>00270   
<a name="l00271"></a>00271   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00272"></a>00272   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a1e279bd4817d0a7e940b796ebb901d39">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00273"></a>00273   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a26c4cf72bd2f93808c53113c45e23552">num_dimensions</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00274"></a>00274   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a559039bce5d7432a2c1b2627400055ed">attenuation_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00275"></a>00275   memcpy(buf+6, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#ab469110a7579b07996d48b7ec6367cc5">num_r_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+6, 2);
<a name="l00276"></a>00276   memcpy(buf+8, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a5b3cb8793edf2f160a1c8893b09ffa4e">num_angles</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+8, 2);
<a name="l00277"></a>00277   memcpy(buf+10, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a78a581032441626011b5394a43bdf2af">num_z_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+10, 2);
<a name="l00278"></a>00278   memcpy(buf+12, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#ab27975a4dbecf07f924abec9ca3022d2">ring_difference</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+12, 2);
<a name="l00279"></a>00279   memcpy(buf+14, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#ad25d43e88b93dc981f8d3dbc85b246a4">x_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+14, 4);
<a name="l00280"></a>00280   memcpy(buf+18, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a9f559f6c3fdde8d0bf93d110a9057b8b">y_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+18, 4);
<a name="l00281"></a>00281   memcpy(buf+22, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a409675e4d6361e84c616079c2316f061">z_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+22, 4);
<a name="l00282"></a>00282   memcpy(buf+26, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a9d90102a2f5032e260edbb5834dff17f">w_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+26, 4);
<a name="l00283"></a>00283   memcpy(buf+30, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a6c90e753da243d94a24384873b0195b3">scale_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+30, 4);
<a name="l00284"></a>00284   memcpy(buf+34, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#adb7c3a7f9ad331e2e2d66ad397d1061e">x_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+34, 4);
<a name="l00285"></a>00285   memcpy(buf+38, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#af00ef016e4bec39cccb0566e0d1e1beb">y_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+38, 4);
<a name="l00286"></a>00286   memcpy(buf+42, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#aade44803290eb7c042e8db22b647c3f3">x_radius</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+42, 4);
<a name="l00287"></a>00287   memcpy(buf+46, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a885d8e8ab2ce770cf193b4273d591de0">y_radius</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+46, 4);
<a name="l00288"></a>00288   memcpy(buf+50, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a8ee01a9d388f1116b71395e62618ced1">tilt_angle</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+50, 4);
<a name="l00289"></a>00289   memcpy(buf+54, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#acfdb1bdf8255158bf0ce77e6b2d682e3">attenuation_coeff</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+54, 4);
<a name="l00290"></a>00290   memcpy(buf+58, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a6734bcf692194b4b2fe3477574549b04">attenuation_min</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+58, 4);
<a name="l00291"></a>00291   memcpy(buf+62, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#abc998fff1d231a8c23ab7bd75e980289">attenuation_max</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+62, 4);
<a name="l00292"></a>00292   memcpy(buf+66, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#ad5b24b2b096cbddc14a358ba21be77d2">skull_thickness</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+66, 4);
<a name="l00293"></a>00293   memcpy(buf+70, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#ac4a70cc92f5cd58fcd9c4d10757c04a0">num_additional_atten_coeff</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+70, 2);
<a name="l00294"></a>00294   memcpy(buf+72, h-&gt;<a class="code" href="structecat7__attenheader.html#ab71ff5127a01d22c4c376a82a128f926">additional_atten_coeff</a>, 8*4); <span class="keywordflow">if</span>(little) swawbip(buf+72, 8*4);
<a name="l00295"></a>00295   memcpy(buf+104, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a2ec9a53c0910ba896e41f486b479fd7c">edge_finding_threshold</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+104, 4);
<a name="l00296"></a>00296   memcpy(buf+108, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#addc2063b495772262146f9385c294323">storage_order</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+108, 2);
<a name="l00297"></a>00297   memcpy(buf+110, &amp;h-&gt;<a class="code" href="structecat7__attenheader.html#a45d73fa0fd340f998265aaf15a123ba8">span</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+110, 2);
<a name="l00298"></a>00298   memcpy(buf+112, h-&gt;<a class="code" href="structecat7__attenheader.html#aeb743233aff66821f8cfbf3ec1f64d3b">z_elements</a>, 64*2); <span class="keywordflow">if</span>(little) swabip(buf+112, 64*2);
<a name="l00299"></a>00299   memcpy(buf+240, h-&gt;<a class="code" href="structecat7__attenheader.html#a81a71d398c08000665962d87c9c62340">fill_cti</a>, 86*2); <span class="keywordflow">if</span>(little) swabip(buf+240, 86*2);
<a name="l00300"></a>00300   memcpy(buf+412, h-&gt;<a class="code" href="structecat7__attenheader.html#abb0256f4ba630ed598d257a8a797d449">fill_user</a>, 50*2); <span class="keywordflow">if</span>(little) swabip(buf+412, 50*2);
<a name="l00301"></a>00301 
<a name="l00302"></a>00302   <span class="comment">/* Write header */</span>
<a name="l00303"></a>00303   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00304"></a>00304   <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(4);
<a name="l00305"></a>00305   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00306"></a>00306 
<a name="l00307"></a>00307   <span class="keywordflow">return</span>(0);
<a name="l00308"></a>00308 }
<a name="l00309"></a>00309 <span class="comment">/*****************************************************************************/</span>
<a name="l00310"></a>00310 
<a name="l00311"></a>00311 <span class="comment">/*****************************************************************************/</span>
<a name="l00321"></a><a class="code" href="ecat7_8h.html#a9edfe58b989a0b6e628f7be1103fec1b">00321</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a9edfe58b989a0b6e628f7be1103fec1b">ecat7WritePolmapheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__polmapheader.html">ECAT7_polmapheader</a> *h) {
<a name="l00322"></a>00322   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00323"></a>00323   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00324"></a>00324 
<a name="l00325"></a>00325   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WritePolmapheader()\n&quot;</span>);
<a name="l00326"></a>00326   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00327"></a>00327   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00328"></a>00328   <span class="comment">/* Clear buf */</span>
<a name="l00329"></a>00329   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00330"></a>00330   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00331"></a>00331   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00332"></a>00332   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00333"></a>00333   
<a name="l00334"></a>00334   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00335"></a>00335   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00336"></a>00336   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a1c42cbb82e3d3abdea6eab7893e3151f">polar_map_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00337"></a>00337   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a503caad4ac64580ff3508463ae8e2342">num_rings</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00338"></a>00338   memcpy(buf+6, h-&gt;<a class="code" href="structecat7__polmapheader.html#a7888f1b2bc8adcc5bcbf918bbbb82dbb">sectors_per_ring</a>, 32*2); <span class="keywordflow">if</span>(little) swabip(buf+6, 32*2);
<a name="l00339"></a>00339   memcpy(buf+70, h-&gt;<a class="code" href="structecat7__polmapheader.html#a1f8b29deb85540e9d4d30d9a8247c0d6">ring_position</a>, 32*4); <span class="keywordflow">if</span>(little) swawbip(buf+70, 32*4);
<a name="l00340"></a>00340   memcpy(buf+198, h-&gt;<a class="code" href="structecat7__polmapheader.html#af91ac7e401a999aaaaf275c8671ad0ab">ring_angle</a>, 32*2); <span class="keywordflow">if</span>(little) swabip(buf+198, 32*2);
<a name="l00341"></a>00341   memcpy(buf+262, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#ad59dd3b498ddd78aa65a6cf4425d259a">start_angle</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+262, 2);
<a name="l00342"></a>00342   memcpy(buf+264, h-&gt;<a class="code" href="structecat7__polmapheader.html#aabc620f253f9b5bc777f1848d8300e5e">long_axis_left</a>, 3*2); <span class="keywordflow">if</span>(little) swabip(buf+264, 3*2);
<a name="l00343"></a>00343   memcpy(buf+270, h-&gt;<a class="code" href="structecat7__polmapheader.html#af9716ddc7fc52ecbf3980dfd38b4fbd3">long_axis_right</a>, 3*2); <span class="keywordflow">if</span>(little) swabip(buf+270, 3*2);
<a name="l00344"></a>00344   memcpy(buf+276, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#af4ebf16c597dd432ffb78c267137c40c">position_data</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+276, 2);
<a name="l00345"></a>00345   memcpy(buf+278, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#ac955d5b0a42d9a35011f0a9687db1ee7">image_min</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+278, 2);
<a name="l00346"></a>00346   memcpy(buf+280, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a402864bf8af8ab091faf877d831cb7ef">image_max</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+280, 2);
<a name="l00347"></a>00347   memcpy(buf+282, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#ad2f57edc57a8a6f328e19ab35502eb20">scale_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+282, 4);
<a name="l00348"></a>00348   memcpy(buf+286, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a4a7a70570769b6b97bf67f6358a61f45">pixel_size</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+286, 4);
<a name="l00349"></a>00349   memcpy(buf+290, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#af2c0109195bbcc833521aed329d2bd83">frame_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+290, 4);
<a name="l00350"></a>00350   memcpy(buf+294, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#ac7757667731f12beb6c6e8a584dd6682">frame_start_time</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+294, 4);
<a name="l00351"></a>00351   memcpy(buf+298, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a1b6921694ee32fdda5e5c4b1a64f733b">processing_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+298, 2);
<a name="l00352"></a>00352   memcpy(buf+300, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#aa4b2dda11a8f10a58a77307ffbf28805">quant_units</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+300, 2);
<a name="l00353"></a>00353   memcpy(buf+302, h-&gt;<a class="code" href="structecat7__polmapheader.html#a873c092e019a8919b5b82030ed29f6a5">annotation</a>, 40);
<a name="l00354"></a>00354   memcpy(buf+342, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a87bdb3bf6e644c357290c320166e068f">gate_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+342, 4);
<a name="l00355"></a>00355   memcpy(buf+346, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#a8a17116a1e9c4a1df60eb9f709b5d03e">r_wave_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+346, 4);
<a name="l00356"></a>00356   memcpy(buf+350, &amp;h-&gt;<a class="code" href="structecat7__polmapheader.html#aae8015e83f96723de1bffab0cf44b2b3">num_accepted_beats</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+350, 4);
<a name="l00357"></a>00357   memcpy(buf+354, h-&gt;<a class="code" href="structecat7__polmapheader.html#ac6a9017cce528db97e827de264aa3142">polar_map_protocol</a>, 20);
<a name="l00358"></a>00358   memcpy(buf+374, h-&gt;<a class="code" href="structecat7__polmapheader.html#a65ab9e055aedc38c33d62fb6ebf05589">database_name</a>, 30);
<a name="l00359"></a>00359   memcpy(buf+404, h-&gt;<a class="code" href="structecat7__polmapheader.html#a164decb72ee26397bf7cba8cd6219b9f">fill_cti</a>, 27*2); <span class="keywordflow">if</span>(little) swabip(buf+404, 27*2);
<a name="l00360"></a>00360 
<a name="l00361"></a>00361   <span class="comment">/* Write header */</span>
<a name="l00362"></a>00362   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00363"></a>00363   <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(4);
<a name="l00364"></a>00364   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00365"></a>00365 
<a name="l00366"></a>00366   <span class="keywordflow">return</span>(0);
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 <span class="comment">/*****************************************************************************/</span>
<a name="l00369"></a>00369 
<a name="l00370"></a>00370 <span class="comment">/*****************************************************************************/</span>
<a name="l00380"></a><a class="code" href="ecat7_8h.html#a33f664191808ea3162295105315e48a0">00380</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a33f664191808ea3162295105315e48a0">ecat7WriteNormheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__normheader.html">ECAT7_normheader</a> *h) {
<a name="l00381"></a>00381   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00382"></a>00382   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00383"></a>00383 
<a name="l00384"></a>00384   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteNormheader()\n&quot;</span>);
<a name="l00385"></a>00385   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00386"></a>00386   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00387"></a>00387   <span class="comment">/* Clear buf */</span>
<a name="l00388"></a>00388   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00389"></a>00389   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00390"></a>00390   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00391"></a>00391   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00392"></a>00392   
<a name="l00393"></a>00393   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00394"></a>00394   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#aed9b4cb1c561d080a8336baf7c80fdcc">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00395"></a>00395   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#ad44f4013947a523f61f406ab26f2e44a">num_r_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00396"></a>00396   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#aa8d1e9e258ad69f1d1af98d30c7a6cf5">num_transaxial_crystals</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00397"></a>00397   memcpy(buf+6, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a3cdec5a8adfe16d0d8fcebcfcdbc4d48">num_crystal_rings</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+6, 2);
<a name="l00398"></a>00398   memcpy(buf+8, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#aaf63afdf4ccafc47626d7075dbb7727c">crystals_per_ring</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+8, 2);
<a name="l00399"></a>00399   memcpy(buf+10, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a7ae2012feb0d317925f54c719c6023bb">num_geo_corr_planes</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+10, 2);
<a name="l00400"></a>00400   memcpy(buf+12, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#aaa65ed681794afc0f8c67b65f05febfb">uld</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+12, 2);
<a name="l00401"></a>00401   memcpy(buf+14, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a64e2d29a3fd63691aa5fd129a32c32f5">lld</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+14, 2);
<a name="l00402"></a>00402   memcpy(buf+16, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a7835b4239c66f51f97b0d96c45ce862e">scatter_energy</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+16, 2);
<a name="l00403"></a>00403   memcpy(buf+18, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a6cb5155206d5f40b4dc6363482364f5a">norm_quality_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+18, 4);
<a name="l00404"></a>00404   memcpy(buf+22, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a71f98c8e0270a3b738a8228a130e6e4a">norm_quality_factor_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+22, 2);
<a name="l00405"></a>00405   memcpy(buf+24, h-&gt;<a class="code" href="structecat7__normheader.html#a981b1ecafed3fc8ffb6027ffa4e37d0d">ring_dtcor1</a>, 32*4); <span class="keywordflow">if</span>(little) swawbip(buf+24, 32*4);
<a name="l00406"></a>00406   memcpy(buf+152, h-&gt;<a class="code" href="structecat7__normheader.html#aca206f1d98356df2cd4ab06bb4b25de0">ring_dtcor2</a>, 32*4); <span class="keywordflow">if</span>(little) swawbip(buf+152, 32*4);
<a name="l00407"></a>00407   memcpy(buf+280, h-&gt;<a class="code" href="structecat7__normheader.html#acf7f342012459796cfea425e7e9faf7f">crystal_dtcor</a>, 8*4); <span class="keywordflow">if</span>(little) swawbip(buf+280, 8*4);
<a name="l00408"></a>00408   memcpy(buf+312, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a83cc022237d464480c1696fece19729f">span</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+312, 2);
<a name="l00409"></a>00409   memcpy(buf+314, &amp;h-&gt;<a class="code" href="structecat7__normheader.html#a7dd4601b4e06fb51df9e6a09d3287154">max_ring_diff</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+314, 2);
<a name="l00410"></a>00410   memcpy(buf+316, h-&gt;<a class="code" href="structecat7__normheader.html#ad3967ba7c86ba41189c2c6becd34da45">fill_cti</a>, 48*2); <span class="keywordflow">if</span>(little) swabip(buf+316, 48*2);
<a name="l00411"></a>00411   memcpy(buf+412, h-&gt;<a class="code" href="structecat7__normheader.html#ac9cdc23bf6850c72fca0d38d2e32b640">fill_user</a>, 50*2); <span class="keywordflow">if</span>(little) swabip(buf+412, 50*2);
<a name="l00412"></a>00412 
<a name="l00413"></a>00413   <span class="comment">/* Write header */</span>
<a name="l00414"></a>00414   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00415"></a>00415   <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(4);
<a name="l00416"></a>00416   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00417"></a>00417 
<a name="l00418"></a>00418   <span class="keywordflow">return</span>(0);
<a name="l00419"></a>00419 }
<a name="l00420"></a>00420 <span class="comment">/*****************************************************************************/</span>
<a name="l00421"></a>00421 
<a name="l00422"></a>00422 <span class="comment">/*****************************************************************************/</span>
<a name="l00433"></a><a class="code" href="ecat7_8h.html#a3cac31bcbcd6a0cd5f557dc20eb71184">00433</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a3cac31bcbcd6a0cd5f557dc20eb71184">ecat7WriteScanheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__scanheader.html">ECAT7_scanheader</a> *h) {
<a name="l00434"></a>00434   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[2*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00435"></a>00435   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00436"></a>00436 
<a name="l00437"></a>00437   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteScanheader()\n&quot;</span>);
<a name="l00438"></a>00438   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00439"></a>00439   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00440"></a>00440   <span class="comment">/* Clear buf */</span>
<a name="l00441"></a>00441   memset(buf, 0, 2*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00442"></a>00442   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00443"></a>00443   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00444"></a>00444   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00445"></a>00445 
<a name="l00446"></a>00446   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00447"></a>00447   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00448"></a>00448   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a4b4361b122c74cfd1c7171357615a2a4">num_dimensions</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00449"></a>00449   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#aee3fd0c2360973b3d53ad1adf6225d7d">num_r_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00450"></a>00450   memcpy(buf+6, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a4f58fe54c66427d34390f6530a12f8ed">num_angles</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+6, 2);
<a name="l00451"></a>00451   memcpy(buf+8, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a18d65465164971f7dcdfe5b251b6c244">corrections_applied</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+8, 2);
<a name="l00452"></a>00452   memcpy(buf+10, h-&gt;<a class="code" href="structecat7__scanheader.html#a714bae4e56b451926ceeb0de19222ad7">num_z_elements</a>, 64*2); <span class="keywordflow">if</span>(little) swabip(buf+10, 64*2);
<a name="l00453"></a>00453   memcpy(buf+138, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ae0d7a41a8f2790fe97d7784367f8daba">ring_difference</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+138, 2);
<a name="l00454"></a>00454   memcpy(buf+140, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#af0fcf4af875d58acf97d1b412d0299b5">storage_order</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+140, 2);
<a name="l00455"></a>00455   memcpy(buf+142, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ad0c5b2146bf087faa53cafd30be60aad">axial_compression</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+142, 2);
<a name="l00456"></a>00456   memcpy(buf+144, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a3b20e770bbcc8bc038190aab1d777199">x_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+144, 4);
<a name="l00457"></a>00457   memcpy(buf+148, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a377740afa37d1774a1938a37354b5bde">v_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+148, 4);
<a name="l00458"></a>00458   memcpy(buf+152, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a1e5bfef1c77d887f15aa6daada8464d7">z_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+152, 4);
<a name="l00459"></a>00459   memcpy(buf+156, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a3377bb6891117ab290ea776444caecf2">w_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+156, 4);
<a name="l00460"></a>00460   memcpy(buf+160, h-&gt;<a class="code" href="structecat7__scanheader.html#add4ebedc9711b45cf37910b50cbfbaf7">fill_gate</a>, 6*2); <span class="keywordflow">if</span>(little) swabip(buf+160, 6*2);
<a name="l00461"></a>00461   memcpy(buf+172, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a603f407610a5e2864bfda5c80152f9c9">gate_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+172, 4);
<a name="l00462"></a>00462   memcpy(buf+176, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ae2bdd51e3b0c9b838e77793eb71280d7">r_wave_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+176, 4);
<a name="l00463"></a>00463   memcpy(buf+180, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ae80300a155f4fcf65cb0851ff8bfa122">num_accepted_beats</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+180, 4);
<a name="l00464"></a>00464   memcpy(buf+184, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a77ed7b5edd51bf8feeea367ec4d143bb">scale_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+184, 4);
<a name="l00465"></a>00465   memcpy(buf+188, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ae8d5fb305463d8a019b452068176c20c">scan_min</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+188, 2);
<a name="l00466"></a>00466   memcpy(buf+190, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a6cad394ec364530cb33b335f1256fec1">scan_max</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+190, 2);
<a name="l00467"></a>00467   memcpy(buf+192, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a421bb8924e8aed2ef38ecc673b71a574">prompts</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+192, 4);
<a name="l00468"></a>00468   memcpy(buf+196, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a8f67a369e6ef599551b8271c08a8b5d7">delayed</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+196, 4);
<a name="l00469"></a>00469   memcpy(buf+200, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a7d8ff4b790f38d9e8be6bf83c4bd185d">multiples</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+200, 4);
<a name="l00470"></a>00470   memcpy(buf+204, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a2e6e0eaff39c88e72fb766c85ebf5c07">net_trues</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+204, 4);
<a name="l00471"></a>00471   memcpy(buf+208, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#aaa779c47e6e11a47795aee0c90437adf">tot_avg_cor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+208, 4);
<a name="l00472"></a>00472   memcpy(buf+212, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a80ffd347fbe13b90be3264318d2cb754">tot_avg_uncor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+212, 4);
<a name="l00473"></a>00473   memcpy(buf+216, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#afcd90f2a17b7af7f495e7ffd5a0a52a8">total_coin_rate</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+216, 4);
<a name="l00474"></a>00474   memcpy(buf+220, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a73b5c4aae33a122d91703ce6a3330f89">frame_start_time</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+220, 4);
<a name="l00475"></a>00475   memcpy(buf+224, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#ae7eafb4bf000a8404407489dbd6b54ac">frame_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+224, 4);
<a name="l00476"></a>00476   memcpy(buf+228, &amp;h-&gt;<a class="code" href="structecat7__scanheader.html#a97b2c1a33ab3c42a21aa9f1d3d9e21e7">deadtime_correction_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+228, 4);
<a name="l00477"></a>00477   memcpy(buf+232, h-&gt;<a class="code" href="structecat7__scanheader.html#a47f557ddadc32ba65cb7cde63dd959d0">fill_cti</a>, 90*2); <span class="keywordflow">if</span>(little) swabip(buf+232, 90*2);
<a name="l00478"></a>00478   memcpy(buf+412, h-&gt;<a class="code" href="structecat7__scanheader.html#a87d711f5f18ee88a7ba4f67f65574cee">fill_user</a>, 50*2); <span class="keywordflow">if</span>(little) swabip(buf+412, 50*2);
<a name="l00479"></a>00479   memcpy(buf+512, h-&gt;<a class="code" href="structecat7__scanheader.html#a30c149d12f3ee869d8303c8430fca0f0">uncor_singles</a>, 128*4); <span class="keywordflow">if</span>(little) swawbip(buf+512, 128*4);
<a name="l00480"></a>00480 
<a name="l00481"></a>00481   <span class="comment">/* Write 3D scan header */</span>
<a name="l00482"></a>00482   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>(4);
<a name="l00483"></a>00483   <span class="keywordflow">if</span>(fwrite(buf, 1, 2*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 2*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00484"></a>00484 
<a name="l00485"></a>00485   <span class="keywordflow">return</span>(0);
<a name="l00486"></a>00486 }
<a name="l00487"></a>00487 <span class="comment">/*****************************************************************************/</span>
<a name="l00488"></a>00488 
<a name="l00489"></a>00489 <span class="comment">/*****************************************************************************/</span>
<a name="l00499"></a><a class="code" href="ecat7_8h.html#aa28a9c3060c74c1f52b280c251b8e926">00499</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#aa28a9c3060c74c1f52b280c251b8e926">ecat7Write2DScanheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__2Dscanheader.html">ECAT7_2Dscanheader</a> *h) {
<a name="l00500"></a>00500   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00501"></a>00501   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00502"></a>00502 
<a name="l00503"></a>00503   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7Write2DScanheader()\n&quot;</span>);
<a name="l00504"></a>00504   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00505"></a>00505   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00506"></a>00506   <span class="comment">/* Clear buf */</span>
<a name="l00507"></a>00507   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00508"></a>00508   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00509"></a>00509   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00510"></a>00510   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00511"></a>00511 
<a name="l00512"></a>00512   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00513"></a>00513   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00514"></a>00514   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a592447ad964ba95e2a29a7d3d2284576">num_dimensions</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00515"></a>00515   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#adfe07cff44e3145ca65c234079ff255a">num_r_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00516"></a>00516   memcpy(buf+6, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ad0d1958b231f10aa68d60c653ec30627">num_angles</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+6, 2);
<a name="l00517"></a>00517   memcpy(buf+8, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a8c126cf20e0b59765720d52fbfbf92d9">corrections_applied</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+8, 2);
<a name="l00518"></a>00518   memcpy(buf+10, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a697bb7a95d88bce42bf80e2d6bd69037">num_z_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+10, 2);
<a name="l00519"></a>00519   memcpy(buf+12, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a6a37718cdfb000b2724062232ecadcf6">ring_difference</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+12, 2);
<a name="l00520"></a>00520   memcpy(buf+14, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a77e48781a4d1eda3cd828fdc2c3b1a62">x_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+14, 4);
<a name="l00521"></a>00521   memcpy(buf+18, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ab4d6c7e3cdd71cf5edb222956600083b">y_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+18, 4);
<a name="l00522"></a>00522   memcpy(buf+22, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aed6ef090a59741c23fc97dec8eb6e17a">z_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+22, 4);
<a name="l00523"></a>00523   memcpy(buf+26, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a946ef333c9627293f30db28447a09f55">w_resolution</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+26, 4);
<a name="l00524"></a>00524   memcpy(buf+30, h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a4a79a87fe7768f023c873b9d38bb75d5">fill_gate</a>, 6*2); <span class="keywordflow">if</span>(little) swabip(buf+30, 6*2);
<a name="l00525"></a>00525   memcpy(buf+42, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a790afb788d414578a5c3ab75ee33e6ef">gate_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+42, 4);
<a name="l00526"></a>00526   memcpy(buf+46, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ac6159922811bbc4faa5227977aa1aecc">r_wave_offset</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+46, 4);
<a name="l00527"></a>00527   memcpy(buf+50, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a268204e52f918f4738cbd4b6b41c0010">num_accepted_beats</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+50, 4);
<a name="l00528"></a>00528   memcpy(buf+54, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ae27dc6ec3582a4e2a0e69ea9377993a3">scale_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+54, 4);
<a name="l00529"></a>00529   memcpy(buf+58, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a6a644bf6cbb45523522f20ebf730af2c">scan_min</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+58, 2);
<a name="l00530"></a>00530   memcpy(buf+60, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#abaf0931401015351496475447bdf2e4a">scan_max</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+60, 2);
<a name="l00531"></a>00531   memcpy(buf+62, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ac4abf37f9a786b4133fe6526cf29463c">prompts</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+62, 4);
<a name="l00532"></a>00532   memcpy(buf+66, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a01d95cfc32cb38a15067f6f2b6835176">delayed</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+66, 4);
<a name="l00533"></a>00533   memcpy(buf+70, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a875117198383dd1ede79e8e0c7e9e98d">multiples</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+70, 4);
<a name="l00534"></a>00534   memcpy(buf+74, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#af370e602f761d19cc1663c84f8fb0fae">net_trues</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+74, 4);
<a name="l00535"></a>00535   memcpy(buf+78, h-&gt;<a class="code" href="structecat7__2Dscanheader.html#af2e871980537eb5bf534ff9ed4d7346f">cor_singles</a>, 16*4); <span class="keywordflow">if</span>(little) swawbip(buf+78, 16*4);
<a name="l00536"></a>00536   memcpy(buf+142, h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ae09638e910e990877f98f8f5bf0450fe">uncor_singles</a>, 16*4); <span class="keywordflow">if</span>(little) swawbip(buf+142, 16*4);
<a name="l00537"></a>00537   memcpy(buf+206, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ab18f6c6f465371a84b37b909e3294dda">tot_avg_cor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+206, 4);
<a name="l00538"></a>00538   memcpy(buf+210, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a3e4245e6136c30d208c36e2e60432ea1">tot_avg_uncor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+210, 4);
<a name="l00539"></a>00539   memcpy(buf+214, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a2f154fd294d938039e15dbc452aae7a0">total_coin_rate</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+214, 4);
<a name="l00540"></a>00540   memcpy(buf+218, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a8930d980328907f75c2518b36e67b36f">frame_start_time</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+218, 4);
<a name="l00541"></a>00541   memcpy(buf+222, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#afe892b507d85054ad72ce5ac289b3b05">frame_duration</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+222, 4);
<a name="l00542"></a>00542   memcpy(buf+226, &amp;h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a8788db06847593186cbeaef45e03b838">deadtime_correction_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+226, 4);
<a name="l00543"></a>00543   memcpy(buf+230, h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a32d5dfdc807697d412704c5ac53adced">physical_planes</a>, 8*2); <span class="keywordflow">if</span>(little) swabip(buf+230, 8*2);
<a name="l00544"></a>00544   memcpy(buf+246, h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ad3b13c4044cd9de84db192d700ebdca4">fill_cti</a>, 83*2); <span class="keywordflow">if</span>(little) swabip(buf+246, 83*2);
<a name="l00545"></a>00545   memcpy(buf+412, h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a07da82cdd5f206c0c52eeb20576f2a77">fill_user</a>, 50*2); <span class="keywordflow">if</span>(little) swabip(buf+412, 50*2);
<a name="l00546"></a>00546 
<a name="l00547"></a>00547   <span class="comment">/* Write header */</span>
<a name="l00548"></a>00548   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00549"></a>00549   <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(4);
<a name="l00550"></a>00550   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00551"></a>00551 
<a name="l00552"></a>00552   <span class="keywordflow">return</span>(0);
<a name="l00553"></a>00553 }
<a name="l00554"></a>00554 <span class="comment">/*****************************************************************************/</span>
<a name="l00555"></a>00555 
<a name="l00556"></a>00556 <span class="comment">/*****************************************************************************/</span>
<a name="l00566"></a><a class="code" href="ecat7_8h.html#aae7cc59d9c6a28e6727518470dff5cb2">00566</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#aae7cc59d9c6a28e6727518470dff5cb2">ecat7Write2DNormheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat7__2Dnormheader.html">ECAT7_2Dnormheader</a> *h) {
<a name="l00567"></a>00567   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00568"></a>00568   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00569"></a>00569 
<a name="l00570"></a>00570   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7Write2DNormheader()\n&quot;</span>);
<a name="l00571"></a>00571   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00572"></a>00572   little=little_endian(); <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;little=%d\n&quot;</span>, little);
<a name="l00573"></a>00573   <span class="comment">/* Clear buf */</span>
<a name="l00574"></a>00574   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00575"></a>00575   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>==<a class="code" href="ecat7_8h.html#ab6ce9728e8574761efa8303ff6a34fe9">ECAT7_VAXI2</a>) h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>;
<a name="l00576"></a>00576   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>==<a class="code" href="ecat7_8h.html#a3256675b42164c36df6e3810ac8c82fa">ECAT7_VAXI4</a>) h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>=<a class="code" href="ecat7_8h.html#a81ca91463b7e64939e4970bb48b4b26f">ECAT7_SUNI4</a>;
<a name="l00577"></a>00577   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>==<a class="code" href="ecat7_8h.html#acff598c85518f15df8aec8175730cbe4">ECAT7_VAXR4</a>) h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>=<a class="code" href="ecat7_8h.html#a2b1d3c2ff1a9c241f41fe68189b95570">ECAT7_IEEER4</a>;
<a name="l00578"></a>00578 
<a name="l00579"></a>00579   <span class="comment">/* Copy the header fields and swap if necessary */</span>
<a name="l00580"></a>00580   memcpy(buf+0, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#aed37b336ee5cf6446aa8f14a8a8589e9">data_type</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+0, 2);
<a name="l00581"></a>00581   memcpy(buf+2, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a2513b09534273845652deb6b9ab94e25">num_dimensions</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+2, 2);
<a name="l00582"></a>00582   memcpy(buf+4, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a9445d293a44e6b33f1114ed77a8aae28">num_r_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+4, 2);
<a name="l00583"></a>00583   memcpy(buf+6, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a56ea7bd534112992fbd8380d9358bb67">num_angles</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+6, 2);
<a name="l00584"></a>00584   memcpy(buf+8, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a83e70d1ac4fa6dd8421c1302370529ed">num_z_elements</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+8, 2);
<a name="l00585"></a>00585   memcpy(buf+10, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#ac43014ca13110db8929ecfa9ae0141b0">ring_difference</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+10, 2);
<a name="l00586"></a>00586   memcpy(buf+12, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a41e0cea1c8ef72712a6f44c1634fa5fc">scale_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+12, 4);
<a name="l00587"></a>00587   memcpy(buf+16, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a27bc628ff44c68378fa60074c442acf1">norm_min</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+16, 4);
<a name="l00588"></a>00588   memcpy(buf+20, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#ad8025a3f59f73ba95c2412bd0a72ff9c">norm_max</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+20, 4);
<a name="l00589"></a>00589   memcpy(buf+24, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a7bbbf33025bb7abbe325825cb7ede630">fov_source_width</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+24, 4);
<a name="l00590"></a>00590   memcpy(buf+28, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a52b683dd331c8c3d3f9f12d354e83522">norm_quality_factor</a>, 4); <span class="keywordflow">if</span>(little) swawbip(buf+28, 4);
<a name="l00591"></a>00591   memcpy(buf+32, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a8642a53226b65eaf30bd7205432871a0">norm_quality_factor_code</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+32, 2);
<a name="l00592"></a>00592   memcpy(buf+34, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a0a45487c98abca585bb1865c00d8bbfb">storage_order</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+34, 2);
<a name="l00593"></a>00593   memcpy(buf+36, &amp;h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a863a208786a3728549c8f8e3f1aa7082">span</a>, 2); <span class="keywordflow">if</span>(little) swabip(buf+36, 2);
<a name="l00594"></a>00594   memcpy(buf+38, h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a020286ea0efc6ef7946ca7120f193a57">fill_cti</a>, 64*2); <span class="keywordflow">if</span>(little) swabip(buf+38, 64*2);
<a name="l00595"></a>00595   memcpy(buf+166, h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a020286ea0efc6ef7946ca7120f193a57">fill_cti</a>, 123*2); <span class="keywordflow">if</span>(little) swabip(buf+166, 123*2);
<a name="l00596"></a>00596   memcpy(buf+412, h-&gt;<a class="code" href="structecat7__2Dnormheader.html#a10847d8706567154e91057fc98012254">fill_user</a>, 50*2); <span class="keywordflow">if</span>(little) swabip(buf+412, 50*2);
<a name="l00597"></a>00597 
<a name="l00598"></a>00598   <span class="comment">/* Write header */</span>
<a name="l00599"></a>00599   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00600"></a>00600   <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(4);
<a name="l00601"></a>00601   <span class="keywordflow">if</span>(fwrite(buf, 1, 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp) != 1*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(5);
<a name="l00602"></a>00602 
<a name="l00603"></a>00603   <span class="keywordflow">return</span>(0);
<a name="l00604"></a>00604 }
<a name="l00605"></a>00605 <span class="comment">/*****************************************************************************/</span>
<a name="l00606"></a>00606 
<a name="l00607"></a>00607 <span class="comment">/*****************************************************************************/</span>
<a name="l00616"></a><a class="code" href="ecat7_8h.html#a85ec2c6c7070a4170b8807e13623b04d">00616</a> FILE *<a class="code" href="ecat7w_8c.html#a85ec2c6c7070a4170b8807e13623b04d">ecat7Create</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fname, <a class="code" href="structecat7__mainheader.html">ECAT7_mainheader</a> *h) {
<a name="l00617"></a>00617   FILE *fp;
<a name="l00618"></a>00618   <span class="keywordtype">char</span> tmp[FILENAME_MAX];
<a name="l00619"></a>00619   <span class="keywordtype">int</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4];
<a name="l00620"></a>00620 
<a name="l00621"></a>00621   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7Create(%s, h)\n&quot;</span>, fname);
<a name="l00622"></a>00622   <span class="comment">/* Check the arguments */</span>
<a name="l00623"></a>00623   <span class="keywordflow">if</span>(fname==NULL || h==NULL) <span class="keywordflow">return</span>(NULL);
<a name="l00624"></a>00624   <span class="comment">/* Check if file exists; backup, if necessary */</span>
<a name="l00625"></a>00625   <span class="keywordflow">if</span>(access(fname, 0) != -1) {
<a name="l00626"></a>00626     strcpy(tmp, fname); strcat(tmp, <a class="code" href="analyze_8h.html#aaefec1fffef0834f552b1dcf3513d2f8">BACKUP_EXTENSION</a>);
<a name="l00627"></a>00627     <span class="keywordflow">if</span>(access(tmp, 0) != -1) <span class="keyword">remove</span>(tmp);
<a name="l00628"></a>00628     <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;Renaming %s -&gt; %s\n&quot;</span>, fname, tmp);
<a name="l00629"></a>00629     rename(fname, tmp);
<a name="l00630"></a>00630   }
<a name="l00631"></a>00631   <span class="comment">/* Open file */</span>
<a name="l00632"></a>00632   fp=fopen(fname, <span class="stringliteral">&quot;wb+&quot;</span>); <span class="keywordflow">if</span>(fp==NULL) <span class="keywordflow">return</span>(fp);
<a name="l00633"></a>00633   <span class="comment">/* Write main header */</span>
<a name="l00634"></a>00634   <span class="keywordflow">if</span>(<a class="code" href="ecat7w_8c.html#ae4ee4bf17962633b914d5c731ac7c321">ecat7WriteMainheader</a>(fp, h)) <span class="keywordflow">return</span>(NULL);
<a name="l00635"></a>00635   <span class="comment">/* Construct an empty matrix list ; convert to little endian if necessary */</span>
<a name="l00636"></a>00636   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00637"></a>00637   buf[0]=31; buf[1]=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>; <span class="keywordflow">if</span>(little_endian()) swawbip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00638"></a>00638   <span class="comment">/* Write data buffer */</span>
<a name="l00639"></a>00639   fseek(fp, (<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00640"></a>00640   <span class="keywordflow">if</span>(ftell(fp)!=(<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a>-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(NULL);
<a name="l00641"></a>00641   <span class="keywordflow">if</span>(fwrite(buf, 4, <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>(NULL);
<a name="l00642"></a>00642   <span class="comment">/* OK, then return file pointer */</span>
<a name="l00643"></a>00643   <span class="keywordflow">return</span>(fp);
<a name="l00644"></a>00644 }
<a name="l00645"></a>00645 <span class="comment">/*****************************************************************************/</span>
<a name="l00646"></a>00646 
<a name="l00647"></a>00647 <span class="comment">/*****************************************************************************/</span>
<a name="l00657"></a><a class="code" href="ecat7_8h.html#a4b4f3a8d69450162cf1652b104bd90e1">00657</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a4b4f3a8d69450162cf1652b104bd90e1">ecat7_is_scaling_needed</a>(<span class="keywordtype">float</span> amax, <span class="keywordtype">float</span> *data, <span class="keywordtype">int</span> nr) {
<a name="l00658"></a>00658   <span class="keywordtype">int</span> i;
<a name="l00659"></a>00659   <span class="keywordtype">double</span> d;
<a name="l00660"></a>00660   
<a name="l00661"></a>00661   <span class="keywordflow">if</span>(nr&lt;1 || data==NULL) <span class="keywordflow">return</span>(0);
<a name="l00662"></a>00662   <span class="comment">/* scaling is necessary if all values are between -1 - 1 */</span>
<a name="l00663"></a>00663   <span class="keywordflow">if</span>(amax&lt;0.9999) <span class="keywordflow">return</span>(1);
<a name="l00664"></a>00664   <span class="comment">/* Lets check first if at least the max value is close to integers or not */</span>
<a name="l00665"></a>00665   <span class="keywordflow">if</span>(modf(amax, &amp;d)&gt;0.0001) <span class="keywordflow">return</span>(1);
<a name="l00666"></a>00666   <span class="comment">/* if it is, then check all pixels */</span>
<a name="l00667"></a>00667   <span class="keywordflow">for</span>(i=0; i&lt;nr; i++) if(modf(*data++, &amp;d)&gt;0.0001) <span class="keywordflow">return</span>(1);
<a name="l00668"></a>00668   <span class="keywordflow">return</span>(0);
<a name="l00669"></a>00669 }
<a name="l00670"></a>00670 <span class="comment">/*****************************************************************************/</span>
<a name="l00671"></a>00671 
<a name="l00672"></a>00672 <span class="comment">/*****************************************************************************/</span>
<a name="l00682"></a><a class="code" href="ecat7_8h.html#a1806f5f5cc75a6446a4d85fa29e4228b">00682</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a1806f5f5cc75a6446a4d85fa29e4228b">ecat7WriteImageMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matrix_id, <a class="code" href="structecat7__imageheader.html">ECAT7_imageheader</a> *h, <span class="keywordtype">float</span> *fdata) {
<a name="l00683"></a>00683   <span class="keywordtype">int</span> i, nxtblk, blkNr, data_size, pxlNr, ret;
<a name="l00684"></a>00684   <span class="keywordtype">float</span> *fptr, fmin, fmax, g, f;
<a name="l00685"></a>00685   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00686"></a>00686   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00687"></a>00687   
<a name="l00688"></a>00688   
<a name="l00689"></a>00689   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteImageMatrix(fp, %d, h, data)\n&quot;</span>, matrix_id);
<a name="l00690"></a>00690   <span class="keywordflow">if</span>(fp==NULL || matrix_id&lt;1 || h==NULL || fdata==NULL) {
<a name="l00691"></a>00691     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00692"></a>00692     <span class="keywordflow">return</span>(1);
<a name="l00693"></a>00693   }
<a name="l00694"></a>00694   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>!=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>) {
<a name="l00695"></a>00695     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid data_type.\n&quot;</span>);
<a name="l00696"></a>00696     <span class="keywordflow">return</span>(2);
<a name="l00697"></a>00697   }
<a name="l00698"></a>00698   <span class="comment">/* nr of pixels */</span>
<a name="l00699"></a>00699   pxlNr=h-&gt;<a class="code" href="structecat7__imageheader.html#a37550f6ce6a114de12aa0d038f573230">x_dimension</a>*h-&gt;<a class="code" href="structecat7__imageheader.html#a217d17f8b1f921fad128ce923fa21c35">y_dimension</a>;
<a name="l00700"></a>00700   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__imageheader.html#acabca0e942a462b769c59804250b9a1c">num_dimensions</a>&gt;2) pxlNr*=h-&gt;<a class="code" href="structecat7__imageheader.html#a7d4bc496c4aa5581d41dff3e5b40a231">z_dimension</a>;
<a name="l00701"></a>00701   <span class="keywordflow">if</span>(pxlNr&lt;1) {
<a name="l00702"></a>00702     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00703"></a>00703     <span class="keywordflow">return</span>(3);
<a name="l00704"></a>00704   }
<a name="l00705"></a>00705   <span class="comment">/* How much memory is needed for ALL pixels */</span>
<a name="l00706"></a>00706   data_size=pxlNr*<a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>);
<a name="l00707"></a>00707   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00708"></a>00708   blkNr=(data_size+<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>-1)/<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; <span class="keywordflow">if</span>(blkNr&lt;1) {
<a name="l00709"></a>00709     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid block number.\n&quot;</span>);
<a name="l00710"></a>00710     <span class="keywordflow">return</span>(4);
<a name="l00711"></a>00711   }
<a name="l00712"></a>00712   <span class="comment">/* Allocate memory for matrix data */</span>
<a name="l00713"></a>00713   mdata=(<span class="keywordtype">char</span>*)calloc(blkNr, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <span class="keywordflow">if</span>(mdata==NULL) {
<a name="l00714"></a>00714     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;out of memory.\n&quot;</span>);
<a name="l00715"></a>00715     <span class="keywordflow">return</span>(5);
<a name="l00716"></a>00716   }
<a name="l00717"></a>00717   <span class="comment">/* Search for min and max for calculation of scale factor */</span>
<a name="l00718"></a>00718   fptr=fdata; fmin=fmax=*fptr;
<a name="l00719"></a>00719   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) {
<a name="l00720"></a>00720     <span class="keywordflow">if</span>(*fptr&gt;fmax) fmax=*fptr; <span class="keywordflow">else</span> <span class="keywordflow">if</span>(*fptr&lt;fmin) fmin=*fptr;
<a name="l00721"></a>00721   }
<a name="l00722"></a>00722   <span class="keywordflow">if</span>(fabs(fmin)&gt;fabs(fmax)) g=fabs(fmin); <span class="keywordflow">else</span> g=fabs(fmax);
<a name="l00723"></a>00723   <span class="keywordflow">if</span>(g&gt;0) f=32766./g; <span class="keywordflow">else</span> f=1.0;
<a name="l00724"></a>00724   <span class="comment">/* Check if pixels values can be left as such with scale_factor = 1 */</span>
<a name="l00725"></a>00725   fptr=fdata;
<a name="l00726"></a>00726   <span class="keywordflow">if</span>(f&gt;=1.0 &amp;&amp; <a class="code" href="ecat7w_8c.html#a4b4f3a8d69450162cf1652b104bd90e1">ecat7_is_scaling_needed</a>(g, fptr, pxlNr)==0) f=1.0;
<a name="l00727"></a>00727   <span class="comment">/* Scale matrix data to shorts */</span>
<a name="l00728"></a>00728   h-&gt;<a class="code" href="structecat7__imageheader.html#a2e44d8de4b5809864432376f713968ec">scale_factor</a>=1.0/f;
<a name="l00729"></a>00729   sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mdata; fptr=fdata;
<a name="l00730"></a>00730   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, sptr++, fptr++) *sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>)temp_roundf(f*(*fptr));
<a name="l00731"></a>00731   <span class="comment">/* Set header short min &amp; max */</span>
<a name="l00732"></a>00732   h-&gt;<a class="code" href="structecat7__imageheader.html#ad599fd1c46c31b598fb2a6f376d562eb">image_min</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmin);
<a name="l00733"></a>00733   h-&gt;<a class="code" href="structecat7__imageheader.html#a08e876d5e60f96c5b90fc99eeedde10f">image_max</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmax);
<a name="l00734"></a>00734   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00735"></a>00735   nxtblk=<a class="code" href="ecat7ml_8c.html#a8f97f2b4eb5bea323738dc3687e773b8">ecat7EnterMatrix</a>(fp, matrix_id, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) {
<a name="l00736"></a>00736     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot determine matrix block (%d).\n&quot;</span>, -nxtblk);
<a name="l00737"></a>00737     free(mdata); <span class="keywordflow">return</span>(8);
<a name="l00738"></a>00738   }
<a name="l00739"></a>00739   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;  block=%d fmin=%g fmax=%g\n&quot;</span>, nxtblk, fmin, fmax);
<a name="l00740"></a>00740   <span class="comment">/* Write header */</span>
<a name="l00741"></a>00741   ret=<a class="code" href="ecat7w_8c.html#a492041a42e77c2958cdd06c17c3267e9">ecat7WriteImageheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) {
<a name="l00742"></a>00742     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write subheader (%d).\n&quot;</span>, ret);
<a name="l00743"></a>00743     free(mdata); <span class="keywordflow">return</span>(10);
<a name="l00744"></a>00744   }
<a name="l00745"></a>00745   <span class="comment">/* Write matrix data */</span>
<a name="l00746"></a>00746   mptr=mdata;
<a name="l00747"></a>00747   ret=<a class="code" href="ecat7w_8c.html#ae44380ec982c9c91f38be4889758c1e2">ecat7WriteMatrixdata</a>(fp, nxtblk+1, mptr, pxlNr, <a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__imageheader.html#a9b90dc8511beaf487a57afc61044d09a">data_type</a>));
<a name="l00748"></a>00748   free(mdata);
<a name="l00749"></a>00749   <span class="keywordflow">if</span>(ret) {
<a name="l00750"></a>00750     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write matrix data (%d).\n&quot;</span>, ret);
<a name="l00751"></a>00751     <span class="keywordflow">return</span>(13);
<a name="l00752"></a>00752   }
<a name="l00753"></a>00753   <span class="keywordflow">return</span>(0);
<a name="l00754"></a>00754 }
<a name="l00755"></a>00755 <span class="comment">/*****************************************************************************/</span>
<a name="l00756"></a>00756 
<a name="l00757"></a>00757 <span class="comment">/*****************************************************************************/</span>
<a name="l00767"></a><a class="code" href="ecat7_8h.html#aa94815cb1caa7fe0fdb4223edafd6f57">00767</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#aa94815cb1caa7fe0fdb4223edafd6f57">ecat7Write2DScanMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matrix_id, <a class="code" href="structecat7__2Dscanheader.html">ECAT7_2Dscanheader</a> *h, <span class="keywordtype">float</span> *fdata) {
<a name="l00768"></a>00768   <span class="keywordtype">int</span> i, nxtblk, blkNr, data_size, pxlNr, ret;
<a name="l00769"></a>00769   <span class="keywordtype">float</span> *fptr, fmin, fmax, g, f;
<a name="l00770"></a>00770   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00771"></a>00771   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00772"></a>00772 
<a name="l00773"></a>00773 
<a name="l00774"></a>00774   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7Write2DScanMatrix(fp, %d, h, data)\n&quot;</span>, matrix_id);
<a name="l00775"></a>00775   <span class="keywordflow">if</span>(fp==NULL || matrix_id&lt;1 || h==NULL || fdata==NULL) {
<a name="l00776"></a>00776     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00777"></a>00777     <span class="keywordflow">return</span>(1);
<a name="l00778"></a>00778   }
<a name="l00779"></a>00779   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>!=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>) {
<a name="l00780"></a>00780     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid data_type.\n&quot;</span>);
<a name="l00781"></a>00781     <span class="keywordflow">return</span>(2);
<a name="l00782"></a>00782   }
<a name="l00783"></a>00783   <span class="comment">/* nr of pixels */</span>
<a name="l00784"></a>00784   pxlNr=h-&gt;<a class="code" href="structecat7__2Dscanheader.html#adfe07cff44e3145ca65c234079ff255a">num_r_elements</a>*h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ad0d1958b231f10aa68d60c653ec30627">num_angles</a>;
<a name="l00785"></a>00785   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a592447ad964ba95e2a29a7d3d2284576">num_dimensions</a>&gt;2) pxlNr*=h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a697bb7a95d88bce42bf80e2d6bd69037">num_z_elements</a>;
<a name="l00786"></a>00786   <span class="keywordflow">if</span>(pxlNr&lt;1) {
<a name="l00787"></a>00787     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00788"></a>00788     <span class="keywordflow">return</span>(3);
<a name="l00789"></a>00789   }
<a name="l00790"></a>00790   <span class="comment">/* How much memory is needed for ALL pixels */</span>
<a name="l00791"></a>00791   data_size=pxlNr*<a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>);
<a name="l00792"></a>00792   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00793"></a>00793   blkNr=(data_size+<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>-1)/<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; <span class="keywordflow">if</span>(blkNr&lt;1) {
<a name="l00794"></a>00794     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid block number.\n&quot;</span>);
<a name="l00795"></a>00795     <span class="keywordflow">return</span>(4);
<a name="l00796"></a>00796   }
<a name="l00797"></a>00797   <span class="comment">/* Allocate memory for matrix data */</span>
<a name="l00798"></a>00798   mdata=(<span class="keywordtype">char</span>*)calloc(blkNr, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <span class="keywordflow">if</span>(mdata==NULL) {
<a name="l00799"></a>00799     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;out of memory.\n&quot;</span>);
<a name="l00800"></a>00800     <span class="keywordflow">return</span>(5);
<a name="l00801"></a>00801   }
<a name="l00802"></a>00802   <span class="comment">/* Search for min and max for calculation of scale factor */</span>
<a name="l00803"></a>00803   fptr=fdata; fmin=fmax=*fptr;
<a name="l00804"></a>00804   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) {
<a name="l00805"></a>00805     <span class="keywordflow">if</span>(*fptr&gt;fmax) fmax=*fptr; <span class="keywordflow">else</span> <span class="keywordflow">if</span>(*fptr&lt;fmin) fmin=*fptr;
<a name="l00806"></a>00806   }
<a name="l00807"></a>00807   <span class="keywordflow">if</span>(fabs(fmin)&gt;fabs(fmax)) g=fabs(fmin); <span class="keywordflow">else</span> g=fabs(fmax);
<a name="l00808"></a>00808   <span class="keywordflow">if</span>(g&gt;0) f=32766./g; <span class="keywordflow">else</span> f=1.0;
<a name="l00809"></a>00809   <span class="comment">/* Check if pixels values can be left as such with scale_factor = 1 */</span>
<a name="l00810"></a>00810   fptr=fdata;
<a name="l00811"></a>00811   <span class="keywordflow">if</span>(f&gt;=1.0 &amp;&amp; <a class="code" href="ecat7w_8c.html#a4b4f3a8d69450162cf1652b104bd90e1">ecat7_is_scaling_needed</a>(g, fptr, pxlNr)==0) f=1.0;
<a name="l00812"></a>00812   <span class="comment">/* Scale matrix data to shorts */</span>
<a name="l00813"></a>00813   h-&gt;<a class="code" href="structecat7__2Dscanheader.html#ae27dc6ec3582a4e2a0e69ea9377993a3">scale_factor</a>=1.0/f;
<a name="l00814"></a>00814   sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mdata; fptr=fdata;
<a name="l00815"></a>00815   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, sptr++, fptr++) *sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>)temp_roundf(f*(*fptr));
<a name="l00816"></a>00816   <span class="comment">/* Set header short min &amp; max */</span>
<a name="l00817"></a>00817   h-&gt;<a class="code" href="structecat7__2Dscanheader.html#a6a644bf6cbb45523522f20ebf730af2c">scan_min</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmin);
<a name="l00818"></a>00818   h-&gt;<a class="code" href="structecat7__2Dscanheader.html#abaf0931401015351496475447bdf2e4a">scan_max</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmax);
<a name="l00819"></a>00819   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00820"></a>00820   nxtblk=<a class="code" href="ecat7ml_8c.html#a8f97f2b4eb5bea323738dc3687e773b8">ecat7EnterMatrix</a>(fp, matrix_id, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) {
<a name="l00821"></a>00821     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot determine matrix block (%d).\n&quot;</span>, -nxtblk);
<a name="l00822"></a>00822     free(mdata); <span class="keywordflow">return</span>(8);
<a name="l00823"></a>00823   }
<a name="l00824"></a>00824   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;  block=%d fmin=%g fmax=%g\n&quot;</span>, nxtblk, fmin, fmax);
<a name="l00825"></a>00825   <span class="comment">/* Write header */</span>
<a name="l00826"></a>00826   ret=<a class="code" href="ecat7w_8c.html#aa28a9c3060c74c1f52b280c251b8e926">ecat7Write2DScanheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) {
<a name="l00827"></a>00827     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write subheader (%d).\n&quot;</span>, ret);
<a name="l00828"></a>00828     free(mdata); <span class="keywordflow">return</span>(10);
<a name="l00829"></a>00829   }
<a name="l00830"></a>00830   <span class="comment">/* Write matrix data */</span>
<a name="l00831"></a>00831   mptr=mdata;
<a name="l00832"></a>00832   ret=<a class="code" href="ecat7w_8c.html#ae44380ec982c9c91f38be4889758c1e2">ecat7WriteMatrixdata</a>(fp, nxtblk+1, mptr, pxlNr, <a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__2Dscanheader.html#aa13b8697f5c56f7e31e942cafb91bddc">data_type</a>));
<a name="l00833"></a>00833   free(mdata);
<a name="l00834"></a>00834   <span class="keywordflow">if</span>(ret) {
<a name="l00835"></a>00835     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write matrix data (%d).\n&quot;</span>, ret);
<a name="l00836"></a>00836     <span class="keywordflow">return</span>(13);
<a name="l00837"></a>00837   }
<a name="l00838"></a>00838   <span class="keywordflow">return</span>(0);
<a name="l00839"></a>00839 }
<a name="l00840"></a>00840 <span class="comment">/*****************************************************************************/</span>
<a name="l00841"></a>00841 
<a name="l00842"></a>00842 <span class="comment">/*****************************************************************************/</span>
<a name="l00852"></a><a class="code" href="ecat7_8h.html#a33c96bd0bbc96506cb27794fadd6abcf">00852</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a33c96bd0bbc96506cb27794fadd6abcf">ecat7WriteScanMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matrix_id, <a class="code" href="structecat7__scanheader.html">ECAT7_scanheader</a> *h, <span class="keywordtype">float</span> *fdata) {
<a name="l00853"></a>00853   <span class="keywordtype">int</span> i, nxtblk, blkNr, data_size, pxlNr, dimz, ret;
<a name="l00854"></a>00854   <span class="keywordtype">float</span> *fptr, fmin, fmax, g, f;
<a name="l00855"></a>00855   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00856"></a>00856   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00857"></a>00857 
<a name="l00858"></a>00858 
<a name="l00859"></a>00859   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteScanMatrix(fp, %d, h, data)\n&quot;</span>, matrix_id);
<a name="l00860"></a>00860   <span class="keywordflow">if</span>(fp==NULL || matrix_id&lt;1 || h==NULL || fdata==NULL) {
<a name="l00861"></a>00861     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00862"></a>00862     <span class="keywordflow">return</span>(1);
<a name="l00863"></a>00863   }
<a name="l00864"></a>00864   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>!=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>) {
<a name="l00865"></a>00865     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid data_type.\n&quot;</span>);
<a name="l00866"></a>00866     <span class="keywordflow">return</span>(2);
<a name="l00867"></a>00867   }
<a name="l00868"></a>00868   <span class="comment">/* nr of pixels */</span>
<a name="l00869"></a>00869   pxlNr=h-&gt;<a class="code" href="structecat7__scanheader.html#aee3fd0c2360973b3d53ad1adf6225d7d">num_r_elements</a>*h-&gt;<a class="code" href="structecat7__scanheader.html#a4f58fe54c66427d34390f6530a12f8ed">num_angles</a>;
<a name="l00870"></a>00870   <span class="keywordflow">for</span>(i=dimz=0; i&lt;64; i++) dimz+=h-&gt;<a class="code" href="structecat7__scanheader.html#a714bae4e56b451926ceeb0de19222ad7">num_z_elements</a>[i]; pxlNr*=dimz;
<a name="l00871"></a>00871   <span class="keywordflow">if</span>(pxlNr&lt;1) {
<a name="l00872"></a>00872     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00873"></a>00873     <span class="keywordflow">return</span>(3);
<a name="l00874"></a>00874   }
<a name="l00875"></a>00875   <span class="comment">/* How much memory is needed for ALL pixels */</span>
<a name="l00876"></a>00876   data_size=pxlNr*<a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>);
<a name="l00877"></a>00877   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00878"></a>00878   blkNr=(data_size+<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>-1)/<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; <span class="keywordflow">if</span>(blkNr&lt;1) {
<a name="l00879"></a>00879     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid block number.\n&quot;</span>);
<a name="l00880"></a>00880     <span class="keywordflow">return</span>(4);
<a name="l00881"></a>00881   }
<a name="l00882"></a>00882   <span class="comment">/* Allocate memory for matrix data */</span>
<a name="l00883"></a>00883   mdata=(<span class="keywordtype">char</span>*)calloc(blkNr, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <span class="keywordflow">if</span>(mdata==NULL) {
<a name="l00884"></a>00884     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;out of memory.\n&quot;</span>);
<a name="l00885"></a>00885     <span class="keywordflow">return</span>(5);
<a name="l00886"></a>00886   }
<a name="l00887"></a>00887   <span class="comment">/* Search for min and max for calculation of scale factor */</span>
<a name="l00888"></a>00888   fptr=fdata; fmin=fmax=*fptr;
<a name="l00889"></a>00889   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) {
<a name="l00890"></a>00890     <span class="keywordflow">if</span>(*fptr&gt;fmax) fmax=*fptr; <span class="keywordflow">else</span> <span class="keywordflow">if</span>(*fptr&lt;fmin) fmin=*fptr;
<a name="l00891"></a>00891   }
<a name="l00892"></a>00892   <span class="keywordflow">if</span>(fabs(fmin)&gt;fabs(fmax)) g=fabs(fmin); <span class="keywordflow">else</span> g=fabs(fmax);
<a name="l00893"></a>00893   <span class="keywordflow">if</span>(g&gt;0) f=32766./g; <span class="keywordflow">else</span> f=1.0;
<a name="l00894"></a>00894   <span class="comment">/* Check if pixels values can be left as such with scale_factor = 1 */</span>
<a name="l00895"></a>00895   fptr=fdata;
<a name="l00896"></a>00896   <span class="keywordflow">if</span>(f&gt;=1.0 &amp;&amp; <a class="code" href="ecat7w_8c.html#a4b4f3a8d69450162cf1652b104bd90e1">ecat7_is_scaling_needed</a>(g, fptr, pxlNr)==0) f=1.0;
<a name="l00897"></a>00897   <span class="comment">/* Scale matrix data to shorts */</span>
<a name="l00898"></a>00898   h-&gt;<a class="code" href="structecat7__scanheader.html#a77ed7b5edd51bf8feeea367ec4d143bb">scale_factor</a>=1.0/f;
<a name="l00899"></a>00899   sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mdata; fptr=fdata;
<a name="l00900"></a>00900   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, sptr++, fptr++) *sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>)temp_roundf(f*(*fptr));
<a name="l00901"></a>00901   <span class="comment">/* Set header short min &amp; max */</span>
<a name="l00902"></a>00902   h-&gt;<a class="code" href="structecat7__scanheader.html#ae8d5fb305463d8a019b452068176c20c">scan_min</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmin);
<a name="l00903"></a>00903   h-&gt;<a class="code" href="structecat7__scanheader.html#a6cad394ec364530cb33b335f1256fec1">scan_max</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmax);
<a name="l00904"></a>00904   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00905"></a>00905   <span class="comment">/* Note that one extra block (blkNr+1) is needed for 3D scan header */</span>
<a name="l00906"></a>00906   nxtblk=<a class="code" href="ecat7ml_8c.html#a8f97f2b4eb5bea323738dc3687e773b8">ecat7EnterMatrix</a>(fp, matrix_id, blkNr+1); <span class="keywordflow">if</span>(nxtblk&lt;1) {
<a name="l00907"></a>00907     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot determine matrix block (%d).\n&quot;</span>, -nxtblk);
<a name="l00908"></a>00908     free(mdata); <span class="keywordflow">return</span>(8);
<a name="l00909"></a>00909   }
<a name="l00910"></a>00910   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;  block=%d fmin=%g fmax=%g\n&quot;</span>, nxtblk, fmin, fmax);
<a name="l00911"></a>00911   <span class="comment">/* Write header */</span>
<a name="l00912"></a>00912   ret=<a class="code" href="ecat7w_8c.html#a3cac31bcbcd6a0cd5f557dc20eb71184">ecat7WriteScanheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) {
<a name="l00913"></a>00913     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write subheader (%d).\n&quot;</span>, ret);
<a name="l00914"></a>00914     free(mdata); <span class="keywordflow">return</span>(10);
<a name="l00915"></a>00915   }
<a name="l00916"></a>00916   <span class="comment">/* Write matrix data */</span>
<a name="l00917"></a>00917   <span class="comment">/* Note that 3D scan header takes TWO blocks */</span>
<a name="l00918"></a>00918   mptr=mdata;
<a name="l00919"></a>00919   ret=<a class="code" href="ecat7w_8c.html#ae44380ec982c9c91f38be4889758c1e2">ecat7WriteMatrixdata</a>(fp, nxtblk+2, mptr, pxlNr, <a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__scanheader.html#ac1dfbebf9227256db4dd3ec96a95277f">data_type</a>));
<a name="l00920"></a>00920   free(mdata);
<a name="l00921"></a>00921   <span class="keywordflow">if</span>(ret) {
<a name="l00922"></a>00922     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write matrix data (%d).\n&quot;</span>, ret);
<a name="l00923"></a>00923     <span class="keywordflow">return</span>(13);
<a name="l00924"></a>00924   }
<a name="l00925"></a>00925   <span class="keywordflow">return</span>(0);
<a name="l00926"></a>00926 }
<a name="l00927"></a>00927 <span class="comment">/*****************************************************************************/</span>
<a name="l00928"></a>00928 
<a name="l00929"></a>00929 <span class="comment">/*****************************************************************************/</span>
<a name="l00939"></a><a class="code" href="ecat7_8h.html#a5f460170ea6c75b8af960ddf5a17d0ef">00939</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#a5f460170ea6c75b8af960ddf5a17d0ef">ecat7WritePolarmapMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matrix_id, <a class="code" href="structecat7__polmapheader.html">ECAT7_polmapheader</a> *h, <span class="keywordtype">float</span> *fdata) {
<a name="l00940"></a>00940   <span class="keywordtype">int</span> i, nxtblk, blkNr, data_size, pxlNr, ret;
<a name="l00941"></a>00941   <span class="keywordtype">float</span> *fptr, fmin, fmax, g, f;
<a name="l00942"></a>00942   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00943"></a>00943   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00944"></a>00944   
<a name="l00945"></a>00945   
<a name="l00946"></a>00946   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WritePolarmapMatrix(fp, %d, h, data)\n&quot;</span>, matrix_id);
<a name="l00947"></a>00947   <span class="keywordflow">if</span>(fp==NULL || matrix_id&lt;1 || h==NULL || fdata==NULL) {
<a name="l00948"></a>00948     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00949"></a>00949     <span class="keywordflow">return</span>(1);
<a name="l00950"></a>00950   }
<a name="l00951"></a>00951   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>!=<a class="code" href="ecat7_8h.html#aee0f2ad8e2d9d538fda30aec053a642a">ECAT7_SUNI2</a>) {
<a name="l00952"></a>00952     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid data_type.\n&quot;</span>);
<a name="l00953"></a>00953     <span class="keywordflow">return</span>(2);
<a name="l00954"></a>00954   }
<a name="l00955"></a>00955   <span class="comment">/* nr of pixels */</span>
<a name="l00956"></a>00956   <span class="keywordflow">for</span>(i=pxlNr=0; i&lt;h-&gt;<a class="code" href="structecat7__polmapheader.html#a503caad4ac64580ff3508463ae8e2342">num_rings</a>; i++) pxlNr+=h-&gt;<a class="code" href="structecat7__polmapheader.html#a7888f1b2bc8adcc5bcbf918bbbb82dbb">sectors_per_ring</a>[i];
<a name="l00957"></a>00957   <span class="keywordflow">if</span>(pxlNr&lt;1) {
<a name="l00958"></a>00958     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00959"></a>00959     <span class="keywordflow">return</span>(3);
<a name="l00960"></a>00960   }
<a name="l00961"></a>00961   <span class="comment">/* How much memory is needed for ALL pixels */</span>
<a name="l00962"></a>00962   data_size=pxlNr*<a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>);
<a name="l00963"></a>00963   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00964"></a>00964   blkNr=(data_size+<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>-1)/<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; <span class="keywordflow">if</span>(blkNr&lt;1) {
<a name="l00965"></a>00965     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;invalid block number.\n&quot;</span>);
<a name="l00966"></a>00966     <span class="keywordflow">return</span>(4);
<a name="l00967"></a>00967   }
<a name="l00968"></a>00968   <span class="comment">/* Allocate memory for matrix data */</span>
<a name="l00969"></a>00969   mdata=(<span class="keywordtype">char</span>*)calloc(blkNr, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>); <span class="keywordflow">if</span>(mdata==NULL) {
<a name="l00970"></a>00970     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;out of memory.\n&quot;</span>);
<a name="l00971"></a>00971     <span class="keywordflow">return</span>(5);
<a name="l00972"></a>00972   }
<a name="l00973"></a>00973   <span class="comment">/* Search for min and max for calculation of scale factor */</span>
<a name="l00974"></a>00974   fptr=fdata; fmin=fmax=*fptr;
<a name="l00975"></a>00975   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) {
<a name="l00976"></a>00976     <span class="keywordflow">if</span>(*fptr&gt;fmax) fmax=*fptr; <span class="keywordflow">else</span> <span class="keywordflow">if</span>(*fptr&lt;fmin) fmin=*fptr;
<a name="l00977"></a>00977   }
<a name="l00978"></a>00978   <span class="keywordflow">if</span>(fabs(fmin)&gt;fabs(fmax)) g=fabs(fmin); <span class="keywordflow">else</span> g=fabs(fmax);
<a name="l00979"></a>00979   <span class="keywordflow">if</span>(g&gt;0) f=32766./g; <span class="keywordflow">else</span> f=1.0;
<a name="l00980"></a>00980   <span class="comment">/* Check if pixels values can be left as such with scale_factor = 1 */</span>
<a name="l00981"></a>00981   fptr=fdata;
<a name="l00982"></a>00982   <span class="keywordflow">if</span>(f&gt;=1.0 &amp;&amp; <a class="code" href="ecat7w_8c.html#a4b4f3a8d69450162cf1652b104bd90e1">ecat7_is_scaling_needed</a>(g, fptr, pxlNr)==0) f=1.0;
<a name="l00983"></a>00983   <span class="comment">/* Scale matrix data to shorts */</span>
<a name="l00984"></a>00984   h-&gt;<a class="code" href="structecat7__polmapheader.html#ad2f57edc57a8a6f328e19ab35502eb20">scale_factor</a>=1.0/f;
<a name="l00985"></a>00985   sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mdata; fptr=fdata;
<a name="l00986"></a>00986   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, sptr++, fptr++) *sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>)temp_roundf(f*(*fptr));
<a name="l00987"></a>00987   <span class="comment">/* Set header short min &amp; max */</span>
<a name="l00988"></a>00988   h-&gt;<a class="code" href="structecat7__polmapheader.html#ac955d5b0a42d9a35011f0a9687db1ee7">image_min</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmin);
<a name="l00989"></a>00989   h-&gt;<a class="code" href="structecat7__polmapheader.html#a402864bf8af8ab091faf877d831cb7ef">image_max</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmax);
<a name="l00990"></a>00990   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00991"></a>00991   nxtblk=<a class="code" href="ecat7ml_8c.html#a8f97f2b4eb5bea323738dc3687e773b8">ecat7EnterMatrix</a>(fp, matrix_id, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) {
<a name="l00992"></a>00992     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot determine matrix block (%d).\n&quot;</span>, -nxtblk);
<a name="l00993"></a>00993     free(mdata); <span class="keywordflow">return</span>(8);
<a name="l00994"></a>00994   }
<a name="l00995"></a>00995   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;  block=%d fmin=%g fmax=%g\n&quot;</span>, nxtblk, fmin, fmax);
<a name="l00996"></a>00996   <span class="comment">/* Write header */</span>
<a name="l00997"></a>00997   ret=<a class="code" href="ecat7w_8c.html#a9edfe58b989a0b6e628f7be1103fec1b">ecat7WritePolmapheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) {
<a name="l00998"></a>00998     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write subheader (%d).\n&quot;</span>, ret);
<a name="l00999"></a>00999     free(mdata); <span class="keywordflow">return</span>(10);
<a name="l01000"></a>01000   }
<a name="l01001"></a>01001   <span class="comment">/* Write matrix data */</span>
<a name="l01002"></a>01002   mptr=mdata;
<a name="l01003"></a>01003   ret=<a class="code" href="ecat7w_8c.html#ae44380ec982c9c91f38be4889758c1e2">ecat7WriteMatrixdata</a>(fp, nxtblk+1, mptr, pxlNr, <a class="code" href="ecat7r_8c.html#a17795a6c58bfa4c1159e0fe642098678">ecat7pxlbytes</a>(h-&gt;<a class="code" href="structecat7__polmapheader.html#a85514ffcdb6dc106fe8d742bcb248947">data_type</a>));
<a name="l01004"></a>01004   free(mdata);
<a name="l01005"></a>01005   <span class="keywordflow">if</span>(ret) {
<a name="l01006"></a>01006     sprintf(<a class="code" href="ecat7_8h.html#a66c8b21d11aea27d874d191a12312207">ecat7errmsg</a>, <span class="stringliteral">&quot;cannot write matrix data (%d).\n&quot;</span>, ret);
<a name="l01007"></a>01007     <span class="keywordflow">return</span>(13);
<a name="l01008"></a>01008   }
<a name="l01009"></a>01009   <span class="keywordflow">return</span>(0);
<a name="l01010"></a>01010 }
<a name="l01011"></a>01011 <span class="comment">/*****************************************************************************/</span>
<a name="l01012"></a>01012 
<a name="l01013"></a>01013 <span class="comment">/*****************************************************************************/</span>
<a name="l01027"></a><a class="code" href="ecat7_8h.html#ae44380ec982c9c91f38be4889758c1e2">01027</a> <span class="keywordtype">int</span> <a class="code" href="ecat7w_8c.html#ae44380ec982c9c91f38be4889758c1e2">ecat7WriteMatrixdata</a>(FILE *fp, <span class="keywordtype">int</span> start_block, <span class="keywordtype">char</span> *data, <span class="keywordtype">int</span> pxl_nr, <span class="keywordtype">int</span> pxl_size) {
<a name="l01028"></a>01028   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l01029"></a>01029   <span class="keywordtype">char</span> *dptr;
<a name="l01030"></a>01030   <span class="keywordtype">int</span> i, blkNr, dataSize, byteNr, little;
<a name="l01031"></a>01031 
<a name="l01032"></a>01032   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>) printf(<span class="stringliteral">&quot;ecat7WriteMatrixdata(fp, %d, data, %d, %d)\n&quot;</span>,
<a name="l01033"></a>01033                         start_block, pxl_nr, pxl_size);
<a name="l01034"></a>01034   <span class="keywordflow">if</span>(fp==NULL || start_block&lt;1 || data==NULL || pxl_nr&lt;1 || pxl_size&lt;1) <span class="keywordflow">return</span>(1);
<a name="l01035"></a>01035   little=little_endian(); memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l01036"></a>01036   dataSize=pxl_nr*pxl_size;
<a name="l01037"></a>01037   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l01038"></a>01038   blkNr=(dataSize+<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>-1)/<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; <span class="keywordflow">if</span>(blkNr&lt;1) <span class="keywordflow">return</span>(1);
<a name="l01039"></a>01039   <span class="keywordflow">if</span>(<a class="code" href="ecat7_8h.html#aeba6b1646ad1dd69809d9ba3a8732939">ECAT7_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;    blkNr=%d\n&quot;</span>, blkNr);
<a name="l01040"></a>01040   <span class="comment">/* Search the place for writing */</span>
<a name="l01041"></a>01041   fseek(fp, (start_block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l01042"></a>01042   <span class="keywordflow">if</span>(ftell(fp)!=(start_block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l01043"></a>01043   <span class="comment">/* Save blocks one at a time */</span>
<a name="l01044"></a>01044   <span class="keywordflow">for</span>(i=0, dptr=data; i&lt;blkNr &amp;&amp; dataSize&gt;0; i++) {
<a name="l01045"></a>01045     byteNr=(dataSize&lt;<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>)?dataSize:<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>;
<a name="l01046"></a>01046     memcpy(buf, dptr, byteNr);
<a name="l01047"></a>01047     <span class="comment">/* Change matrix byte order in little endian platforms */</span>
<a name="l01048"></a>01048     <span class="keywordflow">if</span>(little) {
<a name="l01049"></a>01049       <span class="keywordflow">if</span>(pxl_size==2) swabip(buf, byteNr);
<a name="l01050"></a>01050       <span class="keywordflow">else</span> <span class="keywordflow">if</span>(pxl_size==4) swawbip(buf, byteNr);
<a name="l01051"></a>01051     }
<a name="l01052"></a>01052     <span class="comment">/* Write block */</span>
<a name="l01053"></a>01053     <span class="keywordflow">if</span>(fwrite(buf, 1, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, fp)!=<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(3);
<a name="l01054"></a>01054     <span class="comment">/* Prepare for the next block */</span>
<a name="l01055"></a>01055     dptr+=byteNr; dataSize-=byteNr;
<a name="l01056"></a>01056   } <span class="comment">/* next block */</span>
<a name="l01057"></a>01057   <span class="keywordflow">return</span>(0);
<a name="l01058"></a>01058 }
<a name="l01059"></a>01059 <span class="comment">/*****************************************************************************/</span>
<a name="l01060"></a>01060 
<a name="l01061"></a>01061 <span class="comment">/*****************************************************************************/</span>
<a name="l01062"></a>01062 
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Mon Aug 8 2011 by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>