* Tue Jun 21 14:11:10 EDT 1994 /plas1/h1/mzh/src/test phase2.f c Routine of MJSANL to read trajectory information c from short encounter SEDR files. c c The code was originally written by R. Selesnick 6-17-86 c The code was updated and commented by A. Szabo 4-27-94 c The code was updated and commented by J. Belcher 4-21-2023 c subroutine phase2(jtb,ieod) c c Input variables: c JTB(6) {int*2}: Array of requested time c JTB(1): Year in 4 digit format (i.e. 1981) c JTB(2): Day of year (January 1st is day 1) c JTB(3): Hours c JTB(4): Minutes c JTB(5): Seconds c JTB(6): mSeconds c c The routine returns the standard read error flag IEOD: c IEOD {int*4}: 0 - Ok; -1 - end of file; -2 - read error c c The routine also fills elements of the common blocks: c HEADER, SPEC, and ROTMAX c most of this is accomplished through the routine XSPN c c Navigation block data variables c dimension rnav(27),rnav1(27),rnav2(27),rnavt1(27),rnavt2(27) dimension rnavt2s(18) c c Pointing block data variables c dimension rpt(9),rpt1(9),rpt2(9),rptt1(9),rptt2(9) c c Time arrays c dimension itb(6),itn(6),itp(6) c c Decimal hours from 1977. They need to be double precision c because of the large values involved very close to each other. c real*8 rhb,rhn1,rhn2,rhnt1,rhnt2,rhp1,rhp2,rhpt1,rhpt2 c c The array of the requested time (JTB) is passed in the calling c sequence as an integer*2 array. c integer*2 jtb(6) c c Definition of the logical and character variables are c at the data section. c logical ptl,navl,first,rew character*8 plch,planet(4) character*44 for character*4 v1, v2, vv1, vv2, scch c c The planet ID will be set: c IPLNT = 1 - Jupiter c 2 - Saturn c 3 - Uranus c 4 - Neptune c common/mid/iplnt,fact1 c c The S/C ID will be set: VOY = 453 - Voyager 1; 372 - Voyager 2 c COMMON/SCID/V0,JNE c c Only the ISCID will be set in the HEADER common block: c 0 - Voyager 2; 1 - Voyager 1 c COMMON/HEADER/PROJID,FILEID,ISCID,TAPEID(2),IGENDT,IGENTM,FIPID(2) 1,IFGEND,IFGENT,DPTJ1(2),IFRMT1(2),DPTJ2(2),IFRMT2(2),DPTJ3(2),IFRM 2T3(2),DPTJ4(2),IFRMT4(2),HSPARE(18) c c The start and stop times of the sedr tape will be loaded into c the SEDR common block from the short sedr header. c common/sedr/isedr,ist(6),isp(6) c c Initialize the temporary navigation and pointing decimal c time variables to zero. c data rhnt2/0.d0/, rhpt2/0.d0/ c c Unit number where the trajectory file/tape is expected c data iunit/33/ c c Initialize flags signaling nav and pt data ready to false c data ptl/.false./, navl/.false./ c c Initialize flag signaling first time execution to true c data first/.true./ c c Initialize rewind flag to false c data rew/.false./ c c Set the array with the names of the planets. c The case of the characters of Neptune is historucal c data planet/'JUPITER ','SATURN ','URANUS ','Neptune '/ c c Set possible S/C names encountered in traj header records c data vv1 /' V1 '/, vv2 /' V2 '/, v1 /'V1 '/, v2 /'V2 '/ c c============================================================ c BEGIN THE EXECUTION c============================================================ c c Turn off the error flag c ieod = 0 c c First time around open trajectory file for binary input c c if (first) call initio(1,-iunit,ii) c c Convert the request time from int*2 to int*4 format c c write(6,7711) jtb 7711 format("phase2 called time ",6i5) do 10 i=1,6 10 itb(i)=jtb(i) itn(1)=0 itn(2)=0 itn(3)=0 itn(4)=0 itn(5)=0 itn(6)=0 c write(6,2199) itn,jtb 2199 format("misc",12i5) c c Convert request time to decimal hour from 1977 day 1 c This subroutine is later on in this module. c call dechr(itb,rhb) c c Compare with previous time, rewind if necessary c c write(6,9123) rhb,rhn2,rhpt2 9123 format("rhb,rhn2,rhpt2",3f15.1) if(rhb.lt.rhnt2 .or. rhb.lt.rhpt2) then rew=.true. c rewind iunit rhnt2 = 0. rhpt2 = 0. endif c c Read header only if at the beginning of the file c if(.not.rew .and. .not.first) goto 49 c c Read header record c A complete header record consists of two lines. The first c contains the planet and spacecraft name followed by the c beginning and end times of the whole file. The second line c contains the fortran format of the data records. For more c info, see the revised version of Voy memo #168. c c read(iunit) plch,scch,ist,isp c c Set the planet id to be stored in the common block MID c c do 15 i=1,4 c15 if(plch.eq.planet(i)) iplnt=i c c Set the S/C id to be stored in the common block SCID c c if(scch .eq. vv1 ) voy=453. c if(scch .eq. vv2 ) voy=372. c if(scch .eq. v1 ) voy=453. c if(scch .eq. v2 ) voy=372. c c Set the S/C id to be stored in the common block HEADER c c iscid = 0 c if (voy .eq. 453.) iscid = 1 c c The the 2nd line of header, the format of the data records c c read(iunit) for c c Print header info to the screen c c if (iscid .eq. 1) then c write(6,*)'SEDR Header: Voyager 1 at ',plch,' ID#: ',iplnt c else c write(6,*)'SEDR Header: Voyager 2 at ',plch,' ID#: ',iplnt c endif c c Turn off the rewind flag c rew = .false. c c Read records to get one on each side of rhb, the request time c c But first store previous values c 20 rhnt1=rhnt2 rhpt1=rhpt2 do 30 i=1,27 30 rnavt1(i)=rnavt2(i) do 40 i=1,9 40 rptt1(i)=rptt2(i) c c Read next data record with format appropriate for the planet c go to (41,42,43,44),iplnt c c Jupiter, Uranus: c 41 continue 43 continue read(iunit,298,end=999,err=998)itn,rnavt2,itp,rptt2 c write(6,2119) itn,jtb 2119 format("phase2 jup",6i5,5x,6i5) 2109 format("phase2 not",6i5,5x,6i5) 298 format(6I5,27E16.8,6I5,9E16.8) go to 46 c c Saturn, Neptune: c 42 continue 44 continue c write(6,2109) itn read(iunit,299,end=999,err=998)itn,rnavt2s,itp,rptt2 299 format(6I5,18E16.8,6I5,9E16.8) c c Load the shorter data records into the beginning of the c full length data array c do 45 i=1,18 45 rnavt2(i)=rnavt2s(i) c c Convert the navigation and pointing block times into decimal hrs c 46 call dechr(itn,rhnt2) call dechr(itp,rhpt2) c c Keep nav block if in range c c write(6,7721) rhnt1,rhb,rhnt2 7721 format("7721 rhnt1,rhb,rhnt2",3f15.1) 49 if(.not.(rhnt1.lt.rhb .and. rhb.le.rhnt2)) goto 60 c c Check that the first record is not too far ahead of c the requested time c if ((.not.first) .and. (rhb .lt. rhnt2-24.)) then write(6,*)'WARNING! Requested time is more than' write(6,*)' 24 hours before first SEDR nav block.' endif c c Store data in final variables and set final nav block flag c rhn1=rhnt1 rhn2=rhnt2 do 50 i=1,27 rnav1(i)=rnavt1(i) 50 rnav2(i)=rnavt2(i) navl=.true. c c Keep pnt block if in range c c write(6,8811) rhpt1,rhb,rhpt2 8811 format("8811 rhpt1,rhb,rhpt2 ",3f15.1) 60 if(.not.(rhpt1.lt.rhb .and. rhb.le.rhpt2)) goto 80 c c Check that the first record is not too far ahead of c the requested time c if ((.not.first) .and. (rhb .lt. rhpt2-24.)) then write(6,*)'WARNING! Requested time is more than' write(6,*)' 24 hours before first SEDR pt block.' endif c c Turn off first flag c first = .false. c c Store data in final variables and set final pt block flag c rhp1=rhpt1 rhp2=rhpt2 do 70 i=1,9 rpt1(i)=rptt1(i) 70 rpt2(i)=rptt2(i) ptl=.true. c c Read next record if nav and pnt blocks out of range c 80 continue if(.not.navl .or. .not.ptl) goto 20 c c Interpolate the nav and pt records to the requested time c do 90 i=1,27 90 call intrp(rhn1,rhn2,rhb,rnav1(i),rnav2(i),rnav(i)) do 100 i=1,9 100 call intrp(rhp1,rhp2,rhb,rpt1(i),rpt2(i),rpt(i)) c c The final nav and pt data is now in the arrays RNAV and RPT c c Fill sblk - use the routine xspn to calculate trajectory data c call xspn(rnav,rpt,itb,iplnt) c c Reset data ready flags c navl=.false. ptl=.false. c return c c Read error section c 998 write(6,*)'Read error on trajectory file/tape.' ieod = -2 return c c End of file section c 999 write(6,*)'End of file on trajectory file/tape.' ieod = -1 return end c c======================================================== c END OF EXECUTION c======================================================== c subroutine dechr(it,rh) c c Routine to convert a 6 element integer*4 time array c (year, day, hr, min, sec, msec) to decimal hours (real*8) c from the reference year 1977 day 1. This routine also c takes leap years into account. c integer*4 it(6) real*8 rh, s(6), p(6) c c Reference time c data s/1977.d0,1.d0,0.d0,0.d0,0.d0,0.d0/ c c Conversion factors to hours c data p/8760.d0,24.d0,1.d0,1.66666666666666667d-2, & 2.777777777777777778d-4,2.7777777777777777778d-7/ c c Convert time array to decimal hours from 1977 day 1 c rh = 0.d0 do 10 i=1,6 10 rh = rh + (dfloat(it(i))-s(i)) * p(i) c c Add in days for leap years c rh = rh + dfloat((it(1)-1977)/4) * 24.d0 c write(6,7711) it,rh 7711 format("dechr called",6i5,f15.1) return end c subroutine intrp(rh1,rh2,rh,x1,x2,x) c c Linear interpolation of x between x1 and x2 at time rh c between rh1 and rh2. If rh1=0 than x=x2. c INPUT: c RH {real*8}: The requested time to interpolate to. c RH1 {real*8}: The lower boundary of the time interval. c RH2 {real*8}: The upper boundary of the time interval. c X1: {real*4}: Data value at the lower boundary. c X2: {real*4}: Data value at the upper boundary. c OUTPUT: c X: {real*4}: Interpolated data at time RH. c c The time variables are double precision because they are c large numbers (decimal hours from 1977) very close to each other. c real*8 rh1, rh2, rh c c Check if RH1 is zero indicating that no interpolation should c be made just the value of X2 taken. c c write(6,1295) rh1 1295 format('rh1: ', F8.1) if (rh1 .eq. 0.d0) then x = x2 return endif c c Fractional increment for x c frac = (rh-rh1)/(rh2-rh1) c c Interpolate c x = x1 + frac*(x2-x1) c return end c subroutine xspn(rnav,rpt,itb,iplnt) c c Routine to calculate various trajectory parameters and c fill the common blocks SPEC and ROTMAX. c INPUT: c RNAV(27) R4: Navigation record (see Voy. Memo 168 Revised) c RPT(9) R4: Pointing record (see Voy. Memo 168 Revised) c ITB(6) I4: Six element time array of the above data c IPLNT I4: Planet ID: 1 - Jupiter; 2 - Saturn c 3 - Uranus; 4 - Neptune c c All output is through common blocks. c c The navigation and pointing data arrays, time array c dimension rnav(27), rpt(9), itb(6) COMMON/SCID/V0,JNE c c ECL50 planet centered state of S/C and pos. of one moon c dimension srecl(3), svecl(3), xrecl(3) c c SVNEG=-SVECL, S/C velocity in S/C frame c dimension svneg(3), svsc(3) c c TPMED state of S/C and position of one moon c dimension srtpm(3), svtpm(3), xrtpm(3),xvtpm(3) c c Rotation matrices: S/C->ECL50, TPMED->ECL50, ECL50->TPMED c dimension tscecl(9), ttpecl(9), tecltp(9) c c Rotation matrices: S/C->CYL, TPMED->CYL, S/C->TPMED, TPMED->S/C c dimension tsccy(9), ttpcy(9), tsctp(9), ttpsc(9) c c Rotation matrices: ECL50->Heliographic, Hel.->RTN, ECL50->RTN c dimension teclhe(9), thertn(9), tecrtn(9) c c S/C position in Sun centered heliographic system c dimension srhe(3) c c Corotation velocity in S/C ref. frame S/C coord., -cor. vel. in TPMED c dimension vcrsc(3), vcor(3) c c Corotation velocity components into each cup, and normalized responses c dimension vcomp(4), resp(4) c c Planetary radii, Word#-1 of the last moon in the nav array c dimension rp(4), isat(4) c c S/C coordinates of cup normals, Null vector, Rotation matrix axis c dimension cupn(3,4), vn(3), vr(3) c c S/C velocity in S/C coordinates with corotation aberated c dimension svscco(3) c c Added for Cassini proposal 1/4/90 c Relative spacecraft distance to Titan in ECL50 c dimension satdis(3) c c Trajectory and coordinate transformation common block c common/spec/sblk(60) c c The following elements of this common block are filled: c SBLK(1): Distance of S/C from planetary center (planet radius) c 9-12: Normalized response of all cups to a corotational flow c with no modulator or suppressor voltage. It is the cup c transparency times the sensitive area normalized by the c response to normal incidence with the same cup normal c component. c 13-16: Components of a corotational flow into each cup (km/s) c 17: Rigid corotational speed (km/s) c 19: Distance of S/C from planet rotation axis (planet radii) c 24: Distance of S/C from planetary equatorial plane (planet radii) c 40-42: S/C velocity in planet centered S/C coordinates (km/s) c 44-52: Rotation matrix from S/C to cylindrical coordinates c 55: Distance of the S/C to the center of Titan (km) c (only for Saturn encounter case) c c Rotation matrix common block c common/rotmax/tcyssc(9),tscrtn(9),icoord,trot(9),voff(3), & tnossc(9),teclsc(9) c c The following elements of this common block are filled: c TCYSSC(1-9): Rotation matrix from planetary cylindrical system c to S/C coordinates. c TSCRTN(1-9): Rotation matrix from S/C to RTN coordinates. c TECLSC(1-9): Rotation matrix from ECL50 to S/C coordinates. c c Voyager S/C id common block c c c This common block was filled in the main part of phase2. c The possible values are: c 453. - Voyager 1 c 372. - Voyager 2 c c bkd 3/18/92: c S/C position in Sun centered ECL50 at times of encounter c From pam@leverrier Thu Mar 19 12:02:40 1992 c c Possible S/C positions. The first index is the planet id, c the second is the component number. c real*4 V1POS(4,3), V2POS(4,3), SCPOS(3) c c Voyager 1 position at 1979 64 12 c data ( V1POS(1,I), I=1,3 ) /-4.742981e8, 6.336064e8, 8.132460e6/ c c Voyager 1 position at 1980 318 0 c data ( V1POS(2,I), I=1,3 ) /-1.420619e9, -3.610331e7, 5.710272e7/ c c Voyager 1, of course, never went to Uranus and Neptune c data ( V1POS(3,I), I=1,3 ) /3 * 0.0/ data ( V1POS(4,I), I=1,3 ) /3 * 0.0/ c c Voyager 2 position at 1979 190 0 c data ( V2POS(1,I), I=1,3 ) /-5.819141e8, 5.452475e8, 1.083987e7/ c c Voyager 2 position at 1981 237 4 c data ( V2POS(2,I), I=1,3 ) /-1.408678e9, -2.757932e8, 6.096590e7/ c c Voyager 2 position at 1986 24 19 c data ( V2POS(3,I), I=1,3 ) /-5.834007e8, -2.799786e9, -2.970636e6/ c c Voyager 2 position at 1989 237 4 c data ( V2POS(4,I), I=1,3 ) /8.42286e8, -4.43841e9, 7.09959e7/ c c Null vector c data vn/0.,0.,0./ c c Word#-1 of the first coordinate of the last moon in the navigation c data array for the four planets. See Voy. Memo 168 Revised. c data isat/21,12,21,12/ c c Planetary radii in km (Jupiter, Saturn, Uranus, Neptune) c data rp/71372., 60330., 25600., 24765./ c c The cup normal vectors in S/C coordinates pointing away from cups c CUPN(1-3,1)=CUPN(1-3): A cup normal c CUPN(1-3,2)=CUPN(4-6): B cup normal c CUPN(1-3,3)=CUPN(7-9): C cup normal c CUPN(1-3,4)=CUPN(10-12): D cup normal c data cupn/-.2962, -.1710, -.9397, .2962, -.1710, -.9396, & 0.0, .3420, -.9397, .7310, .6816, -.0349/ c c Conversion factor from degrees to radians c data rd/.0174533/ c c Longitude of ascending node and tilt angle of sun c in ECL50 (deg) c data PHIS/75.07/, TS/7.25/ c c=============================================================== c B E G I N E X E C U T I O N c=============================================================== c c Load the appropriate average S/C position in Sun centered ECL50 c IF (V0 .EQ. 453.) THEN DO 667 I=1,3 667 SCPOS(I) = V1POS(IPLNT, I) ELSE DO 668 I=1,3 668 SCPOS(I) = V2POS(IPLNT, I) END IF c c Load data from the navigation and pointing data arrays c--------------------------------------------------------- c do 1 i=1,3 c c S/C cartesion position and velocity in TPMED c srtpm(i)=rnav(i) svtpm(i)=rnav(3+i) c c S/C cartesian position and velocity in planet centered ECL50 c srecl(i)=rnav(6+i) svecl(i)=rnav(9+i) c c Satellite cartesian position in TPMED. c (it is only Callisto for Jupiter and Titania for Uranus) c j=i+isat(iplnt) xrtpm(i)=rnav(j) c c Satellite cartesian position in planet centered ECL50 c 1 xrecl(i)=rnav(j+3) c c Rotation matrix from ECL50 to S/C coordinates c do 2 i=1,9 2 teclsc(i)=rpt(i) c c=================================== c c For Cassini proposal 1/4/90 rlm c Calculate S/C distance to Titan for Saturn encounter case only c if (iplnt .ne. 2) go to 9000 do 9001 jk=1,3 satdis(jk)=xrecl(jk)-srecl(jk) 9001 continue titan=vecabs(satdis) c c================================== c 9000 continue c c Set rotation rate of planet c CROT has effect only for Uranus where the rotation rate c is changed from 15.56 to 17.24 hrs. c call crot(srtpm,svtpm,itb,iplnt) call crot(xrtpm,xvtpm,itb,iplnt) c c S/C spherical radius from planet center c rs=vecabs(srtpm) c c Rotation matrix from ECL50 to TPMED c call rotmtx(srecl,xrecl,srtpm,xrtpm,tecltp,vr,angle) c c Rotation matrix from TPMED to ECL50 coordinates c call teqatr(ttpecl,tecltp) c c Rotation matrix from TPMED to S/C coordinates c call teqab(ttpsc,teclsc,ttpecl) c c Rotation matrix from S/C to TPMED coordinates c call teqatr(tsctp,ttpsc) c c S/C velocity w.r.t. corotation in S/C coordinates, aberrated c call vtrns(svscco,ttpsc,svtpm,vn) c c Corotation velocity in S/C coordinates, aberrated c do 5 i=1,3 5 vcrsc(i)=-svscco(i) c c Cup response to rigid corotational flow assuming no modulator c or suppressor voltage and normalized to normal incidence. c c write(6,1199) 1199 format(" from PHASE2 ") call cuprsp(vcrsc,resp) c c Rigid corotation velocity component into each cup c do 10 i=1,4 10 vcomp(i)=vecscl(svscco,cupn(1,i)) c c S/C cylindrical radial distance w.r.t. spin axis of planet c scrho=sqrt(srtpm(1)**2+srtpm(2)**2) c c Rigid corotation speed c do 20 i=1,3 20 svneg(i)=-svecl(i) call vtrns(vcor,tecltp,svneg,svtpm) c c NOTE: VCOR is the negative of the corotation velocity in TPMED c vcorot=vecabs(vcor) c c Rotation matrix from TPMED to planetary cylindrical coordinates c (Cylindrical coordinates: X-axis: perpendicular to planet spin c axis and always points towards the S/C; Y-axis = 0; Z-axis is c along the planetary spin axis.) c ttpcy(1)=srtpm(1)/scrho ttpcy(2)=-srtpm(2)/scrho ttpcy(3)=0. ttpcy(4)=srtpm(2)/scrho ttpcy(5)=srtpm(1)/scrho ttpcy(6)=0. ttpcy(7)=0. ttpcy(8)=0. ttpcy(9)=1. c c Rotation matrix from S/C coordinates to planetary c cylindrical coordinates and inverse c call teqab(tsccy,ttpcy,tsctp) call teqatr(tcyssc,tsccy) c c S/C velocity in S/C coordinates c call vtrns(svsc,teclsc,svecl,vn) c c RTN Calculations c--------------------------------------------------------- c Construct rotation matrix from S/C to inertial heliographic c and then to RTN coordinates. c c From xspnur.f originally written for Uranus encounter c by Richard Selesnick c c Get rotation matrix from S/C to ECL50 system c call teqatr(TSCECL,TECLSC) c c Rotation matrix from S/C to inertial heliographic system c For more details, see the inline comments in xcru(phase3.f) c P=PHIS*RD T=TS*RD TECLHE(1)=COS(P) TECLHE(2)=-SIN(P)*COS(T) TECLHE(3)=SIN(P)*SIN(T) TECLHE(4)=SIN(P) TECLHE(5)=COS(P)*COS(T) TECLHE(6)=-COS(P)*SIN(T) TECLHE(7)=0. TECLHE(8)=SIN(T) TECLHE(9)=COS(T) c c Calculate S/C position in heliographic coordinates c call vtrns(SRHE,TECLHE,SCPOS,vn) c c Calculate transformation matrix from inertial heliographic c to RTN coordinates based on the S/C location. c For details, see Voy Memo 33. c A=SQRT(SRHE(1)**2+SRHE(2)**2) B=SQRT(A**2+SRHE(3)**2) THERTN(1)=SRHE(1)/B THERTN(2)=-SRHE(2)/A THERTN(3)=-SRHE(1)*SRHE(3)/(A*B) THERTN(4)=SRHE(2)/B THERTN(5)=SRHE(1)/A THERTN(6)=-SRHE(2)*SRHE(3)/(A*B) THERTN(7)=SRHE(3)/B THERTN(8)=0. THERTN(9)=A/B c c Rotation matrix from ECL50 to RTN c call teqab(TECRTN,THERTN,TECLHE) c c Rotation matrix from S/C to RTN c call teqab(TSCRTN,TECRTN,TSCECL) c c End of RTN calculations c--------------------------------------------------------------- c c Fill SBLK array in SPEC common block c sblk(1)=rs/rp(iplnt) do 200 i=1,4 sblk(i+8)=resp(i) 200 sblk(i+12)=vcomp(i) sblk(17)=vcorot sblk(19)=scrho/rp(iplnt) sblk(24)=srtpm(3)/rp(iplnt) call veccpy(sblk(40),svsc) do 300 i=1,9 300 sblk(i+43)=tsccy(i) c c For Cassini proposal c Distance of S/C to center of Titan in kilometers c sblk(55)=titan c return end c c============================================================= c E N D O F XSPN E X E C U T I O N c============================================================= c subroutine crot(x,v,itb,iplnt) c c change planetary rotation rate c xdr is the new angular velocity minus the old in rad/hr c itref is the time at which the coordinate systems match c x and v are the position and velocity in cartesion TPMED c coordinates which are changed c c uranus period is changed from 15.56 to 17.24 hours c jupiter, saturn and neptune use rotation rates on the sedr c dimension xdr(4),itref(6,4),itb(6),x(3),v(3),itt(6) real*8 rb,rref data xdr/0.,0.,0.03909,0./ data itref/1979,190,0,0,0,0, * 1981,0,0,0,0,0, * 1986,24,18,0,0,0, * 1989,0,0,0,0,0/ if (xdr(iplnt).eq.0.) return call dechr(itb,rb) do 10 i=1,6 10 itt(i)=itref(i,iplnt) call dechr(itt,rref) dt=rb-rref c c new position c th=xdr(iplnt)*dt x1=x(1) x2=x(2) x(1)=x1*cos(th)-x2*sin(th) x(2)=x1*sin(th)+x2*cos(th) c c new velocity c v1=v(1)-(xdr(iplnt)/3600.)*x2 v2=v(2)+(xdr(iplnt)/3600.)*x1 v(1)=v1*cos(th)-v2*sin(th) v(2)=v1*sin(th)+v2*cos(th) c return end