C PROTEL - One minute average sorted by local pitch angle c This version of protel_min1.for has been modified to run on a c Windows PC. This will also run on a non-SGI UNIX platform if the c OPEN statement is changed as indicated below. C Input file = 'd08xxxx.min' ; Output file = 'd08xxxx.lis'' C c Modified for non-SGI UNIX by John F. Cooper, 5/02/2001 c Modified for Windows PC by John F. Cooper, 8/9/2002 c PROGRAM READ_MIN REAL*4 EPHEMA(8),EPHEMB(8),FLUX(24,19),ENERGY(24) INTEGER*2 NOBF(24,19) INTEGER*4 IORBIT,IYEAR,IDAY,IBSEC,IESEC,IBR,IER,IPA CHARACTER*11 INFILE,OUTFILE DATA inFILE/'d08xxxx.min'/ PRINT*,'ENTER ORBIT NUMBER:' READ(*,*)JORBIT PRINT*,'ENTER CHANNEL NUMBER:(1-24)' READ(*,*)ICH WRITE(INFILE(4:7),'(I4.4)')JORBIT OUTFILE=INFILE(1:8)//'lis' c Input data records are SGI binary - this routine reads these on other platforms c Use the following open statement for Windows PC (RECL in bytes) OPEN(1,FILE=INFILE,ACCESS='DIRECT',RECL=2800,ERR=100) ! Windows PC c Use the following open statement for non-SGI UNIX (RECL in 4-byte words) c OPEN(1,FILE=INFILE,ACCESS='DIRECT',RECL=700,ERR=100) ! Non-SGI UNIX WRITE(6,*) ' OPENED INPUT FILE' OPEN(2,FILE=OUTFILE,STATUS='UNKNOWN') WRITE(6,*) ' OPENED OUTPUT FILE' C READ HEADER RECORD READ(1,REC=1)IORBIT,IYEAR,IDAY,IBSEC,IESEC,IBR,IER,ENERGY C REVERSE BINARY BYTE ORDER FOR NON-SGI UNIX and Windows PC PLATFORMS C Comment out the following statements for SGI UNIX platforms CALL BYTIN4(IORBIT) CALL BYTIN4(IYEAR) CALL BYTIN4(IDAY) CALL BYTIN4(IBSEC) CALL BYTIN4(IESEC) CALL BYTIN4(IBR) CALL BYTIN4(IER) DO I=1,24 CALL BYTFL4(ENERGY(I)) ENDDO C Write header record data WRITE(2,21) IYEAR,IDAY,ENERGY(ICH) 21 FORMAT(' YEAR=',I4,' DAY=',I4,' ENERGY=',F5.2,' MEV') WRITE(2,22)IORBIT,IBSEC,IESEC,IER 22 FORMAT(' ORBIT=',I4,' BSEC=',I6,' ESEC=',I6,' NO. RECORDS=', + I4) WRITE(2,*) ' IBR,IER = ',IBR,IER C IBR always is 2, since the first record is the header. c Read the flux data records DO 10 NREC=IBR,IER WRITE(2,*) READ(1,REC=NREC,ERR=100)EPHEMB,EPHEMA,FLUX,NOBF C Comment out the following statements for SGI UNIX platforms DO II=1,8 CALL BYTFL4(EPHEMB(II)) CALL BYTFL4(EPHEMA(II)) ENDDO DO IICH=1,24 DO IPA=1,19 CALL BYTFL4(FLUX(IICH,IPA)) CALL BYTIN2(NOBF(IICH,IPA)) ENDDO ENDDO C Write ephemeris data for this flux record WRITE(2,23)EPHEMB ! Ephemeris data for start of interval 23 FORMAT(' BEG EPHEM. ',4F9.1,4F8.3) write(2,24)EPHEMA ! Ephemeris data for average time of interval 24 FORMAT(' AVE EPHEM. ',4F9.1,4F8.3) C Write out pitch angle (deg), flux, and number of samples WRITE(2,25) 25 FORMAT(/,' Pitch Angle Flux Obs') DO 20 IPA=1,19 WRITE(2,26)IPA*5-5,FLUX(ICH,IPA),NOBF(ICH,IPA) 20 CONTINUE 26 FORMAT(I8,4X,E10.4,I8) 10 CONTINUE 100 CONTINUE STOP END C SUBROUTINE BYTIN4(A) C Reverse byte order for INTEGER*4 INTEGER*4 A,IX,IY BYTE FBYTEI(4),RBYTEI(4) EQUIVALENCE (IX,FBYTEI(1)),(IY,RBYTEI(1)) IX = A DO I = 1,4 J = 5 - I RBYTEI(J) = FBYTEI(I) ENDDO A = IY RETURN END c SUBROUTINE BYTIN2(A) C Reverse byte order for INTEGER*2 INTEGER*2 A,IX,IY BYTE FBYTEI(2),RBYTEI(2) EQUIVALENCE (IX,FBYTEI(1)),(IY,RBYTEI(1)) IX = A DO I = 1,2 J = 3 - I RBYTEI(J) = FBYTEI(I) ENDDO A = IY RETURN END c SUBROUTINE BYTFL4(A) C Reverse byte order for REAL*4 REAL*4 A,X,Y BYTE FBYTEF(4),RBYTEF(4) EQUIVALENCE (X,FBYTEF(1)),(Y,RBYTEF(1)) X = A DO I = 1,4 J = 5 - I RBYTEF(J) = FBYTEF(I) ENDDO A = Y RETURN END