flibs/strings(n) 1.0 "flibs"

NAME

flibs/strings - Writing CSV files

TABLE OF CONTENTS

    TABLE OF CONTENTS
    SYNOPSIS
    DESCRIPTION
    ROUTINES
    COPYRIGHT

SYNOPSIS

use csv_file
call csv_next_record( lun )
call csv_write( lun, data )

DESCRIPTION

The csv_file module facilitates the writing of CSV files. Whereas it is very easy to read CSV files with Fortran, using list-directed read statements:

 
    integer           :: i1, i2
    character(len=20) :: string
    real              :: f3
    read(10,*) i1, i2, string, f3

for instance, writing them is slightly more complicated. The module helps with this by two routines, csv_next_record and csv_write.

The module supports writing scalar variables, one- and two-dimensional arrays according to a simple scheme. As CSV files are ordinary formatted files where each field is separated by commas and strings are possibly delimited by quotation marks ("), the procedure is this:

In more detail, the layout of the CSV-file can be described as follows: Note on the format: CSV-files apparently come in different guises (Kernighan and Pike, The practice of Programming, Addison-Wesley, 1999). This module uses the following rules:

ROUTINES

The module contains two public subroutines:

use csv_file
To import the subroutines for writing a CSV file, use this module.

call csv_next_record( lun )
Writes a new line to the file.

integer lun
The LU-number the file is connected to
call csv_write( lun, data )
Writes data to the file in the proper format.

integer lun
The LU-number the file is connected to

(...) data
The data to be written to the file. The type can be:

  • an integer or a real (single or double precision) number or a character string

  • an integer or a real (single or double precision)one-dimensional array or a one-dimensional array of character strings

  • an integer or a real (single or double precision)two-dimensional array or a two-dimensional array of character strings

COPYRIGHT

Copyright © 2005 Arjen Markus <arjenmarkus@sourceforge.net>