From 68ddde792ebdcdc2ae67a09c68d4e4085f828b4b Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Mon, 16 Jan 2023 18:02:51 +0100 Subject: [PATCH] Fix time axis scaling (fixes #35) Signed-off-by: Cees Bassa --- rfplot.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/rfplot.c b/rfplot.c index b15e2a9..def7df7 100644 --- a/rfplot.c +++ b/rfplot.c @@ -823,6 +823,8 @@ void dec2sex(double x,char *s,int f,int len) if (len==5) sprintf(s,"%c%02i%c%02i%c%05.2f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]); if (len==4) sprintf(s,"%c%02i%c%02i%c%04.1f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]); if (len==2) sprintf(s,"%c%02i%c%02i%c%02i%c",sign,(int) deg,form[f][0],(int) min,form[f][1],(int) floor(sec),form[f][2]); + if (len==1) sprintf(s,"%02i%c%02i%c%02i",(int) deg,form[f][0],(int) min,form[f][1],(int) floor(sec)); + if (len==0) sprintf(s,"%02i%c%02i",(int) deg,form[f][0],(int) min,form[f][1]); return; } @@ -836,14 +838,14 @@ void time_axis(double *mjd,int n,float xmin,float xmax,float ymin,float ymax) char stime[16]; // Find extrema - for (i=0;imjdmax) mjdmax=mjd[i]; - } - } + imin=(int) xmin; + if (imin<0) + imin=0; + imax=(int) xmax; + if (imax>=n) + imax=n-1; + mjdmin=mjd[imin]; + mjdmax=mjd[imax]; dt=(float) 86400*(mjdmax-mjdmin); // Choose tickmarks @@ -862,11 +864,14 @@ void time_axis(double *mjd,int n,float xmin,float xmax,float ymin,float ymax) } else if (dt>900) { lsec=300; ssec=60; + } else if (dt>300) { + lsec=120; + ssec=60; } else { - lsec=60; - ssec=10; + lsec=20; + ssec=5; } - + // Extrema tmin=86400.0*(mjdmin-floor(mjdmin)); tmax=tmin+dt; @@ -881,8 +886,10 @@ void time_axis(double *mjd,int n,float xmin,float xmax,float ymin,float ymax) if (mjdt>=mjd[i] && mjdt