1
2C*GRGENV -- get value of PGPLOT environment parameter (MAC)
3C+
4      SUBROUTINE GRGENV(NAME, VALUE, L)
5      CHARACTER*(*) NAME, VALUE
6      INTEGER L
7C
8C Return the value of a PGPLOT environment parameter. In Sun/Convex-UNIX,
9C environment parameters are UNIX environment variables; e.g. parameter
10C ENVOPT is environment variable PGPLOT_ENVOPT. Translation is not
11C recursive and is case-sensitive.
12C
13C Arguments:
14C  NAME   : (input) the name of the parameter to evaluate.
15C  VALUE  : receives the value of the parameter, truncated or extended
16C           with blanks as necessary. If the parameter is undefined,
17C           a blank string is returned.
18C  L      : receives the number of characters in VALUE, excluding
19C           trailing blanks. If the parameter is undefined, zero is
20C           returned.
21C
22C On Macintosh, the environment variables are stored in file.  This subroutine
23C first looks for the file PGPLOTENVNAMES, in the application directory.
24C If it can't be found, a standard file dialog box will be displayed,
25C so that you can find the file.  Once it is found, the name and location are
26C stored so that you will not be prompted again.
27C--
28C 19-Jan-1988
29C 25-Sep-1995  Modified to work on mac with MPW Fortran 2.1.  All environment
30C              parameters are stored in the file.  The file can have any name
31C              but best thing to do is to put a file called pgplotenvnames
32C              in the application directory. See Tech. Note 35 for more information
33C              about Macintosh file system.  Note: this subroutine
34C              needs to be compiled with the -u switch to initialize volrefnum
35C              to zero, since a value less than zero specifies a folder.
36C-----------------------------------------------------------------------
37      INTEGER LIN, LUN,LStart,VolRefNum, JVRefNum
38      CHARACTER*32 TEST, Line*120, FilNam*120
39	  External JVRefNum
40	  Save FileName,VolRefNum
41
42C
43      TEST = 'PGPLOT_'//NAME
44      LIN = INDEX(TEST, ' ')-1
45	  Value = ' '
46	  L = 0
47	  Call GrgLun(LUN)
48
49C  If volume reference number has been set, switch to that volume.  The
50C  first time grgenv is called, volrefnum will not be set and the current
51C  directory is the application directory.  The volume reference number will
52C  be set after pgplotenvnames is found.
53	  If (VolRefNum .lt. 0) Then
54	     Call  F_SETVOLUME(VolRefNum)
55	  End If
56
57C  Try to open FilNam.  The first time that Grgenv is called Filnam will
58C  be empty and the open will fail.  So try to open pgplotenvnames in the
59C  current directory.  If that fails put up a standard file dialog box to
60C  find pgplotenvnames.  If FilNam has been set then after assigning a
61C  unit number to the file reset the volume reference number to the application
62C  directory.
63	  Open(Unit = lun,File=FilNam,Status='OLD',Err = 10,Readonly)
64	  Call F_SETVOLUME(JVREFNUM(-1))
65	  Go to 1
66
6710    Open(Unit = lun,File='pgplotenvnames',Status='OLD',Err = 20,Readonly)
68      FilNam = 'pgplotenvnames'
69	  VolRefNum = JVREFNUM(Lun)
70      Go to 1
71
72C Put up standard file dialog box.  Once found store the file name and volume
73C reference number.
7420    CALL GRWARN('Could not find file PGPLOTENVNAMES in current directory.')
75      CALL GRWARN('A dialog box will come up allowing you to find the file with the')
76      CALL GRWARN('environment variables. Hit return for the dialog box to appear.')
77      Pause
78      Open(Unit=lun,File=*,STATUS='OLD',err=100,Readonly)
79      Inquire(Unit=LUN,Name=FilNam)
80	  VolRefNum = JVREFNUM(Lun)
81
82C File has been found, so search for environmental variable and extract value.
831     Continue
84	     Read(Lun,'(A512)',End=2) Line
85	     If (Test(:Lin) .EQ. Line(:Lin)) Then
86	        Lstart = index(Line,"'")+1
87	        L = index(Line(Lstart:),"'")-1
88	        Value = Line(LStart:LStart+L-1)
89			Close(Lun)
90	        Go to 2
91	     End If
92	  Go to 1
932     Close(LUN)
94      Return
95
96
97C     Could not find PGPLOTENVNAMES.
98100   Close(LUN)
99      CALL GRWARN('Cancelled dialog box to find PGPLOTENVNAMES')
100      Return
101      END
102