initialize_ephemeris Subroutine

private subroutine initialize_ephemeris(me, filename, ksize, km, bary, status_ok)

Initialize the ephemeris. This routine may be called to load a different ephemeris file. Otherwise, it is called on the first call to get_state, and loads the file specified in the module header.

Note

  • Based on code formerly in state.

Type Bound

jpl_ephemeris

Arguments

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

ephemeris file name

integer, intent(in), optional :: ksize

corresponding ksize

logical, intent(in), optional :: km

defining physical units of the output states. km = .true. : km and km/sec [default], km = .false. : au and au/day.

logical, intent(in), optional :: bary

logical flag defining output center. only the 9 planets are affected. bary = .true. : center is solar-system barycenter, bary = .false. : center is sun [default].

logical, intent(out) :: status_ok

true if there were not problems.


Called by

proc~~initialize_ephemeris~~CalledByGraph proc~initialize_ephemeris jpl_ephemeris_module::jpl_ephemeris%initialize_ephemeris proc~ephemeris_test jpl_ephemeris_module::ephemeris_test proc~ephemeris_test->proc~initialize_ephemeris proc~transformation_module_test transformation_module::transformation_module_test proc~transformation_module_test->proc~initialize_ephemeris

Source Code

    subroutine initialize_ephemeris(me,filename,ksize,km,bary,status_ok)

    implicit none

    class(jpl_ephemeris),intent(inout) :: me
    character(len=*),intent(in)        :: filename   !! ephemeris file name
    integer,intent(in),optional        :: ksize      !! corresponding `ksize`
    logical,intent(in),optional        :: km         !! defining physical units of the output states.
                                                     !! `km = .true.`  : km and km/sec [default],
                                                     !! `km = .false.` : au and au/day.
    logical,intent(in),optional        :: bary       !! logical flag defining output center.
                                                     !! only the 9 planets are affected.
                                                     !! `bary = .true.`  : center is solar-system barycenter,
                                                     !! `bary = .false.` : center is sun [default].
    logical,intent(out) :: status_ok                 !! true if there were not problems.

    !local variables:
    integer :: irecsz,istat,i,j,k,l

    !just in case it was already open:
    call me%close()  ! clears everything in the class

    !ephemeris file name:
    me%namfil = trim(filename)

    !optional inputs:
    if (present(ksize)) me%ksize  = ksize
    if (present(km))    me%km     = km
    if (present(bary))  me%bary   = bary

    irecsz     = nrecl*me%ksize
    me%ncoeffs = me%ksize/2

    open(newunit = me%nrfile,     &
         file    = me%namfil,     &
         access  = 'DIRECT',      &
         form    = 'UNFORMATTED', &
         action  = 'READ',        &   !JW added
         recl    = irecsz,        &
         iostat  = istat,         &
         status  = 'OLD'          )

         !write(*,*) "istat=",istat

    status_ok = (istat==0)  !if there were no problems opening the file

    if (status_ok) then

        read(me%nrfile,rec=1,iostat=istat) &
                 me%ttl,(me%cnam(k),k=1,oldmax),me%ss,me%ncon,me%au,me%emrat,&
                 ((me%ipt(i,j),i=1,3),j=1,12),me%numde,(me%ipt(i,13),i=1,3), &
                 (me%cnam(l),l=oldmax+1,me%ncon)

        if (istat==0) then
            if (me%ncon <= oldmax) then
                read(me%nrfile,rec=2,iostat=istat) (me%cval(i),i=1,oldmax)
            else
                read(me%nrfile,rec=2,iostat=istat) (me%cval(i),i=1,me%ncon)
            endif
            if (istat==0) then
                me%nrl = 0
                me%initialized = .true.
            end if
        end if

        ! check if the reads went OK:
        status_ok = me%initialized
        if (status_ok) then
            !initialize some of the class variables:
            ! [note: this was formerly done in the interp routine]
            me%pc(1) = 1.0_wp
            me%vc(2) = 1.0_wp
        else
            write(error_unit,'(A)') 'Error reading ephemeris file: '//trim(me%namfil)
        end if

    else
        write(error_unit,'(A)') 'Error opening ephemeris file: '//trim(me%namfil)
    end if

    end subroutine initialize_ephemeris