File: read_xml.f90

package info (click to toggle)
espresso 5.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 146,004 kB
  • ctags: 17,245
  • sloc: f90: 253,041; sh: 51,271; ansic: 27,494; tcl: 15,570; xml: 14,508; makefile: 2,958; perl: 2,035; fortran: 1,924; python: 337; cpp: 200; awk: 57
file content (664 lines) | stat: -rw-r--r-- 17,574 bytes parent folder | download
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
!
!---------------------------------------------------------!
!   This module handles the reading of fields and cards   !
!   in case of xml input                                  !
!                                                         !
!   written by Simone Ziraldo (08/2010)                   !
!---------------------------------------------------------!
MODULE read_xml_module
  !
  !
  USE input_parameters
  !
  USE io_global, ONLY : ionode, ionode_id, xmlinputunit => qestdin
  USE mp,        ONLY : mp_bcast
  USE mp_images, ONLY : intra_image_comm
  USE iotk_module, ONLY : iotk_attlenx
  !
  ! ...default and checkin of fields
  !
  USE read_namelists_module, ONLY : control_defaults, system_defaults,&
       electrons_defaults, wannier_ac_defaults, ions_defaults, &
       cell_defaults, press_ai_defaults, wannier_defaults, control_bcast, &
       system_bcast, electrons_bcast, ions_bcast,cell_bcast, &
       press_ai_bcast, wannier_bcast, wannier_ac_bcast, control_checkin, &
       system_checkin, electrons_checkin, ions_checkin, cell_checkin, &
       wannier_checkin, wannier_ac_checkin, fixval
  !
  !
  USE read_xml_fields_module, ONLY : read_xml_fields
  USE read_xml_cards_module, ONLY : card_xml_atomic_species, card_xml_atomic_list, &
       card_xml_chain, card_xml_cell, card_xml_kpoints, card_xml_occupations, &
       card_xml_constraints, card_xml_climbing_images, card_xml_plot_wannier, card_default, card_bcast
  !
  !
  IMPLICIT NONE
  !
  SAVE
  !
  PRIVATE
  !
  PUBLIC :: read_xml
  !
CONTAINS
  !
  !
  !--------------------------------------------------------!
  !    This routine organizes the reading of the xml file  !
  !    depending on the program                            !
  !--------------------------------------------------------!
  SUBROUTINE read_xml( prog, attr )
    !
    !
    IMPLICIT NONE
    !
    !
    CHARACTER(len = 2), INTENT(IN) :: prog
    CHARACTER(len = *), INTENT(IN) :: attr
    INTEGER :: ierr
    !
    SELECT CASE (prog)
       !
    CASE ('PW')
       !
       CALL read_xml_common( attr, 'PW' )
       CALL read_xml_pw()
       !
    CASE ('CP')
       !
       CALL read_xml_common( attr, 'CP' )
       CALL read_xml_cp()
       !
    CASE default
       !
       CALL errore('read_xml', "xml input isn't implemented for "//prog//' program', 1)
       !
    END SELECT
    !
    !
    RETURN
    !
  END SUBROUTINE read_xml
  !
  !
  !--------------------------------------------------------!
  ! Common part of the reading: setting default values,    !
  ! reading of cell and atomic_species cards               !
  !--------------------------------------------------------!
  SUBROUTINE read_xml_common( attr, prog )
    !
    !
    USE iotk_module, ONLY : iotk_scan_attr
    !
    !
    IMPLICIT NONE
    !
    !
    CHARACTER (len = *), INTENT(IN) :: attr, prog
    !
    CHARACTER (len = 256) :: dummy
    INTEGER :: ierr
    LOGICAL :: found
    !
    !
    ! ... default settings for all parameters
    !
    CALL control_defaults( prog )
    CALL system_defaults( prog )
    CALL electrons_defaults( prog )
    CALL ions_defaults( prog )
    CALL cell_defaults( prog )
    CALL wannier_defaults( prog )
    CALL wannier_ac_defaults( prog )
    !
    !
    ! ... reading the attributes of the xml root node
    !
    IF (ionode) THEN
       !
       CALL iotk_scan_attr( attr, 'calculation', dummy, found = found, ierr = ierr )
       IF ( .not. found ) CALL errore( 'read_xml_cp', 'attribute calculation of root &
            &node is compulsory', abs(ierr) )
       !
       IF ( ierr /= 0 ) CALL errore( 'read_xml_cp', 'error reading calculation &
            &attribute of root node', 1 )
       calculation = trim( dummy )
       !
       CALL iotk_scan_attr( attr, 'prefix', dummy, found = found, ierr = ierr )
       IF ( ierr /= 0 ) CALL errore( 'read_xml_cp', 'error reading prefix attribute &
            &of root node', abs(ierr) )
       IF ( found ) prefix = trim( dummy )
       !
       CALL iotk_scan_attr( attr, 'title', dummy, found = found, ierr = ierr )
       IF ( ierr /= 0 ) CALL errore( 'read_xml_cp', 'error reading title attribute &
            &of root node', 1 )
       IF ( found ) title = trim( dummy )
       !
    END IF
    !
    !  ... bcast the read attributes
    !
    CALL mp_bcast( calculation, ionode_id, intra_image_comm )
    CALL mp_bcast( prefix, ionode_id, intra_image_comm )
    CALL mp_bcast( title, ionode_id, intra_image_comm )
    
    !
    ! ... fixing some default values using the calculation variable
    !
    CALL fixval( prog )
    !
    ! ... why this is compulsory? ( read autopilot.f90 )
    CALL card_default( 'INIT_AUTOPILOT' )
    !
    !
    !   ... reading CELL card
    !   
    CALL card_default( 'CELL' )
    !
    IF ( ionode ) THEN
       !
       CALL card_xml_cell( )
       !
    END IF
    !
    CALL card_bcast( 'CELL' )
    !
    !
    ! ...  reading ATOMIC_SPECIES card
    !
    CALL card_default( 'ATOMIC_SPECIES' )
    !
    IF ( ionode ) THEN
       !
       CALL card_xml_atomic_species( )
       !
    END IF
    !
    CALL card_bcast( 'ATOMIC_SPECIES' )
    !
    RETURN
    !
  END SUBROUTINE read_xml_common
  !
  !
  !--------------------------------------------------------!
  ! The remaining part of the reading for PW: fields and   !
  ! other cards                                            !
  !--------------------------------------------------------!
  SUBROUTINE read_xml_pw( )
    !
    !
    USE iotk_module, ONLY : iotk_scan_begin, iotk_scan_end
    USE iotk_unit_interf, ONLY : iotk_rewind
    !
    !
    IMPLICIT NONE
    !
    !
    INTEGER :: ierr
    CHARACTER (len = iotk_attlenx) :: attr
    CHARACTER (len = 30) :: field, card
    LOGICAL :: found_al, found
    !
    !
    ! ... reading ATOMIC_LIST or CHAIN cards
    !
    CALL card_default( 'ATOMIC_LIST' )
    CALL card_default( 'CHAIN' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, 'atomic_list', found = found_al, ierr = ierr )
       IF ( ierr /= 0 ) CALL errore( 'read_xml_pw', 'error scanning begin &
            &of atomic_list card', abs(ierr) )
       !
       IF ( found_al ) THEN
          !
          CALL iotk_scan_end( xmlinputunit, 'atomic_list', ierr = ierr )
          IF ( ierr /= 0 ) CALL errore( 'read_xml_pw', 'error scanning end &
               &of atomic_list card', abs( ierr ) )
          !
          CALL card_xml_atomic_list( )
          !
       ELSE
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
          CALL iotk_scan_begin( xmlinputunit, 'chain', found = found, ierr = ierr )
          IF ( ierr /= 0 ) CALL errore( 'read_xml_pw', 'error scanning begin &
               &of chain card', abs( ierr ) )
          !
          IF ( found ) THEN
             CALL iotk_scan_end( xmlinputunit, 'chain', ierr = ierr )
             IF ( ierr /= 0 ) CALL errore( 'read_xml_pw', 'error scanning &
                  &end of chain card', ABS( ierr ) )
             CALL card_xml_chain( )
          ELSE
             CALL errore('read_xml_pw',"neither atomic_list nor chain found", 1 )
          ENDIF
       ENDIF
    ENDIF
    !
    CALL mp_bcast( found_al, ionode_id, intra_image_comm)
    !
    IF (found_al) THEN
       CALL card_bcast( 'ATOMIC_LIST' )
    ELSE
       CALL card_bcast( 'CHAIN' )
    ENDIF
    !
    !
    !
    ! ... reading all the FIELDS
    !
    !
    ! ... we need to know if startingwfc and starting pot are set
    startingwfc = 'none'
    startingpot = 'none'
    !
    IF (ionode) THEN
       !
       CALL read_xml_fields()
       !
    END IF
    !
    !
    ! ... some fixval that the previous call of fixval wasn't
    ! ... able to do
    !
    IF ( calculation == 'nscf' .or. calculation == 'bands'  ) THEN
       !
       IF (startingpot == 'none') startingpot = 'file'
       IF (startingwfc == 'none') startingwfc = 'atomic+random'
       !
    ELSE IF ( restart_mode == 'from_scratch' ) THEN
       !
       IF (startingwfc == 'none') startingwfc = 'atomic+random'
       IF (startingpot == 'none') startingpot = 'atomic'
       !
    ELSE
       !
       IF (startingwfc == 'none') startingwfc = 'file'
       IF (startingpot == 'none') startingpot = 'file'
       !
    END IF
    !
    !
    ! 
    ! ... checkin of all the parameters inserted in the fields
    !
    IF ( ionode ) THEN
       !
       CALL control_checkin( 'PW' )
       CALL system_checkin( 'PW' )
       CALL electrons_checkin( 'PW' )
       CALL ions_checkin( 'PW' )
       CALL cell_checkin( 'PW' )
       CALL wannier_checkin( 'PW' )
       CALL wannier_ac_checkin( 'PW' )
       !
    END IF
    !
    !
    ! ... bcast all the field parameters
    !
    CALL control_bcast( )
    CALL system_bcast( )
    CALL electrons_bcast( )
    CALL ions_bcast( )
    CALL cell_bcast()
    CALL press_ai_bcast()
    CALL wannier_bcast()
    CALL wannier_ac_bcast()
    !
    !
    ! ... second step : reading of the remaining cards
    !
    !
    ! ... reading CONSTRAINTS card
    !
    card = 'constraints'
    CALL card_default( 'CONSTRAINTS' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim(card), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF ( found ) THEN
          !
          CALL card_xml_constraints( )
          !
          CALL iotk_scan_end( xmlinputunit, trim(card), ierr = ierr)
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'CONSTRAINTS' )
    !
    !
    ! ... reading K_POINTS card
    !
    card = 'k_points'
    CALL card_default( 'K_POINTS' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim( card ), attr = attr, found = found,&
            ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF ( found ) THEN
          !
          CALL card_xml_kpoints( attr )
          !
          CALL iotk_scan_end( xmlinputunit, trim( card ), ierr = ierr)
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          CALL errore('read_xml_pw', 'K_POINTS card was not found', 1)
          !
       END IF
       !
    END IF
    !
    CALL card_bcast( 'K_POINTS' )
    !
    !
    ! ... reading OCCUPATIONS card
    !
    card = 'occupations'
    CALL card_default( 'OCCUPATIONS' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim( card ), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF  ( found ) THEN
          !
          CALL card_xml_occupations()
          !
          CALL iotk_scan_end( xmlinputunit, trim( card ), ierr = ierr )
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'OCCUPATIONS' )
    !
       !
    ! ... reading CLIMBING_IMAGES card
    !
    card = 'climbing_images'
    CALL card_default( 'CLIMBING_IMAGES' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim( card ), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF ( found ) THEN
          !
          CALL card_xml_climbing_images()
          !
          CALL iotk_scan_end( xmlinputunit, trim( card ), ierr = ierr )
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'CLIMBING_IMAGES' )
    !
    !
    !
    !
    RETURN
    !
9   CALL errore('read_xml_pw', 'error reading begin tag of '//card//' card', ABS( ierr ) )
10  CALL errore('read_xml_pw', 'error reading end tag of '//card//' card', ABS( ierr ) )
    !
    !
  END SUBROUTINE read_xml_pw
  !
  !
  !
  !--------------------------------------------------------!
  ! The rest of the reading for CP program : fileds and    !
  ! other cards                                            !
  !--------------------------------------------------------!
  SUBROUTINE read_xml_cp( )
    !
    !
    USE iotk_module, ONLY : iotk_scan_begin, iotk_scan_end
    USE iotk_unit_interf, ONLY : iotk_rewind
    !
    !
    IMPLICIT NONE
    !
    !
    INTEGER :: ierr
    CHARACTER (len = iotk_attlenx) :: attr
    CHARACTER (len = 30) :: field, card
    LOGICAL :: found
    !
    !
    ! ... reading ATOMIC_LIST cards
    !
    !
    CALL card_default( 'ATOMIC_LIST' )
    !
    IF ( ionode ) THEN
       !
       IF ( ( trim( calculation ) == 'neb' ) .or. ( trim( calculation ) == 'smd' ) ) THEN
          CALL card_xml_chain ( )
       ELSE
          CALL card_xml_atomic_list ( )
       END IF
       !
    END IF
    !
    CALL card_bcast( 'ATOMIC_LIST' )
    !
    !
    ! ... reading all the FIELDS
    !
    IF (ionode) THEN
       !
       CALL read_xml_fields()
       !
    END IF
    !
    ! 
    ! ... checkin of all the parameters inserted in the fields
    !
    IF ( ionode ) THEN
       !
       CALL control_checkin( 'CP' )
       CALL system_checkin( 'CP' )
       CALL electrons_checkin( 'CP' )
       CALL ions_checkin( 'CP' )
       CALL cell_checkin( 'CP' )
       CALL wannier_checkin( 'CP' )
       CALL wannier_ac_checkin( 'CP' )
       !
    END IF
    !
    !
    ! ... bcast all the field parameters
    !
    CALL control_bcast( )
    CALL system_bcast( )
    CALL electrons_bcast( )
    CALL ions_bcast( )
    CALL cell_bcast()
    CALL press_ai_bcast()
    CALL wannier_bcast()
    CALL wannier_ac_bcast()
    !
    !
    ! ... second step : reading of the remaining cards
    !
    !
    ! ... reading CONSTRAINTS card
    !
    card = 'constraints'
    CALL card_default( 'CONSTRAINTS' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim(card), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF ( found ) THEN
          !
          CALL card_xml_constraints( )
          !
          CALL iotk_scan_end( xmlinputunit, trim(card), ierr = ierr)
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'CONSTRAINTS' )
    !
    ! ... reading OCCUPATIONS card
    !
    card = 'occupations'
    CALL card_default( 'OCCUPATIONS' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim( card ), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF  ( found ) THEN
          !
          CALL card_xml_occupations()
          !
          CALL iotk_scan_end( xmlinputunit, trim( card ), ierr = ierr )
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'OCCUPATIONS' )
    !
    !
    ! ... reading CLIMBING_IMAGES card
    !
    card = 'climbing_images'
    CALL card_default( 'CLIMBING_IMAGES' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim( card ), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF ( found ) THEN
          !
          CALL card_xml_climbing_images()
          !
          CALL iotk_scan_end( xmlinputunit, trim( card ), ierr = ierr )
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'CLIMBING_IMAGES' )
    !
    !
    ! ... reading CLIMBING_IMAGES card
    !
    card = 'plot_wannier'
    CALL card_default( 'PLOT_WANNIER' )
    !
    IF ( ionode ) THEN
       !
       CALL iotk_scan_begin( xmlinputunit, trim( card ), found = found, ierr = ierr )
       IF ( ierr /= 0 ) GO TO 9
       !
       IF ( found ) THEN
          !
          CALL card_xml_plot_wannier()
          !
          CALL iotk_scan_end( xmlinputunit, trim( card ), ierr = ierr )
          IF ( ierr /= 0 ) GOTO 10
          !
       ELSE
          !
          ! ... due to a iotk problem with gfortran compiler
          CALL iotk_rewind( xmlinputunit )
          !
       END IF
       !
    END IF
    !
    CALL mp_bcast ( found, ionode_id, intra_image_comm )
    !
    IF ( found ) CALL card_bcast( 'PLOT_WANNIER' )
    !
    !
    !
    !
    RETURN
    !
9   CALL errore('read_xml_pw', 'error reading begin tag of '//card//' card', ABS( ierr ) )
10  CALL errore('read_xml_pw', 'error reading end tag of '//card//' card', ABS( ierr ) )
    !
    !
  END SUBROUTINE read_xml_cp
  !
  !
  !
END MODULE read_xml_module