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

Selecting TAC(s) in TAC struct. More...

#include "tpcclibConfig.h"
#include "tpcift.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpctac.h"

Go to the source code of this file.

Functions

int tacSelectTACs (TAC *d, const char *region_name, int reset, TPCSTATUS *status)
int tacSelectedTACs (TAC *d)
int tacFirstSelected (TAC *d)
int tacSelectBestReference (TAC *d)

Detailed Description

Selecting TAC(s) in TAC struct.

Definition in file tacselect.c.

Function Documentation

◆ tacFirstSelected()

int tacFirstSelected ( TAC * d)

Get the index of first selected TAC (sw!=0) in TAC structure.

Returns
the index of first selected TACs, or <0 if not found.
See also
tacSelectedTACs, tacSelectTACs, tacSelectBestReference
Parameters
dPointer to TAC data.

Definition at line 122 of file tacselect.c.

125 {
126 if(d==NULL || d->tacNr<1) return(-1);
127 for(int i=0; i<d->tacNr; i++) if(d->c[i].sw!=0) return(i);
128 return(-1);
129}
char sw
Definition tpctac.h:77
TACC * c
Definition tpctac.h:117
int tacNr
Definition tpctac.h:91

◆ tacSelectBestReference()

int tacSelectBestReference ( TAC * d)

Select the best guess of reference region in case that several TACs were matching with tacSelectTACs().

Returns
the index of best region, or <0 in case of an error.
Author
Vesa Oikonen
See also
tacSelectTACs, tacSelectedTACs, tacEnsureNames, roinameMatch, tacIndividualNames
Parameters
dPointer to TAC structure, after using tacSelectTACs().

Definition at line 139 of file tacselect.c.

142 {
143 int ri, len, min_len, i;
144
145 if(d==NULL || d->tacNr<1) return -1;
146 if(tacSelectedTACs(d)<1) return -2;
147 for(ri=0, i=-1, min_len=9999; ri<d->tacNr; ri++) {
148 if(d->c[ri].sw==0) continue;
149 len=strlen(d->c[ri].name);
150 if(strcasestr(d->c[ri].name, "ALL")!=NULL) len-=4;
151 if(strcasestr(d->c[ri].name, "AVG")!=NULL) len-=4;
152 if(strcasestr(d->c[ri].name, "MEAN")!=NULL) len-=5;
153 if(len<min_len) {min_len=len; i=ri;}
154 }
155 if(i<0) return -2; else return i;
156}
char * strcasestr(const char *haystack, const char *needle)
Definition stringext.c:155
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
int tacSelectedTACs(TAC *d)
Definition tacselect.c:103

Referenced by tacReadReference().

◆ tacSelectedTACs()

int tacSelectedTACs ( TAC * d)

Get the number of selected TACs (sw!=0) in TAC structure.

Returns
the number of selected TACs.
Author
Vesa Oikonen
See also
tacSelectTACs, tacSelectBestReference, roinameMatch, tacIndividualNames
Parameters
dPointer to TAC data.

Definition at line 103 of file tacselect.c.

106 {
107 int ri, n;
108
109 /* Check the input */
110 if(d==NULL || d->tacNr<1) return(0);
111 /* Check each VOI */
112 for(ri=n=0; ri<d->tacNr; ri++) if(d->c[ri].sw!=0) n++;
113 return(n);
114}

Referenced by tacSelectBestReference().

◆ tacSelectTACs()

int tacSelectTACs ( TAC * d,
const char * region_name,
int reset,
TPCSTATUS * status )

Select the TAC(s) that have matching ID name or number.

Returns
the number of newly selected VOIs, or <=0 in case of an error.
Author
Vesa Oikonen
See also
tacSelectedTACs, tacSelectBestReference, roinameMatch, tacIndividualNames
Parameters
dPointer to TAC structure.
region_nameName or TAC number (as string, starting from 1) which is searched; string can be inside quotation marks. Enter NULL to select all TACs, or empty string to select TACs with empty name (which really should not exist).
reset1=Non-matching VOIs are deselected, 0=Old selections are preserved.
statusPointer to status data; enter NULL if not needed.

Definition at line 24 of file tacselect.c.

35 {
36 int verbose=0; if(status!=NULL) verbose=status->verbose;
37 if(verbose>0) printf("%s()\n", __func__);
38 /* Check that required data exists */
39 if(d==NULL || d->tacNr<1) {
40 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
41 return 0;
42 }
43
44 int ri, len, match_nr=0;
45
46 /* Check if NULL was given as tac name; if, then select all */
47 if(region_name==NULL) {
48 for(ri=0; ri<d->tacNr; ri++) d->c[ri].sw=1;
49 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
50 return(d->tacNr);
51 }
52
53 /* Reset all selections if required */
54 if(reset!=0) for(ri=0; ri<d->tacNr; ri++) d->c[ri].sw=0;
55
56 /* Remove any quotation marks from name */
57 len=strlen(region_name);
58 char local_name[len+1];
59 if(len>1) len=strncpyClean(local_name, region_name, len+1);
60 else strcpy(local_name, region_name);
61
62 /* If tac name is empty, then select all tacs with missing names */
63 if(len<1) {
64 for(ri=0; ri<d->tacNr; ri++) {
65 if(strlen(d->c[ri].name)==0) {d->c[ri].sw=1; match_nr++; continue;}
66 /* maybe here should also be checked for names consisting of only space characters */
67 }
68 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
69 return(match_nr);
70 }
71
72 /* Check each TAC name */
73 for(ri=0; ri<d->tacNr; ri++) {
74 /* does the name match? */
75 if(roinameMatch(d->c[ri].name, local_name, status)!=0) {
76 d->c[ri].sw=1; match_nr++; continue;
77 }
78 }
79 /* If at least one match was found, then we are ready */
80 if(match_nr>0) {
81 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
82 return(match_nr);
83 }
84
85 /* Next try VOI number, if region_name is suitable */
86 int n;
87 if(sscanf(local_name, "%d", &n)!=1 || n<1 || n>d->tacNr) {
88 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
89 return(0);
90 }
91 d->c[n-1].sw=1; match_nr=1;
92 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
93 return(match_nr);
94}
int roinameMatch(const char *roiname, const char *test_str, TPCSTATUS *status)
Definition roiname.c:183
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
int strncpyClean(char *s1, const char *s2, int maxlen)
Definition stringext.c:321
int verbose
Verbose level, used by statusPrint() etc.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.

Referenced by tacReadReference().