c Thu Nov 18 15:33:52 EST 1993 /plas1/h1/mzh/src/test vgrtrd c Thue Dec 8, 1994 Space Craft Clock added gsg jr. c Modified and commented by A. Szabo c Wed Nov 17 16:56:51 EST 1993 /plas5/h1/vgr/src/vgr vgrtrd c Wed May 2 13:52:37 EDT 1990 /leverrier/h1/ksg/src/test vgrtrd.f c Tue Mar 20 09:53:35 EST 1990 /plas0/h1/vgr/src/vgr vgrtrd c subroutine vgrtrd(ANS,JTB,JDATA,JNE,LSTAT,JTLMOD,JCLK,IEOD) c c Routine to read Voyager mission tapes c The following parameters are returned: c real: ANS(150): Answer array filled for L and M modes only. Only the c first 12 elements are filled. The elements are: c ANS(1) = Proton density in #/cc [ANS(38)] c ANS(2) = VR Proton velocity component in km/s [ANS(99)] c ANS(3) = VT Proton velocity component in km/s [ANS(100)] c ANS(4) = VN Proton velocity component in km/s [ANS(101)] c ANS(5) = Thermal width, moment in km/s [(ANS(34)+ANS(35)+ANS(36))/3] c The average of the A,B and C cup moments. c ANS(6) = Thermal width, fit in km/s Wf=(Wa + Wb + Wc) / 3 where c Wa = sqrt((WPER^2*(1-B.Na^2))+(WPAR^2*(B.Na^2))) c Likewise for Wb and Wc. c WPER = ANS(69); WPAR = ANS(68); B.N{a,b,c} are the directional c cosines between B and the cup normals [ANS(130,131,132)] c ANS(7) = Alpha density in #/cc, moment [ANS(117)] c ANS(8) = Alpha density in #/cc, fit [ANS(59)] c ANS(9) = BR magnetic field component in gammas [ANS(96)] c ANS(10)= BT magnetic field component in gammas [ANS(97)] c ANS(11)= BN magnetic field component in gammas [ANS(98)] c ANS(12)= Radial distance from Sun in AU c int*2: JTB(6): Time of the spectra set read with elements: c JTB(1) = Year in two digit form (Year = year - 1900) c JTB(2) = Day (if day > 255 then day = day - 256 and hour = hour + 100) c JTB(3) = Hour (if day > 255 then hour = hour + 100) c JTB(4) = Minutes c JTB(5) = Seconds c JTB(6) = mSeconds / 4 c int*2: JDATA(512): Digital currents in channels. 64 elements are filled for c L mode, 512 for M, and 16 for E1 and E2. Missing channel c currents are filled with -1's. c int*2: JNE: The total number of channels appropriate for the mode: 64 for L c 512 for M, 16 for E1 and E2. c int*4: LSTAT: Status word. Only one byte of the status word is stored on a c mission tape. It is copied twice at the bottom 2 bytes of c LSTAT. The upper half word is set to be 0. c int*2: JTLMOD: Mode type: 1 - L; 2 - M; 3 - E1; 4 - E2 c int*2: JCLK: Cup integration time index: 1 - 30 ms; 2 - 210 ms; 3 - 930 ms c int*4: IEOD: Error flag: 0 - ok; -1 - read 0 bytes, end of file; c -2 - read error from twait in bat.c c c COMMON /CMODE/ IYR,IDOY,IHR,IMIN,SEC,ICLK 1 ,ISTATA,ICOMM,IDATAN(4,144),ITLMOD 2 ,TTMP(3),IENGDN(9),MODTAL,IKINDS,MINDEX,MODTLM c c The following elements of this common block are filled in this routine: c int*4: MODTLM: Telemetry mode index: c 0 - GS-3 c 1 - CR-1 c 2 - CR-2 c 3 - CR-3 c 4 - CR-4 c 5 - CR5A c 6 - CR6A c 7 - CR6B c 8 - CR5B c 9 - CR7S c 10 - CR7L c 11 - GS5S c 12 - GS5L c 13,14,15 - **** c char*4: IKINDS: Telemetry mode. The string corresponding to MODTLM. c int*4: MINDEX: First channel used (for M mode only) c integer iyr,idoy,ihr,imin,iclk,istata,icomm,idatan,itlmod integer iengdn,modtal,mindex,modtlm character*4 ikinds real ttmp, sec, ans(150) INTEGER*2 JTB(6),JDATA(512),JNE,JTLMOD,JCLK integer ieod,lstat, dumlst c c dumlst and cdl is used for the status word reading c character*1 cdl(2) equivalence (dumlst,cdl(1)) c c ncur will be the # of words of digital current (# of digital current data / 4) c n4 will be just 4*ncur c integer i,j,k,ncur,n4 c c buf will be used to read the data into c real buf(146) c c All the equivalencing is done in order to be able to read the one byte data c on the mission tape and put it into the appropriate variable type. c integer*4 i4,ibuf(146) integer*2 ihbuf(292), i2(2) character*1 i1(4), cbuf( 584) equivalence (ihbuf(1),buf(1)),(i4,i2(1)),(i1(1),i2(1)) equivalence (ibuf(1),buf(1)), ( cbuf(1), ibuf(1)) integer*2 i216(532) character*1 i1216(2,532) equivalence (i216(1),i1216(1,1)) c c jnea stores the total # of chennels for each possible mode c integer*4 jnea(4) c c ikinda stores the telemetry mode strings c character*4 ikinda(16) c c unit stores the environment variable name of the unit c character*4 unit c c llast is logical variable for end of tape check c logical*4 llast data unit /"ft32"/ data jnea /64, 512, 16, 16/ data ikinda /"GS-3", "CR-1", "CR-2", "CR-3", "CR-4", "CR5A", 1 "CR6A", "CR6B", "CR5B", "CR7S", "CR7L", "GS5S", "GS5L", 2 3*"****"/ c=========================================================================== c BEGIN EXECUTION c 25 continue c write(6,1111) 1111 format(" in vgrtrd") ieod = 0 c c len is the maximum allowed length in bytes to be read c it is set for the length of M modes c len = 4*144 call newreadbat( len, buf, ieof) if(ieof .ne. 0) go to 2000 c write(6,1112) 1112 format(" again in vgrtrd") c c treadbat: Routine to read from unit the next record c (a maximum of len bytes) into the array buf. Unit c has to be a character variable containing the name c of the unit (like "ft32"). Since treadbat is a c c routine residing in bat.c, fortran will also pass c the length of the string unit at the end of the c argument list received in the variable il. c buf has to be big enough the store the maximum number c of bytes possible. Buf is a 4 byte real array, but not c all of its stored values are reals. Therefore the c contents still need decoding. See mission tape c documentation. c c call wait( unit, len, ieod) c c wait: Routine (at the end of this module) to return the c # of bytes read on unit into len and the error flag c into ieod. c char*4: unit: The name of the unit. The same format c as for treadbat. c int*4: len: The # bytes read the last time from c unit at the last treadbat command. c int*4: ieod: Error flag. 0 = ok c -1 = end of file c -2 = end of tape c -4 = permanent error c c If at the end of file (NOTE: ieod=-1 is not always correctly set) c c write(6,1113) len 1113 format(" len", i5) if ( len .le. 0) go to 2000 c c If end of tape or permanent error then c if (ieod .ne. 0) go to 1000 c c Place the 1 byte data (i1) into 2 byte integer c array (i216). Only the first 12 bytes are c decoded here. k is the byte number. c k = 1 do 100 i=1,3 i4 = ibuf(i) do 50 j=1,4 i216(k) = 0 i1216(2,k) = i1(j) k = k+1 50 continue 100 continue c c Put the first 6 array elements into the time array. c do 210 i=1,6 jtb(i) = i216(i) 210 continue c write(6,1300) jword,jtlmod,jtb 1300 format(8I5) c The 7th element is the first M mode channel used c mindex = i216(7) c c The 8th element is the telemetry mode index c modtlm = i216(8) c c Put the corresponding telemetry mode string into ikinds c ikinds = ikinda(modtlm+1) c c Make up the status word from the status byte. c Since only one byte of the status word is stored c on a mission tape the rest has to be filled in here. c The first byte is the status as passed from JPL. c The second is as figured by PLS. If everything is ok c than they are the same. Here we force them to be the c same (cdl(1,2)). The other two bytes are set to be zero. c The whole word will be zero if the status info c is missing. c dumlst = 0 cdl(1) = i1216(2,9) cdl(2) = i1216(2,9) lstat = dumlst c c The 10th element is the # of words of digital current c (= 4 * # of individula bytes of digital data) c ncur = i216(10) c c The 11th element is the mode type index c jtlmod = i216(11) c c Record the total number of channel appropriate for the c mode indexed in jtlmod. c jne = jnea(jtlmod) c c The 12th element is the integration time index c jclk = i216(12) c c Load in the digital 1 byte currents and store them c as 2 byte integers in i216 starting at element 13. c do 500 i=1,ncur i4 = ibuf(i+3) do 450 j=1,4 i216(k) = 0 i1216(2,k) = i1(j) k = k+1 450 continue 500 continue c c Place all the digital current read into the array c jdata. n4 is the total number of currents read. c n4 = ncur * 4 do 600 i=1,n4 jdata(i) = i216(i+12) 600 continue c Fill the channles for which no currents were read c with the fill value of -1. c n4 = n4+1 do 620 i=n4,jne jdata(i) = -1 620 continue c c Fill the answer array only for the L and M modes c i = 0 if (jtlmod .gt. 2) go to 900 c c The answer array elements are 4 byte reals, therefore c no conversion is necessary. c do 800 i=1,12 ans(i) = buf(i+ncur+3) 800 continue c c get spacecraft clock if there c 900 continue if ( len .eq. (i + ncur +3)*4 ) then mod16 = 0 mod60 = 0 linecnt = 0 else mod16 = ihbuf( len/2 -2) i4 = 0 i1(4) = cbuf( len - 2) mod60 = i4 i4 = 0 i1(3) = cbuf( len - 1) linecnt = i4 end if return c c END OF ROUTINE c=========================================================== c c If other than end of file error is detected c continue here by setting ieod to -2. c 1000 ieod = -2 return c c If end of file detected continue here c 2000 continue c If ther are no more files to read from set ieod to -1. c ieod = -1 return end c subroutine wait(unit,l,ieod) c c Routine to determine the # of bytes last read on c unit and decode the error flags. c char*4: unit: Name of the unit from which data was c read (like "ft32") c int*4: l: The # of bytes last read from unit c int*4: ieod: Error index. 0 = ok c -1 = end of file c -2 = end of tape c -4 = permanent error c character*4 unit logical*4 rb(13),res(12) equivalence(icount,rb(1)),(rb(2),res(1)) c c Zero all the error flags c do 10 i=1,12 res(i) = .FALSE. 10 continue ierr=0 c call twait(unit,rb) c c twait: c routine in bat.c to determine the # bytes last c read from unit and set the logical error flags. c char*4: unit: Name of the unit (like "ft32") c log*4: rb(13): error flags c rb(1): if read as a int*4: the # of bytes c last read from unit. c rb(2): if true: tape mark/end of file c rb(3): if true: end of tape c rb(4): if true: permanent error c The rest of rb is not implemented c c Decode the error flags c if (res(3)) ierr = ierr-4 if (res(2)) ierr = ierr-2 if (res(1) .or. icount .eq. 0) ierr = ierr -1 c c Fill returned variables c l = icount ieod = ierr return end