	SUBROUTINE SETDEFS(STATUS)
	INTEGER STATUS

	include 'cmpr.common'

	CHARACTER*1 IANS
	INTEGER CLI$GET_VALUE,CLI$PRESENT,lib$spawn
	EXTERNAL CLI$_PRESENT,CLI$_DEFAULTED,CLI$_ABSENT,CLI$_NEGATED
	INTEGER I,J

	IF (CLI$PRESENT('MANUAL') .eq. %LOC(CLI$_PRESENT) .or.
	1	CLI$PRESENT('AUTO') .eq. %LOC(CLI$_NEGATED)) THEN
	    DEFAULT = .false.
	    RETURN
	ELSEIF (CLI$PRESENT('MANUAL') .eq. %LOC(CLI$_NEGATED) .or.
	1	CLI$PRESENT('AUTO') .eq. %LOC(CLI$_PRESENT)) THEN
	    DEFAULT = .true.
	    RETURN
	ENDIF

	IF (.not. PROMPT) THEN
	  WRITE (lo,'(/A/)') ' Unable to prompt for defaults'
	  STATUS = .false.
	  RETURN
	ENDIF

21	FORMAT('$Use default options where possible ',A,': ')
	IF (PROMPT) THEN
	  WRITE(lo,21) '(Y/[N])'
	  READ (li,'(A)',err=3) ians
	  IF (ians .eq. 'Y' .or. ians .eq. 'y') DEFAULT = .true.
	ELSE
	  WRITE(lo,21) '([Y]/N)'
	  READ (li,'(A)',err=3) ians
	  IF (ians .eq. 'N' .or. ians .eq. 'n') DEFAULT = .false.
	ENDIF

C
C   XUNITDF	X axis default units
C		  0 = no scale change
C		  1 = d-space
C		  2 = two-theta at default wavelength
C		  3 = Q
10	WRITE(lo,'(A)') ' ',
	1	' Options for x-axis plotting units:'
	WRITE(lo,'(3x,a)')
	2	'0 = use file units','1 = d-space','2 = two-theta',
	3	'3 = Q'
	WRITE(lo,'(a,i1,a)')
	1	'$Enter the default x-axis plotting units [',
	2	XUNITDF,']: '
	READ (li,'(q,I)',err=10,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 3) goto 10
	  XUNITDF = J
	ENDIF
C
C   YUNITDF	Y axis default units
C		  0 = linear
C		  1 = SQRT(Intensity)
C		  2 = Log(Intensity))
15	WRITE(lo,'(A)') ' ',
	1	' Options for y-axis plotting units:'
	WRITE(lo,'(3x,a)')
	2	'0 = linear','1 = SQRT(Intensity)','2 = LOG(Intensity)'
	WRITE(lo,'(a,i1,a)')
	1	'$Enter the default y-axis plotting units [',
	2	YUNITDF,']: '
	READ (li,'(q,I)',err=15,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 2) goto 15
	  YUNITDF = J
	ENDIF
C
C   XSCLDF	X Axis scaling option
C		  0 = default (no prompt)
C		  1 = no default (prompt)
20	WRITE(lo,'(A)') ' ',
	1	' Options for x-axis scaling:'
	WRITE(lo,'(3x,a)') '0 = default (no prompt)',
	3	'1 = no default (prompt)'
	WRITE(lo,'(a,i1,a)') 
	1	'$Enter the default x-axis scaling option [',
	2	XSCLDF,']: '
	READ (li,'(q,I)',err=20,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 1) goto 20
	  XSCLDF = J
	ENDIF
C
C   YSCLDF	Y Axis scaling option
C		  0 = Extreme (no prompt)
C		  1 = Scale to first file
C		  2 = Relative scaling for each file
C		  3 = no default (prompt)
25	WRITE(lo,'(A)') ' ',
	1	' Options for y-axis scaling:'
	WRITE(lo,'(3x,a)') '0 = Maximum of all files (/EXTREME)',
	1	'1 = Scale to first file (/FIRST)',
	2	'2 = Relative scaling to maximum of each file (/RELATIVE)',
	3	'3 = no default (prompt showing maximums for all files)'
	WRITE(lo,'(a,i1,a)') 
	1	'$Enter the default y-axis scaling option [',
	2	YSCLDF,']: '
	READ (li,'(q,I)',err=25,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 3) goto 25
	  YSCLDF = J
	ENDIF
C
C    BOXDF	Box option
C		  0 = no default (prompt)
C		  1 = All files in one box, note offsets 
C		  2 = All files in separate boxes
30	WRITE(lo,'(A)') ' ',
	1	' Options display of multiple files:'
	WRITE(lo,'(3x,a)') '0 = no default (prompt)',
	1	'1 = place all files in one box (with optional offset)',
	2	'2 = place all files in separate boxes'
	WRITE(lo,'(a,i1,a)') 
	1	'$Enter the display option [',BOXDF,']: '
	READ (li,'(q,I)',err=30,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 2) goto 30
	  BOXDF = J
	ENDIF
C
C   XSTAKDF	Default offset when plotting in one box
40	WRITE(lo,'(/A,i3,A)') 
	1	'$Enter the X-axis default offset for 1 box plots [',
	1	XSTAKDF,'%] : '
	READ (li,'(q,I)',err=40,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 100) goto 40
	  XSTAKDF = J
	ENDIF
C
C   YSTAKDF	Default offset when plotting in one box
45	WRITE(lo,'(/A,i3,A)') 
	1	'$Enter the Y-axis default offset for 1 box plots [',
	1	YSTAKDF,'%] : '
	READ (li,'(q,I)',err=45,end=3) I,j
	IF (i .gt. 0) THEN
	  IF (j .lt. 0 .or. j .gt. 100) goto 45
	  YSTAKDF = J
	ENDIF
C
C   MISCDF	Misc plotting defaults (combinations allowed)
C		  0 = none of the below
C		  1 = Clip
C		  2 = draw grid
C		  4 = plots with label with file names
C		  8 = plots with label with file titles
C		 16 = prompt for plot size
50	IF (mod(MISCDF,2) .eq. 1) THEN
	  write (lo,22) 'Clip plot at limits'
22	  format(/1x,A,1x,'([Y]/N): ',$)
	  READ (li,'(A)',err=50,end=3) ians
	  IF (ians .eq. 'N' .or. ians .eq. 'n') MISCDF = MISCDF - 1
	ELSE
	  write (lo,23) 'Clip plot at limits'
23	  format(/1x,A,1x,'(Y/[N]): ',$)
	  READ (li,'(A)',err=50,end=3) ians
	  IF (ians .eq. 'Y' .or. ians .eq. 'y') MISCDF = MISCDF + 1
	ENDIF

51	IF (mod(MISCDF/2,2) .eq. 1) THEN
	  write (lo,22) 'Overlay plot(s) with a grid'
	  READ (li,'(A)',err=51,end=3) ians
	  IF (ians .eq. 'N' .or. ians .eq. 'n') MISCDF = MISCDF - 2
	ELSE
	  write (lo,23) 'Overlay plot(s) with a grid'
	  READ (li,'(A)',err=51,end=3) ians
	  IF (ians .eq. 'Y' .or. ians .eq. 'y') MISCDF = MISCDF + 2
	ENDIF

52	IF (mod(MISCDF/4,2) .eq. 1) THEN
	  write (lo,22) 'Label plots with file names'
	  READ (li,'(A)',err=52,end=3) ians
	  IF (ians .eq. 'N' .or. ians .eq. 'n') MISCDF = MISCDF - 4
	ELSE
	  write (lo,23) 'Label plots with file names'
	  READ (li,'(A)',err=52,end=3) ians
	  IF (ians .eq. 'Y' .or. ians .eq. 'y') MISCDF = MISCDF + 4
	ENDIF

53	IF (mod(MISCDF/8,2) .eq. 1) THEN
	  write (lo,22) 'Label plots with file titles'
	  READ (li,'(A)',err=53,end=3) ians
	  IF (ians .eq. 'N' .or. ians .eq. 'n') MISCDF = MISCDF - 8
	ELSE
	  write (lo,23) 'Label plots with file titles'
	  READ (li,'(A)',err=53,end=3) ians
	  IF (ians .eq. 'Y' .or. ians .eq. 'y') MISCDF = MISCDF + 8
	ENDIF

54	IF (mod(MISCDF/16,2) .eq. 1) THEN
	  write (lo,22) 'Prompt for plot dimensions'
	  READ (li,'(A)',err=53,end=3) ians
	  IF (ians .eq. 'N' .or. ians .eq. 'n') MISCDF = MISCDF - 16
	ELSE
	  write (lo,23) 'Prompt for plot dimensions'
	  READ (li,'(A)',err=53,end=3) ians
	  IF (ians .eq. 'Y' .or. ians .eq. 'y') MISCDF = MISCDF + 16
	ENDIF

	write (lo,'(/2A)') '$Save these options on disk for future',
	1	' CMPR runs (Y/[N]): '
	READ (li,'(A)',end=3) ians
	IF (ians .eq. 'Y' .or. ians .eq. 'y') THEN
	  CALL SAVEDEFS(STATUS)
	  CALL PS_PAUSE(prompt)
	ENDIF

3	STATUS = .true.

	RETURN
	END
C------------------------------------------------------------------------
	SUBROUTINE SAVEDEFS(STATUS)
	INTEGER STATUS

	include 'cmpr.common'
	CHARACTER*80 line
	INTEGER LENCH

	OPEN (file='PS_CMPR.DEFAULTS',STATUS='UNKNOWN',UNIT=OUT,
	1	CARRIAGECONTROL='LIST')

10	FORMAT(A,t11,i5,2x,A)
15	FORMAT(18x,A)
	WRITE (OUT,10) 'XUNITDF',XUNITDF,'X axis default units'
	WRITE (OUT,15) '0 = no scale change','1 = d-space',
	1	'2 = two-theta at default wavelength','3 = Q'
	WRITE (OUT,10) 'YUNITDF',YUNITDF,'Y axis default units'
	WRITE (OUT,15) '0 = linear','1 = SQRT','2 = LOG'
	WRITE (OUT,10) 'XSCLDF', XSCLDF,'X Axis scaling option'
	WRITE (OUT,15) '0 = default (no prompt)',
	3	'1 = no default (prompt)'
	WRITE (OUT,10) 'YSCLDF', YSCLDF,'Y Axis scaling option'
	WRITE (OUT,15) '0 = Extreme of all files',
	1	'1 = Scale to first file',
	2	'2 = Relative scaling for each file',
	3	'3 = no default (prompt)'
	WRITE (OUT,10) 'BOXDF',  BOXDF,'Box option'
	WRITE (OUT,15) '0 = no default (prompt)',
	1	'1 = All file in one box, optional offset',
	2	'2 = All files in separate boxes'
	WRITE (OUT,10) 'XSTAKDF',XSTAKDF,
	1	'X-axis default offset for 1 box plotting (%)'
	WRITE (OUT,10) 'YSTAKDF',YSTAKDF,
	1	'Y-axis default offset for 1 box plotting (%)'
	WRITE (OUT,10) 'MISCDF',MISCDF,'Misc plotting defaults'
	WRITE (OUT,15) '0 = none of the below','1 = Clip',
	1	'2 = draw grid','4 = plots with label with file names',
	2	'8 = plots with label with file titles',
	3	'16 = prompt for plot size'
	inquire(unit=out,name=line)
	write (lo,'(2a)') ' Writing file ',line(:lench(line))
	CLOSE(UNIT=OUT)
	RETURN
	END
C------------------------------------------------------------------------
	SUBROUTINE LOADDEFS(STATUS)
C Read defaults from PS_CMPR.DEFAULT
C   The file will be opened if present in the current directory or if not, 
C   in the login directory
	INTEGER STATUS
C------------------------------------------------------------------------

	include 'cmpr.common'
	CHARACTER*80 line
	LOGICAL endoffile
	INTEGER LENCH, LINNUM

C open file in current directory
	OPEN (file='PS_CMPR.DEFAULTS',STATUS='OLD',UNIT=OUT,
	1	CARRIAGECONTROL='LIST',err=100)
	goto 1

C not found, try to open file in login directory
100	OPEN (file='SYS$LOGIN:PS_CMPR.DEFAULTS',STATUS='OLD',UNIT=OUT,
	1	CARRIAGECONTROL='LIST',err=3)

1	inquire(unit=out,name=line)
	write (lo,'(2a)') ' Reading defaults from file ',
	1	line(:lench(line))

	LINNUM = 0
	endoffile = .false.
10	DO while (.not. endoffile)
	  READ (out,'(A)',end=99) line
	  LINNUM = LINNUM + 1
	  IF     (line(1:7) .eq. 'XUNITDF') THEN
	    READ(line,'(10x,i5)',err=101) XUNITDF
	  ELSEIF (line(1:7) .eq. 'YUNITDF') THEN
	    READ(line,'(10x,i5)',err=101) YUNITDF
	  ELSEIF (line(1:6) .eq. 'XSCLDF') THEN
	    READ(line,'(10x,i5)',err=101) XSCLDF
	  ELSEIF (line(1:6) .eq. 'YSCLDF') THEN
	    READ(line,'(10x,i5)',err=101) YSCLDF
	  ELSEIF (line(1:5) .eq. 'BOXDF') THEN
	    READ(line,'(10x,i5)',err=101) BOXDF
	  ELSEIF (line(1:7) .eq. 'XSTAKDF') THEN
	    READ(line,'(10x,i5)',err=101) XSTAKDF
	  ELSEIF (line(1:7) .eq. 'YSTAKDF') THEN
	    READ(line,'(10x,i5)',err=101) YSTAKDF
	  ELSEIF (line(1:6) .eq. 'MISCDF') THEN
	    READ(line,'(10x,i5)',err=101) MISCDF
	  ELSEIF (line(1:10) .ne. ' ') THEN
	    WRITE (lo,'(A,i3,A)') ' Warning: invalid line (#',LINNUM,
	1	') in Default file --'
	    WRITE (lo,'(5x,A)') line(:lench(line))
	  ENDIF
	ENDDO

99	CLOSE(unit=out)
	STATUS = .true.
	RETURN
101	WRITE (lo,'(A,i3,A)') ' Warning: error reading line (#',LINNUM,
	1	') in Default file --'
	WRITE (lo,'(5x,A)') line(:lench(line))
	goto 10

3	STATUS = .false.
	RETURN
	END
