Oct 02, 2021

*The first Fortran program I ever wrote (Jan. 1997).*
At the recent FortranCon2021, I was amused to see in the presentation "The State of Fortran 2021" that the first bullet point on the slide "Formation of Fortran-Lang" was:
August 2019 Conversations on Twitter between Ondřej Čertík, Milan Curcic, and Jacob Williams bring out common perceived shortcomings in the Fortran ecosystem
Laurence Kedward, et. al., "The State of Fortran 2021", Fortran2021, Sept. 2021
So, now, over two years later, I think it's finally time to tell my side of the story. 😀
I was first introduced to Fortran 25 years ago, in 1997 (my only previous programming experience was with BASIC on Apple ]['s). We used the WATFOR FORTRAN 77 compiler on DOS machines in an undergraduate programming class for engineers. Little did I know (or little did the university know) that Fortran 90 had been published years earlier (and indeed Fortran 95 was published at the end of that very semester).
Over the course of my academic career, I encountered and used Fortran a few times, mostly FORTRAN 77, and mostly to solve homework problems or do class projects. I came to use IMSL, Numerical Recipes in FORTRAN 77, Harwell Subroutine Library, and had some minimal exposure to Fortran 90 one semester when asked to modernize some old code by one of the professors for some project that I've forgotten about (something to do with gravity anomalies). But mostly I used a lot of Matlab, which is very popular among engineering students (due to cheap student licenses). I also used a little MathCad, some Mathematica, REALBasic (since renamed Xojo), and Visual Basic (classic). There was then no exposure in the aerospace engineering curriculum of two major US universities to any sort of formal software development practices (for all I know this is still the case). I never once encountered version control, unit testing, continuous integration, etc. Maybe those weren't as common then? (Subversion didn't come out until 2000, and Git until 2005).

*The FORTRAN book from my first (and only) programming class. I still have it.*
When I entered professional life in late 2006, it wasn't long before I became the lead developer of a Fortran tool at NASA called Copernicus. Originally created by one of my former professors, Copernicus is a tool for spacecraft trajectory optimization and design. While working on Copernicus, I was introduced to Fortran 90/95 in earnest. Copernicus was originally developed on Windows with Compaq Visual Fortran (which, by the time I came along, had recently become defunct) and one of my first projects was to convert the code over to use the Intel Fortran compiler (which we have used ever since). During this period I first became aware of modern-ish (Fortran 95) concepts such as user derived types, operator overloading, function overloading, etc. Eventually Fortran 2003 came along, which was quite a revelation, and as soon as non-buggy implementations of the new features appeared in the Intel compiler (it took a while) I was using it like crazy. It's hard to imagine programming Fortran now without modern features such as type bound procedures. FORTRAN 77 (and indeed, even Fortran 95), to me, now seems like something out of the dark ages. And so I came to really appreciate the Modern Fortran programming language, and wondered why more people didn't use it (or seem to even know about it).
![[from archive.org]](https://degenerateconic.com/uploads/2021/10/compaq.png)
*Compaq Visual Fortran [from [archive.org](https://archive.org/details/fortran66c)]*
The fact was, all was not well in the larger Fortran community. Really, there was very little community. Most of the code I encountered on the internet was still FORTRAN 77, like the last 25 years never happened. There were also few if any Fortran blogs (there were a few of exceptions: Fortran Dev [now defunct], Fortran in a C World [now also defunct], and Steve Lionel's Doctor Fortran column at Intel [still updated infrequently]). One of the bright spots was the Intel Fortran Compiler forum, which was always full of helpful folks (Steve, of course, the most helpful of all). There were very few websites to speak of that had much useful Modern Fortran content. Fortran.com is a mostly-useless site, and fortran.org has been held hostage by a domain name squatter for years. Ondřej Čertík's site fortran90.org is good (but of course it is folly to put the standard name in the URL since that will eventually be out of date). Fortranwiki.org, administrated by Jason Blevins is also a good site.

*The favicon for this website*
On June 26, 2014, I started this blog, with the intent to focus on modern Fortran and astrodynamics algorithms. Earlier that year, I had also discovered GitHub and started to work on some projects there as well. At work, we were still using Subversion for version control at this time, but I wanted to learn more about git. The blog and my presence on GitHub was an experiment to attempt to publicly develop an ecosystem of Modern Fortran libraries (either by creating new ones, or refactoring old codes that hadn't been updated in decades that nobody else seemed to want to update), as well as to advocate for Fortran and show what it could do. On GitHub I encountered others who were also working on Fortran tools, namely Stefano Zaghi (author of lots of great libraries and tools, including FoBiS, the Fortran Building System for poor people, which is very dear to my heart), Zaak Beekman (who helped me greatly with JSON-Fortran and introduced me to continuous integration), Chris MacMackin (author of the ford automatic documentation generator for Fortran, which I contributed a very very small amount to), and a few others. Zaak also started a GitHub group called the Fortran F/OSS Programmers Group, which I also participated in and view as sort of a precursor to the fortran-lang group. Zaak and I coauthored a paper in 2018 on Modern Fortran applications in my field of spacecraft trajectory optimization, which I consider to be my magnum opus.

In April 2017, I was approached by Manning Publications, who wanted to discuss the possibility of writing a Fortran book. I didn't really have time to do that so I declined. But luckily, they also approached Milan Curcic, who did end up writing it (Modern Fortran, 2020) and it turned out excellent.

I currently have 67 repositories on GitHub, the vast majority of them being Fortran libraries, and they are used by lots of people all over the world in various fields of science and engineering. But one thing I didn't really have the aptitude or know-how to do was to form an online community. Years ago I considered buying the fortran.io domain when I noticed it was still up for grabs, but it was eventually bought by Nick Doiron around 2016 (see FORTRAN.io -- finally, a Fortran Web Framework) which made the rounds somewhat on the tech internet, basically just as a novelty. I guess the .io fad for tech domain names is over now anyway?

*The Fortran-lang logo.*
There just wasn't a website that really served as a focal point for the entire Fortran community. It was a huge image problem. This was one of the things I lamented in my (infamous?) August 2019 post. Luckily, Milan had purchased fortran-lang.org sometime in 2018, and that is what he activated for the new site in April 2020. Milan and Ondřej have already written about their amazing efforts to rejuvenate the Fortran community and ecosystem (I first became aware of Ondřej in April 2019 when he announced LFortran, which totally blew my mind). The fortran-lang website, the Fortran Standard Library, the Fortran Package Manager, and everything else that has come out these activities has been spectacular. I have actually contributed very little to all of this, although I did help with the logo (see this previous post for the story on that). I also continue to toil away on my libraries like before (recently getting a good number of them set up to compile with the new Fortran Package Manager).
So, now you know my side of the story. The future of Fortran is looking bright, and I'm pleased to have contributed in some small way. Now get off my lawn.
See also
- J. Williams, R. D. Falck, and I. B. Beekman, "Application of Modern Fortran to Spacecraft Trajectory Design and Optimization", 2018 Space Flight Mechanics Meeting, 8–12 January 2018, AIAA 2018-145.
- J. Williams, End of Life [degenerateconic.com] August 3, 2019
- J. Williams, New Blood [degenerateconic.com] April 26, 2020
- M. Curcic, First year of Fortran-lang [medium.com] Dec 21, 2020
- O. Čertík, Resurrecting Fortran [ondrejcertik.com] March 12, 2021
Sep 25, 2021

FortranCon 2021 (September 23-24, 2021), the second international conference dedicated to the Fortran programming language, has concluded. Once again, it was an amazing conference, with lots of great talks, including a fortran-lang minisymposium. This year there were about 160 registered attendees and about 80 people on average on Zoom and Slack at any given time.
Lists of talks

See also
Jun 13, 2021

There are a lot a JSON libraries available for Fortran nowadays. The complete list, as far as I know is:
- fson Fortran 95 JSON Parser. JSON-Fortran is a fork of this library. (started 2012).
- YAJL-Fort A Modern Fortran Interface to YAJL. This one is an interface to a C library, and not pure Fortran. See also petaca. (started 2013).
- JSON-Fortran A Fortran 2008 JSON API. This is my library. As far as I know, this was the first production-ready JSON parser written in modern Fortran. (started 2014).
- fortjson JSON library written in Fortran 2003. Designed with portability across HPC architectures in mind. (started 2018).
- jsonff JSON for Fortran. (started 2019).
Example
Here's an example of using JSON-Fortran to read in some data from a JSON string:
program test
use json_module, wp => json_RK, ip => json_IK
implicit none
type(json_file) :: json
integer(ip) :: t
real(wp),dimension(:),allocatable :: x
call json%deserialize('{"t": 1, "x": [2.0, 3.0, 4.0]}')
call json%get('t', t); write(*,*) t
call json%get('x', x); write(*,*) x
end program test
This prints:
1
2.00000000000000 3.00000000000000 4.00000000000000
Note that JSON-Fortran has all sorts of options for:
- Using different real (real32, real64, and real128) and integer kinds (int8, int16, int32, and int64).
- Controlling the JSON format for printing, including number of spaces for indenting, printing vectors on one line only, or full minification with no extra whitespace or line breaks.
- Support for comments in a JSON file.
- Multiple ways to get data from a JSON structure, such as RFC 6901 "JSON Pointer" paths or JSONPath) "bracket-notation".
- Graceful handing of unusual inputs such as NaN or Infinity.
- Thread safe error handling.
See also
Dec 18, 2020

Intel recently released its new oneAPI Toolkit, which had been in beta for a while. According to their documentation, oneAPI includes various products:
The big news here is that this is all now entirely free to use. They are all available for Windows, Linux, and macOS. The Fortran compiler also now includes all of the Fortran 2018 standard. Apparently, Intel will still sell you a license, but it seems the only reason to buy one would be to get the Premier Support.
See also
Oct 30, 2020

MPFUN2015 is a Fortran arbitrary precision library by David H. Bailey. An archive of the source code can be found on his website here (note that I also have a mirror of the source at GitHub if you want to peruse it). This library seems to be one of the few freely-available production-ready arbitrary precision Fortran libraries available that I can find, although arbitrary precision Fortran code has existed for quite a while (e.g., see Reference 1 from 1971). MPFUN2015 is pretty easy to use, but I think could use a little bit of modernization.
See also
- L. C. Maximon, Fortran Program for Arbitrary Precision Arithmetic, National Bureau of Standards, NBS 10-563, April 1, 1971.
- D. H. Bailey, A Thread-Safe Arbitrary Precision Computation Package (Full Documentation), August 23, 2019.
Jul 03, 2020

FortranCon 2020 was the first international conference entirely focused on the Fortran programming language. It took place in Zurich, Switzerland, but because of the current pandemic, it was almost entirely virtual. It was a terrific two-day conference with a lot of amazing presentations from people all around the world.
Here is the list of talks:
- Steve Lionel, Keynote: Fortran 2018…and Beyond
- Milan Curcic, Toward a thriving open source Fortran community
- Jeremie Vandenplas, Fortran Standard Library
- Brad Richardson, Fortran Package Manager
- Thomas König, Front-end optimization in gfortran
- Gary Klimowicz, Flang: The LLVM Fortran Front-End
- Ondřej Čertík, LFortran: Interactive LLVM-based Fortran Compiler for Modern Architectures
- Jacob Williams, Copernicus Spacecraft Trajectory Design and Optimization Program
- William Sawyer, Evolving Fortran for Emerging Architectures: Lessons from the ICON-GPU Atmospheric Model
- Christopher Brady, EIS2 - A mathematically rich input file processor for HPC applications
- Erin Hodgess, Using R with High Performance Fortran on a Windows Laptop
- Philipp Engel, Connecting Fortran to the Internet of Things
- Vincent MAGNIN, gtk-fortran: a GTK / Fortran binding
- Lee Taylor, Shroud: generate Fortran wrappers for C and C++ libraries
- Maximilien Ambroise, Designing a Modern C++/Fortran Interface by Example
- Nick Papior, Program flow control using scripting languages
- Luigi Genovese, The Futile project: an embedded DSL to simplify the treatment of low-level operation in large Fortran programs
- Patrick Seewald, Generic Programming Techniques
- Arjen Markus, Experimental Fortran Programming
- Laurence Kedward, Interfacing with OpenCL from Modern Fortran for Highly Parallel Workloads
- Robert Schweppe, Applying context-free grammar to hierarchically organized and variably shaped arrays
- Jordan Ott, A Fortran-Keras Deep Learning Bridge for Scientific Computing
- Darius Markauskas, Code::Blocks: open source, cross platform IDE for Fortran
- Melissa Weber Mendonça, F2PY: Bringing fast code into the future
- Jeff Larkin, Highly Parallel Fortran and OpenACC Directives
- Nicolas Netto, Parallelization of a Legacy Software through Fortran 2018 Standard
- Amir Shahmoradi, ParaMonte: Plain Powerful Parallel Monte Carlo Library
I presented a talk on Copernicus, the spacecraft trajectory design and optimization software that I develop for NASA. We recently completed the 5.0 release of Copernicus, which included some major upgrades and a new GUI. The core of Copernicus, of course, is written in Fortran. Copernicus is being used to design the trajectories that will return humans to the Moon.

*A mind numbing chart from my talk on Copernicus at FortranCon 2020.*
Many thanks to the organizers of FortranCon 2020. I hope this is just the first of many FortranCon's to come.
See also
Update (July 26, 2020): added the missing links
Apr 26, 2020

It's been about 8 months since my screed about things that were wrong with the Fortran ecosystem and standards committee. I got a lot of feedback from that post. It seems like a lot of people felt the same way. The funny thing is, it seems like some things are slowing beginning to change:
- A new GitHub repo was created for the community to work on proposals for the Fortran standard, to be discussed at committee meetings. This is unprecedented, and hopefully is just the beginning of putting the actual standard on GitHub for community inputs and editing.
- A new project: the Fortran standard library has begun to be developed on GitHub. This is for things that have been left out of the standard, and can be added to a library much quicker than the standard and compilers can be updated.
- A new website has appeared: fortran-lang.org as well as an associated project on GitHub. The goal of this is to be "the home" of Fortran on the internet. Something the two Fortran committee websites have never attempted to be. This site is community created (the contents are also on GitHub, so join us in helping to make it better).
These efforts are terrific, and serve as an online focus for the Fortran community, which up to this point has been mostly scattered and unorganized. The Fortran standards development process has hitherto been extremely opaque to the user community, so shining (still just a little bit of) light on that is good for everybody I think.
It has been clear for some time that some kind of change was needed in how the Fortran language is developed. In my view, the Fortran standards committee has failed spectacularly in the years since the release of Fortran 2003. Fortran 2003 was an amazing update to Fortran 95 that significantly expanded the utility of the language. Since then (for almost two decades) the focus has been on supercomputers and incremental improvements. The main pillar of Fortran language development seems to be to make absolutely sure that 50 year old spaghetti code still works without any modifications, even at the expense of correcting mistakes from decades ago that continually bedevil beginner Fortran programmers. In the meantime, Python (basically a scripting language used to wrap C/C++ libraries) has almost completely taken over scientific/technical computing, and amazing new languages have been created entirely from scratch (e.g., Chapel, Julia, Rust, Go, Swift) that all have made inroads into this field. All while the Fortran committee did very little to advance the language into new areas or make it more appealing to new programmers or people developing new libraries and codes. Fortran continues in some respects to hold its own on supercomputers and some massive legacy applications, but the writing is on the wall. The situation is dire, but I guess some of the committee seem to think nothing is wrong or they are in no hurry to do anything about Fortran's steady decline into irrelevance. According to a recent first-time attendee of the last committee meeting:
I spent last week at my first Fortran Standards Committee meeting. It was a pretty interesting experience. Everyone there was brilliant, and interested in trying to do a good job improving the language. And yet, it was still somehow very disfunctional.
everythingfunctional.wordpress.com

*Recent Meeting of the Fortran Standards Committee. (I kid because I love!)*
So I was very pleased to learn that Ondřej Čertík (@ondrejcertik) is running for chairman of the ISO Fortran Committee. Ondřej has been one of the main people spearheading all these new efforts. He also is the one behind LFortran, which looks to be one of the most innovative Fortran compilers in recent memory (actually moving Fortran just a little bit toward the direction of dynamic languages like Python, which is absolutely critical for getting new users onboard). Ondřej has published a platform which is fantastic. He has my total support (whatever that's worth!)
So, we'll see where all this goes. Hopefully things are improving. I encourage all Fortran users to support these new efforts, contribute to these new projects, and help with the website. Fortran is still a terrific language for numerical/scientific/technical computing. Getting the user community organized, improving the ecosystem, and improving the language standards process are only going to make it better in the long run.
Fun fact: the "F" Fortran logo shown above is based on the cover of the original IBM Fortran programmer's reference manual from 1956. Using the "WhatTheFont" feature at MyFonts.com, I determined that the font was Clarendon, or something very close to it. I created this icon in Inkscape some time ago in the original ugly brown color (e.g., it's the favicon for this website). Milan Curcic (@realmilancurcic) changed it to a nice purple and started using it on the fortran-lang.org website. I cleaned it up a bit and now SVG and PNG versions can be found here. I guess we'll use it until somebody comes up with something better.
See also
Dec 18, 2019

Intel has released version 19.1 the Intel Fortran Compiler (part of Intel Parallel Studio XE 2020). According to the release notes, the new version adds a lot of features from Fortran 2018:
- Enhancements to the IMPLICIT statement allow specifying that all external procedures must declared EXTERNAL
- Enhancements to the GENERIC statement permit it to be used to declare generic interfaces
- The locality of variables may now be specified on a DO CONCURRENT statement
- Enhancements to edit descriptor forms E, D, EN, ES, and G allow a field width of zero, analogous to the F edit descriptor
- The exponent width e in a data edit descriptor may now be zero, analogous to a field width of zero
- The RN edit descriptor now rounds to nearest as specified by Fortran 2018 and ISO/IEC/IEEE 60559:2011
- The EX edit descriptor allows for hexadecimal format output of floating point values. Hexadecimal format floating point values are allowed on input.
- SIZE= may be specified for non-advancing I/O
- The values for SIZE= and POS= in an INQUIRE statement for pending asynchronous operations have been standardized
- The value assigned to the RECL= specifier in an INQUIRE statement now has standardized values
- A new form of the intrinsic function CMPLX does not require the KIND= keyword if the first argument is type COMPLEX
- The arguments to the SIGN function may be of different kinds
- INTEGER and LOGICAL arguments to intrinsic procedures are no longer required to be of default kind
- The named constants STAT_FAILED_IMAGE and STAT_UNLOCKED_FAILED_IMAGE have been defined in the intrinsic
ISO_FORTRAN_ENV module
- The non-block DO statement and the arithmetic IF statement are now deleted in Fortran 2018.
- COMMON, EQUIVALENCE and BLOCKDATA statements are now obsolescent
- The labeled form of DO loops is now obsolescent
- Locality of variables in DO CONCURRENT constructs can now be declared on the DO CONCURRENT statement
- Specific names of intrinsic procedures are now obsolescent
- FAIL IMAGE statement allows debugging recovery code for failed images without having to wait for an actual image failure
- The named constants STAT_FAILED_IMAGE and STAT_UNLOCKED_FAILED_IMAGE have been defined in the intrinsic
ISO_FORTRAN_ENV module
- An optional argument STAT= has been added to ATOMIC_REF and ATOMIC_DEFINE intrinsic procedures
- Optional STAT= and ERRMSG= specifiers have been added to the MOVE_ALLOC intrinsic procedure, to image selectors, and to the CRITICAL statement and construct
- Atomic subroutines ATOMIC_ADD, ATOMIC_AND, ATOMIC_CAS, ATOMIC_FETCH_ADD, ATOMIC_FETCH_AND, ATOMIC_FETCH_OR, ATOMIC_FETCH_XOR, ATOMIC_OR, and ATOMIC_XOR have been implemented
- Collective subroutines CO_BROADCAST, CO_MAX, CO_MIN, CO_REDUCE, and CO_SUM have been implemented
- The SELECT RANK construct has been implemented allowing manipulation of assumed rank dummy arguments
- The compiler will now diagnose the use of nonstandard intrinsic procedures and modules as required by Fortran 2018
- Transformational intrinsic functions from the intrinsic modules ISO_C_BINDING, IEEE_ARITHMETIC, and IEEE_EXCEPTIONS are now allowed in specification expressions
- You can now specify the optional argument RADIX for the IEEE_GET_ROUNDING_MODE and IEEE_SET_ROUNDING_MODE intrinsic module procedures
- The optional ROUND argument has been added to the IEEE_RINT function in the intrinsic module IEEE_ARITHMETIC
- The intrinsic module IEEE_ARITHMETIC now includes the functions IEEE_FMA, IEEE_SIGN_BIT, IEEE_NEXT_UP and IEEE_NEXT_DOWN
- The intrinsic module procedures IEEE_MAX, IEEE_MIN, IEEE_MAX_MAG, and IEEE_MIN_MAG have been implemented
- The intrinsic module procedures IEEE_INT and IEEE_REAL have been implemented
- The intrinsic module IEEE_EXCEPTIONS now contains a new derived type, IEEE_MODES_TYPE, which can be used to save and restore the IEEE_MODES using the IEEE_GET_MODES and the IEEE_SET_MODES intrinsic module procedures
- A new rounding mode, IEEE_AWAY has been added
- SUBNORMAL is now synonymous with DENORMAL
- IEEE_QUIET_EQ, IEEE_QUIET_NE, IEEE_QUIET_LT, IEEE_QUIET_LE, IEEE_QUIET_GT, IEEE_QUIET_GE, IEEE_SIGNALING_EQ, IEEE_SIGNALING_NE, IEEE_SIGNALING_GT, IEEE_SIGNALING_GE, IEEE_SIGNALING_LT, and IEEE_SIGNALING_LE intrinsic module procedures have been implemented
The Intel Fortran Compiler has full support for the Fortran 2008 standard and includes most features from the Fortran 2018 standard.
See also
Oct 18, 2019

Just in case you find yourself needing to do some multidimensional data interpolation with modern Fortran:
- I just published a modernized version of REGRIDPACK, a library for "regriding" 1D-4D data sets using linear and spline interpolation. The original version of this library (which used to be called TLCPACK) was formerly available from the UCAR website, but it is now nowhere to be seen. It was a well-written library, and had the nice feature of being able to specify linear or spline interpolation independently for each dimension. My refactoring is simply an update of the old code to modern standards.
- I also recently added nearest neighbor interpolation to my Finterp library. So, now you can perform linear and nearest neighbor interpolation/extrapolation on 1D-6D data sets.
- My Bspline-Fortran library can also be used for interpolation/extrapolation of 1D-6D data sets using B-splines. This library is being used by several people for CFD work, it seems.
There are precious few modern Fortran libraries for other types of interpolation. Here are a couple:
- FOLLIA -- Fortran Library for Lagrange Interpolation
- curvefit -- A library for fitting functions to sets of data.
There are also any number of old school FORTRAN 77 codes out there that haven't been updated in decades, but still work fine for what they do, including:
- PCHIP -- Piecewise Cubic Hermite Interpolation Package from SLATEC.
- PPPACK -- Piecewise polynomial interpolation code from from A Practical Guide to Splines by C. de Boor.
- FITPACK -- a collection of FORTRAN programs for curve and surface fitting with splines and tensor product splines.
See also
Sep 15, 2019

I'm working on a modern Fortran version of the simulated annealing optimization algorithm, using this code as a starting point. There is a Fortran 90 version here, but this seems to be mostly just a straightforward conversion of the original code to free-form source formatting. I have in mind a more thorough modernization and the addition of some new features that I need.
Refactoring old Fortran code is always fun. Consider the following snippet:
C Check termination criteria.
QUIT = .FALSE.
FSTAR(1) = F
IF ((FOPT - FSTAR(1)) .LE. EPS) QUIT = .TRUE.
DO 410, I = 1, NEPS
IF (ABS(F - FSTAR(I)) .GT. EPS) QUIT = .FALSE.
410 CONTINUE
This can be greatly simplified to:
! check termination criteria.
fstar(1) = f
quit = ((fopt-f)<=eps) .and. (all(abs(f-fstar)<=eps)
Note that we are using some of the vector features of modern Fortran to remove the loop. Consider also this function in the original code:
FUNCTION EXPREP(RDUM)
C This function replaces exp to avoid under- and overflows and is
C designed for IBM 370 type machines. It may be necessary to modify
C it for other machines. Note that the maximum and minimum values of
C EXPREP are such that they has no effect on the algorithm.
DOUBLE PRECISION RDUM, EXPREP
IF (RDUM .GT. 174.) THEN
EXPREP = 3.69D+75
ELSE IF (RDUM .LT. -180.) THEN
EXPREP = 0.0
ELSE
EXPREP = EXP(RDUM)
END IF
RETURN
END
It is somewhat disturbing that the comments mention IBM 370 machines. This routine is unchanged in the f90 version. However, these numeric values are no longer correct for modern hardware. Using modern Fortran, we can write a totally portable version of this routine like so:
pure function exprep(x) result(f)
use, intrinsic :: ieee_exceptions
implicit none
real(dp), intent(in) :: x
real(dp) :: f
logical,dimension(2) :: flags
type(ieee_flag_type),parameter,dimension(2) :: out_of_range = [ieee_overflow,ieee_underflow]
call ieee_set_halting_mode(out_of_range,.false.)
f = exp(x)
call ieee_get_flag(out_of_range,flags)
if (any(flags)) then
call ieee_set_flag(out_of_range,.false.)
if (flags(1)) then
f = huge(1.0_dp)
else
f = 0.0_dp
end if
end if
end function exprep
This new version is entirely portable and works for any real kind. It contains no magic numbers and uses the intrinsic IEEE exceptions module of modern Fortran to protect against overflow and underflow, and the huge() intrinsic to return the largest real(dp) number.
So, stay tuned...
See also
- S. Kirkpatrick, C. D. Gelatt Jr., M. P. Vecchi, "Optimization by Simulated Annealing", Science 13 May 1983, Vol. 220, Issue 4598, pp. 671-680
- W. L. Goffe, SIMANN: A Global Optimization Algorithm using Simulated Annealing, Studies in Nonlinear Dynamics & Econometrics, De Gruyter, vol. 1(3), pages 1-9, October 1996.
- Original simann.f source code [Netlib]