Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Case sensitivity in Fortran

Yadav__Geetanjali
1,652 Views

Dear Members,

I am completely new to the Fortran. I have a very simple program for the Identity matrix. I want to know if Fortran is case insensitive?

The "N" in the subroutine is the same "n" used in the DO loop? 

SUBROUTINE IDENTITY(Mat, N)

IMPLICIT NONE

INTEGER, INTENT(IN) :: N

REAL*8, INTENT(OUT), DIMENSION(N,N) :: Mat

INTEGER :: i, j

!      Creates and Identity Matrix
  
     DO i=1,n
         DO j=1,n
            IF (i .EQ. j) THEN
              Mat(i,j) = 1.0D0
            ELSE
              Mat(i,j) = 0.0D0
            END IF
         END DO
       END DO

Thanks!

0 Kudos
6 Replies
dboggs
New Contributor I
1,652 Views

May I suggest you obtain--and read--a basic textbook or guidebook on the Fortran language. The question you ask is a very basic one, and if you continue to rely on this (or other) source for all such basic questions, you will be spending much more time than if you get it all in one document.

0 Kudos
Steve_Lionel
Honored Contributor III
1,652 Views

To answer your immediate question, though - Fortran is not a case-sensitive language, so, yes, N and n identify the same variable.

0 Kudos
Yadav__Geetanjali
1,652 Views

Thank you dboggs for your suggestion. I will definitely refer books for the basics.

 

Thank You Steve. Much appreciated.

 

Regards,

Geetanjali

0 Kudos
Roy_S_
Beginner
1,652 Views

Hi Geetanjali,

FORTRAN is one of the oldest compiler languages.  It dates back to when source code was written on 80 column punched cards.  The cards only used upper case letters, numbers, and a few special characters.   When lower case letters were introduced with the ASCII character set, FORTRAN kept the tradition of interpreting all alpha characters as their upper case variant.  So, "a" and "A" are interpreted as "A" by a FORTRAN compiler.  I personally like this much better than languages like C that are case sensitive.  I like it that I don't have to worry whether "caps lock" is on or off while writing code.  There are more than enough variable names available without making the names case sensitive.  One hint I will pass on as good coding practice.  Always include the line " IMPLICIT NONE" at the beginning of a FORTRAN program before you declare variables.  This requires you to declare all your variables,  prevents getting INTEGER and REAL variables from being declared based on their initial letter, and helps the compiler find any variable misspellings.  

0 Kudos
Julian_H_
Beginner
1,652 Views

Books which i definetly recommend are:

Fortran 95/2003 for Scientists & Engineers, J. Chapman

Guide to Fortran 2008 Programming, S. Brainerd

because if it comes to Fortran the internet (except this forum) is not the best ressource, because there is a lot of legacy code floating around.

0 Kudos
DataScientist
Valued Contributor I
1,652 Views

A free concise introduction to Fortran 90 is available here:

https://www.uv.es/dogarcar/man/IntrFortran90.pdf

It is rather well written and easy to follow. Although it is still relevant, it is way behind modern Fortran (2003, 2008, 2018) features (notably object-oriented programming, submodules, and Coarray parallel programming). A a definitive reference on modern Fortran (2008) would be the book by Metcalf et al. "Modern Fortran Explained".

0 Kudos
Reply