stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
103 stars 28 forks source link

Psyclone fixed format support #2192

Open LonelyCat124 opened 1 year ago

LonelyCat124 commented 1 year ago

Socrates contains a number of fixed-format files which are not handled correctly by PSyclone, using the NEMO API.

fparser throws an exception on this code:

      SUBROUTINE make_block_6_1(ierr
     &  , n_band, wave_length_short, wave_length_long
     &  , l_exclude, n_band_exclude, index_exclude
     &  , n_deg_fit, t_ref_thermal, thermal_coefficient
     &  , theta_planck_tbl, l_present_6, l_planck_tbl
     &  )

This is valid fixed-format Fortran, but will cause a standard F90 compiler to raise syntax errors (e.g. godbolt with no arguments). At the moment, PSyclone also fails to parse this with this error:

Parse Error: algorithm.py:parse_fp2: Syntax error in file './make_block_6_1.f':
at line 20
>>>      SUBROUTINE make_block_6_1(ierr

Andy's suggestions here were:

  1. Either retry with fixed format is parsing fails (could be expensive) or be a bit smarter and consider the file suffix when creating the parser.
  2. Add a command line flag to PSyclone to override this and force either fixed or free formatted Fortran parsing.

At least this breaks for make_block_6_* files and perhaps also the cause of issues in disort_interface for Socrates.

LonelyCat124 commented 1 year ago

As an addendum to the original comment, its not clear what is causing the error for some files and not others. The subroutine header above causes Psyclone/fparser to fail, while this subroutine block is fine:

      SUBROUTINE write_profile(ierr
     &  , n_level, n_column_profile, i_data_group, i_data_type, profile
     &  , l_reference, n_level_ref, p_ref, z_ref
     &  , name_profile, length
     &  , nd_cdl_dimen, nd_cdl_dimen_size, nd_cdl_data, nd_cdl_var
     &  )
LonelyCat124 commented 1 year ago

This may be an fparser issue not a PSyclone bug (not 100%), I will make an issue there.

FParser issue: https://github.com/stfc/fparser/issues/420