|
From: <arj...@us...> - 2009-01-13 20:58:58
|
Revision: 9298
http://plplot.svn.sourceforge.net/plplot/?rev=9298&view=rev
Author: arjenmarkus
Date: 2009-01-13 20:58:51 +0000 (Tue, 13 Jan 2009)
Log Message:
-----------
Tcl API expanded and slightly revised, so that the plmap and plmeridians
commands optionally take a procedure name as their first argument. This
procedure can then perform the coordinate transformation. Note: the
implementation could possibly be optimised, as now the matrix commands
are created with each invocation of the transformation procedure.
Modified Paths:
--------------
trunk/bindings/tcl/tclAPI.c
Modified: trunk/bindings/tcl/tclAPI.c
===================================================================
--- trunk/bindings/tcl/tclAPI.c 2009-01-13 12:50:08 UTC (rev 9297)
+++ trunk/bindings/tcl/tclAPI.c 2009-01-13 20:58:51 UTC (rev 9298)
@@ -2822,18 +2822,69 @@
* x[], y[] are the coordinates to be plotted.
\*--------------------------------------------------------------------------*/
+static char *transform_name; /* Name of the procedure that transforms the
+ coordinates */
+static Tcl_Interp *tcl_interp; /* Pointer to the current interp */
+static int return_code; /* Saved return code */
+
void
mapform(PLINT n, PLFLT *x, PLFLT *y)
{
int i;
double xp, yp, radius;
+ char *cmd;
+ tclMatrix *xPtr, *yPtr;
+
+ cmd = (char *) malloc( strlen(transform_name) + 40);
+
+ /* Build the (new) matrix commands and fill the matrices */
+ sprintf(cmd, "matrix %cx f %d", (char)1, n);
+ if (Tcl_Eval(tcl_interp, cmd) != TCL_OK) {
+ return_code = TCL_ERROR;
+ free(cmd);
+ return;
+ }
+ sprintf(cmd, "matrix %cy f %d", (char)1, n);
+ if (Tcl_Eval(tcl_interp, cmd) != TCL_OK) {
+ return_code = TCL_ERROR;
+ free(cmd);
+ return;
+ }
+
+ sprintf(cmd, "%cx", (char)1);
+ xPtr = Tcl_GetMatrixPtr(tcl_interp, cmd);
+ sprintf(cmd, "%cy", (char)1);
+ yPtr = Tcl_GetMatrixPtr(tcl_interp, cmd);
+
+ if (xPtr == NULL || yPtr == NULL ) return; /* Impossible, but still */
+
for (i = 0; i < n; i++) {
- radius = 90.0 - y[i];
- xp = radius * cos(x[i] * PI / 180.0);
- yp = radius * sin(x[i] * PI / 180.0);
- x[i] = xp;
- y[i] = yp;
+ xPtr->fdata[i] = x[i];
+ yPtr->fdata[i] = y[i];
}
+
+ /* Now call the Tcl procedure to do the work */
+ sprintf(cmd, "%s %d %cx %cy", transform_name, n, (char)1, (char)1);
+ return_code = Tcl_Eval(tcl_interp, cmd);
+ if (return_code != TCL_OK) {
+ free(cmd);
+ return;
+ }
+
+ /* Don't forget to copy the results back into the original arrays
+ */
+ for (i = 0; i < n; i++) {
+ x[i] = xPtr->fdata[i] ;
+ y[i] = yPtr->fdata[i] ;
+ }
+
+ /* Clean up, otherwise the next call will fail - [matrix] does not
+ overwrite existing commands
+ */
+ sprintf(cmd, "rename %cx {}; rename %cy {}", (char)1, (char)1);
+ return_code = Tcl_Eval(tcl_interp, cmd);
+
+ free(cmd);
}
/*--------------------------------------------------------------------------*\
@@ -2852,27 +2903,48 @@
{
PLFLT minlong, maxlong, minlat, maxlat;
PLINT transform;
+ PLINT idxname;
+ char cmd[40];
- if (argc < 7 ) {
+ return_code = TCL_OK;
+ if (argc < 6 || argc > 7) {
Tcl_AppendResult(interp, "bogus syntax for plmap, see doc.",
(char *) NULL );
return TCL_ERROR;
}
- transform = atoi(argv[2]);
- minlong = atof( argv[3] );
- maxlong = atof( argv[4] );
- minlat = atof( argv[5] );
- maxlat = atof( argv[6] );
+ if ( argc == 6 ) {
+ transform = 0;
+ idxname = 1;
+ transform_name = NULL;
+ minlong = atof( argv[2] );
+ maxlong = atof( argv[3] );
+ minlat = atof( argv[4] );
+ maxlat = atof( argv[5] );
+ } else {
+ transform = 1;
+ idxname = 2;
+ minlong = atof( argv[3] );
+ maxlong = atof( argv[4] );
+ minlat = atof( argv[5] );
+ maxlat = atof( argv[6] );
- if (transform) {
- plmap(&mapform, argv[1], minlong, maxlong, minlat, maxlat);
+ tcl_interp = interp;
+ transform_name = argv[1];
+ if (strlen(transform_name) == 0) {
+ idxname = 1;
+ }
+ }
+
+ if (transform && idxname == 2) {
+ plmap(&mapform, argv[idxname], minlong, maxlong, minlat, maxlat);
} else {
- plmap(NULL, argv[1], minlong, maxlong, minlat, maxlat);
+ /* No transformation given */
+ plmap(NULL, argv[idxname], minlong, maxlong, minlat, maxlat);
}
plflush();
- return TCL_OK;
+ return return_code;
}
/*--------------------------------------------------------------------------*\
@@ -2892,20 +2964,39 @@
PLFLT dlong, dlat, minlong, maxlong, minlat, maxlat;
PLINT transform;
- if (argc < 8 ) {
- Tcl_AppendResult(interp, "bogus syntax for plmap, see doc.",
+ return_code = TCL_OK;
+
+ if (argc < 7 || argc > 8) {
+ Tcl_AppendResult(interp, "bogus syntax for plmeridians, see doc.",
(char *) NULL );
return TCL_ERROR;
}
- transform = atoi(argv[1]);
- dlong = atof( argv[2] );
- dlat = atof( argv[3] );
- minlong = atof( argv[4] );
- maxlong = atof( argv[5] );
- minlat = atof( argv[6] );
- maxlat = atof( argv[7] );
+ if ( argc == 7 ) {
+ transform = 0;
+ transform_name = NULL;
+ dlong = atof( argv[1] );
+ dlat = atof( argv[2] );
+ minlong = atof( argv[3] );
+ maxlong = atof( argv[4] );
+ minlat = atof( argv[5] );
+ maxlat = atof( argv[6] );
+ } else {
+ dlong = atof( argv[2] );
+ dlat = atof( argv[3] );
+ minlong = atof( argv[4] );
+ maxlong = atof( argv[5] );
+ minlat = atof( argv[6] );
+ maxlat = atof( argv[7] );
+ transform = 1;
+ tcl_interp = interp;
+ transform_name = argv[1];
+ if (strlen(transform_name) == 0) {
+ transform = 0;
+ }
+ }
+
if (transform) {
plmeridians(&mapform, dlong, dlat, minlong, maxlong, minlat, maxlat);
} else {
@@ -3060,6 +3151,13 @@
}
}
+ fprintf(stderr,"nx, ny: %d %d\n", nx, ny);
+ fprintf(stderr,"xmin, xmax: %.17g %.17g\n", xmin, xmax);
+ fprintf(stderr,"ymin, ymax: %.17g %.17g\n", ymin, ymax);
+ fprintf(stderr,"zmin, zmax: %.17g %.17g\n", zmin, zmax);
+ fprintf(stderr,"Dxmin, Dxmax: %.17g %.17g\n", Dxmin, Dxmax);
+ fprintf(stderr,"Dymin, Dymax: %.17g %.17g\n", Dymin, Dymax);
+
c_plimage(pidata, nx, ny, xmin, xmax, ymin, ymax, zmin, zmax,
Dxmin, Dxmax, Dymin, Dymax);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|