MPAS-Dev / MPAS-Model

Repository for MPAS models and shared framework releases.
238 stars 317 forks source link

Update fortprintf to support Fortran 2003 linebreaks #1103

Closed dimomatt closed 1 year ago

dimomatt commented 1 year ago

The main purpose of this pull request is to support double quote strings in the fortprintf function. This is accomplished by adding a separate check for double quotes, and also changing the style of line breaks when inside of character contexts.

This removes a lot of the logic that was required by the old Fortran 90 linebreak style. Previously, we were required to know if we were inside of and to keep track of the indices of those quotes, so that the quotes could be terminated before a multi line string could be created by concatenating two new strings together. The Fortran 2003 standard allows for character context strings to be continued by adding a leading ampersand, such as:

str = 'This is a & &string'

This allows us to not have to close quotes, and so makes the logic much simpler. We now look only for being within quotes of any kind. The line is broken at the closest space to the maximum character limit, and ended with an ampersand. If we are within quotes and therefore a character context, we lead the new line with an ampersand. If not, we carry on in the next line as normal.

Two tests were also added, and some incorrect test numbering was cleaned up in the same file.

This was confirmed to compile with the oldest available gnu and intel compilers on Cheyenne, and produces the expected output when compiled with gfortran.