libtpccurveio
 All Data Structures Files Functions Variables Enumerations Enumerator Defines
Functions
dft.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "decpoint.h"
#include "include/dft.h"
#include "include/dftunit.h"
#include "include/dftio.h"
Include dependency graph for dft.c:

Go to the source code of this file.

Functions

int dftQSortName (const void *voi1, const void *voi2)
int dftQSortPlane (const void *voi1, const void *voi2)
void dftEmpty (DFT *data)
void dftInit (DFT *data)
int dftSetmem (DFT *data, int frameNr, int voiNr)
int dftAddmem (DFT *dft, int voiNr)
int dftAdd (DFT *data1, DFT *data2, int voi)
int dftSelect (DFT *data, char *name)
int dftSelectRegions (DFT *dft, char *region_name, int reset)
int dftSelectBestReference (DFT *dft)
void dftFrametimes (DFT *data)
int dftOverflow (DFT *data)
int dftCopyvoi (DFT *data, int from, int to)
int dftMovevoi (DFT *dft, int from, int to)
int dftDelete (DFT *dft, int voi)
int dftCopymainhdr (DFT *dft1, DFT *dft2)
int dftCopyvoihdr (DFT *dft1, int from, DFT *dft2, int to)
int dftdup (DFT *dft1, DFT *dft2)
int dftAllocateWithHeader (DFT *dft, int frameNr, int voiNr, DFT *dft_from)
int dftAddnullframe (DFT *data)
int dftSort (DFT *data)
int dftSortPlane (DFT *data)
int dft_nr_of_NA (DFT *dft)
int dftNAfill (DFT *dft)
int dftMinMax (DFT *dft, double *minx, double *maxx, double *miny, double *maxy)
int dftMinMaxTAC (DFT *dft, int tacindex, double *minx, double *maxx, double *miny, double *maxy, int *mini, int *maxi)
int dftMaxY (DFT *dft, double t1, double t2, double *miny, double *maxy)
double dft_kBqMin (DFT *data)
double dft_kBqMax (DFT *data)
int dftSortByFrame (DFT *dft)
int dftDeleteFrameOverlap_old (DFT *dft)
int dftDeleteFrameOverlap (DFT *dft)
void dftSetComments (DFT *dft)
int dftFillInitialGap (DFT *dft)
int dftAddSpaceForFrames (DFT *dft, int nr_to_add)

Function Documentation

double dft_kBqMax ( DFT data)

Returns the highest activity value in DFT

Definition at line 1196 of file dft.c.

References DFT::frameNr, DFT::voi, DFT::voiNr, and Voi::y.

double dft_kBqMin ( DFT data)

Returns the lowest activity value in DFT

Definition at line 1179 of file dft.c.

References DFT::frameNr, DFT::voi, DFT::voiNr, and Voi::y.

int dft_nr_of_NA ( DFT dft)

Check DFT for NA's in sample times and values.

Returns:
Returns the number of NA's that were found.

Definition at line 973 of file dft.c.

References DFT_TIME_STARTEND, DFT::frameNr, DFT::timetype, DFT::voi, DFT::voiNr, DFT::x, DFT::x1, DFT::x2, and Voi::y.

int dftAdd ( DFT data1,
DFT data2,
int  voi 
)

Add the specified voi [0,voiNr-1] from data2 to data1. Allocates memory for additional data VOI, if necessary.

Returns:
Returns 0 if ok.

Definition at line 379 of file dft.c.

References DFT::_type, DFT::_voidataNr, DFT_FORMAT_PLAIN, dftAddmem(), dftCopyvoihdr(), dfterrmsg, DFT::frameNr, DFT::isweight, DFT::timeunit, DFT::unit, DFT::voi, DFT::voiNr, DFT::w, Voi::y, Voi::y2, and Voi::y3.

Here is the call graph for this function:

int dftAddmem ( DFT dft,
int  voiNr 
)

Adds room for additional VOI TAC(s) into DFT data struct. Old data is left unchanged.

Returns:
Returns 0 when successful.
Parameters:
dftPointer to DFT data struct
voiNrNr of additional VOI memory blocks

Definition at line 298 of file dft.c.

References DFT::_data, DFT::_dataSize, DFT::_voidataNr, DFT::frameNr, Voi::hemisphere, Voi::name, Voi::place, Voi::size, Voi::sw, Voi::sw2, Voi::sw3, DFT::voi, Voi::voiname, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Referenced by dftAdd().

int dftAddnullframe ( DFT data)

Include a frame with time 0, unless one already exists.

Definition at line 835 of file dft.c.

References DFT::_type, DFT::comments, dftEmpty(), dftInit(), dftSetmem(), DFT::frameNr, Voi::hemisphere, DFT::isweight, Voi::name, Voi::place, Voi::size, DFT::studynr, Voi::sw, Voi::sw2, Voi::sw3, DFT::timetype, DFT::timeunit, DFT::unit, DFT::voi, Voi::voiname, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Here is the call graph for this function:

int dftAddSpaceForFrames ( DFT dft,
int  nr_to_add 
)

Add space for additional frames into DFT, keeping the existing data. frameNr is increased by nr_to_add, but new last frame(s) are empty.

Returns:
Returns zero if successful, otherwise <>0.
Parameters:
dftAllocated and data-filled DFT where new frame(s) are added to the end
nr_to_addNr of frames to add

Definition at line 1436 of file dft.c.

References DFT::comments, dftCopymainhdr(), dftCopyvoihdr(), dftdup(), dftEmpty(), dftInit(), dftSetmem(), DFT::frameNr, DFT::isweight, DFT::voi, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Here is the call graph for this function:

int dftAllocateWithHeader ( DFT dft,
int  frameNr,
int  voiNr,
DFT dft_from 
)

Allocates a DFT structure with specified size, containing no TAC data but header information as available in another DFT struct. Any existing content of dft2 will be deleted. Dft2 must be initiated.

Returns:
Returns 0 if ok.
Parameters:
dftPointer to initiated DFT struct which will be allocated here; any previous contents will be deleted.
frameNrNr of frames to be allocated
voiNrNr of planes to be allocated
dft_fromPointer to DFT struct where header contents will be copied from

Definition at line 787 of file dft.c.

References dftCopymainhdr(), dftCopyvoihdr(), dftEmpty(), dftSetmem(), DFT::frameNr, DFT::isweight, DFT::voi, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Here is the call graph for this function:

int dftCopymainhdr ( DFT dft1,
DFT dft2 
)
int dftCopyvoi ( DFT data,
int  from,
int  to 
)

Copy VOI data inside DFT data structure from one place to another.

Definition at line 633 of file dft.c.

References DFT::_voidataNr, DFT::frameNr, Voi::hemisphere, Voi::name, Voi::place, Voi::size, Voi::sw, Voi::sw2, Voi::sw3, DFT::voi, Voi::voiname, Voi::y, Voi::y2, and Voi::y3.

Referenced by dftRead().

int dftCopyvoihdr ( DFT dft1,
int  from,
DFT dft2,
int  to 
)

Copy voi header info from dft1.voi[from] to dft2.voi[to].

Definition at line 724 of file dft.c.

References DFT::_voidataNr, Voi::hemisphere, Voi::name, Voi::place, Voi::size, Voi::sw, Voi::sw2, Voi::sw3, DFT::voi, and Voi::voiname.

Referenced by dftAdd(), dftAddSpaceForFrames(), dftAllocateWithHeader(), dftdup(), and dftFillInitialGap().

int dftDelete ( DFT dft,
int  voi 
)

Delete specified TAC (0..voiNr-1) from the DFT structure.

Returns:
Returns 0 if ok.

Definition at line 687 of file dft.c.

References dftMovevoi(), and DFT::voiNr.

Referenced by csv2dft_a().

Here is the call graph for this function:

int dftDeleteFrameOverlap ( DFT dft)

Correct frame start and end times if frames are slightly overlapping or have small gaps in between. Large gap is not corrected and it does not lead to an error.

Returns:
If overlap is considerable (>1 s), or another error is encountered, function returns a non-zero value. Otherwise 0 is returned.
Parameters:
dftPointer to DFT data. Time unit must be set, otherwise no checking is done. Timetype must be DFT_TIME_STARTEND, i.e. both frame start and end time must be present.

Definition at line 1268 of file dft.c.

References DFT_TIME_STARTEND, DFT::frameNr, DFT::timetype, DFT::timeunit, DFT::x1, and DFT::x2.

Correct frame start and end times if frames are slightly overlapping or have small gaps in between. Data is not corrected if time unit is not known to be min or sec.

Returns:
If overlap is considerable (>1 s), or another error is encountered, function returns a non-zero value. Otherwise 0 is returned.

Definition at line 1244 of file dft.c.

References DFT::frameNr, DFT::timeunit, DFT::x1, and DFT::x2.

int dftdup ( DFT dft1,
DFT dft2 
)

Makes a duplicate of DFT structure pointed to by dft1 into dft2. Any existing content of dft2 will be deleted. Dft2 must be initiated.

Returns:
Returns 0 if ok.

Definition at line 748 of file dft.c.

References dftCopymainhdr(), dftCopyvoihdr(), dftEmpty(), dftSetmem(), DFT::frameNr, DFT::isweight, DFT::voi, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Referenced by dftAddSpaceForFrames(), and dftFillInitialGap().

Here is the call graph for this function:

void dftEmpty ( DFT data)
int dftFillInitialGap ( DFT dft)

Check if there is a time gap between time zero and first sample time; if gap does not exist, then nothing is done; if gap exists, then gap is filled with an extra frame.

Returns:
Returns zero if successful, otherwise <>0.

Definition at line 1357 of file dft.c.

References DFT::comments, DFT_TIME_STARTEND, dftCopymainhdr(), dftCopyvoihdr(), dftdup(), dftEmpty(), dftInit(), dftSetmem(), DFT::frameNr, DFT::isweight, DFT::timetype, DFT::voi, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Here is the call graph for this function:

void dftFrametimes ( DFT data)

Calculate frame mid or start and end times. Timetype is not changed.

Definition at line 517 of file dft.c.

References DFT_TIME_END, DFT_TIME_MIDDLE, DFT_TIME_START, DFT_TIME_STARTEND, DFT::frameNr, DFT::timetype, DFT::x, DFT::x1, and DFT::x2.

Referenced by csv2dft_a(), dftRead(), and idwcRead().

void dftInit ( DFT data)
int dftMaxY ( DFT dft,
double  t1,
double  t2,
double *  miny,
double *  maxy 
)

Search the min and max values of DFT TAC data inside specified time range. Data may contain NA's.

Returns:
Returns 0 if successful.
Parameters:
dftPointer to the DFT TAC data to search
t1Start time
t2End time
minyPointer to min Y; set to NULL if not needed
maxyPointer to max Y; set to NULL if not needed

Definition at line 1140 of file dft.c.

References DFT_TIME_STARTEND, DFT::frameNr, DFT::timetype, DFT::voi, DFT::voiNr, DFT::x, DFT::x1, DFT::x2, and Voi::y.

int dftMinMax ( DFT dft,
double *  minx,
double *  maxx,
double *  miny,
double *  maxy 
)

Search the min and max values of DFT TAC data. Data may contain NA's. Note that minx and maxx are the smallest and highest x values in data, not the x values at y minimum and maximum; use dftMinMaxTAC() for that.

Returns:
Returns 0 if successful.
Parameters:
dftPointer to the DFT TAC data to search
minxPointer to min X; set to NULL if not needed
maxxPointer to max X; set to NULL if not needed
minyPointer to min Y; set to NULL if not needed
maxyPointer to max Y; set to NULL if not needed

Definition at line 1034 of file dft.c.

References DFT_TIME_STARTEND, DFT::frameNr, DFT::timetype, DFT::voi, DFT::voiNr, DFT::x, DFT::x1, DFT::x2, and Voi::y.

int dftMinMaxTAC ( DFT dft,
int  tacindex,
double *  minx,
double *  maxx,
double *  miny,
double *  maxy,
int *  mini,
int *  maxi 
)

Search the min and max values of DFT TAC data. Data may contain NA's. This is not a replacement of dftMinMax() which is needed e.g. in plotting functions.

Returns:
Returns 0 if successful.
Parameters:
dftPointer to the DFT TAC data to search
tacindexIndex of the only TAC which is searched for min and max; <0 if all
minxPointer to X at TAC min; set to NULL if not needed
maxxPointer to X at TAC max; set to NULL if not needed
minyPointer to min Y; set to NULL if not needed
maxyPointer to max Y; set to NULL if not needed
miniIndex of min TAC; set to NULL if not needed
maxiIndex of max TAC; set to NULL if not needed

Definition at line 1082 of file dft.c.

References DFT_TIME_STARTEND, DFT::frameNr, DFT::timetype, DFT::voi, DFT::voiNr, DFT::x, DFT::x1, DFT::x2, and Voi::y.

int dftMovevoi ( DFT dft,
int  from,
int  to 
)

Move VOI in DFT structure from one position to another.

Definition at line 663 of file dft.c.

References DFT::_voidataNr, and DFT::voi.

Referenced by dftDelete().

int dftNAfill ( DFT dft)

Replace NA's in basic DFT data with interpolated values. If extrapolation is necessary, then the values (0,0) and (Infinity,last measured) are assumed.

Returns:
Returns 0, if NA's could be filled with sensible values.

Definition at line 994 of file dft.c.

References DFT::frameNr, DFT::voi, DFT::voiNr, DFT::x, and Voi::y.

int dftOverflow ( DFT data)

Check for overflows in data structure. Returns 0, if ok.

Definition at line 614 of file dft.c.

References DFT::frameNr, DFT::voi, DFT::voiNr, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

int dftQSortName ( const void *  voi1,
const void *  voi2 
)

Definition at line 930 of file dft.c.

Referenced by dftSort().

int dftQSortPlane ( const void *  voi1,
const void *  voi2 
)

Definition at line 954 of file dft.c.

Referenced by dftSortPlane().

int dftSelect ( DFT data,
char *  name 
)

Select VOIs (sets sw=1), whose names are matching specified string. If no string is specified, then all VOIs are selected. This function is to replaced by dftSelectRegions().

Returns:
Returns the number of matches, or <0, if an error occurred.

Definition at line 423 of file dft.c.

References Voi::hemisphere, Voi::place, Voi::sw, DFT::voi, Voi::voiname, and DFT::voiNr.

int dftSelectBestReference ( DFT dft)

Select the best reference region in case that several were found with dftSelectRegions.

Returns:
Returns the index of best region, or <0 in case of an error.
Parameters:
dftPointer to DFT struct, after using dftSelectRegions()

Definition at line 491 of file dft.c.

References Voi::hemisphere, Voi::place, Voi::sw, DFT::voi, Voi::voiname, and DFT::voiNr.

int dftSelectRegions ( DFT dft,
char *  region_name,
int  reset 
)

Select the VOIs that have matching region name or number. Sets sw=1 or sw=0. This function will replace dftSelect().

Returns:
Returns the number of selected VOIs, or <0 in case of an error.
Parameters:
dftPointer to DFT data where VOIs are selected
region_nameName or VOI number which is searched
reset1=Non-matching VOIs are deselected, 0=Old selections are preserved

Definition at line 462 of file dft.c.

References Voi::name, Voi::sw, DFT::voi, and DFT::voiNr.

void dftSetComments ( DFT dft)

Overwrites DFT comments with information in current DFT header. If DFT format specifies that titles are to be saved, that information is not included in comments.

Definition at line 1302 of file dft.c.

References DFT::_type, DFT::comments, DFT::decayCorrected, DFT_DECAY_CORRECTED, DFT_DECAY_NOTCORRECTED, DFT_FORMAT_PMOD, DFT_FORMAT_STANDARD, DFT::injectionTime, DFT::isotope, DFT::radiopharmaceutical, DFT::scanStartTime, DFT::studynr, DFT::timeunit, and DFT::unit.

int dftSetmem ( DFT data,
int  frameNr,
int  voiNr 
)

Allocate memory for DFT data and sets data pointers. Old data is destroyed.

Definition at line 256 of file dft.c.

References DFT::_data, DFT::_dataSize, DFT::_voidataNr, dftEmpty(), DFT::voi, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

Referenced by cptReadOne(), csv2dft_a(), csv2dft_b(), dftAddnullframe(), dftAddSpaceForFrames(), dftAllocateWithHeader(), dftdup(), dftFillInitialGap(), dftRead(), idwcRead(), ifRead(), roikbqRead(), tsvRead(), and xelRead().

Here is the call graph for this function:

int dftSort ( DFT data)

Sort DFT regions in alphabetical order by their name.

Definition at line 923 of file dft.c.

References dftQSortName(), DFT::voi, and DFT::voiNr.

Here is the call graph for this function:

int dftSortByFrame ( DFT dft)

Sorts TAC frames by increasing sample time.

Returns:
Returns 0 if ok.

Definition at line 1215 of file dft.c.

References DFT::frameNr, DFT::voi, DFT::voiNr, DFT::w, DFT::x, DFT::x1, DFT::x2, Voi::y, Voi::y2, and Voi::y3.

int dftSortPlane ( DFT data)

Sort DFT regions in alphabetical order by their plane.

Definition at line 947 of file dft.c.

References dftQSortPlane(), DFT::voi, and DFT::voiNr.

Referenced by cptWrite().

Here is the call graph for this function: