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

Working with y values (concentrations) 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 tacYRange (TAC *d, int i, double *ymin, double *ymax, int *smin, int *smax, int *imin, int *imax)
 Get the range of y values (concentrations) in TAC struct.
int tacYRangeInXRange (TAC *d, int i, const double xmin, const double xmax, double *ymin, double *ymax, int *smin, int *smax, int *imin, int *imax)
 Get the range of y values (concentrations) in TAC struct, including only samples with x (times) inside given range.

Detailed Description

Working with y values (concentrations) in TAC struct.

Definition in file tacy.c.

Function Documentation

◆ tacYRange()

int tacYRange ( TAC * d,
int i,
double * ymin,
double * ymax,
int * smin,
int * smax,
int * imin,
int * imax )

Get the range of y values (concentrations) in TAC struct.

Data is not modified. Data does not need to be sorted. Data can contain NaNs, but y values omitted if corresponding x is NaN.

See also
tacYRangeInXRange, tacXRange, tacYUnitConvert, tacCopyTacc
Author
Vesa Oikonen
Returns
Returns <>0 in case of failure.
Parameters
dPointer to TAC structure.
iIndex of TAC, [0, ..., tacNr-1] ; enter <0 to search for max and/or min from all TACs.
yminPointer to variable for min y value (NULL if not needed).
ymaxPointer to variable for max y value (NULL if not needed).
sminPointer to variable where sample index of min y value will be stored (NULL if not needed).
smaxPointer to variable where sample index of max y value will be stored (NULL if not needed).
iminPointer to variable where tac index of min y value will be stored (NULL if not needed).
imaxPointer to variable where tac index of max y value will be stored (NULL if not needed).

Definition at line 26 of file tacy.c.

43 {
44 if(ymin!=NULL) *ymin=nan("");
45 if(ymax!=NULL) *ymax=nan("");
46 if(smin!=NULL) *smin=-1;
47 if(smax!=NULL) *smax=-1;
48 if(imin!=NULL) *imin=-1;
49 if(imax!=NULL) *imax=-1;
50 /* Check the data */
51 if(d==NULL || d->sampleNr<1) return(1);
52 /* Check the index */
53 if(i>=d->tacNr) return(2);
54
55 /* Find the min and max time */
56 double *xi, *xa;
57 if(d->isframe) {xi=d->x1; xa=d->x2;} else xi=xa=d->x;
58 double mi, ma;
59 mi=ma=nan("");
60 for(int j=0; j<d->sampleNr; j++) {
61 if(isnan(xi[j]) || isnan(xa[j])) continue;
62 for(int k=0; k<d->tacNr; k++) {
63 if(i>=0 && i!=k) continue;
64 if(isnan(mi) || isnan(ma)) {
65 mi=d->c[k].y[j]; ma=d->c[k].y[j];
66 if(smin!=NULL) *smin=j;
67 if(smax!=NULL) *smax=j;
68 if(imin!=NULL) *imin=k;
69 if(imax!=NULL) *imax=k;
70 continue;
71 }
72 if(d->c[k].y[j]<mi) {
73 mi=d->c[k].y[j];
74 if(smin!=NULL) *smin=j;
75 if(imin!=NULL) *imin=k;
76 } else if(d->c[k].y[j]>ma) {
77 ma=d->c[k].y[j];
78 if(smax!=NULL) *smax=j;
79 if(imax!=NULL) *imax=k;
80 }
81 }
82 }
83 if(ymin!=NULL) *ymin=mi;
84 if(ymax!=NULL) *ymax=ma;
85 if(isnan(mi) || isnan(ma)) return(2);
86 return(0);
87}
double * y
Definition tpctac.h:75
double * x
Definition tpctac.h:97
int sampleNr
Definition tpctac.h:89
int isframe
Definition tpctac.h:95
TACC * c
Definition tpctac.h:117
double * x2
Definition tpctac.h:101
double * x1
Definition tpctac.h:99
int tacNr
Definition tpctac.h:91

Referenced by mtgaPlotSVG().

◆ tacYRangeInXRange()

int tacYRangeInXRange ( TAC * d,
int i,
const double xmin,
const double xmax,
double * ymin,
double * ymax,
int * smin,
int * smax,
int * imin,
int * imax )

Get the range of y values (concentrations) in TAC struct, including only samples with x (times) inside given range.

Data is not modified. Data does not need to be sorted. Data can contain NaNs, but y values omitted if corresponding x is NaN.

See also
tacYRange, tacXRange, tacYUnitConvert
Author
Vesa Oikonen
Returns
Returns <>0 in case of failure.
Parameters
dPointer to TAC structure.
iIndex of TAC, [0, ..., tacNr-1] ; enter <0 to search for max and/or min from all TACs.
xminMin x value.
xmaxMax x value.
yminPointer to variable for min y value (NULL if not needed).
ymaxPointer to variable for max y value (NULL if not needed).
sminPointer to variable where sample index of min y value will be stored (NULL if not needed).
smaxPointer to variable where sample index of max y value will be stored (NULL if not needed).
iminPointer to variable where tac index of min y value will be stored (NULL if not needed).
imaxPointer to variable where tac index of max y value will be stored (NULL if not needed).

Definition at line 99 of file tacy.c.

120 {
121 if(ymin!=NULL) *ymin=nan("");
122 if(ymax!=NULL) *ymax=nan("");
123 if(smin!=NULL) *smin=-1;
124 if(smax!=NULL) *smax=-1;
125 if(imin!=NULL) *imin=-1;
126 if(imax!=NULL) *imax=-1;
127 /* Check the data */
128 if(d==NULL || d->sampleNr<1) return(1);
129 /* Check the index */
130 if(i>=d->tacNr) return(2);
131 /* Check x range */
132 if(xmin>xmax) return(3);
133
134 /* Find the min and max time */
135 double *xi, *xa, x;
136 if(d->isframe) {xi=d->x1; xa=d->x2;} else xi=xa=d->x;
137 double mi, ma;
138 mi=ma=nan("");
139 for(int j=0; j<d->sampleNr; j++) {
140 if(isnan(xi[j]) || isnan(xa[j])) continue;
141 x=0.5*(xi[j]+xa[j]); if(x<xmin || x>xmax) continue;
142 for(int k=0; k<d->tacNr; k++) {
143 if(i>=0 && i!=k) continue;
144 if(isnan(mi) || isnan(ma)) {
145 mi=d->c[k].y[j]; ma=d->c[k].y[j];
146 if(smin!=NULL) *smin=j;
147 if(smax!=NULL) *smax=j;
148 if(imin!=NULL) *imin=k;
149 if(imax!=NULL) *imax=k;
150 continue;
151 }
152 if(d->c[k].y[j]<mi) {
153 mi=d->c[k].y[j];
154 if(smin!=NULL) *smin=j;
155 if(imin!=NULL) *imin=k;
156 } else if(d->c[k].y[j]>ma) {
157 ma=d->c[k].y[j];
158 if(smax!=NULL) *smax=j;
159 if(imax!=NULL) *imax=k;
160 }
161 }
162 }
163 if(ymin!=NULL) *ymin=mi;
164 if(ymax!=NULL) *ymax=ma;
165 if(isnan(mi) || isnan(ma)) return(2);
166 return(0);
167}

Referenced by tacPlotFitSVG(), tacPlotHistogramSVG(), and tacPlotLineSVG().