Skip to content

Commit

Permalink
2v5 files uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
p-j-miller authored Feb 16, 2022
1 parent 9b56d2d commit a7bd1d7
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 66 deletions.
150 changes: 108 additions & 42 deletions UDataPlotWindow.cpp

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions UDataPlotWindow.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object PlotWindow: TPlotWindow
OnResize = FormResize
DesignSize = (
1290
1002)
982)
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Expand Down Expand Up @@ -479,15 +479,15 @@ object PlotWindow: TPlotWindow
end
object Label15: TLabel
Left = 184
Top = 400
Top = 378
Width = 43
Height = 13
Anchors = [akTop, akRight]
Caption = 'Skip lines'
end
object Label16: TLabel
Left = 189
Top = 419
Top = 397
Width = 88
Height = 13
Anchors = [akTop, akRight]
Expand Down Expand Up @@ -853,7 +853,7 @@ object PlotWindow: TPlotWindow
end
object Edit_skip_lines: TEdit
Left = 233
Top = 397
Top = 375
Width = 41
Height = 21
Hint = 'Enter number of lines to skip in csv file before header line'
Expand All @@ -864,6 +864,20 @@ object PlotWindow: TPlotWindow
TabOrder = 23
Text = '0'
end
object Time_from0: TCheckBox
Left = 179
Top = 420
Width = 109
Height = 17
Hint =
'Tick this box to start time from zero (based on the first date/t' +
'ime in the csv file)'
Caption = 'Start time from 0'
ParentShowHint = False
ShowHint = True
TabOrder = 24
OnClick = Time_from0Click
end
end
object ActionList1: TActionList
Images = ImageList1
Expand Down Expand Up @@ -935,7 +949,7 @@ object PlotWindow: TPlotWindow
Left = 304
Top = 32
Bitmap = {
494C01010A000E00A40110001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
494C01010A000E00B80110001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000003000000001002000000000000030
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
Expand Down
2 changes: 2 additions & 0 deletions UDataPlotWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class TPlotWindow : public TForm
TEdit *Edit_skip_lines;
TLabel *Label15;
TLabel *Label16;
TCheckBox *Time_from0;
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall ResizeExecute(TObject *Sender);
Expand Down Expand Up @@ -168,6 +169,7 @@ class TPlotWindow : public TForm
void __fastcall Edit_xcolChange(TObject *Sender);
void __fastcall Edit_ycolChange(TObject *Sender);
void __fastcall Action1Execute(TObject *Sender);
void __fastcall Time_from0Click(TObject *Sender);
private: // User declarations
int iShape1X,iShape1Y;
void virtual __fastcall WmDropFiles(TWMDropFiles& Message); // for drag n drop
Expand Down
9 changes: 6 additions & 3 deletions UScientificGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,10 @@ float TScientificGraph::fnAddDataPoint_nextx(int iGraphNumberF) // returns ne
SGraph *pAGraph = ((SGraph*) pHistory->Items[iGraphNumberF]);
SGraph *pAGraph_1 = ((SGraph*) pHistory->Items[iGraphNumberF-1]); // previous trace added
int i=pAGraph->nos_vals; // current size
if(i >=pAGraph_1->nos_vals ) return 0; // past end of previous x array
if(i >=pAGraph_1->nos_vals )
{rprintf("Warning:fnAddDataPoint_nextx(%d): pAGraph->nos_vals=%d pAGraph_1->nos_vals=%d\n",iGraphNumberF,i,pAGraph_1->nos_vals);
return 0; // past end of previous x array
}
return pAGraph_1->x_vals[i]; // value from previous trace
};

Expand Down Expand Up @@ -3270,12 +3273,12 @@ void TScientificGraph::fnAutoScale()
}
if(max_graph>=0)
{aGraph=(SGraph*) pHistory->Items[max_graph];
rprintf("Maximum value = %g found on trace %d (%s) at X=%g\n",dYMax,max_graph,aGraph->Caption.c_str(),X_for_maxY);
rprintf("Maximum value = %g found on trace %d (%s) at X=%g\n",dYMax,max_graph+1,aGraph->Caption.c_str(),X_for_maxY);
}
else dXMax=dYMax=1;
if(min_graph>=0)
{aGraph=(SGraph*) pHistory->Items[min_graph];
rprintf("Minimum value = %g found on trace %d (%s) at X=%g\n",dYMin,min_graph,aGraph->Caption.c_str(),X_for_minY);
rprintf("Minimum value = %g found on trace %d (%s) at X=%g\n",dYMin,min_graph+1,aGraph->Caption.c_str(),X_for_minY);
}
else dXMin=dYMin=0;
d=dYMax-dYMin; //space to axis
Expand Down
Binary file modified csvgraph.docx
Binary file not shown.
34 changes: 19 additions & 15 deletions expr-code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,16 +1284,17 @@ bool getfloatge0(char *s, float *d)
/* functions to deal with time input */
#if 1
/* this is a faster version that tries to avoid floating point maths, this reduced load time of 2 columns from 67 secs to 51 secs */
float gethms(char *s)
{/* read a time of the format hh:mm:ss.s , returns it as a float value in seconds */
double gethms(char *s)
{/* read a time of the format hh:mm:ss.s , returns it as a double value in seconds */
/* if just a number is found this will be treated as seconds (which can include a decimal point and digits after the dp)
if aa:bb is found this will be treated as aa mins and bb secs (which can include a decimal point and digits after the dp)
if aa:bb:cc is found this will be treated as aa hours, bb mins and cc secs (which can include a decimal point and digits after the dp)
returns 0 if does not start with a number, otherwise converts as much as possible based on the above format
This means in particular that trailing whitespace and "'s are ignored
23:59:59 => 86399 secs which is well within the capability of a uint32
*/
uint32_t sec=0,sec1=0; // sec1 is current set of digits, sec is previous total
int pow10=0; // exponent
int power10=0; // exponent
if(!isdigit(*s)) return 0; /* must start with a number */
sec1=(*s++ -'0'); // ascii->decimal for 1st digit
while(isdigit(*s))
Expand All @@ -1304,7 +1305,7 @@ float gethms(char *s)
sec1=sec1*10+(uint32_t)(*s++ -'0'); // ascii->decimal in general
else
{s++;
pow10++; // too many digits - keep track of decimal point
power10++; // too many digits - keep track of decimal point
}
}
if(*s==':' && isdigit(s[1]))
Expand All @@ -1313,24 +1314,25 @@ float gethms(char *s)
++s; // skip :
}
}
if(pow10!=0)
{return (float)(sec+sec1)*pow(10.0f,pow10);// already have too many sf so we can ignore dp if its present
if(power10!=0)
{return ((double)sec+(double)sec1)*pow10(power10);// already have too many sf so we can ignore dp if its present
/* was pow(10.0,power10), replaced with pow10(power10) */
}
if(*s=='.')
{ // seconds contains dp , so we now need to keep track of dp and watch out for uint32 overflowing - we have at most 59 secs in sec1 so we have plenty of resolution
++s; // skip dp
while(isdigit(*s) && (sec1&0xf0000000) == 0 )
{sec1=sec1*10+(uint32_t)(*s++ -'0');
pow10++; // keep track of decimal point position
power10++; // keep track of decimal point position
}
if(isdigit(*s) && *s>='5') sec1++; // round if more digits present
return (float)sec+(float)sec1/pow(10.0f,pow10);
return (double)sec+(double)sec1/pow10(power10);
}
return (float)(sec+sec1); // if seconds is an integer
return (double)sec+(double)sec1; // if seconds is an integer
}

static unsigned int days=0;
static float last_time_secs=0;
static double last_time_secs=0;
static bool skip=false; // skip 1st number in a big step
void reset_days(void) /* reset static variables for gethms_days() - should be used before using gethms_days() to read times from a file */
{days=0;
Expand All @@ -1339,20 +1341,22 @@ void reset_days(void) /* reset static variables for gethms_days() - should be u
}

double gethms_days(char *s) /* read time in format hh:mm:ss.s , assumed to be called in sequence and accounts for days when time wraps around. Returns secs, or -ve number on error */
/* this has to return a double as we could have a lot of days and we would quickly run out of resolution with a float */
{float t;
/* this has to return a double as we could have a lot of days and we would quickly run out of resolution with a float */
{double t;
if(!isdigit(*s)) return -1; /* should start with a number, return -1 to flag this is an error */
t=gethms(s);
if(t<last_time_secs)
{
if((last_time_secs - t) > 64800.0f ) // 64800=18.0*60.0*60.0
{if(last_time_secs-t <= 1.0)
skip=false; // allow up to 1 second backwards, data will need to be sorted to get correct order but is possibly OK (eg it could be due to a leap second?).
else if((last_time_secs - t) > 64800.0 ) // 64800=18.0*60.0*60.0
{
days++; /* if time appears to have gone > 18 hours backwards assume this is because we have passed into a new day */
skip=false; // assume time is valid
}
else
{if(!skip)
{skip=true;
// rprintf("gethms_days(%s): last_time_secs=%.9g t=%.9g\n",s,last_time_secs,t);
t= -2;/* time has gone backwards for no reason - return -2 to indicate an error */
}
else skip=false; // repeated , accept value (could be due to a gap in the log [power cut?] that crossed midnight)
Expand All @@ -1364,7 +1368,7 @@ double gethms_days(char *s) /* read time in format hh:mm:ss.s , assumed to be ca
{ // -ve value of t indicate an error
last_time_secs=t;
if(days!=0)
return (double)t+86400.0*(double)days; /* 86400=24.0*60.0*60.0 , 24 hours a day, 3600 secs in a hour */
return t+86400.0*(double)days; /* 86400=24.0*60.0*60.0 , 24 hours a day, 3600 secs in a hour */
}
return t;
}
Expand Down
2 changes: 1 addition & 1 deletion expr-code.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool getfloat(char *s, float *d); /*reads a floating point number returns true i
bool getfloatgt0(char *s, float *d);/* as above but requires number to be >0 */
bool getfloatge0(char *s, float *d);/* as above but requires number to be >0 */

float gethms(char *s); /* read a time of format hh:mm:ss.s , returns time in seconds */
double gethms(char *s); /* read a time of format hh:mm:ss.s , returns time in seconds */
void reset_days(void); /* reset static variables for gethms_days() - should be used before using gethms_days() to read times from a file */
double gethms_days(char *s); /* read time in format hh:mm:ss.s , assumed to be called in sequence and accounts for days when time wraps around. Returns secs */

Expand Down

0 comments on commit a7bd1d7

Please sign in to comment.