csv_write(3f) - [M_csv] prints intrinsic type to a file assigned to LUN CSV_LUN (LICENSE:PD)
Synopsis
Description
Options
Examples
Author
License
function write_csv(g1,g2,g3,..g20|g(:)|g(:,:))
class(*),intent(in),optional :: g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 & g11,g12,g13,g14,g15,g16,g17,g18,g19,g20 or class(*),intent(in),optional :: g(:) or class(*),intent(in),optional :: g(:,:)
write_csv(3f) writes values in CSV(Comma-Separated Values) format. Either up to twenty scalar values, a vector, or a matrix is allowed as an argument(s).
The data is written to the LUN CSV_LUN, which is assumed to have been opened by the program.
If no arguments are provided the current line is terminated.
g[1-20] optional values to print the value of. May be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION, COMPLEX, or CHARACTER. The line is not advanced. g(:) a vector is written as a list of values. The line is not advanced. g(:,:) each row becomes an output line.
Sample program:
program demo_csv_write ! use M_csv, only : csv_write use M_csv, only : CSV_lun, CSV_TRUE, CSV_FALSE implicit none integer :: i integer :: v integer :: iarr(10)=[(i*10,i=1,size(iarr))] real,dimension(3,4) :: rand2d integer,dimension(3,4) :: array2dResults:open(newunit=CSV_lun,file=csv_test.csv,action=write) CSV_true=TRUE CSV_false=FALSE
! a number of scalar values in a row do i = 0,8 v = 10**i call csv_write( v ) enddo call csv_write() ! end line
! strings, some with double-quotes in them call csv_write( Aha,"Aha",Aha "!") call csv_write() ! end line
! lots of types call csv_write(string,.true.,.false.,111,23.45,10.20e15) call csv_write(3456.78901234d0,cmplx(huge(0.0),tiny(0.0))) call csv_write() ! end line
call csv_write(1.234) ! scalars call csv_write(1.234d0) call csv_write([1,2,3,4,5,6,7,8,9,10]) ! a vector call csv_write() ! end line
call csv_write(iarr) ! a vector call csv_write() ! end line ! even a vector needs a line end
call random_number( rand2d ) ! a table is written one row per line array2d = int( rand2d*100.0) call csv_write( array2d)
close( unit=CSV_lun)
end program demo_csv_write
1,10,100,1000,10000,100000,1000000,10000000,100000000 "Aha","""Aha""","Aha ""!""" "string",TRUE,FALSE,111,23.4500008,1.01999997E+16,3456.7890123400002,3.40282347E+38,1.17549435E-38 1.23399997,1.2340000000000000,1,2,3,4,5,6,7,8,9,10 10,20,30,40,50,60,70,80,90,100 64,95,86,28 78,94,18,36 10,89,6,86
John S. Urban
Public Domain
Nemo Release 3.1 | csv_write (3) | February 23, 2025 |