Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28637 Discussions

writing a mixture of ascii and binary data

robbiet
Beginner
1,264 Views
I'm trying to use fortran to to write a simple legacy vtk data file which will be a mix of both ascii labels and binary data. i.e. what i need is

ascii file labels
more ascii file labels
BINARY DATA
ascii file labels
more ascii file labels
BINARY DATA

I have not had much experience with writing binary data, but I understand that the binary or ascii distinction must be made in a file OPEN statement (in the FORM='FORMATTED' or 'UMFORMATTED' tag). In that case how is it possible to write a mixture of ascii and binary data to a single file?

Ta, Rob.
0 Kudos
11 Replies
Steven_L_Intel1
Employee
1,264 Views
If you use UNFORMATTED, you simply have to convert whatever data you want to character before writing. You can use an "internal WRITE" for that.

For your purpose, I would recommend FORM='BINARY'. This is a special form of UNFORMATTED which does not introduce record length data into the file. You do the writes as if it were unformatted.
0 Kudos
Crystal_T_
Beginner
1,264 Views

Hi,

I have a similar need to write to an output file with ascii id and binary data:

Sample output file: 

   Input one (in ascii)

   <binary data>

   Input two (in ascii)

   <binary data>

I have to use fortran 77 on a VAX system.  So I guess I can’t use FORM=’BINARY’ as suggestion.  (btw, I can’t use BINARY because I need to use BACKSPACE and REWIND in the program, and I read on web saying that BACKSPACE doesn’t work with Binary form. I can’t use DIRECT access either.)

For example, when I did as the following in my coding:

CHARACTER*40 DATA_ID

OPEN(UNIT=12,FILE=’TEST.DAT’,FORM=’UNFORMATTED’,STATUS=’UNKNOWN’)

DATA_ID = ‘INPUT ONE’

WRITE (12) DATA_ID

CLOSE(12)

When I open the output file, I saw there are two weird characters in front of the ‘INPUT ONE’ (record marker?)  I need only the exact word ‘INPUT ONE’ in the row (or one record) since the input file (*.com) has the word 'INPUT ONE' and will look for / compare the exact same word in the output file in order to be continued. And I can't create the same weird characters in the input file to make them the same.

Is there a way to not having the weird characters in front of the words ‘INPUT ONE’, or is there a way to code in the program to delete those characters from the output please? (I’m new to Fortran, and I got really stuck here).

Thanks,

Crystal

 

0 Kudos
mecej4
Honored Contributor III
1,264 Views

BACKSPACE requires the ability to locate records (the "weird" bytes that you wrote about contain information about where records begin/end and record lengths, in an implementation-dependent way).

When you use BINARY, that information is simply not there in the file, so how do you expect BACKSPACE to work?

0 Kudos
Steven_L_Intel1
Employee
1,264 Views

You are really using VAX Fortran 77 on a VAX VMS system? Where did you find such a system?

The "weird characters" are because VAX Fortran 77 defaults to using 'SEGMENTED' records that use the RMS VFC (Variable with Fixed Control) record type to indicate segments. You can get rid of these by adding RECORDTYPE='VARIABLE' to the OPEN. This may be sufficient for your needs, assuming the file is being read by another VMS program.

(And I thought my VMS days were behind me....)

0 Kudos
Crystal_T_
Beginner
1,264 Views

Steve,

Thanks so much for your helps and the valuable lecture about segmented records and the “weird characters” using VAX Fortran 77.  It works and the problem solved!  I spent lots of time on Google but found no good posting related to the problem I had, and here you saved my life!

Yes, all the Fortran programs here are still running on VAX VMS system, and the programs have been around since…1970 or so.  My manager joked that I wouldn’t even find a VAX machine on ebay anymore!  I’m new hire here who doesn’t know Fortran at all.  When I have problem/question, I found no one to ask since people who wrote the programs or had knowledge on these stuffs were either left or retired :(

Thanks again and have a great day!

Crystal

0 Kudos
JohnNichols
Valued Contributor III
1,262 Views

Or dead.

0 Kudos
Steven_L_Intel1
Employee
1,264 Views

1978 for the earliest VAX. VMS isn't dead, though I did not realize there were still operating VAXen.

Two of these computers are real, one is a model VAX.

0 Kudos
rase
New Contributor I
1,264 Views

Let me guess: the left one is an early mechanical VAX, or a part of the VAX CPU, presumably a NAND gate. The input values were set manually at the switch on the left, and the result displayed in the lower part of the switch. The result had to be set at the next stage of the circuitry, and so on. Calculations took a bit longer as we are used to presently. The machine on the right is a functional, but proportionally shrunk version of the original VAX 780. The reduction in size was necessary to solve the problems caused by the increase in processor speed by several orders of magnitude.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,264 Views

The 1978 version of VAX may have used a 3um to 1um process, whereas the one on the right is using a 22nm process. Thus permitting the 100:1 reduction in size. Apparently a similar advancement has taken place in read-to-reel tape size as evident by the picture.

Jim Dempsey

0 Kudos
Les_Neilson
Valued Contributor II
1,264 Views

I reckon the one in the middle is the model. Made from papier mache; in the late 1960s judging by the psychedelic colouring. The large size compared to the VAX next to it, restricted its sales potential as a personal computer.

Les

0 Kudos
Steven_L_Intel1
Employee
1,264 Views

Actually, the one on the right is real - it's just a trick of perspective.

0 Kudos
Reply