| 1 |
c* *************************************************************************** |
| 2 |
c* MALOC = < Minimal Abstraction Layer for Object-oriented C > |
| 3 |
c* Copyright (C) 1994-- Michael Holst |
| 4 |
c* |
| 5 |
c* This library is free software; you can redistribute it and/or |
| 6 |
c* modify it under the terms of the GNU Lesser General Public |
| 7 |
c* License as published by the Free Software Foundation; either |
| 8 |
c* version 2.1 of the License, or (at your option) any later version. |
| 9 |
c* |
| 10 |
c* This library is distributed in the hope that it will be useful, |
| 11 |
c* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
c* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
c* Lesser General Public License for more details. |
| 14 |
c* |
| 15 |
c* You should have received a copy of the GNU Lesser General Public |
| 16 |
c* License along with this library; if not, write to the Free Software |
| 17 |
c* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
c* |
| 19 |
c* rcsid="$Id: mainf.f,v 1.10 2010/08/12 05:40:43 fetk Exp $" |
| 20 |
c* *************************************************************************** |
| 21 |
|
| 22 |
c***************************************************************************** |
| 23 |
c* FORTRAN interface to vnm library: |
| 24 |
c* |
| 25 |
c* int function vrand(); |
| 26 |
c* int function vrndmx(); |
| 27 |
c* double function vepsma(); |
| 28 |
c* subroutine vtstrt(timer, name, len); |
| 29 |
c* subroutine vtstop(timer, name, len); |
| 30 |
c* int function vsystm(cmd, len); |
| 31 |
c* subroutine vnmprt(int *unit, char *strng, int *len); |
| 32 |
c* |
| 33 |
c* timer --- integer timer number |
| 34 |
c* name --- char timer name of length eq len (with no '\0') |
| 35 |
c* cmd --- char command of length eq len (with no '\0') |
| 36 |
c* val --- integer tag number |
| 37 |
c* unit --- integer I/O unit number |
| 38 |
c* strng --- char message of length eq len (with no '\0') |
| 39 |
c* |
| 40 |
c* FORTRAN interface to vio library: |
| 41 |
c* |
| 42 |
c* int function vioctr(type, frmt, host, lenh, file, lenf, cmode) |
| 43 |
c* int function viodtr(sockn) |
| 44 |
c* int function vioutl(sockn, mode) |
| 45 |
c* subroutine vioint(sockn, ival, len) |
| 46 |
c* subroutine vioflt(sockn, rval, len) |
| 47 |
c* subroutine viodbl(sockn, dval, len) |
| 48 |
c* subroutine viostr(sockn, sval, len) |
| 49 |
c* |
| 50 |
c* sockn --- integer socket number |
| 51 |
c* |
| 52 |
c* type --- char*4 vio device type (FILE,PIPE,UNIX,INET,MPI1) |
| 53 |
c* frmt --- char*3 datatype (XDR,ASC) |
| 54 |
c* |
| 55 |
c* host --- char hostname of length eq lenh (with no '\0') |
| 56 |
c* file --- char filename of length eq lenf (with no '\0') |
| 57 |
c* |
| 58 |
c* cmode --- char*1 'r' create for read, or 'w' create for write |
| 59 |
c* mode --- char*1 'o' open, or 'c' close (both for read/write) |
| 60 |
c* |
| 61 |
c* ival --- int array of length len |
| 62 |
c* rval --- float array of length len |
| 63 |
c* dval --- double array of length len |
| 64 |
c* sval --- char array of length len (no terminating '\0') |
| 65 |
c* |
| 66 |
c***************************************************************************** |
| 67 |
|
| 68 |
program main |
| 69 |
c* *************************************************************************** |
| 70 |
c* File: mainf.f |
| 71 |
c* |
| 72 |
c* Purpose: Test the FORTRAN interface to the VNM and VIO libraries. |
| 73 |
c* |
| 74 |
c* Author: Michael Holst |
| 75 |
c* *************************************************************************** |
| 76 |
implicit none |
| 77 |
integer vio1, vio2, rc |
| 78 |
integer vioctr, viodtr, vioutl |
| 79 |
integer vrand, vrndmx |
| 80 |
double precision vepsma |
| 81 |
|
| 82 |
call vtstrt(10, "Test Program", 12); |
| 83 |
|
| 84 |
c* *** some VNM testing *** |
| 85 |
call vnmprt(0, '0: This message is being sent to VNM unit 0',43) |
| 86 |
call vnmprt(1, '1: This message is being sent to VNM unit 1',43) |
| 87 |
call vnmprt(2, '2: This message is being sent to VNM unit 2',43) |
| 88 |
call vnmpri(2, '2: A call to vrand() produces: ',34,vrand()) |
| 89 |
call vnmpri(2, '2: A call to vrndmx() produces: ',34,vrndmx()) |
| 90 |
call vnmprd(2, '2: A call to vepsma() produces: ',34,vepsma()) |
| 91 |
call vnmprt(2, '2: Sending "df" command to system ',34) |
| 92 |
call vsystm('df', 2) |
| 93 |
call vnmprt(2, '2: Returned from the "df" command ',34) |
| 94 |
|
| 95 |
c* *** start (initialize) the VIO library *** |
| 96 |
call viosta() |
| 97 |
|
| 98 |
c* *** you can call the VIO initializer multiple times w/o error *** |
| 99 |
call viosta() |
| 100 |
call viosta() |
| 101 |
call viosta() |
| 102 |
|
| 103 |
c* *** construct VIO1 (socket 1) and VIO2 (socket 2) *** |
| 104 |
vio1 = vioctr('INET', 'ASC', 'localhost',9, '1',1, 'w') |
| 105 |
if (vio1 .lt. 0) call vnmprt(2,'2: vioctr vio1 failed',21) |
| 106 |
vio2 = vioctr('INET', 'ASC', 'localhost',9, '2',1, 'w') |
| 107 |
if (vio2 .lt. 0) call vnmprt(2,'2: vioctr vio2 failed',21) |
| 108 |
|
| 109 |
c* *** open VIO1 and VIO2 connections for writing *** |
| 110 |
rc = vioutl(vio1,'o') |
| 111 |
if (rc .ne. 0) call vnmprt(2,'2: vioutl vio1 failed',21) |
| 112 |
rc = vioutl(vio2,'o') |
| 113 |
if (rc .ne. 0) call vnmprt(2,'2: vioutl vio2 failed',21) |
| 114 |
|
| 115 |
c* *** write things to VIO1 and VIO2 *** |
| 116 |
call myoutput(vio1) |
| 117 |
call myoutput(vio2) |
| 118 |
|
| 119 |
c* *** close VIO1 and VIO2 connections *** |
| 120 |
rc = vioutl(vio1,'c') |
| 121 |
if (rc .ne. 0) call vnmprt(2,'2: vioutl vio1 failed',21) |
| 122 |
rc = vioutl(vio2,'c') |
| 123 |
if (rc .ne. 0) call vnmprt(2,'2: vioutl vio2 failed',21) |
| 124 |
|
| 125 |
c* *** destroy VIO1 and VIO2 *** |
| 126 |
rc = viodtr(vio1) |
| 127 |
if (rc .ne. 0) call vnmprt(2,'2: viodtr vio1 failed',21) |
| 128 |
rc = viodtr(vio2) |
| 129 |
if (rc .ne. 0) call vnmprt(2,'2: viodtr vio2 failed',21) |
| 130 |
|
| 131 |
c* *** stop (de-initialize) the VIO library *** |
| 132 |
call viostp() |
| 133 |
|
| 134 |
c* *** you can call the VIO de-initializer multiple times w/o error *** |
| 135 |
call viostp() |
| 136 |
call viostp() |
| 137 |
call viostp() |
| 138 |
|
| 139 |
c* ************************************************************************ |
| 140 |
c* *** NOTE: once you call "viostp()" one time, you MUST call "viosta()" |
| 141 |
c* *** BEFORE you can use any VIO routines again...otherwise an |
| 142 |
c* *** error message is generated and you don't get any I/O. |
| 143 |
c* *** I.e., any calls to the VIO routine must be preceeded by |
| 144 |
c* *** at least one call to "viosta()", with no intervening calls |
| 145 |
c* *** to "viostp()". |
| 146 |
c* ************************************************************************ |
| 147 |
|
| 148 |
call vtstop(10, "Test Program", 12); |
| 149 |
call vnmprt(2,'2: Stopping the program. ',43) |
| 150 |
stop |
| 151 |
end |
| 152 |
c* *************************************************************************** |
| 153 |
subroutine myoutput(vio) |
| 154 |
integer vio |
| 155 |
|
| 156 |
c* *** write out a single red triangle in BH format *** |
| 157 |
call viostr(vio,'bhsingle',8) |
| 158 |
|
| 159 |
call viostr(vio,'putl',4) |
| 160 |
call vioint(vio,1,1) |
| 161 |
call vioflt(vio,1.0,1) |
| 162 |
call vioflt(vio,0.0,1) |
| 163 |
call vioflt(vio,0.0,1) |
| 164 |
|
| 165 |
call viostr(vio,'list',4) |
| 166 |
call vioint(vio,7,1) |
| 167 |
call viostr(vio,'fill',4) |
| 168 |
call vioint(vio,1,1) |
| 169 |
call vioint(vio,3,1) |
| 170 |
call vioflt(vio,0.1,1) |
| 171 |
call vioflt(vio,0.9,1) |
| 172 |
call vioflt(vio,0.1,1) |
| 173 |
call vioflt(vio,0.1,1) |
| 174 |
call vioflt(vio,0.1,1) |
| 175 |
call vioflt(vio,0.9,1) |
| 176 |
call vioflt(vio,0.1,1) |
| 177 |
call vioflt(vio,0.1,1) |
| 178 |
call vioflt(vio,0.1,1) |
| 179 |
call viostr(vio,'list',4) |
| 180 |
call vioint(vio,-7,1) |
| 181 |
|
| 182 |
call viostr(vio,'putl',4) |
| 183 |
call vioint(vio,-1,1) |
| 184 |
|
| 185 |
return |
| 186 |
end |
| 187 |
|