-
Notifications
You must be signed in to change notification settings - Fork 20
/
io_mod.f
2194 lines (2004 loc) · 63.2 KB
/
io_mod.f
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
! fortran_dialect=elf
!-----------------------------------------------------------------------
! PSCF - Polymer Self-Consistent Field Theory
! Copyright (2002-2016) Regents of the University of Minnesota
! contact: David Morse, [email protected]
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation. A copy of this license is included in
! the LICENSE file in the top-level PSCF directory.
!-----------------------------------------------------------------------
!****m* scf/io_mod
! MODULE
! io_mod - generic subroutine interfaces for file io
!
! PURPOSE
!
! The generic subroutine interfaces 'input' and 'output' provide
! a standard interface for reading parameters from and writing
! to file. Similar interfaces are used for integer, real, logical,
! and character(*) data, for 1D arrays of integers, real, or
! character(*) data, and 2D arrays of integers or real data.
!
! Input and output styles can be chosen from several that allow
! each data item to be accompanied by a comment string, namely:
! comment on line above data, comment before or after data on the
! same line, or no comment. Subroutines with names beginning with
! set_... allow the user to set values of private module variables
! that determine default input and output formats. These default
! values may also be overridden by the use of optional arguments
! to input and output routines
!
! PUBLIC PROCEDURES
!
! input - generic interface for input subroutines
! output - generic interface for output subroutine
!
! set_io_units - set input and output file unit numbers
! set_com_style - set comment style (same for input and output)
! set_output_fmt - set output format (field widths, float format)
! set_echo - choose whether to echo input
! set_com_use - choose whether to echo input comments
!
! AUTHOR
! David Morse (12/2003)
!
!*** -------------------------------------------------------------------
!****p* io_mod/input
! SUBROUTINE
!
! input - generic interface for reading data from file
! output - generic interface for writing data to file
!
! SYNOPSIS
!
! Scalar integer, real(long), character(*) data
!
! call input(data,[c,i,o,e,f,u])
! call output(data,[c,o,e,f]) ! integer, real, and logical
! call output(data,[c,o,e,f,l]) ! character(*)
!
! data = variable to be read and/or written to file
! integer, real(long)
!
! Vectors (1D arrays) integer, real, or character data:
!
! input(data,n,[c,s,i,o,e,f,u])
! output(data,n,[c,s,o,e,f]) ! integer or real
! output(data,n,[c,o,e,f,l]) ! character(*)
!
! data(:) = 1D array to be to be read from file
! integer or real(long)
!
! n = logical dimension of data(1:n)
! integer
!
! Matrices (2D arrays) of integer or real data (input & output)
!
! input(data,m,n,[c,s,i,o,e,f,u])
! output(data,m,n,[c,s,o,e,f])
!
! data(:,:) = 2D array to be to be read from file
! integer or real(long)
!
! m, n = logical dimensions of data(1:m,1:n)
! integers
!
! ARGUMENTS
!
! data = scalar, vector, or matrix data, as discussed above
!
! c = comment string for output (or echoed input)
! character(*) (optional)
!
! i, o = input and output file unit numbers
! integer (optional)
!
! e = echo flag: e=1 echo input, e=0 no echo
! integer (optional)
!
! f = comment style flag (see discussion)
! character(1) (optional)
!
! u = comment usage flag (see discussion)
! character(1) (optional) - only for input
!
! l = field width for character string output
! integer(optional) - only for character output
!
! s = vector or matrix io format flag - see discussion below
! character(1) (optional) - only for vector or matrix data
!
!***
!---------------------------------------------------------------------
!****p* io_mod/output
! SUBROUTINE
!
! output - generic interface for writing data to file
!
! SYNOPSIS
!
! Scalar integer, real(long), character(*) data
!
! call output(data,[c,o,e,f]) ! integer, real, and logical
! call output(data,[c,o,e,f,l]) ! character(*)
!
! Vectors (1D arrays) integer, real, or character data:
!
! output(data,n,[c,s,o,e,f]) ! integer or real
! output(data,n,[c,o,e,f,l]) ! character(*)
!
! Matrices (2D arrays) of integer or real data (input & output)
!
! output(data,m,n,[c,s,o,e,f])
!
! ARGUMENTS
!
! See arguments of subroutine input
!
!***
!-------------------------------------------------------------------
!****c io_mod/io_format
! COMMENT
!
! Comment styles:
!
! The module defines four styles in which comments strings
! can be associated with inputs and output data. These
! styles are associated with four possible values of a
! character(1) variable:
!
! 'N' -> None - no comment
! 'A' -> Above - comment on separate line above data
! 'L' -> Left - comment to the left of data on the same line
! 'R' -> Right - comment to the right of data on the same line
!
! The 'N' and 'A' style are defined for any type of data,
! while only 'N' and 'A' are defined for matrix data.
!
! A default comment style is given by the value of one the
! three global character(1) variables, which must have one of
! above values:
!
! scalar_com_style for scalar (int, real, or char)
! vector_com_style for vectors (int or real)
! matrix_com_style for matrices (int or real)
!
! These default comment style variables may modified by
! a subroutine call:
!
! call set_com_style([s],[v],[m])
!
! in which optional character(1) variables s, v, and m hold
! the desired values of the scalar, vector, and matrix
! comment styles, respectively.
!
! The default comment style may be overridden by passing
! input or output the optional character(1) argument f with
! one of the above values.
!
!-----------------------------------------------------------------
! Input format:
!
! All input routines use the default format read(iunit,*) for
! both comments and data. As a result of this:
!
! 1) The spacing of data and comments within an input record
! is irrelevant.
!
! 2) Input comment strings must consist of single character(*)
! tokens, i.e., they must either be strings with no spaces or
! other delimiters, or surrounded by quotation marks.
!
! Rule (2) must be obeyed in the 'L' comment style in order to
! to allow the comment to be distinguished from the input data.
! In the 'A' and 'R' styles, if a comment string contains spaces,
! the data is read corectly, but only the first word of comment
! is actually read.
!
!-----------------------------------------------------------------
! Output formats:
!
! The output format is controlled by the following global
! variables, whose values may be modified by calling
! set_output_format:
!
! com_width = width of comment output field (integer)
! data_width = width of data output field (integer)
! frac_width = # digits after decimal for reals #s (integer)
! fmt_ef = format for reals = 'E','F', or 'ES' (character*2)
!
! The field width data_width is used for scalar integer,
! real, and character data. Initial values are given in
! the declarations of these variables.
!
! Row vectors are output on a single record by repeating the
! format string for the corresponding scalar, preceded by a
! comment line in the 'A' comment style.
!
! Matrices are output as a sequence of row vectors,
! preceded by a comment line in the 'A' comment style.
! If the symmetry flag s='A' or s='L', then only the
! lower diagonal or below diagonal sector that is read
! on input is output (see below)
!
!-----------------------------------------------------------------
! Vector io format flag:
!
! s = 'R' Row vector - all data in one record
! (default if argument s is absent)
!
! Format (for comment style 'N' or 'A')
!
! data(1) data(2) data(3) ... data(N)
!
! s = 'C' Column vector -each element on a separate line
!
! Format (for comment style 'N' or 'A')
!
! data(1)
! data(2)
! ...
! data(N)
!
!-----------------------------------------------------------------
! Matrix io format flag:
!
! s = 'N' Normal or No symmetry
! (default if argument s is absent)
!
! Format for 3 x 3 matrix
!
! data(1,1) data(1,2) data(1,3)
! data(2,1) data(2,2) data(2,3)
! data(3,1) data(3,2) data(3,3)
!
! s = 'S' Symmetric matrix
! data(i,j) = data(j,i)
! read only data(i,j) for j <= i, i=1,..,m
!
! Format for 3 x 3 matrix:
!
! data(1,1)
! data(2,1) data(2,2)
! data(3,1) data(3,2) data(3,3)
!
!
! s = 'L' Symmetric matrix with zero diagonal elements
! data(i,j) = data(j,i)
! data(i,i) = 0
! read only data(i,j) for j < i, i=2,..,m
!
! Format for 3 x 3 matrix:
!
! data(2,1)
! data(3,1) data(3,2)
!
!-----------------------------------------------------------------
! Echoing:
!
! Input data and a comment are printed to an output file if:
!
! 1) The global variable default_echo has the value
! default_echo = 1, and the optional argument e is absent
!
! 2) the optional argument e is present, and e=1.
!
! Echoed output is output using the same comment style as that
! used for input.
!
! The default_echo variable may be reset by the subroutine call
!
! call set_echo(e)
!
! where e is the desired integer default value (e=1 for echoing,
! e=0 for no echoing)
!
!-----------------------------------------------------------------
! Comment Usage:
!
! The module defines three possible treatments of the
! comments that are read from the input file with data,
! which are associated with four possible values of a
! character(1) com_use variable:
!
! 'K' -> Keep - Return the input comment as argument c
! on output, if c is present, and use it
! in any echoed output.
!
! 'R' -> Replace - Replace the input comment by the input
! value of argument c in any echoed output.
!
! 'C' -> Check - Check that the input comment matches the
! input value of argument c, write error
! message if they do not match (not yet
! implemented)
!
! The choice of one of these actions is determined either by
! by the value of a global argument*1 variable default_com_use,
! or the value of the character(1) argument 'u', if present,
! both of which must take on one of the above values.
!
!***
!-------------------------------------------------------------------
module io_mod
use const_mod
use string_mod
implicit none
PRIVATE
PUBLIC :: input, output
PUBLIC :: set_io_units, set_com_style, set_output_fmt
PUBLIC :: set_echo, set_com_use
!-------------------------------------------------------------
! Global variables - declare and set initial values
! Default input and output file units :
integer :: default_iunit = 5 ! input file unit
integer :: default_ounit = 6 ! output file unit
! Default echo flag (echo 1, don't if 0)
integer :: default_echo = 1
! Default comment styles for scalar, vector, and matrix data:
character(1) :: scalar_com_style = 'A' ! data comment
character(1) :: vector_com_style = 'A' ! comment / data
character(1) :: matrix_com_style = 'A' ! comment / data
! Default com_use flag
character(1) :: default_com_use = 'R' ! replace
! Default vector and matrix symmetry flags:
character(1) :: default_vec_sym = 'R' ! row vector
character(1) :: default_mat_sym = 'N' ! normal (full matrix)
! Integer field widths for output of comments and data:
integer :: com_width = 40 ! comment field width
integer :: data_width = 20 ! data field width (total)
integer :: frac_width = 12 ! # digits after decimal
! Choice of format descriptor (E or F) for real numbers
character(2) :: fmt_ef = 'ES' ! must = F, E, or ES
! Output format strings for scalar variables:
character(3) :: fmt_c = 'A40' ! comment format
character(3) :: fmt_i = 'I20' ! integer format
character(7) :: fmt_r = 'ES20.10' ! real format
character(3) :: fmt_l = 'L20' ! logical format
! The initial values of the format strings
! fmt_c, fmt_i, fmt_r fmt_l, may be modified, but should
! be consistent with initial values of the integer field
! widths com_width , data_width, frac_width. Also, the
! floating point io descriptor E, F, or ES in fmt_r should
! be that given in the variable fmt_ef. Calls to the
! subroutine set_output_format allow the integer field
! widths and character format strings to be reset in
! a consistent manner.
! Global character length parameters (used in declarations)
integer, parameter :: com_len = 50 ! comment variables
integer, parameter :: fmt_len = 25 ! io format strings
! End global variables and parameters
!-------------------------------------------------------------
interface input
module procedure input_int
module procedure input_real
module procedure input_char
module procedure input_logic
module procedure input_int_vec
module procedure input_real_vec
module procedure input_char_vec
module procedure input_int_mat
module procedure input_real_mat
end interface
interface output
module procedure output_int
module procedure output_real
module procedure output_char
module procedure output_logic
module procedure output_int_vec
module procedure output_real_vec
module procedure output_char_vec
module procedure output_int_mat
module procedure output_real_mat
end interface
contains
!------------------------------------------------------------
!****p* io_mod/set_io_units
! SUBROUTINE
! set_io_units - set input and output file unit numbers
! SOURCE
!-------------------------------------------------------------------
subroutine set_io_units(i,o)
integer, intent(IN), optional :: i ! default input unit #
integer, intent(IN), optional :: o ! default output unit #
!***
if (present(i)) then
default_iunit = i
endif
if (present(o)) then
default_ounit = o
endif
end subroutine set_io_units
!-----------------------------------------------------------
!-------------------------------------------------------------------
!****p* io_mod/set_echo
! SUBROUTINE
! set_echo(e) - choose whether to echo input
! SOURCE
!-------------------------------------------------------------------
subroutine set_echo(e)
integer, intent(IN) :: e
!***
select case(e)
case(0,1)
default_echo = e
case default
write(6,*) 'Error: Incorrect argument',e,'to set_echo'
end select
end subroutine set_echo
!------------------------------------------------------------------
!------------------------------------------------------------------
!****p* io_mod/set_com_style
! SUBROUTINE
! set_com_style(s,v,m) - set comment style for input and output
! PURPOSE
! Allows new values to be set for the default comment
! styles for scalars, vectors, and matrices. All
! arguments are optional character(1) variables which
! must (if present) must have a valid value 'N', 'A',
! 'L' or 'R for a comment
! SOURCE
!------------------------------------------------------------------
subroutine set_com_style(s,v,m)
character(1), intent(IN), optional :: s ! scalar_com_style
character(1), intent(IN), optional :: v ! vector_com_style
character(1), intent(IN), optional :: m ! matrix_com_style
!***
if (present(s)) then
if ((s=='N').or.(s=='A').or.(s=='L').or.(s=='R')) then
scalar_com_style = s
else
write(6,*)'Error: Illegal scalar_com_style =', s
endif
endif
if (present(v)) then
if ((v=='N').or.(v=='A').or.(v=='L').or.(v=='R')) then
vector_com_style = v
else
write(6,*)'Error: Illegal vector_com_style =', v
endif
endif
if (present(m)) then
if ((m=='N').or.(m=='A')) then
matrix_com_style = m
else
write(6,*)'Error: Illegal matrix_com_style =', m
endif
endif
end subroutine set_com_style
!-------------------------------------------------------
!-------------------------------------------------------------------
!****p* io_mod/set_com_use
! SUBROUTINE
! set_com_use(u) - choose whether to echo input comments
! PURPOSE
! Reset default comment usage variable default_com_use
! to input value of argument u
!-------------------------------------------------------------------
subroutine set_com_use(u)
character(1), intent(IN) :: u ! new value of default_com_use
!***
if ((u=='K').or.(u=='R')) then
default_com_use = u
else if (u=='C') then
write(6,*)'Error checking not yet implemented, ignored'
else
write(6,*)'Error: Illegal scalar_com_use =', u
endif
end subroutine set_com_use
!-------------------------------------------------------
!-------------------------------------------------------------------
!****p* io_mod/set_output_fmt
! SUBROUTINE
! set_output_fmt - set output format (field widths, float format)
!
! PURPOSE
! Routine allows new values to be set for the integer
! variables com_width , data_width, and/or frac_width,
! which determine field widths for comment and data
! fields, and for the character(2) fmt_ef, which is the
! format specifier 'E' or 'F' used to output real numbers.
!
! Also resets the format strings fmt_c, fmt_i, and/or
! fmt_r, as needed, so as to agree with the new values
! of the field widths and fmt_ef.
!
! Subroutine arguments (all are optional arguments):
!
! c = com_width = width of comment field
! d = data_width = width of scalar data field
! f = frac_width = # of digits after decimal in floats
! e = fmt_ef = 'E', 'F', or 'ES' format style for floats
!
! SOURCE
!--------------------------------------------------------
subroutine set_output_fmt(c,d,f,e)
integer, intent(IN), optional :: c ! com_width
integer, intent(IN), optional :: d ! data_width
integer, intent(IN), optional :: f ! frac_width
character(2), intent(IN), optional :: e ! fmt_ef
!***
if (present(c)) then
if (c <= com_len) then
com_width = c
fmt_c = 'A' // trim(int_string(com_width ))
else
write(6,*) 'Error: Input com_width > com_len'
endif
endif
if (present(d)) then
data_width = d
fmt_i = 'I' // trim(int_string(data_width))
fmt_l = 'L' // trim(int_string(data_width))
endif
if (present(f)) then
frac_width = f
endif
if (present(e)) then
if ((trim(e) =='E').or.(trim(e) == 'F').or.e =='SE' ) then
fmt_ef = e
else
write(6,*) 'Error: Illegal value of fmt_ef=',e
endif
endif
if (present(d).or.present(f).or.present(e)) then
fmt_r = trim(fmt_ef) // trim(int_string(data_width))
fmt_r = trim(fmt_r) // '.' // trim(int_string(frac_width))
endif
end subroutine set_output_fmt
!-------------------------------------------------------
! Input subroutines (generic interface input)
subroutine input_int(data,c,i,o,e,f,u)
!--------------------------------------------------------------
integer, intent(OUT) :: data
character(*), optional :: c ! comment
integer, intent(IN), optional :: i ! input unit #
integer, intent(IN), optional :: o ! output unit #
integer, intent(IN), optional :: e ! echo flag
character(1), intent(IN), optional :: f ! comment style
character(1), intent(IN), optional :: u ! comment usage
! Local variables
integer :: iunit, ounit, echo
character(1) :: com_style, com_use
character(com_len) :: comment
! Set defaults
if (present(i)) then
iunit = i
else
iunit = default_iunit
endif
if (present(o)) then
ounit = o
else
ounit = default_ounit
endif
echo = default_echo
if (present(e)) then
if ((e==0).or.(e==1)) then
echo = e
else
write(6,*) 'Error: Illegal value of e=',e
endif
endif
if (present(f)) then
if ((f=='N').or.(f=='A').or.(f=='L').or.(f=='R')) then
com_style = f
else
write(ounit,*) 'Error: incorrect f = ' , f , ' in in_int'
com_style = scalar_com_style
endif
else
com_style = scalar_com_style
endif
if (present(u)) then
com_use = u
else
com_use = default_com_use
endif
if (.not.present(c)) com_use = 'K'
! Read data
select case(com_style)
case('N') ! No comment
read(iunit,*) data
case('A') ! comment above
read(iunit,*) comment
read(iunit,*) data
case('L') ! comment to left of data
read(iunit,*) comment, data
case('R') ! comment to right of data
read(iunit,*) data, comment
end select
if (com_style /= 'N') then
comment = adjustl(comment)
if ((com_use == 'K').and.present(c)) then
c = comment
endif
endif
if (echo == 1) then ! echo in to ounit
if ((com_use == 'R').and.present(c)) then
comment = adjustl(c)
endif
call output(data,comment,ounit,com_style)
endif
end subroutine input_int
!--------------------------------------------------------------
subroutine input_real(data,c,i,o,e,f,u)
!--------------------------------------------------------------
real(long), intent(OUT) :: data !
character(*), optional :: c ! comment
integer, intent(IN), optional :: i ! input unit #
integer, intent(IN), optional :: o ! output unit #
integer, intent(IN), optional :: e ! echo flag
character(1), intent(IN), optional :: f ! comment style
character(1), intent(IN), optional :: u ! comment usage
! Local variables
integer :: iunit, ounit, echo
character(1) :: com_style, com_use
character(com_len) :: comment
! Set defaults
if (present(i)) then
iunit = i
else
iunit = default_iunit
endif
if (present(o)) then
ounit = o
else
ounit = default_ounit
endif
echo = default_echo
if (present(e)) then
if ((e==0).or.(e==1)) then
echo = e
else
write(6,*) 'Error: Illegal value of e=',e
endif
endif
if (present(f)) then
if ((f=='N').or.(f=='A').or.(f=='L').or.(f=='R')) then
com_style = f
else
write(ounit,*) 'Error: incorrect f = ' , f , ' in in_real'
com_style = scalar_com_style
endif
else
com_style = scalar_com_style
endif
if (present(u)) then
com_use = u
else
com_use = default_com_use
endif
! Read data
select case(com_style)
case('N') ! No comment
read(iunit,*) data
case('A') ! comment above
read(iunit,*) comment
read(iunit,*) data
case('L') ! comment to left of data
read(iunit,*) comment, data
case('R') ! comment to right of data
read(iunit,*) data, comment
end select
if (com_style /= 'N') then
comment = adjustl(comment)
if ((com_use == 'K').and.present(c)) then
c = comment
endif
endif
if (echo == 1) then
if ((com_use == 'R').and.present(c)) then
comment = adjustl(c)
endif
call output(data,comment,ounit,com_style)
endif
end subroutine input_real
!--------------------------------------------------------------
subroutine input_char(data,c,i,o,e,f,u)
!--------------------------------------------------------------
character(*), intent(OUT) :: data ! input string
character(*), optional :: c ! comment
integer, intent(IN), optional :: i ! input unit #
integer, intent(IN), optional :: o ! output unit #
integer, intent(IN), optional :: e ! echo flag
character(1), intent(IN), optional :: f ! comment style
character(1), intent(IN), optional :: u ! comment usage
! Local variables
integer :: iunit, ounit, echo
character(1) :: com_style, com_use
character(com_len) :: comment
! Set defaults
if (present(i)) then
iunit = i
else
iunit = default_iunit
endif
if (present(o)) then
ounit = o
else
ounit = default_ounit
endif
echo = default_echo
if (present(e)) then
if ((e==0).or.(e==1)) then
echo = e
else
write(6,*) 'Error: Illegal value of e=',e
endif
endif
if (present(f)) then
if ((f=='N').or.(f=='A').or.(f=='L').or.(f=='R')) then
com_style = f
else
write(ounit,*) 'Error: incorrect f = ' , f , ' in in_char'
com_style = scalar_com_style
endif
else
com_style = scalar_com_style
endif
if (present(u)) then
com_use = u
else
com_use = default_com_use
endif
if (.not.present(c)) com_use = 'K'
! Read data
select case(com_style)
case('N') ! No comment
read(iunit,*) data
case('A') ! comment above
read(iunit,*) comment
read(iunit,*) data
case('L') ! comment to left of data
read(iunit,*) comment, data
case('R') ! comment to right of data
read(iunit,*) data, comment
end select
if (com_style /= 'N') then
comment = adjustl(comment)
if ((com_use == 'K').and.present(c)) then
c = comment
endif
endif
if (echo == 1) then
if ((com_use == 'R').and.present(c)) then
comment = adjustl(c)
endif
call output(trim(data),comment,ounit,com_style)
endif
end subroutine input_char
!--------------------------------------------------------------
subroutine input_logic(data,c,i,o,e,f,u)
!--------------------------------------------------------------
logical, intent(OUT) :: data
character(*), optional :: c ! comment
integer, intent(IN), optional :: i ! input unit #
integer, intent(IN), optional :: o ! output unit #
integer, intent(IN), optional :: e ! echo flag
character(1), intent(IN), optional :: f ! comment style
character(1), intent(IN), optional :: u ! comment usage
! Local variables
integer :: iunit, ounit, echo
character(1) :: com_style, com_use
character(com_len) :: comment
! Set defaults
if (present(i)) then
iunit = i
else
iunit = default_iunit
endif
if (present(o)) then
ounit = o
else
ounit = default_ounit
endif
echo = default_echo
if (present(e)) then
if ((e==0).or.(e==1)) then
echo = e
else
write(6,*) 'Error: Illegal value of e=',e
endif
endif
if (present(f)) then
if ((f=='N').or.(f=='A').or.(f=='L').or.(f=='R')) then
com_style = f
else
write(ounit,*) 'Error: incorrect f = ' , f , ' in in_int'
com_style = scalar_com_style
endif
else
com_style = scalar_com_style
endif
if (present(u)) then
com_use = u
else
com_use = default_com_use
endif
if (.not.present(c)) com_use = 'K'
! Read data
select case(com_style)
case('N') ! No comment
read(iunit,*) data
case('A') ! comment above
read(iunit,*) comment
read(iunit,*) data
case('L') ! comment to left of data
read(iunit,*) comment, data
case('R') ! comment to right of data
read(iunit,*) data, comment
end select
if (com_style /= 'N') then
comment = adjustl(comment)
if ((com_use == 'K').and.present(c)) then
c = comment
endif
endif
if (echo == 1) then ! echo in to ounit
if ((com_use == 'R').and.present(c)) then
comment = adjustl(c)
endif
call output(data,comment,ounit,com_style)
endif
end subroutine input_logic
!--------------------------------------------------------------
subroutine input_int_vec(data,n,c,s,i,o,e,f,u)
!--------------------------------------------------------------
integer, intent(OUT) :: data(:) ! in array
integer, intent(IN) :: n ! dimension
character(*), optional :: c ! comment
character(1), intent(IN), optional :: s ! column or row
integer, intent(IN), optional :: i ! input unit #
integer, intent(IN), optional :: o ! output unit #
integer, intent(IN), optional :: e ! echo flag
character(1), intent(IN), optional :: f ! comment style
character(1), intent(IN), optional :: u ! comment usage
! Local variables
integer :: iunit, ounit, echo, j
character(1) :: com_style, com_use, symmetry
character(com_len) :: comment
! Set defaults
if (present(s)) then
if ((s=='R').or.(s=='C')) then
symmetry = s
else
write(6,*) 'Error: Illegal s=',s,' in input_int_vec'
symmetry = default_vec_sym
endif
else
symmetry = default_vec_sym
endif
if (present(i)) then
iunit = i
else
iunit = default_iunit
endif
if (present(o)) then
ounit = o
else
ounit = default_ounit
endif
echo = default_echo
if (present(e)) then
if ((e==0).or.(e==1)) then
echo = e
else
write(6,*) 'Error: Illegal value of e=',e
endif
endif
if (present(f)) then
if ((f=='N').or.(f=='A').or.(f=='L').or.(f=='R')) then
com_style = f
else
write(ounit,*) 'Error: incorrect f = ' , f , ' in in_int_vec'
com_style = vector_com_style
endif
else
com_style = vector_com_style
endif
if (present(u)) then
com_use = u
else
com_use = default_com_use
endif
if (.not.present(c)) com_use = 'K'
! Comment line
if (com_style=='A') then
read(iunit,*) comment
comment = adjustl(comment)
if ((com_use == 'K').and.present(c)) then
c = comment
endif
endif
! Read data
select case(symmetry)
case('R')
read(iunit,*) data(1:n)
case('C')
do j=1, n
read(iunit,*) data(j)
enddo
end select
! Echo
if (echo == 1) then
if ((com_use == 'R').and.present(c)) then
comment = adjustl(c)