Write a Python or Perl script to group variable declarations in Fortran functions and subroutines so that
(1) function or subroutine arguments appear before declarations of local variables. The function declaration itself
(the data type it returns) should appear after the argument
declarations, on its own line.
(2) within the subgroups of arguments and local variables,
declarations of variables of the same type are aggregated
when possible.
For example, the declarations
real z
integer i
integer j
real y(4)
integer k(3)
real x
can be aggregated as
integer i,j,k(3)
real z,y(4),x
A statement is a declaration in Fortran if the first word is
real, integer, character, logical, or type(foo), where "foo" can
be any word.
A 'kind' attribute of the form (kind=n) can appear after the real, integer, character, or logical keyword, and it should be regarded as part of the data type, so that
integer (kind=4) i
integer (kind=8) j
would not be aggregated
but
integer (kind=4) i
integer (kind=4) j
would be aggregated to
integer (kind=4) i,j
Do NOT aggregate any declarations for which a comment (denoted by a leading !)
appears on the same line, so
integer i
integer num_days ! number of days
integer j
would be aggregated as
integer i,j
integer num_days ! number of days
Put a comment line
! local variables
after the declaration of the function and subroutine arguments
and before declaring the local variables. More detail are in the attachment.
## Deliverables
Code that runs with Python 2.4 OR Perl 5.0.
## Platform
Windows XP, but should be written in portable Python or Perl.