sif.c
Go to the documentation of this file.
1 /******************************************************************************
2 
3  File: sif.c
4  Description: Routines for Scan Information Files (SIF).
5 
6  Copyright (c) 2000-2005 Turku PET Centre
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  See the GNU Lesser General Public License for more details:
17  http://www.gnu.org/copyleft/lesser.html
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with this library/program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi
24 
25  Modification history:
26  2000-09-04 Vesa Oikonen
27  2000-09-08 VO
28  malloc->calloc.
29  2000-09-18 VO
30  weightSIF() can calculate weights for decay corrected data.
31  2000-12-13 VO
32  Included function writeSIF().
33  2002-07-30 VO
34  memset() added to initSIF().
35  2004-09-17 VO
36  Doxygen style comments.
37  2004-10-13 VO
38  tm_isdst=-1 (unknown Daylight saving time).
39  2005-01-12 VO
40  Changed and additional comments not affecting compiled code.
41  2005-01-15 VO
42  SIF related stuff moved from libpet to new libsif.
43  Function names changed, although old names can still be used.
44  2005-01-16 VO
45  studynr and isotope_name were added to SIF structure.
46  2005-04-26 CL
47  Merged libsif to libtpcimio
48 
49 ******************************************************************************/
50 
51 /*****************************************************************************/
52 #include "sif.h"
53 /*****************************************************************************/
54 
55 /*****************************************************************************/
61 void sifInit(SIF *data) {
62  if(SIF_TEST) printf("sifInit()\n");
63  memset(data, 0, sizeof(SIF));
64  data->frameNr=data->colNr=0;
65 }
66 /*****************************************************************************/
67 
68 /*****************************************************************************/
74 void sifEmpty(SIF *data) {
75  if(SIF_TEST) printf("sifEmpty()\n");
76  if(data->frameNr>0) {
77  free((char*)(data->x1)); free((char*)(data->x2));
78  free((char*)(data->prompts)); free((char*)(data->randoms));
79  free((char*)(data->trues)); free((char*)(data->weights));
80  data->frameNr=data->colNr=0;
81  }
82  data->scantime=(time_t)0; data->version=0;
83  strcpy(data->studynr, ""); strcpy(data->isotope_name, "");
84 }
85 /*****************************************************************************/
86 
87 /*****************************************************************************/
95 int sifSetmem(SIF *data, int frameNr) {
96  if(SIF_TEST) printf("sifSetmem()\n");
97  /* Clear previous data, if necessary */
98  if(data->frameNr>0) sifEmpty(data);
99  if(frameNr<1) return(0);
100 
101  /* Allocate memory */
102  data->x1=(double*)calloc(frameNr, sizeof(double));
103  data->x2=(double*)calloc(frameNr, sizeof(double));
104  data->prompts=(double*)calloc(frameNr, sizeof(double));
105  data->randoms=(double*)calloc(frameNr, sizeof(double));
106  data->trues=(double*)calloc(frameNr, sizeof(double));
107  data->weights=(double*)calloc(frameNr, sizeof(double));
108  if(data->x1==NULL || data->x2==NULL || data->prompts==NULL ||
109  data->randoms==NULL || data->trues==NULL || data->weights==NULL) {
110  strcpy(siferrmsg, "out of memory"); return(1);}
111  data->frameNr=frameNr;
112 
113  return(0);
114 }
115 /*****************************************************************************/
116 
117 /*****************************************************************************/
118 
time_t scantime
Definition: sif.h:38
void sifInit(SIF *data)
Definition: sif.c:61
int colNr
Definition: sif.h:42
int frameNr
Definition: sif.h:40
double * prompts
Definition: sif.h:54
int sifSetmem(SIF *data, int frameNr)
Definition: sif.c:95
double * randoms
Definition: sif.h:56
Definition: sif.h:36
double * x2
Definition: sif.h:52
char studynr[11]
Definition: sif.h:46
int version
Definition: sif.h:44
double * trues
Definition: sif.h:58
char siferrmsg[128]
Definition: sif.h:33
int SIF_TEST
Definition: sif.h:63
double * x1
Definition: sif.h:50
char isotope_name[8]
Definition: sif.h:48
double * weights
Definition: sif.h:60
void sifEmpty(SIF *data)
Definition: sif.c:74