Read fortran codes from files and 1) Get rid of comments, line continuations, and empty lines; lower cases. 2) Call dowithline(line) on every line. 3) Recursively call itself when statement \"include ' '\" is met.
(ffile, dowithline=show, istop=1)
| 356 | |
| 357 | # Read fortran (77,90) code |
| 358 | def readfortrancode(ffile, dowithline=show, istop=1): |
| 359 | """ |
| 360 | Read fortran codes from files and |
| 361 | 1) Get rid of comments, line continuations, and empty lines; lower cases. |
| 362 | 2) Call dowithline(line) on every line. |
| 363 | 3) Recursively call itself when statement \"include '<filename>'\" is met. |
| 364 | """ |
| 365 | global gotnextfile, filepositiontext, currentfilename, sourcecodeform, strictf77 |
| 366 | global beginpattern, quiet, verbose, dolowercase, include_paths |
| 367 | |
| 368 | if not istop: |
| 369 | saveglobals = gotnextfile, filepositiontext, currentfilename, sourcecodeform, strictf77,\ |
| 370 | beginpattern, quiet, verbose, dolowercase |
| 371 | if ffile == []: |
| 372 | return |
| 373 | localdolowercase = dolowercase |
| 374 | # cont: set to True when the content of the last line read |
| 375 | # indicates statement continuation |
| 376 | cont = False |
| 377 | finalline = '' |
| 378 | ll = '' |
| 379 | includeline = re.compile( |
| 380 | r'\s*include\s*(\'|")(?P<name>[^\'"]*)(\'|")', re.I) |
| 381 | cont1 = re.compile(r'(?P<line>.*)&\s*\Z') |
| 382 | cont2 = re.compile(r'(\s*&|)(?P<line>.*)') |
| 383 | mline_mark = re.compile(r".*?'''") |
| 384 | if istop: |
| 385 | dowithline('', -1) |
| 386 | ll, l1 = '', '' |
| 387 | spacedigits = [' '] + [str(_m) for _m in range(10)] |
| 388 | filepositiontext = '' |
| 389 | fin = fileinput.FileInput(ffile, openhook=openhook) |
| 390 | while True: |
| 391 | try: |
| 392 | l = fin.readline() |
| 393 | except UnicodeDecodeError as msg: |
| 394 | raise Exception( |
| 395 | f'readfortrancode: reading {fin.filename()}#{fin.lineno()}' |
| 396 | f' failed with\n{msg}.\nIt is likely that installing charset_normalizer' |
| 397 | ' package will help f2py determine the input file encoding' |
| 398 | ' correctly.') |
| 399 | if not l: |
| 400 | break |
| 401 | if fin.isfirstline(): |
| 402 | filepositiontext = '' |
| 403 | currentfilename = fin.filename() |
| 404 | gotnextfile = 1 |
| 405 | l1 = l |
| 406 | strictf77 = 0 |
| 407 | sourcecodeform = 'fix' |
| 408 | ext = os.path.splitext(currentfilename)[1] |
| 409 | if Path(currentfilename).suffix.lower() in COMMON_FIXED_EXTENSIONS and \ |
| 410 | not (_has_f90_header(l) or _has_fix_header(l)): |
| 411 | strictf77 = 1 |
| 412 | elif is_free_format(currentfilename) and not _has_fix_header(l): |
| 413 | sourcecodeform = 'free' |
| 414 | if strictf77: |
| 415 | beginpattern = beginpattern77 |
no test coverage detected
searching dependent graphs…