      SUBROUTINE SAVLOD (LUNIT, ID, M, N, IMG, JOB, XREAL, XIMAG)
      IMPLICIT NONE
C
C IMPLEMENT SAVE AND LOAD
C   LUNIT = LOGICAL UNIT NUMBER
C   ID    = NAME, FORMAT 4A1
C   M, N  = DIMENSIONS
C   IMG   = NONZERO IF XIMAG IS NONZERO
C   JOB   = 0     FOR SAVE
C         = SPACE AVAILABLE FOR LOAD
C   XREAL, XIMAG = REAL AND OPTIONAL IMAGINARY PARTS
C
      INTEGER LUNIT, ID(4), M, N, IMG, JOB
      DOUBLE PRECISION XREAL(*), XIMAG(*)
C
      INTEGER I, J, K, L
C
C
      IF (JOB.GT.0) GO TO 20
C
C ***      SAVE
10    CONTINUE
      WRITE (LUNIT, 101) ID, M, N, IMG
101   FORMAT (4A1, 3I4)
      DO 15 J = 1, N
        K = (J-1)*M+1
        L = J*M
        WRITE (LUNIT, 102) (XREAL(I), I = K, L)
        IF (IMG.NE.0) WRITE (LUNIT, 102) (XIMAG(I), I = K, L)
102     FORMAT (4Z18)
15    CONTINUE
      RETURN
C
C ***      LOAD
20    CONTINUE
      READ (LUNIT, 101, END = 30) ID, M, N, IMG
      IF (M*N.GT.JOB) GO TO 30
      DO 25 J = 1, N
        K = (J-1)*M+1
        L = J*M
        READ (LUNIT, 102, END = 30) (XREAL(I), I = K, L)
        IF (IMG.NE.0) READ (LUNIT, 102, END = 30) (XIMAG(I), I = K, L)
25    CONTINUE
      RETURN
C
C     END OF FILE
30    CONTINUE
      M = 0
      N = 0
C
      RETURN
      END
