0

伙计们。我正在尝试读取由 VAX FORTRAN 代码存储的科学数据文件。数据以结构形式存储,其文件和代码说明如下。我用谷歌搜索了 FORTRAN 77 可能会读取该文件,但我经常使用的语言不是 FORTRAN。那么有人可以告诉我如何将数据读入 FORTRAN 或 C/IDL/等。变量?例如,结构的 N 个单元存储在文件“pxm.mos”中,如何将数据读入我的变量中?非常感谢!以下是说明。

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 
4

1 回答 1

2

这并不难。您可以将结构想象成带有联合的 C 结构。每条记录是 2048 字节(VAX 术语中的 512 个“长字”),由五个 32 位整数、一个用于填充的 3 个整数数组、两个 32 位浮点数和一个 428 个浮点数数组组成。鉴于文件是固定长度的,因此无需担心元数据。可以忽略带有“缓冲区”的联合。

我会更关心文件是如何进入您的计算机的,假设它起源于 VMS 系统。您需要验证文件大小是 2048 字节的精确倍数。很可能它传输得很好,所以声明一个具有正确布局的结构并将其读入,逐条记录。

于 2015-04-21T17:50:14.790 回答