Sophie

Sophie

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

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>ecat63w.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">ecat63w.c</div>  </div>
</div>
<div class="contents">
<a href="ecat63w_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">  ecat63w.c  (c) 2003-2008 by Turku PET Centre</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">  Procedures for writing ECAT 6.3 matrix data.</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">  This program is free software; you can redistribute it and/or modify it under</span>
<a name="l00008"></a>00008 <span class="comment">  the terms of the GNU General Public License as published by the Free Software</span>
<a name="l00009"></a>00009 <span class="comment">  Foundation; either version 2 of the License, or (at your option) any later</span>
<a name="l00010"></a>00010 <span class="comment">  version.</span>
<a name="l00011"></a>00011 <span class="comment"></span>
<a name="l00012"></a>00012 <span class="comment">  This program is distributed in the hope that it will be useful, but WITHOUT</span>
<a name="l00013"></a>00013 <span class="comment">  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span>
<a name="l00014"></a>00014 <span class="comment">  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">  You should have received a copy of the GNU General Public License along with</span>
<a name="l00017"></a>00017 <span class="comment">  this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span>
<a name="l00018"></a>00018 <span class="comment">  Place, Suite 330, Boston, MA 02111-1307 USA.</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment">  Turku PET Centre hereby disclaims all copyright interest in the program.</span>
<a name="l00021"></a>00021 <span class="comment">  Juhani Knuuti</span>
<a name="l00022"></a>00022 <span class="comment">  Director, Professor</span>
<a name="l00023"></a>00023 <span class="comment">  Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi/</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00025"></a>00025 <span class="comment">  Assumptions:</span>
<a name="l00026"></a>00026 <span class="comment">  1. All data is always saved in little endian byte order (i386 and VAX).</span>
<a name="l00027"></a>00027 <span class="comment">  2. Data is automatically saved in one of the little endian formats</span>
<a name="l00028"></a>00028 <span class="comment">     as specified in header data_type.</span>
<a name="l00029"></a>00029 <span class="comment">  3. VAX data can be saved correctly only in 2-byte formats.</span>
<a name="l00030"></a>00030 <span class="comment"></span>
<a name="l00031"></a>00031 <span class="comment">  Modification history:</span>
<a name="l00032"></a>00032 <span class="comment">  2003-07-21 Vesa Oikonen</span>
<a name="l00033"></a>00033 <span class="comment">    Created based on previous contents of ecat63.c.</span>
<a name="l00034"></a>00034 <span class="comment">  2003-09-08 VO</span>
<a name="l00035"></a>00035 <span class="comment">    Added function ecat63WriteImageMatrix() and ecat63WriteScanMatrix().</span>
<a name="l00036"></a>00036 <span class="comment">  2003-11-30 VO</span>
<a name="l00037"></a>00037 <span class="comment">    For now, calls temp_roundf() instead of roundf().</span>
<a name="l00038"></a>00038 <span class="comment">  2004-01-07 VO</span>
<a name="l00039"></a>00039 <span class="comment">    ecat63WriteImageMatrix(): corrected img min&amp;max in header.</span>
<a name="l00040"></a>00040 <span class="comment">  2004-09-17 VO</span>
<a name="l00041"></a>00041 <span class="comment">    Doxygen style comments.</span>
<a name="l00042"></a>00042 <span class="comment">  2004-12-28 VO</span>
<a name="l00043"></a>00043 <span class="comment">    Included function ecat63_is_scaling_needed().</span>
<a name="l00044"></a>00044 <span class="comment">    This function is applied to determine whether scal factor can be set to</span>
<a name="l00045"></a>00045 <span class="comment">    one in case that all pixel values are close to integers and small enough.</span>
<a name="l00046"></a>00046 <span class="comment">  2007-01-27 VO</span>
<a name="l00047"></a>00047 <span class="comment">    Unsigned char pointer was corrected to signed in ecat63WriteMatdata().</span>
<a name="l00048"></a>00048 <span class="comment">  2007-09-02 VO</span>
<a name="l00049"></a>00049 <span class="comment">    Backup file extension changed from % to .bak.</span>
<a name="l00050"></a>00050 <span class="comment"></span>
<a name="l00051"></a>00051 <span class="comment">******************************************************************************/</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00057"></a>00057 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00058"></a>00058 <span class="comment">/*****************************************************************************/</span>
<a name="l00059"></a>00059 <span class="preprocessor">#include &lt;swap.h&gt;</span>
<a name="l00060"></a>00060 <span class="preprocessor">#include &lt;petc99.h&gt;</span>
<a name="l00061"></a>00061 <span class="preprocessor">#include &quot;<a class="code" href="ecat63_8h.html">include/ecat63.h</a>&quot;</span>
<a name="l00062"></a>00062 <span class="comment">/*****************************************************************************/</span>
<a name="l00063"></a>00063 
<a name="l00064"></a>00064 <span class="comment">/*****************************************************************************/</span>
<a name="l00073"></a><a class="code" href="ecat63_8h.html#af7389948dcb81fe5984b5ece280e9267">00073</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#af7389948dcb81fe5984b5ece280e9267">ecat63WriteMainheader</a>(FILE *fp, <a class="code" href="structecat63__mainheader.html">ECAT63_mainheader</a> *h) {
<a name="l00074"></a>00074   <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> i, little, tovax;
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 
<a name="l00078"></a>00078   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteMainheader()\n&quot;</span>);
<a name="l00079"></a>00079   little=little_endian();
<a name="l00080"></a>00080   <span class="comment">/* Clear buf */</span>
<a name="l00081"></a>00081   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00082"></a>00082   <span class="comment">/* Check arguments */</span>
<a name="l00083"></a>00083   <span class="keywordflow">if</span>(fp==NULL || h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>&lt;1 || h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>&gt;7) <span class="keywordflow">return</span>(1);
<a name="l00084"></a>00084   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>==<a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a> || h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>==<a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>==<a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>)
<a name="l00085"></a>00085     tovax=1; <span class="keywordflow">else</span> tovax=0;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087   <span class="comment">/* Copy short ints to buf */</span>
<a name="l00088"></a>00088   memcpy(buf+50, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>, 2); memcpy(buf+48, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a433a5fddd8c83644a9f081001815c6e6">sw_version</a>, 2);
<a name="l00089"></a>00089   memcpy(buf+52, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a90a0ac55f8a40ddcf53446ee30e2aa7a">system_type</a>, 2); memcpy(buf+54, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#aeb7fd4a6b107a810dcff5d82b6f58440">file_type</a>, 2);
<a name="l00090"></a>00090   memcpy(buf+66, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a2d2676e349d9446fba65f1185b22b6c9">scan_start_day</a>, 2); memcpy(buf+68, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#accef159de133ceecb8712a22b9aaa261">scan_start_month</a>, 2);
<a name="l00091"></a>00091   memcpy(buf+70, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ac50ce9695fe8b410dc42d611a9c3bff7">scan_start_year</a>, 2); memcpy(buf+72, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a1f67ed153d99b8f1e5edf24850312275">scan_start_hour</a>, 2);
<a name="l00092"></a>00092   memcpy(buf+74, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a152db2ee622ee372c1a0691ef9eea5a5">scan_start_minute</a>, 2); memcpy(buf+76, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ae5de61076a9b1bfd13c22bea60c6b933">scan_start_second</a>, 2);
<a name="l00093"></a>00093   memcpy(buf+134, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ac24a7070e07c35906285b975eb6aacae">rot_source_speed</a>, 2); memcpy(buf+136, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ac554d77fa721e3454396f35d77fa31b8">wobble_speed</a>, 2);
<a name="l00094"></a>00094   memcpy(buf+138, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ab89f9adf0c7c53a823892065750d9e2d">transm_source_type</a>, 2); memcpy(buf+148, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#afd42572adc630dfd3dbcd2602afddfa6">transaxial_samp_mode</a>, 2);
<a name="l00095"></a>00095   memcpy(buf+150, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#af0124cfc4b7e4ac510702b6339b32403">coin_samp_mode</a>, 2); memcpy(buf+152, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a577058082315645f5f27ca4a5d9c0a19">axial_samp_mode</a>, 2);
<a name="l00096"></a>00096   memcpy(buf+158, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ad8b7b38c78851f5724f8e2095d850271">calibration_units</a>, 2); memcpy(buf+160, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ab8b4fa825fdb60803fe60d53cffa8e74">compression_code</a>, 2);
<a name="l00097"></a>00097   memcpy(buf+350, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a16c7a2c3d3e98b2c0cef829e6bc00290">acquisition_type</a>, 2); memcpy(buf+352, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a49caf11d85e6fef4eb039276ecf64256">bed_type</a>, 2);
<a name="l00098"></a>00098   memcpy(buf+354, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a79a415479a0c09dfb06d3245f7599f96">septa_type</a>, 2); memcpy(buf+376, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#aec1a2e31ad9fa2e9d03220565bc3cfa0">num_planes</a>, 2);
<a name="l00099"></a>00099   memcpy(buf+378, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a01ad1f4be366fb3ad82da61022e9761c">num_frames</a>, 2); memcpy(buf+380, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a5038021b6504d93e304931a95af64746">num_gates</a>, 2);
<a name="l00100"></a>00100   memcpy(buf+382, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ad8cbcc286f61bd37eb2a6f196b88a4bb">num_bed_pos</a>, 2); memcpy(buf+452, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a13f45bc9caa001d28019f421ca46a52d">lwr_sctr_thres</a>, 2);
<a name="l00101"></a>00101   memcpy(buf+454, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a685b532f86091f57191edb6c0ba8da53">lwr_true_thres</a>, 2); memcpy(buf+456, &amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a101df6a9ca3509b5e1f7d0518c383fb7">upr_true_thres</a>, 2);
<a name="l00102"></a>00102   memcpy(buf+472, h-&gt;<a class="code" href="structecat63__mainheader.html#a9413616e9b11fcd27160252e93b7395b">fill2</a>, 40);
<a name="l00103"></a>00103   <span class="comment">/* big to little endian if necessary */</span>
<a name="l00104"></a>00104   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00105"></a>00105 
<a name="l00106"></a>00106   <span class="comment">/* Copy floats to buf */</span>
<a name="l00107"></a>00107   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#aa80e2c3fda2047135338e9525b48fb17">isotope_halflife</a>, buf+86, tovax, little);
<a name="l00108"></a>00108   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a38e8f748203bf3de942564a0d3aab35a">gantry_tilt</a>, buf+122, tovax, little);
<a name="l00109"></a>00109   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a32ea34339fa4cc9512ef5b2f7ce46827">gantry_rotation</a>, buf+126, tovax, little);
<a name="l00110"></a>00110   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a6de93fb04de87b775340ee78426e2df2">bed_elevation</a>, buf+130, tovax, little);
<a name="l00111"></a>00111   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#acfb971c6cfaffd74900fb23da894bef2">axial_fov</a>, buf+140, tovax, little);
<a name="l00112"></a>00112   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a3545e9b7344313ca3f5c0e9f817d1fc4">transaxial_fov</a>, buf+144, tovax, little);
<a name="l00113"></a>00113   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ab8dd149fc8b61f8ccd115799e419f7e1">calibration_factor</a>, buf+154, tovax, little);
<a name="l00114"></a>00114   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a918cf8249e510ed1ea646eb2950f8917">init_bed_position</a>, buf+384, tovax, little);
<a name="l00115"></a>00115   <span class="keywordflow">for</span>(i=0; i&lt;15; i++) <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a42922815c9a98cfa855ccca6414607a8">bed_offset</a>[i], buf+388+4*i, tovax, little);
<a name="l00116"></a>00116   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#afa9b56b592ebcc6a0c8a499c7b74562a">plane_separation</a>, buf+448, tovax, little);
<a name="l00117"></a>00117   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a918cf8249e510ed1ea646eb2950f8917">init_bed_position</a>, buf+458, tovax, little);
<a name="l00118"></a>00118 
<a name="l00119"></a>00119   <span class="comment">/* Copy chars */</span>
<a name="l00120"></a>00120   <span class="comment">/*memcpy(buf+0, h-&gt;ecat_format, 14);*/</span>
<a name="l00121"></a>00121   memcpy(buf+14, h-&gt;<a class="code" href="structecat63__mainheader.html#a13f283213e6bb6a5148fc2f4b0e03af1">fill1</a>, 14);
<a name="l00122"></a>00122   memcpy(buf+28, h-&gt;<a class="code" href="structecat63__mainheader.html#a935ae0ef7f06681f8c5be4b271241a71">original_file_name</a>, 20); memcpy(buf+56, h-&gt;<a class="code" href="structecat63__mainheader.html#a606ca1749b0691876985fb9402214340">node_id</a>, 10);
<a name="l00123"></a>00123   memcpy(buf+78, h-&gt;<a class="code" href="structecat63__mainheader.html#ad5e1bd9b72bdc5e5cc820bf25231bef5">isotope_code</a>, 8); memcpy(buf+90, h-&gt;<a class="code" href="structecat63__mainheader.html#a51129743a09356f7b83e11fa0865d17d">radiopharmaceutical</a>, 32);
<a name="l00124"></a>00124   memcpy(buf+162, h-&gt;<a class="code" href="structecat63__mainheader.html#ae42d92d4f2b85a68511f266f7cddfc8c">study_name</a>, 12); memcpy(buf+174, h-&gt;<a class="code" href="structecat63__mainheader.html#ac0ca7836b26f3bcc824110278ecb6508">patient_id</a>, 16);
<a name="l00125"></a>00125   memcpy(buf+190, h-&gt;<a class="code" href="structecat63__mainheader.html#a7c66591db9e9dd727d6707ea1051df88">patient_name</a>, 32); buf[222]=h-&gt;<a class="code" href="structecat63__mainheader.html#a44b07fa3efe28762d2ade58833788168">patient_sex</a>;
<a name="l00126"></a>00126   memcpy(buf+223, h-&gt;<a class="code" href="structecat63__mainheader.html#a33db620324b99d80ca7b8b106ef520ba">patient_age</a>, 10); memcpy(buf+233, h-&gt;<a class="code" href="structecat63__mainheader.html#ad28e6cdce6b92758d74d22eac1be292b">patient_height</a>, 10);
<a name="l00127"></a>00127   memcpy(buf+243, h-&gt;<a class="code" href="structecat63__mainheader.html#a35febd9319d39da8ae89316b99521101">patient_weight</a>, 10); buf[253]=h-&gt;<a class="code" href="structecat63__mainheader.html#aabd34d2a124d86226a292cbfec77e7d8">patient_dexterity</a>;
<a name="l00128"></a>00128   memcpy(buf+254, h-&gt;<a class="code" href="structecat63__mainheader.html#a910f5c488748b19dbb94fa1aec78f705">physician_name</a>, 32); memcpy(buf+286, h-&gt;<a class="code" href="structecat63__mainheader.html#abd8730336b30375e6727da5bc96200b7">operator_name</a>, 32);
<a name="l00129"></a>00129   memcpy(buf+318, h-&gt;<a class="code" href="structecat63__mainheader.html#a6322ecb4779f20b48b19360b605127e7">study_description</a>, 32); memcpy(buf+356, h-&gt;<a class="code" href="structecat63__mainheader.html#ae6a2bf495625010946776df823250e3f">facility_name</a>, 20);
<a name="l00130"></a>00130   memcpy(buf+462, h-&gt;<a class="code" href="structecat63__mainheader.html#aeae1e01c587128f945503d87cb6d3ada">user_process_code</a>, 10);
<a name="l00131"></a>00131 
<a name="l00132"></a>00132   <span class="comment">/* Write main header */</span>
<a name="l00133"></a>00133   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>(2);
<a name="l00134"></a>00134   <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>(3);
<a name="l00135"></a>00135 
<a name="l00136"></a>00136   <span class="keywordflow">return</span>(0);
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138 <span class="comment">/*****************************************************************************/</span>
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 <span class="comment">/*****************************************************************************/</span>
<a name="l00150"></a><a class="code" href="ecat63_8h.html#a327a43e9f2dbfe66dcec54ff4141877c">00150</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a327a43e9f2dbfe66dcec54ff4141877c">ecat63WriteImageheader</a>(FILE *fp, <span class="keywordtype">int</span> block, <a class="code" href="structecat63__imageheader.html">ECAT63_imageheader</a> *h) {
<a name="l00151"></a>00151   <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00152"></a>00152   <span class="keywordtype">int</span> i, little, tovax;
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 
<a name="l00155"></a>00155   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteImageheader(fp, %d, ih)\n&quot;</span>, block);
<a name="l00156"></a>00156   little=little_endian();
<a name="l00157"></a>00157   <span class="comment">/* Clear buf */</span>
<a name="l00158"></a>00158   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00159"></a>00159   <span class="comment">/* Check arguments */</span>
<a name="l00160"></a>00160   <span class="keywordflow">if</span>(fp==NULL || block&lt;3 || h-&gt;data_type&lt;1 || h-&gt;data_type&gt;7) <span class="keywordflow">return</span>(1);
<a name="l00161"></a>00161   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>==<a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a> || h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>==<a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>==<a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>)
<a name="l00162"></a>00162     tovax=1; <span class="keywordflow">else</span> tovax=0;
<a name="l00163"></a>00163 
<a name="l00164"></a>00164   <span class="comment">/* Copy short ints to buf */</span>
<a name="l00165"></a>00165   memcpy(buf+126, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>, 2); memcpy(buf+128, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a417f483d23efabd675ed72cdd4bbdb98">num_dimensions</a>, 2);
<a name="l00166"></a>00166   memcpy(buf+132, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a86aae28e4de4b65fa5de745aab0bf082">dimension_1</a>, 2); memcpy(buf+134, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ad53dbc60f5f5a34b7327abbf0d609d5d">dimension_2</a>, 2);
<a name="l00167"></a>00167   memcpy(buf+176, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ad9ae22f6f465f3872ad5dbc66f0a171b">image_min</a>, 2); memcpy(buf+178, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a7020d45c4b35dd0c72ce4b87028ed9b9">image_max</a>, 2);
<a name="l00168"></a>00168   memcpy(buf+200, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ab2ad7047109098114baaf68ae96f785a">slice_location</a>, 2); memcpy(buf+202, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#add9fadfc6afa697b50b6a84e360cf71c">recon_start_hour</a>, 2);
<a name="l00169"></a>00169   memcpy(buf+204, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aefab8b0646f7233d6c7f08a0328a984e">recon_start_min</a>, 2); memcpy(buf+206, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ae69b914674635a9da4c600e78703051e">recon_start_sec</a>, 2);
<a name="l00170"></a>00170   memcpy(buf+236, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#adcb3ed305ba54f4b8a9a741c3d6057d5">filter_code</a>, 2); memcpy(buf+376, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ad88958ba21580417790fc9c23b00c201">processing_code</a>, 2);
<a name="l00171"></a>00171   memcpy(buf+380, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a38136ac931d35627e8644ccc71d97aec">quant_units</a>, 2); memcpy(buf+382, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a0f9df554b4dd1694ae38c207efcec372">recon_start_day</a>, 2);
<a name="l00172"></a>00172   memcpy(buf+384, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a88c4c57b18c0350780971f7be380752a">recon_start_month</a>, 2); memcpy(buf+386, &amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aee97d9526938759b161038f6e8252a75">recon_start_year</a>, 2);
<a name="l00173"></a>00173   memcpy(buf+460, h-&gt;<a class="code" href="structecat63__imageheader.html#a6c2f1300a3551d37dd81b91d9b625839">fill2</a>, 52);
<a name="l00174"></a>00174   <span class="comment">/* big to little endian if necessary */</span>
<a name="l00175"></a>00175   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00176"></a>00176 
<a name="l00177"></a>00177   <span class="comment">/* Copy floats to buf */</span>
<a name="l00178"></a>00178   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a9fea37402b9dfb18edbaba6b2afd3bab">x_origin</a>, buf+160, tovax, little);
<a name="l00179"></a>00179   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a0ffe63c2a805cb90643870800e01b1ff">y_origin</a>, buf+164, tovax, little);
<a name="l00180"></a>00180   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a9a0fd8c173273797330c7c67effdffd6">recon_scale</a>, buf+168, tovax, little);
<a name="l00181"></a>00181   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>, buf+172, tovax, little);
<a name="l00182"></a>00182   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a749a7dfb6443194317be2260fc7b5b7b">pixel_size</a>, buf+184, tovax, little);
<a name="l00183"></a>00183   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ac2b4f461866cfcbe8bf33939d461becc">slice_width</a>, buf+188, tovax, little);
<a name="l00184"></a>00184   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a74e01096c6d9daad3aabf5eaa50dd7a1">image_rotation</a>, buf+296, tovax, little);
<a name="l00185"></a>00185   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a7c53b9df3c138cf5b9d5b2986d003377">plane_eff_corr_fctr</a>, buf+300, tovax, little);
<a name="l00186"></a>00186   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a46ec10bffd9ad4bd54271b68022bd41c">decay_corr_fctr</a>, buf+304, tovax, little);
<a name="l00187"></a>00187   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ab7fe2e08a8afa0b40c4fb9cf5a434ac1">loss_corr_fctr</a>, buf+308, tovax, little);
<a name="l00188"></a>00188   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aeb7e92ca7928577171eb2649879f0ea6">intrinsic_tilt</a>, buf+312, tovax, little);
<a name="l00189"></a>00189   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aa50b6a76225241de1056e26de450fb1c">ecat_calibration_fctr</a>, buf+388, tovax, little);
<a name="l00190"></a>00190   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a6338eb4b7fdcb624ac0673260d16db42">well_counter_cal_fctr</a>, buf+392, tovax, little);
<a name="l00191"></a>00191   <span class="keywordflow">for</span>(i=0; i&lt;6; i++) <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#af215d79c43ac183c8d871f4cae77719b">filter_params</a>[i], buf+396+4*i, tovax, little);
<a name="l00192"></a>00192 
<a name="l00193"></a>00193   <span class="comment">/* Copy ints to buf */</span>
<a name="l00194"></a>00194   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ae4fba67f8fb4e7f72f4d74b215b39058">frame_duration</a>, buf+192, tovax, little);
<a name="l00195"></a>00195   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a14bdbc2c5ce62d9ed0c57514b02f8f0e">frame_start_time</a>, buf+196, tovax, little);
<a name="l00196"></a>00196   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a759c941e68c9518ac37e09e03701c168">scan_matrix_num</a>, buf+238, tovax, little);
<a name="l00197"></a>00197   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a6e6757740c620b06c0c9d2ab8fcae00f">norm_matrix_num</a>, buf+242, tovax, little);
<a name="l00198"></a>00198   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aae892e831603ccf3a4308f9dc36d4859">atten_cor_mat_num</a>, buf+246, tovax, little);
<a name="l00199"></a>00199 
<a name="l00200"></a>00200   <span class="comment">/* Copy chars */</span>
<a name="l00201"></a>00201   memcpy(buf+0, h-&gt;<a class="code" href="structecat63__imageheader.html#aa86c76e6040ffa3c46ef183a81e77644">fill1</a>, 126); memcpy(buf+420, h-&gt;<a class="code" href="structecat63__imageheader.html#a773755a2de4e065ae28f0d52f6de101d">annotation</a>, 40);
<a name="l00202"></a>00202 
<a name="l00203"></a>00203   <span class="comment">/* Write subheader */</span>
<a name="l00204"></a>00204   fseek(fp, (block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00205"></a>00205   <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>(3);
<a name="l00206"></a>00206 
<a name="l00207"></a>00207   <span class="keywordflow">return</span>(0);
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 <span class="comment">/*****************************************************************************/</span>
<a name="l00210"></a>00210 
<a name="l00211"></a>00211 <span class="comment">/*****************************************************************************/</span>
<a name="l00221"></a><a class="code" href="ecat63_8h.html#a4fc17d1d569fe825751dc0116a9e7854">00221</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a4fc17d1d569fe825751dc0116a9e7854">ecat63WriteAttnheader</a>(FILE *fp, <span class="keywordtype">int</span> block, <a class="code" href="structecat63__attnheader.html">ECAT63_attnheader</a> *h) {
<a name="l00222"></a>00222   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00223"></a>00223   <span class="keywordtype">int</span> little, tovax;
<a name="l00224"></a>00224 
<a name="l00225"></a>00225   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteAttnheader(fp, %d, ah)\n&quot;</span>, block);
<a name="l00226"></a>00226   little=little_endian();
<a name="l00227"></a>00227   <span class="comment">/* Clear buf */</span>
<a name="l00228"></a>00228   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00229"></a>00229   <span class="comment">/* Check arguments */</span>
<a name="l00230"></a>00230   <span class="keywordflow">if</span>(fp==NULL || block&lt;3 || h-&gt;data_type&lt;1 || h-&gt;data_type&gt;7) <span class="keywordflow">return</span>(1);
<a name="l00231"></a>00231   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>==<a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a> || h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>==<a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>==<a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>)
<a name="l00232"></a>00232     tovax=1; <span class="keywordflow">else</span> tovax=0;
<a name="l00233"></a>00233 
<a name="l00234"></a>00234   <span class="comment">/* Copy short ints to buf */</span>
<a name="l00235"></a>00235   memcpy(buf+126, &amp;h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>, 2); memcpy(buf+128, &amp;h-&gt;<a class="code" href="structecat63__attnheader.html#afddf2ebc3902db6517580be3dfbe8d5e">attenuation_type</a>, 2);
<a name="l00236"></a>00236   memcpy(buf+132, &amp;h-&gt;<a class="code" href="structecat63__attnheader.html#acbea9636493630fc7bdc3de4fcd4cfa2">dimension_1</a>, 2); memcpy(buf+134, &amp;h-&gt;<a class="code" href="structecat63__attnheader.html#af9fa1e4491aa3321b4ce99f54e5ebb6e">dimension_2</a>, 2);
<a name="l00237"></a>00237   <span class="comment">/* big to little endian if necessary */</span>
<a name="l00238"></a>00238   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00239"></a>00239 
<a name="l00240"></a>00240   <span class="comment">/* Copy floats to buf */</span>
<a name="l00241"></a>00241   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a649891350c3b30214f43ca2d640a0e47">scale_factor</a>, buf+182, tovax, little);
<a name="l00242"></a>00242   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a392054bdf86e477fa5cf6da7cca40ce5">x_origin</a>, buf+186, tovax, little);
<a name="l00243"></a>00243   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a625b116f6858b728a3a83d9312c914d2">y_origin</a>, buf+190, tovax, little);
<a name="l00244"></a>00244   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a525063ffc32765f26d039e3bcba1996c">x_radius</a>, buf+194, tovax, little);
<a name="l00245"></a>00245   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#ab85f3c502080d57c3b01db2a4ff17096">y_radius</a>, buf+198, tovax, little);
<a name="l00246"></a>00246   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a28abaa374db45b1b6be743117cd269eb">tilt_angle</a>, buf+202, tovax, little);
<a name="l00247"></a>00247   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a2cb849370c0300e6e88f8668cfae4bce">attenuation_coeff</a>, buf+206, tovax, little);
<a name="l00248"></a>00248   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#a8637550d8495fed5a5f5e59701f8d428">sample_distance</a>, buf+210, tovax, little);
<a name="l00249"></a>00249 
<a name="l00250"></a>00250   <span class="comment">/* Write subheader */</span>
<a name="l00251"></a>00251   fseek(fp, (block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00252"></a>00252   <span class="keywordflow">if</span>(ftell(fp)!=(block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00253"></a>00253   <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>(3);
<a name="l00254"></a>00254 
<a name="l00255"></a>00255   <span class="keywordflow">return</span>(0);
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 <span class="comment">/*****************************************************************************/</span>
<a name="l00258"></a>00258 
<a name="l00259"></a>00259 <span class="comment">/*****************************************************************************/</span>
<a name="l00269"></a><a class="code" href="ecat63_8h.html#a608dc4920336f49febe13ea8b74dd0c8">00269</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a608dc4920336f49febe13ea8b74dd0c8">ecat63WriteScanheader</a>(FILE *fp, <span class="keywordtype">int</span> block, <a class="code" href="structecat63__scanheader.html">ECAT63_scanheader</a> *h) {
<a name="l00270"></a>00270   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00271"></a>00271   <span class="keywordtype">int</span> i, little, tovax;
<a name="l00272"></a>00272 
<a name="l00273"></a>00273 
<a name="l00274"></a>00274   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteScanheader(fp, %d, ih)\n&quot;</span>, block);
<a name="l00275"></a>00275   little=little_endian();
<a name="l00276"></a>00276   <span class="comment">/* Clear buf */</span>
<a name="l00277"></a>00277   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00278"></a>00278   <span class="comment">/* Check arguments */</span>
<a name="l00279"></a>00279   <span class="keywordflow">if</span>(fp==NULL || block&lt;3 || h-&gt;data_type&lt;1 || h-&gt;data_type&gt;7) <span class="keywordflow">return</span>(1);
<a name="l00280"></a>00280   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>==<a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a> || h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>==<a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>==<a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>)
<a name="l00281"></a>00281     tovax=1; <span class="keywordflow">else</span> tovax=0;
<a name="l00282"></a>00282 
<a name="l00283"></a>00283   <span class="comment">/* Copy short ints to buf */</span>
<a name="l00284"></a>00284   memcpy(buf+126, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>, 2);
<a name="l00285"></a>00285   memcpy(buf+132, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#adee5ad20def49d6f13da7efde9da4e3e">dimension_1</a>, 2); memcpy(buf+134, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a87c12560397fa7408d95ad30d1800f92">dimension_2</a>, 2);
<a name="l00286"></a>00286   memcpy(buf+136, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#aedadbe34a589d483a34936e17e416131">smoothing</a>, 2); memcpy(buf+138, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a639b2f86794956dbb694ec5eb072e85b">processing_code</a>, 2);
<a name="l00287"></a>00287   memcpy(buf+170, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#aaf23846f5c3ee43188d49fac0f592498">frame_duration_sec</a>, 2);
<a name="l00288"></a>00288   memcpy(buf+192, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#abeeb6fea3c31b83464be7afcdff37219">scan_min</a>, 2); memcpy(buf+194, &amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a87fc09622afe7e2372588f650e7e6afd">scan_max</a>, 2);
<a name="l00289"></a>00289   memcpy(buf+468, h-&gt;<a class="code" href="structecat63__scanheader.html#a27cb56a4d012e3bf4bbd0f53aaf39183">fill2</a>, 44);
<a name="l00290"></a>00290   <span class="comment">/* big to little endian if necessary */</span>
<a name="l00291"></a>00291   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00292"></a>00292 
<a name="l00293"></a>00293   <span class="comment">/* Copy floats to buf */</span>
<a name="l00294"></a>00294   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#acb676ed22b052fbaa07bd044263ac279">sample_distance</a>, buf+146, tovax, little);
<a name="l00295"></a>00295   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a3310fbd6ef8bb0062d44b8dcb0315726">isotope_halflife</a>, buf+166, tovax, little);
<a name="l00296"></a>00296   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>, buf+182, tovax, little);
<a name="l00297"></a>00297   <span class="keywordflow">for</span>(i=0; i&lt;16; i++) {
<a name="l00298"></a>00298     <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a0620862723c58710a4510ffcb184f4cd">cor_singles</a>[i], buf+316+4*i, tovax, little);
<a name="l00299"></a>00299     <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a1ccfde8610fb4974ce32c3dd6f252480">uncor_singles</a>[i], buf+380+4*i, tovax, little);
<a name="l00300"></a>00300   }
<a name="l00301"></a>00301   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#afcbe607c1cd9a432f6aac5dabc9a77ea">tot_avg_cor</a>, buf+444, tovax, little);
<a name="l00302"></a>00302   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#af8563b96c975f59dec8ff89fe4ce46b4">tot_avg_uncor</a>, buf+448, tovax, little);
<a name="l00303"></a>00303   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a3077aca1fa9f9b64c57f4b6eb19780fb">loss_correction_fctr</a>, buf+464, tovax, little);
<a name="l00304"></a>00304 
<a name="l00305"></a>00305   <span class="comment">/* Copy ints to buf */</span>
<a name="l00306"></a>00306   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#abf1ed74916f2296dbdc73246f0ac7e26">gate_duration</a>, buf+172, tovax, little);
<a name="l00307"></a>00307   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a7507738b6d21d0b5145bc66e0baefcd1">r_wave_offset</a>, buf+176, tovax, little);
<a name="l00308"></a>00308   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a28b007d345ada719bb886fd7a2683d76">prompts</a>, buf+196, tovax, little);
<a name="l00309"></a>00309   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#ad0a2468779aec56e8d45ca685834eb16">delayed</a>, buf+200, tovax, little);
<a name="l00310"></a>00310   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a8100b3eed008502c7817e0b629de155e">multiples</a>, buf+204, tovax, little);
<a name="l00311"></a>00311   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a8acda07cbdfaba46a41cdb735e6ff222">net_trues</a>, buf+208, tovax, little);
<a name="l00312"></a>00312   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#ada524bc7b4273bd533cc1a1071fb71f0">total_coin_rate</a>, buf+452, tovax, little);
<a name="l00313"></a>00313   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#aa7214f91108a9d7a5bec6f0edbe3493d">frame_start_time</a>, buf+456, tovax, little);
<a name="l00314"></a>00314   <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a253426410960e4047acfb591c24e179b">frame_duration</a>, buf+460, tovax, little);
<a name="l00315"></a>00315 
<a name="l00316"></a>00316   <span class="comment">/* Copy chars */</span>
<a name="l00317"></a>00317   memcpy(buf+0, h-&gt;<a class="code" href="structecat63__scanheader.html#aed0424fc176e0af33fe14ed05eb4d11e">fill1</a>, 126);
<a name="l00318"></a>00318 
<a name="l00319"></a>00319   <span class="comment">/* Write subheader */</span>
<a name="l00320"></a>00320   fseek(fp, (block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00321"></a>00321   <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>(3);
<a name="l00322"></a>00322 
<a name="l00323"></a>00323   <span class="keywordflow">return</span>(0);
<a name="l00324"></a>00324 }<span class="comment">/*****************************************************************************/</span>
<a name="l00325"></a>00325 
<a name="l00326"></a>00326 <span class="comment">/*****************************************************************************/</span>
<a name="l00336"></a><a class="code" href="ecat63_8h.html#ab1a871c42693f0cb1cf5831e6aaa946f">00336</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#ab1a871c42693f0cb1cf5831e6aaa946f">ecat63WriteNormheader</a>(FILE *fp, <span class="keywordtype">int</span> block, <a class="code" href="structecat63__normheader.html">ECAT63_normheader</a> *h)
<a name="l00337"></a>00337 {
<a name="l00338"></a>00338   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00339"></a>00339   <span class="keywordtype">int</span> little, tovax;
<a name="l00340"></a>00340 
<a name="l00341"></a>00341   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteNormheader(fp, %d, nh)\n&quot;</span>, block);
<a name="l00342"></a>00342   little=little_endian();
<a name="l00343"></a>00343   <span class="comment">/* Clear buf */</span>
<a name="l00344"></a>00344   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00345"></a>00345   <span class="comment">/* Check arguments */</span>
<a name="l00346"></a>00346   <span class="keywordflow">if</span>(fp==NULL || block&lt;3 || h-&gt;data_type&lt;1 || h-&gt;data_type&gt;7) <span class="keywordflow">return</span>(1);
<a name="l00347"></a>00347   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>==<a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a> || h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>==<a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>==<a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>)
<a name="l00348"></a>00348     tovax=1; <span class="keywordflow">else</span> tovax=0;
<a name="l00349"></a>00349 
<a name="l00350"></a>00350   <span class="comment">/* Copy short ints to buf */</span>
<a name="l00351"></a>00351   memcpy(buf+126, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>, 2);
<a name="l00352"></a>00352   memcpy(buf+132, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#a546d6d89d6df87d2de51c1588884d5b5">dimension_1</a>, 2); memcpy(buf+134, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#aa49aa059f33fad5d960b044da8076fe7">dimension_2</a>, 2);
<a name="l00353"></a>00353   memcpy(buf+372, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#a89973101e53a28f7ea189da834d833f5">norm_hour</a>, 2);
<a name="l00354"></a>00354   memcpy(buf+376, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#aa23c1f37bfc67d61ac6c23ad47e0ef3f">norm_minute</a>, 2);
<a name="l00355"></a>00355   memcpy(buf+380, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#a3b5598a2aec2cf470d28704984ba8abe">norm_second</a>, 2);
<a name="l00356"></a>00356   memcpy(buf+384, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#af2594e900754a91cfd91ae9c0abb4189">norm_day</a>, 2);
<a name="l00357"></a>00357   memcpy(buf+388, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#a07ca626ae6c4ccebc0259e4938b788a6">norm_month</a>, 2);
<a name="l00358"></a>00358   memcpy(buf+392, &amp;h-&gt;<a class="code" href="structecat63__normheader.html#a50b35e9ff630f374ff9699073a40f118">norm_year</a>, 2);
<a name="l00359"></a>00359   <span class="comment">/* big to little endian if necessary */</span>
<a name="l00360"></a>00360   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00361"></a>00361 
<a name="l00362"></a>00362   <span class="comment">/* Copy floats to buf */</span>
<a name="l00363"></a>00363   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a914977ee68c14326a4551abae57fc9ab">scale_factor</a>, buf+182, tovax, little);
<a name="l00364"></a>00364   <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a7b68dc00c4466d354e5caec905af190b">fov_source_width</a>, buf+198, tovax, little);
<a name="l00365"></a>00365 
<a name="l00366"></a>00366   <span class="comment">/* Write subheader */</span>
<a name="l00367"></a>00367   fseek(fp, (block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00368"></a>00368   <span class="keywordflow">if</span>(ftell(fp)!=(block-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00369"></a>00369   <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>(3);
<a name="l00370"></a>00370 
<a name="l00371"></a>00371   <span class="keywordflow">return</span>(0);
<a name="l00372"></a>00372 }
<a name="l00373"></a>00373 <span class="comment">/*****************************************************************************/</span>
<a name="l00374"></a>00374 
<a name="l00375"></a>00375 <span class="comment">/*****************************************************************************/</span>
<a name="l00386"></a><a class="code" href="ecat63_8h.html#aa9545a4a59002bf59a77478977f479eb">00386</a> FILE *<a class="code" href="ecat63w_8c.html#aa9545a4a59002bf59a77478977f479eb">ecat63Create</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fname, <a class="code" href="structecat63__mainheader.html">ECAT63_mainheader</a> *h) {
<a name="l00387"></a>00387   FILE *fp;
<a name="l00388"></a>00388   <span class="keywordtype">char</span> tmp[FILENAME_MAX];
<a name="l00389"></a>00389   <span class="keywordtype">int</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>/4];
<a name="l00390"></a>00390 
<a name="l00391"></a>00391   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63Create()\n&quot;</span>);
<a name="l00392"></a>00392   <span class="comment">/* Check the arguments */</span>
<a name="l00393"></a>00393   <span class="keywordflow">if</span>(fname==NULL || h==NULL) <span class="keywordflow">return</span>(NULL);
<a name="l00394"></a>00394   <span class="comment">/* Check if file exists; backup, if necessary */</span>
<a name="l00395"></a>00395   <span class="keywordflow">if</span>(access(fname, 0) != -1) {
<a name="l00396"></a>00396     strcpy(tmp, fname); strcat(tmp, <a class="code" href="analyze_8h.html#aaefec1fffef0834f552b1dcf3513d2f8">BACKUP_EXTENSION</a>);
<a name="l00397"></a>00397     <span class="keywordflow">if</span>(access(tmp, 0) != -1) <span class="keyword">remove</span>(tmp);
<a name="l00398"></a>00398     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Renaming %s -&gt; %s\n&quot;</span>, fname, tmp);
<a name="l00399"></a>00399     rename(fname, tmp);
<a name="l00400"></a>00400   }
<a name="l00401"></a>00401   <span class="comment">/* Open file */</span>
<a name="l00402"></a>00402   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="l00403"></a>00403   <span class="comment">/* Write main header */</span>
<a name="l00404"></a>00404   <span class="keywordflow">if</span>(<a class="code" href="ecat63w_8c.html#af7389948dcb81fe5984b5ece280e9267">ecat63WriteMainheader</a>(fp, h)) <span class="keywordflow">return</span>(NULL);
<a name="l00405"></a>00405   <span class="comment">/* Construct an empty matrix list ; convert to little endian if necessary */</span>
<a name="l00406"></a>00406   memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);  
<a name="l00407"></a>00407   buf[0]=31; buf[1]=2; <span class="keywordflow">if</span>(!little_endian()) swawbip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00408"></a>00408   <span class="comment">/* Write data buffer */</span>
<a name="l00409"></a>00409   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="l00410"></a>00410   <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="l00411"></a>00411   <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="l00412"></a>00412   <span class="comment">/* OK, then return file pointer */</span>
<a name="l00413"></a>00413   <span class="keywordflow">return</span>(fp);
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415 <span class="comment">/*****************************************************************************/</span>
<a name="l00416"></a>00416 
<a name="l00417"></a>00417 <span class="comment">/*****************************************************************************/</span>
<a name="l00429"></a><a class="code" href="ecat63_8h.html#ab7e9bf33b3225d1260ad04c44ce817ab">00429</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#ab7e9bf33b3225d1260ad04c44ce817ab">ecat63WriteImage</a>(FILE *fp, <span class="keywordtype">int</span> matnum, <a class="code" href="structecat63__imageheader.html">ECAT63_imageheader</a> *h, <span class="keywordtype">void</span> *data) {
<a name="l00430"></a>00430   <span class="keywordtype">int</span> nxtblk, blkNr, data_size, pxlNr, pxlSize, ret;
<a name="l00431"></a>00431 
<a name="l00432"></a>00432   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteImage(fp, %d, ih, data)\n&quot;</span>, matnum);
<a name="l00433"></a>00433   <span class="keywordflow">if</span>(fp==NULL || matnum&lt;1 || h==NULL || data==NULL) <span class="keywordflow">return</span>(1);
<a name="l00434"></a>00434   <span class="comment">/* nr of pixels */</span>
<a name="l00435"></a>00435   pxlNr=h-&gt;<a class="code" href="structecat63__imageheader.html#a86aae28e4de4b65fa5de745aab0bf082">dimension_1</a>*h-&gt;<a class="code" href="structecat63__imageheader.html#ad53dbc60f5f5a34b7327abbf0d609d5d">dimension_2</a>; <span class="keywordflow">if</span>(pxlNr&lt;1) <span class="keywordflow">return</span>(2);
<a name="l00436"></a>00436   <span class="comment">/* mem taken by one pixel */</span>
<a name="l00437"></a>00437   <span class="keywordflow">switch</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>) {
<a name="l00438"></a>00438     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>: pxlSize=1;
<a name="l00439"></a>00439       <span class="keywordflow">break</span>;
<a name="l00440"></a>00440     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a>:
<a name="l00441"></a>00441     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>: pxlSize=2;
<a name="l00442"></a>00442       <span class="keywordflow">break</span>;
<a name="l00443"></a>00443     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a>: <span class="keywordflow">return</span>(3);
<a name="l00444"></a>00444     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>: <span class="keywordflow">return</span>(3);
<a name="l00445"></a>00445     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>:
<a name="l00446"></a>00446     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>: pxlSize=4;
<a name="l00447"></a>00447       <span class="keywordflow">break</span>;
<a name="l00448"></a>00448     <span class="keywordflow">default</span>: <span class="keywordflow">return</span>(2);
<a name="l00449"></a>00449   }
<a name="l00450"></a>00450   <span class="comment">/* mem taken by all pixels */</span>
<a name="l00451"></a>00451   data_size=pxlNr*pxlSize;
<a name="l00452"></a>00452   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00453"></a>00453   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) <span class="keywordflow">return</span>(3);
<a name="l00454"></a>00454   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00455"></a>00455   nxtblk=<a class="code" href="ecat63ml_8c.html#a01664c72df6a487a1de8d1da3bbc9983">ecat63Matenter</a>(fp, matnum, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) <span class="keywordflow">return</span>(4);
<a name="l00456"></a>00456   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;  block=%d\n&quot;</span>, nxtblk);
<a name="l00457"></a>00457   <span class="comment">/* Write header */</span>
<a name="l00458"></a>00458   ret=<a class="code" href="ecat63w_8c.html#a327a43e9f2dbfe66dcec54ff4141877c">ecat63WriteImageheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(40+ret);
<a name="l00459"></a>00459   <span class="comment">/* Write matrix data */</span>
<a name="l00460"></a>00460   ret=<a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(fp, nxtblk+1, data, pxlNr, pxlSize);
<a name="l00461"></a>00461   <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(50+ret);
<a name="l00462"></a>00462   <span class="keywordflow">return</span> 0;
<a name="l00463"></a>00463 }
<a name="l00464"></a>00464 <span class="comment">/*****************************************************************************/</span>
<a name="l00465"></a>00465 
<a name="l00466"></a>00466 <span class="comment">/*****************************************************************************/</span>
<a name="l00478"></a><a class="code" href="ecat63_8h.html#a0ef3ec20d54221eb1730dd531724b378">00478</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a0ef3ec20d54221eb1730dd531724b378">ecat63WriteScan</a>(FILE *fp, <span class="keywordtype">int</span> matnum, <a class="code" href="structecat63__scanheader.html">ECAT63_scanheader</a> *h, <span class="keywordtype">void</span> *data) {
<a name="l00479"></a>00479   <span class="keywordtype">int</span> nxtblk, blkNr, data_size, pxlNr, pxlSize, ret;
<a name="l00480"></a>00480 
<a name="l00481"></a>00481   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteScan(fp, %d, sh, data)\n&quot;</span>, matnum);
<a name="l00482"></a>00482   <span class="keywordflow">if</span>(fp==NULL || matnum&lt;1 || h==NULL || data==NULL) <span class="keywordflow">return</span>(1);
<a name="l00483"></a>00483   <span class="comment">/* nr of pixels */</span>
<a name="l00484"></a>00484   pxlNr=h-&gt;<a class="code" href="structecat63__scanheader.html#adee5ad20def49d6f13da7efde9da4e3e">dimension_1</a>*h-&gt;<a class="code" href="structecat63__scanheader.html#a87c12560397fa7408d95ad30d1800f92">dimension_2</a>; <span class="keywordflow">if</span>(pxlNr&lt;1) <span class="keywordflow">return</span>(1);
<a name="l00485"></a>00485   <span class="comment">/* mem taken by one pixel */</span>
<a name="l00486"></a>00486   <span class="keywordflow">switch</span>(h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>) {
<a name="l00487"></a>00487     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>: pxlSize=1;
<a name="l00488"></a>00488       <span class="keywordflow">break</span>;
<a name="l00489"></a>00489     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a>:
<a name="l00490"></a>00490     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>: pxlSize=2;
<a name="l00491"></a>00491       <span class="keywordflow">break</span>;
<a name="l00492"></a>00492     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a>: <span class="keywordflow">return</span>(3);
<a name="l00493"></a>00493     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>: <span class="keywordflow">return</span>(3);
<a name="l00494"></a>00494     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>:
<a name="l00495"></a>00495     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>: pxlSize=4;
<a name="l00496"></a>00496       <span class="keywordflow">break</span>;
<a name="l00497"></a>00497     <span class="keywordflow">default</span>: <span class="keywordflow">return</span>(2);
<a name="l00498"></a>00498   }
<a name="l00499"></a>00499   <span class="comment">/* mem taken by all pixels */</span>
<a name="l00500"></a>00500   data_size=pxlNr*pxlSize;
<a name="l00501"></a>00501   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00502"></a>00502   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) <span class="keywordflow">return</span>(3);
<a name="l00503"></a>00503   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00504"></a>00504   nxtblk=<a class="code" href="ecat63ml_8c.html#a01664c72df6a487a1de8d1da3bbc9983">ecat63Matenter</a>(fp, matnum, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) <span class="keywordflow">return</span>(4);
<a name="l00505"></a>00505   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;  block=%d\n&quot;</span>, nxtblk);
<a name="l00506"></a>00506   <span class="comment">/* Write header */</span>
<a name="l00507"></a>00507   ret=<a class="code" href="ecat63w_8c.html#a608dc4920336f49febe13ea8b74dd0c8">ecat63WriteScanheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(40+ret);
<a name="l00508"></a>00508   <span class="comment">/* Write matrix data */</span>
<a name="l00509"></a>00509   ret=<a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(fp, nxtblk+1, data, pxlNr, pxlSize);
<a name="l00510"></a>00510   <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(50+ret);
<a name="l00511"></a>00511   <span class="keywordflow">return</span> 0;
<a name="l00512"></a>00512 }
<a name="l00513"></a>00513 <span class="comment">/*****************************************************************************/</span>
<a name="l00514"></a>00514 
<a name="l00515"></a>00515 <span class="comment">/*****************************************************************************/</span>
<a name="l00527"></a><a class="code" href="ecat63_8h.html#a85d370c72e0c5fb5a43178a1f02cc215">00527</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a85d370c72e0c5fb5a43178a1f02cc215">ecat63WriteNorm</a>(FILE *fp, <span class="keywordtype">int</span> matnum, <a class="code" href="structecat63__normheader.html">ECAT63_normheader</a> *h, <span class="keywordtype">void</span> *data) {
<a name="l00528"></a>00528   <span class="keywordtype">int</span> nxtblk, blkNr, data_size, pxlNr, pxlSize, ret;
<a name="l00529"></a>00529 
<a name="l00530"></a>00530   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteNorm(fp, %d, nh, data)\n&quot;</span>, matnum);
<a name="l00531"></a>00531   <span class="keywordflow">if</span>(fp==NULL || matnum&lt;1 || h==NULL || data==NULL) <span class="keywordflow">return</span>(1);
<a name="l00532"></a>00532   <span class="comment">/* nr of pixels */</span>
<a name="l00533"></a>00533   pxlNr=h-&gt;<a class="code" href="structecat63__normheader.html#a546d6d89d6df87d2de51c1588884d5b5">dimension_1</a>*h-&gt;<a class="code" href="structecat63__normheader.html#aa49aa059f33fad5d960b044da8076fe7">dimension_2</a>; <span class="keywordflow">if</span>(pxlNr&lt;1) <span class="keywordflow">return</span>(1);
<a name="l00534"></a>00534   <span class="comment">/* mem taken by one pixel */</span>
<a name="l00535"></a>00535   <span class="keywordflow">switch</span>(h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>) {
<a name="l00536"></a>00536     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>: pxlSize=1;
<a name="l00537"></a>00537       <span class="keywordflow">break</span>;
<a name="l00538"></a>00538     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a>:
<a name="l00539"></a>00539     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>: pxlSize=2;
<a name="l00540"></a>00540       <span class="keywordflow">break</span>;
<a name="l00541"></a>00541     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a>: <span class="keywordflow">return</span>(3);
<a name="l00542"></a>00542     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>: <span class="keywordflow">return</span>(3);
<a name="l00543"></a>00543     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>:
<a name="l00544"></a>00544     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>: pxlSize=4;
<a name="l00545"></a>00545       <span class="keywordflow">break</span>;
<a name="l00546"></a>00546     <span class="keywordflow">default</span>: <span class="keywordflow">return</span>(2);
<a name="l00547"></a>00547   }
<a name="l00548"></a>00548   <span class="comment">/* mem taken by all pixels */</span>
<a name="l00549"></a>00549   data_size=pxlNr*pxlSize;
<a name="l00550"></a>00550   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00551"></a>00551   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) <span class="keywordflow">return</span>(3);
<a name="l00552"></a>00552   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00553"></a>00553   nxtblk=<a class="code" href="ecat63ml_8c.html#a01664c72df6a487a1de8d1da3bbc9983">ecat63Matenter</a>(fp, matnum, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) <span class="keywordflow">return</span>(4);
<a name="l00554"></a>00554   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;  block=%d\n&quot;</span>, nxtblk);
<a name="l00555"></a>00555   <span class="comment">/* Write header */</span>
<a name="l00556"></a>00556   ret=<a class="code" href="ecat63w_8c.html#ab1a871c42693f0cb1cf5831e6aaa946f">ecat63WriteNormheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(40+ret);
<a name="l00557"></a>00557   <span class="comment">/* Write matrix data */</span>
<a name="l00558"></a>00558   ret=<a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(fp, nxtblk+1, data, pxlNr, pxlSize);
<a name="l00559"></a>00559   <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(50+ret);
<a name="l00560"></a>00560   <span class="keywordflow">return</span> 0;
<a name="l00561"></a>00561 }
<a name="l00562"></a>00562 <span class="comment">/*****************************************************************************/</span>
<a name="l00563"></a>00563 
<a name="l00564"></a>00564 <span class="comment">/*****************************************************************************/</span>
<a name="l00576"></a><a class="code" href="ecat63_8h.html#a826f96374b28edfaa5f5d6fe2edd8071">00576</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a826f96374b28edfaa5f5d6fe2edd8071">ecat63WriteAttn</a>(FILE *fp, <span class="keywordtype">int</span> matnum, <a class="code" href="structecat63__attnheader.html">ECAT63_attnheader</a> *h, <span class="keywordtype">void</span> *data) {
<a name="l00577"></a>00577   <span class="keywordtype">int</span> nxtblk, blkNr, data_size, pxlNr, pxlSize, ret;
<a name="l00578"></a>00578 
<a name="l00579"></a>00579   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteAttn(fp, %d, ah, data)\n&quot;</span>, matnum);
<a name="l00580"></a>00580   <span class="keywordflow">if</span>(fp==NULL || matnum&lt;1 || h==NULL || data==NULL) <span class="keywordflow">return</span>(1);
<a name="l00581"></a>00581   <span class="comment">/* nr of pixels */</span>
<a name="l00582"></a>00582   pxlNr=h-&gt;<a class="code" href="structecat63__attnheader.html#acbea9636493630fc7bdc3de4fcd4cfa2">dimension_1</a>*h-&gt;<a class="code" href="structecat63__attnheader.html#af9fa1e4491aa3321b4ce99f54e5ebb6e">dimension_2</a>; <span class="keywordflow">if</span>(pxlNr&lt;1) <span class="keywordflow">return</span>(1);
<a name="l00583"></a>00583   <span class="comment">/* mem taken by one pixel */</span>
<a name="l00584"></a>00584   <span class="keywordflow">switch</span>(h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>) {
<a name="l00585"></a>00585     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>: pxlSize=1;
<a name="l00586"></a>00586       <span class="keywordflow">break</span>;
<a name="l00587"></a>00587     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a>:
<a name="l00588"></a>00588     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>: pxlSize=2;
<a name="l00589"></a>00589       <span class="keywordflow">break</span>;
<a name="l00590"></a>00590     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a>: <span class="keywordflow">return</span>(3);
<a name="l00591"></a>00591     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>: <span class="keywordflow">return</span>(3);
<a name="l00592"></a>00592     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>:
<a name="l00593"></a>00593     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>: pxlSize=4;
<a name="l00594"></a>00594       <span class="keywordflow">break</span>;
<a name="l00595"></a>00595     <span class="keywordflow">default</span>: <span class="keywordflow">return</span>(2);
<a name="l00596"></a>00596   }
<a name="l00597"></a>00597   <span class="comment">/* mem taken by all pixels */</span>
<a name="l00598"></a>00598   data_size=pxlNr*pxlSize;
<a name="l00599"></a>00599   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00600"></a>00600   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) <span class="keywordflow">return</span>(3);
<a name="l00601"></a>00601   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00602"></a>00602   nxtblk=<a class="code" href="ecat63ml_8c.html#a01664c72df6a487a1de8d1da3bbc9983">ecat63Matenter</a>(fp, matnum, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) <span class="keywordflow">return</span>(4);
<a name="l00603"></a>00603   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;  block=%d\n&quot;</span>, nxtblk);
<a name="l00604"></a>00604   <span class="comment">/* Write header */</span>
<a name="l00605"></a>00605   ret=<a class="code" href="ecat63w_8c.html#a4fc17d1d569fe825751dc0116a9e7854">ecat63WriteAttnheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(40+ret);
<a name="l00606"></a>00606   <span class="comment">/* Write matrix data */</span>
<a name="l00607"></a>00607   ret=<a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(fp, nxtblk+1, data, pxlNr, pxlSize);
<a name="l00608"></a>00608   <span class="keywordflow">if</span>(ret) <span class="keywordflow">return</span>(50+ret);
<a name="l00609"></a>00609   <span class="keywordflow">return</span> 0;
<a name="l00610"></a>00610 }
<a name="l00611"></a>00611 <span class="comment">/*****************************************************************************/</span>
<a name="l00612"></a>00612 
<a name="l00613"></a>00613 <span class="comment">/*****************************************************************************/</span>
<a name="l00629"></a><a class="code" href="ecat63_8h.html#ae12c957a9ab48147bd356f207d176cf2">00629</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(FILE *fp, <span class="keywordtype">int</span> strtblk, <span class="keywordtype">char</span> *data, <span class="keywordtype">int</span> pxlNr, <span class="keywordtype">int</span> pxlSize) {
<a name="l00630"></a>00630   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00631"></a>00631   <span class="keywordtype">char</span> *dptr;
<a name="l00632"></a>00632   <span class="keywordtype">int</span> i, blkNr, dataSize, byteNr, little;
<a name="l00633"></a>00633 
<a name="l00634"></a>00634   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteMatdata(fp, %d, data, %d, %d)\n&quot;</span>, strtblk, pxlNr, pxlSize);
<a name="l00635"></a>00635   <span class="keywordflow">if</span>(fp==NULL || strtblk&lt;1 || data==NULL || pxlNr&lt;1 || pxlSize&lt;1) <span class="keywordflow">return</span>(1);
<a name="l00636"></a>00636   little=little_endian(); memset(buf, 0, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00637"></a>00637   dataSize=pxlNr*pxlSize; <span class="keywordflow">if</span>(dataSize&lt;1) <span class="keywordflow">return</span>(1);
<a name="l00638"></a>00638   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00639"></a>00639   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="l00640"></a>00640   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>&gt;1) printf(<span class="stringliteral">&quot;    blkNr=%d\n&quot;</span>, blkNr);
<a name="l00641"></a>00641   <span class="comment">/* Search the place for writing */</span>
<a name="l00642"></a>00642   fseek(fp, (strtblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(strtblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00643"></a>00643   <span class="comment">/* Save blocks one at a time */</span>
<a name="l00644"></a>00644   <span class="keywordflow">for</span>(i=0, dptr=data; i&lt;blkNr &amp;&amp; dataSize&gt;0; i++) {
<a name="l00645"></a>00645     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="l00646"></a>00646     memcpy(buf, dptr, byteNr);
<a name="l00647"></a>00647     <span class="comment">/* Change matrix byte order in big endian platforms */</span>
<a name="l00648"></a>00648     <span class="keywordflow">if</span>(!little_endian()) {
<a name="l00649"></a>00649       <span class="keywordflow">if</span>(pxlSize==2) swabip(buf, byteNr);
<a name="l00650"></a>00650       <span class="keywordflow">else</span> <span class="keywordflow">if</span>(pxlSize==4) swawbip(buf, byteNr);
<a name="l00651"></a>00651     }
<a name="l00652"></a>00652     <span class="comment">/* Write block */</span>
<a name="l00653"></a>00653     <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="l00654"></a>00654     <span class="comment">/* Prepare for the next block */</span>
<a name="l00655"></a>00655     dptr+=byteNr;
<a name="l00656"></a>00656     dataSize-=byteNr;
<a name="l00657"></a>00657   } <span class="comment">/* next block */</span>
<a name="l00658"></a>00658   <span class="keywordflow">return</span>(0);
<a name="l00659"></a>00659 }
<a name="l00660"></a>00660 <span class="comment">/*****************************************************************************/</span>
<a name="l00661"></a>00661 
<a name="l00662"></a>00662 <span class="comment">/*****************************************************************************/</span>
<a name="l00672"></a><a class="code" href="ecat63_8h.html#a6c63b8a6ad8bc0b86257b3d00441c1c7">00672</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a6c63b8a6ad8bc0b86257b3d00441c1c7">ecat63_is_scaling_needed</a>(<span class="keywordtype">float</span> amax, <span class="keywordtype">float</span> *data, <span class="keywordtype">int</span> nr) {
<a name="l00673"></a>00673   <span class="keywordtype">int</span> i;
<a name="l00674"></a>00674   <span class="keywordtype">double</span> d;
<a name="l00675"></a>00675 
<a name="l00676"></a>00676   <span class="keywordflow">if</span>(nr&lt;1 || data==NULL) <span class="keywordflow">return</span>(0);
<a name="l00677"></a>00677   <span class="comment">/* scaling is necessary if all values are between -1 - 1 */</span>
<a name="l00678"></a>00678   <span class="keywordflow">if</span>(amax&lt;0.9999) <span class="keywordflow">return</span>(1);
<a name="l00679"></a>00679   <span class="comment">/* Lets check first if at least the max value is close to integers or not */</span>
<a name="l00680"></a>00680   <span class="keywordflow">if</span>(modf(amax, &amp;d)&gt;0.0001) <span class="keywordflow">return</span>(1);
<a name="l00681"></a>00681   <span class="comment">/* if it is, then check all pixels */</span>
<a name="l00682"></a>00682   <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="l00683"></a>00683   <span class="keywordflow">return</span>(0);
<a name="l00684"></a>00684 }
<a name="l00685"></a>00685 <span class="comment">/*****************************************************************************/</span>
<a name="l00686"></a>00686 
<a name="l00687"></a>00687 <span class="comment">/*****************************************************************************/</span>
<a name="l00700"></a><a class="code" href="ecat63_8h.html#a904b20e0e7304bc40e2e562f73e1b6ae">00700</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a904b20e0e7304bc40e2e562f73e1b6ae">ecat63WriteImageMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matnum, <a class="code" href="structecat63__imageheader.html">ECAT63_imageheader</a> *h, <span class="keywordtype">float</span> *fdata) {
<a name="l00701"></a>00701   <span class="keywordtype">int</span> i, nxtblk, blkNr, data_size, pxlNr, ret;
<a name="l00702"></a>00702   <span class="keywordtype">float</span> *fptr, fmin, fmax, g, f;
<a name="l00703"></a>00703   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00704"></a>00704   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00705"></a>00705 
<a name="l00706"></a>00706 
<a name="l00707"></a>00707 
<a name="l00708"></a>00708   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteImageMatrix(fp, %d, h, data)\n&quot;</span>, matnum);
<a name="l00709"></a>00709   <span class="keywordflow">if</span>(fp==NULL || matnum&lt;1 || h==NULL || fdata==NULL) {
<a name="l00710"></a>00710     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00711"></a>00711     <span class="keywordflow">return</span>(1);
<a name="l00712"></a>00712   }
<a name="l00713"></a>00713   <span class="comment">/* nr of pixels */</span>
<a name="l00714"></a>00714   pxlNr=h-&gt;<a class="code" href="structecat63__imageheader.html#a86aae28e4de4b65fa5de745aab0bf082">dimension_1</a>*h-&gt;<a class="code" href="structecat63__imageheader.html#ad53dbc60f5f5a34b7327abbf0d609d5d">dimension_2</a>;
<a name="l00715"></a>00715   <span class="keywordflow">if</span>(pxlNr&lt;1) {
<a name="l00716"></a>00716     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00717"></a>00717     <span class="keywordflow">return</span>(3);
<a name="l00718"></a>00718   }
<a name="l00719"></a>00719   <span class="comment">/* How much memory is needed for ALL pixels */</span>
<a name="l00720"></a>00720   data_size=pxlNr*<a class="code" href="ecat63r_8c.html#af68deed580dda9af0e046697323d616d">ecat63pxlbytes</a>(h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>);
<a name="l00721"></a>00721   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00722"></a>00722   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="l00723"></a>00723     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid block number.\n&quot;</span>);
<a name="l00724"></a>00724     <span class="keywordflow">return</span>(4);
<a name="l00725"></a>00725   }
<a name="l00726"></a>00726   <span class="comment">/* Allocate memory for matrix data */</span>
<a name="l00727"></a>00727   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="l00728"></a>00728     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;out of memory.\n&quot;</span>);
<a name="l00729"></a>00729     <span class="keywordflow">return</span>(5);
<a name="l00730"></a>00730   }
<a name="l00731"></a>00731   <span class="comment">/* Search for min and max for calculation of scale factor */</span>
<a name="l00732"></a>00732   fptr=fdata; fmin=fmax=*fptr;
<a name="l00733"></a>00733   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) {
<a name="l00734"></a>00734     <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="l00735"></a>00735   }
<a name="l00736"></a>00736   <span class="keywordflow">if</span>(fabs(fmin)&gt;fabs(fmax)) g=fabs(fmin); <span class="keywordflow">else</span> g=fabs(fmax);
<a name="l00737"></a>00737   <span class="keywordflow">if</span>(g&gt;0) f=32766./g; <span class="keywordflow">else</span> f=1.0;
<a name="l00738"></a>00738   <span class="comment">/* Check if pixels values can be left as such with scale_factor = 1 */</span>
<a name="l00739"></a>00739   fptr=fdata;
<a name="l00740"></a>00740   <span class="keywordflow">if</span>(f&gt;=1.0 &amp;&amp; <a class="code" href="ecat63w_8c.html#a6c63b8a6ad8bc0b86257b3d00441c1c7">ecat63_is_scaling_needed</a>(g, fptr, pxlNr)==0) f=1.0;
<a name="l00741"></a>00741   <span class="comment">/* Scale matrix data to shorts */</span>
<a name="l00742"></a>00742   h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>=1.0/f;
<a name="l00743"></a>00743   sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mdata; fptr=fdata;
<a name="l00744"></a>00744   <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="l00745"></a>00745   <span class="comment">/* Set header short min &amp; max */</span>
<a name="l00746"></a>00746   h-&gt;<a class="code" href="structecat63__imageheader.html#ad9ae22f6f465f3872ad5dbc66f0a171b">image_min</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmin);
<a name="l00747"></a>00747   h-&gt;<a class="code" href="structecat63__imageheader.html#a7020d45c4b35dd0c72ce4b87028ed9b9">image_max</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmax);
<a name="l00748"></a>00748   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00749"></a>00749   nxtblk=<a class="code" href="ecat63ml_8c.html#a01664c72df6a487a1de8d1da3bbc9983">ecat63Matenter</a>(fp, matnum, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) {
<a name="l00750"></a>00750     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot determine matrix block (%d).\n&quot;</span>, -nxtblk);
<a name="l00751"></a>00751     free(mdata); <span class="keywordflow">return</span>(8);
<a name="l00752"></a>00752   }
<a name="l00753"></a>00753   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;  block=%d fmin=%g fmax=%g\n&quot;</span>, nxtblk, fmin, fmax);
<a name="l00754"></a>00754   <span class="comment">/* Write header */</span>
<a name="l00755"></a>00755   ret=<a class="code" href="ecat63w_8c.html#a327a43e9f2dbfe66dcec54ff4141877c">ecat63WriteImageheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) {
<a name="l00756"></a>00756     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot write subheader (%d).\n&quot;</span>, ret);
<a name="l00757"></a>00757     free(mdata); <span class="keywordflow">return</span>(10);
<a name="l00758"></a>00758   }
<a name="l00759"></a>00759   <span class="comment">/* Write matrix data */</span>
<a name="l00760"></a>00760   mptr=mdata;
<a name="l00761"></a>00761   ret=<a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(fp, nxtblk+1, mptr, pxlNr, <a class="code" href="ecat63r_8c.html#af68deed580dda9af0e046697323d616d">ecat63pxlbytes</a>(h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>));
<a name="l00762"></a>00762   free(mdata);
<a name="l00763"></a>00763   <span class="keywordflow">if</span>(ret) {
<a name="l00764"></a>00764     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot write matrix data (%d).\n&quot;</span>, ret);
<a name="l00765"></a>00765     <span class="keywordflow">return</span>(13);
<a name="l00766"></a>00766   }
<a name="l00767"></a>00767   <span class="keywordflow">return</span>(0);
<a name="l00768"></a>00768 }
<a name="l00769"></a>00769 <span class="comment">/*****************************************************************************/</span>
<a name="l00770"></a>00770 
<a name="l00771"></a>00771 <span class="comment">/*****************************************************************************/</span>
<a name="l00784"></a><a class="code" href="ecat63_8h.html#a35a5f197ce098dfc1d91166962af59d2">00784</a> <span class="keywordtype">int</span> <a class="code" href="ecat63w_8c.html#a35a5f197ce098dfc1d91166962af59d2">ecat63WriteScanMatrix</a>(FILE *fp, <span class="keywordtype">int</span> matnum, <a class="code" href="structecat63__scanheader.html">ECAT63_scanheader</a> *h, <span class="keywordtype">float</span> *fdata) {
<a name="l00785"></a>00785   <span class="keywordtype">int</span> i, nxtblk, blkNr, data_size, pxlNr, ret;
<a name="l00786"></a>00786   <span class="keywordtype">float</span> *fptr, fmin, fmax, g, f;
<a name="l00787"></a>00787   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00788"></a>00788   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00789"></a>00789 
<a name="l00790"></a>00790 
<a name="l00791"></a>00791   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63WriteScanMatrix(fp, %d, h, data)\n&quot;</span>, matnum);
<a name="l00792"></a>00792   <span class="keywordflow">if</span>(fp==NULL || matnum&lt;1 || h==NULL || fdata==NULL) {
<a name="l00793"></a>00793     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00794"></a>00794     <span class="keywordflow">return</span>(1);
<a name="l00795"></a>00795   }
<a name="l00796"></a>00796   <span class="comment">/* nr of pixels */</span>
<a name="l00797"></a>00797   pxlNr=h-&gt;<a class="code" href="structecat63__scanheader.html#adee5ad20def49d6f13da7efde9da4e3e">dimension_1</a>*h-&gt;<a class="code" href="structecat63__scanheader.html#a87c12560397fa7408d95ad30d1800f92">dimension_2</a>;
<a name="l00798"></a>00798   <span class="keywordflow">if</span>(pxlNr&lt;1) {
<a name="l00799"></a>00799     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00800"></a>00800     <span class="keywordflow">return</span>(3);
<a name="l00801"></a>00801   }
<a name="l00802"></a>00802   <span class="comment">/* How much memory is needed for ALL pixels */</span>
<a name="l00803"></a>00803   data_size=pxlNr*<a class="code" href="ecat63r_8c.html#af68deed580dda9af0e046697323d616d">ecat63pxlbytes</a>(h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>);
<a name="l00804"></a>00804   <span class="comment">/* block nr taken by all pixels */</span>
<a name="l00805"></a>00805   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="l00806"></a>00806     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid block number.\n&quot;</span>);
<a name="l00807"></a>00807     <span class="keywordflow">return</span>(4);
<a name="l00808"></a>00808   }
<a name="l00809"></a>00809   <span class="comment">/* Allocate memory for matrix data */</span>
<a name="l00810"></a>00810   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="l00811"></a>00811     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;out of memory.\n&quot;</span>);
<a name="l00812"></a>00812     <span class="keywordflow">return</span>(5);
<a name="l00813"></a>00813   }
<a name="l00814"></a>00814   <span class="comment">/* Search for min and max for calculation of scale factor */</span>
<a name="l00815"></a>00815   fptr=fdata; fmin=fmax=*fptr;
<a name="l00816"></a>00816   <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) {
<a name="l00817"></a>00817     <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="l00818"></a>00818   }
<a name="l00819"></a>00819   <span class="keywordflow">if</span>(fabs(fmin)&gt;fabs(fmax)) g=fabs(fmin); <span class="keywordflow">else</span> g=fabs(fmax);
<a name="l00820"></a>00820   <span class="keywordflow">if</span>(g&gt;0) f=32766./g; <span class="keywordflow">else</span> f=1.0;
<a name="l00821"></a>00821   <span class="comment">/* Check if pixels values can be left as such with scale_factor = 1 */</span>
<a name="l00822"></a>00822   fptr=fdata;
<a name="l00823"></a>00823   <span class="keywordflow">if</span>(f&gt;=1.0 &amp;&amp; <a class="code" href="ecat63w_8c.html#a6c63b8a6ad8bc0b86257b3d00441c1c7">ecat63_is_scaling_needed</a>(g, fptr, pxlNr)==0) f=1.0;
<a name="l00824"></a>00824   <span class="comment">/* Scale matrix data to shorts */</span>
<a name="l00825"></a>00825   h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>=1.0/f;
<a name="l00826"></a>00826   sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mdata; fptr=fdata;
<a name="l00827"></a>00827   <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="l00828"></a>00828   <span class="comment">/* Set header short min &amp; max */</span>
<a name="l00829"></a>00829   h-&gt;<a class="code" href="structecat63__scanheader.html#abeeb6fea3c31b83464be7afcdff37219">scan_min</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmin);
<a name="l00830"></a>00830   h-&gt;<a class="code" href="structecat63__scanheader.html#a87fc09622afe7e2372588f650e7e6afd">scan_max</a>=(<span class="keywordtype">short</span> int)temp_roundf(f*fmax);
<a name="l00831"></a>00831   <span class="comment">/* Get block number for matrix header and data */</span>
<a name="l00832"></a>00832   nxtblk=<a class="code" href="ecat63ml_8c.html#a01664c72df6a487a1de8d1da3bbc9983">ecat63Matenter</a>(fp, matnum, blkNr); <span class="keywordflow">if</span>(nxtblk&lt;1) {
<a name="l00833"></a>00833     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot determine matrix block (%d).\n&quot;</span>, -nxtblk);
<a name="l00834"></a>00834     free(mdata); <span class="keywordflow">return</span>(8);
<a name="l00835"></a>00835   }
<a name="l00836"></a>00836   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>&gt;2) printf(<span class="stringliteral">&quot;  block=%d fmin=%g fmax=%g\n&quot;</span>, nxtblk, fmin, fmax);
<a name="l00837"></a>00837   <span class="comment">/* Write header */</span>
<a name="l00838"></a>00838   ret=<a class="code" href="ecat63w_8c.html#a608dc4920336f49febe13ea8b74dd0c8">ecat63WriteScanheader</a>(fp, nxtblk, h); <span class="keywordflow">if</span>(ret) {
<a name="l00839"></a>00839     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot write subheader (%d).\n&quot;</span>, ret);
<a name="l00840"></a>00840     free(mdata); <span class="keywordflow">return</span>(10);
<a name="l00841"></a>00841   }
<a name="l00842"></a>00842   <span class="comment">/* Write matrix data */</span>
<a name="l00843"></a>00843   mptr=mdata;
<a name="l00844"></a>00844   ret=<a class="code" href="ecat63w_8c.html#ae12c957a9ab48147bd356f207d176cf2">ecat63WriteMatdata</a>(fp, nxtblk+1, mptr, pxlNr, <a class="code" href="ecat63r_8c.html#af68deed580dda9af0e046697323d616d">ecat63pxlbytes</a>(h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>));
<a name="l00845"></a>00845   free(mdata);
<a name="l00846"></a>00846   <span class="keywordflow">if</span>(ret) {
<a name="l00847"></a>00847     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot write matrix data (%d).\n&quot;</span>, ret);
<a name="l00848"></a>00848     <span class="keywordflow">return</span>(13);
<a name="l00849"></a>00849   }
<a name="l00850"></a>00850   <span class="keywordflow">return</span>(0);
<a name="l00851"></a>00851 }
<a name="l00852"></a>00852 <span class="comment">/*****************************************************************************/</span>
<a name="l00853"></a>00853 
<a name="l00854"></a>00854 <span class="comment">/*****************************************************************************/</span>
<a name="l00863"></a><a class="code" href="ecat63_8h.html#a52c9b0ff6e331b42fc4ba033d7c0e920">00863</a> <span class="keywordtype">void</span> <a class="code" href="ecat63w_8c.html#a52c9b0ff6e331b42fc4ba033d7c0e920">ecat63wFloat</a>(<span class="keywordtype">float</span> *bufi, <span class="keywordtype">void</span> *bufo, <span class="keywordtype">int</span> tovax, <span class="keywordtype">int</span> islittle) {
<a name="l00864"></a>00864   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ul;
<a name="l00865"></a>00865 
<a name="l00866"></a>00866   memcpy(&amp;ul, bufi, 4); <span class="keywordflow">if</span>(ul==0) {memcpy(bufo, bufi, 4); <span class="keywordflow">return</span>;}
<a name="l00867"></a>00867   <span class="keywordflow">if</span>(tovax) { <span class="comment">/* If VAX format is needed */</span>
<a name="l00868"></a>00868     ul+=(2L&lt;&lt;23); <span class="comment">/* increase exp by 2 */</span>
<a name="l00869"></a>00869     <span class="comment">/* Swap words on i386 and bytes on SUN */</span>
<a name="l00870"></a>00870     <span class="keywordflow">if</span>(islittle) swawip(&amp;ul, 4); <span class="keywordflow">else</span> swabip(&amp;ul, 4);
<a name="l00871"></a>00871   } <span class="keywordflow">else</span> {
<a name="l00872"></a>00872     <span class="keywordflow">if</span>(!islittle) swawbip(&amp;ul, 4); <span class="comment">/* Switch words and bytes on SUN */</span>
<a name="l00873"></a>00873   }
<a name="l00874"></a>00874   memcpy(bufo, &amp;ul, 4);
<a name="l00875"></a>00875 }
<a name="l00885"></a><a class="code" href="ecat63_8h.html#ac390002ea856aed49e87dde307fb05cb">00885</a> <span class="keywordtype">void</span> <a class="code" href="ecat63w_8c.html#ac390002ea856aed49e87dde307fb05cb">ecat63wInt</a>(<span class="keywordtype">int</span> *bufi, <span class="keywordtype">void</span> *bufo, <span class="keywordtype">int</span> tovax, <span class="keywordtype">int</span> islittle) {
<a name="l00886"></a>00886   <span class="keywordtype">int</span> i;
<a name="l00887"></a>00887 
<a name="l00888"></a>00888   <span class="comment">/* Swap both words and bytes on SUN */</span>
<a name="l00889"></a>00889   memcpy(&amp;i, bufi, 4); <span class="keywordflow">if</span>(!islittle) swawbip(&amp;i, 4);
<a name="l00890"></a>00890   memcpy(bufo, &amp;i, 4);
<a name="l00891"></a>00891 }
<a name="l00892"></a>00892 <span class="comment">/*****************************************************************************/</span>
<a name="l00893"></a>00893 
<a name="l00894"></a>00894 <span class="comment">/*****************************************************************************/</span>
</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>