Sophie

Sophie

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

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>ecat63r.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">ecat63r.c</div>  </div>
</div>
<div class="contents">
<a href="ecat63r_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">  ecat63r.c  (c) 2003,2004 by Turku PET Centre</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">  Procedures for reading ECAT 6.3 format.</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">  Assumptions:</span>
<a name="l00008"></a>00008 <span class="comment">  1. Data_type in headers specifies, whether ints, long ints and floats in</span>
<a name="l00009"></a>00009 <span class="comment">     header and matrix data are in VAX format (1, 2, 3 and 4) or in IEEE</span>
<a name="l00010"></a>00010 <span class="comment">     (i386, SUN) format.</span>
<a name="l00011"></a>00011 <span class="comment">  2. Data is automatically converted to little or big endian when read,</span>
<a name="l00012"></a>00012 <span class="comment">     according to the current platform.</span>
<a name="l00013"></a>00013 <span class="comment">  3. Data is automatically converted out from the VAX format when read,</span>
<a name="l00014"></a>00014 <span class="comment">     but header data_type remains as original.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">  Version: Contents were previously in ecat63.c</span>
<a name="l00017"></a>00017 <span class="comment">  2003-07-21 Vesa Oikonen</span>
<a name="l00018"></a>00018 <span class="comment">  2003-09-05 VO</span>
<a name="l00019"></a>00019 <span class="comment">    Added function ecat63ReadImageMatrix() and ecat63ReadScanMatrix().</span>
<a name="l00020"></a>00020 <span class="comment">  2003-09-08 VO</span>
<a name="l00021"></a>00021 <span class="comment">    Added function ecat63pxlbytes().</span>
<a name="l00022"></a>00022 <span class="comment">  2004-06-21 VO</span>
<a name="l00023"></a>00023 <span class="comment">    Larger range allowed for calibration factor in ecat63ReadMainheader().</span>
<a name="l00024"></a>00024 <span class="comment">  2004-09-20 VO</span>
<a name="l00025"></a>00025 <span class="comment">    Doxygen style comments.</span>
<a name="l00026"></a>00026 <span class="comment"></span>
<a name="l00027"></a>00027 <span class="comment">******************************************************************************/</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;ctype.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00035"></a>00035 <span class="comment">/*****************************************************************************/</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;swap.h&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="ecat63_8h.html">include/ecat63.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="comment">/*****************************************************************************/</span>
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="comment">/*****************************************************************************/</span>
<a name="l00050"></a><a class="code" href="ecat63_8h.html#af904c6b26259c4f280cdc18f92aeeae5">00050</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#af904c6b26259c4f280cdc18f92aeeae5">ecat63ReadMainheader</a>(FILE *fp, <a class="code" href="structecat63__mainheader.html">ECAT63_mainheader</a> *h) {
<a name="l00051"></a>00051   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00052"></a>00052   <span class="keywordtype">int</span> i;
<a name="l00053"></a>00053   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00054"></a>00054   <span class="keywordtype">int</span> vaxdata=1; <span class="comment">/* 1 if data is in VAX format, else 0 */</span>
<a name="l00055"></a>00055 
<a name="l00056"></a>00056   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadMainheader()\n&quot;</span>);
<a name="l00057"></a>00057   <span class="keywordflow">if</span>(fp==NULL || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00058"></a>00058   little=little_endian();
<a name="l00059"></a>00059   <span class="comment">/* Seek the first block */</span>
<a name="l00060"></a>00060   fseek(fp, 0, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=0) <span class="keywordflow">return</span>(1);
<a name="l00061"></a>00061   <span class="comment">/* Read the subheader block */</span>
<a name="l00062"></a>00062   <span class="keywordflow">if</span>(fread(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, 1, fp)&lt;1) <span class="keywordflow">return</span>(2);
<a name="l00063"></a>00063 
<a name="l00064"></a>00064   <span class="comment">/* Copy char data to header structure */</span>
<a name="l00065"></a>00065   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#abf166690e9be3bc9536dc0304292bd1f">ecat_format</a>, buf+0, 14); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a13f283213e6bb6a5148fc2f4b0e03af1">fill1</a>, buf+14, 14);
<a name="l00066"></a>00066   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a935ae0ef7f06681f8c5be4b271241a71">original_file_name</a>, buf+28, 20); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a606ca1749b0691876985fb9402214340">node_id</a>, buf+56, 10);
<a name="l00067"></a>00067   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#ad5e1bd9b72bdc5e5cc820bf25231bef5">isotope_code</a>, buf+78, 8); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a51129743a09356f7b83e11fa0865d17d">radiopharmaceutical</a>, buf+90, 32);
<a name="l00068"></a>00068   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#ae42d92d4f2b85a68511f266f7cddfc8c">study_name</a>, buf+162, 12); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#ac0ca7836b26f3bcc824110278ecb6508">patient_id</a>, buf+174, 16);
<a name="l00069"></a>00069   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a7c66591db9e9dd727d6707ea1051df88">patient_name</a>, buf+190, 32); h-&gt;<a class="code" href="structecat63__mainheader.html#a44b07fa3efe28762d2ade58833788168">patient_sex</a>=buf[222];
<a name="l00070"></a>00070   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a33db620324b99d80ca7b8b106ef520ba">patient_age</a>, buf+223, 10); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#ad28e6cdce6b92758d74d22eac1be292b">patient_height</a>, buf+233, 10);
<a name="l00071"></a>00071   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a35febd9319d39da8ae89316b99521101">patient_weight</a>, buf+243, 10); h-&gt;<a class="code" href="structecat63__mainheader.html#aabd34d2a124d86226a292cbfec77e7d8">patient_dexterity</a>=buf[253];
<a name="l00072"></a>00072   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a910f5c488748b19dbb94fa1aec78f705">physician_name</a>, buf+254, 32); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#abd8730336b30375e6727da5bc96200b7">operator_name</a>, buf+286, 32);
<a name="l00073"></a>00073   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a6322ecb4779f20b48b19360b605127e7">study_description</a>, buf+318, 32); memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#ae6a2bf495625010946776df823250e3f">facility_name</a>, buf+356, 20);
<a name="l00074"></a>00074   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#aeae1e01c587128f945503d87cb6d3ada">user_process_code</a>, buf+462, 10);
<a name="l00075"></a>00075 
<a name="l00076"></a>00076   <span class="comment">/* Copy short ints */</span>
<a name="l00077"></a>00077   <span class="comment">/* in big endian platform, change byte order temporarily */</span>
<a name="l00078"></a>00078   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00079"></a>00079   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>, buf+50, 2); <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>&gt;4) vaxdata=0;
<a name="l00080"></a>00080   <span class="comment">/*printf(&quot;main_header.data_type=%d\n&quot;, h-&gt;data_type);*/</span>
<a name="l00081"></a>00081   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a433a5fddd8c83644a9f081001815c6e6">sw_version</a>, buf+48, 2);
<a name="l00082"></a>00082   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a90a0ac55f8a40ddcf53446ee30e2aa7a">system_type</a>, buf+52, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#aeb7fd4a6b107a810dcff5d82b6f58440">file_type</a>, buf+54, 2);
<a name="l00083"></a>00083   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a2d2676e349d9446fba65f1185b22b6c9">scan_start_day</a>, buf+66, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#accef159de133ceecb8712a22b9aaa261">scan_start_month</a>, buf+68, 2);
<a name="l00084"></a>00084   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ac50ce9695fe8b410dc42d611a9c3bff7">scan_start_year</a>, buf+70, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a1f67ed153d99b8f1e5edf24850312275">scan_start_hour</a>, buf+72, 2);
<a name="l00085"></a>00085   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a152db2ee622ee372c1a0691ef9eea5a5">scan_start_minute</a>, buf+74, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ae5de61076a9b1bfd13c22bea60c6b933">scan_start_second</a>, buf+76, 2);
<a name="l00086"></a>00086   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ac24a7070e07c35906285b975eb6aacae">rot_source_speed</a>, buf+134, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ac554d77fa721e3454396f35d77fa31b8">wobble_speed</a>, buf+136, 2);
<a name="l00087"></a>00087   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ab89f9adf0c7c53a823892065750d9e2d">transm_source_type</a>, buf+138, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#afd42572adc630dfd3dbcd2602afddfa6">transaxial_samp_mode</a>, buf+148, 2);
<a name="l00088"></a>00088   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#af0124cfc4b7e4ac510702b6339b32403">coin_samp_mode</a>, buf+150, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a577058082315645f5f27ca4a5d9c0a19">axial_samp_mode</a>, buf+152, 2);
<a name="l00089"></a>00089   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ad8b7b38c78851f5724f8e2095d850271">calibration_units</a>, buf+158, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ab8b4fa825fdb60803fe60d53cffa8e74">compression_code</a>, buf+160, 2);
<a name="l00090"></a>00090   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a16c7a2c3d3e98b2c0cef829e6bc00290">acquisition_type</a>, buf+350, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a49caf11d85e6fef4eb039276ecf64256">bed_type</a>, buf+352, 2);
<a name="l00091"></a>00091   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a79a415479a0c09dfb06d3245f7599f96">septa_type</a>, buf+354, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#aec1a2e31ad9fa2e9d03220565bc3cfa0">num_planes</a>, buf+376, 2);
<a name="l00092"></a>00092   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a01ad1f4be366fb3ad82da61022e9761c">num_frames</a>, buf+378, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a5038021b6504d93e304931a95af64746">num_gates</a>, buf+380, 2);
<a name="l00093"></a>00093   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#ad8cbcc286f61bd37eb2a6f196b88a4bb">num_bed_pos</a>, buf+382, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a13f45bc9caa001d28019f421ca46a52d">lwr_sctr_thres</a>, buf+452, 2);
<a name="l00094"></a>00094   memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a685b532f86091f57191edb6c0ba8da53">lwr_true_thres</a>, buf+454, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__mainheader.html#a101df6a9ca3509b5e1f7d0518c383fb7">upr_true_thres</a>, buf+456, 2);
<a name="l00095"></a>00095   memcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#a9413616e9b11fcd27160252e93b7395b">fill2</a>, buf+472, 40);
<a name="l00096"></a>00096   <span class="comment">/* Change back the byte order */</span>
<a name="l00097"></a>00097   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00098"></a>00098 
<a name="l00099"></a>00099   <span class="comment">/* Copy floats */</span>
<a name="l00100"></a>00100   h-&gt;<a class="code" href="structecat63__mainheader.html#aa80e2c3fda2047135338e9525b48fb17">isotope_halflife</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+86, vaxdata, little);
<a name="l00101"></a>00101   h-&gt;<a class="code" href="structecat63__mainheader.html#a38e8f748203bf3de942564a0d3aab35a">gantry_tilt</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+122, vaxdata, little);
<a name="l00102"></a>00102   h-&gt;<a class="code" href="structecat63__mainheader.html#a32ea34339fa4cc9512ef5b2f7ce46827">gantry_rotation</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+126, vaxdata, little);
<a name="l00103"></a>00103   h-&gt;<a class="code" href="structecat63__mainheader.html#a6de93fb04de87b775340ee78426e2df2">bed_elevation</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+130, vaxdata, little);
<a name="l00104"></a>00104   h-&gt;<a class="code" href="structecat63__mainheader.html#acfb971c6cfaffd74900fb23da894bef2">axial_fov</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+140, vaxdata, little);
<a name="l00105"></a>00105   h-&gt;<a class="code" href="structecat63__mainheader.html#a3545e9b7344313ca3f5c0e9f817d1fc4">transaxial_fov</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+144, vaxdata, little);
<a name="l00106"></a>00106   h-&gt;<a class="code" href="structecat63__mainheader.html#ab8dd149fc8b61f8ccd115799e419f7e1">calibration_factor</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+154, vaxdata, little);
<a name="l00107"></a>00107   h-&gt;<a class="code" href="structecat63__mainheader.html#a918cf8249e510ed1ea646eb2950f8917">init_bed_position</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+384, vaxdata, little);
<a name="l00108"></a>00108   <span class="keywordflow">for</span>(i=0; i&lt;15; i++) h-&gt;<a class="code" href="structecat63__mainheader.html#a42922815c9a98cfa855ccca6414607a8">bed_offset</a>[i]=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+388+i*4, vaxdata, little);
<a name="l00109"></a>00109   h-&gt;<a class="code" href="structecat63__mainheader.html#afa9b56b592ebcc6a0c8a499c7b74562a">plane_separation</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+448, vaxdata, little);
<a name="l00110"></a>00110   h-&gt;<a class="code" href="structecat63__mainheader.html#aa6dabd51cbb7ff438d8119618e5d2cc3">collimator</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+458, vaxdata, little);
<a name="l00111"></a>00111 
<a name="l00112"></a>00112   <span class="comment">/* Check file format and platform */</span>
<a name="l00113"></a>00113   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat_format=&#39;%.14s&#39;\n&quot;</span>, h-&gt;<a class="code" href="structecat63__mainheader.html#abf166690e9be3bc9536dc0304292bd1f">ecat_format</a>);
<a name="l00114"></a>00114   <span class="comment">/* if format is not specified, ECAT63 is assumed */</span>
<a name="l00115"></a>00115   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__mainheader.html#abf166690e9be3bc9536dc0304292bd1f">ecat_format</a>[0]==(<span class="keywordtype">char</span>)0) {
<a name="l00116"></a>00116     strcpy(h-&gt;<a class="code" href="structecat63__mainheader.html#abf166690e9be3bc9536dc0304292bd1f">ecat_format</a>, <span class="stringliteral">&quot;ECAT63&quot;</span>);
<a name="l00117"></a>00117   }
<a name="l00118"></a>00118   <span class="comment">/* only ECAT63 format is approved here */</span>
<a name="l00119"></a>00119   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat_format=&#39;%.14s&#39;\n&quot;</span>, h-&gt;<a class="code" href="structecat63__mainheader.html#abf166690e9be3bc9536dc0304292bd1f">ecat_format</a>);
<a name="l00120"></a>00120   <span class="keywordflow">if</span>(strncmp(h-&gt;<a class="code" href="structecat63__mainheader.html#abf166690e9be3bc9536dc0304292bd1f">ecat_format</a>, <span class="stringliteral">&quot;ECAT63&quot;</span>, 6)!=0) <span class="keywordflow">return</span>(3);
<a name="l00121"></a>00121 
<a name="l00122"></a>00122   <span class="comment">/* Check that most important contents are ok */</span>
<a name="l00123"></a>00123   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>&lt;<a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a> || h-&gt;<a class="code" href="structecat63__mainheader.html#a727d6abe8019b32f33965c76ca19a9ee">data_type</a>&gt;<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00124"></a>00124     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid data types; probable conversion error.\n&quot;</span>);
<a name="l00125"></a>00125     <span class="keywordflow">return</span>(5);
<a name="l00126"></a>00126   }
<a name="l00127"></a>00127   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__mainheader.html#ab8dd149fc8b61f8ccd115799e419f7e1">calibration_factor</a>&lt;0.0 || h-&gt;<a class="code" href="structecat63__mainheader.html#ab8dd149fc8b61f8ccd115799e419f7e1">calibration_factor</a>&gt;1.0e12) {
<a name="l00128"></a>00128     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid calibration factor; possible conversion error.\n&quot;</span>);
<a name="l00129"></a>00129     <span class="keywordflow">return</span>(6);
<a name="l00130"></a>00130   }
<a name="l00131"></a>00131   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__mainheader.html#aeb7fd4a6b107a810dcff5d82b6f58440">file_type</a>!=<a class="code" href="ecat63_8h.html#a7140d943b6f40ad3c4bdab5a2073c2f6">RAW_DATA</a> &amp;&amp; h-&gt;<a class="code" href="structecat63__mainheader.html#aeb7fd4a6b107a810dcff5d82b6f58440">file_type</a>!=<a class="code" href="ecat63_8h.html#aaf5f1adfda44941c4bf4de3e71219e4a">IMAGE_DATA</a> &amp;&amp;
<a name="l00132"></a>00132      h-&gt;<a class="code" href="structecat63__mainheader.html#aeb7fd4a6b107a810dcff5d82b6f58440">file_type</a>!=<a class="code" href="ecat63_8h.html#a23271440af335f92b16c81abdff7818a">ATTN_DATA</a> &amp;&amp; h-&gt;<a class="code" href="structecat63__mainheader.html#aeb7fd4a6b107a810dcff5d82b6f58440">file_type</a>!=<a class="code" href="ecat63_8h.html#a978e691d4d6416577705c5c654096e02">NORM_DATA</a>) {
<a name="l00133"></a>00133     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid file types; probable conversion error.\n&quot;</span>);
<a name="l00134"></a>00134     <span class="keywordflow">return</span>(7);
<a name="l00135"></a>00135   }
<a name="l00136"></a>00136 
<a name="l00137"></a>00137   <span class="keywordflow">return</span>(0);
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 <span class="comment">/*****************************************************************************/</span>
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 <span class="comment">/*****************************************************************************/</span>
<a name="l00152"></a><a class="code" href="ecat63_8h.html#adc36293804c18dd15771c61500841b7c">00152</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#adc36293804c18dd15771c61500841b7c">ecat63ReadImageheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat63__imageheader.html">ECAT63_imageheader</a> *h) {
<a name="l00153"></a>00153   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00154"></a>00154   <span class="keywordtype">int</span> i;
<a name="l00155"></a>00155   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00156"></a>00156   <span class="keywordtype">int</span> vaxdata=1; <span class="comment">/* 1 if data is in VAX format, else 0 */</span>
<a name="l00157"></a>00157 
<a name="l00158"></a>00158   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadImageheader(fp, %d ih)\n&quot;</span>, blk);
<a name="l00159"></a>00159   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00160"></a>00160   little=little_endian();
<a name="l00161"></a>00161   <span class="comment">/* Seek the subheader block */</span>
<a name="l00162"></a>00162   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00163"></a>00163   <span class="comment">/* Read the subheader block */</span>
<a name="l00164"></a>00164   <span class="keywordflow">if</span>(fread(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, 1, fp)&lt;1) <span class="keywordflow">return</span>(3);
<a name="l00165"></a>00165 
<a name="l00166"></a>00166   <span class="comment">/* Copy char data to header structure */</span>
<a name="l00167"></a>00167   memcpy(h-&gt;<a class="code" href="structecat63__imageheader.html#aa86c76e6040ffa3c46ef183a81e77644">fill1</a>, buf+0, 126); memcpy(h-&gt;<a class="code" href="structecat63__imageheader.html#a773755a2de4e065ae28f0d52f6de101d">annotation</a>, buf+420, 40);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169   <span class="comment">/* Copy short ints */</span>
<a name="l00170"></a>00170   <span class="comment">/* in big endian platform, change byte order temporarily */</span>
<a name="l00171"></a>00171   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00172"></a>00172   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>, buf+126, 2); <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>&gt;4) vaxdata=0;
<a name="l00173"></a>00173   <span class="comment">/*printf(&quot;data_type=%d\n&quot;, h-&gt;data_type);*/</span>
<a name="l00174"></a>00174   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a417f483d23efabd675ed72cdd4bbdb98">num_dimensions</a>, buf+128, 2);
<a name="l00175"></a>00175   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a86aae28e4de4b65fa5de745aab0bf082">dimension_1</a>, buf+132, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ad53dbc60f5f5a34b7327abbf0d609d5d">dimension_2</a>, buf+134, 2);
<a name="l00176"></a>00176   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ad9ae22f6f465f3872ad5dbc66f0a171b">image_min</a>, buf+176, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a7020d45c4b35dd0c72ce4b87028ed9b9">image_max</a>, buf+178, 2);
<a name="l00177"></a>00177   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ab2ad7047109098114baaf68ae96f785a">slice_location</a>, buf+200, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#add9fadfc6afa697b50b6a84e360cf71c">recon_start_hour</a>, buf+202, 2);
<a name="l00178"></a>00178   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aefab8b0646f7233d6c7f08a0328a984e">recon_start_min</a>, buf+204, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ae69b914674635a9da4c600e78703051e">recon_start_sec</a>, buf+206, 2);
<a name="l00179"></a>00179   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#adcb3ed305ba54f4b8a9a741c3d6057d5">filter_code</a>, buf+236, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#ad88958ba21580417790fc9c23b00c201">processing_code</a>, buf+376, 2);
<a name="l00180"></a>00180   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a38136ac931d35627e8644ccc71d97aec">quant_units</a>, buf+380, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a0f9df554b4dd1694ae38c207efcec372">recon_start_day</a>, buf+382, 2);
<a name="l00181"></a>00181   memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#a88c4c57b18c0350780971f7be380752a">recon_start_month</a>, buf+384, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__imageheader.html#aee97d9526938759b161038f6e8252a75">recon_start_year</a>, buf+386, 2);
<a name="l00182"></a>00182   memcpy(h-&gt;<a class="code" href="structecat63__imageheader.html#a6c2f1300a3551d37dd81b91d9b625839">fill2</a>, buf+460, 52);
<a name="l00183"></a>00183   <span class="comment">/* Change back the byte order */</span>
<a name="l00184"></a>00184   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00185"></a>00185 
<a name="l00186"></a>00186   <span class="comment">/* Copy ints */</span>
<a name="l00187"></a>00187   h-&gt;<a class="code" href="structecat63__imageheader.html#ae4fba67f8fb4e7f72f4d74b215b39058">frame_duration</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+192, vaxdata, little);
<a name="l00188"></a>00188   h-&gt;<a class="code" href="structecat63__imageheader.html#a14bdbc2c5ce62d9ed0c57514b02f8f0e">frame_start_time</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+196, vaxdata, little);
<a name="l00189"></a>00189   h-&gt;<a class="code" href="structecat63__imageheader.html#ab42dbd148db808e27572485fde3d7206">recon_duration</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+208, vaxdata, little);
<a name="l00190"></a>00190   h-&gt;<a class="code" href="structecat63__imageheader.html#a759c941e68c9518ac37e09e03701c168">scan_matrix_num</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+238, vaxdata, little);
<a name="l00191"></a>00191   h-&gt;<a class="code" href="structecat63__imageheader.html#a6e6757740c620b06c0c9d2ab8fcae00f">norm_matrix_num</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+242, vaxdata, little);
<a name="l00192"></a>00192   h-&gt;<a class="code" href="structecat63__imageheader.html#aae892e831603ccf3a4308f9dc36d4859">atten_cor_mat_num</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+246, vaxdata, little);
<a name="l00193"></a>00193 
<a name="l00194"></a>00194   <span class="comment">/* Copy floats */</span>
<a name="l00195"></a>00195   h-&gt;<a class="code" href="structecat63__imageheader.html#a9fea37402b9dfb18edbaba6b2afd3bab">x_origin</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+160, vaxdata, little);
<a name="l00196"></a>00196   h-&gt;<a class="code" href="structecat63__imageheader.html#a0ffe63c2a805cb90643870800e01b1ff">y_origin</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+164, vaxdata, little);
<a name="l00197"></a>00197   h-&gt;<a class="code" href="structecat63__imageheader.html#a9a0fd8c173273797330c7c67effdffd6">recon_scale</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+168, vaxdata, little);
<a name="l00198"></a>00198   h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+172, vaxdata, little);
<a name="l00199"></a>00199   h-&gt;<a class="code" href="structecat63__imageheader.html#a749a7dfb6443194317be2260fc7b5b7b">pixel_size</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+184, vaxdata, little);
<a name="l00200"></a>00200   h-&gt;<a class="code" href="structecat63__imageheader.html#ac2b4f461866cfcbe8bf33939d461becc">slice_width</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+188, vaxdata, little);
<a name="l00201"></a>00201   h-&gt;<a class="code" href="structecat63__imageheader.html#a74e01096c6d9daad3aabf5eaa50dd7a1">image_rotation</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+296, vaxdata, little);
<a name="l00202"></a>00202   h-&gt;<a class="code" href="structecat63__imageheader.html#a7c53b9df3c138cf5b9d5b2986d003377">plane_eff_corr_fctr</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+300, vaxdata, little);
<a name="l00203"></a>00203   h-&gt;<a class="code" href="structecat63__imageheader.html#a46ec10bffd9ad4bd54271b68022bd41c">decay_corr_fctr</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+304, vaxdata, little);
<a name="l00204"></a>00204   h-&gt;<a class="code" href="structecat63__imageheader.html#ab7fe2e08a8afa0b40c4fb9cf5a434ac1">loss_corr_fctr</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+308, vaxdata, little);
<a name="l00205"></a>00205   h-&gt;<a class="code" href="structecat63__imageheader.html#aeb7e92ca7928577171eb2649879f0ea6">intrinsic_tilt</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+312, vaxdata, little);
<a name="l00206"></a>00206   h-&gt;<a class="code" href="structecat63__imageheader.html#aa50b6a76225241de1056e26de450fb1c">ecat_calibration_fctr</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+388, vaxdata, little);
<a name="l00207"></a>00207   h-&gt;<a class="code" href="structecat63__imageheader.html#a6338eb4b7fdcb624ac0673260d16db42">well_counter_cal_fctr</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+392, vaxdata, little);
<a name="l00208"></a>00208   <span class="keywordflow">for</span>(i=0; i&lt;6; i++) h-&gt;<a class="code" href="structecat63__imageheader.html#af215d79c43ac183c8d871f4cae77719b">filter_params</a>[i]=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+396+i*4, vaxdata, little);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210   <span class="comment">/* Check that most important contents are ok */</span>
<a name="l00211"></a>00211   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>&lt;<a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a> || h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>&gt;<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00212"></a>00212     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid data types; probable conversion error.\n&quot;</span>);
<a name="l00213"></a>00213     <span class="keywordflow">return</span>(4);
<a name="l00214"></a>00214   }
<a name="l00215"></a>00215   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#aa50b6a76225241de1056e26de450fb1c">ecat_calibration_fctr</a>&lt;0.0 || h-&gt;<a class="code" href="structecat63__imageheader.html#aa50b6a76225241de1056e26de450fb1c">ecat_calibration_fctr</a>&gt;1.0e10) {
<a name="l00216"></a>00216     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid calibration factor; probable conversion error.\n&quot;</span>);
<a name="l00217"></a>00217     <span class="keywordflow">return</span>(5);
<a name="l00218"></a>00218   }
<a name="l00219"></a>00219   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#ae4fba67f8fb4e7f72f4d74b215b39058">frame_duration</a>&lt;0.0 || h-&gt;<a class="code" href="structecat63__imageheader.html#ae4fba67f8fb4e7f72f4d74b215b39058">frame_duration</a>&gt;1.0e12) {
<a name="l00220"></a>00220     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid frame duration; probable conversion error.\n&quot;</span>);
<a name="l00221"></a>00221     <span class="keywordflow">return</span>(6);
<a name="l00222"></a>00222   }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224   <span class="keywordflow">return</span>(0);
<a name="l00225"></a>00225 }
<a name="l00226"></a>00226 <span class="comment">/*****************************************************************************/</span>
<a name="l00227"></a>00227 
<a name="l00228"></a>00228 <span class="comment">/*****************************************************************************/</span>
<a name="l00238"></a><a class="code" href="ecat63_8h.html#ac9c08bd1e03ddc4f4a8c83a5ea198e05">00238</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#ac9c08bd1e03ddc4f4a8c83a5ea198e05">ecat63ReadAttnheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat63__attnheader.html">ECAT63_attnheader</a> *h) {
<a name="l00239"></a>00239   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00240"></a>00240   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00241"></a>00241   <span class="keywordtype">int</span> vaxdata=1; <span class="comment">/* 1 if data is in VAX format, else 0 */</span>
<a name="l00242"></a>00242 
<a name="l00243"></a>00243   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadAttnheader(fp, %d, ah)\n&quot;</span>, blk);
<a name="l00244"></a>00244   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00245"></a>00245   little=little_endian();
<a name="l00246"></a>00246   <span class="comment">/* Seek the subheader block */</span>
<a name="l00247"></a>00247   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00248"></a>00248   <span class="comment">/* Read the subheader block */</span>
<a name="l00249"></a>00249   <span class="keywordflow">if</span>(fread(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, 1, fp)&lt;1) <span class="keywordflow">return</span>(3);
<a name="l00250"></a>00250 
<a name="l00251"></a>00251   <span class="comment">/* Copy short ints */</span>
<a name="l00252"></a>00252   <span class="comment">/* in big endian platform, change byte order temporarily */</span>
<a name="l00253"></a>00253   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00254"></a>00254   memcpy(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>, buf+126, 2); <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>&gt;4) vaxdata=0;
<a name="l00255"></a>00255   <span class="comment">/*printf(&quot;data_type=%d\n&quot;, h-&gt;data_type);*/</span>
<a name="l00256"></a>00256   memcpy(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#afddf2ebc3902db6517580be3dfbe8d5e">attenuation_type</a>, buf+128, 2);
<a name="l00257"></a>00257   memcpy(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#acbea9636493630fc7bdc3de4fcd4cfa2">dimension_1</a>, buf+132, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__attnheader.html#af9fa1e4491aa3321b4ce99f54e5ebb6e">dimension_2</a>, buf+134, 2);
<a name="l00258"></a>00258   <span class="comment">/* Change back the byte order */</span>
<a name="l00259"></a>00259   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00260"></a>00260 
<a name="l00261"></a>00261   <span class="comment">/* Copy floats */</span>
<a name="l00262"></a>00262   h-&gt;<a class="code" href="structecat63__attnheader.html#a649891350c3b30214f43ca2d640a0e47">scale_factor</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+182, vaxdata, little);
<a name="l00263"></a>00263   h-&gt;<a class="code" href="structecat63__attnheader.html#a392054bdf86e477fa5cf6da7cca40ce5">x_origin</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+186, vaxdata, little);
<a name="l00264"></a>00264   h-&gt;<a class="code" href="structecat63__attnheader.html#a625b116f6858b728a3a83d9312c914d2">y_origin</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+190, vaxdata, little);
<a name="l00265"></a>00265   h-&gt;<a class="code" href="structecat63__attnheader.html#a525063ffc32765f26d039e3bcba1996c">x_radius</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+194, vaxdata, little);
<a name="l00266"></a>00266   h-&gt;<a class="code" href="structecat63__attnheader.html#ab85f3c502080d57c3b01db2a4ff17096">y_radius</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+198, vaxdata, little);
<a name="l00267"></a>00267   h-&gt;<a class="code" href="structecat63__attnheader.html#a28abaa374db45b1b6be743117cd269eb">tilt_angle</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+202, vaxdata, little);
<a name="l00268"></a>00268   h-&gt;<a class="code" href="structecat63__attnheader.html#a2cb849370c0300e6e88f8668cfae4bce">attenuation_coeff</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+206, vaxdata, little);
<a name="l00269"></a>00269   h-&gt;<a class="code" href="structecat63__attnheader.html#a8637550d8495fed5a5f5e59701f8d428">sample_distance</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+210, vaxdata, little);
<a name="l00270"></a>00270 
<a name="l00271"></a>00271   <span class="comment">/* Check that most important contents are ok */</span>
<a name="l00272"></a>00272   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>&lt;<a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a> || h-&gt;<a class="code" href="structecat63__attnheader.html#ac5bea9d6b3dae0b4c87d5e66a0d2006e">data_type</a>&gt;<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00273"></a>00273     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid data types; probable conversion error.\n&quot;</span>);
<a name="l00274"></a>00274     <span class="keywordflow">return</span>(4);
<a name="l00275"></a>00275   }
<a name="l00276"></a>00276   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__attnheader.html#a649891350c3b30214f43ca2d640a0e47">scale_factor</a>&lt;=0.0 || h-&gt;<a class="code" href="structecat63__attnheader.html#a649891350c3b30214f43ca2d640a0e47">scale_factor</a>&gt;1.0e8) {
<a name="l00277"></a>00277     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid scale factor; probable conversion error.\n&quot;</span>);
<a name="l00278"></a>00278     <span class="keywordflow">return</span>(5);
<a name="l00279"></a>00279   }
<a name="l00280"></a>00280 
<a name="l00281"></a>00281   <span class="keywordflow">return</span>(0);
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 <span class="comment">/*****************************************************************************/</span>
<a name="l00284"></a>00284 
<a name="l00285"></a>00285 <span class="comment">/*****************************************************************************/</span>
<a name="l00296"></a><a class="code" href="ecat63_8h.html#a811c9c52c52f1c749ee6cb0f7a51f884">00296</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#a811c9c52c52f1c749ee6cb0f7a51f884">ecat63ReadScanheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat63__scanheader.html">ECAT63_scanheader</a> *h) {
<a name="l00297"></a>00297   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00298"></a>00298   <span class="keywordtype">int</span> i;
<a name="l00299"></a>00299   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00300"></a>00300   <span class="keywordtype">int</span> vaxdata=1; <span class="comment">/* 1 if data is in VAX format, else 0 */</span>
<a name="l00301"></a>00301 
<a name="l00302"></a>00302   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadScanheader(fp, %d, sh)\n&quot;</span>, blk);
<a name="l00303"></a>00303   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00304"></a>00304   little=little_endian();
<a name="l00305"></a>00305   <span class="comment">/* Seek the subheader block */</span>
<a name="l00306"></a>00306   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00307"></a>00307   <span class="comment">/* Read the subheader block */</span>
<a name="l00308"></a>00308   <span class="keywordflow">if</span>(fread(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, 1, fp)&lt;1) <span class="keywordflow">return</span>(3);
<a name="l00309"></a>00309 
<a name="l00310"></a>00310   <span class="comment">/* Copy char data to header structure */</span>
<a name="l00311"></a>00311   memcpy(h-&gt;<a class="code" href="structecat63__scanheader.html#aed0424fc176e0af33fe14ed05eb4d11e">fill1</a>, buf+0, 126);
<a name="l00312"></a>00312 
<a name="l00313"></a>00313   <span class="comment">/* Copy short ints */</span>
<a name="l00314"></a>00314   <span class="comment">/* in big endian platform, change byte order temporarily */</span>
<a name="l00315"></a>00315   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00316"></a>00316   memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>, buf+126, 2); <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>&gt;4) vaxdata=0;
<a name="l00317"></a>00317   <span class="comment">/*printf(&quot;data_type=%d\n&quot;, h-&gt;data_type);*/</span>
<a name="l00318"></a>00318   memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#adee5ad20def49d6f13da7efde9da4e3e">dimension_1</a>, buf+132, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a87c12560397fa7408d95ad30d1800f92">dimension_2</a>, buf+134, 2);
<a name="l00319"></a>00319   memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#aedadbe34a589d483a34936e17e416131">smoothing</a>, buf+136, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a639b2f86794956dbb694ec5eb072e85b">processing_code</a>, buf+138, 2);
<a name="l00320"></a>00320   memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#aaf23846f5c3ee43188d49fac0f592498">frame_duration_sec</a>, buf+170, 2);
<a name="l00321"></a>00321   memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#abeeb6fea3c31b83464be7afcdff37219">scan_min</a>, buf+192, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__scanheader.html#a87fc09622afe7e2372588f650e7e6afd">scan_max</a>, buf+194, 2);
<a name="l00322"></a>00322   memcpy(h-&gt;<a class="code" href="structecat63__scanheader.html#a27cb56a4d012e3bf4bbd0f53aaf39183">fill2</a>, buf+468, 44);
<a name="l00323"></a>00323   <span class="comment">/* Change back the byte order */</span>
<a name="l00324"></a>00324   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00325"></a>00325 
<a name="l00326"></a>00326   <span class="comment">/* Copy ints */</span>
<a name="l00327"></a>00327   h-&gt;<a class="code" href="structecat63__scanheader.html#abf1ed74916f2296dbdc73246f0ac7e26">gate_duration</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+172, vaxdata, little);
<a name="l00328"></a>00328   h-&gt;<a class="code" href="structecat63__scanheader.html#a7507738b6d21d0b5145bc66e0baefcd1">r_wave_offset</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+176, vaxdata, little);
<a name="l00329"></a>00329   h-&gt;<a class="code" href="structecat63__scanheader.html#a28b007d345ada719bb886fd7a2683d76">prompts</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+196, vaxdata, little);
<a name="l00330"></a>00330   h-&gt;<a class="code" href="structecat63__scanheader.html#ad0a2468779aec56e8d45ca685834eb16">delayed</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+200, vaxdata, little);
<a name="l00331"></a>00331   h-&gt;<a class="code" href="structecat63__scanheader.html#a8100b3eed008502c7817e0b629de155e">multiples</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+204, vaxdata, little);
<a name="l00332"></a>00332   h-&gt;<a class="code" href="structecat63__scanheader.html#a8acda07cbdfaba46a41cdb735e6ff222">net_trues</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+208, vaxdata, little);
<a name="l00333"></a>00333   h-&gt;<a class="code" href="structecat63__scanheader.html#ada524bc7b4273bd533cc1a1071fb71f0">total_coin_rate</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+452, vaxdata, little);
<a name="l00334"></a>00334   h-&gt;<a class="code" href="structecat63__scanheader.html#aa7214f91108a9d7a5bec6f0edbe3493d">frame_start_time</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+456, vaxdata, little);
<a name="l00335"></a>00335   h-&gt;<a class="code" href="structecat63__scanheader.html#a253426410960e4047acfb591c24e179b">frame_duration</a>=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(buf+460, vaxdata, little);
<a name="l00336"></a>00336 
<a name="l00337"></a>00337   <span class="comment">/* Copy floats */</span>
<a name="l00338"></a>00338   h-&gt;<a class="code" href="structecat63__scanheader.html#acb676ed22b052fbaa07bd044263ac279">sample_distance</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+146, vaxdata, little);
<a name="l00339"></a>00339   h-&gt;<a class="code" href="structecat63__scanheader.html#a3310fbd6ef8bb0062d44b8dcb0315726">isotope_halflife</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+166, vaxdata, little);
<a name="l00340"></a>00340   h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+182, vaxdata, little);
<a name="l00341"></a>00341   <span class="keywordflow">for</span>(i=0; i&lt;16; i++) h-&gt;<a class="code" href="structecat63__scanheader.html#a0620862723c58710a4510ffcb184f4cd">cor_singles</a>[i]=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+316+i*4, vaxdata, little);
<a name="l00342"></a>00342   <span class="keywordflow">for</span>(i=0; i&lt;16; i++) h-&gt;<a class="code" href="structecat63__scanheader.html#a1ccfde8610fb4974ce32c3dd6f252480">uncor_singles</a>[i]=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+380+i*4, vaxdata, little);
<a name="l00343"></a>00343   h-&gt;<a class="code" href="structecat63__scanheader.html#afcbe607c1cd9a432f6aac5dabc9a77ea">tot_avg_cor</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+444, vaxdata, little);
<a name="l00344"></a>00344   h-&gt;<a class="code" href="structecat63__scanheader.html#af8563b96c975f59dec8ff89fe4ce46b4">tot_avg_uncor</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+448, vaxdata, little);
<a name="l00345"></a>00345   h-&gt;<a class="code" href="structecat63__scanheader.html#a3077aca1fa9f9b64c57f4b6eb19780fb">loss_correction_fctr</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+464, vaxdata, little);
<a name="l00346"></a>00346 
<a name="l00347"></a>00347   <span class="comment">/* Check that most important contents are ok */</span>
<a name="l00348"></a>00348   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>&lt;<a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a> || h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>&gt;<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00349"></a>00349     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid data types; probable conversion error.\n&quot;</span>);
<a name="l00350"></a>00350     <span class="keywordflow">return</span>(4);
<a name="l00351"></a>00351   }
<a name="l00352"></a>00352   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>&lt;=0.0 || h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>&gt;1.0e8) {
<a name="l00353"></a>00353     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid scale factor; probable conversion error.\n&quot;</span>);
<a name="l00354"></a>00354     <span class="keywordflow">return</span>(5);
<a name="l00355"></a>00355   }
<a name="l00356"></a>00356   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__scanheader.html#a253426410960e4047acfb591c24e179b">frame_duration</a>&lt;0.0 || h-&gt;<a class="code" href="structecat63__scanheader.html#a253426410960e4047acfb591c24e179b">frame_duration</a>&gt;1.0e12) {
<a name="l00357"></a>00357     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid frame duration; probable conversion error.\n&quot;</span>);
<a name="l00358"></a>00358     <span class="keywordflow">return</span>(6);
<a name="l00359"></a>00359   }
<a name="l00360"></a>00360 
<a name="l00361"></a>00361   <span class="keywordflow">return</span>(0);
<a name="l00362"></a>00362 }
<a name="l00363"></a>00363 <span class="comment">/*****************************************************************************/</span>
<a name="l00364"></a>00364 
<a name="l00365"></a>00365 <span class="comment">/*****************************************************************************/</span>
<a name="l00375"></a><a class="code" href="ecat63_8h.html#a6a169297491f0f8a734247467cfb2b89">00375</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#a6a169297491f0f8a734247467cfb2b89">ecat63ReadNormheader</a>(FILE *fp, <span class="keywordtype">int</span> blk, <a class="code" href="structecat63__normheader.html">ECAT63_normheader</a> *h) {
<a name="l00376"></a>00376   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>];
<a name="l00377"></a>00377   <span class="keywordtype">int</span> little; <span class="comment">/* 1 if current platform is little endian (i386), else 0 */</span>
<a name="l00378"></a>00378   <span class="keywordtype">int</span> vaxdata=1; <span class="comment">/* 1 if data is in VAX format, else 0 */</span>
<a name="l00379"></a>00379 
<a name="l00380"></a>00380   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadNormheader(fp, %d, nh)\n&quot;</span>, blk);
<a name="l00381"></a>00381   <span class="keywordflow">if</span>(fp==NULL || blk&lt;2 || h==NULL) <span class="keywordflow">return</span>(1);
<a name="l00382"></a>00382   little=little_endian();
<a name="l00383"></a>00383   <span class="comment">/* Seek the subheader block */</span>
<a name="l00384"></a>00384   fseek(fp, (blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET); <span class="keywordflow">if</span>(ftell(fp)!=(blk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(2);
<a name="l00385"></a>00385   <span class="comment">/* Read the subheader block */</span>
<a name="l00386"></a>00386   <span class="keywordflow">if</span>(fread(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, 1, fp)&lt;1) <span class="keywordflow">return</span>(3);
<a name="l00387"></a>00387 
<a name="l00388"></a>00388   <span class="comment">/* Copy short ints */</span>
<a name="l00389"></a>00389   <span class="comment">/* in big endian platform, change byte order temporarily */</span>
<a name="l00390"></a>00390   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00391"></a>00391   memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>, buf+126, 2); <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>&gt;4) vaxdata=0;
<a name="l00392"></a>00392   <span class="comment">/*printf(&quot;data_type=%d\n&quot;, h-&gt;data_type);*/</span>
<a name="l00393"></a>00393   memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a546d6d89d6df87d2de51c1588884d5b5">dimension_1</a>, buf+132, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#aa49aa059f33fad5d960b044da8076fe7">dimension_2</a>, buf+134, 2);
<a name="l00394"></a>00394   memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a89973101e53a28f7ea189da834d833f5">norm_hour</a>, buf+186, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#aa23c1f37bfc67d61ac6c23ad47e0ef3f">norm_minute</a>, buf+188, 2);
<a name="l00395"></a>00395   memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a3b5598a2aec2cf470d28704984ba8abe">norm_second</a>, buf+190, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#af2594e900754a91cfd91ae9c0abb4189">norm_day</a>, buf+192, 2);
<a name="l00396"></a>00396   memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a07ca626ae6c4ccebc0259e4938b788a6">norm_month</a>, buf+194, 2); memcpy(&amp;h-&gt;<a class="code" href="structecat63__normheader.html#a50b35e9ff630f374ff9699073a40f118">norm_year</a>, buf+196, 2);
<a name="l00397"></a>00397   <span class="comment">/* Change back the byte order */</span>
<a name="l00398"></a>00398   <span class="keywordflow">if</span>(!little) swabip(buf, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00399"></a>00399 
<a name="l00400"></a>00400   <span class="comment">/* Copy floats */</span>
<a name="l00401"></a>00401   h-&gt;<a class="code" href="structecat63__normheader.html#a914977ee68c14326a4551abae57fc9ab">scale_factor</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+182, vaxdata, little);
<a name="l00402"></a>00402   h-&gt;<a class="code" href="structecat63__normheader.html#a7b68dc00c4466d354e5caec905af190b">fov_source_width</a>=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(buf+198, vaxdata, little);
<a name="l00403"></a>00403 
<a name="l00404"></a>00404   <span class="comment">/* Check that most important contents are ok */</span>
<a name="l00405"></a>00405   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>&lt;<a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a> &amp;&amp; h-&gt;<a class="code" href="structecat63__normheader.html#ae7d4136070d36e9edbe684a80e39b942">data_type</a>&gt;<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00406"></a>00406     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid data types; probable conversion error.\n&quot;</span>);
<a name="l00407"></a>00407     <span class="keywordflow">return</span>(4);
<a name="l00408"></a>00408   }
<a name="l00409"></a>00409   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__normheader.html#a914977ee68c14326a4551abae57fc9ab">scale_factor</a>&lt;=0.0 || h-&gt;<a class="code" href="structecat63__normheader.html#a914977ee68c14326a4551abae57fc9ab">scale_factor</a>&gt;1.0e8) {
<a name="l00410"></a>00410     <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;Invalid scale factor; probable conversion error.\n&quot;</span>);
<a name="l00411"></a>00411     <span class="keywordflow">return</span>(5);
<a name="l00412"></a>00412   }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414   <span class="keywordflow">return</span>(0);
<a name="l00415"></a>00415 }
<a name="l00416"></a>00416 <span class="comment">/*****************************************************************************/</span>
<a name="l00417"></a>00417 
<a name="l00418"></a>00418 <span class="comment">/*****************************************************************************/</span>
<a name="l00432"></a><a class="code" href="ecat63_8h.html#a7f3456ddf0f774026d462df66bf1210b">00432</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#a7f3456ddf0f774026d462df66bf1210b">ecat63ReadMatdata</a>(FILE *fp, <span class="keywordtype">int</span> strtblk, <span class="keywordtype">int</span> blkNr, <span class="keywordtype">char</span> *data, <span class="keywordtype">int</span> dtype) {
<a name="l00433"></a>00433   <span class="keywordtype">int</span> i, n, little, err=0;
<a name="l00434"></a>00434   <span class="keywordtype">char</span> *cptr;
<a name="l00435"></a>00435   <span class="keywordtype">float</span> f;
<a name="l00436"></a>00436 
<a name="l00437"></a>00437 
<a name="l00438"></a>00438   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadMatdata(fp, %d, %d, data, %d)\n&quot;</span>, strtblk, blkNr, dtype);
<a name="l00439"></a>00439   <span class="comment">/* Check the arguments */</span>
<a name="l00440"></a>00440   <span class="keywordflow">if</span>(blkNr&lt;=0 || strtblk&lt;1 || data==NULL) <span class="keywordflow">return</span>(1);
<a name="l00441"></a>00441   <span class="comment">/* Seek the first data block */</span>
<a name="l00442"></a>00442   fseek(fp, (strtblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, SEEK_SET);
<a name="l00443"></a>00443   <span class="keywordflow">if</span>(ftell(fp)!=(strtblk-1)*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>) <span class="keywordflow">return</span>(9);
<a name="l00444"></a>00444   <span class="comment">/* Read the data blocks */</span>
<a name="l00445"></a>00445   <span class="keywordflow">if</span>(fread(data, <a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>, blkNr, fp) &lt; blkNr) <span class="keywordflow">return</span>(2);
<a name="l00446"></a>00446   <span class="comment">/* Translate data if necessary */</span>
<a name="l00447"></a>00447   little=little_endian();
<a name="l00448"></a>00448   <span class="keywordflow">switch</span>(dtype) {
<a name="l00449"></a>00449     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>: <span class="comment">/* byte format...no translation necessary */</span>
<a name="l00450"></a>00450       <span class="keywordflow">break</span>;
<a name="l00451"></a>00451     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a>:    <span class="comment">/* byte conversion necessary on big endian platform */</span>
<a name="l00452"></a>00452       <span class="keywordflow">if</span>(!little) {cptr=data; swabip(cptr, blkNr*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);}
<a name="l00453"></a>00453       <span class="keywordflow">break</span>;
<a name="l00454"></a>00454     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a>:
<a name="l00455"></a>00455       <span class="keywordflow">for</span>(i=0, cptr=data; i&lt;blkNr*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; i+=4, cptr+=4) {
<a name="l00456"></a>00456         n=<a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(cptr, 1, little); memcpy(cptr, &amp;n, 4);
<a name="l00457"></a>00457       }
<a name="l00458"></a>00458       <span class="keywordflow">break</span>;
<a name="l00459"></a>00459     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>:
<a name="l00460"></a>00460       <span class="keywordflow">for</span>(i=0, cptr=data; i&lt;blkNr*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>; i+=4, cptr+=4) {
<a name="l00461"></a>00461         f=<a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(cptr, 1, little); memcpy(cptr, &amp;f, 4);
<a name="l00462"></a>00462       }
<a name="l00463"></a>00463       <span class="keywordflow">break</span>;
<a name="l00464"></a>00464     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>:   <span class="comment">/* IEEE float ; byte conversion necessary on big end platforms */</span>
<a name="l00465"></a>00465     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>:    <span class="comment">/* SUN int ; byte conversion necessary on big end platforms */</span>
<a name="l00466"></a>00466       <span class="keywordflow">if</span>(!little) swawbip(data, blkNr*MatBLKSIZE);
<a name="l00467"></a>00467       <span class="keywordflow">break</span>;
<a name="l00468"></a>00468     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>:    <span class="comment">/* SUN short ; byte conversion necessary on big end platforms */</span>
<a name="l00469"></a>00469       <span class="keywordflow">if</span>(!little) swabip(data, blkNr*MatBLKSIZE);
<a name="l00470"></a>00470       <span class="keywordflow">break</span>;
<a name="l00471"></a>00471     <span class="keywordflow">default</span>:  <span class="comment">/* if something else, for now think it as an error */</span>
<a name="l00472"></a>00472       err=2;
<a name="l00473"></a>00473       <span class="keywordflow">break</span>;
<a name="l00474"></a>00474   }
<a name="l00475"></a>00475   <span class="keywordflow">return</span>(err);
<a name="l00476"></a>00476 }
<a name="l00477"></a>00477 <span class="comment">/*****************************************************************************/</span>
<a name="l00478"></a>00478 
<a name="l00479"></a>00479 <span class="comment">/*****************************************************************************/</span>
<a name="l00494"></a><a class="code" href="ecat63_8h.html#aa94680e2ed072a3d47a09794b1b82224">00494</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#a5ea48c98c6349c318a1f3dc0c0f84e09">ecat63ReadImageMatrix</a>(FILE *fp, <span class="keywordtype">int</span> first_block, <span class="keywordtype">int</span> last_block, <a class="code" href="structecat63__imageheader.html">ECAT63_imageheader</a> *h, <span class="keywordtype">float</span> **fdata) {
<a name="l00495"></a>00495   <span class="keywordtype">int</span> i, ret, blockNr, pxlNr;
<a name="l00496"></a>00496   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00497"></a>00497   <span class="keywordtype">float</span> *_fdata, *fptr;
<a name="l00498"></a>00498   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00499"></a>00499   <span class="keywordtype">int</span> *iptr;
<a name="l00500"></a>00500   
<a name="l00501"></a>00501   
<a name="l00502"></a>00502   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadImageMatrix(fp, %d, %d, hdr, fdata)\n&quot;</span>,
<a name="l00503"></a>00503     first_block, last_block);
<a name="l00504"></a>00504   <span class="keywordflow">if</span>(fp==NULL || first_block&lt;=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a> || h==NULL) {
<a name="l00505"></a>00505     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00506"></a>00506     <span class="keywordflow">return</span>(1);
<a name="l00507"></a>00507   }
<a name="l00508"></a>00508   *fdata=(<span class="keywordtype">float</span>*)NULL;
<a name="l00509"></a>00509   
<a name="l00510"></a>00510   <span class="comment">/* Read subheader */</span>
<a name="l00511"></a>00511   ret=<a class="code" href="ecat63r_8c.html#adc36293804c18dd15771c61500841b7c">ecat63ReadImageheader</a>(fp, first_block, h);
<a name="l00512"></a>00512   <span class="keywordflow">if</span>(ret) {
<a name="l00513"></a>00513     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot read subheader (%d).\n&quot;</span>, ret);
<a name="l00514"></a>00514     <span class="keywordflow">return</span>(5);
<a name="l00515"></a>00515   }
<a name="l00516"></a>00516   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>&gt;4) <a class="code" href="ecat63p_8c.html#a5f3ba1102f964d98b4de5a93c3d9fd36">ecat63PrintImageheader</a>(h, stdout);
<a name="l00517"></a>00517   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="l00518"></a>00518   <span class="keywordflow">if</span>(pxlNr&lt;=0) {
<a name="l00519"></a>00519     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00520"></a>00520     <span class="keywordflow">return</span>(6);  
<a name="l00521"></a>00521   }
<a name="l00522"></a>00522   
<a name="l00523"></a>00523   <span class="comment">/* Read matrix data */</span>
<a name="l00524"></a>00524   blockNr=last_block-first_block; <span class="keywordflow">if</span>(blockNr&lt;1) <span class="keywordflow">return</span>(0);
<a name="l00525"></a>00525   mdata=(<span class="keywordtype">char</span>*)malloc(blockNr*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00526"></a>00526   <span class="keywordflow">if</span>(mdata==NULL) {
<a name="l00527"></a>00527     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot allocate memory.\n&quot;</span>);
<a name="l00528"></a>00528     <span class="keywordflow">return</span>(8);  
<a name="l00529"></a>00529   }
<a name="l00530"></a>00530   mptr=mdata;
<a name="l00531"></a>00531   ret=<a class="code" href="ecat63r_8c.html#a7f3456ddf0f774026d462df66bf1210b">ecat63ReadMatdata</a>(fp, first_block+1, blockNr, mptr, h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>);
<a name="l00532"></a>00532   <span class="keywordflow">if</span>(ret || mdata==NULL) {
<a name="l00533"></a>00533     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot read matrix data (%d).\n&quot;</span>, ret);
<a name="l00534"></a>00534     free(mdata); <span class="keywordflow">return</span>(9);
<a name="l00535"></a>00535   }
<a name="l00536"></a>00536   
<a name="l00537"></a>00537   <span class="comment">/* Allocate memory for float data */</span>
<a name="l00538"></a>00538   _fdata=(<span class="keywordtype">float</span>*)malloc(pxlNr*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
<a name="l00539"></a>00539   <span class="keywordflow">if</span>(_fdata==NULL) {
<a name="l00540"></a>00540     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot allocate memory.\n&quot;</span>);
<a name="l00541"></a>00541     free(mdata); <span class="keywordflow">return</span>(11);  
<a name="l00542"></a>00542   }
<a name="l00543"></a>00543 
<a name="l00544"></a>00544   <span class="comment">/* Convert matrix data to floats */</span>
<a name="l00545"></a>00545   <span class="keywordflow">if</span>(h-&gt;<a class="code" href="structecat63__imageheader.html#aa50b6a76225241de1056e26de450fb1c">ecat_calibration_fctr</a>&gt;0.0) h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>*=h-&gt;<a class="code" href="structecat63__imageheader.html#aa50b6a76225241de1056e26de450fb1c">ecat_calibration_fctr</a>;
<a name="l00546"></a>00546   fptr=_fdata; mptr=mdata;
<a name="l00547"></a>00547   <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#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>) {
<a name="l00548"></a>00548     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, mptr++, fptr++)
<a name="l00549"></a>00549       *fptr=h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>*(<span class="keywordtype">float</span>)(*mptr);
<a name="l00550"></a>00550   } <span class="keywordflow">else</span> <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#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>) {
<a name="l00551"></a>00551     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, mptr+=2, fptr++) {
<a name="l00552"></a>00552       sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mptr;
<a name="l00553"></a>00553       *fptr=h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>*(float)(*sptr);
<a name="l00554"></a>00554     }
<a name="l00555"></a>00555   } <span class="keywordflow">else</span> <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#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>==<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00556"></a>00556     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, mptr+=4, fptr++) {
<a name="l00557"></a>00557       iptr=(<span class="keywordtype">int</span>*)mptr;
<a name="l00558"></a>00558       *fptr=h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>*(float)(*iptr);
<a name="l00559"></a>00559     }
<a name="l00560"></a>00560   } <span class="keywordflow">else</span> <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#a43d671e0f827418673872adcd63418c4">VAX_R4</a> || h-&gt;<a class="code" href="structecat63__imageheader.html#a00da8baaaefa0ca83e0c12636b298196">data_type</a>==<a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>) {
<a name="l00561"></a>00561     memcpy(fptr, mptr, pxlNr*4);
<a name="l00562"></a>00562     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) *fptr *= h-&gt;<a class="code" href="structecat63__imageheader.html#ac4ff92a4d0a9b55e3647bfb45af9d381">quant_scale</a>;
<a name="l00563"></a>00563   }
<a name="l00564"></a>00564   free(mdata);
<a name="l00565"></a>00565   *fdata=_fdata;
<a name="l00566"></a>00566 
<a name="l00567"></a>00567   <span class="keywordflow">return</span>(0);
<a name="l00568"></a>00568 }
<a name="l00569"></a>00569 <span class="comment">/*****************************************************************************/</span>
<a name="l00570"></a>00570 
<a name="l00571"></a>00571 <span class="comment">/*****************************************************************************/</span>
<a name="l00586"></a><a class="code" href="ecat63_8h.html#ae6dab3a20c27983657ecd94ade915432">00586</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#a800c7269b993f26fdfd62f760133f6d9">ecat63ReadScanMatrix</a>(FILE *fp, <span class="keywordtype">int</span> first_block, <span class="keywordtype">int</span> last_block, <a class="code" href="structecat63__scanheader.html">ECAT63_scanheader</a> *h, <span class="keywordtype">float</span> **fdata) {
<a name="l00587"></a>00587   <span class="keywordtype">int</span> i, ret, blockNr, pxlNr;
<a name="l00588"></a>00588   <span class="keywordtype">char</span> *mdata, *mptr;
<a name="l00589"></a>00589   <span class="keywordtype">float</span> *_fdata, *fptr;
<a name="l00590"></a>00590   <span class="keywordtype">short</span> <span class="keywordtype">int</span> *sptr;
<a name="l00591"></a>00591   <span class="keywordtype">int</span> *iptr;
<a name="l00592"></a>00592   
<a name="l00593"></a>00593   
<a name="l00594"></a>00594   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>) printf(<span class="stringliteral">&quot;ecat63ReadScanMatrix(fp, %d, %d, hdr, fdata)\n&quot;</span>,
<a name="l00595"></a>00595     first_block, last_block);
<a name="l00596"></a>00596   <span class="keywordflow">if</span>(fp==NULL || first_block&lt;=<a class="code" href="ecat63_8h.html#a08ed2cc1d5f72492fb6b4eceb66665ad">MatFirstDirBlk</a> || h==NULL) {
<a name="l00597"></a>00597     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid function parameter.\n&quot;</span>);
<a name="l00598"></a>00598     <span class="keywordflow">return</span>(1);
<a name="l00599"></a>00599   }
<a name="l00600"></a>00600   *fdata=(<span class="keywordtype">float</span>*)NULL;
<a name="l00601"></a>00601   
<a name="l00602"></a>00602   <span class="comment">/* Read subheader */</span>
<a name="l00603"></a>00603   ret=<a class="code" href="ecat63r_8c.html#a811c9c52c52f1c749ee6cb0f7a51f884">ecat63ReadScanheader</a>(fp, first_block, h);
<a name="l00604"></a>00604   <span class="keywordflow">if</span>(ret) {
<a name="l00605"></a>00605     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot read subheader (%d).\n&quot;</span>, ret);
<a name="l00606"></a>00606     <span class="keywordflow">return</span>(5);
<a name="l00607"></a>00607   }
<a name="l00608"></a>00608   <span class="keywordflow">if</span>(<a class="code" href="ecat63_8h.html#a31112b67a89269c5bed48d48ce2957ed">ECAT63_TEST</a>&gt;4) <a class="code" href="ecat63p_8c.html#a67a369196200471d7954b4788de262a6">ecat63PrintScanheader</a>(h, stdout);
<a name="l00609"></a>00609   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="l00610"></a>00610   <span class="keywordflow">if</span>(pxlNr&lt;=0) {
<a name="l00611"></a>00611     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;invalid matrix dimension.\n&quot;</span>);
<a name="l00612"></a>00612     <span class="keywordflow">return</span>(6);  
<a name="l00613"></a>00613   }
<a name="l00614"></a>00614   
<a name="l00615"></a>00615   <span class="comment">/* Read matrix data */</span>
<a name="l00616"></a>00616   blockNr=last_block-first_block; <span class="keywordflow">if</span>(blockNr&lt;1) <span class="keywordflow">return</span>(0);
<a name="l00617"></a>00617   mdata=(<span class="keywordtype">char</span>*)malloc(blockNr*<a class="code" href="ecat63_8h.html#abdf75c7aade8a596594e8e7ce8b16872">MatBLKSIZE</a>);
<a name="l00618"></a>00618   <span class="keywordflow">if</span>(mdata==NULL) {
<a name="l00619"></a>00619     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot allocate memory.\n&quot;</span>);
<a name="l00620"></a>00620     <span class="keywordflow">return</span>(8);  
<a name="l00621"></a>00621   }
<a name="l00622"></a>00622   mptr=mdata;
<a name="l00623"></a>00623   ret=<a class="code" href="ecat63r_8c.html#a7f3456ddf0f774026d462df66bf1210b">ecat63ReadMatdata</a>(fp, first_block+1, blockNr, mptr, h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>);
<a name="l00624"></a>00624   <span class="keywordflow">if</span>(ret || mdata==NULL) {
<a name="l00625"></a>00625     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot read matrix data (%d).\n&quot;</span>, ret);
<a name="l00626"></a>00626     free(mdata); <span class="keywordflow">return</span>(9);
<a name="l00627"></a>00627   }
<a name="l00628"></a>00628   
<a name="l00629"></a>00629   <span class="comment">/* Allocate memory for float data */</span>
<a name="l00630"></a>00630   _fdata=(<span class="keywordtype">float</span>*)malloc(pxlNr*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
<a name="l00631"></a>00631   <span class="keywordflow">if</span>(_fdata==NULL) {
<a name="l00632"></a>00632     sprintf(<a class="code" href="ecat63_8h.html#a1a4fc8f123b2ef83d928b63743aa49d9">ecat63errmsg</a>, <span class="stringliteral">&quot;cannot allocate memory.\n&quot;</span>);
<a name="l00633"></a>00633     free(mdata); <span class="keywordflow">return</span>(11);  
<a name="l00634"></a>00634   }
<a name="l00635"></a>00635 
<a name="l00636"></a>00636   <span class="comment">/* Convert matrix data to floats */</span>
<a name="l00637"></a>00637   fptr=_fdata; mptr=mdata;
<a name="l00638"></a>00638   <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#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>) {
<a name="l00639"></a>00639     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, mptr++, fptr++)
<a name="l00640"></a>00640       *fptr=h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>*(<span class="keywordtype">float</span>)(*mptr);
<a name="l00641"></a>00641   } <span class="keywordflow">else</span> <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#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>) {
<a name="l00642"></a>00642     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, mptr+=2, fptr++) {
<a name="l00643"></a>00643       sptr=(<span class="keywordtype">short</span> <span class="keywordtype">int</span>*)mptr;
<a name="l00644"></a>00644       *fptr=h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>*(float)(*sptr);
<a name="l00645"></a>00645     }
<a name="l00646"></a>00646   } <span class="keywordflow">else</span> <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#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a> || h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>==<a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>) {
<a name="l00647"></a>00647     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, mptr+=4, fptr++) {
<a name="l00648"></a>00648       iptr=(<span class="keywordtype">int</span>*)mptr;
<a name="l00649"></a>00649       *fptr=h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>*(float)(*iptr);
<a name="l00650"></a>00650     }
<a name="l00651"></a>00651   } <span class="keywordflow">else</span> <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#a43d671e0f827418673872adcd63418c4">VAX_R4</a> || h-&gt;<a class="code" href="structecat63__scanheader.html#ad1ee12caf8404e9237c9b14d95711109">data_type</a>==<a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>) {
<a name="l00652"></a>00652     memcpy(fptr, mptr, pxlNr*4);
<a name="l00653"></a>00653     <span class="keywordflow">for</span>(i=0; i&lt;pxlNr; i++, fptr++) *fptr *= h-&gt;<a class="code" href="structecat63__scanheader.html#acfabab41eaa593a0625a43057bd9b558">scale_factor</a>;
<a name="l00654"></a>00654   }
<a name="l00655"></a>00655   free(mdata);
<a name="l00656"></a>00656   *fdata=_fdata;
<a name="l00657"></a>00657 
<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="l00671"></a><a class="code" href="ecat63_8h.html#a093061b988fd4047855b40ed5ab09910">00671</a> <span class="keywordtype">float</span> <a class="code" href="ecat63r_8c.html#a093061b988fd4047855b40ed5ab09910">ecat63rFloat</a>(<span class="keywordtype">void</span> *bufi, <span class="keywordtype">int</span> isvax, <span class="keywordtype">int</span> islittle) {
<a name="l00672"></a>00672   <span class="keyword">union </span>{<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ul; <span class="keywordtype">float</span> f;} t;
<a name="l00673"></a>00673 
<a name="l00674"></a>00674   memcpy(&amp;t.ul, bufi, 4); <span class="keywordflow">if</span>(t.ul==0) {<span class="keywordflow">return</span>(0.0);}
<a name="l00675"></a>00675   <span class="keywordflow">if</span>(isvax) { <span class="comment">/* if input is in VAX format */</span>
<a name="l00676"></a>00676     <span class="comment">/* Swap words on i386 and bytes on SUN */</span>
<a name="l00677"></a>00677     <span class="keywordflow">if</span>(islittle) swawip(&amp;t.ul, 4); <span class="keywordflow">else</span> swabip(&amp;t.ul, 4);
<a name="l00678"></a>00678     t.ul-=(2L&lt;&lt;23); <span class="comment">/* subtract 2 from exp */</span>
<a name="l00679"></a>00679   } <span class="keywordflow">else</span> { <span class="comment">/* input is in i386 format */</span>
<a name="l00680"></a>00680     <span class="keywordflow">if</span>(!islittle) swawbip(&amp;t.ul, 4); <span class="comment">/* Switch words and bytes on SUN */</span>
<a name="l00681"></a>00681   }
<a name="l00682"></a>00682   <span class="keywordflow">return</span>(t.f);
<a name="l00683"></a>00683 }
<a name="l00684"></a>00684 
<a name="l00694"></a><a class="code" href="ecat63_8h.html#a270d63adddcee5b6b719e8ee43f601a1">00694</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#a270d63adddcee5b6b719e8ee43f601a1">ecat63rInt</a>(<span class="keywordtype">void</span> *bufi, <span class="keywordtype">int</span> isvax, <span class="keywordtype">int</span> islittle) {
<a name="l00695"></a>00695   <span class="keywordtype">int</span> i;
<a name="l00696"></a>00696 
<a name="l00697"></a>00697   <span class="comment">/* Swap both words and bytes on SUN */</span>
<a name="l00698"></a>00698   memcpy(&amp;i, bufi, 4); <span class="keywordflow">if</span>(!islittle) swawbip(&amp;i, 4);
<a name="l00699"></a>00699   <span class="keywordflow">return</span>(i);
<a name="l00700"></a>00700 }
<a name="l00701"></a>00701 <span class="comment">/*****************************************************************************/</span>
<a name="l00702"></a>00702 
<a name="l00703"></a>00703 <span class="comment">/*****************************************************************************/</span>
<a name="l00711"></a><a class="code" href="ecat63_8h.html#af68deed580dda9af0e046697323d616d">00711</a> <span class="keywordtype">int</span> <a class="code" href="ecat63r_8c.html#af68deed580dda9af0e046697323d616d">ecat63pxlbytes</a>(<span class="keywordtype">short</span> <span class="keywordtype">int</span> data_type) {
<a name="l00712"></a>00712   <span class="keywordtype">int</span> byteNr=0;
<a name="l00713"></a>00713   <span class="keywordflow">switch</span>(data_type) {
<a name="l00714"></a>00714     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a8e1f9f0fd436e762641718456852ee80">BYTE_TYPE</a>: byteNr=1; <span class="keywordflow">break</span>;
<a name="l00715"></a>00715     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#ab6ed0aaf03f063c606604089878ed91a">VAX_I2</a>:
<a name="l00716"></a>00716     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#aebd1500a1497c6489f1820442db218d2">SUN_I2</a>: byteNr=2; <span class="keywordflow">break</span>;
<a name="l00717"></a>00717     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a91402eabd36b6383a537f5ba993e1d13">VAX_I4</a>:
<a name="l00718"></a>00718     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a43d671e0f827418673872adcd63418c4">VAX_R4</a>:
<a name="l00719"></a>00719     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a6001c489ee0296a6dca313ee3bfe4412">IEEE_R4</a>:
<a name="l00720"></a>00720     <span class="keywordflow">case</span> <a class="code" href="ecat63_8h.html#a105892e015b38ae62e69684acf6df31d">SUN_I4</a>: byteNr=4; <span class="keywordflow">break</span>;
<a name="l00721"></a>00721   }
<a name="l00722"></a>00722   <span class="keywordflow">return</span>(byteNr);
<a name="l00723"></a>00723 }
<a name="l00724"></a>00724 <span class="comment">/*****************************************************************************/</span>
<a name="l00725"></a>00725 
<a name="l00726"></a>00726 <span class="comment">/*****************************************************************************/</span>
<a name="l00727"></a>00727 
</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>