libsim Versione 7.2.4
file_utilities_test.f90
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! Programma di test per il module file_utilities
19! migliorare a piacimento
20PROGRAM file_test
21USE kinds
23IMPLICIT NONE
24
25TYPE(csv_record) :: csv_writer, csv_reader
26CHARACTER(len=80) :: charbuf, ccheck
27INTEGER :: nfield, ier, icheck, clen
28REAL :: rcheck
29DOUBLE PRECISION :: dcheck
30
31
32print*,'=== Testing file_utilities module ==='
33
34print*,'Checking csv_record writing'
35CALL init(csv_writer)
36CALL csv_record_addfield(csv_writer, 45)
37CALL csv_record_addfield_miss(csv_writer, imiss)
38CALL csv_record_addfield(csv_writer, 'Berlusconi mafioso')
39CALL csv_record_addfield(csv_writer, ' a''nvedi "er pecora"')
40CALL csv_record_addfield_miss(csv_writer, rmiss)
41print*,'Checking csv_record_getrecord'
42charbuf = csv_record_getrecord(csv_writer)
43IF (charbuf /= '45,,Berlusconi mafioso," a''nvedi ""er pecora""",') THEN
44 print*,'charbuf:',trim(charbuf)
45 CALL exit(1)
46ENDIF
47CALL delete(csv_writer)
48
49print*,'Checking csv_record reading'
50charbuf = '45, 897.4,903.1 ,,Berlusconi mafioso," a''nvedi ""er pecora""",'
51CALL init(csv_reader, charbuf, nfield=nfield)
52print*,'Checking nfield with a missing at the end'
53IF (nfield /= 7) THEN
54 print*,'nfield:',nfield
55 CALL exit(1)
56ENDIF
57
58print*,'Checking csv_record_getfield integer'
59CALL csv_record_getfield(csv_reader, icheck, ier)
60IF (ier /= 0) THEN
61 print*,'Error code:',ier
62 CALL exit(1)
63ENDIF
64IF (icheck /= 45) THEN
65 print*,'icheck:',icheck
66 CALL exit(1)
67ENDIF
68
69print*,'Checking csv_record_getfield real'
70CALL csv_record_getfield(csv_reader, rcheck, ier)
71IF (ier /= 0) THEN
72 print*,'Error code:',ier
73 CALL exit(1)
74ENDIF
75IF (abs(rcheck-897.4) > .1) THEN
76 print*,'rcheck:',rcheck
77 CALL exit(1)
78ENDIF
79CALL csv_record_getfield(csv_reader, dcheck, ier)
80IF (ier /= 0) THEN
81 print*,'Error code:',ier
82 CALL exit(1)
83ENDIF
84IF (abs(dcheck-903.1) > .1) THEN
85 print*,'dcheck:',dcheck
86 CALL exit(1)
87ENDIF
88
89print*,'Checking csv_record_getfield missing integer'
90CALL csv_record_getfield(csv_reader, icheck, ier)
91IF (ier /= 0) THEN
92 print*,'Error code:',ier
93 CALL exit(1)
94ENDIF
95IF (c_e(icheck)) THEN
96 print*,'icheck:',icheck
97 CALL exit(1)
98ENDIF
99
100print*,'Checking csv_record_getfield simple character'
101CALL csv_record_getfield(csv_reader, ccheck, clen, ier)
102IF (ier /= 0) THEN
103 print*,'Error code:',ier
104 CALL exit(1)
105ENDIF
106IF (ccheck(1:clen) /= 'Berlusconi mafioso') THEN
107 print*,'ccheck:',ccheck(1:clen)
108 CALL exit(1)
109ENDIF
110
111print*,'Checking csv_record_getfield quoted character'
112CALL csv_record_getfield(csv_reader, ccheck, clen, ier)
113IF (ier /= 0) THEN
114 print*,'Error code:',ier
115 CALL exit(1)
116ENDIF
117IF (ccheck(1:clen) /= ' a''nvedi "er pecora"') THEN
118 print*,'ccheck:',ccheck(1:clen)
119 CALL exit(1)
120ENDIF
121
122print*,'Checking csv_record_getfield empty character'
123CALL csv_record_getfield(csv_reader, ccheck, clen, ier)
124IF (ier /= 0) THEN
125 print*,'Error code:',ier
126 CALL exit(1)
127ENDIF
128IF (ccheck /= '') THEN
129 print*,'ccheck:',ccheck(1:clen)
130 CALL exit(1)
131ENDIF
132
133CALL delete(csv_reader)
134
135charbuf(len_trim(charbuf)-1:) = ' '
136CALL init(csv_reader, charbuf, nfield=nfield)
137print*,'Checking nfield'
138IF (nfield /= 6) THEN
139 print*,'nfield:',nfield
140 CALL exit(1)
141ENDIF
142
143print*,'Checking csv_record_getfield with empty charbuf'
144charbuf = ''
145CALL init(csv_reader, charbuf, nfield=nfield)
146print*,'Checking nfield'
147IF (nfield /= 1) THEN
148 print*,'nfield:',nfield
149 CALL exit(1)
150ENDIF
151
152CALL csv_record_getfield(csv_reader, ccheck, clen, ier)
153IF (ier /= 0) THEN
154 print*,'Error code:',ier
155 CALL exit(1)
156ENDIF
157IF (ccheck /= '') THEN
158 print*,'ccheck:',ccheck(1:clen)
159 CALL exit(1)
160ENDIF
161
162CALL delete(csv_reader)
163
164print*,'Checking csv_record_getfield with one empty, quoted record'
165charbuf = '""'
166CALL init(csv_reader, charbuf, nfield=nfield)
167print*,'Checking nfield'
168IF (nfield /= 1) THEN
169 print*,'nfield:',nfield
170 CALL exit(1)
171ENDIF
172
173CALL csv_record_getfield(csv_reader, ccheck, clen, ier)
174IF (ier /= 0) THEN
175 print*,'Error code:',ier
176 CALL exit(1)
177ENDIF
178IF (ccheck /= '') THEN
179 print*,'ccheck:',ccheck(1:clen)
180 CALL exit(1)
181ENDIF
182
183CALL delete(csv_reader)
184
185END PROGRAM file_test
Methods for successively adding fields to a csv_record object.
Methods for successively adding fields to a csv_record object.
Methods for successively obtaining the fields of a csv_record object.
Destructor for the class csv_record.
Constructor for the class csv_record.
Utilities for managing files.
Definition of constants to be used for declaring variables of a desired type.
Definition kinds.F90:245

Generated with Doxygen.