fortran.c

Go to the documentation of this file.
00001 /*                       F O R T R A N . 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 fort */
00023 /*@{*/
00024 /** @file fortran.c
00025  * @brief
00026  *  A FORTRAN-callable interface to libplot3.
00027  *
00028  *  A FORTRAN-callable interface to libplot3, which is
00029  *  a public-domain UNIX plot library, for 2-D and 3-D plotting in
00030  *  16-bit signed integer spaces, and in floating point.
00031  *
00032  *  Note that all routines which expect floating point parameters
00033  *  currently expect them to be of
00034  *  type "float" (single precision) so that all FORTRAN constants
00035  *  can be written normally, rather than having to insist on
00036  *  FORTRAN "double precision" parameters.
00037  *  This is at odds with the C routines and the meta-file format,
00038  *  which both operate in "C double" precision.
00039  *
00040  *  Note that on machines like the Cray,
00041  *      (C float == C double == FORTRAN REAL) != FORTRAN DOUBLE PRECISION
00042  *
00043  *  Also note that on the Cray, the only interface provision required
00044  *  is that the subroutine name be in all upper case.  Other systems
00045  *  may have different requirements, such as adding a leading underscore.
00046  *  It is not clear how to handle this in a general way.
00047  *
00048  *  Note that due to the 6-character name space required to be
00049  *  generally useful in the FORTRAN environment, the names have been
00050  *  shortened.  At the same time, a consistency of naming has been
00051  *  implemented;  the first character or two giving a clue as to
00052  *  the purpose of the subroutine:
00053  *
00054  *@li   I       General routines, and integer-parameter routines
00055  *@li   I2      Routines with enumerated 2-D integer parameters
00056  *@li   I3      Routines with enumerated 3-D integer parameters
00057  *@li   F2      Routines with enumerated 2-D float parameters
00058  *@li   F3      Routines with enumerated 3-D float parameters
00059  *@li   A3      Routines with arrays of 3-D float parameters
00060  *
00061  *  This name space leaves the door open for a double-precision
00062  *  family of routines, D, D2, and D3.
00063  *
00064  *
00065  *  @author
00066  *      Mike Muuss
00067  *
00068  *  @par Source -
00069  *      SECAD/VLD Computing Consortium, Bldg 394
00070  *@n    The U. S. Army Ballistic Research Laboratory
00071  *@n    Aberdeen Proving Ground, Maryland  21005-5066
00072  *
00073  */
00074 
00075 
00076 #ifndef lint
00077 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbn/fortran.c,v 14.11 2006/09/02 14:02:14 lbutler Exp $ (BRL)";
00078 #endif
00079 
00080 #include "common.h"
00081 
00082 
00083 
00084 #include <stdio.h>
00085 
00086 #include "machine.h"
00087 #include "plot3.h"
00088 /**
00089  *                      P L _ S T R N C P Y
00090  *
00091  *  Make null-terminated copy of a string in output buffer,
00092  *  being careful not to exceed indicated buffer size
00093  *  Accept "$" as alternate string-terminator for FORTRAN Holerith constants,
00094  *  because getting FORTRAN to null-terminate strings is to painful
00095  *  (and non-portable) to contemplate.
00096  */
00097 void
00098 pl_strncpy(register char *out, register char *in, register int sz)
00099 {
00100         register int c = '\0';
00101 
00102         while( --sz > 0 && (c = *in++) != '\0' && c != '$' )
00103                 *out++ = c;
00104         *out++ = '\0';
00105 }
00106 
00107 /**
00108  *  Macro 'F' is used to take the 'C' function name,
00109  *  and convert it to the convention used for a particular system.
00110  *  Both lower-case and upper-case alternatives have to be provided
00111  *  because there is no way to get the C preprocessor to change the
00112  *  case of a token.
00113  */
00114 #if CRAY
00115 #       define  F(lc,uc)        uc
00116 #endif
00117 #if defined(apollo) || defined(mips) || defined(aux)
00118         /* Lower case, with a trailing underscore */
00119 #ifdef __STDC__
00120 #       define  F(lc,uc)        lc ## _
00121 #else
00122 #       define  F(lc,uc)        lc/**/_
00123 #endif
00124 #endif
00125 #if !defined(F)
00126 #       define  F(lc,uc)        lc
00127 #endif
00128 
00129 /*
00130  *  These interfaces provide necessary access to C library routines
00131  *  from the FORTRAN environment
00132  */
00133 
00134 /**
00135  *                      I F D O P E
00136  *
00137  *  Open a file descriptor for plotting.
00138  */
00139 void
00140 F(ifdopn,IFDOPN)( plotfp, fd )
00141 FILE    **plotfp;
00142 int     *fd;
00143 {
00144         if( (*plotfp = fdopen(*fd, "w")) == NULL )
00145                 perror("IFDOPN/fdopen");
00146 }
00147 
00148 /**
00149  *                      I F O P E N
00150  *
00151  *  Open a file (by name) for plotting.
00152  */
00153 void
00154 F(ifopen,IFOPEN)( plotfp, name )
00155 FILE    **plotfp;
00156 char    *name;
00157 {
00158         char    buf[128];
00159 
00160         pl_strncpy( buf, name, (int)sizeof(buf) );
00161         if( (*plotfp = fopen(buf, "w")) == NULL )
00162                 perror(buf);
00163 }
00164 
00165 /*
00166  *  These interfaces provide the standard UNIX-Plot functionality
00167  */
00168 
00169 void
00170 F(i2pnt,I2PNT)( plotfp, x, y )
00171 FILE    **plotfp;
00172 int     *x, *y;
00173 {
00174         pl_point( *plotfp, *x, *y );
00175 }
00176 
00177 void
00178 F(i2line,I2LINE)( plotfp, x1, y1, x2, y2 )
00179 FILE    **plotfp;
00180 int     *x1, *y1, *x2, *y2;
00181 {
00182         pl_line( *plotfp, *x1, *y1, *x2, *y2 );
00183 }
00184 
00185 void
00186 F(ilinmd,ILINMD)( plotfp, s )
00187 FILE    **plotfp;
00188 char *s;
00189 {
00190         char buf[32];
00191         pl_strncpy( buf, s, (int)sizeof(buf) );
00192         pl_linmod( *plotfp, buf );
00193 }
00194 
00195 void
00196 F(i2move,I2MOVE)( plotfp, x, y )
00197 FILE    **plotfp;
00198 int     *x, *y;
00199 {
00200         pl_move( *plotfp, *x, *y );
00201 }
00202 
00203 void
00204 F(i2cont,I2CONT)( plotfp, x, y )
00205 FILE    **plotfp;
00206 int     *x, *y;
00207 {
00208         pl_cont( *plotfp, *x, *y );
00209 }
00210 
00211 void
00212 F(i2labl,I2LABL)( plotfp, s )
00213 FILE    **plotfp;
00214 char *s;
00215 {
00216         char    buf[256];
00217         pl_strncpy( buf, s, (int)sizeof(buf) );
00218         pl_label( *plotfp, buf );
00219 }
00220 
00221 void
00222 F(i2spac,I2SPAC)( plotfp, x1, y1, x2, y2 )
00223 FILE    **plotfp;
00224 int     *x1, *y1, *x2, *y2;
00225 {
00226         pl_space( *plotfp, *x1, *y1, *x2, *y2 );
00227 }
00228 
00229 void
00230 F(ierase,IERASE)( plotfp )
00231 FILE    **plotfp;
00232 {
00233         pl_erase( *plotfp );
00234 }
00235 
00236 void
00237 F(i2circ,I2CIRC)( plotfp, x, y, r )
00238 FILE    **plotfp;
00239 int     *x, *y, *r;
00240 {
00241         pl_circle( *plotfp, *x, *y, *r );
00242 }
00243 
00244 void
00245 F(i2arc,I2ARC)( plotfp, xc, yc, x1, y1, x2, y2 )
00246 FILE    **plotfp;
00247 int     *xc, *yc, *x1, *y1, *x2, *y2;
00248 {
00249         pl_arc( *plotfp, *xc, *yc, *x1, *y1, *x2, *y2 );
00250 }
00251 
00252 void
00253 F(i2box,I2BOX)( plotfp, x1, y1, x2, y2 )
00254 FILE    **plotfp;
00255 int     *x1, *y1, *x2, *y2;
00256 {
00257         pl_box( *plotfp, *x1, *y1, *x2, *y2 );
00258 }
00259 
00260 /*
00261  * Here lie the BRL 3-D extensions.
00262  */
00263 
00264 /* Warning: r, g, b are ints.  The output is chars. */
00265 void
00266 F(icolor,ICOLOR)( plotfp, r, g, b )
00267 FILE    **plotfp;
00268 int     *r, *g, *b;
00269 {
00270         pl_color( *plotfp, *r, *g, *b );
00271 }
00272 
00273 void
00274 F(iflush,IFLUSH)( plotfp )
00275 FILE    **plotfp;
00276 {
00277         pl_flush( *plotfp );
00278 }
00279 
00280 void
00281 F(i3spac,I3SPAC)( plotfp, x1, y1, z1, x2, y2, z2 )
00282 FILE    **plotfp;
00283 int     *x1, *y1, *z1, *x2, *y2, *z2;
00284 {
00285         pl_3space( *plotfp, *x1, *y1, *z1, *x2, *y2, *z2 );
00286 }
00287 
00288 void
00289 F(i3pnt,I3PNT)( plotfp, x, y, z )
00290 FILE    **plotfp;
00291 int     *x, *y, *z;
00292 {
00293         pl_3point( *plotfp, *x, *y, *z );
00294 
00295 }
00296 
00297 void
00298 F(i3move,I3MOVE)( plotfp, x, y, z )
00299 FILE    **plotfp;
00300 int     *x, *y, *z;
00301 {
00302         pl_3move( *plotfp, *x, *y, *z );
00303 }
00304 
00305 void
00306 F(i3cont,I3CONT)( plotfp, x, y, z )
00307 FILE    **plotfp;
00308 int     *x, *y, *z;
00309 {
00310         pl_3cont( *plotfp, *x, *y, *z );
00311 }
00312 
00313 void
00314 F(i3line,I3LINE)( plotfp, x1, y1, z1, x2, y2, z2 )
00315 FILE    **plotfp;
00316 int     *x1, *y1, *z1, *x2, *y2, *z2;
00317 {
00318         pl_3line( *plotfp, *x1, *y1, *z1, *x2, *y2, *z2 );
00319 }
00320 
00321 void
00322 F(i3box,I3BOX)( plotfp, x1, y1, z1, x2, y2, z2 )
00323 FILE    **plotfp;
00324 int     *x1, *y1, *z1, *x2, *y2, *z2;
00325 {
00326         pl_3box( *plotfp, *x1, *y1, *z1, *x2, *y2, *z2 );
00327 }
00328 
00329 /*
00330  *  Floating point routines.
00331  */
00332 
00333 void
00334 F(f2pnt,F2PNT)( plotfp, x, y )
00335 FILE    **plotfp;
00336 float   *x, *y;
00337 {
00338         pd_point( *plotfp, *x, *y );
00339 }
00340 
00341 void
00342 F(f2line,F2LINE)( plotfp, x1, y1, x2, y2 )
00343 FILE    **plotfp;
00344 float   *x1, *y1, *x2, *y2;
00345 {
00346         pd_line( *plotfp, *x1, *y1, *x2, *y2 );
00347 }
00348 
00349 void
00350 F(f2move,F2MOVE)( plotfp, x, y )
00351 FILE    **plotfp;
00352 float   *x, *y;
00353 {
00354         pd_move( *plotfp, *x, *y );
00355 }
00356 
00357 void
00358 F(f2cont,F2CONT)( plotfp, x, y )
00359 FILE    **plotfp;
00360 float   *x, *y;
00361 {
00362         pd_cont( *plotfp, *x, *y );
00363 }
00364 
00365 void
00366 F(f2spac,F2SPAC)( plotfp, x1, y1, x2, y2 )
00367 FILE    **plotfp;
00368 float   *x1, *y1, *x2, *y2;
00369 {
00370         pd_space( *plotfp, *x1, *y1, *x2, *y2 );
00371 }
00372 
00373 void
00374 F(f2circ,F2CIRC)( plotfp, x, y, r )
00375 FILE    **plotfp;
00376 float   *x, *y, *r;
00377 {
00378         pd_circle( *plotfp, *x, *y, *r );
00379 }
00380 
00381 void
00382 F(f2arc,F2ARC)( plotfp, xc, yc, x1, y1, x2, y2 )
00383 FILE    **plotfp;
00384 float   *xc, *yc, *x1, *y1, *x2, *y2;
00385 {
00386         pd_arc( *plotfp, *xc, *yc, *x1, *y1, *x2, *y2 );
00387 }
00388 
00389 void
00390 F(f2box,F2BOX)( plotfp, x1, y1, x2, y2 )
00391 FILE    **plotfp;
00392 float   *x1, *y1, *x2, *y2;
00393 {
00394         pd_box( *plotfp, *x1, *y1, *x2, *y2 );
00395 }
00396 
00397 /*
00398  *  Floating-point 3-D, both in array (vector) and enumerated versions.
00399  *  The same remarks about float/double apply as above.
00400  */
00401 
00402 void
00403 F(a2spac,A3SPAC)( plotfp, min, max )
00404 FILE    **plotfp;
00405 float   min[3];
00406 float   max[3];
00407 {
00408         pd_3space( *plotfp, min[0], min[1], min[2], max[0], max[1], max[2] );
00409 }
00410 
00411 void
00412 F(f3spac,F3SPAC)( plotfp, x1, y1, z1, x2, y2, z2 )
00413 FILE    **plotfp;
00414 float   *x1, *y1, *z1, *x2, *y2, *z2;
00415 {
00416         pd_3space( *plotfp, *x1, *y1, *z1, *x2, *y2, *z2 );
00417 }
00418 
00419 void
00420 F(a3pnt,A3PNT)( plotfp, pt )
00421 FILE    **plotfp;
00422 float   pt[3];
00423 {
00424         pd_3point( *plotfp, pt[0], pt[1], pt[2] );
00425 }
00426 
00427 void
00428 F(f3pnt,F3PNT)( plotfp, x, y, z )
00429 FILE    **plotfp;
00430 float   *x, *y, *z;
00431 {
00432         pd_3point( *plotfp, *x, *y, *z );
00433 }
00434 
00435 void
00436 F(a3move,A3MOVE)( plotfp, pt )
00437 FILE    **plotfp;
00438 float   pt[3];
00439 {
00440         pd_3move( *plotfp, pt[0], pt[1], pt[2] );
00441 }
00442 
00443 void
00444 F(f3move,F3MOVE)( plotfp, x, y, z )
00445 FILE    **plotfp;
00446 float   *x, *y, *z;
00447 {
00448         pd_3move( *plotfp, *x, *y, *z );
00449 }
00450 
00451 void
00452 F(a3cont,A3CONT)( plotfp, pt )
00453 FILE    **plotfp;
00454 float   pt[3];
00455 {
00456         pd_3cont( *plotfp, pt[0], pt[1], pt[2] );
00457 }
00458 
00459 void
00460 F(f3cont,F3CONT)( plotfp, x, y, z )
00461 FILE    **plotfp;
00462 float   *x, *y, *z;
00463 {
00464         pd_3cont( *plotfp, *x, *y, *z );
00465 }
00466 
00467 void
00468 F(a3line,A3LINE)( plotfp, a, b )
00469 FILE    **plotfp;
00470 float   a[3], b[3];
00471 {
00472         pd_3line( *plotfp, a[0], a[1], a[2], b[0], b[1], b[2] );
00473 }
00474 
00475 void
00476 F(f3line,F3LINE)( plotfp, x1, y1, z1, x2, y2, z2 )
00477 FILE    **plotfp;
00478 float   *x1, *y1, *z1, *x2, *y2, *z2;
00479 {
00480         pd_3line( *plotfp, *x1, *y1, *z1, *x2, *y2, *z2 );
00481 }
00482 
00483 void
00484 F(a3box,A3BOX)( plotfp, a, b )
00485 FILE    **plotfp;
00486 float   a[3], b[3];
00487 {
00488         pd_3box( *plotfp, a[0], a[1], a[2], b[0], b[1], b[2] );
00489 }
00490 
00491 void
00492 F(f3box,F3BOX)( plotfp, x1, y1, z1, x2, y2, z2 )
00493 FILE    **plotfp;
00494 float   *x1, *y1, *z1, *x2, *y2, *z2;
00495 {
00496         pd_3box( *plotfp, *x1, *y1, *z1, *x2, *y2, *z2 );
00497 }
00498 
00499 /*@}*/
00500 /*
00501  * Local Variables:
00502  * mode: C
00503  * tab-width: 8
00504  * c-basic-offset: 4
00505  * indent-tabs-mode: t
00506  * End:
00507  * ex: shiftwidth=4 tabstop=8
00508  */

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