libsim Versione 7.2.6
vol7d_serialize_csv_class.F03
1! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
2! authors:
3! Davide Cesari <dcesari@arpa.emr.it>
4! Paolo Patruno <ppatruno@arpa.emr.it>
5
6! This program is free software; you can redistribute it and/or
7! modify it under the terms of the GNU General Public License as
8! published by the Free Software Foundation; either version 2 of
9! the License, or (at your option) any later version.
10
11! This program is distributed in the hope that it will be useful,
12! but WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14! GNU General Public License for more details.
15
16! You should have received a copy of the GNU General Public License
17! along with this program. If not, see <http://www.gnu.org/licenses/>.
18MODULE vol7d_serialize_csv_class
19use,INTRINSIC :: iso_c_binding
22IMPLICIT NONE
23
24TYPE,EXTENDS(vol7d_serialize) :: vol7d_serialize_csv
25 INTEGER :: csv_header=1
26 CONTAINS
27 PROCEDURE :: vol7d_serialize_optionparser
28 PROCEDURE :: vol7d_serialize_export
29END TYPE vol7d_serialize_csv
30
31PRIVATE
32PUBLIC vol7d_serialize_csv, vol7d_serialize_csv_new
33
34CONTAINS
35
36FUNCTION vol7d_serialize_csv_new() RESULT(this)
37TYPE(vol7d_serialize_csv) :: this
38
39this%vol7d_serialize = vol7d_serialize_new()
40
41END FUNCTION vol7d_serialize_csv_new
42
43
44SUBROUTINE vol7d_serialize_optionparser(this, opt, ext)
45CLASS(vol7d_serialize_csv),INTENT(inout) :: this
46TYPE(optionparser),INTENT(inout),OPTIONAL :: opt
47CHARACTER(len=*),INTENT(in),OPTIONAL :: ext
48
49IF (PRESENT(ext)) THEN
50 this%ext = ext
51ELSE
52 this%ext = 'csv'
53ENDIF
54
55! reset unconditionally some parameters
56this%vol7d_serialize%cachedesc = .true.
57
58! call the generic method
59CALL this%vol7d_serialize%vol7d_serialize_optionparser(opt, ext)
60! add a specific parameter
61IF (present(opt)) &
62 CALL optionparser_add(opt, ' ', 'csv-header', this%csv_header, 2, help= &
63 'write 0 to 2 header lines at the beginning of csv output')
64
65
66END SUBROUTINE vol7d_serialize_optionparser
67
68
69SUBROUTINE vol7d_serialize_export(this, iun)
70CLASS(vol7d_serialize_csv),INTENT(inout) :: this
71INTEGER,INTENT(in) :: iun
72
73CHARACTER(len=64),TARGET,ALLOCATABLE :: col(:)
74CHARACTER(len=2048),TARGET :: line
75CHARACTER(len=1),POINTER :: pline
76INTEGER :: i
77TYPE(vol7d_serialize_iterline) :: linei
78TYPE(vol7d_serialize_itercol) :: coli
79
80
81! old header to be erased in the future
82IF (this%csv_header >= 2) WRITE(iun,'(A)')'written by v7d_transform'
83
84! make csv header and count columns
85i = 0; line = ''
86coli = this%vol7d_serialize_itercol_new()
87DO WHILE(coli%next())
88 i = i + 1
89 IF (i /= 1) THEN
90 line(len_trim(line)+1:) = ','
91 ENDIF
92! use double pointer to avoid ICE on IBM xlf compiler
93 pline => line(len_trim(line)+1:len_trim(line)+1)
94 CALL coli%export(c_loc(pline))
95END DO
96
97IF (this%csv_header >= 1) WRITE(iun,'(A)')trim(line)
98ALLOCATE(col(i))
99
100! loop over lines
101linei = this%vol7d_serialize_iterline_new()
102DO WHILE(linei%next())
103 i = 0; line = ''
104 coli = linei%vol7d_serialize_itercol_new()
105 DO WHILE(coli%next())
106 i = i + 1
107 IF (i /= 1) THEN
108 line(len_trim(line)+1:) = ','
109 ENDIF
110 CALL coli%export(c_loc(col(i)(1:1)))
111 line(len_trim(line)+1:) = col(i)
112 END DO
113 WRITE(iun,'(A)')trim(line)
114END DO
115
116END SUBROUTINE vol7d_serialize_export
117
118END MODULE vol7d_serialize_csv_class
Add a new option of a specific type.
Module for parsing command-line optons.
Extension of vol7d_class for serializing the contents of a volume.
Class for serializing a vol7d object.

Generated with Doxygen.