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

Find keys and values in IFT. More...

#include "tpcclibConfig.h"
#include "tpcextensions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "tpcift.h"

Go to the source code of this file.

Functions

int iftFindKey (IFT *ift, const char *key, int start_index)
 
int iftFindPair (IFT *ift, const char *key, const char *value, int start_index)
 
int iftSearchKey (IFT *ift, const char *s, int start_index)
 
int iftSearchValue (IFT *ift, const char *s, int start_index)
 
int iftFindNrOfKeys (IFT *ift, const char *key)
 
void iftDeleteKey (IFT *ift, const char *key)
 
int iftGetDoubleValue (IFT *ift, const char *key, int index, double *v)
 

Detailed Description

Find keys and values in IFT.

Definition in file iftfind.c.

Function Documentation

◆ iftDeleteKey()

void iftDeleteKey ( IFT * ift,
const char * key )

Delete all items which have the the specified key in the IFT.

Key is case insensitive.

See also
iftSearchKey, iftFindPair, iftFindKey, iftDelete, iftDeleteDuplicateKeys
Author
Vesa Oikonen
Parameters
iftPointer to existing IFT.
keyPointer to the key string.

Definition at line 169 of file iftfind.c.

174 {
175 if(ift==NULL || key==NULL || *key=='\0') return;
176 int i=0, start=0;
177 while(1) {
178 i=iftFindKey(ift, key, start); if(i<0) break;
179 iftDelete(ift, i); if(i>start) start=i;
180 }
181 return;
182}
int iftDelete(IFT *ift, int index)
Definition ift.c:206
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30

Referenced by imgFillOHeader(), and parWriteCSV().

◆ iftFindKey()

int iftFindKey ( IFT * ift,
const char * key,
int start_index )

Find the IFT item with specified key.

Search is case-insensitive, but otherwise match must be exact.

See also
iftInit, iftRead, iftFindPair, iftSearchKey, iftSearchValue, iftFindNrOfKeys, iftGetDoubleWithUnit
Returns
item index, or <0 if not found.
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
keyKey to be searched for.
start_indexIFT item index [0..keyNr-1] from which search is started.

Definition at line 30 of file iftfind.c.

37 {
38 if(ift==NULL || key==NULL) return -2;
39 if(start_index<0 || start_index>=ift->keyNr) return -2;
40 for(int i=start_index; i<ift->keyNr; i++) if(ift->item[i].key!=NULL)
41 if(strcasecmp(ift->item[i].key, key)==0) return i;
42 return -1;
43}
char * key
Definition tpcift.h:32
IFT_ITEM * item
Definition tpcift.h:57
int keyNr
Definition tpcift.h:47

Referenced by abssWrite(), ecatWriteMainheader(), iftCheckKeyValue(), iftCheckKeyValues(), iftDeleteDuplicateKeys(), iftDeleteKey(), iftGetDoubleValue(), micropetHeaderRead(), parAllocateWithTAC(), parFromIFT(), parIsOptcrit(), parIsStudyNr(), parReadCSV(), parReadFIT(), parReadRES(), parSetStudyNr(), parWriteCSV(), parWriteFIT(), parWriteRES(), tacAllocateWithPAR(), tacGetHeaderDecayCorrection(), tacGetHeaderInjectiontime(), tacGetHeaderIsotope(), tacGetHeaderScanstarttime(), tacGetHeaderStudynr(), tacGetHeaderTimeunit(), tacGetHeaderUnit(), tacRead(), tacReadAllogg(), tacReadGEMS(), tacReadOldAllogg(), tacReadScanditronics(), tacSetHeaderDecayCorrection(), tacSetHeaderInjectiontime(), tacSetHeaderIsotope(), tacSetHeaderScanstarttime(), tacSetHeaderStudynr(), tacSetHeaderTimeunit(), and tacSetHeaderUnit().

◆ iftFindNrOfKeys()

int iftFindNrOfKeys ( IFT * ift,
const char * key )

Find the nr of exact occurrences of the specified key in the IFT.

Key is case insensitive.

See also
iftSearchKey, iftFindPair, iftFindKey, iftDeleteKey
Returns
nr of occurrences of the key.
Author
Vesa Oikonen
Parameters
iftPointer to existing IFT.
keyPointer to the key string; if empty or NULL, then the nr of empty keys is returned.

Definition at line 142 of file iftfind.c.

147 {
148 if(ift==NULL) return(0);
149 int i, found_nr=0;
150 if(key==NULL || strlen(key)<1) {
151 for(i=0; i<ift->keyNr; i++)
152 if(ift->item[i].key==NULL || strlen(ift->item[i].key)<1) found_nr++;
153 return found_nr;
154 }
155 for(i=0; i<ift->keyNr; i++) if(ift->item[i].key!=NULL)
156 if(strcasecmp(ift->item[i].key, key)==0) found_nr++;
157 return found_nr;
158}

Referenced by iftCheckKeyValue(), iftCheckKeyValues(), and parFromIFT().

◆ iftFindPair()

int iftFindPair ( IFT * ift,
const char * key,
const char * value,
int start_index )

Find the IFT item with specified key and value.

Search is case-insensitive, but otherwise match must be exact.

See also
iftSearchKey, iftSearchValue, iftFindNrOfKeys, iftDeleteKey
Returns
item index, or <0 if not found.
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
keyKey to be searched for.
valueValue to be searched for.
start_indexIFT item index [0..keyNr-1] from which search is started.

Definition at line 55 of file iftfind.c.

64 {
65 if(ift==NULL || key==NULL || value==NULL) return -2;
66 if(start_index<0 || start_index>=ift->keyNr) return -2;
67 for(int i=start_index; i<ift->keyNr; i++) {
68 if(ift->item[i].key==NULL || ift->item[i].value==NULL) continue;
69 if(strcasecmp(ift->item[i].key, key)!=0) continue;
70 if(strcasecmp(ift->item[i].value, value)!=0) continue;
71 return i;
72 }
73 return -1;
74}
char * value
Definition tpcift.h:37

Referenced by tacRead().

◆ iftGetDoubleValue()

int iftGetDoubleValue ( IFT * ift,
const char * key,
int index,
double * v )

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
iftGetDoubleWithUnit, iftGetDouble, iftGetInt, iftFindKey
Parameters
iftPointer to existing IFT.
keyPointer to the key string; search is case-insensitive.
indexIndex [0..keyNr-1] from which the search is started.
vPointer to double variable where value is written; NaN is written in case of an error.

Definition at line 191 of file iftfind.c.

200 {
201 if(v!=NULL) *v=nan(""); else return(-10);
202 int li=iftFindKey(ift, key, index); if(li<0) return(li);
203 if(atofCheck(ift->item[li].value, v)!=0) return(-2);
204 return(li);
205}
int atofCheck(const char *s, double *v)
Definition decpoint.c:94

Referenced by micropetExists(), and parReadLimits().

◆ iftSearchKey()

int iftSearchKey ( IFT * ift,
const char * s,
int start_index )

Find the IFT item where key contains the given search string.

Search is case-insensitive.

See also
iftFindKey, iftSearchValue, iftFindNrOfKeys, iftDeleteKey
Returns
item index, or <0 if not found.
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
sString to be searched for in keys.
start_indexIFT item index [0..keyNr-1] from which search is started.

Definition at line 86 of file iftfind.c.

93 {
94 if(ift==NULL || s==NULL) return -2;
95 if(start_index<0 || start_index>=ift->keyNr) return -2;
96 for(int i=start_index; i<ift->keyNr; i++) {
97 if(*s!='\0') {if(strcasestr(ift->item[i].key, s)!=NULL) return i; else continue;}
98 // s is empty
99 if(ift->item[i].key==NULL || ift->item[i].key[0]=='\0') return i;
100 }
101 return -1;
102}
char * strcasestr(const char *haystack, const char *needle)
Definition stringext.c:155

Referenced by abssWrite().

◆ iftSearchValue()

int iftSearchValue ( IFT * ift,
const char * s,
int start_index )

Find the IFT item where value contains the given search string.

Search is case-insensitive.

See also
iftSearchKey, iftFindPair, iftFindKey, iftDeleteKey
Returns
item index, or <0 if not found.
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
sString to be searched for in values.
start_indexIFT item index [0..keyNr-1] from which search is started.

Definition at line 114 of file iftfind.c.

121 {
122 if(ift==NULL || s==NULL) return -2;
123 if(start_index<0 || start_index>=ift->keyNr) return -2;
124 for(int i=start_index; i<ift->keyNr; i++) {
125 if(*s!='\0') {if(strcasestr(ift->item[i].value, s)!=NULL) return i; else continue;}
126 // s is empty
127 if(ift->item[i].value==NULL || ift->item[i].value[0]=='\0') return i;
128 }
129 return -1;
130}

Referenced by parReadRES(), tacRead(), tacReadAllogg(), tacReadGEMS(), and tacReadScanditronics().