TPCCLIB
Loading...
Searching...
No Matches
tpcift.h File Reference

Header file for library libtpcift. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "tpcextensions.h"

Go to the source code of this file.

Data Structures

struct  IFT_ITEM
struct  IFT

Functions

void iftInit (IFT *ift)
void iftFree (IFT *ift)
int iftPut (IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
int iftPutDouble (IFT *ift, const char *key, const double value, char comment, TPCSTATUS *status)
int iftPutInt (IFT *ift, const char *key, const int value, char comment, TPCSTATUS *status)
int iftPutUInt (IFT *ift, const char *key, const unsigned int value, char comment, TPCSTATUS *status)
int iftDelete (IFT *ift, int index)
int iftDuplicate (IFT *ift1, IFT *ift2)
int iftReplaceValue (IFT *ift, int i, const char *value, TPCSTATUS *status)
int iftReplaceKey (IFT *ift, int i, const char *key, TPCSTATUS *status)
int iftDeleteDuplicateKeys (IFT *ift, TPCSTATUS *status)
int iftCopyItems (IFT *ift1, IFT *ift2, int is_key_required, int is_value_required, int is_comment_accepted, TPCSTATUS *status)
int iftWrite (IFT *ift, FILE *fp, TPCSTATUS *status)
int iftWriteItem (IFT *ift, int item, FILE *fp, TPCSTATUS *status)
int iftRead (IFT *ift, FILE *fp, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
int iftPutFromString (IFT *ift, const char *line, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
int iftPutFromStringWithSpaceSeparator (IFT *ift, const char *line, int is_comment_accepted, TPCSTATUS *status)
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)
int iftGetFloat (IFT *ift, int index, float *v)
int iftGetDouble (IFT *ift, int index, double *v)
int iftGetInt (IFT *ift, int index, int *v)
int iftGetUInt (IFT *ift, int index, unsigned int *v)
int iftGetDoubleWithUnit (IFT *ift, int index, double *v, int *unit)

Detailed Description

Header file for library libtpcift.

Interfile-type header information processing and file i/o

Author
Vesa Oikonen

Definition in file tpcift.h.

Function Documentation

◆ iftCopyItems()

int iftCopyItems ( IFT * ift1,
IFT * ift2,
int is_key_required,
int is_value_required,
int is_comment_accepted,
TPCSTATUS * status )
extern

Copy items from one IFT struct into another.

Duplicates, empty source, or no copied items are not considered as errors.

See also
iftDeleteDuplicateKeys, iftPut
Returns
tpcerror (TPCERROR_OK when successful).
Parameters
ift1Pointer to target IFT.
ift2Pointer to source IFT.
is_key_requiredSpecifies whether items without key name are copied (0) or not (1).
is_value_requiredSpecifies whether items without value are copied (0) or not (1).
is_comment_acceptedSpecifies whether comment items are copied or not.
  • 0 = comment lines are not copied,
  • 1 = also comment lines are copied,
  • 2 = only comment lines are copied.
statusPointer to status data; enter NULL if not needed

Definition at line 386 of file ift.c.

402 {
403 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
404 if(ift1==NULL) return TPCERROR_FAIL;
405 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
406 if(verbose>0)
407 printf("%s(*ift1, *ift2, %d, %d, %d, status)\n", __func__,
408 is_key_required, is_value_required, is_comment_accepted);
409 if(ift2==NULL || ift2->keyNr<1) {
410 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
411 return TPCERROR_OK;
412 }
413
414 /* Copy the appropriate items */
415 int n=0;
416 for(int i=0; i<ift2->keyNr; i++) {
417 if(is_key_required && (ift2->item[i].key==NULL || strlen(ift2->item[i].key)<1)) continue;
418 if(is_value_required && (ift2->item[i].value==NULL || strlen(ift2->item[i].value)<1)) continue;
419 if(ift2->item[i].comment!=0 && is_comment_accepted==0) continue;
420 if(ift2->item[i].comment==0 && is_comment_accepted==2) continue;
421 int ret=iftPut(ift1, ift2->item[i].key, ift2->item[i].value, ift2->item[i].comment, status);
422 if(ret!=TPCERROR_OK) return(status->error);
423 n++;
424 }
425 if(verbose>1) printf(" %d item(s) copied.\n", n);
426
427 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
428 return TPCERROR_OK;
429}
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition ift.c:63
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
char comment
Definition tpcift.h:27
char * value
Definition tpcift.h:37
char * key
Definition tpcift.h:32
IFT_ITEM * item
Definition tpcift.h:57
int keyNr
Definition tpcift.h:47
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.

◆ iftDelete()

int iftDelete ( IFT * ift,
int index )
extern

Remove the specified item from IFT struct.

See also
iftFree, iftPut, iftDeleteKey, iftFindKey, iftDeleteDuplicateKeys
Returns
tpcerror, TPCERROR_OK (0) when successful.
Author
Vesa Oikonen
Parameters
iftPointer to existing IFT
indexIndex [0..keyNr-1] of key and value

Definition at line 206 of file ift.c.

211 {
212 if(ift==NULL) return TPCERROR_FAIL;
213 if(index<0 || index>=ift->keyNr) return TPCERROR_NO_KEY;
214
215 free(ift->item[index].key); ift->item[index].key=NULL;
216 free(ift->item[index].value); ift->item[index].value=NULL;
217 ift->item[index].key=ift->item[index].value=NULL;
218 for(int i=index+1; i<ift->keyNr; i++) {
219 ift->item[i-1].comment=ift->item[i].comment;
220 ift->item[i-1].sw=ift->item[i].sw;
221 ift->item[i-1].key=ift->item[i].key;
222 ift->item[i-1].value=ift->item[i].value;
223 ift->item[i].key=ift->item[i].value=NULL;
224 }
225 ift->keyNr--;
226 return(0);
227}
short int sw
Definition tpcift.h:29
@ TPCERROR_NO_KEY
Key not found.

Referenced by dcmFileList(), iftDeleteDuplicateKeys(), iftDeleteKey(), parReadCSV(), parSetStudyNr(), tacReadAllogg(), tacReadGEMS(), tacReadOldAllogg(), tacReadScanditronics(), tacSetHeaderDecayCorrection(), tacSetHeaderInjectiontime(), tacSetHeaderIsotope(), tacSetHeaderScanstarttime(), tacSetHeaderStudynr(), tacSetHeaderTimeunit(), and tacSetHeaderUnit().

◆ iftDeleteDuplicateKeys()

int iftDeleteDuplicateKeys ( IFT * ift,
TPCSTATUS * status )
extern

Find and delete items that have similar key names.

The first occurrence of the key is kept. Search is case-insensitive, but otherwise key name match must be exact.

See also
iftDeleteKey, iftFindKey, iftCopyItems
Returns
tpcerror (TPCERROR_OK when successful).
Parameters
iftPointer to IFT.
statusPointer to status data; enter NULL if not needed

Definition at line 348 of file ift.c.

353 {
354 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
355 if(ift==NULL) return TPCERROR_FAIL;
356 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
357 if(verbose>0) printf("%s()\n", __func__);
358 if(ift->keyNr<2) {
359 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
360 return TPCERROR_OK;
361 }
362
363 /* Go through the (remaining) items */
364 int i=0;
365 while(i<ift->keyNr-1) {
366 int j=i+1;
367 while(j<ift->keyNr) {
368 int k=iftFindKey(ift, ift->item[i].key, j);
369 if(k>=0) iftDelete(ift, k); else j++;
370 }
371 i++;
372 }
373 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
374 return TPCERROR_OK;
375}
int iftDelete(IFT *ift, int index)
Definition ift.c:206
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30

◆ iftDeleteKey()

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

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}

Referenced by imgFillOHeader(), and parWriteCSV().

◆ iftDuplicate()

int iftDuplicate ( IFT * ift1,
IFT * ift2 )
extern

Make a copy (duplicate) of an IFT struct.

See also
iftInit, iftDeleteKey, iftDeleteDuplicateKeys
Returns
tpcerror, TPCERROR_OK (0) when successful.
Author
Vesa Oikonen
Parameters
ift1Pointer to source IFT struct to be copied
ift2Pointer to initiated target IFT struct; any previous contents are deleted.

Definition at line 236 of file ift.c.

241 {
242 if(ift1==NULL || ift2==NULL) return TPCERROR_FAIL;
243 /* Empty the new IFT */
244 iftFree(ift2);
245
246 /* Copy the contents */
247 ift2->type=ift1->type;
249 ift2->space_after_eq=ift1->space_after_eq;
250 int ret;
251 for(int i=0; i<ift1->keyNr; i++) {
252 ret=iftPut(ift2, ift1->item[i].key, ift1->item[i].value, ift1->item[i].comment, NULL);
253 if(ret!=TPCERROR_OK) {iftFree(ift2); return(ret);}
254 ift2->item[i].sw=ift1->item[i].sw;
255 }
256 // keyNr was set by iftPut()
257 return TPCERROR_OK;
258}
void iftFree(IFT *ift)
Definition ift.c:37
int space_after_eq
Definition tpcift.h:55
int type
Definition tpcift.h:51
int space_before_eq
Definition tpcift.h:53

Referenced by imgFillOHeader(), parReadCSV(), tacCopyHdr(), tacReadAllogg(), tacReadCSV(), tacReadDFT(), tacReadGEMS(), tacReadOldAllogg(), tacReadPMOD(), tacReadScanditronics(), tacReadSimple(), tacWriteCSV(), and tacWriteDFT().

◆ iftFindKey()

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

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}

Referenced by abssWrite(), ecatWriteMainheader(), iftCheckKeyValue(), iftCheckKeyValues(), iftDeleteDuplicateKeys(), iftDeleteKey(), iftGetDoubleValue(), mfCreateTAC(), 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 )
extern

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 )
extern

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}

Referenced by tacRead().

◆ iftFree()

void iftFree ( IFT * ift)
extern

Free memory allocated for IFT data. All contents are destroyed.

Precondition
Before first use initialize the IFT struct with iftInit().
See also
iftInit
Author
Vesa Oikonen
Parameters
iftPointer to IFT

Definition at line 37 of file ift.c.

40 {
41 int i;
42
43 if(ift==NULL) return;
44 for(i=0; i<ift->_memNr; i++) {
45 free(ift->item[i].key);
46 free(ift->item[i].value);
47 }
48 free(ift->item); ift->item=NULL; ift->_memNr=ift->keyNr=0;
49 iftInit(ift);
50}
void iftInit(IFT *ift)
Definition ift.c:21
int _memNr
Definition tpcift.h:45

Referenced by dcmFileList(), dcmFileRemove(), iftDuplicate(), imgFree(), imgRead(), micropetExists(), micropetHeaderRead(), parFree(), parRead(), parReadLimits(), parWriteIFT(), parWriteLimits(), pathRemoveFiles(), tacCopyHdr(), tacFree(), tacRead(), tacWriteCSV(), and tacWriteDFT().

◆ iftGetDouble()

int iftGetDouble ( IFT * ift,
int index,
double * v )
extern

Read the value in IFT as a double from given item index.

Value in IFT must not contain decimal comma.

See also
iftGetFloat, iftGetDoubleWithUnit, iftFindKey, iftPutDouble
Returns
0 if successful, <>0 in case of an error.
Author
Vesa Oikonen
Parameters
iftPointer to IFT
indexIFT item index
vPointer to double which is read from item value. It will be set to NaN in case of an error.

Definition at line 52 of file iftget.c.

60 {
61 if(v!=NULL) *v=nan(""); else return -2;
62 if(ift==NULL) return -2;
63 if(index<0 || index>=ift->keyNr) return -2;
64 if(ift->item[index].value==NULL) return -1;
65 if(sscanf(ift->item[index].value, "%lf", v)!=1 || isnan(*v)) return -1;
66 return 0;
67}

Referenced by parFromIFT().

◆ iftGetDoubleValue()

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

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().

◆ iftGetDoubleWithUnit()

int iftGetDoubleWithUnit ( IFT * ift,
int index,
double * v,
int * unit )
extern

Read the value in IFT as a double with unit from given item index.

Value in IFT is allowed to be written with decimal comma, and units may be written in pars () or [].

See also
iftGetDouble, iftFindKey, iftSearchKey, iftSearchValue
Returns
0 if at least the double was found, otherwise <>0.
Author
Vesa Oikonen
Parameters
iftPointer to IFT
indexIFT item index
vPointer to double which is read from item value. It will be set to NaN in case of an error.
unitPointer for unit (enum unit) which is read from item value. It will be to 0 (enum UNIT_UNKNOWN) if not identified or not present.

Definition at line 129 of file iftget.c.

140 {
141 if(v!=NULL) *v=nan("");
142 if(unit!=NULL) *unit=UNIT_UNKNOWN;
143 if(ift==NULL) return(2);
144 if(index<0 || index>=ift->keyNr) return(1);
145 if(ift->item[index].value==NULL) return(2);
146 char s[128];
147 if(strTokenNCpy(ift->item[index].value, " \t", 1, s, 128)==0) return(2);
148 if(v!=NULL) *v=atofVerified(s);
149 if(unit==NULL) return(0);
150 if(strTokenNCpy(ift->item[index].value, " \t", 2, s, 128)==0) return(0);
152 return 0;
153}
double atofVerified(const char *s)
Definition decpoint.c:75
void strCleanPars(char *s)
Definition stringext.c:476
int strTokenNCpy(const char *s1, const char *s2, int i, char *s3, int count)
Definition stringext.c:53
unit
@ UNIT_UNKNOWN
Unknown unit.
int unitIdentify(const char *s)
Definition units.c:162

Referenced by parReadCSV().

◆ iftGetFloat()

int iftGetFloat ( IFT * ift,
int index,
float * v )
extern

Read the value in IFT as a float from given item index.

Value in IFT must not contain decimal comma.

See also
iftGetDouble, iftFindKey, iftGetInt, iftSearchKey
Returns
0 if successful, <>0 in case of an error.
Author
Vesa Oikonen
Parameters
iftPointer to IFT
indexIFT item index
vPointer to float which is read from item value. It will be set to NaN in case of an error.

Definition at line 25 of file iftget.c.

33 {
34 if(v!=NULL) *v=nanf(""); else return -2;
35 if(ift==NULL) return -2;
36 if(index<0 || index>=ift->keyNr) return -2;
37 if(ift->item[index].value==NULL) return -1;
38 if(sscanf(ift->item[index].value, "%f", v)!=1 || isnan(*v)) return -1;
39 return 0;
40}

◆ iftGetInt()

int iftGetInt ( IFT * ift,
int index,
int * v )
extern

Read the value in IFT as an integer from given item index.

See also
iftGetUInt, iftGetDouble, iftFindKey, iftGetUInt, iftPutInt
Returns
0 if successful, <>0 in case of an error.
Author
Vesa Oikonen
Parameters
iftPointer to IFT
indexIFT item index
vPointer to int which is read from item value. It will be set to -9999 in case of an error.

Definition at line 76 of file iftget.c.

84 {
85 if(v!=NULL) *v=-9999; else return -2;
86 if(ift==NULL) return -2;
87 if(index<0 || index>=ift->keyNr) return -2;
88 if(ift->item[index].value==NULL) return -1;
89 if(sscanf(ift->item[index].value, "%d", v)!=1 || *v==-9999) return -1;
90 return 0;
91}

Referenced by parFromIFT(), and parReadCSV().

◆ iftGetUInt()

int iftGetUInt ( IFT * ift,
int index,
unsigned int * v )
extern

Read the value in IFT as an unsigned integer from given item index.

See also
iftGetDouble, iftFindKey, iftSearchKey, iftSearchValue, iftGetInt, iftPutUint
Returns
0 if successful, <>0 in case of an error.
Author
Vesa Oikonen
Parameters
iftPointer to IFT
indexIFT item index
vPointer to unsigned int which is read from item value. It will be set to 0 in case of an error.

Definition at line 101 of file iftget.c.

109 {
110 if(v!=NULL) *v=0; else return -2;
111 if(ift==NULL) return -2;
112 if(index<0 || index>=ift->keyNr) return -2;
113 if(ift->item[index].value==NULL) return -1;
114 if(sscanf(ift->item[index].value, "%ud", v)!=1) return -1;
115 return 0;
116}

Referenced by parFromIFT().

◆ iftInit()

void iftInit ( IFT * ift)
extern

Initiate the IFT struct before any use.

See also
iftFree, iftDuplicate
Author
Vesa Oikonen
Parameters
iftPointer to IFT

Definition at line 21 of file ift.c.

24 {
25 if(ift==NULL) return;
26 ift->_memNr=ift->keyNr=0; ift->item=NULL; ift->type=0;
28}

Referenced by dcmFileRemove(), iftFree(), imgInit(), imgRead(), micropetExists(), micropetHeaderRead(), parInit(), parRead(), parReadLimits(), parWriteIFT(), parWriteLimits(), pathRemoveFiles(), tacInit(), tacRead(), tacWriteCSV(), and tacWriteDFT().

◆ iftPut()

int iftPut ( IFT * ift,
const char * key,
const char * value,
char comment,
TPCSTATUS * status )
extern

Add specified key and its value to the IFT.

Either key or value can be empty, but not both of them.

See also
iftInit, iftFree, iftDelete, iftDeleteKey, iftPutDouble, iftCopyItems
Returns
tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT struct with iftInit().
Author
Vesa Oikonen
Parameters
iftPointer to initiated IFT; previous contents are not changed
keyKey string; can be empty ("" or NULL)
valueValue string; can be empty ("" or NULL)
commentIs this comment line, or line that is commented out?
  • 0: not a comment line
  • 1: line will be started with '#'
statusPointer to status data; enter NULL if not needed

Definition at line 63 of file ift.c.

76 {
77 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
78 if(ift==NULL) return TPCERROR_FAIL;
79 if((key==NULL || strlen(key)<1) && (value==NULL || strlen(value)<1)) return TPCERROR_FAIL;
80 int verbose=0; if(status!=NULL) verbose=status->verbose;
81 if(verbose>10) {
82 printf("iftPut(ift, ");
83 if(key!=NULL) printf("\"%s\", ", key); else printf("NULL, ");
84 if(value!=NULL) printf("\"%s\", ", value); else printf("NULL, ");
85 printf("%d)\n", comment);
86 fflush(stdout);
87 }
88
89 /* If necessary, allocate more memory for items */
90 if(ift->_memNr<=ift->keyNr) {
91 int i, add_nr=20;
92 ift->item=(IFT_ITEM*)realloc(ift->item, (ift->_memNr+add_nr)*sizeof(IFT_ITEM));
93 if(ift->item==NULL) {
94 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OUT_OF_MEMORY);
96 }
97 for(i=ift->_memNr; i<ift->_memNr+add_nr; i++) {
98 ift->item[i].comment=(char)0;
99 ift->item[i].sw=(short int)0;
100 ift->item[i].key=NULL;
101 ift->item[i].value=NULL;
102 }
103 ift->_memNr+=add_nr;
104 }
105
106 /* Set the contents */
107 /* type */
108 if(comment!=0) ift->item[ift->keyNr].comment=(char)1;
109 /* key (do not put NULL because it would segfault in std functions) */
110 if(key!=NULL) ift->item[ift->keyNr].key=strdup(key);
111 else ift->item[ift->keyNr].key=strdup("");
112 /* value (do not put NULL because it would segfault in std functions) */
113 if(value!=NULL) ift->item[ift->keyNr].value=strdup(value);
114 else ift->item[ift->keyNr].value=strdup("");
115
116 ift->keyNr++;
117 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
118 return TPCERROR_OK;
119}
char * strdup(const char *s)
Definition stringext.c:185
@ TPCERROR_OUT_OF_MEMORY
Cannot allocate memory.

Referenced by dcmFileList(), ecatReadMainheader(), iftCopyItems(), iftDuplicate(), iftPutDouble(), iftPutFromString(), iftPutFromStringWithSpaceSeparator(), iftPutInt(), iftPutUInt(), imgFillOHeader(), parAllocateWithTAC(), parExamplePerfectBolus(), parExampleRadiowaterBolus(), parExampleTTACs(), parFromIFT(), parReadFIT(), parReadRES(), parSetStudyNr(), parToIFT(), parWriteCSV(), pathFileList(), tacAllocateWithPAR(), tacReadGEMS(), tacReadScanditronics(), tacSetHeaderDecayCorrection(), tacSetHeaderInjectiontime(), tacSetHeaderIsotope(), tacSetHeaderScanstarttime(), tacSetHeaderStudynr(), tacSetHeaderTimeunit(), and tacSetHeaderUnit().

◆ iftPutDouble()

int iftPutDouble ( IFT * ift,
const char * key,
const double value,
char comment,
TPCSTATUS * status )
extern

Add specified key and its floating point (double) value to the IFT.

See also
iftInit, iftPut, iftPutFromString, iftPutInt, iftGetDouble
Returns
tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT structure with iftInit().
Parameters
iftPointer to initiated IFT; previous contents are not changed
keyKey string; can be empty ("" or NULL).
valueValue as double.
commentIs this comment line, or line that is commented out?
  • 0: not a comment line
  • 1: line will be started with '#'
statusPointer to status data; enter NULL if not needed.

Definition at line 128 of file ift.c.

141 {
142 char dstr[128];
143 sprintf(dstr, "%g", value);
144 return(iftPut(ift, key, dstr, comment, status));
145}

Referenced by parWriteLimits().

◆ iftPutFromString()

int iftPutFromString ( IFT * ift,
const char * line,
int is_key_required,
int is_comment_accepted,
TPCSTATUS * status )
extern

Process a given string to add key and value to IFT.

Either key or value can be empty, but not both of them.

See also
iftInit, iftDuplicate
Returns
tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT struct with iftInit().
Author
Vesa Oikonen
Parameters
iftPointer to initiated IFT; previous contents are not changed.
linePointer to the string to be processed, e.g. "key := value"; extra space characters are excluded from key and value.
is_key_requiredSpecifies whether key name is required or not. If not required, then line contents without equals sign are assumed to represent a value string and key name in IFT struct is left empty.
  • 0 = key name is not required,
  • 1 = only lines with key and equals sign are read,
  • 2 = only lines with key and value separated by space are read.
is_comment_acceptedSpecifies whether comment lines are processed or not.
  • 0 = comment lines are not read,
  • 1 = also comment lines are read,
  • 2 = only comment lines are read.
statusPointer to status data; enter NULL if not needed.

Definition at line 229 of file iftio.c.

248 {
249 if(ift==NULL) return TPCERROR_FAIL;
250 if(line==NULL || strlen(line)<1) {
251 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
252 return TPCERROR_NO_DATA;
253 }
254 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
255 if(verbose>10) {
256 printf("%s(ift, ", __func__);
257 if(line!=NULL) printf("\"%s\", ", line); else printf("NULL, ");
258 printf("%d, %d)\n", is_key_required, is_comment_accepted);
259 fflush(stdout);
260 }
261 if(is_key_required==2) { // If space is used as separator
262 return(iftPutFromStringWithSpaceSeparator(ift, line, is_comment_accepted, status));
263 }
264
265 /* Check if line is a comment line */
266 char *lptr=(char*)line; int i; char cmt;
267 if(asciiCommentLine(lptr, &i)) {cmt=(char)1; lptr+=i;} else cmt=(char)0;
268 /* If comment line requirement is not met, then return here */
269 if((is_comment_accepted==0 && cmt) || (is_comment_accepted==2 && !cmt)) {
270 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
271 return TPCERROR_OK;
272 }
273
274 /* Find the 'equals' sign, ':=', '=', or ':' */
275 char *eq_ptr;
276 eq_ptr=strstrNoQuotation(lptr, ":=");
277 if(eq_ptr==NULL) eq_ptr=strstrNoQuotation(lptr, "=");
278 /* If not yet found, try ':' but it must not be part of time or Windows path, for example 'C:\tmp' */
279 char *cptr2=lptr;
280 while(eq_ptr==NULL) {
281 if(verbose>100) printf("cptr2 := '%s'\n", cptr2);
282 eq_ptr=strstrNoQuotation(cptr2, ":"); if(eq_ptr==NULL) break;
283 if(eq_ptr[1]=='\\') {
284 /* ok ':' was part of windows path ... but search for later equals sign */
285 cptr2=eq_ptr+2; eq_ptr=NULL; continue;
286 }
287 if(verbose>100) printf("eq_ptr := '%s'\n", eq_ptr);
288 if(strlen(cptr2)-strlen(eq_ptr)<2) break; // cannot be time
289 if(verbose>100) printf("is this time '%s'\n", eq_ptr-2);
290 if(strTimeValid(eq_ptr-2)>0) break; // was not time
291 /* ok ':' was part of time ... but search for later equals sign */
292 if(verbose>100) printf("yes it was\n");
293 cptr2=eq_ptr+6; eq_ptr=NULL;
294 }
295
296 /* We must have equals sign if key is required */
297 if(is_key_required!=0 && eq_ptr==NULL) {
298 if(verbose>50) printf("key required but equals sign not found\n");
299 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_KEY);
300 return TPCERROR_NO_KEY;
301 }
302
303 char *key=NULL, *value=NULL;
304 if(eq_ptr==NULL) {
305 /* No key */
306 key=strndup("", 0);
307 /* then value is the whole string, excluding comment */
308 value=strndup(lptr, strlen(lptr)); strClean(value);
309 } else {
310 /* key starts after comment */
311 key=strndup(lptr, strlen(lptr)-strlen(eq_ptr));
312 if(verbose>100) printf("key before cleaning is '%s'\n", key);
313 strClean(key);
314 if(verbose>100) printf("key after cleaning is '%s'\n", key);
315 /* Find the end of the 'equals' sign; that is the start of value */
316 int j=strspn(eq_ptr, ":="); value=strdup(eq_ptr+j);
317 if(verbose>100) printf("value before cleaning is '%s'\n", value);
318 strClean(value);
319 if(verbose>100) printf("value after cleaning is '%s'\n", value);
320 }
321
322 int ret=iftPut(ift, key, value, cmt, status);
323 free(key); free(value);
324 if(ret==0) statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
325 return ret;
326}
int strTimeValid(const char *str)
Definition datetime.c:284
int iftPutFromStringWithSpaceSeparator(IFT *ift, const char *line, int is_comment_accepted, TPCSTATUS *status)
Definition iftio.c:339
int asciiCommentLine(const char *line, int *cont)
char * strstrNoQuotation(const char *haystack, const char *needle)
Definition stringext.c:225
int strClean(char *s)
Definition stringext.c:389
char * strndup(const char *s, size_t n)
Definition stringext.c:205
@ TPCERROR_NO_DATA
File contains no data.

Referenced by iftRead().

◆ iftPutFromStringWithSpaceSeparator()

int iftPutFromStringWithSpaceSeparator ( IFT * ift,
const char * line,
int is_comment_accepted,
TPCSTATUS * status )
extern

Process a given string to add key and value to IFT.

Key and value must be present, with space character as the field separator.

See also
iftInit, iftDuplicate
Returns
tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT struct with iftInit().
Author
Vesa Oikonen
Parameters
iftPointer to initiated IFT; previous contents are not changed.
linePointer to the string to be processed, e.g. "key value"; extra space characters are excluded from key and value.
is_comment_acceptedSpecifies whether comment lines are processed or not.
  • 0 = comment lines are not read,
  • 1 = also comment lines are read,
  • 2 = only comment lines are read.
statusPointer to status data; enter NULL if not needed.

Definition at line 339 of file iftio.c.

352 {
353 if(ift==NULL) return TPCERROR_FAIL;
354 if(line==NULL || strlen(line)<1) {
355 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
356 return TPCERROR_NO_DATA;
357 }
358 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
359 if(verbose>10) {
360 printf("%s(ift, ", __func__);
361 if(line!=NULL) printf("\"%s\", ", line); else printf("NULL, ");
362 printf("%d)\n", is_comment_accepted);
363 }
364
365 /* Check if line is a comment line */
366 char *lptr=(char*)line; int i; char cmt;
367 if(asciiCommentLine(lptr, &i)) {cmt=(char)1; lptr+=i;} else cmt=(char)0;
368 /* If comment line requirement is not met, then return here */
369 if((is_comment_accepted==0 && cmt) || (is_comment_accepted==2 && !cmt)) {
370 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
371 return TPCERROR_OK;
372 }
373
374 /* Find the 'equals' sign, ' ' or '\t' */
375 char *eq_ptr;
376 eq_ptr=strstrNoQuotation(lptr, " ");
377 if(eq_ptr==NULL) eq_ptr=strstrNoQuotation(lptr, "\t");
378
379 /* key is required */
380 if(eq_ptr==NULL) {
381 if(verbose>50) printf("key required but space not found\n");
382 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_KEY);
383 return TPCERROR_NO_KEY;
384 }
385
386 char *key=NULL, *value=NULL;
387 /* key starts after comment */
388 key=strndup(lptr, strlen(lptr)-strlen(eq_ptr));
389 if(verbose>100) printf("key before cleaning is '%s'\n", key);
390 strClean(key);
391 if(verbose>100) printf("key after cleaning is '%s'\n", key);
392 /* Find the end of the 'equals' sign; that is the start of value */
393 int j=strspn(eq_ptr, " \t"); value=strdup(eq_ptr+j);
394 if(verbose>100) printf("value before cleaning is '%s'\n", value);
395 strClean(value);
396 if(verbose>100) printf("value after cleaning is '%s'\n", value);
397
398 int ret=iftPut(ift, key, value, cmt, status);
399 free(key); free(value);
400 if(ret==0) statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
401 return ret;
402}

Referenced by iftPutFromString(), and iftRead().

◆ iftPutInt()

int iftPutInt ( IFT * ift,
const char * key,
const int value,
char comment,
TPCSTATUS * status )
extern

Add specified key and its integer (signed) value to the IFT.

See also
iftInit, iftPut, iftPutFromString, iftPutUint, iftPutDouble, iftGetInt
Returns
tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT structure with iftInit().
Parameters
iftPointer to initiated IFT; previous contents are not changed
keyKey string; can be empty ("" or NULL).
valueValue as int.
commentIs this comment line, or line that is commented out?
  • 0: not a comment line
  • 1: line will be started with '#'
statusPointer to status data; enter NULL if not needed.

Definition at line 154 of file ift.c.

167 {
168 char dstr[128];
169 sprintf(dstr, "%d", value);
170 return(iftPut(ift, key, dstr, comment, status));
171}

◆ iftPutUInt()

int iftPutUInt ( IFT * ift,
const char * key,
const unsigned int value,
char comment,
TPCSTATUS * status )
extern

Add specified key and its integer (unsigned) value to the IFT.

See also
iftInit, iftPut, iftPutFromString, iftPutInt, iftPutDouble, iftGetUint
Returns
tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT structure with iftInit().
Parameters
iftPointer to initiated IFT; previous contents are not changed
keyKey string; can be empty ("" or NULL).
valueValue as int.
commentIs this comment line, or line that is commented out?
  • 0: not a comment line
  • 1: line will be started with '#'
statusPointer to status data; enter NULL if not needed.

Definition at line 180 of file ift.c.

193 {
194 char dstr[128];
195 sprintf(dstr, "%u", value);
196 return(iftPut(ift, key, dstr, comment, status));
197}

Referenced by imgFillOHeader().

◆ iftRead()

int iftRead ( IFT * ift,
FILE * fp,
int is_key_required,
int is_comment_accepted,
TPCSTATUS * status )
extern

Read IFT data into IFT structure.

Any previous contents of IFT are preserved. This function can read the initial ASCII part of files that contain also binary data in the end (from some Interfile images), but not the binary data itself.

See also
iftInit, iftWrite, iftFree
Returns
enum tpcerror (TPCERROR_OK when successful).
Precondition
Before first use initialize the IFT structure with iftInit().
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
fpInput file pointer.
is_key_requiredSpecifies whether key name is required or not. If not required, then line contents without equals sign are assumed to represent a value string and key name in IFT struct is left empty.
  • 0 = key name is not required,
  • 1 = only lines with key and equals sign are read,
  • 2 = only lines with key and value separated by space are read.
is_comment_acceptedSpecifies whether comment lines are processed or not.
  • 0 = comment lines are not read,
  • 1 = also comment lines are read,
  • 2 = only comment lines are read.
statusPointer to status data; enter NULL if not needed.

Definition at line 130 of file iftio.c.

148 {
149 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
150 if(ift==NULL || fp==NULL) return TPCERROR_FAIL;
151 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
152 if(verbose>0) {
153 printf("%s(*ift, fp, %d, %d)\n", __func__, is_key_required, is_comment_accepted);
154 fflush(stdout);
155 }
156 int initial_key_nr=0; if(ift->keyNr>0) initial_key_nr=ift->keyNr;
157 if(verbose>11) {
158 printf(" initial_key_nr := %d\n", initial_key_nr);
159 fflush(stdout);
160 }
161
162 /* Get the size of the ASCII part of the file */
163 size_t fsize=asciiFileSize(fp, NULL);
164 if(verbose>11) {printf(" ASCII size := %d\n", (int)fsize); fflush(stdout);}
165 /* If ASCII part is too small, then lets consider that an error */
166 if( fsize<1 || (is_key_required && fsize<3) ) {
167 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
168 return TPCERROR_NO_DATA;
169 }
170 /* If ASCII part is too large, then lets consider that an error */
171 if(fsize>5000000) {
172 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_TOO_BIG);
173 return TPCERROR_TOO_BIG;
174 }
175 /* Read that to a string */
176 char *data;
177 data=asciiFileRead(fp, NULL, fsize+1); rewind(fp);
178 if(data==NULL) {
179 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
180 return TPCERROR_NO_DATA;
181 }
182 /* Read one line at a time from the string and fill IFT */
183 int i=0, j, ret;
184 char *cptr, *line;
185 cptr=data;
186 while((line=strTokenDup(cptr, "\n\r", &j))!=NULL) {
187 if(verbose>15) {printf(" '%s'\n", line); fflush(stdout);}
188 ret=iftPutFromString(ift, line, is_key_required, is_comment_accepted, status);
189 if(verbose>1 && ret!=0) {
190 fprintf(stderr, "Warning: cannot read line %d: '%s'.\n", i, line);
191 fflush(stderr);
192 }
193 free(line); cptr+=j; i++;
194 }
195#if(0) // this would mess up the functions that read other data formats as ift
196 /* If none found, and key is required, we will try with space as separator */
197 if(initial_key_nr==ift->keyNr && is_key_required) {
198 cptr=data; i=0;
199 while((line=strTokenDup(cptr, "\n\r", &j))!=NULL) {
200 ret=iftPutFromStringWithSpaceSeparator(ift, line, is_comment_accepted, status);
201 if(verbose>1 && ret!=0)
202 fprintf(stderr, "Warning: cannot read line %d: '%s'.\n", i, line);
203 free(line); cptr+=j; i++;
204 }
205 }
206#endif
207 /* Ready */
208 free(data);
209 if(i==0) {
210 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
211 return TPCERROR_NO_DATA;
212 }
213
214 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
215 return TPCERROR_OK;
216}
int iftPutFromString(IFT *ift, const char *line, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
Definition iftio.c:229
char * asciiFileRead(FILE *fp, char *data, size_t maxlen)
size_t asciiFileSize(FILE *fp, int *nonprintable)
char * strTokenDup(const char *s1, const char *s2, int *next)
Definition stringext.c:413
@ TPCERROR_TOO_BIG
File is too big.

Referenced by micropetHeaderRead(), parRead(), parReadLimits(), and tacRead().

◆ iftReplaceKey()

int iftReplaceKey ( IFT * ift,
int i,
const char * key,
TPCSTATUS * status )
extern

Replace the key name of a specified IFT item.

See also
iftReplaceValue, iftDelete, iftDeleteKey, iftPut
Returns
tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
iftPointer to IFT containing at least the item to be edited.
iIFT item index [0..keyNr-1] to be edited.
keyNew key string; can be empty ("" or NULL)
statusPointer to status data; enter NULL if not needed

Definition at line 307 of file ift.c.

316 {
317 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
318 if(ift==NULL) return TPCERROR_FAIL;
319 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
320 if(verbose>10) {
321 printf("iftReplaceKey(ift, %d", i);
322 if(key!=NULL) printf("\"%s\")\n", key); else printf("NULL)\n");
323 fflush(stdout);
324 }
325 if(i<0 || i>=ift->keyNr) return TPCERROR_FAIL;
326
327 /* Delete the previous value */
328 free(ift->item[i].key);
329 /* Set the new value;
330 do not put NULL because it would segfault in std functions */
331 if(key!=NULL) ift->item[i].key=strdup(key);
332 else ift->item[i].key=strdup("");
333
334 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
335 return TPCERROR_OK;
336}

◆ iftReplaceValue()

int iftReplaceValue ( IFT * ift,
int i,
const char * value,
TPCSTATUS * status )
extern

Replace the value of specified IFT item.

See also
iftReplaceKey, iftDelete, iftDeleteKey, iftPut
Returns
tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
iftPointer to IFT containing at least the item to be edited.
iIFT item index [0..keyNr-1] to be edited.
valueNew value string; can be empty ("" or NULL)
statusPointer to status data; enter NULL if not needed

Definition at line 268 of file ift.c.

277 {
278 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
279 if(ift==NULL) return TPCERROR_FAIL;
280 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
281 if(verbose>10) {
282 printf("iftReplaceValue(ift, %d", i);
283 if(value!=NULL) printf("\"%s\")\n", value); else printf("NULL)\n");
284 fflush(stdout);
285 }
286 if(i<0 || i>=ift->keyNr) return TPCERROR_FAIL;
287
288 /* Delete the previous value */
289 free(ift->item[i].value);
290 /* Set the new value;
291 do not put NULL because it would segfault in std functions */
292 if(value!=NULL) ift->item[i].value=strdup(value);
293 else ift->item[i].value=strdup("");
294
295 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
296 return TPCERROR_OK;
297}

◆ iftSearchKey()

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

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 )
extern

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().

◆ iftWrite()

int iftWrite ( IFT * ift,
FILE * fp,
TPCSTATUS * status )
extern

Write the contents of IFT to the specified file pointer.

See also
iftWriteItem, iftInit, iftFree
Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
fpOutput file pointer.
statusPointer to status data; enter NULL if not needed.

Definition at line 98 of file iftio.c.

105 {
106 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
107 if(ift==NULL || fp==NULL) return TPCERROR_FAIL;
108 if(status!=NULL && status->verbose>100) printf("keyNr := %d\n", ift->keyNr);
109 /* Write the contents */
110 int li, ret;
111 for(li=0, ret=0; li<ift->keyNr; li++) {
112 ret=iftWriteItem(ift, li, fp, status); if(ret!=TPCERROR_OK) break;
113 }
114 return(ret);
115}
int iftWriteItem(IFT *ift, int item, FILE *fp, TPCSTATUS *status)
Definition iftio.c:25

Referenced by parReadFIT(), parReadRES(), parWriteCSV(), parWriteIFT(), parWriteLimits(), tacWriteCSV(), tacWriteDFT(), tacWritePMOD(), and tacWriteSimple().

◆ iftWriteItem()

int iftWriteItem ( IFT * ift,
int item,
FILE * fp,
TPCSTATUS * status )
extern

Write one item in IFT to the specified file pointer.

Use iftWrite() to write all IFT items.

See also
iftWrite, iftInit, iftFree
Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
iftPointer to IFT.
itemIndex [0..keyNr-1] of key and value to print.
fpOutput file pointer.
statusPointer to status data; enter NULL if not needed.

Definition at line 25 of file iftio.c.

34 {
35 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
36 if(ift==NULL) return TPCERROR_FAIL;
37 int verbose=0; if(status!=NULL) verbose=status->verbose-1;
38 if(verbose>10) printf("%s(*ift, %d, fp)\n", __func__, item);
39 if(fp==NULL) {
40 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_CANNOT_WRITE);
42 }
43 if(item<0 || item>=ift->keyNr) {
44 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
45 return TPCERROR_NO_DATA;
46 }
47
48 /* Set interfile-type key/value separator */
49 char eq_sign[3];
50 switch(ift->type) {
51 case 1: strcpy(eq_sign, ":="); break;
52 case 2: strcpy(eq_sign, "="); break;
53 case 3: strcpy(eq_sign, ":"); break;
54 case 4: strcpy(eq_sign, " "); break;
55 case 5: strcpy(eq_sign, "\t"); break;
56 case 6: strcpy(eq_sign, ","); break;
57 case 7: strcpy(eq_sign, ";"); break;
58 default: strcpy(eq_sign, ":="); break;
59 }
60
61 int n=5; if(ift->item[item].key!=NULL) n+=strlen(ift->item[item].key);
62 if(ift->item[item].value!=NULL) n+=strlen(ift->item[item].value);
63 if(ift->item[item].comment!=0) n+=2;
64 if(verbose>100) printf(" n := %d\n", n);
65 char line[n], cmt[3];
66 /* 'Print' comment character, if required */
67 if(ift->item[item].comment!=0) strcpy(cmt, "# "); else strcpy(cmt, "");
68 /* 'Print' key and/or value */
69 if(ift->item[item].key==NULL || strlen(ift->item[item].key)<1) {
70 sprintf(line, "%s%s", cmt, ift->item[item].value);
71 } else {
72 if((ift->space_before_eq==0 && ift->space_after_eq==0) ||
73 ift->type==4 || ift->type==5 || ift->type==6 || ift->type==7)
74 sprintf(line, "%s%s%s%s", cmt, ift->item[item].key, eq_sign, ift->item[item].value);
75 else if(ift->space_before_eq==1 && ift->space_after_eq==0)
76 sprintf(line, "%s%s %s%s", cmt, ift->item[item].key, eq_sign, ift->item[item].value);
77 else if(ift->space_before_eq==0 && ift->space_after_eq==1)
78 sprintf(line, "%s%s%s %s", cmt, ift->item[item].key, eq_sign, ift->item[item].value);
79 else
80 sprintf(line, "%s%s %s %s", cmt, ift->item[item].key, eq_sign, ift->item[item].value);
81 }
82 /* Write line into file */
83 if(fprintf(fp, "%s\n", line) < (int)strlen(line)) {
84 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_CANNOT_WRITE);
86 }
87 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
88 return TPCERROR_OK;
89}
@ TPCERROR_CANNOT_WRITE
Cannot write file.

Referenced by abssWrite(), and iftWrite().