How can I comment a piece of code? 
Author Message
 How can I comment a piece of code?

Is there a way in fortran 90 to comment a large piece of code using something like /* */ of
C? It's very annoying to have to put ! on each line I like to comment :-S

I'm using CVF for the development.

Thanks a lot for your help

--
Atte.
lvaro Palma Aste
******************************************************
It's the only form of protest they're allowed
I've seen their silent faces scream so loud
If they were to speak these words they'd go missing too
Another woman on a torture table what else can they do

Sting - They Dance Alone (Cueca Sola)...

30 a?os, ni perdn ni olvido, JUSTICIA!



Sun, 16 Jul 2006 04:20:12 GMT  
 How can I comment a piece of code?

Quote:
> Is there a way in Fortran 90 to comment a large piece of code using
> something like /* */ of C?

No.

I'll skip the explanations of why many people think that a bad idea.
Instead, I'll just stick to the facts.

You can get a similar effect using preprocessor constructs, assuming
that the compiler you are using supports a preprocessor (or you
run one before invoking the compiler).

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Sun, 16 Jul 2006 05:11:54 GMT  
 How can I comment a piece of code?

Quote:

> Is there a way in Fortran 90 to comment a large piece of code using
> something like /* */ of C? It's very annoying to have to put ! on each
> line I like to comment :-S

> I'm using CVF for the development.

In general, productivity experiments have shown that such block
comments are detrimental to productivity and that languages shouldn't
allow them.  A conditional compilation tool is a better means of
eliding code.  It can then be turned on again by setting a flag for
the preprocessor - without changing the code itself.  CVF has a
preprocessor that works similarly to the C preprocessor.  It has
ifdefs and other such facilities.  There is a Fortran standard
preprocessor called COCO which you could find on the internet.
Its implementations are written in (fairly portable) Fortran, and
so, it will work just about anywhere your Fortran is likely to
be ported.

--
J. Giles



Sun, 16 Jul 2006 05:27:30 GMT  
 How can I comment a piece of code?


|
| > Is there a way in Fortran 90 to comment a large piece of code using
| > something like /* */ of C?
| You can get a similar effect using preprocessor constructs, assuming
| that the compiler you are using supports a preprocessor (or you
| run one before invoking the compiler).

a decent editor will also comment/uncomment large blocks of code for
you. Emacs for instance comments out the current block with the keystroke
"C-c ;"

--
Helge



Sun, 16 Jul 2006 06:15:21 GMT  
 How can I comment a piece of code?

Quote:


>>Is there a way in Fortran 90 to comment a large piece of code using
>>something like /* */ of C?

(snip)

Quote:
> You can get a similar effect using preprocessor constructs, assuming
> that the compiler you are using supports a preprocessor (or you
> run one before invoking the compiler).

That is still the best solution in C.

C comments don't nest, so you can't comment out a large piece of
code that contains comments using /* and */.  You can with

#if 0   and   #endif

-- glen



Sun, 16 Jul 2006 06:26:06 GMT  
 How can I comment a piece of code?

|| Is there a way in Fortran 90 to comment a large piece of code using
|| something like /* */ of C? It's very annoying to have to put ! on each
|| line I like to comment :-S
||
|| I'm using CVF for the development.
|
| In general, productivity experiments have shown that such block
| comments are detrimental to productivity and that languages shouldn't
| allow them.  A conditional compilation tool is a better means of
| eliding code.  It can then be turned on again by setting a flag for
| the preprocessor - without changing the code itself.  CVF has a
| preprocessor that works similarly to the C preprocessor.  It has
| ifdefs and other such facilities.

The CVF-specific preprocessor syntax is

!DEC$IF (condition)
...
[!DEC$ELSE]
...
!DEC$ENDIF

where <condition> is a compile-time evaluable expression. It's not
portable, so it should be avoided, but it's quite useful during
development. For example, you can "comment out" a block of code using

!DEC$IF (.FALSE.)
...
!DEC$ENDIF

or, if you're trying to rewrite/speed up a piece of code, you can
write something like:

!DEC$DEFINE (ATTEMPT)
...
!DEC$IF DEFINED(ATTEMPT)
<new faster code you're testing and want to reproduce old result>
!DEC$ELSE
<old, (almost) working code >
!DEC$ENDIF

To switch from one to another, just comment out the DEFINE line.
(!DEC$ is not really a comment; !!DEC$ is).

--
 Jugoslav
___________
www.geocities.com/jdujic



Sun, 16 Jul 2006 16:41:27 GMT  
 How can I comment a piece of code?

Quote:


...
>> [...]       CVF has a
>> preprocessor that works similarly to the C preprocessor.  It has
>> ifdefs and other such facilities.

> The CVF-specific preprocessor syntax is

> !DEC$IF (condition)
> ...
> [!DEC$ELSE]
> ...
> !DEC$ENDIF

> where <condition> is a compile-time evaluable expression. It's not
> portable, so it should be avoided, but it's quite useful during
> development. For example, you can "comment out" a block of code using

According to the CVF document, it also comes with an implementation
of the cpp-like preprocessor fpp:

    FPP is a modified version of the ANSI C preprocessor and supports
    a similar set of directives (including syntax and semantics). It supports
    the following directives: #define, #elif, #else, #endif, #if, #ifdef,
#ifndef,
    #include, and #undef.

The fpp syntax is rather more portable than the CVF-specific preprocessor.
COCO is still the _standard_ Fortran preprocessor.

--
J. Giles



Sun, 16 Jul 2006 17:19:46 GMT  
 How can I comment a piece of code?


Quote:
>Is there a way in Fortran 90 to comment a large piece of code using
>something like /* */ of
>C? It's very annoying to have to put ! on each line I like to comment :-S

>I'm using CVF for the development.

>Thanks a lot for your help

As others have pointed out, you can't do this. However, you can very
quickly simulate it in standard Fortran (if you're just debugging, for
instance) by surrounding the block with

IF (.FALSE.)

ENDIF

Or if you want to take out the body or end of a subroutine you can just
add a RETURN.

If I resort to this, I always put in the same comment with my initials
just before the inserted bit which says REMOVE THIS. Then I can easily
check at testing time by doing a global string search that I haven't
left anything in by mistake.

HTH,

Catherine.
--
Catherine Rees Lay
To email me, use my first name in front of the "at".



Sun, 16 Jul 2006 17:47:01 GMT  
 How can I comment a piece of code?

Quote:
> IF (.FALSE.)

> ENDIF

I thought of mentioning this.  I've seen it on occasion.  On very
rare occasion I've even used it myself; can't recall when I last
did, but it has certainly happened.

I'm sure that Catherine is aware of a point that is "obvious", but
that I've seen people overlook.  More than once....

With this approach, the code isn't executed, but it does still have
to compile.  There are lots of ways that can cause problems.
Things in the "commented out" part better be used in ways consistent
with their declarations.  Better not have statement numbers in
there that duplicate statement numbers elsewhere (I don't use many
statement numbers any more, but some people do).  Better not goto
any statement numbers in there from places outside of there.
Doesn't work at all with declarations, etc., etc., etc.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Mon, 17 Jul 2006 00:01:50 GMT  
 How can I comment a piece of code?


Quote:
>As others have pointed out, you can't do this. However, you can very
>quickly simulate it in standard Fortran (if you're just debugging, for
>instance) by surrounding the block with

>IF (.FALSE.)

>ENDIF

Another side effect of this is linking: at no or low optimization, a
lot of compilers are not going to do dead-code elimination, so any
calls inside this block have to be linked in. The NAS Parallel
Benchmarks are an example of this -- there's a missing symbol if you
compile with the pathscale compilers at -O0, because we only eliminate
dead code at -O1 and higher.

-- greg
employed by, not speaking for, pathscale



Mon, 17 Jul 2006 01:57:09 GMT  
 How can I comment a piece of code?


Quote:

>> IF (.FALSE.)

>> ENDIF

>I thought of mentioning this.  I've seen it on occasion.  On very
>rare occasion I've even used it myself; can't recall when I last
>did, but it has certainly happened.

>I'm sure that Catherine is aware of a point that is "obvious", but
>that I've seen people overlook.  More than once....

>With this approach, the code isn't executed, but it does still have
>to compile.  There are lots of ways that can cause problems.
>Things in the "commented out" part better be used in ways consistent
>with their declarations.  Better not have statement numbers in
>there that duplicate statement numbers elsewhere (I don't use many
>statement numbers any more, but some people do).  Better not goto
>any statement numbers in there from places outside of there.
>Doesn't work at all with declarations, etc., etc., etc.

Must admit I hadn't thought of any of them - but then I do only ever use
it for debugging purposes, so I already know it compiles and links.

If it doesn't compile, what I sometimes do if faced with a large routine
(which I don't understand and the error messages are overwhelming) is to
start with a new file containing an empty copy of the routine and
gradually add chunks of the old one. This is a better aid to getting to
understand the code IMO than commenting bits out, because you can see
the structure better. Sometimes this works better than others: it's
harder with nested loops.

Catherine.
--
Catherine Rees Lay
To email me, use my first name in front of the "at".



Mon, 17 Jul 2006 17:28:56 GMT  
 How can I comment a piece of code?


Quote:
>As others have pointed out, you can't do this. However, you can very
>quickly simulate it in standard Fortran (if you're just debugging, for
>instance) by surrounding the block with

>IF (.FALSE.)

>ENDIF

The first line should be IF (.FALSE.) THEN

John Harper, School of Mathematical and Computing Sciences,
Victoria University, PO Box 600, Wellington, New Zealand



Tue, 18 Jul 2006 04:31:39 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Need a piece of code...

2. Help with piece of code

3. Very nasty piece of code

4. code from "Lisp in Small Pieces"

5. piece of code

6. Interesting piece of code

7. Fast Additive Shading - A Piece of x86 Assembly Code

8. question about piece of code

9. piece of code

10. small piece of code

11. Performance monitoring a specific piece of code

12. WANTED: small piece of source code !!!!

 

 
Powered by phpBB® Forum Software