-
Notifications
You must be signed in to change notification settings - Fork 2
/
mod_utilities.f90
1360 lines (1102 loc) · 37.5 KB
/
mod_utilities.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
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
665
666
667
668
669
670
671
672
673
674
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
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
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module mod_utilities
! Description:
! - Write arrays (of real and integer type) of up to
! 7 dimensions to text file or binary file columnwise
! - Print a matrix to a file as (row,col)
!
! Date Programmer Description of change
! ==== ========== =====================
! 20210407 A. Di Nola Original code
! 20210701 A. Di Nola Added read1dim,read2dim
! 20210725 A. Di Nola Added writescalar, readscalar
! 20210829 A. Di Nola Added print_vector, print_matrix
! 20210901 A. Di Nola Added write1dimBinary
! 20211120 A. Di Nola Added disp
! 20211123 A. Di Nola Added read3dim
! 20211216 A. Di Nola Added writeArr1
! USE other modules
implicit none
!private !Variables and internal proc are not visible outside of this module
! Visible outside
!public :: myerror
!Declare module variables
!Declare generic interface
interface print1dim
module procedure print1dim_i
module procedure print1dim_r
end interface
interface printMatrix
module procedure printMatrix_i
module procedure printMatrix_r
end interface
interface writescalar
module procedure writescalar_i
module procedure writescalar_r
end interface
interface write1dimBinary
module procedure write1dimBinary_i
module procedure write1dimBinary_r
end interface
interface writeArr1
module procedure writeArr1_i
module procedure writeArr1_r
end interface
interface write1dim
module procedure write1dim_i
module procedure write1dim_r
end interface
interface write2dim
module procedure write2dim_i
module procedure write2dim_r
end interface
interface write3dim
module procedure write3dim_i
module procedure write3dim_r
end interface
interface write4dim
module procedure write4dim_i
module procedure write4dim_r
end interface
interface write5dim
module procedure write5dim_i
module procedure write5dim_r
end interface
interface write6dim
module procedure write6dim_i
module procedure write6dim_r
end interface
interface write7dim
module procedure write7dim_i
module procedure write7dim_r
end interface
! - Read scalar
interface readscalar
module procedure readscalar_i
module procedure readscalar_r
end interface
! - Read 1-DIM array
interface read1dim
module procedure read1dim_i
module procedure read1dim_r
end interface
! - Read 2-DIM array
interface read2dim
module procedure read2dim_i
module procedure read2dim_r
end interface
! - Read 3-DIM array
interface read3dim
module procedure read3dim_i
module procedure read3dim_r
end interface
! - Display vector, matrix or 3-D array (with title)
interface disp
module procedure disp_scal, disp_vec, disp_mat, disp_3d, disp_vec_i, disp_mat_i, &
disp_scal_title, disp_vec_title, disp_mat_title, disp_3d_title, &
disp_vec_title_i, disp_mat_title_i, disp_mat_title_l, disp_mat_l
end interface disp
integer, parameter :: rt = 8
contains
!Module procedures
!**********************************************************
! PRINT VECTOR BASH
!**********************************************************
subroutine print_vector(v)
!**********************************************************
! PRINT_VECTOR prints a vector in the terminal
! Usage:
! call print_vector(v)
! INPUTS
! v : vector to print
!
!***********************************************************
!Local
integer :: i
!Dummy
real(8), intent(in) :: v(:)
do i = 1,size(v)
write(*,*) v(i)
end do
end subroutine print_vector
!**********************************************************
! PRINT MATRIX BASH
!**********************************************************
subroutine print_matrix(v)
!**********************************************************
! PRINT_MATRIX prints matrix in the terminal
! Usage:
! call print_matrix(v)
! INPUTS
! v : matrix to print
!
!***********************************************************
!Local
integer :: i
!Dummy
real, intent(in) :: v(:,:)
do i = 1,size(v,1)
write(*,*) v(i,:)
end do
end subroutine print_matrix
!**********************************************************
! PRINT MATRIX DATA FILE (.dat)
!**********************************************************
subroutine print_matrix_dat(namefile,v)
!**********************************************************
! PRINT_MATRIX_DAT print matrix in a dat file
! Usage:
! call print_matrix_dat(namefile,v)
! INPUTS
! namefile : name of the file
! v : matrix to print
!
!***********************************************************
!Local
integer :: i
!Dummy
real, intent(in) :: v(:,:)
character (len=*) :: namefile
open(1, file=namefile, action='write', status='replace')
do i = 1,size(v,1)
write(1,*) v(i,:)
end do
close(1)
end subroutine print_matrix_dat
!**********************************************************
! PRINT VECTOR DATA FILE (.dat)
!**********************************************************
subroutine print_vector_dat(namefile,v)
!**********************************************************
! PRINT_VECTOR_DAT prints vector in a dat file
! Usage:
! call print_matrix_dat(namefile,v,n)
! INPUTS
! namefile : name of the dat file
! v : vector to print
! n : size of the vector
!
!***********************************************************
!Local
integer :: i
!Dummy
real, intent(in) :: v(:)
character (len=*) :: namefile
open(1, file=namefile, action='write', status = 'replace')
do i = 1,size(v)
write(1,*) v(i)
end do
close(1)
end subroutine print_vector_dat
!-----------------------------------------------------------------!
! PRINT VECTOR
!-----------------------------------------------------------------!
subroutine print1dim_r(x)
! This subroutine prints a vector (1-dim array) x on the screen
implicit none
!Declare inputs:
real(8), intent(in) :: x(:)
integer :: i
!Display vector x on screen
do i = 1,size(x)
write(*,'(f12.6," ")'), x(i)
!write(*,'(" ")', advance = 'no')
enddo
write(*,"()")
write(*,*) " "
end subroutine print1dim_r
!-----------------------------------------------------------------!
subroutine print1dim_i(x)
! This subroutine prints a vector (1-dim array) x on the screen
implicit none
!Declare inputs:
integer, intent(in) :: x(:)
integer :: i
!Display vector x on screen
do i = 1,size(x)
write(*,'(I6," ")'), x(i)
!write(*,'(" ")', advance = 'no')
enddo
write(*,"()")
write(*,*) " "
end subroutine print1dim_i
!-----------------------------------------------------------------!
! PRINT MATRIX
!-----------------------------------------------------------------!
subroutine printMatrix_r(x,file_name)
! This subroutine prints matrix (2-dim array) x on file file_name.
! If filename is not present, matrix is displayed on the screen.
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:)
character(len=*), intent(in), optional :: file_name
integer :: unitno, ierr, i, j
if (present(file_name)) then
!Write matrix x(row,col) into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: printMatrix: cannot open file"
pause
stop
endif
do i = 1,size(x,1)
do j = 1,size(x,2)
write(unitno,'(f12.6," ")',advance='no'), x(i,j)
write(unitno,'(" ")', advance = 'no')
enddo
write(unitno,"()")
enddo
write(unitno,*) " "
close(unitno)
else
!Display matrix x(row,col) on screen
do i = 1,size(x,1)
do j = 1,size(x,2)
write(*,'(f12.6," ")',advance='no'), x(i,j)
write(*,'(" ")', advance = 'no')
enddo
write(*,"()")
enddo
write(*,*) " "
endif
end subroutine printMatrix_r
!-----------------------------------------------------------------!
subroutine printMatrix_i(x,file_name)
! This subroutine prints matrix (2-dim array) x on file file_name.
! If filename is not present, matrix is displayed on the screen.
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:)
character(len=*), intent(in), optional :: file_name
integer :: unitno, ierr, i, j
if (present(file_name)) then
!Write integer matrix x(row,col) into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: printMatrix: cannot open file"
pause
stop
endif
do i = 1,size(x,1)
do j = 1,size(x,2)
write(unitno,'(I6)',advance='no'), x(i,j)
enddo
write(unitno,*) " "
enddo
write(unitno,*) " "
close(unitno)
else
!Write integer matrix x(row,col) into a txt file
do i = 1,size(x,1)
do j = 1,size(x,2)
write(*,'(I6)',advance='no'), x(i,j)
enddo
write(*,*) " "
enddo
write(*,*) " "
endif
end subroutine printMatrix_i
!-----------------------------------------------------------------!
! WRITE SCALARS
!-----------------------------------------------------------------!
subroutine writescalar_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x
character(len=*), intent(in) :: file_name
integer :: unitno,i, ierr
!Write scalar x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: writescalar: cannot open file"
pause
stop
endif
write(unitno,*) x
close(unitno)
end subroutine writescalar_r
!-----------------------------------------------------------------!
subroutine writescalar_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x
character(len=*), intent(in) :: file_name
integer :: unitno,i, ierr
!Write scalar x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: writescalar: cannot open file"
pause
stop
endif
write(unitno,*) x
close(unitno)
end subroutine writescalar_i
!-----------------------------------------------------------------!
subroutine write1dimBinary_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:)
character(len=*), intent(in) :: file_name
integer :: unitno,i, ierr
!Write 1 dim array x into a BINARY file
!Note the commands FORM="unformatted", ACCESS="stream"
!and the fact that write(unitno) instead of write(unitno,*)
OPEN(NEWUNIT=unitno, FILE=file_name, FORM="unformatted", ACCESS="stream", STATUS="unknown", iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write1dimBinary: cannot open file"
pause
stop
endif
!do i = 1,size(x,dim=1)
! write(unitno) x(i)
!enddo
write(unitno) x
close(unitno)
end subroutine write1dimBinary_r
!-----------------------------------------------------------------!
subroutine write1dimBinary_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:)
character(len=*), intent(in) :: file_name
integer :: unitno, ierr
!Write 1 dim array x into a BINARY file
!Note the commands FORM="unformatted", ACCESS="stream"
!and the fact that write(unitno) instead of write(unitno,*)
OPEN(NEWUNIT=unitno, FILE=file_name, FORM="unformatted", ACCESS="stream", STATUS="unknown", iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write1dimBinary: cannot open file"
pause
stop
endif
!do i = 1,size(x,dim=1)
! write(unitno) x(i)
!enddo
write(unitno) x
close(unitno)
end subroutine write1dimBinary_i
!-----------------------------------------------------------------!
!-----------------------------------------------------------------!
! WRITE 1-D ARRAY as single line (faster than write1dim)
!-----------------------------------------------------------------!
subroutine writeArr1_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:)
character(len=*), intent(in) :: file_name
character(len=50) :: file_format
integer :: unitno, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write1dim: cannot open file"
pause
stop
endif
!write(unitno,"(330000(F20.16))") x
write(file_format,*) "(",size(x),"(F,:,','))"
write(unitno,trim(file_format)) x
close(unitno)
end subroutine writeArr1_r
!-----------------------------------------------------------------!
subroutine writeArr1_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:)
character(len=*), intent(in) :: file_name
character(len=50) :: file_format
integer :: unitno,i, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write1dim: cannot open file"
pause
stop
endif
!Assume size(x) is equal to 330000
!write(unitno,"(330000(F20.16))") x
write(file_format,*) "(",size(x),"(I,:,','))"
write(unitno,trim(file_format)) x
close(unitno)
end subroutine writeArr1_i
!-----------------------------------------------------------------!
!-----------------------------------------------------------------!
! WRITE 1 DIM ARRAYS as text files
!-----------------------------------------------------------------!
subroutine write1dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:)
character(len=*), intent(in) :: file_name
character(len=50) :: file_format
integer :: unitno, i, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write1dim: cannot open file"
pause
stop
endif
do i = 1,size(x)
write(unitno,*) x(i)
enddo
close(unitno)
end subroutine write1dim_r
!-----------------------------------------------------------------!
subroutine write1dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:)
character(len=*), intent(in) :: file_name
!character(len=*) :: file_format
integer :: unitno,i, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write1dim: cannot open file"
pause
stop
endif
!write(file_format,*) size(x)
do i = 1,size(x)
write(unitno,*) x(i)
enddo
close(unitno)
end subroutine write1dim_i
!-----------------------------------------------------------------!
! WRITE 2 DIM ARRAYS
!-----------------------------------------------------------------!
subroutine write2dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write2dim: cannot open file"
pause
stop
endif
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2)
enddo
enddo
close(unitno)
end subroutine write2dim_r
!-----------------------------------------------------------------!
subroutine write2dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2,ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write2dim: cannot open file"
pause
stop
endif
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2)
enddo
enddo
close(unitno)
end subroutine write2dim_i
!-----------------------------------------------------------------!
! WRITE 3 DIM ARRAYS
!-----------------------------------------------------------------!
subroutine write3dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write3dim: cannot open file"
pause
stop
endif
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3)
enddo
enddo
enddo
close(unitno)
end subroutine write3dim_r
!-----------------------------------------------------------------!
subroutine write3dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write3dim: cannot open file"
pause
stop
endif
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3)
enddo
enddo
enddo
close(unitno)
end subroutine write3dim_i
!-----------------------------------------------------------------!
! WRITE 4 DIM ARRAYS
!-----------------------------------------------------------------!
subroutine write4dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write4dim: cannot open file"
pause
stop
endif
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4)
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write4dim_r
!-----------------------------------------------------------------!
subroutine write4dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write4dim: cannot open file"
pause
stop
endif
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4)
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write4dim_i
!-----------------------------------------------------------------!
!-----------------------------------------------------------------!
! WRITE 5 DIM ARRAYS
!-----------------------------------------------------------------!
subroutine write5dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4,i5, ierr
!Write 5-dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write6dim: cannot open file"
pause
stop
endif
do i5 = 1,size(x,dim=5)
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4,i5)
enddo
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write5dim_r
!-----------------------------------------------------------------!
subroutine write5dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4,i5, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write6dim: cannot open file"
pause
stop
endif
do i5 = 1,size(x,dim=5)
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4,i5)
enddo
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write5dim_i
!-----------------------------------------------------------------!
!-----------------------------------------------------------------!
! WRITE 6 DIM ARRAYS
!-----------------------------------------------------------------!
subroutine write6dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:,:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4,i5,i6, ierr
!Write 6-dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write6dim: cannot open file"
pause
stop
endif
do i6 = 1,size(x,dim=6)
do i5 = 1,size(x,dim=5)
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4,i5,i6)
enddo
enddo
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write6dim_r
!-----------------------------------------------------------------!
subroutine write6dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:,:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4,i5,i6, ierr
!Write 1 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write6dim: cannot open file"
pause
stop
endif
do i6 = 1,size(x,dim=6)
do i5 = 1,size(x,dim=5)
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4,i5,i6)
enddo
enddo
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write6dim_i
!-----------------------------------------------------------------!
!-----------------------------------------------------------------!
! WRITE 7 DIM ARRAYS
!-----------------------------------------------------------------!
subroutine write7dim_r(x,file_name)
implicit none
!Declare inputs:
real(8), intent(in) :: x(:,:,:,:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4,i5,i6,i7, ierr
!Write 7 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write7dim: cannot open file"
pause
stop
endif
do i7 = 1,size(x,dim=7)
do i6 = 1,size(x,dim=6)
do i5 = 1,size(x,dim=5)
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4,i5,i6,i7)
enddo
enddo
enddo
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write7dim_r
!-----------------------------------------------------------------!
subroutine write7dim_i(x,file_name)
implicit none
!Declare inputs:
integer, intent(in) :: x(:,:,:,:,:,:,:)
character(len=*), intent(in) :: file_name
integer :: unitno,i1,i2, i3, i4,i5,i6,i7, ierr
!Write 7 dim array x into a txt file
open(newunit=unitno, file=file_name, status='replace', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error: write7dim: cannot open file"
pause
stop
endif
do i7 = 1,size(x,dim=7)
do i6 = 1,size(x,dim=6)
do i5 = 1,size(x,dim=5)
do i4 = 1,size(x,dim=4)
do i3 = 1,size(x,dim=3)
do i2 = 1,size(x,dim=2)
do i1 = 1,size(x,dim=1)
write(unitno,*) x(i1,i2,i3,i4,i5,i6,i7)
enddo
enddo
enddo
enddo
enddo
enddo
enddo
close(unitno)
end subroutine write7dim_i
!-----------------------------------------------------------------!
!=======================================================================!
subroutine readscalar_i(x,file_name)
implicit none
character(len=*), intent(in) :: file_name
integer, intent(out) :: x
integer :: unitno,i, ierr
open(newunit=unitno, file=file_name, status='old', iostat=ierr)
if (ierr/=0) then
write(*,*) "Error in readscalar: cannot open file"
pause
stop
endif
read(unitno,*) x
close(unitno)
end subroutine readscalar_i