|
|
 |
 |
 |
 |
Fortran Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
conversion of floating point constants
I have some f77 codes that I would like to update to f90. This will include replacing common blocks with modules, putting subroutines into modules, and so on. One of the tasks that I need to do is to replace double precision floating point constants with the same constant specified with an "e" format and appended with a kind parameter. For example, I would like to change the expression a = c*1.2345678901234d-9+d to a = c*1.2345678901234e-9_wp+d I need to do this in thousands of lines of code in expressions, actual arguments to subprograms, parameter statements, and data statements. This needs to work for all possible floating point constants (with and without a leading sign, with and without a decimal point, etc.). Is there a tool that does this already? If not, does someone have a perl script that does this? I can get close with a home grown perl script, but it is tricky to cover all the possible formats while ignoring all of the things that sort of look like floating point values but aren't, so I don't want to reinvent a wheel if there is a well-tested one already out there somewhere. $.02 -Ron Shepard
Kedit: arb on $ cha /$d-9+d/$e-9_wp+d/ * * Skip On Tue, 22 May 2007 23:58:37 -0500, Ron Shepard <ron-shep @NOSPAM.comcast.net> wrote: -|I have some f77 codes that I would like to update to f90. This will -|include replacing common blocks with modules, putting subroutines -|into modules, and so on. One of the tasks that I need to do is to -|replace double precision floating point constants with the same -|constant specified with an "e" format and appended with a kind -|parameter. For example, I would like to change the expression -| -| a = c*1.2345678901234d-9+d -| -|to -| -| a = c*1.2345678901234e-9_wp+d -| -|I need to do this in thousands of lines of code in expressions, -|actual arguments to subprograms, parameter statements, and data -|statements. This needs to work for all possible floating point -|constants (with and without a leading sign, with and without a -|decimal point, etc.). -| -|Is there a tool that does this already? If not, does someone have a -|perl script that does this? I can get close with a home grown perl -|script, but it is tricky to cover all the possible formats while -|ignoring all of the things that sort of look like floating point -|values but aren't, so I don't want to reinvent a wheel if there is a -|well-tested one already out there somewhere. -| -|$.02 -Ron Shepard
On May 23, 7:59 am, Herman D. Knoble <SkipKnobleL@SPAMpsu.DOT.edu> wrote: > Kedit: > arb on $ > cha /$d-9+d/$e-9_wp+d/ * *
... d_new = d_old-9+d becomes...??? Don't know/have a good tool for the general purpose but brings back terrible memories of assigning the similar task to a summer intern during conversion of a huge code from CDC to DEC machine ages ago. A TECO macro changed all "E" to "D" throughout amongst other things w/o creating a backup of the file(s) before submitting the job (which took most of the night shift on the old DEC-10). Needless to say, it turned out more effective to simply start the project over again despite two months of effort wasted... :(
In article <oje85358ohf180lpm8rrltehpnn31tp@4ax.com>, Herman D. Knoble <SkipKnobleL@SPAMpsu.DOT.edu> wrote: > Kedit: > arb on $ > cha /$d-9+d/$e-9_wp+d/ * *
Thanks, but that only changes that one expression I gave as an example. What I want is a tool that appends "_wp" to all floating point constants, and only to floating point constants, in all the many ways that floating point constants can be written. I also want to change the "d" exponents to "e" exponents. Also, if a constant happens to already end with "_wp" or some other kind parameter because someone manually edited one already, then I don't want to append another one. If a variable or expression happens to look like a floating point constant (e.g. the variable A1234d0 or the expression A1234d-9), then I don't want to modify those. Since this is fixed-format f77 code that I'm starting with, there may be oddball whitespace and continuation line cases that might need to be handled, although I hope there aren't too many of those, so I could probably do those by hand if the tool could just point them out to me. People have been converting legacy f77 code to f90 for over 15 years now, so I expect there are well-tested conversion tools, editor scripts, perl scripts, etc. out there that do this correctly. > -|I need to do this in thousands of lines of code in expressions, > -|actual arguments to subprograms, parameter statements, and data > -|statements. This needs to work for all possible floating point > -|constants (with and without a leading sign, with and without a > -|decimal point, etc.). > -| > -|Is there a tool that does this already? If not, does someone have a > -|perl script that does this? I can get close with a home grown perl > -|script, but it is tricky to cover all the possible formats while > -|ignoring all of the things that sort of look like floating point > -|values but aren't, so I don't want to reinvent a wheel if there is a > -|well-tested one already out there somewhere.
$.02 -Ron Shepard
In case anyone else is interested, here is what I'm using so far. This is a homegrown perl script with a one-line substitution, and it doesn't handle all possible cases that might arise in f77, but it takes care of the common ones. $.02 -Ron Shepard ===================== $ cat fp_convert.pl #!/usr/bin/perl # usage: fp_convert.pl <infile >outfile # or fp_convert.pl infile1 [infile2...] >appendfile # replace all floating point constants written with a d exponent with # the equivalent e exponent form with trailing _wp. # matched forms include: # 123d99 # 123.d99 # 123.456d99 # .123d99 # with optional leading sign and optional exponent sign. # embedded spaces and continuation line breaks are not allowed. # 22-May-2007 -Ron Shepard while (<>) { s/\b([+-]?(?:\d+(?:\.\d*)?|\.\d+))([dD])([+-]?\d+)/\1e\3_wp/g; print;
}
|
 |
 |
 |
 |
|