@@ -1056,7 +1056,6 @@ def find_parameter_declaration(line,datatype):
1056
1056
# Remove header and spaces
1057
1057
if old_style :
1058
1058
nospace = re .sub ('\s' ,'' ,ll )
1059
- print (nospace )
1060
1059
nospace = nospace [10 :len (nospace )- 1 ]
1061
1060
datatype = " "
1062
1061
@@ -1664,6 +1663,49 @@ def declaration(self,strip_prefix,keep_classifiers):
1664
1663
1665
1664
return head ,var_decl
1666
1665
1666
+ # Cleanup a function's header and comment section
1667
+ def cleanup_comments (self ):
1668
+
1669
+ # Header description
1670
+ new_header = []
1671
+ started = False
1672
+ colonized = False
1673
+ for h in range (len (self .header )):
1674
+ l = self .header [h ].rstrip ()
1675
+ ls = l .lstrip ()
1676
+ nspaces = len (l ) - len (ls )
1677
+
1678
+ # Skip empty comment lines before start
1679
+ if (not started ) and (ls == '!' or ls == "" ):
1680
+ continue
1681
+ else :
1682
+ started = True
1683
+
1684
+ # If the function name is contained, follow a colon
1685
+ if self .old_name .upper () in ls and not colonized :
1686
+ ls = re .sub (r'\b' + self .old_name .upper ()+ r'\b' ,self .old_name .upper ()+ ":" ,ls )
1687
+ colonized = True
1688
+
1689
+ # FORD-style comment
1690
+ new_header .append (nspaces * " " + "!>" + ls [1 :])
1691
+
1692
+ self .header = new_header
1693
+
1694
+ # Cleanup a function's LAPACK-style .. comments ..
1695
+ def cleanup_double_dots (body ):
1696
+
1697
+ # Comments: remove double-dot style
1698
+ new_body = []
1699
+ for b in range (len (body )):
1700
+ new = re .sub (r'^(\s*\!\s*)\.{2}\s*([ \w]*)\s*\.{0,2}\s*$' ,r'\1\2' ,body [b ])
1701
+ if len (new )< len (body [b ]) and len (new )> 0 :
1702
+ new_body .append (new .title ())
1703
+ else :
1704
+ new_body .append (new )
1705
+
1706
+ return new_body
1707
+
1708
+
1667
1709
class Fortran_Line :
1668
1710
def __init__ (self ):
1669
1711
self .string = ""
@@ -2312,6 +2354,10 @@ def rename_source_body(Source,Sources,external_funs,prefix):
2312
2354
for j in range (len (body )):
2313
2355
body [j ] = re .sub (r' lsame\(' ,r' stdlib_lsame(' ,body [j ])
2314
2356
2357
+ # Finally, adjust comment style
2358
+ body = cleanup_double_dots (body )
2359
+
2360
+
2315
2361
return body ,dependency_list
2316
2362
2317
2363
# Replace data statements with variable assignments.
@@ -2404,8 +2450,6 @@ def replace_data_statements(Source,prefix,body):
2404
2450
m = re .match (r'data\(mm\((\d+),j\),j=(\d+),(\d+)\)/(.+)/' ,nosp )
2405
2451
2406
2452
if (not m is None ):
2407
- print (m .group (1 ))
2408
- print (m .group (4 ))
2409
2453
line = nspaces * " " + "mm(" + m .group (1 )+ "," + m .group (2 )+ ":" + m .group (3 )+ ")=[" + m .group (4 )+ "]"
2410
2454
new_body .append (line )
2411
2455
@@ -2639,7 +2683,7 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
2639
2683
initial = 'a'
2640
2684
2641
2685
INDENT = " "
2642
- DEBUG = False # file_name.startswith("sisnan ")
2686
+ DEBUG = False #file_name.startswith("caxpy ")
2643
2687
2644
2688
Procedures = []
2645
2689
@@ -2657,6 +2701,7 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
2657
2701
loop_lines = [] # Starting line where the loop is opened
2658
2702
loop_spaces = [] # Heading spaces of an open loop label
2659
2703
loop_statements = [] # Other statements for this loop were found
2704
+ header_spaces = 0
2660
2705
2661
2706
# FiLoad whole file; split by lines; join concatenation lines
2662
2707
with open (os .path .join (source_folder ,file_name ), 'r' ) as file :
@@ -2762,7 +2807,15 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
2762
2807
line = re .sub (r'\!\>' ,"" ,line )
2763
2808
line = re .sub (r'\\verbatim' ,"" ,line )
2764
2809
line = re .sub (r'=============' ,"" ,line )
2765
- if len (line )> 0 : Source .header .append ("! " + line .strip ())
2810
+
2811
+ # Ensure (constant) number of line spaces
2812
+ if len (line )> 0 :
2813
+
2814
+ ls = line .lstrip ()
2815
+ if header_spaces == 0 : header_spaces = len (line )- len (ls )
2816
+ Source .header .append ("! " + ls .rstrip ())
2817
+
2818
+
2766
2819
if DEBUG : print (Source .header [- 1 ])
2767
2820
2768
2821
@@ -2999,12 +3052,14 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
2999
3052
else :
3000
3053
if DEBUG : print ("NOT printed: " + line + " " + str (whereAt ))
3001
3054
3002
- # On function end
3055
+ # On function end, do some cleanup
3003
3056
if whereAt == Section .END :
3004
3057
3005
3058
# Data statements
3006
3059
Source .body = replace_data_statements (Source ,prefix ,Source .body )
3007
3060
3061
+ # Header
3062
+ Source .cleanup_comments ()
3008
3063
if DEBUG : print ("function " + Source .old_name + " is pure: " + str (Source .is_pure ()))
3009
3064
3010
3065
# Save source
@@ -3018,6 +3073,7 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
3018
3073
loop_lines = []
3019
3074
loop_spaces = []
3020
3075
loop_statements = []
3076
+ header_spaces = 0
3021
3077
3022
3078
3023
3079
0 commit comments