Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How does the Fortran90 function floor not have a main type?

  1. Oct 4, 2011 #1

    Simfish

    User Avatar
    Gold Member

    I'm running Fortran 90 with the ifort compiler. As far as I can tell, floor is a function introduced in Fortran 90

     
    Last edited: Oct 4, 2011
  2. jcsd
  3. Oct 5, 2011 #2

    Mark44

    Staff: Mentor

    The compiler seems to be complaining that the PLANET_DAY_RATIO thing in the call to the floor intrinsic doesn't have a type. A workaround might be to define it as a parameter.
     
  4. Oct 5, 2011 #3

    uart

    User Avatar
    Science Advisor

    That's strange, it should recognize "floor()"

    Can you test if int() and nint() work?
     
  5. Oct 5, 2011 #4

    Simfish

    User Avatar
    Gold Member

    I see - thanks very much for the reply!

    Here is the subroutine. I defined PLANET_DAY_RATIO within the subroutine. Am I doing it wrong?

    Code (Text):

    subroutine get_curr_date(yr, mon, day, tod, offset)

    ! Return date components valid at end of current timestep with an optional
    ! offset (positive or negative) in seconds.

       implicit none
       
    ! Arguments
       integer, intent(out) ::&
          yr,    &! year
          mon,   &! month
          day,   &! day of month
          tod     ! time of day (seconds past 0Z)

       integer, optional, intent(in) :: offset  ! Offset from current time in seconds.
                                                ! Positive for future times, negative
                                                ! for previous times.

    ! Local variables
       character(len=*), parameter :: sub = 'get_curr_date'
       integer :: rc
       type(esmf_date) :: date
       type(esmf_time) :: off
       integer :: ymd
       integer :: leap_days
       integer :: yZero
       integer :: day_earth
       float :: PLANET_DAY_RATIO

    (stuff)

       yr = ymd/10000
       mon = mod(ymd, 10000) / 100
       day = mod(ymd, 100)
        PLANET_DAY_RATIO = 0.5 !0.5 is for spinning twice as fast, or 43200 seconds
        yZero = start_ymd/10000
        leap_days = (yr -yZero)/4
       day_earth = day_earth + 365*(yr -yZero) + leap_days
        tmd = day_earth/PLANET_DAY_RATIO - floor(day_earth / PLANET_DAY_RATIO)
       
    end subroutine get_curr_date
     
     
    Last edited by a moderator: Oct 5, 2011
  6. Oct 5, 2011 #5

    Simfish

    User Avatar
    Gold Member

    mod() definitely works, so I'm pretty sure that floor() should work too
     
  7. Oct 5, 2011 #6

    uart

    User Avatar
    Science Advisor

    Hi simfish. I'm not real big on Fortran but when I have used it I've generally had problems whenever I've tried to mix integers and reals in the same expression. Honestly I've given up on trying to figure out the whys and where-fores and now I simply assign all integers to a temporary real before using them in a mixed expression.

    Something like

    Code (Text):
    integer :: day_earth
    real :: day_earth_tmp, PLANET_DAY_RATIO

    ...
    day_earth_tmp = day_earth
    tmd = day_earth_tmp/PLANET_DAY_RATIO - floor(day_earth_tmp / PLANET_DAY_RATIO)
     
     
  8. Oct 5, 2011 #7

    Simfish

    User Avatar
    Gold Member

    Ah okay - thanks for the suggestion! I'll try to see if that works tomorrow.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook