Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fparser failing to handle inline array declaration in reshape (maybe?) #421

Open
LonelyCat124 opened this issue Jun 27, 2023 · 0 comments
Open

Comments

@LonelyCat124
Copy link

One of the Socrates files has some unusual (at least to me) array syntax involving symbols from other modules, and fparser is failing to handle it correctly.

fparser call and errors:

>>> from fparser.two.parser import ParserFactory
>>> from fparser.common.readfortran import FortranFileReader
>>> parser = ParserFactory().create(std="f2008")
>>> reader = FortranFileReader("aerosol_model_pcf.f90", include_dirs=".")
>>> parser(reader)
Traceback (most recent call last):
  File "/home/achalk/LFRIC/LFRIC_env/lib64/python3.6/site-packages/fparser/two/Fortran2003.py", line 266, in __new__
    return Base.__new__(cls, string)
  File "/home/achalk/LFRIC/LFRIC_env/lib64/python3.6/site-packages/fparser/two/utils.py", line 487, in __new__
    raise NoMatchError(errmsg)
fparser.two.utils.NoMatchError: at line 68
>>>    (/ NPD_aerosol_component, NPD_aerosol_model /) )


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/achalk/LFRIC/LFRIC_env/lib64/python3.6/site-packages/fparser/two/Fortran2003.py", line 270, in __new__
    raise FortranSyntaxError(string, "")
fparser.two.utils.FortranSyntaxError: at line 68
>>>    (/ NPD_aerosol_component, NPD_aerosol_model /) )

Source file declaration:

  REAL  (RealK), Parameter, &
    Dimension(NPD_aerosol_component, NPD_aerosol_model) :: &
    fraction_component = RESHAPE( (/ &
    0.61_RealK, 0.17_RealK, 0.0_RealK, 0.22_RealK, 0.0_RealK, 0.0_RealK, &
      (0.0_RealK, im=1,NPD_aerosol_component-6) &
    0.29_RealK, 0.70_RealK, 0.0_RealK, 0.01_RealK, 0.0_RealK, 0.0_RealK, &
      (0.0_RealK, im=1,NPD_aerosol_component-6) &
    0.05_RealK, 0.0_RealK, 0.95_RealK, 0.0_RealK, 0.0_RealK, 0.0_RealK, &
      (0.0_RealK, im=1,NPD_aerosol_component-6) &
    0.0_RealK, 0.0_RealK, 0.0_RealK, 0.0_RealK, 0.0_RealK, 1.0_RealK, &
      (0.0_RealK, im=1,NPD_aerosol_component-6) &
    0.0_RealK, 0.0_RealK, 0.0_RealK, 0.0_RealK, 1.0_RealK, 0.0_RealK, &
      (0.0_RealK, im=1,NPD_aerosol_component-6) &
    0.0_RealK, 0.0_RealK, 0.0_RealK, 0.0_RealK, 0.0_RealK, 1.0_RealK, &
      (0.0_RealK, im=1,NPD_aerosol_component-6) /), &
    (/ NPD_aerosol_component, NPD_aerosol_model /) )

NPD_aerosol_model is a parameter declared in this file (6), realK is defined in realtype_rd and NPD_aerosol_complonent is a parameter defined in rad_pcf - both readltype_rd and rad_pcf are USEd by this fortran file. The sceond argument to reshape is an array which is defined here inline - perhaps causing the failure?

@LonelyCat124 LonelyCat124 changed the title fparser failing to handle unusual array declaration syntax involving symbols from other modules fparser failing to handle inline array declaration in reshape (maybe?) Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant