initialize_moon_pa_frame Subroutine

private subroutine initialize_moon_pa_frame(me, filename, et0, etf)

Read the table and compute the (global) splines, for the time span [et0, etf]: the rows from the last one at or before et0 to the first one at or after etf (as in moonframe). Then the object's workspace is reset; copies of the object (allocate(..., source=...)) can be used by other threads.

Type Bound

moon_pa_frame

Arguments

Type IntentOptional Attributes Name
class(moon_pa_frame), intent(inout) :: me
character(len=*), intent(in) :: filename

csv file with the ephemeris time, roll, pitch and yaw (rad)

real(kind=wp), intent(in) :: et0

start ephemeris time of the span to spline [sec]

real(kind=wp), intent(in) :: etf

end ephemeris time of the span to spline [sec]


Calls

proc~~initialize_moon_pa_frame~~CallsGraph proc~initialize_moon_pa_frame moon_pa_frame%initialize_moon_pa_frame db1ink db1ink proc~initialize_moon_pa_frame->db1ink destroy destroy proc~initialize_moon_pa_frame->destroy get get proc~initialize_moon_pa_frame->get

Source Code

    subroutine initialize_moon_pa_frame(me, filename, et0, etf)

    class(moon_pa_frame),intent(inout) :: me
    character(len=*),intent(in) :: filename !! csv file with the ephemeris time, roll, pitch and yaw (rad)
    real(wp),intent(in) :: et0 !! start ephemeris time of the span to spline [sec]
    real(wp),intent(in) :: etf !! end ephemeris time of the span to spline [sec]

    type(csv_file) :: f
    real(wp),dimension(:),allocatable :: et, roll, pitch, yaw, fcn
    integer :: n, istart, iend, i, j, iflag
    logical :: status_ok

    ! read the data from the csv file:
    call f%read(filename, header_row=1, status_ok=status_ok)
    if (.not. status_ok) error stop 'error reading file: '//trim(filename)
    call f%get(1, et,    status_ok); if (.not. status_ok) error stop 'error getting et from file: '//trim(filename)
    call f%get(2, roll,  status_ok); if (.not. status_ok) error stop 'error getting roll from file: '//trim(filename)
    call f%get(3, pitch, status_ok); if (.not. status_ok) error stop 'error getting pitch from file: '//trim(filename)
    call f%get(4, yaw,   status_ok); if (.not. status_ok) error stop 'error getting yaw from file: '//trim(filename)
    call f%destroy()

    ! the rows to use (the span, with the rows just outside it):
    n = size(et)
    istart = minloc(abs(et-et0), 1)
    if (et(istart) > et0) istart = max(1, istart - 1)
    iend = minloc(abs(et-etf), 1)
    if (et(iend) < etf) iend = min(n, iend + 1)
    if (et(iend) < et(istart)) error stop 'Error: end time is before start time'

    ! the global splines. roll and pitch have no discontinuities; the yaw angle wraps
    ! around once per lunar rotation, so its cosine and sine are splined instead.
    if (allocated(tx)) deallocate(tx)
    if (allocated(bcoef)) deallocate(bcoef)
    nx = iend - istart + 1
    allocate(tx(nx+kx, n_splines), bcoef(nx, n_splines), fcn(nx))
    do j = 1, n_splines
        do i = istart, iend  ! (a loop: no large temporaries on the stack)
            select case (j)
            case (1); fcn(i-istart+1) = roll(i)
            case (2); fcn(i-istart+1) = pitch(i)
            case (3); fcn(i-istart+1) = cos(yaw(i))
            case (4); fcn(i-istart+1) = sin(yaw(i))
            end select
        end do
        call db1ink(et(istart:iend), nx, fcn, kx, iknot, tx(:,j), bcoef(:,j), iflag)
        if (iflag/=0) error stop 'error initializing the MOON_PA spline: '//trim(filename)
    end do

    call me%destroy()  ! (reset the workspace)

    end subroutine initialize_moon_pa_frame