Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

File position inquiry with non-advancing formatted stream access and sheep

$
0
0

I've never been good at poetry... so I've started using Fortran to help me.  Getting the right number of syllables in each line has always been tricky, so sometimes I skip over bits, and then fill them in later.

PROGRAM poetic_streaming
  IMPLICIT NONE

  INTEGER :: unit
  INTEGER :: pos

  OPEN(  &
      NEWUNIT=unit,  &
      FILE='poetry.txt',  &
      FORM='FORMATTED',  &
      ACCESS='STREAM',  &
      ACTION='WRITE',  &
      STATUS='REPLACE' )

  WRITE (unit, "(A)", ADVANCE='NO') 'Mary had a '
  ! Remember where we are and leave a placeholder for now.
  INQUIRE(unit, POS=pos) ; print *, pos
  WRITE (unit, "(A7)", ADVANCE='NO') ''
  WRITE (unit, "(A)") ' processor'

  WRITE (unit, "(A)") 'ifort was its name'
  WRITE (unit, "(A)") 'but support for querying the file position after non-advancing formatted stream access output was broken'
  WRITE (unit, "(A)") 'so she had to rethink her game'

  WRITE (unit, "(A7)", POS=pos, ADVANCE='NO') 'Fortran'

  CLOSE(unit)
END PROGRAM poetic_streaming

Alas...

>ifort /check:all /warn:all /standard-semantics "2015-11-21 poetic_streaming.f90"&& "2015-11-21 poetic_streaming.exe"&& type poetry.txt
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0 Build 20151021
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

"-out:2015-11-21 poetic_streaming.exe"
-subsystem:console"2015-11-21 poetic_streaming.obj"
 1
Fortran
a         processor
ifort was its name
but support for querying the file position after non-advancing formatted stream access output was broken
so she had to rethink her game

I think I spy a stray newline in there too.


Viewing all articles
Browse latest Browse all 3270

Trending Articles