Search code examples
fortrandirectory-structure

What is the accepted way to setup a directory structure for Fortran code?


For a large Fortran project I would like to know what is the accepted way to setup a directory structure. For example I have the main source code (main.f90), some modules (mod_1.f90, mod_2.f90, etc...), and some source code for particular subroutines (subr_1.f90, subr_2.f90, etc...)

I currently have a directory with a mod directory which contains all the mod_*.f90 files and a src directory which contains main.f90 along with the subroutines. Is this the way to do it?


Solution

  • Generally, the best way to learn is to just look at directory structures that other people use. For example, this is geared towards using cmake, but has a fairly typical directory structure:

    https://github.com/SethMMorton/cmake_fortran_template

    Here's another large project that uses fortran, but their directory structure is a bit different (but still consistent):

    https://github.com/cp2k/cp2k

    Generally, you do directory structures similar to how you would any other project in another language. You want your folder names to make sense: as an example, you might decide that binaries go in the /bin folder, documentation goes in /doc, examples go in /example, source in /src, a nice readme.txt or readme.md in the root folder, etc.

    Really, the most important thing is to just be consistent about it. Don't just toss everything into the root folder unless it's a tiny project with only a couple files.