| 138 | f2cmap_mapped = [] |
| 139 | |
| 140 | def load_f2cmap_file(f2cmap_file): |
| 141 | global f2cmap_all, f2cmap_mapped |
| 142 | |
| 143 | f2cmap_all = copy.deepcopy(f2cmap_default) |
| 144 | |
| 145 | if f2cmap_file is None: |
| 146 | # Default value |
| 147 | f2cmap_file = '.f2py_f2cmap' |
| 148 | if not os.path.isfile(f2cmap_file): |
| 149 | return |
| 150 | |
| 151 | # User defined additions to f2cmap_all. |
| 152 | # f2cmap_file must contain a dictionary of dictionaries, only. For |
| 153 | # example, {'real':{'low':'float'}} means that Fortran 'real(low)' is |
| 154 | # interpreted as C 'float'. This feature is useful for F90/95 users if |
| 155 | # they use PARAMETERS in type specifications. |
| 156 | try: |
| 157 | outmess(f'Reading f2cmap from {f2cmap_file!r} ...\n') |
| 158 | with open(f2cmap_file) as f: |
| 159 | d = eval(f.read().lower(), {}, {}) |
| 160 | f2cmap_all, f2cmap_mapped = process_f2cmap_dict(f2cmap_all, d, c2py_map, True) |
| 161 | outmess('Successfully applied user defined f2cmap changes\n') |
| 162 | except Exception as msg: |
| 163 | errmess(f'Failed to apply user defined f2cmap changes: {msg}. Skipping.\n') |
| 164 | |
| 165 | |
| 166 | cformat_map = {'double': '%g', |