# Program to numerically solve 3 ODE's

**URL:** <https://fortran-lang.discourse.group/t/program-to-numerically-solve-3-odes/2275>\
**Category:** Homework\
**Created:** [November 15, 2021, 4:54pm UTC](https://fortran-lang.discourse.group/t/program-to-numerically-solve-3-odes/2275 "2021-11-15T16:54:45Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [November 17, 2021, 8:19pm UTC](https://fortran-lang.discourse.group/t/program-to-numerically-solve-3-odes/2275/15 "2021-11-17T20:19:46Z")

</div>

One resource is the fortran-lang tutorial: [Organising code structure - Fortran Programming Language](https://fortran-lang.org/learn/quickstart/organising_code)

If available to you, I would recommend the latest edition of “Modern Fortran explained” by Metcalf, Reid & Cohen, chapter 5 - Program units and procedures.

A second option would be “Guide to Fortran 2008 Programming” by Walter Brainerd: [Guide to Fortran 2008 Programming | SpringerLink](https://link.springer.com/book/10.1007/978-1-4471-6759-4). Perhaps you can access the digital version with your university account.

The keyword `contains` is simply used to collect internal subprograms (subroutines and functions) in a main program or module:

```fortran
program main
  implicit none
  
  ! ... declarations ...

  ! ... main program unit commands ...

contains

  ! ... internal subprograms ...

  subroutine runge(...)

  end subroutine

  function dydt(t,y)

  end function

end program

```

Instead of placing the procedures in the main program, you can place them in a module:

```fortran
module flow_solver_routines
  implicit none

  ! ... declarations ...

contains

  ! ... internal subprograms ...

  subroutine runge(...)

  end subroutine

  function dydt(t,y)

  end function

end module  

```

that you then use in the main program as follows:

```fortran
program main
  use flow_solver_routines, only: runge, dydt
  implicit none

  ! ...

  call runge(dydt,tstart,tend,y)

end program

```

In fact even subroutines and functions can have procedures nested in their own `contains` section.

On the other hand, your [old program](https://fortran-lang.discourse.group/t/if-statement-formatting-related-to-runge-kutta-ode-solver/2240) used so-called `external` subprograms, i.e. subprograms that are not located within a program unit or module. External procedures were the norm in F77, but since F90 modules are the preferred approach to organize your (sub)programs.

When using internal subprograms the compiler can check you are calling the function or subroutine correctly since the interface is visible. Internal subprograms also have access to the objects in their host program, which can be useful for many things.

---

_[View the full topic](https://fortran-lang.discourse.group/t/program-to-numerically-solve-3-odes/2275)._
