Sophie

Sophie

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

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>sifio.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">sifio.c</div>  </div>
</div>
<div class="contents">
<a href="sifio_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/******************************************************************************</span>
<a name="l00002"></a>00002 <span class="comment"></span>
<a name="l00003"></a>00003 <span class="comment">  Copyright (c) 2005,2006,2009 Turku PET Centre</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">  File:        sifio.c</span>
<a name="l00006"></a>00006 <span class="comment">  Description: Functions for reading and writing SIF format files.</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment">  This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment">  modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment">  License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment">  version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"></span>
<a name="l00013"></a>00013 <span class="comment">  This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</span>
<a name="l00016"></a>00016 <span class="comment">  See the GNU Lesser General Public License for more details:</span>
<a name="l00017"></a>00017 <span class="comment">  http://www.gnu.org/copyleft/lesser.html</span>
<a name="l00018"></a>00018 <span class="comment"></span>
<a name="l00019"></a>00019 <span class="comment">  You should have received a copy of the GNU Lesser General Public License</span>
<a name="l00020"></a>00020 <span class="comment">  along with this library/program; if not, write to the Free Software</span>
<a name="l00021"></a>00021 <span class="comment">  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </span>
<a name="l00022"></a>00022 <span class="comment"></span>
<a name="l00023"></a>00023 <span class="comment">  Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00025"></a>00025 <span class="comment">  Modification history:</span>
<a name="l00026"></a>00026 <span class="comment">  2005-01-15 Vesa Oikonen</span>
<a name="l00027"></a>00027 <span class="comment">    First created. Functions from sif.c.</span>
<a name="l00028"></a>00028 <span class="comment">  2005-01-16 VO</span>
<a name="l00029"></a>00029 <span class="comment">    studynr and isotope_name were added to SIF structure, and if available,</span>
<a name="l00030"></a>00030 <span class="comment">    can be read from/written in SIF file.</span>
<a name="l00031"></a>00031 <span class="comment">    sifRead() mostly rewritten.</span>
<a name="l00032"></a>00032 <span class="comment">    sifRead() does not calculate SIF weights.</span>
<a name="l00033"></a>00033 <span class="comment">  2005-04-26 CL</span>
<a name="l00034"></a>00034 <span class="comment">    Merged libsif to libtpcimgio</span>
<a name="l00035"></a>00035 <span class="comment">  2005-05-04 Jarkko Johansson</span>
<a name="l00036"></a>00036 <span class="comment">    Compatibility fix in function strftime().</span>
<a name="l00037"></a>00037 <span class="comment">  2006-10-31 VO</span>
<a name="l00038"></a>00038 <span class="comment">    Return value of mktime() is checked.</span>
<a name="l00039"></a>00039 <span class="comment">  2007-17-07 Harri Merisaari</span>
<a name="l00040"></a>00040 <span class="comment">    Modified for optional ANSi compatibility</span>
<a name="l00041"></a>00041 <span class="comment">  2007-09-10 VO</span>
<a name="l00042"></a>00042 <span class="comment">    Return value of localtime() is checked.</span>
<a name="l00043"></a>00043 <span class="comment">  2009-04-06 VO</span>
<a name="l00044"></a>00044 <span class="comment">    sifRead(): SIF file with only two columns is accepted, if that is correctly</span>
<a name="l00045"></a>00045 <span class="comment">    specified in title line. Comment about weights is corrected.</span>
<a name="l00046"></a>00046 <span class="comment">    sifWrite(): only frame times are saved if SIF column number tells that</span>
<a name="l00047"></a>00047 <span class="comment">    prompts and randoms are not available.</span>
<a name="l00048"></a>00048 <span class="comment"></span>
<a name="l00049"></a>00049 <span class="comment"></span>
<a name="l00050"></a>00050 <span class="comment">******************************************************************************/</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="comment">/*****************************************************************************/</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &quot;<a class="code" href="sif_8h.html">include/sif.h</a>&quot;</span>
<a name="l00054"></a>00054 <span class="comment">/*****************************************************************************/</span>
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="comment">/*****************************************************************************/</span>
<a name="l00064"></a><a class="code" href="sif_8h.html#ae6c3f31d7cbe31ca6b74760978fd39c7">00064</a> <span class="keywordtype">int</span> <a class="code" href="sifio_8c.html#ae6c3f31d7cbe31ca6b74760978fd39c7">sifRead</a>(
<a name="l00066"></a>00066   <span class="keywordtype">char</span> *filename,
<a name="l00068"></a>00068   <a class="code" href="structSIF.html">SIF</a> *data
<a name="l00069"></a>00069 ) {
<a name="l00070"></a>00070   FILE *fp;
<a name="l00071"></a>00071   <span class="keywordtype">int</span> i, c, n, frameNr, yy, mm, dd, h, m, s, longest=0;
<a name="l00072"></a>00072   <span class="keyword">struct </span>tm *st;
<a name="l00073"></a>00073   time_t timet;
<a name="l00074"></a>00074   <span class="keywordtype">char</span> *line, *cptr;
<a name="l00075"></a>00075 
<a name="l00076"></a>00076 
<a name="l00077"></a>00077   <span class="keywordflow">if</span>(<a class="code" href="sif_8h.html#a78c06628d2bc47f66f573e280c77931e">SIF_TEST</a>) printf(<span class="stringliteral">&quot;sifRead(%s, *sif)\n&quot;</span>, filename);
<a name="l00078"></a>00078   <span class="keywordflow">if</span>(filename==NULL || data==NULL) <span class="keywordflow">return</span>(1);
<a name="l00079"></a>00079   <span class="comment">/* Empty data */</span>
<a name="l00080"></a>00080   <a class="code" href="sif_8c.html#ad2378bec7fec69900af6f52737c89784">sifEmpty</a>(data);
<a name="l00081"></a>00081 
<a name="l00082"></a>00082   <span class="comment">/* Open file */</span>
<a name="l00083"></a>00083   fp=fopen(filename, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00084"></a>00084   <span class="keywordflow">if</span>(fp==NULL) {strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;cannot open file&quot;</span>); <span class="keywordflow">return</span>(2);}
<a name="l00085"></a>00085 
<a name="l00086"></a>00086   <span class="comment">/* Get the length of the longest line */</span>
<a name="l00087"></a>00087   i=0; <span class="keywordflow">while</span>((c=fgetc(fp))!=EOF) {
<a name="l00088"></a>00088     <span class="keywordflow">if</span>(c==10) {<span class="keywordflow">if</span>(i&gt;longest) longest=i; i=0;} <span class="keywordflow">else</span> i++;
<a name="l00089"></a>00089   }
<a name="l00090"></a>00090   <span class="keywordflow">if</span>(i&gt;longest) longest=i;
<a name="l00091"></a>00091   rewind(fp); longest+=1;
<a name="l00092"></a>00092   <span class="comment">/* and allocate memory for string of that length */</span>
<a name="l00093"></a>00093   line=(<span class="keywordtype">char</span>*)malloc((longest+1)*<span class="keyword">sizeof</span>(char));
<a name="l00094"></a>00094   <span class="keywordflow">if</span>(line==NULL) {strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;out of memory&quot;</span>); fclose(fp); <span class="keywordflow">return</span>(3);}
<a name="l00095"></a>00095 
<a name="l00096"></a>00096   <span class="comment">/* Read the title line */</span>
<a name="l00097"></a>00097   <span class="keywordflow">do</span> {
<a name="l00098"></a>00098     <span class="keywordflow">if</span>(fgets(line, longest, fp)==NULL) {
<a name="l00099"></a>00099       strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;wrong format&quot;</span>); fclose(fp); free(line); <span class="keywordflow">return</span>(4);
<a name="l00100"></a>00100     }
<a name="l00101"></a>00101     cptr=strpbrk(line, <span class="stringliteral">&quot;\n\r&quot;</span>); <span class="keywordflow">if</span>(cptr!=NULL) *cptr=<span class="charliteral">&#39;\0&#39;</span>;
<a name="l00102"></a>00102     cptr=line+strspn(line, <span class="stringliteral">&quot; \t&quot;</span>);
<a name="l00103"></a>00103   } <span class="keywordflow">while</span>(*cptr==<span class="charliteral">&#39;#&#39;</span> || strlen(cptr)==0);
<a name="l00104"></a>00104   n=sscanf(line, <span class="stringliteral">&quot;%d/%d/%d %d:%d:%d %d %d %d %10s %7s&quot;</span>,
<a name="l00105"></a>00105       &amp;dd, &amp;mm, &amp;yy, &amp;h, &amp;m, &amp;s, &amp;frameNr, &amp;data-&gt;<a class="code" href="structSIF.html#ae6e05bc7807e015b7a188d88e54c722d">colNr</a>, &amp;data-&gt;<a class="code" href="structSIF.html#a48b4293795f15b4c214549e0dad3ce41">version</a>,
<a name="l00106"></a>00106       data-&gt;<a class="code" href="structSIF.html#a2d3e6df8c97d55d0c28d83501d12f523">studynr</a>, data-&gt;<a class="code" href="structSIF.html#aaf18449475434d1cf5ab11b2c36780b1">isotope_name</a>);
<a name="l00107"></a>00107   <span class="keywordflow">if</span>(n&lt;9 || frameNr&lt;1 || data-&gt;colNr&lt;2 || data-&gt;version!=1) {
<a name="l00108"></a>00108     strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;wrong filetype&quot;</span>); fclose(fp); free(line); <span class="keywordflow">return</span>(5);}
<a name="l00109"></a>00109   timet=time(NULL); st=localtime(&amp;timet);
<a name="l00110"></a>00110   <span class="keywordflow">if</span>(st!=NULL) {
<a name="l00111"></a>00111     st-&gt;tm_mday=dd; st-&gt;tm_mon=mm-1; st-&gt;tm_year=yy-1900;
<a name="l00112"></a>00112     st-&gt;tm_hour=h; st-&gt;tm_min=m; st-&gt;tm_sec=s; st-&gt;tm_isdst=-1;
<a name="l00113"></a>00113     data-&gt;<a class="code" href="structSIF.html#a98b5ff616033e728f0edc9bdc7eddce2">scantime</a>=mktime(st); <span class="keywordflow">if</span>(data-&gt;<a class="code" href="structSIF.html#a98b5ff616033e728f0edc9bdc7eddce2">scantime</a>==-1) data-&gt;<a class="code" href="structSIF.html#a98b5ff616033e728f0edc9bdc7eddce2">scantime</a>=0;
<a name="l00114"></a>00114   } <span class="keywordflow">else</span> {
<a name="l00115"></a>00115     data-&gt;<a class="code" href="structSIF.html#a98b5ff616033e728f0edc9bdc7eddce2">scantime</a>=0;
<a name="l00116"></a>00116   }
<a name="l00117"></a>00117 
<a name="l00118"></a>00118   <span class="comment">/* Allocate memory for data */</span>
<a name="l00119"></a>00119   <span class="keywordflow">if</span>(<a class="code" href="sif_8c.html#ac1ea54c7476aa6b3d0b1835e22798915">sifSetmem</a>(data, frameNr)) {
<a name="l00120"></a>00120     fclose(fp); free(line); <span class="keywordflow">return</span>(6);
<a name="l00121"></a>00121   }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123   <span class="comment">/* Read data lines */</span>
<a name="l00124"></a>00124   i=0;
<a name="l00125"></a>00125   <span class="keywordflow">while</span>(i&lt;data-&gt;frameNr) {
<a name="l00126"></a>00126     <span class="keywordflow">do</span> {
<a name="l00127"></a>00127       <span class="keywordflow">if</span>(fgets(line, longest, fp)==NULL) {
<a name="l00128"></a>00128         strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;wrong format&quot;</span>); <a class="code" href="sif_8c.html#ad2378bec7fec69900af6f52737c89784">sifEmpty</a>(data);
<a name="l00129"></a>00129         fclose(fp); free(line); <span class="keywordflow">return</span>(8);
<a name="l00130"></a>00130       }
<a name="l00131"></a>00131       cptr=strpbrk(line, <span class="stringliteral">&quot;\n\r&quot;</span>); <span class="keywordflow">if</span>(cptr!=NULL) *cptr=<span class="charliteral">&#39;\0&#39;</span>;
<a name="l00132"></a>00132       cptr=line+strspn(line, <span class="stringliteral">&quot; \t&quot;</span>);
<a name="l00133"></a>00133       <span class="comment">/*printf(&quot;  i=%d cptr=&#39;%s&#39;\n&quot;, i, cptr);*/</span>
<a name="l00134"></a>00134     } <span class="keywordflow">while</span>(*cptr==<span class="charliteral">&#39;#&#39;</span> || strlen(cptr)==0);
<a name="l00135"></a>00135     n=sscanf(line, <span class="stringliteral">&quot;%lf %lf %lf %lf&quot;</span>, &amp;data-&gt;<a class="code" href="structSIF.html#a085f3f1a4b2a77eabe13f52c2010a3c0">x1</a>[i], &amp;data-&gt;<a class="code" href="structSIF.html#a45001ad49c925e6ae266357b3ab7d8a4">x2</a>[i],
<a name="l00136"></a>00136         &amp;data-&gt;<a class="code" href="structSIF.html#a20d6fecbd751d872300c661e19903eed">prompts</a>[i], &amp;data-&gt;<a class="code" href="structSIF.html#af2fa6ee9e91796baa37261bd866b641f">randoms</a>[i]);
<a name="l00137"></a>00137     <span class="comment">/*</span>
<a name="l00138"></a>00138 <span class="comment">    printf(&quot;i=%d n=%d line=&#39;%s&#39;\n&quot;, i, n, line);</span>
<a name="l00139"></a>00139 <span class="comment">    printf(&quot; -&gt; x1=%g x2=%g prompts=%g randoms=%g\n&quot;, data-&gt;x1[i], data-&gt;x2[i],</span>
<a name="l00140"></a>00140 <span class="comment">        data-&gt;prompts[i], data-&gt;randoms[i]);</span>
<a name="l00141"></a>00141 <span class="comment">    */</span>
<a name="l00142"></a>00142     <span class="keywordflow">if</span>(n&lt;data-&gt;colNr || data-&gt;<a class="code" href="structSIF.html#a45001ad49c925e6ae266357b3ab7d8a4">x2</a>[i]&lt;data-&gt;<a class="code" href="structSIF.html#a085f3f1a4b2a77eabe13f52c2010a3c0">x1</a>[i]) { 
<a name="l00143"></a>00143       strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;wrong data format&quot;</span>); <a class="code" href="sif_8c.html#ad2378bec7fec69900af6f52737c89784">sifEmpty</a>(data);
<a name="l00144"></a>00144       fclose(fp); free(line); <span class="keywordflow">return</span>(9);
<a name="l00145"></a>00145     }
<a name="l00146"></a>00146     i++;
<a name="l00147"></a>00147   }
<a name="l00148"></a>00148 
<a name="l00149"></a>00149   <span class="comment">/* Close file */</span>
<a name="l00150"></a>00150   fclose(fp); free(line);
<a name="l00151"></a>00151 
<a name="l00152"></a>00152   <span class="comment">/* Calculate trues */</span>
<a name="l00153"></a>00153   <span class="keywordflow">if</span>(data-&gt;<a class="code" href="structSIF.html#ae6e05bc7807e015b7a188d88e54c722d">colNr</a>&gt;=4) <span class="keywordflow">for</span>(i=0; i&lt;data-&gt;<a class="code" href="structSIF.html#a441bd4d1d3825ace8f21d02e9f5d650d">frameNr</a>; i++)
<a name="l00154"></a>00154     data-&gt;<a class="code" href="structSIF.html#afacb83b024d68548311e34263a3319ea">trues</a>[i]=data-&gt;<a class="code" href="structSIF.html#a20d6fecbd751d872300c661e19903eed">prompts</a>[i]-data-&gt;<a class="code" href="structSIF.html#af2fa6ee9e91796baa37261bd866b641f">randoms</a>[i];
<a name="l00155"></a>00155   <span class="comment">/* Set weights to 1.0 */</span>
<a name="l00156"></a>00156   <span class="keywordflow">for</span>(i=0; i&lt;data-&gt;frameNr; i++) data-&gt;<a class="code" href="structSIF.html#abd4ddd6bc4aa25c3f8ed6d85445dce23">weights</a>[i]=1.0;
<a name="l00157"></a>00157 
<a name="l00158"></a>00158   <span class="keywordflow">return</span>(0);
<a name="l00159"></a>00159 }
<a name="l00160"></a>00160 <span class="comment">/*****************************************************************************/</span>
<a name="l00161"></a>00161 
<a name="l00162"></a>00162 <span class="comment">/*****************************************************************************/</span>
<a name="l00167"></a><a class="code" href="sif_8h.html#a306c8a06e0576bdbe31012da3be1eb40">00167</a> <span class="keywordtype">int</span> <a class="code" href="sifio_8c.html#a306c8a06e0576bdbe31012da3be1eb40">sifWrite</a>(
<a name="l00169"></a>00169   <a class="code" href="structSIF.html">SIF</a> *data,
<a name="l00171"></a>00171   <span class="keywordtype">char</span> *filename
<a name="l00172"></a>00172 ) {
<a name="l00173"></a>00173   FILE *fp;
<a name="l00174"></a>00174   <span class="keywordtype">int</span> i, n;
<a name="l00175"></a>00175   <span class="keywordtype">char</span> buf[1024];
<a name="l00176"></a>00176   <span class="keyword">struct </span>tm *st;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178 
<a name="l00179"></a>00179   <span class="keywordflow">if</span>(<a class="code" href="sif_8h.html#a78c06628d2bc47f66f573e280c77931e">SIF_TEST</a>) printf(<span class="stringliteral">&quot;sifWrite(*sif, %s)\n&quot;</span>, filename);
<a name="l00180"></a>00180   <span class="comment">/* Check data */</span>
<a name="l00181"></a>00181   <span class="keywordflow">if</span>(data-&gt;<a class="code" href="structSIF.html#a441bd4d1d3825ace8f21d02e9f5d650d">frameNr</a>&lt;1) {strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;no data to save&quot;</span>); <span class="keywordflow">return</span> 1;}
<a name="l00182"></a>00182 
<a name="l00183"></a>00183   <span class="comment">/* Open file */</span>
<a name="l00184"></a>00184   fp=fopen(filename, <span class="stringliteral">&quot;w&quot;</span>);
<a name="l00185"></a>00185   <span class="keywordflow">if</span>(fp==NULL) {strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;cannot open file&quot;</span>); <span class="keywordflow">return</span> 2;}
<a name="l00186"></a>00186 
<a name="l00187"></a>00187   <span class="comment">/* Write title line */</span>
<a name="l00188"></a>00188   st=localtime(&amp;data-&gt;<a class="code" href="structSIF.html#a98b5ff616033e728f0edc9bdc7eddce2">scantime</a>);
<a name="l00189"></a>00189   <span class="keywordflow">if</span>(st!=NULL) strftime(buf, 1024, <span class="stringliteral">&quot;%d/%m/%Y %H:%M:%S&quot;</span>, st);
<a name="l00190"></a>00190   <span class="keywordflow">else</span> strcpy(buf, <span class="stringliteral">&quot;1/1/1900 00:00:00&quot;</span>);
<a name="l00191"></a>00191   n=fprintf(fp, <span class="stringliteral">&quot;%s %d %d %d&quot;</span>, buf, data-&gt;<a class="code" href="structSIF.html#a441bd4d1d3825ace8f21d02e9f5d650d">frameNr</a>, data-&gt;<a class="code" href="structSIF.html#ae6e05bc7807e015b7a188d88e54c722d">colNr</a>, data-&gt;<a class="code" href="structSIF.html#a48b4293795f15b4c214549e0dad3ce41">version</a>);
<a name="l00192"></a>00192   <span class="keywordflow">if</span>(<a class="code" href="sif_8h.html#a78c06628d2bc47f66f573e280c77931e">SIF_TEST</a>)
<a name="l00193"></a>00193     printf(<span class="stringliteral">&quot;%s %d %d %d\n&quot;</span>, buf, data-&gt;<a class="code" href="structSIF.html#a441bd4d1d3825ace8f21d02e9f5d650d">frameNr</a>, data-&gt;<a class="code" href="structSIF.html#ae6e05bc7807e015b7a188d88e54c722d">colNr</a>, data-&gt;<a class="code" href="structSIF.html#a48b4293795f15b4c214549e0dad3ce41">version</a>);
<a name="l00194"></a>00194   <span class="keywordflow">if</span>(n&lt;7) {strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;cannot write file&quot;</span>); fclose(fp); <span class="keywordflow">return</span> 2;}
<a name="l00195"></a>00195   <span class="keywordflow">if</span>(strlen(data-&gt;<a class="code" href="structSIF.html#a2d3e6df8c97d55d0c28d83501d12f523">studynr</a>)!=0 || strlen(data-&gt;<a class="code" href="structSIF.html#aaf18449475434d1cf5ab11b2c36780b1">isotope_name</a>)!=0) {
<a name="l00196"></a>00196     <span class="comment">/* Write also study number and isotope */</span>
<a name="l00197"></a>00197     <span class="keywordflow">if</span>(strlen(data-&gt;<a class="code" href="structSIF.html#a2d3e6df8c97d55d0c28d83501d12f523">studynr</a>)==0) fprintf(fp, <span class="stringliteral">&quot; .&quot;</span>);
<a name="l00198"></a>00198     <span class="keywordflow">else</span> fprintf(fp, <span class="stringliteral">&quot; %s&quot;</span>, data-&gt;<a class="code" href="structSIF.html#a2d3e6df8c97d55d0c28d83501d12f523">studynr</a>);
<a name="l00199"></a>00199     <span class="keywordflow">if</span>(strlen(data-&gt;<a class="code" href="structSIF.html#aaf18449475434d1cf5ab11b2c36780b1">isotope_name</a>)&gt;0) fprintf(fp, <span class="stringliteral">&quot; %s&quot;</span>, data-&gt;<a class="code" href="structSIF.html#aaf18449475434d1cf5ab11b2c36780b1">isotope_name</a>);
<a name="l00200"></a>00200   }
<a name="l00201"></a>00201   fprintf(fp, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00202"></a>00202 
<a name="l00203"></a>00203   <span class="comment">/* Write data lines */</span>
<a name="l00204"></a>00204   <span class="keywordflow">for</span>(i=0; i&lt;data-&gt;<a class="code" href="structSIF.html#a441bd4d1d3825ace8f21d02e9f5d650d">frameNr</a>; i++) {
<a name="l00205"></a>00205     <span class="keywordflow">if</span>(data-&gt;<a class="code" href="structSIF.html#ae6e05bc7807e015b7a188d88e54c722d">colNr</a>&gt;2)
<a name="l00206"></a>00206       n=fprintf(fp, <span class="stringliteral">&quot;%.0f %.0f %.0f %.0f\n&quot;</span>,
<a name="l00207"></a>00207         data-&gt;<a class="code" href="structSIF.html#a085f3f1a4b2a77eabe13f52c2010a3c0">x1</a>[i], data-&gt;<a class="code" href="structSIF.html#a45001ad49c925e6ae266357b3ab7d8a4">x2</a>[i], data-&gt;<a class="code" href="structSIF.html#a20d6fecbd751d872300c661e19903eed">prompts</a>[i], data-&gt;<a class="code" href="structSIF.html#af2fa6ee9e91796baa37261bd866b641f">randoms</a>[i]);
<a name="l00208"></a>00208     <span class="keywordflow">else</span>
<a name="l00209"></a>00209       n=fprintf(fp, <span class="stringliteral">&quot;%.0f %.0f\n&quot;</span>,
<a name="l00210"></a>00210         data-&gt;<a class="code" href="structSIF.html#a085f3f1a4b2a77eabe13f52c2010a3c0">x1</a>[i], data-&gt;<a class="code" href="structSIF.html#a45001ad49c925e6ae266357b3ab7d8a4">x2</a>[i]);
<a name="l00211"></a>00211     <span class="keywordflow">if</span>(n&lt;3) {strcpy(<a class="code" href="sif_8h.html#aead6d915302aed6cb03d80791abd866f">siferrmsg</a>, <span class="stringliteral">&quot;cannot write file&quot;</span>); fclose(fp); <span class="keywordflow">return</span> 3;}
<a name="l00212"></a>00212   }
<a name="l00213"></a>00213 
<a name="l00214"></a>00214   <span class="comment">/* Close file */</span>
<a name="l00215"></a>00215   fclose(fp);
<a name="l00216"></a>00216 
<a name="l00217"></a>00217   <span class="keywordflow">return</span> 0;
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219 <span class="comment">/*****************************************************************************/</span>
<a name="l00220"></a>00220 
<a name="l00221"></a>00221 <span class="comment">/*****************************************************************************/</span>
<a name="l00224"></a><a class="code" href="sif_8h.html#a8ef6e8273b016fde2c629d2bc2ac7127">00224</a> <span class="keywordtype">void</span> <a class="code" href="sifio_8c.html#a8ef6e8273b016fde2c629d2bc2ac7127">sifPrint</a>(
<a name="l00226"></a>00226   <a class="code" href="structSIF.html">SIF</a> *data
<a name="l00227"></a>00227 ) {
<a name="l00228"></a>00228   <span class="keywordtype">int</span> i;
<a name="l00229"></a>00229   <span class="keywordtype">char</span> buf[512];
<a name="l00230"></a>00230   <span class="keyword">struct </span>tm *st;
<a name="l00231"></a>00231   
<a name="l00232"></a>00232   <span class="comment">/*printf(&quot;Number of frames: %d\n&quot;, data-&gt;frameNr);*/</span>
<a name="l00233"></a>00233   st=localtime(&amp;data-&gt;<a class="code" href="structSIF.html#a98b5ff616033e728f0edc9bdc7eddce2">scantime</a>);
<a name="l00234"></a>00234   <span class="keywordflow">if</span>(st!=NULL) strftime(buf, 512, <span class="stringliteral">&quot;%Y-%m-%d %H:%M:%S&quot;</span>, st);
<a name="l00235"></a>00235   <span class="keywordflow">else</span> strcpy(buf, <span class="stringliteral">&quot;1900-01-01 00:00:00&quot;</span>);
<a name="l00236"></a>00236   printf(<span class="stringliteral">&quot;Scan time: %s\n&quot;</span>, buf);
<a name="l00237"></a>00237   printf(<span class="stringliteral">&quot;Isotope: %s\n&quot;</span>, data-&gt;<a class="code" href="structSIF.html#aaf18449475434d1cf5ab11b2c36780b1">isotope_name</a>);
<a name="l00238"></a>00238   printf(<span class="stringliteral">&quot;Frame start  end     Prompts    Randoms      Trues   Weight\n&quot;</span>);
<a name="l00239"></a>00239   <span class="keywordflow">for</span>(i=0; i&lt;data-&gt;<a class="code" href="structSIF.html#a441bd4d1d3825ace8f21d02e9f5d650d">frameNr</a>; i++) {
<a name="l00240"></a>00240     printf(<span class="stringliteral">&quot; %03d %5.0f %5.0f  %10.0f %10.0f %10.0f %8.6f\n&quot;</span>, i+1,
<a name="l00241"></a>00241       data-&gt;<a class="code" href="structSIF.html#a085f3f1a4b2a77eabe13f52c2010a3c0">x1</a>[i], data-&gt;<a class="code" href="structSIF.html#a45001ad49c925e6ae266357b3ab7d8a4">x2</a>[i], data-&gt;<a class="code" href="structSIF.html#a20d6fecbd751d872300c661e19903eed">prompts</a>[i], data-&gt;<a class="code" href="structSIF.html#af2fa6ee9e91796baa37261bd866b641f">randoms</a>[i],
<a name="l00242"></a>00242       data-&gt;<a class="code" href="structSIF.html#afacb83b024d68548311e34263a3319ea">trues</a>[i], data-&gt;<a class="code" href="structSIF.html#abd4ddd6bc4aa25c3f8ed6d85445dce23">weights</a>[i]);
<a name="l00243"></a>00243   }
<a name="l00244"></a>00244   <span class="keywordflow">return</span>;
<a name="l00245"></a>00245 }
<a name="l00246"></a>00246 <span class="comment">/*****************************************************************************/</span>
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 <span class="comment">/*****************************************************************************/</span>
<a name="l00249"></a>00249 
</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>