[Spice_discussion] Porting SPICE Fortran program from Mac PowerPC
to Mac Intel
William Thompson
William.T.Thompson at nasa.gov
Tue Nov 25 10:37:27 PST 2008
Yes, that fixed the problem. Thank you.
Boris Semenov wrote:
> Hi Bill --
>
> It's possible that the cause of the problem is in the incorrect
> declaration of CMAT. In your program it is declared as
>
> DOUBLE PRECISION CMAT(4)
>
> while it should be
>
> DOUBLE PRECISION CMAT(3,3)
>
> Also, it would be cleaner is you changed "... , 1, ..." in CKW03 call to
> "..., .TRUE., ...".
>
> Please, let me know if your program with these changes works on Intel Mac.
>
> Regards,
> Boris.
>
> William Thompson wrote:
>> Folks:
>>
>> I've been running the attached SPICE Fortran program for some years
>> now without problem on a Mac OSX PowerPC platform. I recently tried
>> to port it to the Mac Intel platform. It seemed to compile and run
>> okay, but when I examined the values, I found that it gave a
>> completely different answer from that on older PowerPC platform. Can
>> anybody suggest why that should be?
>>
>> The program was compiled with
>>
>> ifort -C -o cksmooth -assume byterecl cksmooth.f \
>> /service/stereo3/stereo/software/spice_fortran/i386/lib/support.a \
>> /service/stereo3/stereo/software/spice_fortran/i386/lib/spicelib.a
>>
>> The "-assume byterecl" was based on an examination of the compilation
>> program for the source library. However, I also tried it with this
>> keyword off, and it didn't seem to make a difference.
>>
>> I also tried "-real-size 32 -double-size 64", but that didn't seem to
>> help either.
>>
>> Thanks for any help you can give me,
>>
>> Bill Thompson
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> C This program applies a smoothing algorithm to a STEREO Type III
>> C Attitude History (CK) file. It is used in conjunction with the
>> C CKSMRG utility to produce a reduced-resolution attitude history file
>> C representative of the average pointing.
>> C
>> C This routine is called with 1-3 parameters:
>> C
>> C INFILE = The name of the CK file to process.
>> C
>> C OUTFILE = The name of the output file. If not passed, then
>> C defaults to "cksmooth_out.bc".
>> C
>> C NSMOOTH = A parameter related to the size of the boxcar average
>> C smoothing function. The box will run between
>> C I-NSMOOTH to I+NSMOOTH, so that the total size of the
>> C box is 2*NSMOOTH+1. The default is NSMOOTH=150,
>> C which for STEREO is equivalent to a box 5 minutes
>> C wide.
>> C
>> C Example:
>> C
>> C rm -f ahead_2006_303_01_temp.ah.bc
>> C cksmooth ahead_2006_303_01.ah.bc ahead_2006_303_01_temp.ah.bc
>> C
>> C Note that the output file must not exist when calling this program.
>> C
>>
>> PROGRAM CKSMOOTH
>>
>> IMPLICIT DOUBLE PRECISION (A-H, O-Z)
>> IMPLICIT INTEGER (I-N)
>>
>> PARAMETER (ND=2, NI=6)
>>
>> CHARACTER*(128) INFILE, OUTFILE
>> CHARACTER*(80) ARCH, TYPE, REF, SSMOOTH
>> CHARACTER*(40) NAME
>> INTEGER INHANDLE, OUTHANDLE, IC(NI)
>> LOGICAL FOUND
>> DOUBLE PRECISION DC(ND), SUM(125), QUAT0(4), CMAT(4)
>>
>> PARAMETER (MAXREC=1000000)
>> DOUBLE PRECISION RECORD(8),INARRAY(8,MAXREC)
>> DOUBLE PRECISION SCLKDP(MAXREC), QUATS(4,MAXREC), AVVS(3,MAXREC)
>> DOUBLE PRECISION ANGLE0(3), ANGLES(3,MAXREC)
>>
>> C Get the number of arguments. The first argument should be the name
>> C of the input file. If supplied, the second argument will be the
>> C name of the output file, and the third argument will be the window
>> C size (+/-).
>>
>> NARGS = IARGC()
>> CALL GETARG (1, INFILE )
>> OUTFILE = 'cksmooth_out.bc'
>> IF (NARGS .GE. 2) CALL GETARG (2, OUTFILE)
>> NSMOOTH = 150
>> IF (NARGS .GE. 3) THEN
>> CALL GETARG (3, SSMOOTH)
>> READ (SSMOOTH,'(I5)') NSMOOTH
>> ENDIF
>>
>> C Open the input file.
>>
>> CALL DAFOPR (INFILE, INHANDLE)
>>
>> C Open the new file to initialize it.
>>
>> NAME = 'STEREO Ahead spacecraft bus (smoothed)'
>> IF (IC(1) .EQ. -235000) NAME =
>> $ 'STEREO Behind spacecraft bus (smoothed)'
>> CALL CKOPN(OUTFILE, NAME, 0, OUTHANDLE)
>>
>> C Begin forward search, and find the first array.
>>
>> CALL DAFBFS (INHANDLE)
>> CALL DAFFNA (FOUND)
>>
>> C Step through the arrays. Get the summary and unpack it.
>>
>> DO WHILE (FOUND)
>> CALL DAFGS (SUM)
>> CALL DAFUS (SUM, ND, NI, DC, IC)
>>
>> C Get the number of pointing instances. Step through the pointing
>> C instances, and collect the array.
>>
>> CALL CKNR03(INHANDLE, SUM, NREC)
>> DO J=1,NREC
>> CALL CKGR03(INHANDLE, SUM, J, RECORD)
>> DO I=1,8
>> INARRAY(I,J) = RECORD(I)
>> ENDDO
>> ENDDO
>>
>> C Convert the quaternion first to a C-matrix, and then to Euler
>> C angles.
>>
>> DO J=1,NREC
>> DO I=1,4
>> QUAT0(I) = INARRAY(I+1,J)
>> ENDDO
>> CALL Q2M(QUAT0, CMAT)
>> CALL M2EUL(CMAT, 1, 2, 3, ROLL0, PITCH0, YAW0)
>> ANGLES(1,J) = ROLL0
>> ANGLES(2,J) = PITCH0
>> ANGLES(3,J) = YAW0
>> ENDDO
>>
>> C Extract out the spacecraft clock values, smoothed quaternions,
>> C and smoothed angular velocities.
>>
>> DO J=1,NREC
>> SCLKDP(J) = INARRAY(1,J)
>>
>> J1 = J-NSMOOTH
>> IF (J1 .LT. 1) J1 = 1
>> J2 = J+NSMOOTH
>> IF (J2 .GT. NREC) J2 = NREC
>> NAVG = J2-J1+1
>>
>> C Average together the Euler angles.
>>
>> DO I=1,3
>> C1 = 0.D0
>> S1 = 0.D0
>> X1 = 0.D0
>> X2 = 0.D0
>> XC = 0.D0
>> XS = 0.D0
>> DO K=J1,J2
>> COS_ANGLE = DCOS(ANGLES(I,K))
>> SIN_ANGLE = DSIN(ANGLES(I,K))
>> C1 = C1 + COS_ANGLE
>> S1 = S1 + SIN_ANGLE
>> DX = K - J
>> X1 = X1 + DX
>> X2 = X2 + DX**2
>> XC = XC + DX * COS_ANGLE
>> XS = XS + DX * SIN_ANGLE
>> ENDDO
>> C1 = C1 / NAVG
>> S1 = S1 / NAVG
>> X1 = X1 / NAVG
>> X2 = X2 / NAVG
>> XC = XC / NAVG
>> XS = XS / NAVG SLOPE = (XC
>> - X1*C1) / (X2 - X1**2)
>> COS_ANGLE = C1 - SLOPE*X1
>> SLOPE = (XS - X1*S1) / (X2 - X1**2)
>> SIN_ANGLE = S1 - SLOPE*X1
>> ANGLE0(I) = DATAN2(SIN_ANGLE, COS_ANGLE)
>> ENDDO
>>
>> C Convert the Euler angles back into a C-matrix, and then back into a
>> C quaternion.
>>
>> CALL EUL2M(ANGLE0(1), ANGLE0(2), ANGLE0(3), 1, 2, 3, CMAT)
>> CALL M2Q(CMAT, QUAT0)
>> DO I=1,4
>> QUATS(I,J) = QUAT0(I)
>> ENDDO
>>
>> C Average together the angular velocities.
>>
>> DO I=1,3
>> AVVS(I,J) = 0
>> DO K=J1,J2
>> AVVS(I,J) = AVVS(I,J) + INARRAY(I+5,K)
>> ENDDO
>> AVVS(I,J) = AVVS(I,J) / NAVG
>> ENDDO
>> ENDDO
>>
>> C Write out the smoothed pointing segment.
>>
>> CALL CKW03(OUTHANDLE, DC(1), DC(2), IC(1), 'J2000', 1,
>> $ 'Smoothed CK', NREC, SCLKDP, QUATS, AVVS, 1, SCLKDP(1))
>>
>> C Step to the next array
>>
>> CALL DAFGH(INHANDLE)
>> CALL DAFFNA (FOUND)
>> END DO
>>
>> C Close the input and output files.
>>
>> CALL DAFCLS(INHANDLE)
>> CALL DAFCLS(OUTHANDLE)
>>
>> END
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Spice_discussion mailing list
>> Spice_discussion at naif.jpl.nasa.gov
>> http://naif.jpl.nasa.gov/mailman/listinfo/spice_discussion
>
>
--
William Thompson
NASA Goddard Space Flight Center
Code 671
Greenbelt, MD 20771
USA
301-286-2040
William.T.Thompson at nasa.gov
(Note changed email address)
More information about the Spice_discussion
mailing list