Check if file is in free format Fortran.
(file)
| 982 | _free_f90_start = re.compile(r'[^c*!]\s*[^\s\d\t]', re.I).match |
| 983 | |
| 984 | def is_free_format(file): |
| 985 | """Check if file is in free format Fortran.""" |
| 986 | # f90 allows both fixed and free format, assuming fixed unless |
| 987 | # signs of free format are detected. |
| 988 | result = 0 |
| 989 | with open(file, encoding='latin1') as f: |
| 990 | line = f.readline() |
| 991 | n = 10000 # the number of non-comment lines to scan for hints |
| 992 | if _has_f_header(line) or _has_fix_header(line): |
| 993 | n = 0 |
| 994 | elif _has_f90_header(line): |
| 995 | n = 0 |
| 996 | result = 1 |
| 997 | while n>0 and line: |
| 998 | line = line.rstrip() |
| 999 | if line and line[0]!='!': |
| 1000 | n -= 1 |
| 1001 | if (line[0]!='\t' and _free_f90_start(line[:5])) or line[-1:]=='&': |
| 1002 | result = 1 |
| 1003 | break |
| 1004 | line = f.readline() |
| 1005 | return result |
| 1006 | |
| 1007 | def has_f90_header(src): |
| 1008 | with open(src, encoding='latin1') as f: |