简体   繁体   English

在Fortran 77中创建表

[英]Creating a Table in Fortran 77

Let me preface my question by saying that I am completely unqualified to be working in Fortran 77, but alas, here I am and I'm learning what I can. 首先,我要说我完全没有资格在Fortran 77中工作,但是我在这里,我正在学习我能做的。

I'm working on a project involving modeling flame properties under different conditions. 我正在从事一个涉及在不同条件下对火焰特性建模的项目。 Here I have a snippet that is outputting the first row in a table, giving labels for the rows underneath their appropriate columns. 在这里,我有一个片段,用于输出表中的第一行,并在其适当的列下方为行提供标签。 (KSYM is a array of strings that label the different chemical compounds present) (KSYM是一个字符串数组,用于标记存在的不同化合物)

   WRITE(LOUT,1) "Standoff(cm)", "Density(g/cm3)", 
 +  "HeatReleaseRate(erg/cm3/s)","Temperature(K)",
 +  KSYM(1),KSYM(2),KSYM(3),KSYM(4),KSYM(5),KSYM(6),KSYM(7),
 +  KSYM(8),KSYM(9),KSYM(10),KSYM(11),KSYM(12),KSYM(13),KSYM(14),
 +  KSYM(15),KSYM(16),KSYM(17),KSYM(18),KSYM(19),KSYM(20),
 +  KSYM(21),KSYM(22),KSYM(23),KSYM(24),KSYM(25),KSYM(26),
 +  KSYM(27),KSYM(28),KSYM(29),KSYM(30),KSYM(31),KSYM(32),
 +  KSYM(33)

then later in a loop for each standoff interval 然后稍后在每个僵持间隔的循环中

    WRITE(LOUT,6) X(J),F(J),HR(J),(SN(N,J), N=1,NATJ-1)

And here's the formats: 格式如下:

 1     FORMAT(A16,3X,A16,3X,A30,3X,A16,3X,80(A16,3X))
 2     FORMAT(I10)
 3     FORMAT(3(I10,3X))
 4     FORMAT(3(E17.7,3X))
 5     FORMAT(80(E17.7,3X))
 6     FORMAT(F17.7,3X,F17.7,3X,F20.7,3X,80(E15.5,3X))

My problem is that the data comes out in away that the labels in the first row and their appropriate columns don't stay aligned after the first few columns, making it difficult to read and manipulate. 我的问题是,数据消失了,因为第一行中的标签及其相应的列在前几列之后没有保持对齐,从而难以读取和操作。

The two possible solutions I can think of: 1. would be to either use the "T" format descriptor to make absolute columns 2. ignore the issue of immediate readability, insert commas or semicommas after every entry to then open in excel as a .CSV file 我可以想到的两种可能的解决方案:1.将使用“ T”格式描述符来创建绝对列2.忽略即时可读性的问题,在每个条目后插入逗号或半逗号,然后以excel形式在excel中打开。 CSV文件

Since I'm going to end up graphing the data eventually, I might as well do option 2. I've tried just adding "," in between each entry in the first code snippet, but I kept getting syntax errors, so I'm assuming I'm doing something wrong. 由于最终要对数据进行图形化处理,因此我不妨做选项2。我尝试在第一个代码段的每个条目之间添加“,”,但是我一直在获取语法错误,所以我我以为我做错了什么。

EDIT: 编辑:

To test idea 2, I've added ",", inbetween each entry. 为了测试想法2,我在每个条目之间添加了“,”。

       WRITE(LOUT,*) 'Name',KSYM(1),';',KSYM(2),';',KSYM(3),';',
 +  KSYM(4),';',KSYM(5),';',KSYM(6),';',KSYM(7),';',KSYM(8),';',
 +  KSYM(9),';',KSYM(10),';',KSYM(11),';',KSYM(12),';',
 +  KSYM(13),';',KSYM(14),';',KSYM(15),';',KSYM(16),';',
 +  KSYM(17),';',KSYM(18),';',KSYM(19),';',KSYM(20),';',
 +  KSYM(21),';',KSYM(22),';',KSYM(23),';',KSYM(24),';',
 +  KSYM(25),';',KSYM(26),';',KSYM(27),';',KSYM(28),';',
 +  KSYM(29),';',KSYM(30),';',KSYM(31),';',KSYM(32),';',
 +  KSYM(33)

But same syntax errors as before. 但是语法错误与以前相同。 I am using a peculiar compiler pgf77 if that makes any difference. 我正在使用一个特殊的编译器pgf77,如果有任何区别。

The basic problem is that your field widths in formats 1 and 6 are different. 基本问题是格式1和6的字段宽度不同。 In format 1 you have spacings of 3X and strings (labels) of length 16. Except one is A30. 在格式1中,您的间距为3X,字符串(标签)的长度为16。除了A30是一个。 In format 6, used for the values, you have spaces of 3, and fields for the numeric item with different lengths such as 17, 20 or 15. If you make every numeric format item 16 long, except for the 3rd item, then things should line up. 在用于值的格式6中,您有3个空格,数字项目的字段具有不同的长度,例如17、20或15。如果使每个数字格式项目的长度都变长,除了第3个项目,则为16。应该排队。

The first write would be much easier to read by replacing 33 separately indexed values of the array with an implied do-loop: (ksym (i), i=1,33). 通过用隐含的do-loop替换数组的33个单独索引的值,将更容易读取第一次写入:(ksym(i),i = 1,33)。 Might as well use array features instead of writing all of that stuff out! 最好使用数组功能,而不是全部写出来!

Format statements are largely incompatible with variable width output such as CSV. 格式语句与可变宽度输出(例如CSV)在很大程度上不兼容。 Instead, just use list-directed output: 相反,只需使用列表控制的输出:

    write (LOUT,*) 'Standoff(cm), Density(g/cm3), HeatReleaseRate(erg/cm3/s), Temperature(K)'

    do 101 i=1,n
    write (LOUT,*) X(J), ',', F(J), ',', HR(J), ',', (SN(N,J), ',', N=1,NATJ-1)
101 continue

(untested) (另)

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

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