简体   繁体   English

在Fortran中从文件中读取用空格分隔的字符串

[英]Reading strings from file separated by space in Fortran

I am reading large files in Fortran that contain mixed string/numeric data such as: 我正在读取Fortran中包含混合字符串/数字数据的大文件,例如:

114 MIDSIDE 0 0 O0002        436        437        584        438
115 SURFACE M00002 0 0        359        561        560        356
412236 SOLID   M00002 O00001 0      86157      82419      82418      79009

Currently, each line is read as a string and then post-processed to identify the proper terms. 当前,每行被读取为一个字符串,然后进行后处理以识别适当的术语。 I was wondering if there is any way to read each line as an integer followed by four strings separated by space , and then some more integers; 我想知道是否有任何方法可以将每一行读取为整数,然后读取四个以空格分隔的字符串,然后再读取一些整数; ie similar to '(I10,4(A6,X),4I10)' format, but without any information on the size of each string. 即类似于'(I10,4(A6,X),4I10)'格式,但没有有关每个字符串大小的任何信息。

Does not work (charr is empty, iarr(2:5)=0): 不起作用(字符为空,iarr(2:5)= 0):

INTEGER IARR(5)
CHARACTER*30 CHARR(4)
C open the file with ID=1
READ(1,*)IARR(1),(CHARR(I),I=1,4),(IARR(I),I=2,5)

Works (only for the last line in the data example): 有效(仅适用于数据示例的最后一行):

INTEGER IARR(5)
CHARACTER*30 CHARR(4)
C open the file with ID=1
READ(1,'(I10,4(A7,X),4I10)')IARR(1),(CHARR(I),I=1,4),(IARR(I),I=2,5)

The issue is I don't know a-priori what would be the size of each string. 问题是我不知道每个字符串的大小是什么。

I actually found out the f77rtl flag was used to compile the project, and when I removed the flag, the issue was resolved. 我实际上发现f77rtl标志用于编译项目,当我删除该标志时,问题已解决。 So the list-directed input format works just fine. 因此,列表导向的输入格式可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM