	SUBROUTINE SAVE(NAME)
C
C	Note:  this is the UNIX version.
C
C       This subroutine opens a file to save the input parameters
C  requested by SAVEC.FOR which were required by USRINP.FOR.
C			Version 2, Donald H. Gudehus, October, 1983
C			Changed file type from UNKNOWN to NEW.
C			Version 2U, D. H. G., April 18, 1998
C			Put in call to IERRNO and changed file type
C			to UNKNOWN.
C			Version 2UU, D. H. G., October 14, 2001
C			Further Unix changes (eliminated .SVE).  Since
C			the extension must always be used under Unix,
C			any name with any extension is now possible.
C			Version 3, D. H. G., October 17, 2001
C			Changed formatting of output to save file
C			so that small numbers of parameters are arranged
C			horizontally on one line as before, but large numbers of
C			parameters are output on successive lines.  This allows
C			for arbitrarily large numbers of parameters for one
C			keyword.  Increased length of FLN, A, and B.
C			Version 4, D. H. G., September 20, 2002
C			Increased size of B to 2048 to cover variables of
C			large dimension.
C			Version 4UM, D. H. G., January 31, 2005
C			Changed DISPOSE to STATUS in CLOSE statement, and 
C			modified FORMAT 1001 to allow Absoft compiler to 
C			function on Mac OS.
C			Version 5, D. H. G., February 5, 2008
C			Further increased the size of B to 4096
C
	CHARACTER NAME*(*),FLN*132,A*132,B*4096
	COMMON/BKEY/B
	PARAMETER (LU=49) !  Logical unit for save file
C
	FLN=NAME
	OPEN(UNIT=LU,NAME=FLN,TYPE='UNKNOWN')
	RETURN
C
C
	ENTRY SAVEP(NAME,NL)
C
C       This subroutine writes the keyword NAME and the associated
C  parameters in the COMMON block BKEY, into the save file.
C  Called by USRINP.  The buffer B should be long enough to hold
C  all the values of a multidimensional variable associated with
C  any keyword.  Therefore it should be dimensioned as 2048 in some
C  subroutine, or preferably all subroutines, referencing the COMMON
C  block BKEY.
C
	IF (NL.GE.1) THEN !  Parameter was entered manually
	  IF (NL.LT.50) THEN !  Horizontally spaced
	    WRITE(LU,1000) NAME,B(1:NL)
1000	    FORMAT(1X,A,A)
	  ELSE !  Vertically spaced
	    WRITE(LU,1500) NAME
1500	    FORMAT(' ',A)
	    I=1
C  Find the beginning (the first non-blank character)
	    DO WHILE (I.LE.NL)
	      IF (B(I:I).EQ.' ') THEN
	        I=I+1
	      ELSE
C  Find the next blank
	        N1=I
	        N2=INDEX(B(N1:NL),' ')
C  Convert from relative to absolute
	        N2=N2+N1-1
	        IF (N2.GE.N1.AND.N2.LE.NL) THEN
	          WRITE(LU,1500) B(N1:N2-1)
	          I=N2+1
	        ELSE
	          WRITE(LU,1500) B(N1:NL)
	          I=NL+1 !  Ends the loop
	        END IF
	      END IF
	    END DO
	  END IF
	ELSE !  Default parameters
	  WRITE(LU,1500) NAME
	END IF
	RETURN
C
	ENTRY SAVEC(NAME)
C
C       This subroutine closes a save file.
C
	IF (NAME.EQ.'DELETE') CLOSE(UNIT=LU,STATUS='DELETE')
	IF (NAME.NE.'DELETE') CLOSE(UNIT=LU,STATUS='KEEP')
	RETURN
C
	ENTRY RESTR(NAME)
C
C       This subroutine appends the parameters from the save file
C  NAME to any optional parameters already in buffer B in
C  STRKEY when called by MIIPSOPT or any other application using
C  the .OPTION method.  Here buffer A only need be as long as the
C  longest keyword or the longest parameter associated with a
C  single dimension of a keyword, approximately 132 characters.
	FLN=NAME
	OPEN(UNIT=LU,NAME=FLN,ERR=20,TYPE='OLD')
	GO TO 21
   20	IERR=IERRNO()
	IF (IERR.EQ.2) THEN
	  CALL ERROR(-2,'CANT FIND THE SAVE FILE')
	  RETURN
	ELSE
	  CALL ERROR(-3,'OPEN ERROR FOR SAVE FILE')
	  RETURN
	END IF
   21	REWIND LU
   22	READ(LU,1001,END=23) NN,A
C1001	FORMAT(1X,Q,A<NN>)
1001	FORMAT(1X,Q,A) !  D.H.G
	CALL ADDKEY(A(:NN))
	GO TO 22
   23	CONTINUE
	CLOSE(UNIT=LU)
	RETURN
	END
