files_multiple_test


files_multiple_test, an Octave code which demonstrates how a program can open multiple output files at one time, and write data to any one specific file it chooses.

To write data to a file, the code needs a filename, an fopen() statement that assigns a unique unit number to that filename, and fprintf() statements that send data to the file identified by unit number.

To handle two or three files is easy, but to handle an arbitrary number of files requires a little planning.

Supposing we need "n" files, we can create a "template" filename with some zeros in it, like "file00.txt", and call a function like "filename_inc()" which, each time, will return a filename with the numeric text incremented by 1:

        file01.txt
        file02.txt
        file03.txt
        ...
      

Licensing:

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

Languages:

files_multiple_test is available in a C version and a C++ version and a Fortran77 version and a Fortran90 version and a MATLAB version and an Octave version.

Related Data and Programs:

file_name_sequence, an Octave code which demonstrates ways to generate a sequence of filenames that can be used when generating images for an animation.

filum, an Octave code which works with information in text files.

table_io, an Octave code which reads and writes table files.

Reference:

  1. Jeanne Adams, Walter Brainerd, Jeanne Martin, Brian Smith, Jerrold Wagener,
    Fortran90 Handbook,
    Complete ANSI/ISO Reference,
    McGraw Hill, 1992,
    ISBN: 0-07-000406-4,
    LC: QA76.73.F28.F67.

Source Code:

test01() counts from 0 to 100. Each divisor of 2 is written to "divisor1.txt", each divisor of 3 is written to "divisor2.txt" and so on.

test02() watches a vector X, of length 100, as it changes 20 times.


Last revised on 19 June 2024.