crackfortran --- read fortran (77,90) code and extract declaration information.
Copyright 1999-2004 Pearu Peterson all rights reserved, Pearu Peterson <pearu@ioc.ee> Permission to use, modify, and distribute this software is given under the terms of the NumPy License.
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. $Date: 2005/09/27 07:13:49 $ Pearu Peterson
Functions: crackfortran, crack2fortran The following Fortran statements/constructions are supported (or will be if needed):
block data,byte,call,character,common,complex,contains,data, dimension,double complex,double precision,end,external,function, implicit,integer,intent,interface,intrinsic, logical,module,optional,parameter,private,public, program,real,(sequence?),subroutine,type,use,virtual, include,pythonmodule
Note: 'virtual' is mapped to 'dimension'. Note: 'implicit integer (z) static (z)' is 'implicit static (z)' (this is minor bug). Note: code after 'contains' will be ignored until its scope ends. Note: 'common' statement is extended: dimensions are moved to variable definitions Note: f2py directive: <commentchar>f2py<line> is read as <line> Note: pythonmodule is introduced to represent Python module
postlist=crackfortran(files)
postlist
contains declaration information read from the list of filesfiles
.crack2fortran(postlist)
returns a fortran code to be saved to pyf-file
postlist
has the following structure:
B['body'] --- list containing `subblocks' with the same structure as `blocks' B['parent_block'] --- dictionary of a parent block:
C['body'][<index>]['parent_block'] is C
B['vars'] --- dictionary of variable definitions B['sortvars'] --- dictionary of variable definitions sorted by dependence (independent first) B['name'] --- name of the block (not if B['block']=='interface') B['prefix'] --- prefix string (only if B['block']=='function') B['args'] --- list of argument names if B['block']== 'function' | 'subroutine' B['result'] --- name of the return value (only if B['block']=='function') B['implicit'] --- dictionary {'a':<variable definition>,'b':...} | None B['externals'] --- list of variables being external B['interfaced'] --- list of variables being external and defined B['common'] --- dictionary of common blocks (list of objects) B['commonvars'] --- list of variables used in common blocks (dimensions are moved to variable definitions) B['from'] --- string showing the 'parents' of the current block B['use'] --- dictionary of modules used in current block:
{<modulename>:{['only':<0|1>],['map':{<local_name1>:<use_name1>,...}]}}
B['note'] --- list of LaTeX comments on the block B['f2pyenhancements'] --- optional dictionary
- {'threadsafe':'','fortranname':<name>,
- 'callstatement':<C-expr>|<multi-line block>, 'callprotoargument':<C-expr-list>, 'usercode':<multi-line block>|<list of multi-line blocks>, 'pymethoddef:<multi-line block>' }
B['entry'] --- dictionary {entryname:argslist,..} B['varnames'] --- list of variable names given in the order of reading the
Fortran code, useful for derived types.
B['saved_interface'] --- a string of scanned routine signature, defines explicit interface
D = B['vars'][<variable name>] = {'typespec'[,'attrspec','kindselector','charselector','=','typename']} D['typespec'] = 'byte' | 'character' | 'complex' | 'double complex' |
'double precision' | 'integer' | 'logical' | 'real' | 'type'
D['='] --- initialization expression string D['typename'] --- name of the type if D['typespec']=='type' D['dimension'] --- list of dimension bounds D['intent'] --- list of intent specifications D['depend'] --- list of variable names on which current variable depends on D['check'] --- list of C-expressions; if C-expr returns zero, exception is raised D['note'] --- list of LaTeX comments on the variable
(Main source: IBM XL Fortran 5.1 Language Reference Manual) type declaration = <typespec> [[<attrspec>]::] <entitydecl> <typespec> = byte |
character[<charselector>] | complex[<kindselector>] | double complex | double precision | integer[<kindselector>] | logical[<kindselector>] | real[<kindselector>] | type(<typename>)
Only the following attributes are used in building up the interface:
external (parameter --- affects '=' key) optional intent
Other attributes are ignored.
<intentspec> = in | out | inout <arrayspec> = comma separated list of dimension bounds. <entitydecl> = <name> [[*<charlen>][(<arrayspec>)] | [(<arrayspec>)]*<charlen>]
[/<init_expr>/ | =<init_expr>] [,<entitydecl>]
In addition, the following attributes are used: check,depend,note
The above may be solved by creating appropriate preprocessor program, for example.
Variable | analyzeargs_re_1 |
Undocumented |
Variable | badnames |
Undocumented |
Variable | beforethisafter |
Undocumented |
Variable | beginpattern |
Undocumented |
Variable | beginpattern77 |
Undocumented |
Variable | beginpattern90 |
Undocumented |
Variable | callfunpattern |
Undocumented |
Variable | callnameargspattern |
Undocumented |
Variable | callpattern |
Undocumented |
Variable | charselector |
Undocumented |
Variable | commonpattern |
Undocumented |
Variable | containspattern |
Undocumented |
Variable | crackline_re_1 |
Undocumented |
Variable | currentfilename |
Undocumented |
Variable | datapattern |
Undocumented |
Variable | debug |
Undocumented |
Variable | defaultimplicitrules |
Undocumented |
Variable | determineexprtype_re_1 |
Undocumented |
Variable | determineexprtype_re_2 |
Undocumented |
Variable | determineexprtype_re_3 |
Undocumented |
Variable | determineexprtype_re_4 |
Undocumented |
Variable | determineexprtype_re_5 |
Undocumented |
Variable | dimensionpattern |
Undocumented |
Variable | dolowercase |
Undocumented |
Variable | endifpattern |
Undocumented |
Variable | endifs |
Undocumented |
Variable | endpattern |
Undocumented |
Variable | entrypattern |
Undocumented |
Variable | expectbegin |
Undocumented |
Variable | externalpattern |
Undocumented |
Variable | f2pyenhancementspattern |
Undocumented |
Variable | f77modulename |
Undocumented |
Variable | f90modulevars |
Undocumented |
Variable | filepositiontext |
Undocumented |
Variable | formatpattern |
Undocumented |
Variable | fortrantypes |
Undocumented |
Variable | functionpattern |
Undocumented |
Variable | getlincoef_re_1 |
Undocumented |
Variable | gotnextfile |
Undocumented |
Variable | groupbegins77 |
Undocumented |
Variable | groupbegins90 |
Undocumented |
Variable | groupcache |
Undocumented |
Variable | groupcounter |
Undocumented |
Variable | groupends |
Undocumented |
Variable | grouplist |
Undocumented |
Variable | groupname |
Undocumented |
Variable | ignorecontains |
Undocumented |
Variable | implicitpattern |
Undocumented |
Variable | include_paths |
Undocumented |
Variable | intentpattern |
Undocumented |
Variable | intrinsicpattern |
Undocumented |
Variable | invbadnames |
Undocumented |
Variable | is_f_file |
Undocumented |
Variable | kindselector |
Undocumented |
Variable | lenarraypattern |
Undocumented |
Variable | lenkindpattern |
Undocumented |
Variable | multilinepattern |
Undocumented |
Variable | nameargspattern |
Undocumented |
Variable | namepattern |
Undocumented |
Variable | neededmodule |
Undocumented |
Variable | onlyfuncs |
Undocumented |
Variable | optionalpattern |
Undocumented |
Variable | parameterpattern |
Undocumented |
Variable | previous_context |
Undocumented |
Variable | privatepattern |
Undocumented |
Variable | publicpattern |
Undocumented |
Variable | pyffilename |
Undocumented |
Variable | quiet |
Undocumented |
Variable | real16pattern |
Undocumented |
Variable | real8pattern |
Undocumented |
Variable | requiredpattern |
Undocumented |
Variable | selectpattern |
Undocumented |
Variable | skipblocksuntil |
Undocumented |
Variable | skipemptyends |
Undocumented |
Variable | skipfuncs |
Undocumented |
Variable | skipfunctions |
Undocumented |
Variable | sourcecodeform |
Undocumented |
Variable | strictf77 |
Undocumented |
Variable | subroutinepattern |
Undocumented |
Variable | tabchar |
Undocumented |
Variable | typespattern |
Undocumented |
Variable | typespattern4implicit |
Undocumented |
Variable | usepattern |
Undocumented |
Variable | usermodules |
Undocumented |
Variable | verbose |
Undocumented |
Variable | word_pattern |
Undocumented |
Function | _calc_depend_dict |
Undocumented |
Function | _ensure_exprdict |
Undocumented |
Function | _eval_length |
Undocumented |
Function | _eval_scalar |
Undocumented |
Function | _get_depend_dict |
Undocumented |
Function | _is_intent_callback |
Undocumented |
Function | _kind_func |
Undocumented |
Function | _resolvenameargspattern |
Undocumented |
Function | _selected_int_kind_func |
Undocumented |
Function | _selected_real_kind_func |
Undocumented |
Function | _simplifyargs |
Undocumented |
Function | analyzeargs |
Undocumented |
Function | analyzebody |
Undocumented |
Function | analyzecommon |
Undocumented |
Function | analyzeline |
Undocumented |
Function | analyzevars |
Undocumented |
Function | appenddecl |
Undocumented |
Function | appendmultiline |
Undocumented |
Function | buildimplicitrules |
Undocumented |
Function | common2fortran |
Undocumented |
Function | crack2fortran |
Undocumented |
Function | crack2fortrangen |
Undocumented |
Function | crackfortran |
Undocumented |
Function | crackline |
reset=-1 --- initialize reset=0 --- crack the line reset=1 --- final check if mismatch of blocks occurred |
Function | cracktypespec |
Undocumented |
Function | cracktypespec0 |
Undocumented |
Function | determineexprtype |
Undocumented |
Function | expr2name |
Undocumented |
Function | get_parameters |
Undocumented |
Function | get_sorted_names |
|
Function | get_usedict |
Undocumented |
Function | get_useparameters |
Undocumented |
Function | getblockname |
Undocumented |
Function | getextension |
Undocumented |
Function | getlincoef |
Obtain a and b when e == "a*x+b", where x is a symbol in xset. |
Function | is_free_format |
Check if file is in free format Fortran. |
Function | markinnerspaces |
The function replace all spaces in the input variable line which are surrounded with quotation marks, with the triplet "@_@". |
Function | markoutercomma |
Undocumented |
Function | markouterparen |
Undocumented |
Function | myeval |
Like eval but returns only integers and floats |
Function | outmess |
Undocumented |
Function | postcrack |
TODO: function return values determine expression types if in argument list |
Function | postcrack2 |
Undocumented |
Function | readfortrancode |
No summary |
Function | removespaces |
Undocumented |
Function | reset_global_f2py_vars |
Undocumented |
Function | rmbadname |
Undocumented |
Function | rmbadname1 |
Undocumented |
Function | setattrspec |
Undocumented |
Function | setcharselector |
Undocumented |
Function | setkindselector |
Undocumented |
Function | setmesstext |
Undocumented |
Function | sortvarnames |
Undocumented |
Function | split_by_unquoted |
Splits the line into (line[:i], line[i:]), where i is the index of first occurrence of one of the characters not within quotes, or len(line) if no such index exists |
Function | true_intent_list |
Undocumented |
Function | undo_rmbadname |
Undocumented |
Function | undo_rmbadname1 |
Undocumented |
Function | unmarkouterparen |
Undocumented |
Function | updatevars |
Undocumented |
Function | use2fortran |
Undocumented |
Function | vars2fortran |
TODO: public sub ... |
Variable | _free_f90_start |
Undocumented |
Variable | _has_f90_header |
Undocumented |
Variable | _has_f_header |
Undocumented |
Variable | _has_fix_header |
Undocumented |
Variable | _intentcallbackpattern |
Undocumented |
Variable | _is_kind_number |
Undocumented |
reset=-1 --- initialize reset=0 --- crack the line reset=1 --- final check if mismatch of blocks occurred
Cracked data is saved in grouplist[0].
Obtain a and b when e == "a*x+b", where x is a symbol in xset.
>>> getlincoef('2*x + 1', {'x'}) (2, 1, 'x') >>> getlincoef('3*x + x*2 + 2 + 1', {'x'}) (5, 3, 'x') >>> getlincoef('0', {'x'}) (0, 0, None) >>> getlincoef('0*x', {'x'}) (0, 0, 'x') >>> getlincoef('x*x', {'x'}) (None, None, None)
This can be tricked by sufficiently complex expressions
>>> getlincoef('(x - 0.5)*(x - 1.5)*(x - 1)*x + 2*x + 3', {'x'}) (2.0, 3.0, 'x')
The function replace all spaces in the input variable line which are surrounded with quotation marks, with the triplet "@_@".
For instance, for the input "a 'b c'" the function returns "a 'b@_@c'"
line : str
str