[Dart-dev] [3780] DART/trunk/utilities: program to check fortran kind behavior

nancy at ucar.edu nancy at ucar.edu
Fri Feb 27 10:43:01 MST 2009


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20090227/49457bdf/attachment-0001.html 
-------------- next part --------------
Added: DART/trunk/utilities/PrecisionCheck.f90
===================================================================
--- DART/trunk/utilities/PrecisionCheck.f90	                        (rev 0)
+++ DART/trunk/utilities/PrecisionCheck.f90	2009-02-27 17:43:00 UTC (rev 3780)
@@ -0,0 +1,81 @@
+      Program Precision_Check
+
+      implicit none
+
+      integer, parameter :: i4 = SELECTED_INT_KIND(8)
+      integer, parameter :: i8 = SELECTED_INT_KIND(13)
+      integer, parameter :: r4 = SELECTED_REAL_KIND(6,30)
+      integer, parameter :: c4 = SELECTED_REAL_KIND(6,30)
+      integer, parameter :: r8 = SELECTED_REAL_KIND(12)
+      integer, parameter :: c8 = SELECTED_REAL_KIND(12)
+
+      integer     :: inative
+      integer(i4) :: int4
+      integer(i8) :: int8
+
+      real        :: rnative
+      real(r4)    :: realr4
+      real(r8)    :: realr8
+
+      double precision :: dp
+
+      write(*,*)
+      write(*,*)'This explores the use of the intrinisc &
+                &SELECTED_[REAL,INT]_KIND() functions'
+      write(*,*)'and the interplay with the compiler options. &
+                &You are encouraged to use the'
+      write(*,*)'"autopromotion" flags on your compiler and compare &
+                &the results.'
+      write(*,*)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"integer"'
+      write(*,*)'DIGITS    = ',   digits(inative)
+      write(*,*)'HUGE      = ',     huge(inative)
+      write(*,*)'KIND      = ',     kind(inative)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"integer(i4)" i4 = SELECTED_INT_KIND(8)'
+      write(*,*)'DIGITS    = ',   digits(int4)
+      write(*,*)'HUGE      = ',     huge(int4)
+      write(*,*)'KIND      = ',     kind(int4)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"integer(i8)" i8 = SELECTED_INT_KIND(13)'
+      write(*,*)'DIGITS    = ',   digits(int8)
+      write(*,*)'HUGE      = ',     huge(int8)
+      write(*,*)'KIND      = ',     kind(int8)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"real"'
+      write(*,*)'DIGITS    = ',   digits(rnative)
+      write(*,*)'EPSILON   = ',  epsilon(rnative)
+      write(*,*)'HUGE      = ',     huge(rnative)
+      write(*,*)'KIND      = ',     kind(rnative)
+      write(*,*)'PRECISION = ',precision(rnative)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"real(r4)" r4 = SELECTED_REAL_KIND(6,30)'
+      write(*,*)'DIGITS    = ',   digits(realr4)
+      write(*,*)'EPSILON   = ',  epsilon(realr4)
+      write(*,*)'HUGE      = ',     huge(realr4)
+      write(*,*)'KIND      = ',     kind(realr4)
+      write(*,*)'PRECISION = ',precision(realr4)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"real(r8") r8 = SELECTED_REAL_KIND(13)'
+      write(*,*)'DIGITS    = ',   digits(realr8)
+      write(*,*)'EPSILON   = ',  epsilon(realr8)
+      write(*,*)'HUGE      = ',     huge(realr8)
+      write(*,*)'KIND      = ',     kind(realr8)
+      write(*,*)'PRECISION = ',precision(realr8)
+
+      write(*,'(''----------------------------------------------'')')
+      write(*,*)'"double precision"'
+      write(*,*)'DIGITS    = ',   digits(dp)
+      write(*,*)'EPSILON   = ',  epsilon(dp)
+      write(*,*)'HUGE      = ',     huge(dp)
+      write(*,*)'KIND      = ',     kind(dp)
+      write(*,*)'PRECISION = ',precision(dp)
+
+      end program Precision_Check


Property changes on: DART/trunk/utilities/PrecisionCheck.f90
___________________________________________________________________
Name: mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: DART/trunk/utilities/PrecisionCheck.html
===================================================================
--- DART/trunk/utilities/PrecisionCheck.html	                        (rev 0)
+++ DART/trunk/utilities/PrecisionCheck.html	2009-02-27 17:43:00 UTC (rev 3780)
@@ -0,0 +1,260 @@
+<HTML>
+<HEAD>
+<TITLE>program PrecisionCheck</TITLE>
+<link rel="stylesheet" type="text/css" href="../doc/html/doc.css"></link> 
+</HEAD>
+<BODY>
+<!--
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!                                                                       !!
+!!                   GNU General Public License                          !!
+!!                                                                       !!
+!! This file is part of the Data Assimilation Research Testbed (DART).   !!
+!!                                                                       !!
+!! DART is free software; you can redistribute it and/or modify          !!
+!! it and are expected to follow the terms of the GNU General Public     !!
+!! License as published by the Free Software Foundation.                 !!
+!!                                                                       !!
+!! DART is distributed in the hope that it will be useful,               !!
+!! but WITHOUT ANY WARRANTY; without even the implied warranty of        !!
+!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         !!
+!! GNU General Public License for more details.                          !!
+!!                                                                       !!
+!! You should have received a copy of the GNU General Public License     !!
+!! along with DART; if not, write to:                                    !!
+!!          Free Software Foundation, Inc.                               !!
+!!          59 Temple Place, Suite 330                                   !!
+!!          Boston, MA  02111-1307  USA                                  !!
+!! or see:                                                               !!
+!!          http://www.gnu.org/licenses/gpl.txt                          !!
+!!                                                                       !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+-->
+
+<!--==================================================================-->
+
+<H1>PROGRAM PrecisionCheck</H1>
+<A NAME="HEADER"></A>
+<TABLE summary="">
+<TR><TD>Contact:       </TD><TD> Tim Hoar     </TD></TR>
+<TR><TD>Revision:      </TD><TD> $Revision$ </TD></TR>
+<TR><TD>Source:        </TD><TD> $URL$ </TD></TR>
+<TR><TD>Change Date:   </TD><TD> $Date$ </TD></TR>
+<TR><TD>Change history:</TD><TD> try "svn log" or "svn diff" </TD></TR>
+</TABLE>
+
+<!--==================================================================-->
+
+<A NAME="OVERVIEW"></A>
+<HR>
+<H2>OVERVIEW</H2>
+
+<P>
+This is a self-contained program to explore the interaction between
+the compiler options to 'autopromote' variables from one precision
+to another and the intrinsic F90 mechanism for getting consistent
+behavior without relying on autopromotion - namely, the
+<em class="code">SELECT_INT_KIND()</em> and 
+<em class="code">SELECT_REAL_KIND()</em> functions.
+The most portable code explicity types the variables to avoid relying
+on compiler flags. The core DART code abides by these rules; some pieces
+that are derived from dynamical models may have original code fragments.
+<br />
+<br />
+All that is required is to compile the single file and run the resulting
+executable. There are no required libraries - any F90 compiler should
+have no trouble with this program. There is no input of any kind.
+<br />
+<br />
+You are encouraged to view the source code. It's pretty obvious 
+what is being tested. 
+</P>
+
+<!--==================================================================-->
+
+<BR><HR><BR>
+<H2>EXAMPLES</H2>
+<P>
+The following examples have differences from the default configuration
+highlighted in boldface. You are strongly encouraged to test your compiler
+and its autopromotion options. The Absoft compiler actually does what I 
+consider to be reasonable and logical (as long as you know that "-dp" 
+means <b>d</b>emote <b>p</b>recision). Many other compilers are surprising.
+</P>
+
+
+<H3 class="indent">PowerPC chipset : Absoft Pro Fortran 9.0</H3>
+<div class="unix">
+<pre>
+[~/DART/utilities] % <em class="input">f90 PrecisionCheck.f90</em>
+[~/DART/utilities] % <em class="input">./a.out</em>
+ 
+ This explores the use of the intrinisc SELECTED_[REAL,INT]_KIND() functions
+ and the interplay with the compiler options. You are encouraged to use the
+ "autopromotion" flags on your compiler and compare the results.
+ 
+----------------------------------------------
+ "integer"
+ DIGITS    =   31
+ HUGE      =   2147483647
+ KIND      =   4
+----------------------------------------------
+ "integer(i4)" i4 = SELECTED_INT_KIND(8)
+ DIGITS    =   31
+ HUGE      =   2147483647
+ KIND      =   4
+----------------------------------------------
+ "integer(i8)" i8 = SELECTED_INT_KIND(13)
+ DIGITS    =   63
+ HUGE      =   9223372036854775807
+ KIND      =   8
+----------------------------------------------
+ "real"
+ DIGITS    =   24
+ EPSILON   =   1.192093E-07
+ HUGE      =   3.402823E+38
+ KIND      =   4
+ PRECISION =   6
+----------------------------------------------
+ "real(r4)" r4 = SELECTED_REAL_KIND(6,30)
+ DIGITS    =   24
+ EPSILON   =   1.192093E-07
+ HUGE      =   3.402823E+38
+ KIND      =   4
+ PRECISION =   6
+----------------------------------------------
+ "real(r8") r8 = SELECTED_REAL_KIND(13)
+ DIGITS    =   53
+ EPSILON   =   2.220446049250313E-016
+ HUGE      =   1.797693134862315E+308
+ KIND      =   8
+ PRECISION =   15
+----------------------------------------------
+ "double precision"
+ DIGITS    =   53
+ EPSILON   =   2.220446049250313E-016
+ HUGE      =   1.797693134862315E+308
+ KIND      =   8
+ PRECISION =   15
+</pre>
+</div>
+
+<H3 class="indent">PowerPC chipset : Absoft Pro Fortran 9.0 : "-dp"</H3>
+<div class="unix">
+<pre>
+[~/DART/utilities] % <em class="input">f90 -dp PrecisionCheck.f90</em>
+[~/DART/utilities] % <em class="input">./a.out</em>
+ 
+ This explores the use of the intrinisc SELECTED_[REAL,INT]_KIND() functions
+ and the interplay with the compiler options. You are encouraged to use the
+ "autopromotion" flags on your compiler and compare the results.
+ 
+----------------------------------------------
+ "integer"
+ DIGITS    =   31
+ HUGE      =   2147483647
+ KIND      =   4
+----------------------------------------------
+ "integer(i4)" i4 = SELECTED_INT_KIND(8)
+ DIGITS    =   31
+ HUGE      =   2147483647
+ KIND      =   4
+----------------------------------------------
+ "integer(i8)" i8 = SELECTED_INT_KIND(13)
+ DIGITS    =   63
+ HUGE      =   9223372036854775807
+ KIND      =   8
+----------------------------------------------
+ "real"
+ DIGITS    =   24
+ EPSILON   =   1.192093E-07
+ HUGE      =   3.402823E+38
+ KIND      =   4
+ PRECISION =   6
+----------------------------------------------
+ "real(r4)" r4 = SELECTED_REAL_KIND(6,30)
+ DIGITS    =   24
+ EPSILON   =   1.192093E-07
+ HUGE      =   3.402823E+38
+ KIND      =   4
+ PRECISION =   6
+----------------------------------------------
+ "real(r8") r8 = SELECTED_REAL_KIND(13)
+ DIGITS    =   53
+ EPSILON   =   2.220446049250313E-016
+ HUGE      =   1.797693134862315E+308
+ KIND      =   8
+ PRECISION =   15
+----------------------------------------------
+ "double precision"
+ DIGITS    =   <b>24</b>
+ EPSILON   =   <b>1.192093E-07</b>
+ HUGE      =   <b>3.402823E+38</b>
+ KIND      =   <b>4</b>
+ PRECISION =   <b>6</b>
+</pre>
+</div>
+ 
+<H3 class="indent">PowerPC chipset : Absoft Pro Fortran 9.0 : "-N113"</H3>
+<div class="unix">
+<pre>
+[~/DART/utilities] % <em class="input">f90 -N113 PrecisionCheck.f90</em>
+[~/DART/utilities] % <em class="input">./a.out</em>
+ 
+ This explores the use of the intrinisc SELECTED_[REAL,INT]_KIND() functions
+ and the interplay with the compiler options. You are encouraged to use the
+ "autopromotion" flags on your compiler and compare the results.
+ 
+----------------------------------------------
+ "integer"
+ DIGITS    =   31
+ HUGE      =   2147483647
+ KIND      =   4
+----------------------------------------------
+ "integer(i4)" i4 = SELECTED_INT_KIND(8)
+ DIGITS    =   31
+ HUGE      =   2147483647
+ KIND      =   4
+----------------------------------------------
+ "integer(i8)" i8 = SELECTED_INT_KIND(13)
+ DIGITS    =   63
+ HUGE      =   9223372036854775807
+ KIND      =   8
+----------------------------------------------
+ "real"
+ DIGITS    =   <b>53</b>
+ EPSILON   =   <b>2.220446049250313E-016</b>
+ HUGE      =   <b>1.797693134862315E+308</b>
+ KIND      =   <b>8</b>
+ PRECISION =   <b>15</b>
+----------------------------------------------
+ "real(r4)" r4 = SELECTED_REAL_KIND(6,30)
+ DIGITS    =   24
+ EPSILON   =   1.192093E-07
+ HUGE      =   3.402823E+38
+ KIND      =   4
+ PRECISION =   6
+----------------------------------------------
+ "real(r8") r8 = SELECTED_REAL_KIND(13)
+ DIGITS    =   53
+ EPSILON   =   2.220446049250313E-016
+ HUGE      =   1.797693134862315E+308
+ KIND      =   8
+ PRECISION =   15
+----------------------------------------------
+ "double precision"
+ DIGITS    =   53
+ EPSILON   =   2.220446049250313E-016
+ HUGE      =   1.797693134862315E+308
+ KIND      =   8
+ PRECISION =   15
+</pre>
+</div>
+
+<!--==================================================================-->
+
+<!--==================================================================-->
+
+<HR>
+</BODY>
+</HTML>


Property changes on: DART/trunk/utilities/PrecisionCheck.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native


More information about the Dart-dev mailing list