list.c

Go to the documentation of this file.
00001 /*                          L I S T . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup plot */
00023 /*@{*/
00024 /** @file libbn/list.c
00025  *
00026  *  NOTE that tp_2list() and tp_3list() are good candidates to become
00027  *  intrinsic parts of plot3.c, for efficiency reasons.
00028  *
00029  *  
00030  * @author Michael John Muuss
00031  * @n   August 04, 1978
00032  *
00033  *  @par Source
00034  *      SECAD/VLD Computing Consortium, Bldg 394
00035  *@n    The U. S. Army Ballistic Research Laboratory
00036  *@n    Aberdeen Proving Ground, Maryland  21005-5066
00037  *
00038  */
00039 
00040 
00041 #ifndef lint
00042 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbn/list.c,v 14.11 2006/09/05 04:19:55 lbutler Exp $ (BRL)";
00043 #endif
00044 
00045 #include "common.h"
00046 
00047 
00048 
00049 #include <stdio.h>
00050 #include "machine.h"
00051 #include "vmath.h"
00052 #include "plot3.h"
00053 
00054 /* Modes for internal flag */
00055 #define TP_MARK         1               /* Draw marks */
00056 #define TP_LINE         2               /* Draw lines */
00057 
00058 /**
00059  *                      T P _ I 2 L I S T
00060  *
00061  *  Take a set of x,y coordinates, and plot them as a
00062  *  polyline, ie, connect them with line segments.
00063  *  For markers, use tp_mlist(), below.
00064  *  This "C" interface expects arrays of INTs.
00065  */
00066 void
00067 tp_i2list(register FILE *fp, register int *x, register int *y, register int npoints)
00068 
00069                                         /* array of points */
00070                                         /* array of points */
00071 
00072 {
00073         if( npoints <= 0 )
00074                 return;
00075 
00076         pl_move( fp, *x++, *y++ );
00077         while( --npoints > 0 )
00078                 pl_cont( fp, *x++, *y++ );
00079 }
00080 
00081 /**
00082  *                      T P _ 2 L I S T
00083  *
00084  *  Take a set of x,y coordinates, and plot them as a
00085  *  polyline, ie, connect them with line segments.
00086  *  For markers, use tp_mlist(), below.
00087  *  This "C" interface expects arrays of DOUBLES.
00088  */
00089 void
00090 tp_2list(register FILE *fp, register double *x, register double *y, register int npoints)
00091 
00092                                         /* array of points */
00093                                         /* array of points */
00094 
00095 {
00096         if( npoints <= 0 )
00097                 return;
00098 
00099         pd_move( fp, *x++, *y++ );
00100         while( --npoints > 0 )
00101                 pd_cont( fp, *x++, *y++ );
00102 }
00103 
00104 void
00105 PL_FORTRAN(f2list, F2LIST)( fpp, x, y, n )
00106 FILE            **fpp;
00107 register float  *x;
00108 register float  *y;
00109 int             *n;
00110 {
00111         register int npoints = *n-1;    /* FORTRAN uses 1-based subscripts */
00112         register FILE   *fp = *fpp;
00113 
00114         if( npoints <= 0 )
00115                 return;
00116 
00117         pd_move( fp, *x++, *y++ );
00118         while( --npoints > 0 )
00119                 pd_cont( fp, *x++, *y++ );
00120 }
00121 
00122 /*
00123  *                      T P _ 3 L I S T
00124  */
00125 void
00126 tp_3list(FILE *fp, register double *x, register double *y, register double *z, register int npoints)
00127 {
00128         if( npoints <= 0 )
00129                 return;
00130 
00131         pd_3move( fp, *x++, *y++, *z++ );
00132         while( --npoints > 0 )
00133                 pd_3cont( fp, *x++, *y++, *z++ );
00134 }
00135 
00136 void
00137 PL_FORTRAN(f3list, F3LIST)( fpp, x, y, z, n )
00138 FILE            **fpp;
00139 register float  *x;
00140 register float  *y;
00141 register float  *z;
00142 int             *n;
00143 {
00144         register int npoints = *n-1;    /* FORTRAN uses 1-based subscripts */
00145         register FILE   *fp = *fpp;
00146 
00147         if( npoints <= 0 )
00148                 return;
00149 
00150         pd_3move( fp, *x++, *y++, *z++ );
00151         while( --npoints > 0 )
00152                 pd_3cont( fp, *x++, *y++, *z++ );
00153 }
00154 
00155 /**
00156  *                      T P _ 2 M L I S T
00157  *
00158  *  Take a set of x,y co-ordinates and plots them,
00159  *  with a combination of connecting lines and/or place markers.
00160  *  It is important to note that the arrays
00161  *  are arrays of doubles, and express UNIX-plot coordinates in the
00162  *  current pl_space().
00163  *
00164  *  tp_scale(TIG) may be called first to optionally re-scale the data.
00165  *
00166  *  The 'mark' character to be used for marking points off can be any
00167  *  printing ASCII character, or 001 to 005 for the special marker characters.
00168  *
00169  *  In addition, the value of the 'flag' variable determines the type
00170  *  of line to be drawn, as follows:
00171  *
00172  *@li   0       Draw nothing (rather silly)
00173  *@li   1       Marks only, no connecting lines.  Suggested interval=1.
00174  *@li   2       Draw connecting lines only.
00175  *@li   3       Draw line and marks
00176  */
00177 void
00178 tp_2mlist(FILE *fp, register double *x, register double *y, int npoints, int flag, int mark, int interval, double size)
00179 
00180 
00181                                         /* arrays of points */
00182 
00183                                         /* TP_MARK|TP_LINE */
00184                                         /* marker character to use */
00185                                         /* marker drawn every N points */
00186                                         /* marker size */
00187 {
00188         register int i;                 /* index variable */
00189         register int counter;           /* interval counter */
00190 
00191         if( npoints <= 0 )
00192                 return;
00193 
00194         if( flag & TP_LINE )
00195                 tp_2list( fp, x, y, npoints );
00196         if( flag & TP_MARK )  {
00197                 tp_2marker( fp, mark, *x++, *y++, size );
00198                 counter = 1;            /* Already plotted one */
00199                 for( i=1; i<npoints; i++ )  {
00200                         if( counter >= interval )  {
00201                                 tp_2marker( fp, mark, *x, *y, size );
00202                                 counter = 0;    /* We made a mark */
00203                         }
00204                         x++; y++;
00205                         counter++;              /* One more point done */
00206                 }
00207         }
00208 }
00209 
00210 /**
00211  *  This FORTRAN interface expects arrays of REALs (single precision).
00212  */
00213 void
00214 PL_FORTRAN(f2mlst, F2MLST)( fp, x, y, np, flag, mark, interval, size )
00215 FILE    **fp;
00216 float   *x;
00217 float   *y;
00218 int     *np;
00219 int     *flag;          /* indicates user's mode request */
00220 int     *mark;
00221 int     *interval;
00222 float   *size;
00223 {
00224         register int i;                 /* index variable */
00225         register int counter;           /* interval counter */
00226         register int npoints = *np-1;
00227 
00228         if( npoints <= 0 )
00229                 return;
00230 
00231         if( *flag & TP_LINE )
00232                 PL_FORTRAN(f2list,F2LIST)( fp, x, y, np );
00233         if( *flag & TP_MARK )  {
00234                 tp_2marker( *fp, *mark, *x++, *y++, *size );
00235                 counter = 1;                    /* We already plotted one */
00236                 for( i=1; i<npoints; i++ )  {
00237                         if( counter >= *interval )  {
00238                                 tp_2marker( *fp, *mark, *x, *y, *size );
00239                                 counter = 0;    /* Made a mark */
00240                         }
00241                         x++; y++;
00242                         counter++;              /* One more point done */
00243                 }
00244         }
00245 }
00246 /*@}*/
00247 /*
00248  * Local Variables:
00249  * mode: C
00250  * tab-width: 8
00251  * c-basic-offset: 4
00252  * indent-tabs-mode: t
00253  * End:
00254  * ex: shiftwidth=4 tabstop=8
00255  */

Generated on Mon Sep 18 01:24:48 2006 for BRL-CAD by  doxygen 1.4.6