Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6549015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:02:26+00:00 2026-05-25T12:02:26+00:00

I have some Fortran code that performs a simulation. The elapsed time is stored

  • 0

I have some Fortran code that performs a simulation. The elapsed time is stored in et, and the timestep is stored in dt. Both are defined as type real. There is another real variable tot which holds the maximum time the simulation should run. i is a counting variable of type integer. My first attempt was like this:

real, intent(in) :: dt
real, intent(in) :: tot

real :: et
integer :: i

et = 0.0
i = 0
do
   i = i+1
   et = real(i)*dt
   if (et > tot) exit

   ! main code here
end do

I wanted to get rid of i since it was only used in the one place, however, when I tried this, the program hangs when the total time is large:

real, intent(in) :: dt
real, intent(in) :: tot

real :: et

et = 0.0
do
   et = et + dt
   if (et > tot) exit

   ! main code here
end do

What is the difference between the two code samples that causes the program to respond so differently? My compiler is g77.

EDIT: I have added the declarations and initializations to the code samples above.

EDIT 2: The initial values passed to the subroutine are dt = 1e-6 and tot = 100.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:02:27+00:00Added an answer on May 25, 2026 at 12:02 pm

    If dt is very small in relation to tot, it might also be that at one point dt is so small, that adding it to the, by then large, et has no effect (lost in numerical precision), and thus et does not grow beyond that point…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a line of Fortran code, which includes some text. I'm changing the
I have a bash script that runs a simulation program written in Fortran 90,
I have some routines written in fortran that I'd like to use in my
I have some old (~1995) legacy fortran code which is compiled with g77 compiler
I have to convert some code from Fortran so doesn't know how what this
I have some old fortran 77 I'm trying to port to gcc on Windows.
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some C# / asp.net code I inherited which has a textbox which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.