SCOPE2 void cfwarn(int adr, int len, int up) { if (V(WARNING) != 0 && 0 != search_wid(adr, len, T(CURRENT), up)) { alerror(adr, len, up); ERROR(" isn't unique\n"); } }
/* * Equip a graph with its data points and calculate the Bezier spline control points: * The input data will be copied. */ void algraph_set_data(algraph *g, double datax[], double datay[], unsigned int n) { unsigned int i; if (g == NULL) aluierror("algraph_set_data: Graph not initialised."); g->data = (alpoint2d *) malloc(n * sizeof(alpoint2d)); if (g->data == NULL) alerror("algraph_set_data: Could not allocate memory!"); for (i = 0; i < n; i++) { g->data[i].x = datax[i]; g->data[i].y = datay[i]; } g->ndata = n; /* Calculate the Bezier spline control points and store them. */ algraph_calculate_bezier_control_points(g); }
/* * Add a new graph node to the list and set the current graph to the new graph. */ void algraph_list_add(algraph *graph) { unsigned int i; algraph_node *cur; algraph_node *new_node; current_graph = graph; #ifdef DEBUG printf("Entering algraph_list_add.\n"); #endif new_node = (algraph_node *) malloc(sizeof(algraph_node)); new_node->graph = graph; new_node->next = NULL; if (new_node == NULL) alerror("algraph_list_add: Could not allocate memory!\n"); if (graph_list.size == 0) { graph_list.size = 1; graph_list.root = new_node; //current_graph = &(graph_list.root->graph); /* set the current graph */ #ifdef DEBUG printf("Exit algraph_list_add (first element added).\n"); #endif return; } cur = graph_list.root; /* Iterate to the last element: */ for (i = 0; i < graph_list.size - 1; i++) { cur = cur->next; } cur->next = new_node; //current_graph = &(cur->next->graph); /* set the current graph */ graph_list.size++; #ifdef DEBUG printf("Exit algraph_list_add.\n"); #endif }
/* * Create a new graph and add it to the list of graphs */ void algraph_create() { static unsigned int id = 1; algraph *g = (algraph *) malloc(sizeof(algraph)); if (g == NULL) alerror("algraph_create: Could not allocate memory!"); g->id = id; id++; g->data = NULL; g->ndata = 0; g->show_graphline = true; g->linewidth = 1.0; g->linecolor.r = g->linecolor.g = g->linecolor.b = 0.0; g->linecolor.alpha = 1.0; g->name = NULL; g->legend = false; //g->show_points = false; //g->pointstyle = 0; //g->pointsize = 5.0; //g->pointcolor.r = g->pointcolor.g = g->pointcolor.b = 0.0; //g->pointcolor.alpha = 1.0; g->bezier_control_points = NULL; g->interpolation_method = 0; g->points.show = false; g->points.style = 0; g->points.size = 5.0; g->points.linewidth = 1.0; g->points.edgecolor.r = g->points.edgecolor.g = g->points.edgecolor.b = 1.0; g->points.edgecolor.alpha = 1.0; g->points.facecolor.r = g->points.facecolor.g = g->points.facecolor.b = 1.0; g->points.facecolor.alpha = 1.0; g->points.filled = false; //g->points = {.show = false, .style = 0, .size = 5.0, .linewidth = 1.0, // .edgecolor = {0.0, 0.0, 0.0, 1.0}, .facecolor = {0.0, 0.0, 0.0, 1.0}, // .filled = false }; algraph_list_add(g); }
/* * This simplified interpreter has no interpret state. * Everything that can be "interpreted" as opposed to "compiled" * is "magic", and is executed directly by this metacompiler. * It doesn't handle numbers either. */ int interpret_word(u_char *adr, cell len, cell *up) { char strbuf[32]; char *cstr = altocstr((char *)adr, len, strbuf, 32); xt_t xt; token_t pct; int immed; int number; if (ismagic(cstr, up)) return(1); if (alfind((char *)adr, len, (xt_t *)&xt, up) != 0) { /* * If the word we found is a primitive, use its primitive number * instead of its cfa */ pct = *(token_t *)xt; compile ( pct < MAXPRIM ? pct : CT_FROM_XT(xt, up) ); return(1); } if (sscanf(cstr,"%d",&number) == 1) { if (V(STATE)) { compile(PAREN_LIT); ncomma(number); } else { stack = number; } return(1); } /* Undefined */ alerror((char *)adr, len, up); FTHERROR(" ?\n"); return(0); }
void algraph_calculate_bezier_control_points(algraph *g) { unsigned int i; int j; double *mdiag; double *supdiag; double *subdiag; double *vx; /* rhs for x coordinates */ double *vy; /* rhs for y coordinates */ double *cprime; /* used in Thomas Algorithm */ double *dprimex; /* used in Thomas Algorithm */ double *dprimey; /* used in Thomas Algorithm */ double tmp; /* used in Thomas Algoritm */ unsigned int n_control_points = 2 * (g->ndata - 1); /* Maybe not needed: */ if (g->ndata == 0) alerror("algraph_calculate_bezier_control_points: No data specified!"); g->bezier_control_points = (alpoint2d*) malloc(n_control_points * sizeof(alpoint2d)); mdiag = (double *) malloc((g->ndata - 1) * sizeof(double)); supdiag = (double *) malloc((g->ndata - 1) * sizeof(double)); subdiag = (double *) malloc((g->ndata - 1) * sizeof(double)); vx = (double *) malloc((g->ndata - 1) * sizeof(double)); vy = (double *) malloc((g->ndata - 1) * sizeof(double)); if (g-> bezier_control_points == NULL || mdiag == NULL || supdiag == NULL || subdiag == NULL || vx == NULL || vy == NULL) alerror("algraph_calculate_bezier_control_points: Could not allocate memory!"); /* Initialize the matrix A */ mdiag[0] = 2.0; mdiag[g->ndata - 2] = 7.0; supdiag[0] = 1.0; supdiag[g->ndata - 2] = 0.0; subdiag[0] = 0.0; subdiag[g->ndata - 2] = 2.0; for (i = 1; i < g->ndata - 2; i++) { mdiag[i] = 4.0; supdiag[i] = subdiag[i] = 1.0; } /* Initialize the rhs */ vx[0] = g->data[0].x + 2 * g->data[1].x; vy[0] = g->data[0].y + 2 * g->data[1].y; vx[g->ndata - 2] = 8 * g->data[g->ndata - 2].x + g->data[g->ndata - 1].x; vy[g->ndata - 2] = 8 * g->data[g->ndata - 2].y + g->data[g->ndata - 1].y; for (i = 1; i < g->ndata - 2; i++) { vx[i] = 4 * g->data[i].x + 2 * g->data[i+1].x; vy[i] = 4 * g->data[i].y + 2 * g->data[i+1].y; } /* * Use Thomas Algorithm to solve the tridiagonal linear system: * http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm */ cprime = (double *) malloc((g->ndata - 1) * sizeof(double)); dprimex = (double *) malloc((g->ndata - 1) * sizeof(double)); dprimey = (double *) malloc((g->ndata - 1) * sizeof(double)); if (cprime == NULL || dprimex == NULL || dprimey == NULL) alerror("algraph_calculate_bezier_control_points: Could not allocate memory!"); cprime[0] = supdiag[0] / mdiag[0]; dprimex[0] = vx[0] / mdiag[0]; dprimey[0] = vy[0] / mdiag[0]; for (i = 1; i < g->ndata - 1; i++) { tmp = 1.0 / (mdiag[i] - cprime[i-1] * subdiag[i]); cprime[i] = supdiag[i] * tmp; dprimex[i] = (vx[i] - dprimex[i-1] * subdiag[i]) * tmp; dprimey[i] = (vy[i] - dprimey[i-1] * subdiag[i]) * tmp; } for (j = g->ndata - 2; j >= 0; j--) { dprimex[j] -= cprime[j] * dprimex[j+1]; dprimey[j] -= cprime[j] * dprimey[j+1]; } /* * Now we have the coordinates of the first bezier spline control points stored in the * arrays dprimex and primey. * Copy them into g->bezier_spline_control_points: */ j = 0; for (i = 0; i < g->ndata - 1; i++) { g->bezier_control_points[j].x = dprimex[i]; g->bezier_control_points[j].y = dprimey[i]; j += 2; } /* Calculate the second bezier spline control points */ j = 1; for (i = 0; i < g->ndata - 2; i++) { g->bezier_control_points[j].x = 2 * g->data[i+1].x - dprimex[i+1]; g->bezier_control_points[j].y = 2 * g->data[i+1].y - dprimey[i+1]; j += 2; } g->bezier_control_points[n_control_points - 1].x = 0.5 * (g->data[g->ndata - 1].x + dprimex[g->ndata - 2]); g->bezier_control_points[n_control_points - 1].y = 0.5 * (g->data[g->ndata - 1].y + dprimey[g->ndata - 2]); //#ifdef DEBUG // printf("algraph_bezier_control_points: Bezier Spline segments:\n"); // for (i = 0; i < g->ndata - 1; i++) { // printf("(%.3f, %.3f), ", g->data[i].x, g->data[i].y); // printf("(%.3f, %.3f), ", g->bezier_control_points[2*i].x, g->bezier_control_points[2*i].y); // printf("(%.3f, %.3f), ", g->bezier_control_points[2*i+1].x, g->bezier_control_points[2*i+1].y); // printf("(%.3f, %.3f)\n", g->data[i+1].x, g->data[i+1].y); // } //#endif free(cprime); free(dprimex); free(dprimey); free(mdiag); free(supdiag); free(subdiag); free(vx); free(vy); }
fatal(char *str, cell *up) { alerror(str, strlen(str), up); (void)exit(1); }