aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-04-07 15:03:30 -0700
committerXiao Pan <xyz@flylightning.xyz>2025-04-07 15:03:30 -0700
commit7188b121e0c76610c17fe7cb9b62e789dd3e73e0 (patch)
tree9e9382697995789441b95e653fe47fd31d194c26
parentc2a2382f1f8922b0038117ffdb8d37ab84fe0d6c (diff)
use a constant instead for data arrary length
-rw-r--r--remote_plot.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/remote_plot.c b/remote_plot.c
index 23dc8cc..9355885 100644
--- a/remote_plot.c
+++ b/remote_plot.c
@@ -31,6 +31,8 @@
// like 15782 which is 7 bytes consider newline and \0?
#define MAX_XFER_BUF_SIZE 7
+#define LEN 10
+
// Variables for holding error return info from PLplot
static PLINT pl_errcode;
static char errmsg[160];
@@ -39,8 +41,8 @@ typedef struct {
ssh_session session;
sftp_session sftp;
PLINT id1;
- PLFLT t[10];
- PLFLT buffer[10];
+ PLFLT t[LEN];
+ PLFLT buffer[LEN];
GtkWidget *area;
}DATA;
@@ -67,7 +69,7 @@ static gboolean sftp_read_sync(gpointer user_data)
return SSH_ERROR;
}
- for(int i=0;i<9;i++)
+ for(int i=0;i<(LEN-1);i++)
data->buffer[i]=data->buffer[i+1];
for (;;) {
@@ -86,7 +88,7 @@ static gboolean sftp_read_sync(gpointer user_data)
//printf("id1 %d\n",data->id1);
//printf("t %f\n",data->t[9]);
//printf("before sftp_read_sync plstripa\n");
- data->buffer[9]=atof(buffer);
+ data->buffer[LEN-1]=atof(buffer);
//printf("after sftp_read_sync plstripa\n");
}
@@ -97,7 +99,7 @@ static gboolean sftp_read_sync(gpointer user_data)
return rc;
}
- for(int i=0;i<10;i++)
+ for(int i=0;i<LEN;i++)
data->t[i]++;
//printf("sftp_read_sync end\n");
@@ -297,7 +299,7 @@ static void draw_function (GtkDrawingArea *area,
autoy = 0; // autoscale y
acc = 1; // accumulate
- for(int i=0;i<10;i++)
+ for(int i=0;i<LEN;i++)
{
//printf("t%d %f\n",i,data->t[i]);
//printf("buffer%d %f\n",i,data->buffer[i]);
@@ -314,11 +316,11 @@ static void print_data (GtkWidget *widget, gpointer user_data)
{
DATA *data=user_data;
printf("t:");
- for(int i=0;i<10;i++)
+ for(int i=0;i<LEN;i++)
printf(" %g",data->t[i]);
printf("\n");
printf("buffer:");
- for(int i=0;i<10;i++)
+ for(int i=0;i<LEN;i++)
printf(" %g",data->buffer[i]);
printf("\n");
}
@@ -364,7 +366,7 @@ int main (int argc, char **argv)
GtkApplication *app;
int status;
- for(int i=0;i<10;i++)
+ for(int i=0;i<LEN;i++)
{
data.t[i]=i;
data.buffer[i]=0;