Data Type Conversion Methods in FORTRAN 5.1

Last reviewed: July 19, 1995
Article ID: Q51471
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS versions 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 5.0, 5.1

SUMMARY

The text below lists the data type conversion methods provided in Microsoft FORTRAN versions 5.0 and 5.1. The article includes information on the following:

  • Intrinsic functions that perform data type conversions.
  • The $STORAGE metacommand.
  • The IMPLICIT statement.
  • The Internal READ and WRITE statements.

MORE INFORMATION

Intrinsic Functions

The following table lists the FORTRAN intrinsic functions that perform data type conversions.

   Function   Description
   -------------------------------------------------------------------

   CHAR       Converts an integer argument to a character (ASCII
              equivalent)

   CMPLX      Converts an integer, real or complex argument to a
              COMPLEX*8

   DBLE       Converts an integer, real or complex argument to a
              DOUBLE PRECISION

   DCMPLX     Converts an integer, real or complex argument to a
              COMPLEX*16

   DFLOAT     Converts an integer, real or complex argument to a
              DOUBLE PRECISION

   DREAL      Converts a COMPLEX*16 argument to a REAL*8

   FLOAT      Converts an integer argument to a REAL*4

   HFIX       Converts an integer, real or complex argument to an
              INTEGER*2

   ICHAR      Converts a character argument to an integer (ASCII
              value)

   IDINT      Converts a DOUBLE PRECISION or REAL*8 argument to an
              integer

   IFIX       Converts a REAL*4 argument to an integer

   INT        Converts an integer, real or complex argument to an
              integer

   INT1       Converts an integer, real or complex argument to an
              INTEGER*1

   INT2       Converts an integer, real or complex argument to an
              INTEGER*2

   INT4       Converts an integer, real or complex argument to an
              INTEGER*4

   INTC       Converts an integer, real or complex argument to a C
              language integer

   JFIX       Converts an integer, real or complex arguments to an
              INTEGER*4

   REAL       Converts an integer, real or complex arguments to a
              REAL*4

   SNGL       Converts a REAL*8 arguments to a REAL*4

For more information about the data conversion intrinsic functions, see pages 240-241 of the Microsoft FORTRAN "Reference" manual for versions 5.0 and 5.1

$STORAGE Metacommand

The $STORAGE:n metacommand allocates "n" bytes of memory for all INTEGER and LOGICAL variables. For example, when an application specifies the $STORAGE:2 metacommand and declares an INTEGER variable B, the compiler allocates two bytes for B instead of four. The $STORAGE metacommand does not affect memory allocation when a declaration includes an explicit length specification, such as an INTEGER*2 or INTEGER*4.

For more information about the $STORAGE metacommand, see pages 34 and 308 of the Reference manual for versions 5.0 and 5.1

IMPLICIT Statement

If an application does not explicitly define a data type for a name, the compiler uses the first letter of the variable or function name to determine its type. By default, names that begin with the letters I, J, K, L, M, or N are of type INTEGER. Names that begin with one of the other letters or with a dollar sign ($) are of type REAL. An application can use the IMPLICIT statement to override the default type assignment.

For more information on the IMPLICIT statement, see pages 8 and 181- 182 of the Reference manual for versions 5.0 and 5.1.

Internal READ and WRITE Statements

Reading from an internal file converts ASCII values to numeric, logical, or character values while writing to an internal file converts the internal values to ASCII text. For more information on the internal READ and WRITE statements, see pages 77-78 of the Reference manual for versions 5.0 and 5.1

The following code example converts a character variable to an integer.

Sample Code

C Compile options needed: None

      CHARACTER*5 NUM
      INTEGER TEST
      NUM = '12345'
      READ(NUM, '(I5)') TEST
      WRITE (*, *) TEST
      END


Additional reference words: kbinf 5.00 5.10
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 19, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.