Need help w/sprintf-like internal file use. 
Author Message
 Need help w/sprintf-like internal file use.

I need sprintf functionality in an F77 program.
As far as my understanding goes, the way to do this is to use internal files.

My problem is illustrated by the following code :
        program bob

        character foo*80
        write (UNIT=foo, FMT=10)

C       In the real world, I'd like to do something more
C       than just printing foo here, of course.
        write (*,*) foo

  10    format ('First line',/,'Second line')
        end

I'd like foo to contain - in C terms - "First line\nSecond line", and to be
printed, accordingly, in two lines.  In stead, I get a run time error ;
*** fortran I/O ERROR 974: RECORD ACCESSED PAST END OF INTERNAL FILE (VARIABLE)

I need foo to be able to handle format strings with 0 to several newlines.
Do I have to make foo a 'character foo(MAXLINES)*80'?

Any feedback will be appreciated.  
Thanks in advance,

Einar Rune Haugnes



Sun, 16 Jan 2000 03:00:00 GMT  
 Need help w/sprintf-like internal file use.


writes:

|>My problem is illustrated by the following code :
|>   program bob
|>
|>   character foo*80
|>   write (UNIT=foo, FMT=10)
|>
|>C  In the real world, I'd like to do something more
|>C  than just printing foo here, of course.
|>   write (*,*) foo
|>
|>  10       format ('First line',/,'Second line')
|>   end
|>
|>I'd like foo to contain - in C terms - "First line\nSecond line", and to be
|>printed, accordingly, in two lines.  In stead, I get a run time error ;
|>*** FORTRAN I/O ERROR 974: RECORD ACCESSED PAST END OF INTERNAL FILE (VARIABLE)
|>
|>I need foo to be able to handle format strings with 0 to several newlines.
|>Do I have to make foo a 'character foo(MAXLINES)*80'?

Yes, making foo an array is the way to handle this in a standard-conforming
manner.  You could, I suppose, insert CHAR(10) in the string which may
cause the following text to be displayed on a new line, but I'd go for the
array method myself.
--


Fortran Development               http://www.digital.com/info/slionel.html
Digital Equipment Corporation    
110 Spit Brook Road, ZKO2-3/N30    
Nashua, NH 03062-2698             "Free advice is worth every cent"

For information on DIGITAL Fortran, see http://www.digital.com/fortran



Sun, 16 Jan 2000 03:00:00 GMT  
 Need help w/sprintf-like internal file use.



Quote:
> I need sprintf functionality in an F77 program.
> As far as my understanding goes, the way to do this is to use internal
files.

> My problem is illustrated by the following code :
>    program bob

>    character foo*80
>    write (UNIT=foo, FMT=10)

> C  In the real world, I'd like to do something more
> C  than just printing foo here, of course.
>    write (*,*) foo

>   10       format ('First line',/,'Second line')
>    end

> I'd like foo to contain - in C terms - "First line\nSecond line", and to
be
> printed, accordingly, in two lines.  In stead, I get a run time error ;
> *** FORTRAN I/O ERROR 974: RECORD ACCESSED PAST END OF INTERNAL FILE

(VARIABLE)

A Fortran internal file (a character variable) consists of one
an only one record.  Why don't you just put the newline into
the string the old fashioned way?  If you know what character
your system interprets as the newline character, just build
a string with that character in it:

      foo = 'First line' // char(10) // 'Second line'

This assumes that you're on a system (like unix) which
uses the linefeed character as the newline (actual
conformance to the intent of the ASCII standard would
use RS - the record separator - which is char(30), but
few systems ever have).

Internal I/O is mostly for conversion of numeric data
to and/or from character representations under format
control.  For general purpose building and manipulation
of strings, you should use character assignment,
concatenation, and character functions.  That's what
they're for.

--
J. Giles
Ricercar Software



Sun, 16 Jan 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with using SPrintf function in a cpp file

2. Newbie help needed - using awk to create a CSV file

3. Drive A is using MS-Dos Compatibility Mode File System -- NEED HELP --

4. Using file data transparently as internal data?

5. Accessing internal signals and ports for writing to a file using testbench

6. Tcl DStrings - need sprintf...

7. Who likes Info files?

8. Help needed: Internal Error 1010

9. I need help on some windows internals

10. need help with Tkinter internals

11. HELP : Look for information of database internal file structure

12. Need help launching external non rexx command using VXREXX (VIO support needed) in OS/2

 

 
Powered by phpBB® Forum Software