reformat


reformat, a FORTRAN90 code which reads an ASCII text file, and writes a copy, with the property that every line (except perhaps the last one) has the same number of values on it.

This code was "inspired" by a situation in which the data in a file was not arranged as expected.

It was assumed that there were 4 items in every line.

But in fact, a free format had been used, and the system "felt free" to write 3 values per line, resulting in a ragged file of lines of alternating lengths of 3 and 1.

One can easily imagine other cases where 11 values would be written as 3/3/3/2.

And if the system had used another limit for the number of values per line, we would find that L values had been written as M/M/M/M/N instead.

The purpose of this code is allow for the repair of these "mistakes" in the simplest case. Thus, we imagine the command


        reformat ragged.txt smooth.txt 4
      
would read data from the file "ragged.txt", and write it out 4 words at a time.

In my experience, it has always been the case that several lines of the ragged file always exactly equaled one line of the smooth file. But it is easy to imagine more complicated situations.

The reasonable thing to do, I think, is to interpret the command as an attempt to get ALL the information in the ragged file into the smooth file, using the fixed limit.

This decision means the code can also be used to take a file of four words per line and turn it into one of 3 words per line.

This version of the code is only able to deal with files that contain nothing but real numbers. For a version that works with abstract 'words', see reword().

Usage:

reformat input output length
where

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

reformat is available in a FORTRAN90 version.

Related Data and codes:

CRRM, a C++ code which reads a text file and writes a copy which has no carriage returns.

CRRM, a C++ code which reads a text file and writes a copy which has no carriage returns.

DEBLANK, a C++ code which reads a text file and writes a copy which has no blank lines.

DECOMMENT, a C++ code which makes a copy of a text file which contains no "comment" lines (that begin with "#").

FILE_TRANSPOSE, a FORTRAN90 code which makes a "transposed" copy of a file, in which the I-th "word" of the J-th line becomes the J-th word of the I-th line.

FILUM, a FORTRAN90 library which performs various operations on files.

REWORD, a C++ code which reads a text file and writes a copy which has a fixed number of "words" per line.

TABLE_COLUMNS, a FORTRAN90 code which will extract the data in certain columns of a file.

UNCONTROL, a C++ code which makes a copy of a text file which contains no control characters.

WRAP, a C++ code which makes a copy of a text file in which no line is longer than a user-specified wrap length.

WRAP2, a C++ code which wraps long lines in a text file, but which wraps some lines "early", so as to avoid breaking words.

Source Code:


Last revised on 12 December 2005.