1

I am trying to upgrade old code to F95 standards. I don't understand how the character string afpn is being assigned a value using the write statement in the below function. I've encountered this in several places. How does this work?

      CHARACTER(LEN=15) FUNCTION XFPN2AL( FPN )

      IMPLICIT NONE
      ! external variables
      REAL(KIND=4)INTENT(IN):: FPN

      ! internal variables
      CHARACTER(LEN=15):: AFPN

      ! initialize variables
      AFPN = ' '
      XFPN2AL = ' '

      WRITE(AFPN,'(G15.7)') FPN
      XFPN2AL = ADJUSTL(AFPN)

      END FUNCTION XFPN2AL
Chris
  • 44,602
  • 16
  • 137
  • 156
user2417662
  • 47
  • 1
  • 4

1 Answers1

3

This is making use of the internal files (see also Wikipedia) feature of Fortran. In addition to reading and writing to files you can use an internal file to read and write to character arrays. As an example of this in action, see this other SO question which describes the use of internal files for converting integers to strings.

Community
  • 1
  • 1
Chris
  • 44,602
  • 16
  • 137
  • 156