C ----------------- EXAPLT SUBROUTINE - READAT ------------------------- C SUBROUTINE READAT (NAME,A,B,MXPNTS,MXCHAN,NPTS,NCHAN,RDFRM, 1 DSPACE,STPDEG,CMNT,IER) C C READAT reads raw EXAFS data from the specified file and creates input C data arrays. Experimental parameters are loaded if the format C includes then. The formats presently supported are: C C RDFRM Format C ----- -------------------------------------------------------- C 1 Old Stanford Format - position in steps, one channel, no C parameters C 2 New Stanford Format - position in steps, multiple C channels, DSPACE & STPDEG C 3 Sum format - created by sum program from raw RDFRM 1 & 2 C files, position in steps, multiple channels, DSPACE C and STPDEG C 4 EXAPLT STEP format - position in steps, multiple C channels, DSPACE & STPDEG C 8 Stohr Format - position in eV, multiple channels, C parameters not applicable C 9 EXAPLT ENERGY format - position in eV, multiple C channels, parameters not applicable C (RDFRM 9 IS THE DATA FORMAT YOU WANT !!!!) C C RDFRM values above 7 indicate that the data are supplied directly in C energy (ev) abscissa units. NAME is replaced by the full INQUIRE C name after open. Error and warning messages may be generated on C channel 6. CRWAIT is used to pause after the message. C C ARGUMENTS: C C NAME: Character*(*) name of the input file [I/O] C A: Real array (MXPNTS) of monochromator positions [OUT] C B: Real array (MXPNTS,MXCHAN) of measurement channel values C which correspond in the first index to the mono- C chromator positions. The second index is the channel C number [OUT] C MXPNTS: Integer maximum number of positions [IN] C MXCHAN: Integer maximum number of channels [IN] C NPTS: Integer actual number of positions [OUT] C NCHAN: Integer actual number OF channels [OUT] C RDFRM: Integer specifying the format of the input file [OUT] C DSPACE: Real crystal lattice spacing (Angstroms) [OUT] C STPDEG: Real monochromator steps/degree [OUT] C CMNT: Character*72, comment field C IER: Integer error code, 0->success [OUT] C C ---------------------------------------------------------------------- IMPLICIT NONE C C Argument declarations C CHARACTER*(*) NAME INTEGER MXPNTS,MXCHAN REAL A(MXPNTS),B(MXPNTS,MXCHAN) INTEGER NPTS,NCHAN,RDFRM,IER REAL DSPACE,STPDEG CHARACTER*72 CMNT C C Function declaration C CHARACTER*72 COMFIX ! Compress comment ot 72 characters C C Internal variables C INTEGER RER ! Internal read error code INTEGER ILIM ! Point limit INTEGER ISKP ! Skip line count INTEGER I,J,K ! Utility indexes INTEGER NRUN ! Stohr run number LOGICAL ENDAT ! End-of-data flag LOGICAL TRUNC ! Truncation flag CHARACTER*80 LINE ! Line buffer REAL THETA_OFF,X,XX,XXX,XXXX,XXXXX !added J.M. 7-11-89 REAL Z,EFAC,STEP_PER_RAD C C ---------------------------------------------------------------------- C C Open the input file and get 1st line C OPEN (1,FILE=NAME,STATUS='OLD',BLANK='ZERO',READONLY, 1 IOSTAT=IER) IF (IER.NE.0) THEN WRITE (6,1901) 'ERROR OPENING FILE',IER CALL CRWAIT RETURN END IF INQUIRE (1,NAME=NAME) READ (1,1001,IOSTAT=IER) LINE IF (IER.NE.0) THEN WRITE (6,1901) 'ERROR READING FIRST LINE',IER GO TO 99 END IF C 1001 FORMAT (A) C C Initialize the output arrays C DO I=1,MXPNTS A(I)=0. DO J=1,MXCHAN B(I,J)=0. END DO END DO C C Strip possible initial bad character (experience!) C IF (LINE(1:1).LT.' ') LINE = LINE (2:LEN(LINE)) C C ----------------------------------------------- C ! Process old Stanford format file, RDFRM = 1 ! C ----------------------------------------------- C C Distinguished by "CUEDGE" in cols 2-7 of the first line C IF (LINE(2:7).EQ.'CUEDGE') THEN RDFRM = 1 NCHAN = 1 ! Always 1 channel READ (1,1011,IOSTAT=IER) LINE ! Get comment IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 1, ERROR READING COMMENT LINE',IER GO TO 99 END IF CMNT = COMFIX(LINE) ! Compress comment C C Explicit number of points not provided. End-of-data signal is a C a monochromator step value of zero or less. C RER = 0 I = 0 ENDAT = .FALSE. DO WHILE ((.NOT.ENDAT).AND.I.LT.MXPNTS.AND.RER.EQ.0) J = MIN(I+4,MXPNTS) READ (1,1012,IOSTAT=RER) (A(K),B(K,1),K=I+1,J) IF (RER.EQ.0) THEN DO WHILE ((.NOT.ENDAT).AND.I.LT.J) IF (A(I+1).GT.0.0) THEN I = I+1 ELSE ENDAT = .TRUE. END IF END DO END IF END DO C 1011 FORMAT(///A) 1012 FORMAT(8F10.0) C C Check something was found (RER = -1 -> End-of-file) C IF (I.EQ.0) THEN IF (RER.EQ.-1.OR.RER.EQ.0) THEN WRITE (6,1900) 'RDFRM 1, NO DATA POINTS IN FILE' ELSE WRITE (6,1901) 1 'RDFRM 1, NO DATA POINTS WITH ERROR = ',RER END IF IER = 1 ! No data points is failure GO TO 99 END IF NPTS = I C C Check termination condition. Unusual termination produces C message but is not a failure. C IF (RER.EQ.-1) THEN WRITE (6,1900) 'RDFRM 1, READ ENDED ON END-OF-FILE' GO TO 99 ELSE IF (RER.NE.0) THEN WRITE (6,1901) 'RDFRM 1, READ ENDED WITH ERROR',IER GO TO 99 ELSE IF (.NOT.ENDAT) THEN WRITE (6,1900) 'RDFRM 1, DATA TRUNCATED TO POINT LIMIT' GO TO 99 END IF C C ----------------------------------------------- C ! Process new Stanford format file, RDFRM = 2 ! C ----------------------------------------------- C C Distinguished by "NPTS" in cols 2-5 of the first line C ELSE IF (LINE(2:5).EQ.'NPTS') THEN RDFRM = 2 READ (1,1021,IOSTAT=IER) NPTS,DSPACE,STPDEG IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 2, ERROR READING NPTS LINE',IER GO TO 99 END IF READ (1,1022,IOSTAT=IER) LINE IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 2, ERROR READING COMMENT LINE',IER GO TO 99 END IF CMNT = COMFIX(LINE) C C Limit number of points C IF (NPTS.GT.MXPNTS) THEN NPTS = MXPNTS TRUNC = .TRUE. ELSE TRUNC = .FALSE. END IF C C Explicit number of points provided in header, but premature C termination is possible and legal. C RER = 0 I = 0 DO WHILE (I.LT.NPTS.AND.RER.EQ.0) I = I+1 READ (1,1023,IOSTAT=RER) (A(I),(B(I,J),J=1,MXCHAN)) END DO IF (RER.NE.0) I = I-1 C 1021 FORMAT(1X,I4,20X,2F8.0) 1022 FORMAT (////A) 1023 FORMAT (0PF10.0,1P8E12.5) ! MAY NEED ADJUSTMENT WITH MXCHAN 1024 FORMAT (0PF11.3,1P8E12.5) ! MAY NEED ADJUSTMENT WITH MXCHAN C C Check something was found (RER = -1 -> End-of file) C IF (I.EQ.0) THEN IF (RER.EQ.-1.OR.RER.EQ.0) THEN WRITE (6,1901) 'RDFRM 2, NO DATA POINTS IN FILE' ELSE WRITE (6,1901) 1 'RDFRM 2, NO DATA POINTS WITH ERROR',RER END IF IER = 1 ! No data points is failure GO TO 99 END IF NPTS = I C C Determine number of channels C I = 1 NCHAN = 1 DO WHILE (I.LE.NPTS.AND.NCHAN.LT.MXCHAN) K = NCHAN+1 DO J = K,MXCHAN IF (B(I,J).NE.0) NCHAN=I END DO I = I+1 END DO C C Check termination condition. Unusual termination produces C message but is not a failure. C IF (RER.EQ.-1) THEN WRITE (6,1900) 'RDFRM 2, SHORT FILE FOUND' GO TO 99 ELSE IF (RER.NE.0) THEN WRITE (6,1901) 'RDFRM 2, READ ENDED WITH ERROR = ',RER GO TO 99 ELSE IF (TRUNC) THEN WRITE (6,1900) 'RDFRM 2, DATA TRUNCATED TO POINT LIMIT' GO TO 99 END IF C C ------------------------------- C ! Process sum file, RDFRM = 3 ! C ------------------------------- C C Distinguished by "SUMNAM" in cols 1-6 of first line. C ELSE IF (LINE(1:6).EQ.'SUMNAM') THEN RDFRM = 3 READ (LINE,1031,IOSTAT=IER) ISKP IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 3, ERROR DECODING FIRST LINE',IER GO TO 99 END IF DO I=1,ISKP+1 READ (1,1032,IOSTAT=IER) IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 9, ERROR IN NAMES SKIP',IER GO TO 99 END IF END DO READ (1,1033,IOSTAT=IER) NPTS,NCHAN,DSPACE,STPDEG IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 3, ERROR READING PARAMETERS',IER GO TO 99 END IF NPTS = MIN(NPTS,MXPNTS) READ (1,1034,IOSTAT=IER) LINE IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 3, ERROR READING COMMENT',IER GO TO 99 END IF CMNT = COMFIX(LINE) C C Number of data points and channels provided in header - any C deviation is fatal. C DO I=1,NPTS READ (1,1035,IOSTAT=IER) A(I),(B(I,J),J=1,NCHAN) IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 3, ERROR READING DATA',IER GO TO 99 END IF END DO C 1031 FORMAT (49X,I5) 1032 FORMAT (1X) 1033 FORMAT (I5,2X,I5,8X,F10.6,1X,F10.1) 1034 FORMAT (A) 1035 FORMAT (0PF10.0,1P5E12.5) C C --------------------------------------- C ! Process EXAPLT STEP file, RDFRM = 4 ! C --------------------------------------- C C Distinguished by "STEP" in cols 1-4 of first line. C ELSE IF (LINE(1:4).EQ.'STEP') THEN RDFRM = 4 C C Get parameters line C READ (1,*,IOSTAT=IER) ILIM,NCHAN,DSPACE,STPDEG IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 4, ERROR READING PARAMETERS',IER GO TO 99 END IF IF (NCHAN.LE.0.OR.NCHAN.GT.MXCHAN) THEN WRITE (6,1900) 'RDFRM 4, ILLEGAL NUMBER OF CHANNELS' GO TO 99 END IF C C Get comment C READ (1,1041,IOSTAT=IER) LINE IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 4, ERROR READING COMMENT',IER GO TO 99 END IF CMNT = COMFIX(LINE) C C Number of channels and number of points provided explicitly in C header, but premature termination is possible and legal. C IF (ILIM.LE.0.OR.ILIM.GT.MXPNTS) THEN K = MXPNTS ELSE K = ILIM END IF C RER = 0 NPTS = 0 DO WHILE (I.LT.K.AND.RER.EQ.0) I = I+1 READ (1,*,IOSTAT=RER) A(I),(B(I,J),J=1,NCHAN) END DO IF (RER.NE.0) I = I-1 C C Check something was found C IF (I.EQ.0) THEN IF (RER.EQ.-1) THEN WRITE (6,1900) 'RDFRM 4, NO DATA POINTS IN FILE' ELSE WRITE (6,1901) 1 'RDFRM 4, NO DATA POINTS WITH ERROR = ',RER END IF IER = 1 ! No points is fatal GO TO 99 END IF C C Check termination condition. Unusual termination produces C message but is not a failure. C NPTS = I IF (RER.EQ.-1) THEN IF (ILIM.GT.0) THEN WRITE (6,1900) 'RDFRM 4, SHORT FILE FOUND' END IF GO TO 99 ELSE IF (RER.NE.0) THEN WRITE (6,1901) 'RDFRM 4, READ ENDED WITH ERROR = ',RER GO TO 99 ELSE IF (ILIM.GT.MXPNTS) THEN WRITE (6,1900) 'RDFRM 4, DATA TRUNCATED TO POINT LIMIT' GO TO 99 END IF C 1041 FORMAT (A) C C ----------------------------------------------- C ! Process new EXXON EXAFS format file, RDFRM = 10 ! C ----------------------------------------------- C C Distinguished by "EXAFS" in cols 1-5 of the first line C ELSE IF (LINE(1:5).EQ.'EXAFS') THEN C--- READ (1,1061,IOSTAT=IER) LINE 1061 FORMAT(A80) C--- C--- Read for Comment LINE C--- READ (1,1061,IOSTAT=IER) LINE IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 10, ERROR READING COMMENT LINE',IER GO TO 99 END IF CMNT = COMFIX(LINE) DO WHILE (LINE(2:5) .NE. 'NPTS') READ (1,1061,IOSTAT=IER) LINE ENDDO C--- C--- Read Number of Points and Channel C--- READ (1,1042,IOSTAT=IER) NPTS,NCHAN 1042 FORMAT(7x,I4,8X,I2) IF (NPTS .LE. 0. .OR. NCHAN .LE. 0 .OR. IER.NE.0) THEN WRITE (6,1901) 'RDFRM 10, ERROR READING NPTS LINE',IER GO TO 99 END IF C--- C--- Read Monocrometer information C--- DO WHILE (LINE(2:6) .NE. 'THETA') READ (1,1061,IOSTAT=IER) LINE ENDDO READ(1,*) THETA_OFF,X,XX,DSPACE,XXX,XXXX,XXXXX c-- c-- Kludgey fix.. for pre 10-25-89 .xfs files c-- if(dspace .eq. 1.92)then dspace = 1.92017 type *,' dspace in header updated internal to exaplt' type *,' 1.920 ------> 1.92017 ' elseif(dspace .eq. 3.136)then dspace = 3.135625 type *,' dspace in header updated internal to exaplt' type *,' 3.136 ------> 3.135625 ' endif 1043 FORMAT(1x,7(F11.3)) C--- C--- kluedge RDFRM to equal 4 so program "thinks" steps are being processed C--- if(dspace .le. 0.)then RDFRM = 10 !takes energies at face value ELSE RDFRM = 4 !recompute from steps Endif C--- C--- get steps per degree C--- If key doesn't exist data file assumed to be create prior to 7-11-89 C--- and the values will be defaulted C--- if(rdfrm .eq. 4)then READ (1,1061,IOSTAT=IER) LINE IF(LINE(2:5) .EQ. 'STEP')THEN READ(1,1044)STPDEG 1044 FORMAT(1X,F11.3) ELSE STPDEG = 64000. !DEFAULT ENDIF endif C--- C--- Look for Start of DATA C--- DO WHILE (LINE(2:11) .NE. 'DATA START') READ (1,1061,IOSTAT=IER) LINE ENDDO C C Limit number of points C IF (NPTS.GT.MXPNTS) THEN NPTS = MXPNTS TRUNC = .TRUE. ELSE TRUNC = .FALSE. END IF C C Explicit number of points provided in header, but premature C termination is possible and legal. C RER = 0 I = 0 C C Compute Efactor C IF(rdfrm .eq. 4 .and. DSPACE .GT. 0.)THEN EFAC = 6.19926/DSPACE ! as expressed in ENLIN routine STEP_PER_RAD = STPDEG/.017453292 ENDIF c c c DO WHILE (I.LT.NPTS.AND.RER.EQ.0) I = I+1 READ (1,1024,IOSTAT=RER) A(I),(B(I,J),J=1,NCHAN) C C Convert energy back to steps based on header info.....and ENLIN equations C if(rdfrm .eq. 4)then if(a(i) .ne. 0)then A(I) = A(I)/1000. !Convert ev to Kev Z = EFAC/A(I) !compute z factor A(I) = ASIN(Z) + THETA_OFF/1000. !comput theta (rads) A(I) = A(I)*STEP_PER_RAD !compute Original E500 steps endif endif END DO IF (RER.NE.0) I = I-1 C C C Check something was found (RER = -1 -> End-of file) C IF (I.EQ.0) THEN IF (RER.EQ.-1.OR.RER.EQ.0) THEN WRITE (6,1901) 'RDFRM 4/10, NO DATA POINTS IN FILE' ELSE WRITE (6,1901) 1 'RDFRM 4/10, NO DATA POINTS WITH ERROR',RER END IF IER = 1 ! No data points is failure GO TO 99 END IF NPTS = I C C Determine number of channels C I = 1 NCHAN = 1 DO WHILE (I.LE.NPTS.AND.NCHAN.LT.MXCHAN) K = NCHAN+1 DO J = K,MXCHAN IF (B(I,J).NE.0) NCHAN=I END DO I = I+1 END DO C C Check termination condition. Unusual termination produces C message but is not a failure. C IF (RER.EQ.-1) THEN WRITE (6,1900) 'RDFRM 4/10, SHORT FILE FOUND' GO TO 99 ELSE IF (RER.NE.0) THEN WRITE (6,1901) 'RDFRM 4/10, READ ENDED WITH ERROR = ',RER GO TO 99 ELSE IF (TRUNC) THEN WRITE (6,1900) 'RDFRM 4/10, DATA TRUNCATED TO POINT LIMIT' GO TO 99 END IF CJMHJMJM C C C ----------------------------------------- C ! Process EXAPLT ENERGY file, RDFRM = 9 ! C ----------------------------------------- C C Distinguished by "ENERGY" in cols 1-6 of first line. C ELSE IF (LINE(1:6).EQ.'ENERGY') THEN RDFRM = 9 C C Get parameters line C READ (1,*,IOSTAT=IER) ILIM,NCHAN IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 9, ERROR READING PARAMETERS',IER GO TO 99 END IF IF (NCHAN.LE.0.OR.NCHAN.GT.MXCHAN) THEN WRITE (6,1900) 'RDFRM 9, ILLEGAL NUMBER OF CHANNELS' GO TO 99 END IF C C Get comment C READ (1,1091,IOSTAT=IER) LINE IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 9, ERROR READING COMMENT',IER GO TO 99 END IF CMNT = COMFIX(LINE) C C Number of channels and number of points provided explicitly in C header, but premature termination is possible and legal. C IF (ILIM.LE.0.OR.ILIM.GT.MXPNTS) THEN K = MXPNTS ELSE K = ILIM END IF C I = 0 RER = 0 NPTS = 0 DO WHILE (I.LT.K.AND.RER.EQ.0) I = I+1 READ (1,*,IOSTAT=RER) A(I),(B(I,J),J=1,NCHAN) END DO IF (RER.NE.0) I = I-1 C C Check something was found C IF (I.EQ.0) THEN IF (RER.EQ.-1) THEN WRITE (6,1900) 'RDFRM 9, NO DATA POINTS IN FILE' ELSE WRITE (6,1901) 1 'RDFRM 9, NO DATA POINTS WITH ERROR = ',RER END IF IER = 1 ! No points is fatal GO TO 99 END IF NPTS = I C C Clear monochromator parameters. Not used by this format. C DSPACE = 0.0 STPDEG = 0.0 C C Check termination condition. Unusual termination produces C message but is not a failure. C IF (RER.EQ.-1) THEN IF (ILIM.GT.0) THEN WRITE (6,1900) 'RDFRM 9, SHORT FILE FOUND' END IF GO TO 99 ELSE IF (RER.NE.0) THEN WRITE (6,1901) 'RDFRM 9, READ ENDED WITH ERROR = ',RER GO TO 99 ELSE IF (ILIM.GT.MXPNTS) THEN WRITE (6,1900) 'RDFRM 9, DATA TRUNCATED TO POINT LIMIT' GO TO 99 END IF C 1091 FORMAT (A) C C --------------------------------- C ! Process Stohr file, RDFRM = 8 ! C --------------------------------- C C Distinguished soley by the fact that is is not one of the above. C ELSE RDFRM = 8 READ (LINE,1081,IOSTAT=IER) NRUN,ISKP,NCHAN IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 8, ERROR DECODING FIRST LINE',IER GO TO 99 END IF IF (NCHAN.LE.0.OR.NCHAN.GT.MXCHAN) THEN WRITE (6,1900) 'RDFRM 8, ILLEGAL NUMBER OF CHANNELS' GO TO 99 END IF IF (ISKP.LE.0) THEN WRITE (6,1900) 'RDFRM 8, ILLEGAL SEGMENT COUNT' GO TO 99 END IF WRITE (CMNT,1089) NRUN DO I=1,ISKP READ (1,1082,IOSTAT=IER) IF (IER.NE.0) THEN WRITE (6,1901) 'RDFRM 8, ERROR IN SEGMENT SKIP',IER GO TO 99 END IF END DO C C Read the data, termination by end-of-file or MXPNTS limit C RER = 0 I = 0 DO WHILE (I.LT.MXPNTS.AND.RER.EQ.0) I = I+1 READ (1,1083,IOSTAT=RER) A(I),(B(I,J),J=1,NCHAN) END DO IF (RER.NE.0) I = I-1 C 1081 FORMAT (1X,4(I6,4X)) 1082 FORMAT (1X) 1083 FORMAT (1X,F9.2,5X,6(1X,F16.6,3X)) 1089 FORMAT ('RUN ',I6) C C Check something was found C IF (I.EQ.0) THEN IF (RER.EQ.-1) THEN WRITE (6,1900) 'RDFRM 8, NO DATA POINTS IN FILE' ELSE WRITE (6,1901) 1 'RDFRM 8, NO DATA POINTS WITH ERROR = ',RER END IF IER = 1 ! No points is fatal GO TO 99 END IF NPTS = I C C Clear monochromator parameters. Not used by this format. C DSPACE = 0.0 STPDEG = 0.0 C C Check termination condition. Unusual termination produces C message but is not a failure. C IF (RER.NE.0.AND.RER.NE.-1) THEN WRITE (6,1901) 'RDFRM 8, READ ENDED WITH ERROR = ',RER GO TO 99 END IF C END IF C C --------------- C ! Normal exit ! C --------------- C CLOSE (1) RETURN C C --------------------- C ! Exit with message ! C --------------------- C 99 CLOSE (1) IF (IER.NE.0) WRITE (6,1900) 'READ FAILURE!' CALL CRWAIT RETURN C 1900 FORMAT (/1X,A) 1901 FORMAT (/1X,A,', CODE=',I8) C END