2

I was attempting to convert some Indexed files created on the OpenVMS to plain flat sequential files to be used in Windows or Linux. Each indexed files contains x quantity of of POD structures (2594 bytes)

I have converted the files using a simple program such as this:

      PROGRAM     MAKE_FLAT
      BYTE        byte_array(2594)
      PARAMETER   FILE_IN  = 1
      PARAMETER   FILE_OUT = 2

      OPEN(UNIT=FILE_IN,  fmt='UNFORMATTED', 
     1    FILE='input.data',
     1    ORGANIZATION='INDEXED',
     1    ACCESS='SEQUENTIAL',
     1    KEY=(1:8:INTEGER), RECL=649)
      OPEN(UNIT=FILE_OUT, fmt='UNFORMATTED', 
     1    FILE='output.data')

      DO WHILE (.TRUE.)
        READ(FILE_IN, END=999) byte_array
          WRITE(FILE_OUT) byte_array
      END DO
  999 CONTINUE
      CLOSE(FILE_IN)
      CLOSE(FILE_OUT)
      END

If there are 1000 records in the file, and I should be expecting a file that is ~ 10002594 bytes, but instead it resulted with 10002044 bytes shown using:

DIR/FULL output.data

Why is it that the program writing fewer bytes per record? Did I do something wrong?

Using the built-in utility of OpenVMS gives me the expected flat file.

ANAL/RMS/FDL FILE.FDL input.data
EDIT/FDL/ANALY=FILE.FDL FILE.FDL

After changing organization from 'INDEXED' to 'SEQUENTIAL' and contiguous to 'YES', performing the following command gives me the flat file of correct size (include padding per record).

CONVERT/FDL=FILE.FDL input.data output.data
francescalus
  • 30,576
  • 16
  • 61
  • 96
Andrea Chua
  • 302
  • 2
  • 8
  • Why is this tagged C++? – Martin Bonner supports Monica Mar 06 '17 at 06:48
  • RECL should never be entered explicitly. The values are not compatible between compilers. `Inquire` should be used instead. See http://stackoverflow.com/questions/32686720/reading-writing-fortran-direct-access-unformatted-files-with-different-compilers – Vladimir F Героям слава Mar 06 '17 at 06:48
  • 2
    I observe that 649*4 is 2596 rather than 2594. Also, what makes you think that each record is short, rather than you have given up half way through? I would print the count of records read/written at the end of the program. – Martin Bonner supports Monica Mar 06 '17 at 06:54
  • 2596 is the length of the indexed record with padding, the actual structure is only 2594 bytes. Besides If i specified the array to be 2594 bytes, it should be writing 2594 bytes out isn't it? – Andrea Chua Mar 06 '17 at 07:27
  • Who knows. Which compiler is it? You are completely outside the standard (your code really shouldn't be called FORTRAN 77), this must be found in the manual. And don't expect this code to be compilable on a PC. – Vladimir F Героям слава Mar 06 '17 at 08:58

2 Answers2

1

If you do not really need to do this in a program, just use CONVERT

 $ CONVERT/FDL=FIXED.FDL IN-FILE OUT-FILE

You can use $ EDIT/FDL FIXED.FDL and follow the prompts for making a sequential file.

Mark Diaz
  • 193
  • 1
  • 10
0

2044 looks like the max. record size FORTRAN on VMS is using to write the data. If the file size is really 1000*2044 something is wrong.

What's the output of DUMP/HEADER/BLOCKS=COUNT=0 FOR002.DAT in the lines 'Record size', 'End of file block' and 'End of file byte'?

I would expect that the 2594 bytes are written in two records. Given that there are two bytes for a flag, you will see records with length 2044 and 554. (You can confirm this with a DUMP/RECORD FOR002.DAT/PAGE.) Each record has a record length field of two bytes. That is, you should have a file size of 1000*(2044+2+554+2) = 2602000.

You can double check that with the "End of file" data from the first DUMP command: (End of file block-1)*512 + End of file byte.

user2116290
  • 1,062
  • 5
  • 6
  • The output file is opened just as 'UNFORMATTED', which means VMS Fortran writes a file with the VFC (variable with fixed control) record type. Each record has a two-byte length and a two-byte flag field, of which only two bits in the flags are used to indicate whether the physical record is first, last or neither of the logical record. – Steve Lionel Mar 06 '17 at 17:52