csv_file module¶
Description
Small module to facilitate writing CSV-files
The module contains the following subroutines:
- csv_next_record
 - Advance to the next record
 - csv_write_integer
 - Write a single integer to the CSV-file
 - csv_write_real
 - Write a single real to the CSV-file
 - csv_write_dble
 - Write a single double-precision real to the CSV-file
 - csv_write_char
 - Write a single character string to the CSV-file
 - csv_write_integer_1d
 - Write a 1D array of integers to the CSV-file
 - csv_write_real_1d
 - Write a 1D array of reals to the CSV-file
 - csv_write_dble_1d
 - Write a 1D array of double-precision real to the CSV-file
 - csv_write_char_1d
 - Write a 1D array of character strings to the CSV-file
 - csv_write_integer_2d
 - Write a 2D array of integers to the CSV-file
 - csv_write_real_2d
 - Write a 2D array of reals to the CSV-file
 - csv_write_dble_2d
 - Write a 2D array of double-precision real to the CSV-file
 - csv_write_char_2d
 - Write a 2D array of character strings to the CSV-file
 
For convenience, the generic name “csv_write” can be used instead of the individual routines.
The file to write to must already be opened as a LU-number is passed.
Layout of the CSV-file:¶
- single items are written to the end of the current record
 - one-dimensional items are also written to the end of the current record
 - two-dimensional items are written to separate records, one for each row
 - except for the two-dimensional versions, all routines allow
you to suppress advancing to the next record:
- for single items you must indicate whether to advance or not
 - for one-dimensional items, the argument is optional. Default is to advance.
 
 
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:
- items are always separated by a single comma (,)
 - string items are delimited by double quotes (”)
 - embedded double quotes are treated by doubling the quote
 - trailing blanks are considered irrelevant
 
Quick access
Subroutines and functions
- 
subroutine  
csv_file/csv_next_record(lun)¶ Go to the next record (convenience routine)
- Result:
 - The current record is closed, the next write will be to the new record
 - Note:
 - This is a convenience routine, it may result in a superfluous comma at the end of the previous record. This does not seem to be problematic, though, for MS Excel
 
Parameters: lun [integer,in] :: LU-number of the CSV-file 
- 
subroutine  
csv_file/csv_write_integer(lun, value, advance)¶ Write a single integer/real/double precision real to the CSV-file
Parameters: - lun [integer,in] :: LU-number of the CSV-file
 - value [integer,in] :: Value to write
 - advance [logical,in] :: Advance (.true.) or not, so that more items can be written to the same record
 
- 
subroutine  
csv_file/csv_write_real(lun, value, advance)¶ Write a single real to the CSV-file
Parameters: - lun [integer,in] :: LU-number of the CSV-file
 - value [real,in] :: Value to write
 - advance [logical,in] :: Advance (.true.) or not, so that more items can be written to the same record
 
- 
subroutine  
csv_file/csv_write_dble(lun, value, advance)¶ Write a double to the CSV file
Parameters: - lun [integer,in] :: LU-number of the CSV-file
 - value [real,in] :: Value to write
 - advance [logical,in] :: Advance (.true.) or not, so that more items can be written to the same record
 
- 
subroutine  
csv_file/csv_write_char(lun, value, advance)¶ Write a single character string to the CSV-file
Parameters: - lun [integer,in] :: LU-number of the CSV-file
 - value [character,in] :: Value to write
 - advance [logical,in] :: Advance (.true.) or not, so that more items can be written to the same record
 
- 
subroutine  
csv_file/csv_write_integer_1d(lun, array[, advance])¶ Write a one-dimensional array of integer items to the CSV-file
Parameters: - lun [integer,in]
 - array (*) [integer,in] :: Array to write
 
Options: advance [logical,in,optional]
- 
subroutine  
csv_file/csv_write_real_1d(lun, array[, advance])¶ Write a one-dimensional array of real items to the CSV-file
Parameters: - lun [integer,in]
 - array (*) [real,in] :: Array to write
 
Options: advance [logical,in,optional]
- 
subroutine  
csv_file/csv_write_dble_1d(lun, array[, advance])¶ Write a one-dimensional array of double items to the CSV-file
Parameters: - lun [integer,in]
 - array (*) [real,in] :: Array to write
 
Options: advance [logical,in,optional]
- 
subroutine  
csv_file/csv_write_char_1d(lun, array[, advance])¶ Write a one-dimensional array of character items to the CSV-file
Parameters: - lun [integer,in]
 - array (*) [character,in] :: Array to write
 
Options: advance [logical,in,optional]
- 
subroutine  
csv_file/csv_write_integer_2d(lun, array)¶ Write a two-dimensional array of integer items to the CSV-file
Parameters: - lun [integer,in]
 - array (,) [integer,in] :: Array to write
 
- 
subroutine  
csv_file/csv_write_real_2d(lun, array)¶ Write a two-dimensional array of real items to the CSV-file
Parameters: - lun [integer,in]
 - array (,) [real,in] :: Array to write
 
- 
subroutine  
csv_file/csv_write_dble_2d(lun, array)¶ Write a two-dimensional array of double items to the CSV-file
Parameters: - lun [integer,in]
 - array (,) [real,in] :: Array to write
 
- 
subroutine  
csv_file/csv_write_char_2d(lun, array)¶ Write a two-dimensional array of character items to the CSV-file
Parameters: - lun [integer,in]
 - array (,) [character,in] :: Array to write