Pages

Showing posts with label fortran. Show all posts
Showing posts with label fortran. Show all posts

Fortran Resources (recipes, libraries, learning materials, etc)

Fortran95 features
from Wikipedia

List of Fortran Numerical Libraries
from Wikipedia

Numerical Methods for Fortran Programmars
from people.sc.fsu.edu
contain links to fortran libraries and subroutines

Scientific Programming and Numerical Computation
from Wu-ting Tsai, National Taiwan University.

Fortran95 Interface to Matlab
from Matlab

Fortran Resources List
from BCS Fortran Specialist Group

Fortran Wiki
contains tutorials and FORTRAN code collections
contains list of links that contain FORTRAN codes

Fortran Tutorials ( a list of tutorials)
a list form The Fortran Company

Computational Physics using Fortran (official link)
an NPTEL course with a brief introduction to Fortran

Fortran90 Tutorial 
From MTU


A crash course on Fortran

Most of the condensed matter physics codes are written in Fortran and here is a quick summary of Fortran 95 language.

"
! To read a file.
    open(unit=11, file="records.txt", status="old") 
    ! The file is referred to by a 'unit number', an integer that you pick in
    ! the range 9:99. Status can be one of {'old','replace','new'}.
    read(unit=11, fmt="(3F10.2)") a, b, c
    close(11)

    ! To write a file.
    open(unit=12, file="records.txt", status="replace")
    write(12, "(F10.2,F10.2,F10.2)") c, b, a
    close(12)
"
References:
Learn Fortran95 in short duration

Fortran Workflow

Fortran Specification Statements

by Michael Metcalf / CERN CN-AS
(taken from https://w3.pppl.gov/~hammett/comp/f90tut/f90.tut7.html
For a complete list of Fortran tutorial link and other useful links, look at
https://w3.pppl.gov/~hammett/

Implicit typing

The imlicit typing rules of FORTRAN 77 still hold. However, it is good practice to explicitly type all variables, and this can be forced by inserting the statement
        IMPLICIT NONE
at the beginning of each prorgam unit.

PARAMETER attribute

A named constant can be specified directly by adding the PARAMETER attribute and the constant values to a type statement:
     REAL, DIMENSION(3), PARAMETER :: field = (/ 0., 1., 2. /)
     TYPE(triplet), PARAMETER :: t =                           &
                                triplet( 0., (/ 0., 0., 0. /) )

DATA statement

The DATA statement can be used also for arrays and variables of derived type. It is also the only way to initialise just parts of such objects, as well as to initialise to binary, octal or hexadecimal values:
       TYPE(triplet) :: t1, t2
       DATA t1/triplet( 0., (/ 0., 1., 2. /) )/, t2%u/0./
       DATA array(1:64) / 64*0/
       DATA i, j, k/ B'01010101', O'77', Z'ff'/

Characters

There are many variations on the way character arrays may be specified. The shortest and longest are
CHARACTER name(4, 5)*20
CHARACTER (KIND = kanji, LEN = 20), DIMENSION (4, 5) :: name

Initialization expressions

The values used in DATA and PARAMETER statements, or with these attributes, are constant expressions that may include references to: array and structure constructors, elemental intrinsic functions with integer or character arguments and results, and the six transformational functions REPEAT, SELECTED_INT_KIND, TRIM, SELECTED_REAL_KIND, RESHAPE and TRANSFER:
     INTEGER, PARAMETER :: long = SELECTED_REAL_KIND(12),   &
                       array(3) = (/ 1, 2, 3 /)

Specification expressions

It is possible to specify details of variables using any non-constant, scalar, integer expression that may also include inquiry function references:
     SUBROUTINE s(b, m, c)
        USE mod                                 ! contains a
        REAL, DIMENSION(:, :)             :: b
        REAL, DIMENSION(UBOUND(b, 1) + 5) :: x
        INTEGER                              m
        CHARACTER(LEN=*)                     c
        CHARACTER(LEN= m + LEN(c))           cc
        REAL (SELECTED_REAL_KIND(2*PRECISION(a))) z

PUBLIC and PRIVATE

These attributes are used in specifications in modules to limit the scope of entities. The attribute form is
     REAL, PUBLIC     :: x, y, z           ! default
     INTEGER, PRIVATE :: u, v, w
and the statement form is
     PUBLIC  :: x, y, z, OPERATOR(.add.)
     PRIVATE :: u, v, w, ASSIGNMENT(=), OPERATOR(*)
The statement form has to be used to limit access to operators, and can also be used to change the overall default:
     PRIVATE                        ! sets default for module
     PUBLIC  :: only_this
For derived types there are three possibilities: the type and its components are all PUBLIC, the type is PUBLIC and its components PRIVATE (the type only is visible and one can change its details easily), or all of it is PRIVATE (for internal use in the module only):
     MODULE mine
        PRIVATE
        TYPE, PUBLIC :: list
           REAL x, y
           TYPE(list), POINTER :: next
        END TYPE list
        TYPE(list) :: tree
        :
     END MODULE mine

USE statement

To gain access to entities in a module, we use the USE statement. It has options to resolve name clashes if an imported name is the same as a local one:
     USE mine, local_list => list
or to restrict the used entities to a specified set:
     USE mine, ONLY : list

Using specific routines in LAPACK library pacakge


How to run specific modules in LAPACK in a Fortran code?

With the title "Using LAPACK library in fortran codes" in this forum, it is clearly explained.


Use call option to find the solution for the A*X = B lenear equations using the routine DGESV

call DGESV()

Compile the code by

gfortran -o output codeName -L. -lliblapack


From LAPACK page, 

"DGESV computes the solution to a real system of linear equations
    A * X = B,
 where A is an N-by-N matrix and X and B are N-by-NRHS matrices.

 The LU decomposition with partial pivoting and row interchanges is
 used to factor A as
    A = P * L * U,
 where P is a permutation matrix, L is unit lower triangular, and U is
 upper triangular.  The factored form of A is then used to solve the
 system of equations A * X = B. "

You may be interested in these posts

Error in image file conversion: convert-im6.q16: not authorized `test.eps' @ error/constitute.c/WriteImage/1037.

This error is because of the vulnerability. This allows remote execution of code using image formats. So, some Linux distributions by defaul...