00001 /****************************************************************************** 00002 00003 File: sif.c 00004 Description: Routines for Scan Information Files (SIF). 00005 00006 Copyright (c) 2000-2005 Turku PET Centre 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 See the GNU Lesser General Public License for more details: 00017 http://www.gnu.org/copyleft/lesser.html 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with this library/program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi 00024 00025 Modification history: 00026 2000-09-04 Vesa Oikonen 00027 2000-09-08 VO 00028 malloc->calloc. 00029 2000-09-18 VO 00030 weightSIF() can calculate weights for decay corrected data. 00031 2000-12-13 VO 00032 Included function writeSIF(). 00033 2002-07-30 VO 00034 memset() added to initSIF(). 00035 2004-09-17 VO 00036 Doxygen style comments. 00037 2004-10-13 VO 00038 tm_isdst=-1 (unknown Daylight saving time). 00039 2005-01-12 VO 00040 Changed and additional comments not affecting compiled code. 00041 2005-01-15 VO 00042 SIF related stuff moved from libpet to new libsif. 00043 Function names changed, although old names can still be used. 00044 2005-01-16 VO 00045 studynr and isotope_name were added to SIF structure. 00046 2005-04-26 CL 00047 Merged libsif to libtpcimio 00048 00049 ******************************************************************************/ 00050 00051 /*****************************************************************************/ 00052 #include "sif.h" 00053 /*****************************************************************************/ 00054 00055 /*****************************************************************************/ 00061 void sifInit(SIF *data) { 00062 if(SIF_TEST) printf("sifInit()\n"); 00063 memset(data, 0, sizeof(SIF)); 00064 data->frameNr=data->colNr=0; 00065 } 00066 /*****************************************************************************/ 00067 00068 /*****************************************************************************/ 00074 void sifEmpty(SIF *data) { 00075 if(SIF_TEST) printf("sifEmpty()\n"); 00076 if(data->frameNr>0) { 00077 free((char*)(data->x1)); free((char*)(data->x2)); 00078 free((char*)(data->prompts)); free((char*)(data->randoms)); 00079 free((char*)(data->trues)); free((char*)(data->weights)); 00080 data->frameNr=data->colNr=0; 00081 } 00082 data->scantime=(time_t)0; data->version=0; 00083 strcpy(data->studynr, ""); strcpy(data->isotope_name, ""); 00084 } 00085 /*****************************************************************************/ 00086 00087 /*****************************************************************************/ 00095 int sifSetmem(SIF *data, int frameNr) { 00096 if(SIF_TEST) printf("sifSetmem()\n"); 00097 /* Clear previous data, if necessary */ 00098 if(data->frameNr>0) sifEmpty(data); 00099 if(frameNr<1) return(0); 00100 00101 /* Allocate memory */ 00102 data->x1=(double*)calloc(frameNr, sizeof(double)); 00103 data->x2=(double*)calloc(frameNr, sizeof(double)); 00104 data->prompts=(double*)calloc(frameNr, sizeof(double)); 00105 data->randoms=(double*)calloc(frameNr, sizeof(double)); 00106 data->trues=(double*)calloc(frameNr, sizeof(double)); 00107 data->weights=(double*)calloc(frameNr, sizeof(double)); 00108 if(data->x1==NULL || data->x2==NULL || data->prompts==NULL || 00109 data->randoms==NULL || data->trues==NULL || data->weights==NULL) { 00110 strcpy(siferrmsg, "out of memory"); return(1);} 00111 data->frameNr=frameNr; 00112 00113 return(0); 00114 } 00115 /*****************************************************************************/ 00116 00117 /*****************************************************************************/ 00118