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

Search functions for IFT contents. More...

#include "libtpcmisc.h"

Go to the source code of this file.

Functions

int iftGet (IFT *ift, char *key, int verbose)
 
int iftGetNth (IFT *ift, char *key, int n, int verbose)
 
int iftFindNthKey (IFT *ift, char *str, int n, int verbose)
 
int iftFindNthValue (IFT *ift, char *str, int n, int verbose)
 
int iftGetFrom (IFT *ift, int si, const char *key, int verbose)
 
int iftGetFullmatchFrom (IFT *ift, int si, const char *key, const char *value, int verbose)
 
int iftGetFloatValue (IFT *ift, int si, const char *key, float *value, int verbose)
 
int iftGetDoubleValue (IFT *ift, int si, const char *key, double *value, int verbose)
 
int iftGetIntValue (IFT *ift, int si, const char *key, int *value, int verbose)
 
int iftGetKeyNr (IFT *ift, const char *key, int verbose)
 

Detailed Description

Search functions for IFT contents.

Author
Vesa Oikonen

Definition in file iftsrch.c.

Function Documentation

◆ iftFindNthKey()

int iftFindNthKey ( IFT * ift,
char * str,
int n,
int verbose )

Find the Nth item of IFT where the specified string is found in the key. Comparison is case sensitive.

Returns
-1 if key was not found, or other negative value in case of an error, and the index [0..keyNr-1] if matching key is found.
See also
iftFindNthValue, iftGetNth, iftGet, iftGetFrom, iftGetKeyNr, iftRead, iftReplaceNthValue
Parameters
iftPointer to IFT structure.
strPointer to the case-sensitive (partial) key string.
nNth (1..keyNr-1) incidence of value is searched.
verboseVerbose level; if zero, then only warnings are printed into stderr

Definition at line 84 of file iftsrch.c.

93 {
94 int li, found_nr=0;
95
96 if(verbose>0) printf("%s(*ift, \"%s\", %d)\n", __func__, str, n);
97 if(ift==NULL) {return(-10);}
98 if(str==NULL || strlen(str)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
99 if(n<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
100
101 /* Search the list */
102 for(li=0; li<ift->keyNr; li++) {
103 if(strstr(ift->item[li].key, str)!=NULL) {
104 found_nr++;
105 if(n==found_nr) {iftSetStatus(ift, IFT_OK); return(li);}
106 }
107 }
108 iftSetStatus(ift, IFT_KEYNOTFOUND);
109 return(-1);
110}
void iftSetStatus(IFT *ift, int status)
Definition ift.c:29
int keyNr
Definition libtpcmisc.h:270
IFT_KEY_AND_VALUE * item
Definition libtpcmisc.h:279

Referenced by cptReadOne().

◆ iftFindNthValue()

int iftFindNthValue ( IFT * ift,
char * str,
int n,
int verbose )

Find the Nth item of IFT where the specified string is found in the value. Comparison is case sensitive.

Returns
-1 if key was not found, or other negative value in case of an error, and the index [0..keyNr-1] if matching value is found.
See also
iftFindNthKey, iftGetFrom, iftGetKeyNr, iftRead, iftReplaceNthValue
Parameters
iftPointer to IFT structure.
strPointer to the case-sensitive (partial) value string.
nNth (1..keyNr-1) incidence of value is searched..
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 120 of file iftsrch.c.

129 {
130 int li, found_nr=0;
131
132 if(verbose>0) printf("%s(*ift, \"%s\", %d)\n", __func__, str, n);
133 if(ift==NULL) {return(-10);}
134 if(str==NULL || strlen(str)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
135 if(n<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
136
137 /* Search the list */
138 for(li=0; li<ift->keyNr; li++) {
139 if(strstr(ift->item[li].value, str)!=NULL) {
140 found_nr++;
141 if(n==found_nr) {iftSetStatus(ift, IFT_OK); return(li);}
142 }
143 }
144 iftSetStatus(ift, IFT_VALUENOTFOUND);
145 return(-1);
146}

Referenced by cptReadOne(), and xelRead().

◆ iftGet()

int iftGet ( IFT * ift,
char * key,
int verbose )

Find the key in the IFT and return the index [0..keyNr-1]. Key is case insensitive.

See also
iftGetNth, iftFindNthKey, iftGetFrom, iftGetKeyNr, iftRead, iftReplaceNthValue
Returns
-1 if key was not found, or other negative value in case of an error
Parameters
iftPointer to IFT structure.
keyPointer to the key string; contents are replaced by the correct key string.
verboseVerbose level; if zero, then only warnings are printed into stderr

Definition at line 15 of file iftsrch.c.

22 {
23 int li;
24
25 if(verbose>0) printf("%s(*ift, \"%s\")\n", __func__, key);
26 if(ift==NULL) {return(-10);}
27 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
28
29 /* Search the list */
30 for(li=0; li<ift->keyNr; li++) {
31 if(strcasecmp(ift->item[li].key, key)==0) {
32 strcpy(key, ift->item[li].key);
33 iftSetStatus(ift, IFT_OK); return(li);
34 }
35 }
36 iftSetStatus(ift, IFT_KEYNOTFOUND);
37 return(-1);
38}

Referenced by cptReadOne(), dft_fill_hdr_from_IFT(), ecat7CopyHeadersNoQuant(), imgGetMicropetHeader(), irdRead(), niftiHeaderFromIFT(), tsvRead(), vrdRead(), and xelRead().

◆ iftGetDoubleValue()

int iftGetDoubleValue ( IFT * ift,
int si,
const char * key,
double * value,
int verbose )

Finds the specified key string from IFT structure, and reads the corresponding value as double.

Returns
Returns the index of key/value, -1 if key or value was not found, and <-1 in case of an error.
See also
iftGetFloatValue, iftGetIntValue, iftRead
Parameters
iftPointer to existing IFT.
siIndex [0..keyNr-1] from which the search is started.
keyPointer to the key string; search is case-insensitive.
valuePointer to double variable where value is written; NaN is written in case of an error.
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 268 of file iftsrch.c.

279 {
280 int li;
281
282 if(verbose>0) printf("%s(*ift, \"%s\", *value)\n", __func__, key);
283 if(ift==NULL) {return(-10);}
284 if(value==NULL) {iftSetStatus(ift, IFT_FAULT); return(-10);}
285 *value=nan("");
286 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
287 if(si<0) {iftSetStatus(ift, IFT_FAULT); return(-12);}
288 iftSetStatus(ift, IFT_VALUENOTFOUND);
289 /* Search the list */
290 for(li=si; li<ift->keyNr; li++) {
291 if(strcasecmp(ift->item[li].key, key)==0) {
292 if(ift->item[li].value==NULL || strlen(ift->item[li].value)<1) return -1;
293 (void)sscanf(ift->item[li].value, "%lf", value);
294 if(isnan(*value)) return -1;
295 iftSetStatus(ift, IFT_OK); return(li);
296 }
297 }
298 iftSetStatus(ift, IFT_KEYNOTFOUND);
299 return(-1);
300}

Referenced by hrrtMakeCalHdr().

◆ iftGetFloatValue()

int iftGetFloatValue ( IFT * ift,
int si,
const char * key,
float * value,
int verbose )

Finds the specified key string from IFT structure, and reads the corresponding value as float.

See also
iftGetDoubleValue, iftGetIntValue
Returns
Returns the index of key/value, -1 if key or value was not found, and <-1 in case of an error.
Parameters
iftPointer to existing IFT.
siIndex [0..keyNr-1] from which the search is started.
keyPointer to the key string; search is case-insensitive.
valuePointer to float variable where value is written; NaN is written in case of an error.
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 228 of file iftsrch.c.

239 {
240 int li;
241
242 if(verbose>0) printf("%s(*ift, \"%s\", *value)\n", __func__, key);
243 if(ift==NULL) {return(-10);}
244 if(value==NULL) {iftSetStatus(ift, IFT_FAULT); return(-10);}
245 *value=nanf("");
246 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
247 if(si<0) {iftSetStatus(ift, IFT_FAULT); return(-12);}
248 iftSetStatus(ift, IFT_VALUENOTFOUND);
249 /* Search the list */
250 for(li=si; li<ift->keyNr; li++) {
251 if(strcasecmp(ift->item[li].key, key)==0) {
252 if(ift->item[li].value==NULL || strlen(ift->item[li].value)<1) return -1;
253 (void)sscanf(ift->item[li].value, "%f", value);
254 if(isnan(*value)) return -1;
255 iftSetStatus(ift, IFT_OK); return(li);
256 }
257 }
258 iftSetStatus(ift, IFT_KEYNOTFOUND);
259 return(-1);
260}

Referenced by imgGetMicropetHeader(), imgReadMicropetFrame(), niftiHeaderFromIFT(), and upetReadImagedata().

◆ iftGetFrom()

int iftGetFrom ( IFT * ift,
int si,
const char * key,
int verbose )

Finds the specified key in the IFT, starting from specified index. Key is case insensitive.

Returns
Returns the index of key/value, -1 if key or value was not found, and <-1 in case of an error.
See also
iftGetFullmatchFrom, iftFindNthValue
Parameters
iftPointer to existing IFT.
siIndex [0..keyNr-1] from which the search is started.
keyPointer to the key string; search is case-insensitive.
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 156 of file iftsrch.c.

165 {
166 int li;
167
168 if(verbose>0) printf("%s(*ift, %d, \"%s\")\n", __func__, si, key);
169 if(ift==NULL) {return(-10);}
170 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
171 if(si<0) {iftSetStatus(ift, IFT_FAULT); return(-12);}
172
173 /* Search the list */
174 for(li=si; li<ift->keyNr; li++) {
175 if(strcasecmp(ift->item[li].key, key)==0) {
176 iftSetStatus(ift, IFT_OK); return(li);
177 }
178 }
179 iftSetStatus(ift, IFT_KEYNOTFOUND);
180 return(-1);
181}

Referenced by hrrtMakeCalHdr(), and interfileIsHeader().

◆ iftGetFullmatchFrom()

int iftGetFullmatchFrom ( IFT * ift,
int si,
const char * key,
const char * value,
int verbose )

Finds the index with specified key and value in the IFT, starting from specified index. Key and value are case insensitive.

Returns
Returns the index of key/value, -1 if key or value was not found, and <-1 in case of an error.
See also
iftGetFrom, iftFindNthValue
Parameters
iftPointer to existing IFT.
siIndex [0..keyNr-1] from which the search is started.
keyPointer to the key string; search is case-insensitive.
valuePointer to the value string; search is case-insensitive.
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 191 of file iftsrch.c.

202 {
203 int li;
204
205 if(verbose>0) printf("%s(*ift, %d, \"%s\", \"%s\")\n", __func__, si, key, value);
206 if(ift==NULL) {return(-10);}
207 if(key==NULL) {iftSetStatus(ift, IFT_FAULT); return(-11);}
208 if(value==NULL) {iftSetStatus(ift, IFT_FAULT); return(-12);}
209 if(si<0) {iftSetStatus(ift, IFT_FAULT); return(-13);}
210
211 /* Search the list */
212 for(li=si; li<ift->keyNr; li++) {
213 if(strcasecmp(ift->item[li].key, key)!=0) continue;
214 if(strcasecmp(ift->item[li].value, value)!=0) continue;
215 iftSetStatus(ift, IFT_OK); return(li);
216 }
217 iftSetStatus(ift, IFT_KEYNOTFOUND);
218 return(-1);
219}

Referenced by imgReadMicropetFrame(), and upetReadImagedata().

◆ iftGetIntValue()

int iftGetIntValue ( IFT * ift,
int si,
const char * key,
int * value,
int verbose )

Finds the specified key string from IFT structure, and reads the corresponding value as int.

Returns
Returns the index of key/value, -1 if key or value was not found, and <-1 in case of an error.
See also
iftGetKeyNr, iftGetDoubleValue
Parameters
iftPointer to existing IFT.
siIndex [0..keyNr-1] from which the search is started.
keyPointer to the key string; search is case-insensitive.
valuePointer to int variable where value is written; -9999 is written in case of an error.
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 309 of file iftsrch.c.

320 {
321 int li;
322
323 if(verbose>0) printf("%s(*ift, \"%s\", *value)\n", __func__, key);
324 if(ift==NULL) {return(-10);}
325 if(value==NULL) {iftSetStatus(ift, IFT_FAULT); return(-10);}
326 *value=-9999;
327 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
328 if(si<0) {iftSetStatus(ift, IFT_FAULT); return(-12);}
329 /* Search the list */
330 iftSetStatus(ift, IFT_VALUENOTFOUND);
331 for(li=si; li<ift->keyNr; li++) {
332 if(strcasecmp(ift->item[li].key, key)==0) {
333 if(ift->item[li].value==NULL || strlen(ift->item[li].value)<1) return -1;
334 (void)sscanf(ift->item[li].value, "%d", value);
335 if(*value==-9999) return -1;
336 iftSetStatus(ift, IFT_OK); return(li);
337 }
338 }
339 iftSetStatus(ift, IFT_KEYNOTFOUND);
340 return(-1);
341}

Referenced by hrrtMakeCalHdr(), imgGetMicropetHeader(), niftiHeaderFromIFT(), and upetReadImagedata().

◆ iftGetKeyNr()

int iftGetKeyNr ( IFT * ift,
const char * key,
int verbose )

Find the nr of occurrences of the specified key in the IFT. Key is case insensitive.

See also
iftFindNthValue
Returns
Returns the nr of occurrences of the key.
Parameters
iftPointer to existing IFT
keyPointer to the key string
verboseVerbose level; if zero, then only warnings are printed into stderr

Definition at line 350 of file iftsrch.c.

357 {
358 int li, found_nr=0;
359
360 if(verbose>0) printf("%s(*ift, \"%s\")\n", __func__, key);
361 if(ift==NULL) {return(0);}
362 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(0);}
363 iftSetStatus(ift, IFT_KEYNOTFOUND);
364
365 /* Search the list */
366 for(li=0; li<ift->keyNr; li++) if(strcasecmp(ift->item[li].key, key)==0) found_nr++;
367 if(found_nr>0) iftSetStatus(ift, IFT_OK);
368 else iftSetStatus(ift, IFT_KEYNOTFOUND);
369 return(found_nr);
370}

◆ iftGetNth()

int iftGetNth ( IFT * ift,
char * key,
int n,
int verbose )

Find the Nth key with similar name in the IFT and return the index [0..keyNr-1]. Key is case insensitive.

See also
iftFindNthKey, iftGet, iftGetFrom, iftGetKeyNr, iftRead, iftReplaceNthValue
Returns
-1 if key was not found, or other negative value in case of an error
Parameters
iftpointer to IFT structure.
keyPointer to the key string; contents are replaced by the correct key string.
nNth (1..) incidence of key is searched.
verboseVerbose level; if zero, then only warnings are printed into stderr.

Definition at line 48 of file iftsrch.c.

57 {
58 int li, found_nr=0;
59
60 if(verbose>0) printf("%s(*ift, \"%s\", %d)\n", __func__, key, n);
61 if(ift==NULL) {return(-10);}
62 if(key==NULL || strlen(key)<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
63 if(n<1) {iftSetStatus(ift, IFT_FAULT); return(-11);}
64
65 /* Search the list */
66 for(li=0; li<ift->keyNr; li++) {
67 if(strcasecmp(ift->item[li].key, key)==0) {
68 strcpy(key, ift->item[li].key); found_nr++;
69 if(n==found_nr) {iftSetStatus(ift, IFT_OK); return(li);}
70 }
71 }
72 iftSetStatus(ift, IFT_KEYNOTFOUND);
73 return(-1);
74}

Referenced by dft_fill_hdr_from_IFT(), and tsvRead().