0

guys. I am trying to read a scientific datum file stored by a VAX FORTRAN code. The data were stored in structure, of which the file and code descriptions are as follows. I googled that FORTRAN 77 might read the file, but my frequently used language is not FORTRAN. So can some one tell me how to read the data into a FORTRAN or C/IDL/etc. variables? For example, N units of the structure are stored in file "pxm.mos", how can I read the data into my variables? Thanks a lot! Here are the descriptions.

c     FILE name is "pxm.mos"
c     FILE AND RECORD STRUCTURE 
c       The files were created with form='unformatted', organization='sequential', 
c       access='sequential', recordtype='fixed', recordsize=512. 
c       The following VAX FORTRAN code specifies the record structure: 

            structure /PXMstruc/ 
              union 
                map 
                  integer*4 buffer(512) 
                end map 
                map 
                  integer*4 mod16           
                  integer*4 mod60          
                  integer*4 line            
                  integer*4 sct
                  integer*4 mfdsc          
                  integer*4 spare(3) 
                  real*4    datamin        
                  real*4    datamax        
                  real*4    data(0:427)   
                end map 
              end union 
            end structure 

            record /PXMstruc/ in 
Hunt
  • 1
  • 1
  • `structure` is a VAX fortran extension. You might first want to see if your current compiler supports it. – agentp Apr 21 '15 at 16:50

1 Answers1

2

This isn't hard. You can think of structure like a C struct, with unions. Each record is 2048 bytes (512 "longwords" in VAX terms) and consists of five 32-bit ints, an array of 3 ints for padding, two 32-bit floats and then an array of 428 floats. Given that the file is fixed length, there's no metadata to worry about. The union with "buffer" can be ignored.

I would be more concerned about how the file made its way to your computer, assuming it originated on a VMS system. You'll want to verify that the file size is an exact multiple of 2048 bytes. Most likely it transferred just fine, so declare a struct with the right layout and read it in, record by record.

Steve Lionel
  • 6,972
  • 18
  • 31
  • Note for unformatted sequential access the record will begin with a (probably) 32 bit integer indicating the record size. The record size is repeated at the end of the record, so the file size should be a multiple of 2048+8. – agentp Apr 21 '15 at 20:31
  • Also beware you may need to deal with byte ordering issues. – agentp Apr 21 '15 at 20:36
  • 1
    There will be no record size because of RECORDTYPE='FIXED'. VMS is little-endian, so indeed if you are on a big-endian system you'll need to do byte swapping. – Steve Lionel Apr 22 '15 at 15:00
  • for the record modern intel fortran handles the VAX `structure` and the nonstandard `open()` keywords just fine ( and of course Steve is correct there are no added record length headers ) – agentp Apr 22 '15 at 18:20
  • Values will be stored in the order as declared in the structure. Here, mod16 is not a "variable", it's a member of the structure. The entire structure is written as a single entity. I don't quite see the point of reading byte by byte - most languages can read a structure in a single operation. If you tell us which language you'll be using and what the computer and OS is, we can advise better. – Steve Lionel Apr 29 '15 at 13:11
  • Thank Steve again. I am trying to use IDL7.1 to read the data file. My OS is Fedora 20 x64. If IDL cannot do this, I think I can also try C or FORTRAN 77(with gcc/g77 in Fedora). If all ways blocked, I think I have to wait. BTW, I checked the size of the file, it is 872448, 426 times 2048 bytes. – Hunt Apr 29 '15 at 13:52
  • Never heard of IDL, but I found it in Wikipedia. You won't have to worry about byte ordering - just read the data, – Steve Lionel Apr 30 '15 at 15:31