C----------------------------------------------------------------------- C Sample FORTRAN 77 program to read a SpinDoctor plot file. C----------------------------------------------------------------------- C PROGRAM: MAIN C PURPOSE: To open the plot file, process the data, and close the file. C C REMARKS: If a command-line argument is provided, then the program C reads plot data from the file named by argument #1. Else, C it reads from standard input. C C DATE: 2000/09/06 T.W.H. C----------------------------------------------------------------------- CHARACTER PRGNAM*64, FILNAM*64 INTEGER IARGC, N, PLOT, RCODE, LPRG, LFIL INTEGER I(5) REAL X(5), Y(5) INTEGER FUNIT, STDIN, STDERR PARAMETER (FUNIT = 1, & STDIN = 5, & STDERR = 0) INTEGER ENDPLT PARAMETER (ENDPLT = 0) C C Open the input file. C IF (IARGC () .GE. 1) THEN CALL GETARG (1, FILNAM) PLOT = FUNIT OPEN (UNIT=PLOT, FILE=FILNAM, STATUS='OLD', & ACCESS='SEQUENTIAL', FORM='FORMATTED', IOSTAT=RCODE) IF (RCODE .NE. 0) THEN CALL GETARG (0, PRGNAM) LPRG = INDEX (PRGNAM, ' ') - 1 LFIL = INDEX (FILNAM, ' ') - 1 IF (LPRG .LE. 0) LPRG = LEN (PRGNAM) IF (LFIL .LE. 0) LFIL = LEN (FILNAM) WRITE (UNIT=STDERR, FMT=1) PRGNAM(1:LPRG), FILNAM(1:LFIL) 1 FORMAT (A, ': failed to open input ', A) STOP ENDIF ELSE PLOT = STDIN ENDIF C C Parse 5 (x,y,i) triples per input line. C 2 READ (UNIT=PLOT, FMT=3, IOSTAT=RCODE) (X(N), Y(N), I(N), N=1, 5) 3 FORMAT (5 (F8.3, F7.3, Z1)) IF (RCODE .NE. 0) GO TO 5 DO 4 N=1, 5 CALL PLTPNT (X(N), Y(N), I(N)) IF (I(N) .EQ. ENDPLT) GO TO 5 4 CONTINUE GO TO 2 C C Close the input file. C 5 IF (PLOT .NE. STDIN) CLOSE (UNIT=PLOT, STATUS='KEEP') STOP END C----------------------------------------------------------------------- C ROUTINE: PLTPNT C PURPOSE: To process an (x,y,i) triple from the plot file. C C ARGS: X,Y REAL x and y plot coordinates, in inches. C I INTEGER command code: C 0 End plot; ignore (X,Y). C 1 Unused; ignore. C 2 Pen down (draw) to (X,Y). C 3 Pen up (move) to (X,Y). C 4 Select pen #1; ignore (X,Y). C 5 Select pen #2; ignore (X,Y). C 6 Select pen #3; ignore (X,Y). C 7 Select pen #4; ignore (X,Y). C 8 Select pen #5; ignore (X,Y). C 9 Select pen #6; ignore (X,Y). C 10 Select pen #7; ignore (X,Y). C 11 Select pen #8; ignore (X,Y). C C REMARKS: Replace this subroutine with something useful. C C DATE: 2000/09/06 T.W.H. C----------------------------------------------------------------------- SUBROUTINE PLTPNT (X, Y, I) REAL X, Y INTEGER I C INTEGER STDOUT PARAMETER (STDOUT = 6) INTEGER ENDPLT, UNUSED, PENDN , PENUP , & PEN1 , PEN2 , PEN3 , PEN4 , & PEN5 , PEN6 , PEN7 , PEN8 PARAMETER (ENDPLT = 0, & UNUSED = 1, & PENDN = 2, & PENUP = 3, & PEN1 = 4, & PEN2 = 5, & PEN3 = 6, & PEN4 = 7, & PEN5 = 8, & PEN6 = 9, & PEN7 = 10, & PEN8 = 11) INTEGER N SAVE N DATA N /0/ C C This simply echos the input to the output in the same plot file C format. In some FORTRAN dialects, the '$' in the first FORMAT C suppresses the usual carriage-return / line-feed at the end of the C WRITE. The second WRITE ends the line after each set of 5 triples. C WRITE (UNIT=STDOUT, FMT=1) X, Y, I 1 FORMAT (F8.3, F7.3, Z1, $) N = MOD ((N + 1), 5) IF ((N .EQ. 0) .OR. (I .EQ. ENDPLT)) WRITE (UNIT=STDOUT, FMT=2) 2 FORMAT () RETURN END