For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2005 > source line count









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author source line count
Al

2005-05-18, 4:00 pm

I would like to know the number of lines of source code in all of our
fortran files. For C/C++/Java, a quick and dirty method is to count
the number of semi-colons. For Fortran, would counting all the lines
in a file except blank lines or lines that start with c or ! be
sufficient?

beliavsky@aol.com

2005-05-18, 4:00 pm

Al wrote:
> I would like to know the number of lines of source code in all of our
> fortran files. For C/C++/Java, a quick and dirty method is to count
> the number of semi-colons. For Fortran, would counting all the lines
> in a file except blank lines or lines that start with c or ! be
> sufficient?


No -- one reason is that for free format Fortran code, 'c' and 'C' do
not have special significance, and

c = 1.2

is valid code. For fixed source form, 'c' or 'C' designate a comment
only when they appear in the first column.

Duane Bozarth

2005-05-18, 4:00 pm

beliavsky@aol.com wrote:
>
> Al wrote:
>
> No -- one reason is that for free format Fortran code, 'c' and 'C' do
> not have special significance, and
>
> c = 1.2
>
> is valid code. For fixed source form, 'c' or 'C' designate a comment
> only when they appear in the first column.


It would be reasonably close if for fixed form you checked for comment
character in column 1 and for free form if you check it is the first
character on a line.

What to do about continuation lines is a question--whether you care to
that level of detail or not.

I've not checked, but do any of the source analysis or pretty-printer
tools provide that as a metric?
Richard E Maine

2005-05-18, 4:00 pm

In article <1116429758.187960.196760@g49g2000cwa.googlegroups.com>,
"Al" <allelopath@hotmail.com> wrote:

> I would like to know the number of lines of source code in all of our
> fortran files. For C/C++/Java, a quick and dirty method is to count
> the number of semi-colons. For Fortran, would counting all the lines
> in a file except blank lines or lines that start with c or ! be
> sufficient?


I assume you are talking about counting statements instead of lines.
Counting lines is independent of the language (and is quite simple).

As for counting statements, no that won't get a precise answer. It
neglects continuation lines and multiple statements on a line.

If you want a quick and easy rough answer, you can probably neglect the
multiple statements on a line. It would be quite surprising if a large
code used enough of these to be a significant percentage. (Unless it has
been processed by a deliberate source-code obfuscator, but one doesn't
usually apply this kind of code metric to intentionally obfuscated code).

Continuation lines are another matter. They are a small fraction in some
programs. But there certainly exist large programs with zillions of
continuation lines (often things like long data statements), where the
fraction is non-negligible. Subtracting out the continuation lines
isn't too hard though, but it does depend on fixed vs free source form.

For fixed source form, continuation lines have something other than
blank or zero in column 6 (and are not comment lines, which you
previously took out, but be sure not to subtract them twice if a comment
line has something in column 6). For free source form. Hmm, it isn't
exactly hard, but it doesn't work out quite as simply. You are looking
for the last non-blank character on a line being an ampersand, but you
have to also allow for the possibility of trailing comments. Getting it
100% right probably requires some work because you can't be completely
naive about looking for & and ! characters (they might be in quoted
strings or, heaven forbid, Holleriths). But getting close is probably
pretty simple.

P.S. Counting semicolons isn't right for C/C++/Java either if you want
it exact. You will get screwed up by semicolons in comments. And I
*HAVE* (fairly often, in fact) seen C comment styles that use semicolons
for boxing like

/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;
;; This is a comment ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;
*/

That would screw your algorithm pretty badly.

--
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
David Flower

2005-05-18, 4:00 pm

If you're doing this, why not calculate a second metric:

Excluding blank lines (and comment lines blank except for column 1):

The ratio of the number of comment lines to the total number of lines.

Could prove instructive

Janne Blomqvist

2005-05-18, 8:58 pm

In article <1116429758.187960.196760@g49g2000cwa.googlegroups.com>, Al wrote:
> I would like to know the number of lines of source code in all of our
> fortran files. For C/C++/Java, a quick and dirty method is to count
> the number of semi-colons. For Fortran, would counting all the lines
> in a file except blank lines or lines that start with c or ! be
> sufficient?


Slightly OT: You might want to check out sloccount
(http://www.dwheeler.com/sloccount/), "a set of tools for counting
physical Source Lines of Code (SLOC)".


--
Janne Blomqvist
Duane Bozarth

2005-05-18, 8:58 pm

Duane Bozarth wrote:
.....
> I've not checked, but do any of the source analysis or pretty-printer
> tools provide that as a metric?


I just looked and Understand for Fortran from STI (Scientific Toolworks,
Inc., http://www.scitools.com/) does the following w/ a sample project
from the CVF Win32 Samples directory--


Project Metrics Summary Report
========================================
=======================================
Files: 3
Lines: 297
Blank Lines: 34
Code Lines: 155
Comment Lines: 108
Declaration Statements: 42
Execution Statements: 102
Percent Comment: 69%

File Metrics
========================================
=======================================

COL2.F90
Lines: 25
Blank Lines: 2
Code Lines: 8
Comment Lines: 15
Execution Statements: 2
Declaration Statements: 6
Mains/Subprograms: 1
Avg. Complexity: 2
Avg. Complexity/Case 1: 2
Percent Comment: 187%

COLOR.F90
Lines: 255
Blank Lines: 26
Code Lines: 142
Comment Lines: 87
Execution Statements: 100
Declaration Statements: 31
Mains/Subprograms: 8
Avg. Complexity: 3
Avg. Complexity/Case 1: 3
Percent Comment: 61%

COLORIN.F90
Lines: 17
Blank Lines: 6
Code Lines: 5
Comment Lines: 6
Execution Statements: 0
Declaration Statements: 5
Mains/Subprograms: 1
Avg. Complexity: 1
Avg. Complexity/Case 1: 1
Percent Comment: 120%
mcalhoun@ksu.edu

2005-05-18, 8:58 pm

>If you're doing this, why not calculate a second metric:
>Excluding blank lines (and comment lines blank except for column 1):
>The ratio of the number of comment lines to the total number of lines.
>Could prove instructive


'Way back in 1987 I wrote a simple "analyzer" for FORTRAN programs
(by "simple" I mean its parser was written for my style of coding and
was NOT a general-purpose FORTRAN parser). I just executed it on itself:

C:> ANALYZE < ANALYZE.FOR

and got the following results:

METACOMMAND= INCLUDE 'FORparse.INC'
METACOMMAND= INCLUDE 'KeyWords.INC'
UNKNOWN=DEBUG
METACOMMAND= INCLUDE 'FORparse.INC'
METACOMMAND= INCLUDE 'KeyWords.INC'
METACOMMAND= INCLUDE 'FORparse.INC'

Analysis completed: There were a total of 500 lines:
1 UNKNOWN 87 BLANK 150 COMMENT
86 ASSIGNMENT 30 CONTINUATION 5 METACOMMAND
70 CONTROL 45 INPUT/OUTPUT 26 SPECIFICATION

--
--Myron A. Calhoun.
Five boxes preserve our freedoms: soap, ballot, witness, jury, and cartridge
PhD EE (retired). "Barbershop" tenor. CDL(PTXS). W0PBV. (785) 539-4448
NRA Life Member and Certified Instructor (Home Firearm Safety, Rifle, Pistol)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com