TPCCLIB
Loading...
Searching...
No Matches
partac.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <time.h>
11#include <string.h>
12/*****************************************************************************/
13#include "tpcextensions.h"
14#include "tpcmodels.h"
15#include "tpcpar.h"
16#include "tpctac.h"
17/*****************************************************************************/
18#include "tpctacmod.h"
19/*****************************************************************************/
20
21/*****************************************************************************/
32 TAC *tac,
34 PAR *par,
36 int sampleNr,
38 TPCSTATUS *status
39) {
40 int verbose=0; if(status!=NULL) verbose=status->verbose;
41 if(verbose>0) printf("%s(tac, par, %d)\n", __func__, sampleNr);
42
43 /* Check the input */
44 if(tac==NULL || par==NULL) {
45 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
46 return TPCERROR_FAIL;
47 }
48 if(sampleNr<1 || par->tacNr<1) {
49 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
50 return TPCERROR_NO_DATA;
51 }
52
53 int ret, i;
54
55 /* Allocate */
56 ret=tacAllocate(tac, sampleNr, par->tacNr);
57 statusSet(status, __func__, __FILE__, __LINE__, ret);
58 if(ret!=TPCERROR_OK) return(ret);
59 tac->sampleNr=sampleNr; tac->tacNr=par->tacNr;
60
61 /* Copy TAC names */
62 for(int i=0; i<par->tacNr; i++) strcpy(tac->c[i].name, par->r[i].name);
63
64 /* Try to find the data units */
65 i=iftFindKey(&par->h, "unit", 0);
66 if(i<0) i=iftFindKey(&par->h, "calibration_unit", 0);
67 if(i>0) tac->cunit=unitIdentify(par->h.item[i].value);
68 i=iftFindKey(&par->h, "timeunit", 0);
69 if(i<0) i=iftFindKey(&par->h, "time_unit", 0);
70 if(i>0) tac->tunit=unitIdentify(par->h.item[i].value);
71 /* Try to find study number */
72 i=iftFindKey(&par->h, "studynr", 0);
73 if(i<0) i=iftFindKey(&par->h, "study", 0);
74 if(i>=0) {
75 iftPut(&tac->h, par->h.item[i].key, par->h.item[i].value, 1, NULL);
76 }
77
78 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
79 return(TPCERROR_OK);
80}
81/*****************************************************************************/
82
83/*****************************************************************************/
94 PAR *par,
96 TAC *tac,
98 int parNr,
100 TPCSTATUS *status
101) {
102 int verbose=0; if(status!=NULL) verbose=status->verbose;
103 if(verbose>0) printf("%s(par, tac, %d)\n", __func__, parNr);
104
105 /* Check the input */
106 if(tac==NULL || par==NULL) {
107 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
108 return TPCERROR_FAIL;
109 }
110 if(parNr<1 || tac->tacNr<1) {
111 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
112 return TPCERROR_NO_DATA;
113 }
114
115 int i, ret;
116
117 /* Allocate memory */
118 if(verbose>2) printf("allocate memory for PAR\n");
119 ret=parAllocate(par, parNr, tac->tacNr);
120 if(ret!=TPCERROR_OK) {statusSet(status, __func__, __FILE__, __LINE__, ret); return ret;}
121 par->tacNr=tac->tacNr;
122 par->parNr=parNr;
123
124 /* Copy TAC names */
125 if(verbose>3) printf("copy TAC names\n");
126 for(int i=0; i<par->tacNr; i++) strcpy(par->r[i].name, tac->c[i].name);
127
128 /* Copy header information */
129 if(verbose>3) printf("copy header\n");
130
131 i=iftFindKey(&tac->h, "studynr", 0);
132 if(i<0) i=iftFindKey(&tac->h, "study_number", 0);
133 if(i>=0) iftPut(&par->h, tac->h.item[i].key, tac->h.item[i].value, 0, NULL);
134
135 i=iftFindKey(&tac->h, "injection_time", 0);
136 if(i<0) i=iftFindKey(&tac->h, "injection time", 0);
137 if(i>=0) iftPut(&par->h, tac->h.item[i].key, tac->h.item[i].value, 0, NULL);
138
139 i=iftFindKey(&tac->h, "isotope", 0);
140 if(i>=0) iftPut(&par->h, tac->h.item[i].key, tac->h.item[i].value, 0, NULL);
141
142 i=iftFindKey(&tac->h, "radiopharmaceutical", 0);
143 if(i>=0) iftPut(&par->h, tac->h.item[i].key, tac->h.item[i].value, 0, NULL);
144
145 i=iftFindKey(&tac->h, "scan_start_time", 0);
146 if(i>=0) iftPut(&par->h, tac->h.item[i].key, tac->h.item[i].value, 0, NULL);
147
148 if(tacIsWeighted(tac)) iftPut(&par->h, "weighting", "yes", 0, NULL);
149 else iftPut(&par->h, "weighting", "no", 0, NULL);
150
151 if(tac->tunit!=UNIT_UNKNOWN)
152 iftPut(&par->h, "timeunit", unitName(tac->tunit), 0, NULL);
153 if(tac->cunit!=UNIT_UNKNOWN)
154 iftPut(&par->h, "unit", unitName(tac->cunit), 0, NULL);
155
156 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
157 return(TPCERROR_OK);
158}
159/*****************************************************************************/
160
161/*****************************************************************************/
171 TAC *tac,
174 PAR *par,
176 TPCSTATUS *status
177) {
178 int verbose=0; if(status!=NULL) verbose=status->verbose;
179 if(verbose>0) printf("%s(par, tac)\n", __func__);
180
181 int ret;
182
183 /* Check the input */
184 if(tac==NULL || par==NULL) {
185 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
186 return TPCERROR_FAIL;
187 }
188 if(tac->sampleNr<1 || tac->tacNr<1) {
189 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
190 return TPCERROR_NO_DATA;
191 }
192
193 /* Allocate memory and copy most of headers */
194 ret=parAllocateWithTAC(par, tac, tac->sampleNr, status);
195 if(ret!=TPCERROR_OK) return(ret);
196
197 /* Copy the values */
198 for(int i=0; i<tac->tacNr; i++)
199 for(int j=0; j<par->parNr; j++)
200 par->r[i].p[j]=tac->c[i].y[j];
201
202 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
203 return TPCERROR_OK;
204}
205/*****************************************************************************/
206
207/*****************************************************************************/
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition ift.c:63
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30
int parAllocate(PAR *par, int parNr, int tacNr)
Definition par.c:108
int tacAllocateWithPAR(TAC *tac, PAR *par, int sampleNr, TPCSTATUS *status)
Allocate TAC based on data in PAR.
Definition partac.c:28
int parAllocateWithTAC(PAR *par, TAC *tac, int parNr, TPCSTATUS *status)
Allocate PAR based on data in TAC.
Definition partac.c:90
int tacToPAR(TAC *tac, PAR *par, TPCSTATUS *status)
Copy the contents of TAC struct into PAR struct.
Definition partac.c:169
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
char * value
Definition tpcift.h:37
char * key
Definition tpcift.h:32
IFT_ITEM * item
Definition tpcift.h:57
Definition tpcpar.h:101
IFT h
Optional (but often useful) header information.
Definition tpcpar.h:148
int parNr
Definition tpcpar.h:109
int tacNr
Definition tpcpar.h:105
PARR * r
Definition tpcpar.h:115
char name[MAX_TACNAME_LEN+1]
Definition tpcpar.h:50
double * p
Definition tpcpar.h:65
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
double * y
Definition tpctac.h:75
Definition tpctac.h:87
int sampleNr
Definition tpctac.h:89
IFT h
Optional (but often useful) header information.
Definition tpctac.h:141
int cunit
Definition tpctac.h:105
TACC * c
Definition tpctac.h:117
int tunit
Definition tpctac.h:109
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition tac.c:130
int tacIsWeighted(TAC *tac)
Definition tacw.c:24
Header file for library libtpcextensions.
@ UNIT_UNKNOWN
Unknown unit.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
int unitIdentify(const char *s)
Definition units.c:162
char * unitName(int unit_code)
Definition units.c:143
Header file for libtpcmodels.
Header file for libtpcpar.
Header file for library libtpctac.
Header file for libtpctacmod.