TPCCLIB
Loading...
Searching...
No Matches
partac.c File Reference

Exchanging information between PAR and TAC structures. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcextensions.h"
#include "tpcmodels.h"
#include "tpcpar.h"
#include "tpctac.h"
#include "tpctacmod.h"

Go to the source code of this file.

Functions

int tacAllocateWithPAR (TAC *tac, PAR *par, int sampleNr, TPCSTATUS *status)
 Allocate TAC based on data in PAR.
int parAllocateWithTAC (PAR *par, TAC *tac, int parNr, TPCSTATUS *status)
 Allocate PAR based on data in TAC.
int tacToPAR (TAC *tac, PAR *par, TPCSTATUS *status)
 Copy the contents of TAC struct into PAR struct.

Detailed Description

Exchanging information between PAR and TAC structures.

Definition in file partac.c.

Function Documentation

◆ parAllocateWithTAC()

int parAllocateWithTAC ( PAR * par,
TAC * tac,
int parNr,
TPCSTATUS * status )

Allocate PAR based on data in TAC.

Region number, names, etc are copied from given TAC.

See also
parAllocate, parAllocateMore, parInit, tacToPar
Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
parPointer to initiated PAR struct; any old contents are deleted. PAR tacNr and parNr will be set, although contents will be empty.
Precondition
Struct must be initiated with parInit.
Parameters
tacPointer to TAC struct which contains at least the TAC number and names.
parNrNr of parameters to allocate.
statusPointer to status data; enter NULL if not needed.

Definition at line 90 of file partac.c.

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}
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
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
IFT h
Optional (but often useful) header information.
Definition tpcpar.h:147
int parNr
Definition tpcpar.h:108
int tacNr
Definition tpcpar.h:104
PARR * r
Definition tpcpar.h:114
char name[MAX_TACNAME_LEN+1]
Definition tpcpar.h:50
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
unit cunit
Definition tpctac.h:105
IFT h
Optional (but often useful) header information.
Definition tpctac.h:141
TACC * c
Definition tpctac.h:117
unit tunit
Definition tpctac.h:109
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
int tacIsWeighted(TAC *tac)
Definition tacw.c:24
@ UNIT_UNKNOWN
Unknown unit.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
char * unitName(int unit_code)
Definition units.c:143

Referenced by tacToPAR().

◆ tacAllocateWithPAR()

int tacAllocateWithPAR ( TAC * tac,
PAR * par,
int sampleNr,
TPCSTATUS * status )

Allocate TAC based on data in PAR.

TAC region number, names, and units are copied from given PAR.

See also
tacAllocate, tacAllocateMore, tacDuplicate, tacAllocateWithIMG
Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
tacPointer to initiated TAC structure; any old contents are deleted. TAC sampleNr and tacNr will be set, although contents will be empty.
Precondition
Structure must be initiated with tacInit.
Parameters
parPointer to PAR structure which contains at least the TAC number and names.
sampleNrNr of samples (time frames) to allocate.
statusPointer to status data; enter NULL if not needed.

Definition at line 28 of file partac.c.

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}
int sampleNr
Definition tpctac.h:89
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition tac.c:130
int unitIdentify(const char *s)
Definition units.c:162

◆ tacToPAR()

int tacToPAR ( TAC * tac,
PAR * par,
TPCSTATUS * status )

Copy the contents of TAC struct into PAR struct.

In addition to data, the header contents such as region names and units are copied if possible.

See also
parInit, parFree, parAllocateWithTAC, parWrite
Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
tacPointer to the TAC struct to be copied.
parPointer to PAR struct; any old contents are deleted.
Precondition
Struct must be initiated with parInit.
Parameters
statusPointer to status data; enter NULL if not needed

Definition at line 169 of file partac.c.

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}
int parAllocateWithTAC(PAR *par, TAC *tac, int parNr, TPCSTATUS *status)
Allocate PAR based on data in TAC.
Definition partac.c:90
double * p
Definition tpcpar.h:64
double * y
Definition tpctac.h:75