简体   繁体   中英

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.

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)

   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

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.

EDIT:

To test idea 2, I've added ",", inbetween each entry.

       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.

The basic problem is that your field widths in formats 1 and 6 are different. In format 1 you have spacings of 3X and strings (labels) of length 16. Except one is 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.

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). 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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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