wfreq_io.f90 25 KB
Newer Older
Marco Govoni's avatar
Marco Govoni committed
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
!
! Copyright (C) 2015-2016 M. Govoni 
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST.
!
! Contributors to this file: 
! Marco Govoni
!
!-----------------------------------------------------------------------
MODULE wfreq_io
  !----------------------------------------------------------------------------
  !
  IMPLICIT NONE
  !
  SAVE
  !
  INTERFACE writeout_overlap
     MODULE PROCEDURE writeout_overlap_real, writeout_overlap_complex
  END INTERFACE 
  !
  INTERFACE readin_overlap
     MODULE PROCEDURE readin_overlap_real, readin_overlap_complex
  END INTERFACE 
  !
  INTERFACE writeout_solvegfreq
     MODULE PROCEDURE writeout_solvegfreq_real, writeout_solvegfreq_complex
  END INTERFACE 
  !
  INTERFACE readin_solvegfreq
     MODULE PROCEDURE readin_solvegfreq_real, readin_solvegfreq_complex
  END INTERFACE 
  !
  !
  CONTAINS
  !
  !-----------------------------------------------------------------------
  SUBROUTINE preallocate_solvewfreq( ik, nb_1, nb_2, idistr )
    !-----------------------------------------------------------------------
    !
    USE kinds,               ONLY : DP
    USE class_idistribute,   ONLY : idistribute
    USE mp_images,           ONLY : nimage,my_image_id,inter_image_comm
    USE mp,                  ONLY : mp_sum
    USE control_flags,       ONLY : gamma_only 
49
    USE westcom,             ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    USE mod_mpiio,           ONLY : mp_master_creates_and_preallocates
    !
    IMPLICIT NONE
    !
    ! I/O
    !
    INTEGER,INTENT(IN) :: ik, nb_1, nb_2
    TYPE(idistribute), INTENT(IN) :: idistr
    !
    ! Workspace
    !
    INTEGER :: ib, ii
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
64
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
65
66
67
68
69
70
71
72
73
74
75
76
77
    INTEGER :: nmode
    !
    IF( gamma_only ) THEN 
       nmode = 1
    ELSE
       nmode = 2
    ENDIF 
    !
    WRITE(c_glob_iks,'(i5.5)') ik
    DO ib = nb_1, nb_2
       !
       WRITE(c_glob_ib, '(i5.5)') ib
       !
78
       fname = TRIM( wfreq_save_dir )//"/w_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
79
       CALL mp_master_creates_and_preallocates( fname, n_lanczos*idistr%nglob * 1 )   
80
       fname = TRIM( wfreq_save_dir )//"/w_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
       CALL mp_master_creates_and_preallocates( fname, n_lanczos*idistr%nglob*idistr%nglob*nmode ) 
       !
    ENDDO
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE preallocate_solvegfreq( ik, nb_1, nb_2, idistr )
    !
    USE kinds,               ONLY : DP
    USE class_idistribute, ONLY : idistribute
    USE mp_images,           ONLY : nimage,my_image_id,inter_image_comm
    USE mp,                  ONLY : mp_sum
    USE control_flags,       ONLY : gamma_only 
96
    USE westcom,             ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    USE mod_mpiio,           ONLY : mp_master_creates_and_preallocates
    !
    IMPLICIT NONE
    !
    ! I/O
    !
    INTEGER,INTENT(IN) :: ik, nb_1, nb_2
    TYPE(idistribute), INTENT(IN) :: idistr
    !
    ! Workspace
    !
    INTEGER :: ib, ii
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
111
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
112
113
114
115
116
117
118
119
120
121
122
123
124
    INTEGER :: nmode
    !
    IF( gamma_only ) THEN 
       nmode = 1
    ELSE
       nmode = 2
    ENDIF 
    !
    WRITE(c_glob_iks,'(i5.5)') ik
    DO ib = nb_1, nb_2
       !
       WRITE(c_glob_ib, '(i5.5)') ib
       !
125
       fname = TRIM( wfreq_save_dir )//"/g_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
126
       CALL mp_master_creates_and_preallocates( fname, n_lanczos*idistr%nglob * 1 )   ! check nmode   
127
       fname = TRIM( wfreq_save_dir )//"/g_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
       CALL mp_master_creates_and_preallocates( fname, n_lanczos*idistr%nglob*idistr%nglob*nmode ) 
       !
    ENDDO
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_solvewfreq( glob_iks, glob_ib, diago, braket, nloc, nglob, myoffset)
    !
    ! WHO WRITES? ... root_bgrp
    ! WHAT?       ... diago(        n_lanczos ) 
    ! WHAT?       ... braket( ndim, n_lanczos ) 
    !
    USE kinds,               ONLY : DP
143
    USE westcom,             ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    USE mp_global,           ONLY : my_image_id,intra_bgrp_comm,me_bgrp,root_bgrp
    USE mp,                  ONLY : mp_bcast
    USE mod_mpiio,           ONLY : mp_write_dmsg_at
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(IN) :: diago(n_lanczos,nloc)
    REAL(DP),INTENT(IN) :: braket(nglob,n_lanczos,nloc)
    INTEGER,INTENT(IN) :: nloc, nglob, myoffset 
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
162
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
163
164
165
166
167
168
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
169
    fname = TRIM( wfreq_save_dir )//"/w_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
170
171
    CALL mp_write_dmsg_at( fname, diago, n_lanczos*nloc, n_lanczos*myoffset ) 
    !
172
    fname = TRIM( wfreq_save_dir )//"/w_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
173
174
175
176
177
178
179
180
181
182
183
184
185
    CALL mp_write_dmsg_at( fname, braket, nglob*n_lanczos*nloc, nglob*n_lanczos*myoffset )
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_solvewfreq( glob_iks, glob_ib, diago, braket, nloc, nglob, myoffset )
    !
    ! WHO READS?  ... root_bgrp
    ! WHAT?       ... diago(        n_lanczos ) 
    ! WHAT?       ... braket( ndim, n_lanczos ) 
    !
    USE kinds,          ONLY : DP
186
    USE westcom,        ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    USE mp_global,      ONLY : my_image_id,intra_bgrp_comm,me_bgrp,root_bgrp
    USE mp,             ONLY : mp_bcast
    USE mod_mpiio,      ONLY : mp_read_dmsg_at
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(OUT) :: diago(n_lanczos,nloc)
    REAL(DP),INTENT(OUT) :: braket(nglob,n_lanczos,nloc)
    INTEGER,INTENT(IN) :: nloc,nglob,myoffset
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
205
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
206
207
208
209
210
211
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
212
    fname = TRIM( wfreq_save_dir )//"/w_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
213
214
    CALL mp_read_dmsg_at( fname, diago, n_lanczos*nloc, n_lanczos*myoffset )
    !
215
    fname = TRIM( wfreq_save_dir )//"/w_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
216
217
218
219
220
221
222
223
224
225
226
227
228
    CALL mp_read_dmsg_at( fname, braket, nglob*n_lanczos*nloc, nglob*n_lanczos*myoffset )
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_imfreq( glob_ifreq,head,lambda )
    !
    ! WHO WRITES? ... me_bgrp ( IF my_image_id == 0 ) 
    ! WHAT?       ... head 
    ! WHAT?       ... lambda( n_pdep_eigen_to_use, n_pdep_eigen_to_use ) 
    !
    USE kinds,          ONLY : DP
229
    USE westcom,        ONLY : n_pdep_eigen_to_use,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    USE mp_global,      ONLY : my_image_id,inter_image_comm,me_image,root_image
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_ifreq
    REAL(DP),INTENT(IN) :: head
    REAL(DP),INTENT(IN) :: lambda(n_pdep_eigen_to_use,n_pdep_eigen_to_use)
    !
    ! Workspace
    !
    CHARACTER(LEN=6) :: c_glob_ifreq
    INTEGER :: iunout, ierr
246
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
247
248
249
    ! 
    !
    WRITE(c_glob_ifreq,'(i6.6)') glob_ifreq
250
    fname = TRIM( wfreq_save_dir )//"/w_imF"//c_glob_ifreq//".dat"
Marco Govoni's avatar
Marco Govoni committed
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
    !
    IF ( my_image_id == 0 ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_write( iunout, FILE = fname , BINARY = .FALSE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, 0, inter_image_comm )
    CALL errore( 'freq', 'cannot open freq file for writing', ierr )
    !
    IF ( my_image_id == 0 ) THEN  
       !
       CALL iotk_write_begin( iunout, "imCHI" )
       CALL iotk_write_dat( iunout, "head", head )
       CALL iotk_write_dat( iunout, "lambda", lambda )
       CALL iotk_write_end( iunout, "imCHI" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_write( iunout )
       !
    ENDIF
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_imfreq( glob_ifreq,head,lambda )
    !
    ! WHO READS?  ... me_bgrp .AND. my_image_id==0; bcasted via inter_image_comm
    ! WHAT?       ... head 
    ! WHAT?       ... lambda( n_pdep_eigen_to_use, n_pdep_eigen_to_use ) 
    !
    USE kinds,          ONLY : DP
288
    USE westcom,        ONLY : n_pdep_eigen_to_use,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
    USE mp_global,      ONLY : my_image_id,inter_image_comm
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_ifreq
    REAL(DP),INTENT(OUT) :: head
    REAL(DP),INTENT(OUT) :: lambda(n_pdep_eigen_to_use,n_pdep_eigen_to_use)
    !
    ! Workspace
    !
    CHARACTER(LEN=6) :: c_glob_ifreq
    INTEGER :: iunout, ierr
305
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
306
307
    ! 
    WRITE(c_glob_ifreq,'(i6.6)') glob_ifreq
308
    fname = TRIM( wfreq_save_dir )//"/w_imF"//c_glob_ifreq//".dat"
Marco Govoni's avatar
Marco Govoni committed
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
    !
    !
    IF ( my_image_id == 0 ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_read( iunout, FILE = fname , BINARY = .FALSE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, 0, inter_image_comm )
    CALL errore( 'freq', 'cannot open freq file for reading', ierr )
    !
    IF ( my_image_id == 0 ) THEN  
       !
       CALL iotk_scan_begin( iunout, "imCHI" )
       CALL iotk_scan_dat( iunout, "head", head )
       CALL iotk_scan_dat( iunout, "lambda", lambda )
       CALL iotk_scan_end( iunout, "imCHI" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_read( iunout )
       !
    ENDIF
    !
    CALL mp_bcast( head  , 0, inter_image_comm)
    CALL mp_bcast( lambda, 0, inter_image_comm)
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_solvegfreq_real( glob_iks, glob_ib, diago, braket, nloc, nglob, myoffset)
    !
    ! WHO WRITES? ... root_bgrp
    ! WHAT?       ... diago(        n_lanczos ) 
    ! WHAT?       ... braket( ndim, n_lanczos ) 
    !
    USE kinds,               ONLY : DP
350
    USE westcom,             ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
    USE mp_global,           ONLY : my_image_id,intra_bgrp_comm,me_bgrp,root_bgrp
    USE mp,                  ONLY : mp_bcast
    USE mod_mpiio,           ONLY : mp_write_dmsg_at
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(IN) :: diago(n_lanczos,nloc)
    REAL(DP),INTENT(IN) :: braket(nglob,n_lanczos,nloc)
    INTEGER,INTENT(IN) :: nloc, nglob, myoffset 
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
369
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
370
371
372
373
374
375
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
376
    fname = TRIM( wfreq_save_dir )//"/g_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
377
378
    CALL mp_write_dmsg_at( fname, diago, n_lanczos*nloc, n_lanczos*myoffset ) 
    !
379
    fname = TRIM( wfreq_save_dir )//"/g_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
380
381
382
383
384
385
386
387
388
389
390
391
392
    CALL mp_write_dmsg_at( fname, braket, nglob*n_lanczos*nloc, nglob*n_lanczos*myoffset ) 
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_solvegfreq_complex( glob_iks, glob_ib, diago, braket, nloc, nglob, myoffset)
    !
    ! WHO WRITES? ... root_bgrp
    ! WHAT?       ... diago(        n_lanczos ) 
    ! WHAT?       ... braket( ndim, n_lanczos ) 
    !
    USE kinds,               ONLY : DP
393
    USE westcom,             ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
    USE mp_global,           ONLY : my_image_id,intra_bgrp_comm,me_bgrp,root_bgrp
    USE mp,                  ONLY : mp_bcast
    USE mod_mpiio,           ONLY : mp_write_dmsg_at,mp_write_zmsg_at
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(IN) :: diago(n_lanczos,nloc)
    COMPLEX(DP),INTENT(IN) :: braket(nglob,n_lanczos,nloc)
    INTEGER,INTENT(IN) :: nloc, nglob, myoffset 
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
412
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
413
414
415
416
417
418
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
419
    fname = TRIM( wfreq_save_dir )//"/g_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
420
421
    CALL mp_write_dmsg_at( fname, diago, n_lanczos*nloc, n_lanczos*myoffset ) 
    !
422
    fname = TRIM( wfreq_save_dir )//"/g_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
423
424
425
426
427
428
429
430
431
432
433
434
435
    CALL mp_write_zmsg_at( fname, braket, nglob*n_lanczos*nloc, nglob*n_lanczos*myoffset ) 
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_solvegfreq_real( glob_iks, glob_ib, diago, braket, nloc, nglob, myoffset )
    !
    ! WHO READS?  ... root_bgrp
    ! WHAT?       ... diago(        n_lanczos ) 
    ! WHAT?       ... braket( ndim, n_lanczos ) 
    !
    USE kinds,          ONLY : DP
436
    USE westcom,        ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
    USE mp_global,      ONLY : my_image_id,intra_bgrp_comm,me_bgrp,root_bgrp
    USE mp,             ONLY : mp_bcast
    USE mod_mpiio,      ONLY : mp_read_dmsg_at
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(OUT) :: diago(n_lanczos,nloc)
    REAL(DP),INTENT(OUT) :: braket(nglob,n_lanczos,nloc)
    INTEGER,INTENT(IN) :: nloc,nglob,myoffset
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
455
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
456
457
458
459
460
461
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
462
    fname = TRIM( wfreq_save_dir )//"/g_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
463
464
    CALL mp_read_dmsg_at( fname, diago, n_lanczos*nloc, n_lanczos*myoffset )
    !
465
    fname = TRIM( wfreq_save_dir )//"/g_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
466
467
468
469
470
471
472
473
474
475
476
477
478
    CALL mp_read_dmsg_at( fname, braket, nglob*n_lanczos*nloc, nglob*n_lanczos*myoffset )
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_solvegfreq_complex( glob_iks, glob_ib, diago, braket, nloc, nglob, myoffset )
    !
    ! WHO READS?  ... root_bgrp
    ! WHAT?       ... diago(        n_lanczos ) 
    ! WHAT?       ... braket( ndim, n_lanczos ) 
    !
    USE kinds,          ONLY : DP
479
    USE westcom,        ONLY : n_pdep_eigen_to_use,iks_l2g,n_lanczos,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
    USE mp_global,      ONLY : my_image_id,intra_bgrp_comm,me_bgrp,root_bgrp
    USE mp,             ONLY : mp_bcast
    USE mod_mpiio,      ONLY : mp_read_dmsg_at,mp_read_zmsg_at
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(OUT) :: diago(n_lanczos,nloc)
    COMPLEX(DP),INTENT(OUT) :: braket(nglob,n_lanczos,nloc)
    INTEGER,INTENT(IN) :: nloc,nglob,myoffset
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
498
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
499
500
501
502
503
504
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
505
    fname = TRIM( wfreq_save_dir )//"/g_diag_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
506
507
    CALL mp_read_dmsg_at( fname, diago, n_lanczos*nloc, n_lanczos*myoffset )
    !
508
    fname = TRIM( wfreq_save_dir )//"/g_brak_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
509
510
511
512
513
514
515
516
517
518
519
520
    CALL mp_read_zmsg_at( fname, braket, nglob*n_lanczos*nloc, nglob*n_lanczos*myoffset )
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_overlap_real( labellina, glob_iks, glob_ib, overlap, no1, no2 )
    !
    ! WHO WRITES? ... root
    ! WHAT?       ... overlap( no1, no2 ) 
    !
    USE kinds,          ONLY : DP
521
    USE westcom,        ONLY : iks_l2g,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
    USE mp_world,       ONLY : mpime,root,world_comm 
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    CHARACTER(LEN=1),INTENT(IN) :: labellina
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(IN) :: overlap(no1,no2)
    INTEGER,INTENT(IN) :: no1,no2
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
    INTEGER :: iunout, ierr
541
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
542
543
544
545
546
547
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
548
    fname = TRIM( wfreq_save_dir )//"/over_"//labellina//"_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
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
    !
    IF ( mpime == root ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_write( iunout, FILE = fname , BINARY = .TRUE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, root, world_comm )
    CALL errore( 'freq', 'cannot open freq file for writing', ierr )
    !
    IF ( mpime == root ) THEN  
       !
       CALL iotk_write_begin( iunout, "OVER" )
       CALL iotk_write_dat( iunout, "overlap", overlap )
       CALL iotk_write_end( iunout, "OVER" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_write( iunout )
       !
    ENDIF
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_overlap_complex( labellina, glob_iks, glob_ib, overlap, no1, no2 )
    !
    ! WHO WRITES? ... root
    ! WHAT?       ... overlap( no1, no2 ) 
    !
    USE kinds,          ONLY : DP
584
    USE westcom,        ONLY : iks_l2g,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
    USE mp_world,       ONLY : mpime,root,world_comm 
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    CHARACTER(LEN=1),INTENT(IN) :: labellina
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    COMPLEX(DP),INTENT(IN) :: overlap(no1,no2)
    INTEGER,INTENT(IN) :: no1,no2
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
    INTEGER :: iunout, ierr
604
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
605
606
607
608
609
610
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
611
    fname = TRIM( wfreq_save_dir )//"/over_"//labellina//"_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
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
    !
    IF ( mpime == root ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_write( iunout, FILE = fname , BINARY = .TRUE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, root, world_comm )
    CALL errore( 'freq', 'cannot open freq file for writing', ierr )
    !
    IF ( mpime == root ) THEN  
       !
       CALL iotk_write_begin( iunout, "OVER" )
       CALL iotk_write_dat( iunout, "overlap", overlap )
       CALL iotk_write_end( iunout, "OVER" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_write( iunout )
       !
    ENDIF
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_overlap_real( labellina, glob_iks, glob_ib, overlap, no1, no2 )
    !
    ! WHO WRITES? ... root
    ! WHAT?       ... overlap( no1, no2 ) 
    !
    USE kinds,          ONLY : DP
647
    USE westcom,        ONLY : iks_l2g,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
    USE mp_world,       ONLY : mpime,root,world_comm 
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    CHARACTER(LEN=1),INTENT(IN) :: labellina
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    REAL(DP),INTENT(OUT) :: overlap(no1,no2)
    INTEGER,INTENT(IN) :: no1,no2
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
    INTEGER :: iunout, ierr
667
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
668
669
670
671
672
673
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
674
    fname = TRIM( wfreq_save_dir )//"/over_"//labellina//"_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
    !
    IF ( mpime == root ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_read( iunout, FILE = fname , BINARY = .TRUE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, root, world_comm )
    CALL errore( 'freq', 'cannot open freq file for reading', ierr )
    !
    IF ( mpime == root ) THEN  
       !
       CALL iotk_scan_begin( iunout, "OVER" )
       CALL iotk_scan_dat( iunout, "overlap", overlap )
       CALL iotk_scan_end( iunout, "OVER" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_read( iunout )
       !
    ENDIF
    !
    CALL mp_bcast( overlap, root, world_comm )
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_overlap_complex( labellina, glob_iks, glob_ib, overlap, no1, no2 )
    !
    ! WHO WRITES? ... root
    ! WHAT?       ... overlap( no1, no2 ) 
    !
    USE kinds,          ONLY : DP
712
    USE westcom,        ONLY : iks_l2g,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
    USE mp_world,       ONLY : mpime,root,world_comm 
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    CHARACTER(LEN=1),INTENT(IN) :: labellina
    INTEGER,INTENT(IN) :: glob_iks
    INTEGER,INTENT(IN) :: glob_ib
    COMPLEX(DP),INTENT(OUT) :: overlap(no1,no2)
    INTEGER,INTENT(IN) :: no1,no2
    !
    ! Workspace
    !
    CHARACTER(LEN=5) :: c_glob_iks
    CHARACTER(LEN=5) :: c_glob_ib
    INTEGER :: iunout, ierr
732
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
733
734
735
736
737
738
    !
    ! Generate the filename
    ! 
    WRITE(c_glob_iks,'(i5.5)') glob_iks
    WRITE(c_glob_ib, '(i5.5)') glob_ib
    !
739
    fname = TRIM( wfreq_save_dir )//"/over_"//labellina//"_K"//c_glob_iks//"B"//c_glob_ib//".dat"
Marco Govoni's avatar
Marco Govoni committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
    !
    IF ( mpime == root ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_read( iunout, FILE = fname , BINARY = .TRUE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, root, world_comm )
    CALL errore( 'freq', 'cannot open freq file for reading', ierr )
    !
    IF ( mpime == root ) THEN  
       !
       CALL iotk_scan_begin( iunout, "OVER" )
       CALL iotk_scan_dat( iunout, "overlap", overlap )
       CALL iotk_scan_end( iunout, "OVER" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_read( iunout )
       !
    ENDIF
    !
    CALL mp_bcast( overlap, root, world_comm )
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE writeout_solvehf( sigma_hf, nb, nk )
    !
    ! WHO WRITES? ... root
    ! WHAT?       ... sigma_hf(nb, nk) 
    !
    USE kinds,          ONLY : DP
777
    USE westcom,        ONLY : wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
778
779
780
781
782
783
784
785
786
787
788
789
790
791
    USE mp_world,       ONLY : mpime,root,world_comm 
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    REAL(DP),INTENT(IN) :: sigma_hf(nb,nk)
    INTEGER,INTENT(IN) :: nb, nk
    !
    ! Workspace
    !
    INTEGER :: iunout, ierr
792
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
793
794
795
    !
    ! Generate the filename
    !
796
    fname = TRIM( wfreq_save_dir )//"/hf.dat"
Marco Govoni's avatar
Marco Govoni committed
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
    !
    IF ( mpime == root ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_write( iunout, FILE = fname , BINARY = .TRUE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, root, world_comm )
    CALL errore( 'freq', 'cannot open freq file for writing', ierr )
    !
    IF ( mpime == root ) THEN  
       !
       CALL iotk_write_begin( iunout, "HF_DB" )
       CALL iotk_write_dat( iunout, "sigma_hf", sigma_hf )
       CALL iotk_write_end( iunout, "HF_DB" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_write( iunout )
       !
    ENDIF
    !
  END SUBROUTINE
  !
  !
  !
  SUBROUTINE readin_solvehf( sigma_hf, nb, nk )
    !
    ! WHO WRITES? ... root
    ! WHAT?       ... sigma_hf(nb, nk) 
    !
    USE kinds,          ONLY : DP
832
    USE westcom,        ONLY : iks_l2g,wfreq_save_dir
Marco Govoni's avatar
Marco Govoni committed
833
834
835
836
837
838
839
840
841
842
843
844
845
846
    USE mp_world,       ONLY : mpime,root,world_comm 
    USE mp,             ONLY : mp_bcast
    USE iotk_module
    !
    IMPLICIT NONE
    !
    ! I/O 
    !
    REAL(DP),INTENT(OUT) :: sigma_hf(nb,nk)
    INTEGER,INTENT(IN) :: nb, nk
    !
    ! Workspace
    !
    INTEGER :: iunout, ierr
847
    CHARACTER(LEN=512) :: fname
Marco Govoni's avatar
Marco Govoni committed
848
849
850
    !
    ! Generate the filename
    ! 
851
    fname = TRIM( wfreq_save_dir )//"/hf.dat"
Marco Govoni's avatar
Marco Govoni committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
    !
    IF ( mpime == root ) THEN
       !
       ! ... open XML descriptor
       !
       CALL iotk_free_unit( iunout, ierr )
       CALL iotk_open_read( iunout, FILE = fname , BINARY = .TRUE., IERR = ierr )
       !
    ENDIF
    !
    CALL mp_bcast( ierr, root, world_comm )
    CALL errore( 'freq', 'cannot open freq file for reading', ierr )
    !
    IF ( mpime == root ) THEN  
       !
       CALL iotk_scan_begin( iunout, "HF_DB" )
       CALL iotk_scan_dat( iunout, "sigma_hf", sigma_hf )
       CALL iotk_scan_end( iunout, "HF_DB" )
       !
       ! ... close XML descriptor
       !
       CALL iotk_close_read( iunout )
       !
    ENDIF
    !
    CALL mp_bcast( sigma_hf, root, world_comm )
    !
  END SUBROUTINE
  !  
END MODULE