forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_xml_primitives.f90
527 lines (438 loc) · 18.6 KB
/
read_xml_primitives.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
! read_xml_prims.f90 - Read routines for primitive data
!
! $Id: read_xml_prims.f90,v 1.7 2007/12/07 10:38:41 arjenmarkus Exp $
!
! Arjen Markus
!
! General information:
! This module is part of the XML-Fortran library. Its
! purpose is to help read individual items from an XML
! file into the variables that have been connected to
! the various tags. It is used by the code generated
! by the make_xml_reader program.
!
! Because the routines differ mostly by the type of the
! output variable, the body is included, to prevent
! too much repeated blocks of code with all the maintenance
! issues that causes.
!
module read_xml_primitives
use xmlparse
implicit none
private :: read_from_buffer
private :: read_from_buffer_integers
private :: read_from_buffer_reals
private :: read_from_buffer_doubles
private :: read_from_buffer_logicals
private :: read_from_buffer_words
interface read_from_buffer
module procedure read_from_buffer_integers
module procedure read_from_buffer_reals
module procedure read_from_buffer_doubles
module procedure read_from_buffer_logicals
module procedure read_from_buffer_words
end interface
contains
! skip_until_endtag --
! Routine to read the XML file until the end tag is encountered
!
! Arguments:
! info The XML file data structure
! tag The tag in question
! attribs Array of attributes and their values
! data Array of strings, representing the data
! error Has an error occurred?
!
subroutine skip_until_endtag( info, tag, attribs, data, error )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
character(len=*), dimension(:,:), intent(inout) :: attribs
character(len=*), dimension(:), intent(inout) :: data
logical, intent(out) :: error
integer :: noattribs
integer :: nodata
integer :: ierr
logical :: endtag
character(len=len(tag)) :: newtag
error = .true.
do
call xml_get( info, newtag, endtag, attribs, noattribs, &
data, nodata )
if ( xml_error(info) ) then
error = .true.
exit
endif
if ( endtag .and. newtag == tag ) then
exit
endif
enddo
end subroutine skip_until_endtag
! read_xml_integer --
! Routine to read a single integer from the parsed data
!
! Arguments:
! info XML parser structure
! tag The tag in question (error message only)
! endtag End tag found? (Dummy argument, actually)
! attribs Array of attributes and their values
! noattribs Number of attributes found
! data Array of strings, representing the data
! nodata Number of data strings
! var Variable to be filled
! has_var Has the variable been set?
!
subroutine read_xml_integer( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
integer, intent(inout) :: var
include 'read_xml_scalar.inc'
end subroutine read_xml_integer
! read_xml_line --
! Routine to read a single line of text from the parsed data
!
! Arguments:
! info XML parser structure
! tag The tag in question (error message only)
! endtag End tag found? (Dummy argument, actually)
! attribs Array of attributes and their values
! noattribs Number of attributes found
! data Array of strings, representing the data
! nodata Number of data strings
! var Variable to be filled
! has_var Has the variable been set?
!
subroutine read_xml_line( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
character(len=*), intent(inout) :: var
logical, intent(inout) :: has_var
character(len=len(attribs(1,1))) :: buffer
integer :: idx
integer :: ierr
!
! The value can be stored in an attribute value="..." or in
! the data
!
has_var = .false.
idx = xml_find_attrib( attribs, noattribs, 'value', buffer )
if ( idx > 0 ) then
var = buffer
has_var = .true.
else
do idx = 1,nodata
if ( data(idx) /= ' ' ) then
var = data(idx)
has_var = .true.
exit
endif
enddo
endif
end subroutine read_xml_line
! read_xml_real, ... --
! See read_xml_integer for an explanation
!
subroutine read_xml_real( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
real, intent(inout) :: var
include 'read_xml_scalar.inc'
end subroutine read_xml_real
subroutine read_xml_double( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
real(kind=kind(1.0d00)), intent(inout) :: var
include 'read_xml_scalar.inc'
end subroutine read_xml_double
subroutine read_xml_logical( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
logical, intent(inout) :: var
include 'read_xml_scalar.inc'
end subroutine read_xml_logical
subroutine read_xml_word( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
character(len=*), intent(inout) :: var
include 'read_xml_word.inc'
end subroutine read_xml_word
! read_xml_integer_array --
! Routine to read a one-dimensional integer array from the parsed
! ata
!
! Arguments:
! info XML parser structure
! tag The tag in question (error message only)
! endtag End tag found? (Dummy argument, actually)
! attribs Array of attributes and their values
! noattribs Number of attributes found
! data Array of strings, representing the data
! nodata Number of data strings
! var Variable to be filled
! has_var Has the variable been set?
!
subroutine read_xml_integer_array( info, tag, endtag, attribs, noattribs, data, &
nodata, var, has_var )
integer, dimension(:), pointer :: var
include 'read_xml_array.inc'
end subroutine read_xml_integer_array
! read_xml_line_array --
! Routine to read an array of lines of text from the parsed data
!
! Arguments:
! info XML parser structure
! tag The tag in question (error message only)
! attribs Array of attributes and their values
! noattribs Number of attributes found
! data Array of strings, representing the data
! nodata Number of data strings
! var Variable to be filled
! has_var Has the variable been set?
!
subroutine read_xml_line_array( info, tag, endtag, attribs, noattribs, data, &
nodata, var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
character(len=*), dimension(:), pointer :: var
logical, intent(inout) :: has_var
character(len=len(attribs(1,1))) :: buffer
integer :: idx
integer :: idxv
integer :: ierr
logical :: started
!
! The value can be stored in an attribute values="..." or in
! the data
!
has_var = .false.
idx = xml_find_attrib( attribs, noattribs, 'values', buffer )
if ( idx > 0 ) then
allocate( var(1:1) )
var(1) = buffer
if ( buffer /= ' ' ) then
has_var = .true.
endif
else
idxv = 0
started = .false.
do idx = 1,nodata
if ( data(idx) /= ' ' .or. started ) then
if ( .not. started ) then
allocate( var(1:nodata-idx+1) )
started = .true.
endif
idxv = idxv + 1
var(idxv) = data(idx)
endif
enddo
if ( started ) then
has_var = .true.
endif
endif
end subroutine read_xml_line_array
! read_xml_real_array, ... --
! See read_xml_integer_array for an explanation
!
subroutine read_xml_real_array( info, tag, endtag, attribs, noattribs, data, &
nodata, var, has_var )
real, dimension(:), pointer :: var
include 'read_xml_array.inc'
end subroutine read_xml_real_array
subroutine read_xml_double_array( info, tag, endtag, attribs, noattribs, data, &
nodata, var, has_var )
real(kind=kind(1.0d00)), dimension(:), pointer :: var
include 'read_xml_array.inc'
end subroutine read_xml_double_array
subroutine read_xml_logical_array( info, tag, endtag, attribs, noattribs, data, &
nodata, var, has_var )
logical, dimension(:), pointer :: var
include 'read_xml_array.inc'
end subroutine read_xml_logical_array
subroutine read_xml_word_array( info, tag, endtag, attribs, noattribs, data, &
nodata, var, has_var )
character(len=*), dimension(:), pointer :: var
include 'read_xml_array.inc'
end subroutine read_xml_word_array
! read_from_buffer_integers --
! Routine to read all integers from a long string
!
! Arguments:
! buffer String containing the data
! var Variable to be filled
! ierror Error flag
!
subroutine read_from_buffer_integers( buffer, var, ierror )
integer, dimension(:), pointer :: var
integer, dimension(:), pointer :: work
include 'read_from_buffer.inc'
end subroutine read_from_buffer_integers
! read_xml_from_buffer_reals, ... -
! See read_xml_from_buffer_integers for an explanation
!
subroutine read_from_buffer_reals( buffer, var, ierror )
real, dimension(:), pointer :: var
real, dimension(:), pointer :: work
include 'read_from_buffer.inc'
end subroutine read_from_buffer_reals
subroutine read_from_buffer_doubles( buffer, var, ierror )
real(kind=kind(1.0d00)), dimension(:), pointer :: var
real(kind=kind(1.0d00)), dimension(:), pointer :: work
include 'read_from_buffer.inc'
end subroutine read_from_buffer_doubles
subroutine read_from_buffer_logicals( buffer, var, ierror )
logical, dimension(:), pointer :: var
logical, dimension(:), pointer :: work
include 'read_from_buffer.inc'
end subroutine read_from_buffer_logicals
subroutine read_from_buffer_words( buffer, var, ierror )
character(len=*), dimension(:), pointer :: var
character(len=len(var)), dimension(:), pointer :: work
include 'read_from_buffer.inc'
end subroutine read_from_buffer_words
! read_xml_word_1dim, ... -
! Read an array of "words" (or ...) but from different elements
!
subroutine read_xml_integer_1dim( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
integer, dimension(:), pointer :: var
logical, intent(inout) :: has_var
integer,dimension(:), pointer :: newvar
character(len=len(attribs(1,1))) :: buffer
integer :: newsize
integer :: ierr
newsize = size(var) + 1
allocate( newvar(1:newsize) )
newvar(1:newsize-1) = var
deallocate( var )
var => newvar
call read_xml_integer( info, tag, endtag, attribs, noattribs, data, nodata, &
var(newsize), has_var )
end subroutine read_xml_integer_1dim
subroutine read_xml_real_1dim( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
real, dimension(:), pointer :: var
logical, intent(inout) :: has_var
real, dimension(:), pointer :: newvar
character(len=len(attribs(1,1))) :: buffer
integer :: newsize
integer :: ierr
newsize = size(var) + 1
allocate( newvar(1:newsize) )
newvar(1:newsize-1) = var
deallocate( var )
var => newvar
call read_xml_real( info, tag, endtag, attribs, noattribs, data, nodata, &
var(newsize), has_var )
end subroutine read_xml_real_1dim
subroutine read_xml_double_1dim( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
real(kind=kind(1.0d00)), dimension(:), pointer:: var
logical, intent(inout) :: has_var
real(kind=kind(1.0d00)), dimension(:), pointer:: newvar
character(len=len(attribs(1,1))) :: buffer
integer :: newsize
integer :: ierr
newsize = size(var) + 1
allocate( newvar(1:newsize) )
newvar(1:newsize-1) = var
deallocate( var )
var => newvar
call read_xml_double( info, tag, endtag, attribs, noattribs, data, nodata, &
var(newsize), has_var )
end subroutine read_xml_double_1dim
subroutine read_xml_logical_1dim( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
logical, dimension(:), pointer :: var
logical, intent(inout) :: has_var
logical, dimension(:), pointer :: newvar
character(len=len(attribs(1,1))) :: buffer
integer :: newsize
integer :: ierr
newsize = size(var) + 1
allocate( newvar(1:newsize) )
newvar(1:newsize-1) = var
deallocate( var )
var => newvar
call read_xml_logical( info, tag, endtag, attribs, noattribs, data, nodata, &
var(newsize), has_var )
end subroutine read_xml_logical_1dim
subroutine read_xml_word_1dim( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
character(len=*), dimension(:), pointer :: var
logical, intent(inout) :: has_var
character(len=len(var)),dimension(:), pointer :: newvar
character(len=len(attribs(1,1))) :: buffer
integer :: newsize
integer :: ierr
newsize = size(var) + 1
allocate( newvar(1:newsize) )
newvar(1:newsize-1) = var
deallocate( var )
var => newvar
call read_xml_word( info, tag, endtag, attribs, noattribs, data, nodata, &
var(newsize), has_var )
end subroutine read_xml_word_1dim
subroutine read_xml_line_1dim( info, tag, endtag, attribs, noattribs, data, nodata, &
var, has_var )
type(XML_PARSE), intent(inout) :: info
character(len=*), intent(in) :: tag
logical, intent(inout) :: endtag
character(len=*), dimension(:,:), intent(in) :: attribs
integer, intent(in) :: noattribs
character(len=*), dimension(:), intent(in) :: data
integer, intent(in) :: nodata
character(len=*), dimension(:), pointer :: var
logical, intent(inout) :: has_var
character(len=len(var)),dimension(:), pointer :: newvar
character(len=len(attribs(1,1))) :: buffer
integer :: newsize
integer :: ierr
newsize = size(var) + 1
allocate( newvar(1:newsize) )
newvar(1:newsize-1) = var
deallocate( var )
var => newvar
call read_xml_line( info, tag, endtag, attribs, noattribs, data, nodata, &
var(newsize), has_var )
end subroutine read_xml_line_1dim
end module read_xml_primitives