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

Utility functions for working with FIT struct. More...

#include "libtpccurveio.h"

Go to the source code of this file.

Functions

int fit_allocate_with_dft (FIT *fit, DFT *dft)
 
int fitToResult (FIT *fit, RES *res, char *status)
 

Detailed Description

Utility functions for working with FIT struct.

Author
Vesa Oikonen
See also
mathfunc.c

Definition in file fitres.c.

Function Documentation

◆ fit_allocate_with_dft()

int fit_allocate_with_dft ( FIT * fit,
DFT * dft )

Allocate memory for regional function fits based on information in DFT.

Returns
Returns 0 if successful, otherwise <>0.
Parameters
fitPointer to initiated FIT struct which will be allocated here and filled with ROI names etc.
dftRegional data from where necessary information is read.

Definition at line 14 of file fitres.c.

19 {
20 int ri;
21
22 //printf("fit_allocate_with_dft()\n"); fflush(stdout);
23 // Check the input data
24 if(fit==NULL || dft==NULL || dft->voiNr<1) return 1;
25 // Allocate memory
26 if(fitSetmem(fit, dft->voiNr)!=0) return 2;
27 fit->voiNr=dft->voiNr;
28 /* Set header contents */
29 fit->time=time(NULL); // Set current time to results
30 strcpy(fit->unit, dft->unit);
31 fit->timeunit=dft->timeunit;
32 strcpy(fit->studynr, dft->studynr);
33 /* Copy region names, etc */
34 for(ri=0; ri<dft->voiNr; ri++) {
35 strcpy(fit->voi[ri].name, dft->voi[ri].name);
36 strcpy(fit->voi[ri].voiname, dft->voi[ri].voiname);
37 strcpy(fit->voi[ri].hemisphere, dft->voi[ri].hemisphere);
38 strcpy(fit->voi[ri].place, dft->voi[ri].place);
39 fit->voi[ri].dataNr=dft->frameNr;
40 if(dft->timetype==DFT_TIME_STARTEND) {
41 fit->voi[ri].start=dft->x1[0]; fit->voi[ri].end=dft->x2[dft->frameNr-1];
42 } else {
43 fit->voi[ri].start=dft->x[0]; fit->voi[ri].end=dft->x[dft->frameNr-1];
44 }
45 }
46
47 return 0;
48}
int fitSetmem(FIT *fit, int voiNr)
Definition mathfunc.c:154
#define DFT_TIME_STARTEND
int timetype
Voi * voi
int timeunit
char studynr[MAX_STUDYNR_LEN+1]
double * x1
int voiNr
double * x2
int frameNr
double * x
char unit[MAX_UNITS_LEN+1]
int timeunit
int voiNr
char unit[MAX_UNITS_LEN+1]
char studynr[MAX_STUDYNR_LEN+1]
FitVOI * voi
time_t time
double end
char place[MAX_REGIONSUBNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
double start
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]

Referenced by dft_end_line().

◆ fitToResult()

int fitToResult ( FIT * fit,
RES * res,
char * status )

Conversion of FIT contents to RES.

See also
res_allocate_with_dft, dftToResult, res2ift
Returns
Returns 0 when successful.
Parameters
fitPointer to FIT structure, contents of which are written to RES struct.
resPointer to initiated RES struct where FIT contents are written; any previous contents are removed.
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed.

Definition at line 56 of file fitres.c.

65 {
66 int pi, ri, maxParNr, ret;
67
68
69 //printf("fitToResult()\n"); fflush(stdout);
70 /* Check input */
71 if(status!=NULL) sprintf(status, "invalid data");
72 if(fit==NULL || res==NULL) return 1;
73 if(fit->voiNr<1) return 2;
74
75 /* Determine max parameter number in fits */
76 for(ri=0, maxParNr=0; ri<fit->voiNr; ri++)
77 if(fit->voi[ri].parNr>maxParNr) maxParNr=fit->voi[ri].parNr;
78 //printf("maxParNr := %d\n", maxParNr); fflush(stdout);
79
80 /* Allocate memory for results */
81 resEmpty(res); ret=resSetmem(res, fit->voiNr);
82 if(ret) {
83 if(status!=NULL) sprintf(status, "cannot allocate memory");
84 return 11;
85 }
86 /* Copy titles & filenames */
87 //printf("copy header contents\n"); fflush(stdout);
88 if(strlen(fit->program)>0 && strlen(fit->program)<512)
89 snprintf(res->program, 1024, "%.512s (c) 2014", fit->program);
90 else
91 strcpy(res->program, "fitToResult (c) 2014");
92 strcpy(res->datafile, fit->datafile);
93 strcpy(res->studynr, fit->studynr);
94 res->time=fit->time;
95 /* Copy region names, etc */
96 //printf("copy region names\n"); fflush(stdout);
97 res->voiNr=fit->voiNr;
98 for(ri=0; ri<fit->voiNr; ri++) {
99 strcpy(res->voi[ri].name, fit->voi[ri].name);
100 strcpy(res->voi[ri].voiname, fit->voi[ri].voiname);
101 strcpy(res->voi[ri].hemisphere, fit->voi[ri].hemisphere);
102 strcpy(res->voi[ri].place, fit->voi[ri].place);
103 }
104 /* Copy sample number, if equal in all TACs */
105 for(ri=1, ret=0; ri<fit->voiNr; ri++)
106 if(fit->voi[ri].dataNr!=fit->voi[0].dataNr) ret++;
107 if(ret==0) res->datanr=fit->voi[0].dataNr;
108 /* Set parameter names */
109 //printf("set parameter names\n"); fflush(stdout);
110 res->parNr=maxParNr+2; // function id and wss too
111 strcpy(res->parname[0], "Func");
112 for(pi=0; pi<maxParNr; pi++) sprintf(res->parname[pi+1], "p%d", pi+1);
113 strcpy(res->parname[pi+1], "WSS");
114 /* Copy parameter values */
115 //printf("copy parameter values\n"); fflush(stdout);
116 for(ri=0; ri<fit->voiNr; ri++) {
117 res->voi[ri].parameter[0]=fit->voi[ri].type; // function id
118 for(pi=0; pi<maxParNr; pi++) { // function parameters
119 if(pi>=fit->voi[ri].parNr) res->voi[ri].parameter[pi+1]=0.0;
120 else res->voi[ri].parameter[pi+1]=fit->voi[ri].p[pi];
121 }
122 res->voi[ri].parameter[pi+1]=fit->voi[ri].wss; // wss
123 }
124 /* Set also deprecated parameter name and unit representations, for now */
125 //printf("set deprecated info\n"); fflush(stdout);
126 resFixParnames(res);
127 return(0);
128}
int resSetmem(RES *res, int voiNr)
Definition result.c:70
void resFixParnames(RES *res)
Definition result.c:107
void resEmpty(RES *res)
Definition result.c:22
char datafile[FILENAME_MAX]
char program[1024]
double wss
double p[MAX_FITPARAMS]
char studynr[MAX_STUDYNR_LEN+1]
int parNr
char parname[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]
int voiNr
int datanr
ResVOI * voi
char program[1024]
char datafile[FILENAME_MAX]
time_t time
double parameter[MAX_RESPARAMS]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
char voiname[MAX_REGIONSUBNAME_LEN+1]