libsim  Versione 7.2.1
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/>.
18 MODULE vol7d_serialize_csv_class
19 use,INTRINSIC :: iso_c_binding
22 IMPLICIT NONE
23 
24 TYPE,EXTENDS(vol7d_serialize) :: vol7d_serialize_csv
25  INTEGER :: csv_header=1
26  CONTAINS
27  PROCEDURE :: vol7d_serialize_optionparser
28  PROCEDURE :: vol7d_serialize_export
29 END TYPE vol7d_serialize_csv
30 
31 PRIVATE
32 PUBLIC vol7d_serialize_csv, vol7d_serialize_csv_new
33 
34 CONTAINS
35 
36 FUNCTION vol7d_serialize_csv_new() RESULT(this)
37 TYPE(vol7d_serialize_csv) :: this
38 
39 this%vol7d_serialize = vol7d_serialize_new()
40 
41 END FUNCTION vol7d_serialize_csv_new
42 
43 
44 SUBROUTINE vol7d_serialize_optionparser(this, opt, ext)
45 CLASS(vol7d_serialize_csv),INTENT(inout) :: this
46 TYPE(optionparser),INTENT(inout),OPTIONAL :: opt
47 CHARACTER(len=*),INTENT(in),OPTIONAL :: ext
48 
49 IF (PRESENT(ext)) THEN
50  this%ext = ext
51 ELSE
52  this%ext = 'csv'
53 ENDIF
54 
55 ! reset unconditionally some parameters
56 this%vol7d_serialize%cachedesc = .true.
57 
58 ! call the generic method
59 CALL this%vol7d_serialize%vol7d_serialize_optionparser(opt, ext)
60 ! add a specific parameter
61 IF (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 
66 END SUBROUTINE vol7d_serialize_optionparser
67 
68 
69 SUBROUTINE vol7d_serialize_export(this, iun)
70 CLASS(vol7d_serialize_csv),INTENT(inout) :: this
71 INTEGER,INTENT(in) :: iun
72 
73 CHARACTER(len=64),TARGET,ALLOCATABLE :: col(:)
74 CHARACTER(len=2048),TARGET :: line
75 CHARACTER(len=1),POINTER :: pline
76 INTEGER :: i
77 TYPE(vol7d_serialize_iterline) :: linei
78 TYPE(vol7d_serialize_itercol) :: coli
79 
80 
81 ! old header to be erased in the future
82 IF (this%csv_header >= 2) WRITE(iun,'(A)')'written by v7d_transform'
83 
84 ! make csv header and count columns
85 i = 0; line = ''
86 coli = this%vol7d_serialize_itercol_new()
87 DO 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))
95 END DO
96 
97 IF (this%csv_header >= 1) WRITE(iun,'(A)')trim(line)
98 ALLOCATE(col(i))
99 
100 ! loop over lines
101 linei = this%vol7d_serialize_iterline_new()
102 DO 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)
114 END DO
115 
116 END SUBROUTINE vol7d_serialize_export
117 
118 END 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.