evolution of fortran standards over the few
play

Evolution of Fortran standards over the few A brief overview of this - PowerPoint PPT Presentation

Evolution of Fortran standards over the few A brief overview of this course decades The 1 st version became a standard by John Backus Advanced Fortran Programming concentrates on aspects related to the most recent versions of the Fortran


  1. Evolution of Fortran standards over the few A brief overview of this course decades The 1 st version became a standard by John Backus Advanced Fortran Programming concentrates on aspects related to the most recent versions of the Fortran (IBM/1957) standard (F2003/2008/2015) Mid- 60’s the most significant version was labeled as an – some Fortran 95 less-known features are covered, too ANSI standard, called FORTRAN66 In 1978 the former “de - facto” FORTRAN77 standard was Our major F2003/F2008 subjects in this course are approved and quickly became popular, contained e.g. – Language interoperability – IMPLICIT statement – Object-oriented Fortran (OOF) – IF – THEN – ELSE IF – ELSE – ENDIF – Parallel programming with Fortran coarrays – CHARACTER data type – PARAMETER statement for specifying constants 1 2 Evolution of Fortran standards… Evolution of Fortran standards… An important extension to FORTRAN77 was release of A major step in keeping Fortran programming alive was “military standard” Fortran enhancements (also in 1978) introduction of the Fortran 90 standard in ’91 (ISO), ’92 by US DoD, and adopted by most FORTRAN77 compilers (ANSI) – IMPLICIT NONE – Free format source input (up to 132 characters per line) – DO – END DO – Dynamic memory handling – INCLUDE statement Marked a number of features obsolescent (but did not – Bit manipulation functions delete any features), e.g. – Arithmetic IF and computed GOTO statements All these were eventually incorporated to the next major – Alternate RETURN, and use of H in FORMAT statements official standard release – Fortran 90 3 4

  2. Evolution of Fortran standards… Evolution of Fortran standards… A minor revision in 1997 (ISO) some features were taken Fortran 2003 was a significant revision of the Fortran 95 from High Performance Fortran (HPF) specification, e.g. standard (introduced in 2004) – Object-oriented programming (OOP), e.g. – FORALL and nested WHERE clauses to improve vectorization  Type extension, (single) inheritance, polymorphism, … – User-defined PURE and ELEMENTAL procedures – Parameterized derived types – Automatic DEALLOCATE when ALLOCATABLE out of scope – Procedure POINTERs – POINTER and TYPE components default initializations – Interoperability with C (and other) languages Deleted some features previously marked as obsolescent – OS interfacing: command line arguments & env. variables – Use of non-INTEGERs as DO loop parameters – ALLOCATABLE improvements – H edit descriptor in FORMATs – POINTER improvements – ASSIGN and assigned GOTO – I0 edit descriptor for INTEGERs in FORMAT statements 5 6 Evolution of Fortran standards… Fortran 2008: A minor revision of Fortran 2003 (approved 2010) New features include – Coarrays – Submodules – CONTIGUOUS attribute – BLOCK construct – newunit= in OPEN statement – DO CONCURRENT construct – G0 edit descriptor for REALs in FORMAT statements 7

  3. Outline Interaction with the operating system – Accessing command line arguments and environment variables – Running operating system commands from Fortran Less known features of allocatable variables contiguous attribute Further scope control mechanisms, associate and Useful features since Fortran 90 block constructs, submodules 8 9 Command line arguments Parameters to a program are very often given to programs as command line arguments – Input file(s), modify program behavior, etc. INTERACTION WITH THE OPERATING SYSTEM Besides command line arguments, environment variables are a common way to influence program behavior Fortran 2003 introduced a standardized method for – reading command line arguments – accessing values of environment variables 10 11

  4. Command line arguments Command line arguments … Access separate command line arguments Access the whole command line get_command_argument(number[,value][,length][,stat call get_command(command[,length][,status]) us]) – command is of type character string and contains the value – number denotes which argument to get of the command line on return. – value is a character string that contains the value of the – length is of type integer and contains the length of the requested argument on return (optional) command line on return (optional) – length contains the length of the requested argument on return (optional) Get the number of command line arguments integer :: command_argument_count() 12 13 Command line input Environment variables Access a value of an environment variable subroutine read_command_line(height, width) Example: reading in integer, intent(out) :: height, width call get_environment_variable(name,value[,length] two integer values character(len=10) :: args(2) [,status][,trim_name]) integer :: n_args, i from the command n_args = command_argument_count() – name is a character string that contains the name of the line, e.g. if ( n_args /= 2 ) then requested variable write(*,*) ' Usage : ./exe height width' % ./a.out 100 100 stop – value is a character string that contains the value of the end if requested variable do i = 1, 2 call get_command_argument(i,args(i)) – length is the length of the requested variable on return args(i) = trim(adjustl(args(i))) end do (optional) read(args(1),*) height read(args(2),*) width – trim_name is of type logical and sets if trailing blanks are end subroutine read_command_line allowed in variable names or not (optional) 14 15

  5. Environment variables: example Executing commands program environment Invoking external programs from within a program is implicit none sometimes useful character(len=256) :: enval integer:: len,stat – No source nor library API available for a useful program – perl/python/etc parsing scripts ! extract hostname call get_environment_variable('hostname',enval,len,stat) Fortran 2008 has a standardized method for invoking an if (stat == 0) write (*,'(a,a)') 'host=', enval(1:len) external command ! extract user call get_environment_variable('user',enval,len,stat) if (stat == 0) write (*,'(a,a)') 'user=', enval(1:len) end program environment 16 17 Executing commands Executing commands: example program execcommand Execute a command line implicit none call execute_command_line(command[,wait] integer :: estat, cstat [,exitstat][,cmdstat][,cmdmsg]) call execute_command_line('ls -al', .true., estat, cstat) – command is a character string containing the command if (estat ==0) write (*,'(a)') 'command completed successfully’ – wait is logical value indicating if command termination is to be end program execcommand waited (optional) – exitstat is an integer value containing the return value of the command if wait=.true. (optional) – cmdstat is zero if command executed successfully (optional) – cmdmsg is a character string containing explanatory message for positive values of cmdstat (optional) 18 19

  6. Automatic deallocate subroutine sub1 An allocatable variable, integer, allocatable :: a(:) which is declared as a local allocate(a(1000)) variable in procedure and call use_array( a ) LESS KNOWN FEATURES OF ALLOCATE ! deallocate(a) ! not needed gets allocated, will be end subroutine sub1 automatically deallocated upon returning back from subroutine sub2 integer, allocatable, save :: a(:) routine allocate(a(1000)) This is “out of scope” rule call use_array( a ) deallocate(a) ! is needed holds as long as variables do end subroutine sub2 not have save attribute as well 20 21 Allocatable derived data type component Allocatable as a dummy argument program test An allocatable variable can module my_mod The Fortran 90 standard integer :: n type my_type appear in the procedure real, allocatable :: a(:) introduced user-defined real, allocatable :: array(:) call read_input(a, n) argument list datatypes, but dynamic end type my_type call use_array (a, n) Enables dynamic memory end module my_mod allocation was restricted to deallocate(a) end program test allocation in the called pointers only subroutine sub(n) routine based on sizing use my_mod The restriction was removed subroutine read_input(a, n) information implicit none real, allocatable, intent(out) :: a(:) in Fortran 2003 integer, intent(in) :: n integer, intent(out) :: n – Allocated (and perhaps Allocation remains intact type(my_type) :: t read *, n initialized) data is returned : even after going out of allocate(a(n)) to the caller allocate(t % array (n) ) read *, a scope, if the type was : ! no automatic deallocate here The caller must remember defined in a module end subroutine sub end subroutine sub to deallocate 22 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend