Tag Archives: Fortran

Fortran get_command_argument

Fortran 2003 is a major extension to Fortran 90/95 including many useful features, one significant feature is access to command arguments; this allows a program to take data from the execution command line and use this arguments as input information.

program cmdline
  implicit none

  character(len=*), parameter :: version = '1.0'
  character(len=32) :: arg
  integer :: i

  do i = 1, command_argument_count()
     call get_command_argument(i, arg)

     select case (arg)
     case ('-v', '--version')
        print '(2a)', 'cmdline version ', version
        stop
     case ('-h', '--help')
        call print_help()
        stop
     case default
        print '(a,a,/)', 'Unrecognized command-line option: ', arg
        call print_help()
        stop
     end select
  end do

contains

  subroutine print_help()
    print '(a)', 'usage: cmdline [OPTIONS]'
    print '(a)', 'cmdline options:'
    print '(a)', '  -v, --version     print version information and exit'
    print '(a)', '  -h, --help        print usage information and exit'
  end subroutine print_help

end program cmdline
Advertisements

Dislin

In my last year of college I started working in solar energy research, processing large amounts of data of global, diffuse and direct solar radiation. The processing of this information was very difficult, considering that a year of measurements means more than 500,000 data measured every minute. For each data had to calculate the position of the sun and do quality control of measurements, it was impossible to do it in Excel due to long processing times and freezes. It was then that I began to process information with Fortran, everything was much faster, did not fall and was able to process lots of information quickly. The problem was that was not possible to generate graphics and that was critical for me.

This is how I reach DISLIN, a library to generate incredible graphics from Fortran, very easy to use and export to all formats. With the time I even use Dislin to generate Graphics Users Interface (GUI) for Fortran software.

Below are images with more than 200,000 points that was realized in a couple of seconds with Fortran and DISLIN.

Where is the Sun ?? (Solar position algorithms)

Accurate computation of solar position plays a fundamental role in solar energy applications, especially for concentrating systems. The required accuracy varies over a wide range, depending on the application: flat systems tolerate errors of a few degrees without significant losses, while high-concentration systems can require an accuracy of the order of 0.01º. More specific applications, such as the calibration of pyranometers ( Reda and Andreas, 2004 ), require an even greater accuracy.

Continue reading

How to compile a Fortran program

Most of the times the most difficult step it is the first one…

Every programing languages have differents statements to interpretate in code what you wants your programs do. To compile is the process to translate from text of source code written in a defined programming language to binary machine language, creating an executable program.

The process of develop a program have some main steps, define the flowchart of information, write the code, test and optimize.

The compilation commands are different if we are in the tests and debugging step or in the optimization step, because for tests of functionality the speed it is not an issue but it is possible to use the debugger and to easily understand where are the problems.

The basic structure of Fortran is:

program <name>

use <module_name>

implicit none

<declarations>

<executable statements>

contains

<internal-subprograms>

end program <name>

Continue reading