# Fortran at the U.S. Geological Survey

**URL:** <https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956>\
**Category:** Uncategorized\
**Created:** [April 5, 2021, 8:12pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956 "2021-04-05T20:12:10Z")\
**Posts on this page:** 14\
**Page:** 1

<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:** [April 5, 2021, 8:12pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/1 "2021-04-05T20:12:10Z")

</div>

The U.S. Geological Survey provides the [MODFLOW](https://www.usgs.gov/mission-areas/water-resources/science/modflow-and-related-programs?qt-science_center_objects=0#qt-science_center_objects) hydrologic model, which is considered an international standard for simulating and predicting groundwater conditions and groundwater/surface interactions.

The latest release is known as the [MODFLOW One-Water Hydrologic Flow Model](https://www.usgs.gov/software/modflow-one-water-hydrologic-flow-model-conjunctive-use-simulation-software-mf-owhm). The MODFLOW code is written in Fortran and can be found [here](https://code.usgs.gov/modflow/mf-owhm).

A [search](https://www.usgs.gov/science-explorer-results?es=fortran) of the USGS website reveals several other interesting Fortran projects, including the [Batteries Included Fortran Library (BiF-lib)](https://www.usgs.gov/software/batteries-included-fortran-library-bif-lib-version-100). The actual code can be found [here](https://code.usgs.gov/fortran/bif) and is under an Apache license. It contains several things you would expect in a standard library.

---

<div class="post-metadata">

**Author:** ![khaors](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/khaors/32/288_2.png) [@khaors](https://fortran-lang.discourse.group/u/khaors)\
**Post date:** [April 7, 2021, 7:10pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/2 "2021-04-07T19:10:49Z")

</div>

Did you try BiF-lib? I tried to compile it with gfortran 10.0 but there are some errors. I think that this library was developed with ifort.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 7, 2021, 7:36pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/3 "2021-04-07T19:36:48Z")

</div>

> [@khaors](#):
>
> Did you try BiF-lib? I tried to compile it with gfortran 10.0 but there are some errors. I think that this library was developed with ifort.

Does it compile with gfortran with the `-std=legacy` option? That’s the first thing to try.when something does not compile by default with gfortran. If it still does not compile, can you list the errors?

---

<div class="post-metadata">

**Author:** ![khaors](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/khaors/32/288_2.png) [@khaors](https://fortran-lang.discourse.group/u/khaors)\
**Post date:** [April 7, 2021, 7:42pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/4 "2021-04-07T19:42:48Z")

</div>

After checking the errors, this library uses modern fortran features such as do concurrent, functions of the iso\_binding\_c module and some other intrinsic functions defined in the fortran 2003 and fortran 2008 standard. These features are all available in gfortran 10 but IMO the errors are due to ifort syntax (e.g do concurrent (integer :: i )). It is possible to specify the compiler in the makefile (using make COMPILER=gcc F90=gfortran), but the errors still appear.

I have tried gfortran 8,3 in windows and gfortran 10.2 in a linux box but the errors are still there.

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [April 7, 2021, 8:42pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/5 "2021-04-07T20:42:04Z")

</div>

> [@khaors](#):
>
> … the errors are due to ifort syntax (e.g do concurrent (integer :: i )) …

That appears to be standard-conforming syntax starting Fortran 2008.

---

<div class="post-metadata">

**Author:** ![khaors](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/khaors/32/288_2.png) [@khaors](https://fortran-lang.discourse.group/u/khaors)\
**Post date:** [April 7, 2021, 8:59pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/6 "2021-04-07T20:59:01Z")

</div>

Thanks for the information about the do concurrent in the fortran 2008 standard, I did not know that. However, gfortran shows the do concurrent (integer :: i …) as an error (using gfortran 8.3 in windows and 10.2 in linux) which means that this is not currently implemented in this compiler.

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [April 7, 2021, 9:07pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/7 "2021-04-07T21:07:57Z")

</div>

`do concurrent` was added to [GNU Fortran 8](https://gcc.gnu.org/wiki/GFortran/News). Make sure you use the correct syntax for concurrent do loops:

```auto
integer :: i

do concurrent (i = 1:10)
    print *, i
end do

```

Sorry, I missed that the source code uses ~~Intel compiler extensions~~ standard conforming F2008 features that are probably not implemented in GNU Fortran 8. Probably has be to solved manually via search and replace.

---

<div class="post-metadata">

**Author:** ![khaors](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/khaors/32/288_2.png) [@khaors](https://fortran-lang.discourse.group/u/khaors)\
**Post date:** [April 7, 2021, 9:13pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/8 "2021-04-07T21:13:54Z")

</div>

@interkosmos Thanks for your reply. Yes, the code that you posted worked fine in gfortran 8.3 and 10.2 I was referring to the syntax do concurrent (integer :: i…) which gfortran shows as an error. And you are right, this can be solved with a search and replace. However, there are other compilation errors that might be caused by some missing features in gfortran.

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [April 7, 2021, 9:15pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/9 "2021-04-07T21:15:33Z")

</div>

> [@interkosmos](#):
>
> … Make sure you use the correct syntax for concurrent do loops: …

Well, the following is a conforming program that `gfortran` does not support, so interested gfortran users can file a request at [**GCC Bugzilla**](https://gcc.gnu.org/bugzilla/). Or better yet will be if a lot more Fortran practitioners become highly enthused to contribute to GCC/gfortran as C developers to enhance the front-end for Fortran.

```Fortran
   integer :: x(3)
   do concurrent ( integer :: i = 1:size(x) ) 
      x(i) = i
   end do
   print *, "x: ", x
end

```

> C:\Temp\>gfortran -c p.f90  
> p.f90:2:18:
> 
> ```
> 2 | do concurrent ( integer :: i = 1:size(x) )
> | 1
> 
> ```
> 
> Error: Syntax error in DO statement at (1)  
> p.f90:4:6:
> 
> ```
> 4 | end do
> | 1
> 
> ```
> 
> Error: Expecting END PROGRAM statement at (1)

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [April 7, 2021, 9:27pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/10 "2021-04-07T21:27:09Z")

</div>

The source code of [BiF-lib](https://code.usgs.gov/fortran/bif) does not seem to be valid Fortran. I tried:

```auto
$ gmake COMPILER=gcc F90=gfortran CONFIG=release

```

And got:

```auto
[…]
gfortran timer_instruction.f90

./src/datetime/timer_instruction.f90:599:8:

  599 | SEC = SEC - day2sec*REAL(ITMP, dbl)
      | 1
Error: Variable 'sec' cannot appear in a variable definition context (assignment) at (1) in PURE procedure
[…]

```

Having a look at the source code in `src/datetime/timer_instruction.f90` shows:

```auto
  PURE FUNCTION PRETTY_PRINT_TIMER(SEC, LEVEL) RESULT(TIM)
    REAL(DBL), VALUE:: SEC
        […]
        SEC = SEC - day2sec*REAL(ITMP, dbl)  

```

IIRC, overriding dummy arguments passed as `value` is not permitted.

---

<div class="post-metadata">

**Author:** ![khaors](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/khaors/32/288_2.png) [@khaors](https://fortran-lang.discourse.group/u/khaors)\
**Post date:** [April 7, 2021, 9:35pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/11 "2021-04-07T21:35:22Z")

</div>

@interkosmos I got the same errors with the pure functions and also with some intrinsic functions due to differences in the precision of the input arguments (iand function with integer16 and integer 32 inputs). It seems that this library compiles with ifort without problem.

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [April 7, 2021, 10:36pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/12 "2021-04-07T22:36:28Z")

</div>

> [@interkosmos](#):
>
> … overriding dummy arguments passed as `value` is not permitted. …

No, the Fortran standard permits dummy arguments with `VALUE` attribute to be used in a variable-definition context provided they are **not** declared with `INTENT(IN)` attribute.

The `PRETTY_PRINT_TIMER` function, at least as shown upthread, looks standard-conformant - again, gfortran does not appear to have caught up with the standard here.

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [April 9, 2021, 9:52am UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/13 "2021-04-09T09:52:25Z")

</div>

I’ve found non-conformances in BiF-lib. There are equality operators between Integer and Logical. There doesn’t seem to be a way of contacting the author or submitting issues or pull requests.

---

<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:** [April 9, 2021, 12:19pm UTC](https://fortran-lang.discourse.group/t/fortran-at-the-u-s-geological-survey/956/14 "2021-04-09T12:19:31Z")

</div>

You can try to contact [Scott Boyce](https://www.usgs.gov/staff-profiles/scott-boyce?qt-staff_profile_science_products=3#qt-staff_profile_science_products) from USGS, directly. He can also add you to their GitLab server.
