What is Fortran 14 output? - fortran

I am writing a javascript lexer/parser for DXF files and have come across this from the AutoDesk Drawing Interchange and File Formats document:
The first line of a group is a group code, which is a positive nonzero
integer output in FORTRAN I3--that is, right-justified and blank
filled in a three-character field (the exception to this is the
four-digit extended entity data group codes, which are output in
FORTRAN I4).
This clearly states what FORTRAN 13 output is, but what is FORTRAN 14 output? A Google search returns absolutely nothing. It must be similar to FORTRAN 13 in style, but how big is the field?
What is FORTRAN 14?

The documentation mentions I4, not 14. The Fortran output format I4 stands for an integer with width four characters.

Related

Fortran code to read formatted data file record wise

I got a Fortran code for K-means clustering from online.
As I am new to Fortran, I do not have an idea about the required input file format for the code as below.
How to prepare an input file according to this Fortran code?
infile1='D1_TR_all_cent63.dat'
OPEN(1,FILE=infile1,form='formatted',access='direct',
+ recl=429)
istep=nvectors/nclusters
DO i=1,nclusters
READ(1,23,rec=istep*(i-1)+1)(vec(j),j=1,42)
DO k=1,nelements
centroid(i,k)=vec(k)
END DO
END DO
23 format(42(f10.3))
It's looking for a file where each line contains 42 fields where it expects to find fixed point numbers. That's the 42(f10.3) in the format
statement. Each of those fields is 10 characters wide; there are no commas or other separator characters between them, although spaces are allowed.
For example:
123456.789 123.123 -123.123 12345.678 0.000
(and onward until there are 42 of those).
Most FORTRAN implementations will be a bit merciful on reading: You can leave off some of the after-decimal point digits, or have a space after the number (but you have to stay in the 10-character fields). But not all do, so it might be better to prepare your input with 6 digits (including sign, if needed, and allowing spaces instead) before the decimal point and three after.

Meaning of 3F7.1 in Fortran data format

I am trying to create an MDM file using HLM 7 Student version, but since I don't have access to SPSS I am trying to import my data using ASCII input. As part of this process I am required to input the data format Fortran style. Try as I might I have not been able to understand this step. Could someone familiar with Fortran (or even better HLM itself) explain to me how this works? Here is my current understanding
From the example EG3.DAT they give
(A4,1X,3F7.1)
I think
A4 signifies that the ID is 4 characters long.
1X means skip a space.
F.1 means that it should read 1 decimal places.
I am very confused about what 3F7 might mean.
EG3.DAT
2020 380.0 40.3 12.5
2040 502.0 83.1 18.6
2180 777.0 96.6 44.4
Below are examples from the help documents.
Rules for format statement
Format statement example
EG1 data format
EG2 data format
EG3 data format
One similar question is Explaining Fortran Write Format. Unfortunately it does not explicitly treat the F descriptor.
3F7.1 means 3 floating point numbers, each printed over 7 characters, each with one decimal number behind the decimal point. Leading characters are blanks.
For reading you don't need the .1 info at all, just read a floating point number from those 7 characters.
You guessed the meaning of A4 (string of four characters) and 1X (one blank) correctly.
In Fortran, so-called data edit descriptors (which format the input or output of data) may have repeat specifications.
In the format (A4,1X,3F7.1) the data edit descriptors are A4 and F7.1. Only F7.1 has a repeat specification (the number before the F). This simply means that the format is as though the descriptor appeared repeated: like F7.1, F7.1, F7.1. With a repeat specification of 1, or not given, there is just the single appearance.
The format of the question, then, is like
(A4,1X,F7.1,F7.1,F7.1)
This format is one that is covered by the rules provided in one of the images of the question. In particular, the aspect of repeat specification is given in rule 2 with the corresponding example of rule 3.
Further, in Fortran proper, a repeat count specifier may also be * as special case: that's like an exceptionally large repeat count. *(F7.1) would be like F7.1, F7.1, F7.1, .... I see no indication that this is supported by HLM but if this is needed a very large repeat count may be given instead.
In 1X the 1 isn't a repeat specification but an integral, and necessary, part of the position edit descriptor.
Procedure for making MDM file from excel for HLM:
-Make sure ALL the characters in ALL the columns line up
Select a column, then right click and select Format Cells
Then click on 'Custom' and go to the 'Type' box and enter the number
of 0s you need to line everything up
-Remove all the tabs from the document and replace them with spaces.
Open the document in word and use find and replace
-To save the document as .dat
First save it as .txt
Then open it in Notepad and save it as .dat
To enter the data format (FORTRAN-Style)
The program wants to read the data file space by space, so you have to specify it perfectly so that it reads the whole set properly.
If something is off, even by a single space, then your descriptive stats will be wonky compared to if you check them in another program.
Enclose the code with brackets ()
Divide the entries with commas ,
-Need ID column for all levels
ID column needs to be sorted so that it is in order from smallest to
largest
Use A# with # being the number of characters in the ID
Use an X1 to
move from the ID to the next column
-Need to say how many characters are needed in each column
Use F
After F is the number of characters needed for that column -Use F# (#= number)
There need to be enough character spaces to provide one 'gap' space
between each column
There need to be enough to character spaces to allow for the decimal
As part of the F you need to specify the number of decimal places
You do this by adding a decimal point after the F number and then a
number to represent the spaces you need -F#.#
You can use a number in front of the F so as to 'repeat' it. Not
necessary though. -#F#.#
All in all, it should look something like this:
(A4,X1,F4.0,F5.1)
Helpful links:
https://books.google.de/books?id=VdmVtz6Wtc0C&pg=PA78&lpg=PA78&dq=data+format+fortran+style+hlm&source=bl&ots=kURJ6USN5e&sig=fdtsmTGSKFxn04wkxvRc2Vw1l5Q&hl=en&sa=X&ved=0ahUKEwi_yPurjYrYAhWIJuwKHa0uCuAQ6AEIPzAC#v=onepage&q&f=false
http://www.ssicentral.com/hlm/help6/error/Problems_creating_MDM_files.pdf
http://www.ssicentral.com/hlm/help7/faq/FAQ_Format_specifications_for_ASCII_data.pdf

Reading integers of unknown width in Fortran

I am trying to read the integers in this line:
# 14 14 10
in Fortran 2008.
I attempted to use this code:
read(21, "(A, I,I,I)") garbage, a, b, c
but this is not standard conforming. Intel Fortran issues a warning "Fortran 2008 does not allow this edit descriptor. [I]" and other qeustions explain this problem: Nonnegative width required in format string Error: Nonnegative width required in format string at (1)
How do I properly read the integers of unknown width using Fortran 2008? I can not simply specify I2, because I do not know the width of the integer in advance.
As I hinted in the comments you can read items like this easily with the list directed I/O. The compiler then itself identifies which characters belong to each item in the input list and parse them. The items can be separated by spaces, commas or also a newline.
read(21,*) garbage, a, b, c
This is the most common way to read stuff interactively, but is also useful for parsing lists in data files (CSV and similar).
If on of the numbers were not present in the input record (line in a text file), the reading would continue on the next record.

Legacy Fortran FORMAT Edit Descriptor Syntax - Number Before Type?

In a snippet of legacy FORTRAN code (actual compiler unknown, suspect it was circa FORTRAN-77), I found a statement like this:
100 FORMAT(5I7.2)
Which I interpret to mean:
Integer
Width 7 characters, of which
2 characters are decimals (e.g., '12345.67')
What I can't find is an explanation of the leading '5'. I assume it means something to the effect of "repeating group," say--five groups of seven integers...etc.
Is this interpretation correct?
Fortran 2008 defines the I edit descriptor in Section 10.7.2.2. The relevant paragraphs to your question are (excerpts):
1 The Iw and Iw .m edit descriptors indicate that the field to be edited occupies w positions, except when w is zero.
When w is zero, the processor selects the field width. On input, w shall not be zero. The specified input/output
list item shall be of type integer.
5 The output field for the Iw .m edit descriptor is the same as for the Iw edit descriptor, except that the digit-string
consists of at least m digits. If necessary, sufficient leading zeros are included to achieve the minimum of m digits.
This means that I7.2 will be 7 digits wide and at least two digits will always be displayed, 0-padded.
The preceding 5 in the edit descriptor is a repeat specification (Fortran 2008 10.3.1 paragraph 1) and is a repeat count of the following edit descriptor.
Put together, 5I7.2 will output 5 integers, each 7 digits wide displaying a minimum of 2 digits being zero padded to two digits if necessary.

How can I left-justify numerical output in fortran?

I am writing some simple output in fortran, but I want whitespace delimiters. If use the following statement, however:
format(A20,ES18.8,A12,ES18.8)
I get output like this:
p001t0000 3.49141273E+01obsgp_oden 1.00000000E+00
I would prefer this:
p001t0000 3.49141273E+01 obsgp_oden 1.00000000E+00
I tried using negative values for width (like in Python) but no dice. So, is there a way to left-justify the numbers?
Many thanks in advance!
There's not a particularly beautiful way. However, using an internal WRITE statement to convert the number to a text string (formerly done with an ENCODE statement), and then manipulating the text may do what you need.
Quoting http://rsusu1.rnd.runnet.ru/develop/fortran/prof77/node168.html
An internal file WRITE is typically
used to convert a numerical value to a
character string by using a suitable
format specification, for example:
CHARACTER*8 CVAL
RVALUE = 98.6
WRITE(CVAL, '(SP, F7.2)') RVALUE
The WRITE statement will fill the
character variable CVAL with the
characters ' +98.60 ' (note that there
is one blank at each end of the
number, the first because the number
is right-justified in the field of 7
characters, the second because the
record is padded out to the declared
length of 8 characters).
Once a number has been turned into a
character-string it can be processed
further in the various ways described
in section 7. This makes it possible,
for example, to write numbers
left-justified in a field, ...
This is easier with Fortran 95, but still not trivial. Write the number or other item to a string with a write statement (as in the first answer). Then use the Fortran 95 intrinsic "ADJUSTL" to left adjust the non-blank characters of the string.
And really un-elegant is my method (I program like a cave woman), after writing the simple Fortran write format (which is not LJ), I use a combination of Excel (csv) and ultraedit to remove the spaces effectively getting the desired LJ followed directly by commas (which I need for my specific import format to another software). BF
If what you really want is whitespace between output fields rather than left-justified numbers to leave whitespace you could simply use the X edit descriptor. For example
format(A20,4X,ES18.8,4X,A12,4X,ES18.8)
will insert 4 spaces between each field and the next. Note that the standard requires 1X for one space, some of the current compilers accept the non-standard X too.
!for left-justified float with 1 decimal.. the number to the right of the decimal is how many decimals are required. Write rounds to the desired decimal space automatically, rather than truncating.
write(*, ['(f0.1)']) RValue !or
write(*, '(f0.1)') RValue
!for left-justified integers..
write(*, ['(i0)']) intValue !or
write(*, '(i0)') RValue
*after feedback from Vladimir, retesting proved the command works with or without the array brackets