J
james.herald
Hi. I'm writing a perl script to convert some fortran code to
IDL (at least, the statements which are easy to do). Here's
a type of conversion that I'm having trouble with:
I'd like to translate all FORTRAN like this:
dimension weight(4), xigau(4), xlim(5)
into this
weight = dblarr(4) && xigau = dblarr(4) && xlim = dblarr(5)
Here's what I have so far:
s/(dimension\s+)(\w+)(\(\d+\))/$1$2 \= dblarr$3/ig;
s/(dimension\s+.+?)(\,\s*)(\w+)(\(\d+\))/$1\&\& $3 \= dblarr$4/ig;
s/(dimension\s+)(\w+)/$2/ig;
which results in:
weight = dblarr(4)&& xigau = dblarr(4), xlim(5)
if I remove the "?" from the second statement, I get:
weight = dblarr(4), xigau(4)&& xlim = dblarr(5)
So, I'm having trouble coming up with an expression that does the
substitution for
multiple times on the same line. I could just repeat the 2nd statement
a few times,
but it seems there should be a way to do it automatically.
Any sed/awk hacks want to recommend something?
Thanks,
jim
IDL (at least, the statements which are easy to do). Here's
a type of conversion that I'm having trouble with:
I'd like to translate all FORTRAN like this:
dimension weight(4), xigau(4), xlim(5)
into this
weight = dblarr(4) && xigau = dblarr(4) && xlim = dblarr(5)
Here's what I have so far:
s/(dimension\s+)(\w+)(\(\d+\))/$1$2 \= dblarr$3/ig;
s/(dimension\s+.+?)(\,\s*)(\w+)(\(\d+\))/$1\&\& $3 \= dblarr$4/ig;
s/(dimension\s+)(\w+)/$2/ig;
which results in:
weight = dblarr(4)&& xigau = dblarr(4), xlim(5)
if I remove the "?" from the second statement, I get:
weight = dblarr(4), xigau(4)&& xlim = dblarr(5)
So, I'm having trouble coming up with an expression that does the
substitution for
multiple times on the same line. I could just repeat the 2nd statement
a few times,
but it seems there should be a way to do it automatically.
Any sed/awk hacks want to recommend something?
Thanks,
jim