C  This has never been udated from the xerox 560 version to the vax
C  It is on my list of things to do but rather low at the moment.
C
C PROGRAM TO SET UP INPUT DECK FOR SOPREF
C ASSIGN F:10 TO AN OUTPUT FILE OF ANY NAME
C ASSIGN F:20 TO YOUR TWO-THETA AND INTENSITY FILE
C ASSIGN F:30 TO THE OUTPUT FILE FROM SOPOWDER
      DIMENSION LOG(12),NAME(12),ITITLE(19),IGO(4),TT(100)
      DIMENSION ITEM(9), KARD(20), KARDC(80)
      DATA YES/'Y'/,IBL/' '/,ICOM/','/
      WAVE=1.5405
      ITYP = 6
      IREAD = 5
      ITP1 = 10
      WRITE(ITYP,2)
    2 FORMAT(' * PROGRAM TO SET UP DECK FOR COMPUTER'
     1 ' RUN OF PREF.')
      WRITE(ITYP,9876)
9876  FORMAT(/,' SET F:10 TO YOUR BATCH FILE FOR OUTPUT',/,
     +' SET F:20 TO THE INPUT TWO-THETA AND INTENSITY FILE',/,
     +' SET F:30 TO THE CALCULATED PATTERN FROM LMDEAN',//,
     +' F:10 MUST BE SET.  INPUT FOR F:20 AND F:30 MAY BE TYPED',/,
     +' IN IF THESE FILES ARE NOT AVAILABLE.')
      WRITE(ITYP,101)
  101 FORMAT(/' TYPE THE FIRST TWO WORDS IN YOUR LOGON CODE'/
     1' WITH COMMA---E.G. FXRAY,75')
      READ(IREAD,108)LOG
  108 FORMAT(12A1)
  102 FORMAT(20A4)
      WRITE(ITYP,103)
  103 FORMAT(/' TYPE YOUR LAST NAME')
      READ(IREAD,108) NAME
      N1 = 0
      N2 = 0
      IC = 0
      DO 55 I = 1,12
      IF(LOG(I).EQ.ICOM) IC = IC + 1
      IF(IC .GE. 2) GO TO 54
      IF(LOG(I).NE.IBL) N2 = N2 + 1
   54 IF(NAME(I).NE.IBL) N1 = N1 + 1
  55  CONTINUE
      WRITE(ITP1,104)N2,(LOG(I),I=1,N2),N1,(NAME(I),I=1,N1)
  104 FORMAT('!JOB ',NA1,'(',NA1,')'/
     1'!LIMIT (CORE,32),(TIME,15)'/
     1'!ASSIGN M:PL,(DEVICE,PLA06)'/
     1'!RUN (LMN,LMPREF,FPOWDER)'/
     1'!DATA')
50    WRITE(ITYP,106)
  106 FORMAT(/' TYPE IN TITLE INFORMATION IDENTIFING THE RUN')
      READ(IREAD,102)ITITLE
      WRITE(ITP1,102)ITITLE
C *
      WRITE(ITYP,130)
130   FORMAT(/'CELL PARAMETERS - INPUT A,B,C,ALPHA,BETA,GAMMA')
      READ(IREAD,60) A,B,C,AL,BE,GA
60    FORMAT(8G)
      WRITE(ITP1,135) A,B,C,AL,BE,GA
135   FORMAT(6F10.4)
C *
      WRITE(ITYP,140)
140   FORMAT(/'CONTROL PARAMETERS.'/'ITEM1     1 = OBSERVED '
     1,'PATTERN ONLY WILL BE INPUT',/
     210X,'0 = CALCULATED AND OBSERVED PATTERN TO BE INPUT',/
     39X,'-1 = USER SELECTS OPTIONS. (SEE OPERATIONS MANUAL)')
      READ(IREAD,60) ITEM(1)
      ITEM(5)=0
      IF(ITEM(1).GE.0) GO TO 70
      WRITE(ITYP,150)
150   FORMAT(/'INPUT CONTROL PARAMETERS.')
      READ(ITYP,155) ITEM(J),J=1,9
      WRITE(ITP1,155) ITEM(J),J=1,9
155   FORMAT(9I1)
      GO TO 85
70    WRITE(ITP1,160) ITEM(1)
160   FORMAT(I1,'10200010')
C *
85    WRITE(ITYP,190)
190   FORMAT(/'OBSERVED PATTERN SETTINGS.'/
     1,'DO YOU WANT DEFAULT VALUES? <Y OR N>')
      READ(IREAD,108) ANS
      IF(ANS.EQ.YES) GO TO 90
      WRITE(ITYP,185)
185   FORMAT(/'INPUT MAXPKN,SINT,BCKGRD,FACTR,X2,X3,WAVE')
      READ(IREAD,60) MP,SI,BC,FA,X2,X3,WAVE
      IF(WAVE.EQ.0.) WAVE=1.5405
      WRITE(ITP1,195) MP,SI,BC,FA,X2,X3,WAVE
195   FORMAT(I5,6F10.4)
      GO TO 62
90    WRITE(ITP1,195) 200,1000.,1.,1.,180.,90.,1.5405
C *
62    WRITE(ITYP,210)
210   FORMAT(/'OBSERVED PATTERN'/'IS YOUR PATTERN ON A FILE?',
     +' <Y OR N>')
      IN20=20
72    READ(IREAD,108) ANS
      IF(ANS.EQ.YES) GO TO 66
      WRITE(ITYP,221)
221   FORMAT(/' INPUT YOUR TWO-THETAS AND INTENSITIES (2G).'/
     1' AFTER LAST ENTRY JUST HIT RETURN.')
      IN20=IREAD
66    READ(IN20,60,END=71)  THETA,INT
      IF(THETA.EQ.0.) GO TO 71
      WRITE(ITP1,215) THETA,INT
215   FORMAT(2F10.4)
      GO TO 66
C *
71    WRITE(ITP1,220)
220   FORMAT(' ')
      IF(ITEM(1).EQ.1) GO TO 93
      WRITE(ITYP,230)
230   FORMAT(/'CALCULATED PATTERN'/'IS YOUR PATTERN ON A FILE?',
     +' <Y OR N>')
      READ(IREAD,108) ANS
      IN30=30
      IF(ANS.EQ.YES) GO TO 81
      WRITE(ITYP,221)
76    READ(IREAD,215) THETA,INT
      IF(THETA.EQ.0.) GO TO 91
      DCALC=WAVE/(2.*SIN(THETA*0.017453295))
      WRITE(ITP1,205) THETA,DCALC,INT
205   FORMAT(F17.4,8X,F7.4,19X,I4)
      GO TO 76
C *  DATA IS FROM AN INPUT FILE
81    READ(IN30,108)  JUNK
      READ(IN30,108)  JUNK
82    READ(IN30,9875) (KARDC(I),I=1,80)
9875  FORMAT(80A1)
      IF( KARDC(15) .NE. 1H. )GO TO 91
      ENCODE(80,9873,KARD(1)) (KARDC(I),I=1,80)
9873  FORMAT(80A1)
      DECODE(80,235,KARD(1)) THETA,DC,IH,IK,IL,INT
      OUTPUT THETA
C82   READ(IN30,235,END=91)  THETA,DC,IH,IK,IL,INT
235   FORMAT(F17.2,7X,F7.3,T34,3I3,T51,I4)
      IF(THETA.EQ.0.) GO TO 91
      WRITE(ITP1,235) THETA,DC,IH,IK,IL,INT
      GO TO 82
C *
91    WRITE(ITP1,220)
93    IF(ITEM(5).EQ.0) GO TO 92
      WRITE(ITYP,245)
245   FORMAT(//' INPUT DATA FOR YOUR NEXT SAMPLE.',/)
      GO TO 50
92    WRITE(ITP1,300)
300   FORMAT('!EOD')
      WRITE(ITYP,120)
  120 FORMAT(///' AS SOON AS TERMINAL RETURNS A  !  TYPE'/
     1,' "BATCH FID" WHERE FID IS THE NAME YOU ASSIGNED TO'/
     2,' YOUR OUTPUT FILE. YOUR JOB WILL BE RUN SHORTLY.'/
     3,' PICK UP YOUR RESULTS AT THE COMPUTER CENTER.'/)
      CALL EXIT
      END
