Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Fortran Programming Language

utility to replace "end" with "end subroutine foo"


Has anyone written a utility to replace "end" statements with "end
program/subroutine/function" statements as appropriate? When I use
someone else's Fortran code one of the first things I want to do is
put it in a module, but this does not work if plain "end" statements
are present.

"Beliavsky" <beliav@aol.com> wrote in message

news:1177699661.529939.195410@r3g2000prh.googlegroups.com...
> Has anyone written a utility to replace "end" statements with "end
> program/subroutine/function" statements as appropriate? When I use
> someone else's Fortran code one of the first things I want to do is
> put it in a module, but this does not work if plain "end" statements
> are present.

Maybe not what you want, but convert.f90 does it when converting from fixed-
to free-form source.

Regards,

Mike Metcalf

Beliavsky wrote:
> Has anyone written a utility to replace "end" statements with "end
> program/subroutine/function" statements as appropriate? When I use
> someone else's Fortran code one of the first things I want to do is
> put it in a module, but this does not work if plain "end" statements
> are present.

The f90-mode in emacs does this when you hit 'tab' over the statement. Being
emacs, I'm sure there's an (arcane, lisp) way to call the function that does
this, for the entire file.

cheers,

Rich

Just write it yourself.

O.k. maybe is not the easiest thing in fortran, it gets a little
easier in C and of course it does not get any easier when using one of
those scripting languages like tcl, perl, python...

If all you know if fortran, and possibly not all that well, here is a
learning opportunity for you, it would be a nice simple exercise.

gsal

Rich Townsend wrote:
> Beliavsky wrote:
>> Has anyone written a utility to replace "end" statements with "end
>> program/subroutine/function" statements as appropriate?
[...]
> The f90-mode in emacs does this when you hit 'tab' over the statement.
> Being emacs, I'm sure there's an (arcane, lisp) way to call the
> function that does this, for the entire file.

Being Emacs, if there isn't already a way, there can be:

(defun f90-match-all-ends (beg end)
  "Qualify all ENDs in the region."
  (interactive "*r")
  (save-excursion
    (goto-char end)
    (setq end (point-marker))
    (goto-char beg)
    (let ((f90-smart-end 'noblink))
      (while (re-search-forward "^[ \t0-9]*end" end t)
        (goto-char (line-beginning-position))
        (skip-chars-forward " \t0-9")
        (when (f90-looking-at-program-block-end)
          (f90-match-end))))))

Interactively:

C-x h
M-x f90-match-all-ends

Batch-mode:

Save the above definition to a file foo.el, then

emacs -batch --no-site-file -l f90 -l ./foo.el \
  --eval '(progn (find-file "code.f90")
  (f90-match-all-ends (point-min) (point-max))
  (write-file "code_end.f90"))'

salger@gmail.com (gsal) wrote in <1177724457.176154.253290
@h2g2000hsg.googlegroups.com>:

>Just write it yourself.

>O.k. maybe is not the easiest thing in fortran, it gets a little
>easier in C and of course it does not get any easier when using one of
>those scripting languages like tcl, perl, python...

It doesn't? I'm pretty fluent in Fortran, C and TCL, and I would write this one in TCL every
time!

gsal wrote:
> O.k. maybe is not the easiest thing in fortran, it gets a little
> easier in C and of course it does not get any easier when using one of
> those scripting languages like tcl, perl, python...

If you simplify the problem somewhat, good enough for the programs
it is likely to be used for, it isn't bad.  No continuation between
the beginning of the subroutine statement and the end of the
name, no continued END statements.

I offer this in awk, which didn't take long at all.

/^ *subroutine / {
     x=$2
     sub("\\(.*$","",x)
     }

/^ *function / {
     x=$2
     sub("\\(.*$","",x)
     }

/^ *end *$/ {
    sub(" *$","")
    print $0, x
    }

-- glen

On Apr 28, 5:49 am, g@sfuu.ca (Ian Gay) wrote:

> salger@gmail.com (gsal) wrote in <1177724457.176154.253290
> @h2g2000hsg.googlegroups.com>:

> >Just write it yourself.

> >O.k. maybe is not the easiest thing in fortran, it gets a little
> >easier in C and of course it does not get any easier when using one of
> >those scripting languages like tcl, perl, python...

> It doesn't? I'm pretty fluent in Fortran, C and TCL, and I would write this one in TCL every
> time!

Yeah, that's what I meant...my typo...I meant to say "it does not get
any easier THAN when using tcl..."  or something along those lines,
you know what I mean, now.  And, yes, I would do it in tcl, too.

Bah, a real programmer would use Intercal. You youngsters, you....

Rich Townsend wrote:
> ...
> Bah, a real programmer would use Intercal. You youngsters, you....

Or TECO.

W.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc