gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dc_string.f90
Go to the documentation of this file.
1! -*- mode: f90; coding: utf-8 -*-
2!-----------------------------------------------------------------------
3! Copyright (c) 2000-2026 Gtool Development Group. All rights reserved.
4!-----------------------------------------------------------------------
84 use dc_types, only: token, string, dp, sp
85 implicit none
86 private
87 public :: stoi
88 public :: stod
89 public :: get_array
90 public :: str_to_logical
91 public :: tochar
92 public :: roundnum
93 public :: joinchar
94 public :: concat
95 public :: stoa
96 public :: split
97 public :: index_ofs
98 public :: replace
99 public :: toupper
100 public :: tolower
101 public :: uchar
102 public :: lchar
103 public :: strieq
104 public :: strhead
105 public :: strinclude
106 ! public :: GTStringQuoteForDcl
107 public :: cprintf
108 public :: cprintft
109 public :: printf
110 public :: putline
111 interface stoi
112 module procedure atoi_scalar
113 end interface stoi
114 interface stor
115 module procedure ator_scalar
116 end interface stor
117 interface stod
118 module procedure atod_scalar
119 end interface stod
120 interface get_array
121 module procedure str2ip
122 module procedure str2rp
123 module procedure str2dp
124 end interface get_array
126 module procedure str2bool
127 end interface str_to_logical
128 !-------------------------------------
129 ! 数値から文字への変換
130 interface tochar
131 module procedure itoa_scalar
132 module procedure itoa_array
133 module procedure rtoa_scalar
134 module procedure rtoa_array
135 module procedure dtoa_scalar
136 module procedure dtoa_array
137 module procedure ltoa_scalar
138 module procedure ltoa_array
139 end interface tochar
140 !-------------------------------------
141 ! 数値表記の文字列の端数除去
142 interface roundnum
143 module procedure roundnum
144 end interface roundnum
145 !-------------------------------------
146 ! 文字型配列の連結
147 !-------------------------------------
148 ! 文字型配列の末尾に文字を連結
149 interface concat
150 module procedure concat_tail
151 end interface concat
152 !-------------------------------------
153 ! 長さの異なる文字群の配列化
154 interface stoa
155 module procedure str_to_array1
156 module procedure str_to_array2
157 module procedure str_to_array3
158 module procedure str_to_array4
159 module procedure str_to_array5
160 module procedure str_to_array6
161 module procedure str_to_array7
162 module procedure str_to_array8
163 module procedure str_to_array9
164 module procedure str_to_array10
165 module procedure str_to_array11
166 module procedure str_to_array12
167 end interface stoa
168 !-------------------------------------
169 ! 文字列の分解
170 interface split
171 module procedure split_cc
172 end interface split
173 !-------------------------------------
174 ! 文字列の解析
175 interface index_ofs
176 module procedure index_ofs
177 end interface index_ofs
178 interface replace
179 module procedure replace
180 end interface replace
181 !-------------------------------------
182 ! 大文字・小文字を無視した処理
183 interface toupper
184 module procedure cupper
185 end interface toupper
186 interface tolower
187 module procedure clower
188 end interface tolower
189 interface uchar
190 module procedure uchar
191 end interface uchar
192 interface lchar
193 module procedure lchar
194 end interface lchar
195 interface strieq
196 module procedure strieq_cc
197 end interface strieq
198 interface strhead
199 module procedure strhead_cc
200 end interface strhead
201 interface strinclude
202 module procedure str_include_ac
203 end interface strinclude
204 !-------------------------------------
205 ! 印字のための文字処理
206 ! interface
207 ! function GTStringQuoteForDcl(string) result(result)
208 ! use dc_types, only: STRLEN => STRING
209 ! character(*), intent(in):: string
210 ! character(STRLEN):: result
211 ! end function GTStringQuoteForDcl
212 ! end interface
213 interface cprintf
214 function dcstringcprintf(fmt, i, r, d, L, n, c1, c2, c3, ca, maxlen) result(result)
215 use dc_types, only: string, dp, sp
216 character(len = STRING):: result
217 character(*), intent(in):: fmt
218 integer, intent(in), optional:: i(:), n(:)
219 real(sp), intent(in), optional:: r(:)
220 real(dp), intent(in), optional:: d(:)
221 logical, intent(in), optional:: l(:)
222 character(*), intent(in), optional:: c1, c2, c3
223 character(*), intent(in), optional:: ca(:)
224 integer, intent(in), optional:: maxlen
225 end function dcstringcprintf
226 end interface cprintf
227 interface cprintft
228 function dcstringcprintft(fmt, i, r, d, L, n, c1, c2, c3, ca, maxlen) result(result)
229 use dc_types, only: token, dp, sp
230 character(len = TOKEN):: result
231 character(*), intent(in):: fmt
232 integer, intent(in), optional:: i(:), n(:)
233 real(sp), intent(in), optional:: r(:)
234 real(dp), intent(in), optional:: d(:)
235 logical, intent(in), optional:: l(:)
236 character(*), intent(in), optional:: c1, c2, c3
237 character(*), intent(in), optional:: ca(:)
238 integer, intent(in), optional:: maxlen
239 end function dcstringcprintft
240 end interface cprintft
241 interface printf
242 subroutine dcstringsprintf(unit, fmt, i, r, d, L, n, c1, c2, c3, ca)
243 use dc_types, only: dp, sp
244 character(*), intent(out):: unit
245 character(*), intent(in):: fmt
246 integer, intent(in), optional:: i(:), n(:)
247 real(SP), intent(in), optional:: r(:)
248 real(DP), intent(in), optional:: d(:)
249 logical, intent(in), optional:: L(:)
250 character(*), intent(in), optional:: c1, c2, c3
251 character(*), intent(in), optional:: ca(:)
252 end subroutine dcstringsprintf
253 subroutine dcstringfprintf(unit, fmt, i, r, d, L, n, c1, c2, c3, ca)
254 use dc_types, only: dp, sp
255 integer, intent(in), optional:: unit
256 character(*), intent(in):: fmt
257 integer, intent(in), optional:: i(:), n(:)
258 real, intent(in), optional:: r(:)
259 real(DP), intent(in), optional:: d(:)
260 logical, intent(in), optional:: L(:)
261 character(*), intent(in), optional:: c1, c2, c3
262 character(*), intent(in), optional:: ca(:)
263 end subroutine dcstringfprintf
264 end interface printf
265 !-------------------------------------
266 ! 数値型配列の要約印字
267 interface putline
268 subroutine putlineint1( array, lbounds, ubounds, unit, indent, sd )
269 integer, intent(in):: array(:)
270 integer, intent(in), optional:: lbounds(1)
271 integer, intent(in), optional:: ubounds(1)
272 integer, intent(in), optional:: unit
273 character(*), intent(in), optional:: indent
274 logical, intent(in), optional:: sd
275 end subroutine putlineint1
276 subroutine putlineint2( array, lbounds, ubounds, unit, indent, sd )
277 integer, intent(in):: array(:,:)
278 integer, intent(in), optional:: lbounds(2)
279 integer, intent(in), optional:: ubounds(2)
280 integer, intent(in), optional:: unit
281 character(*), intent(in), optional:: indent
282 logical, intent(in), optional:: sd
283 end subroutine putlineint2
284 subroutine putlineint3( array, lbounds, ubounds, unit, indent, sd )
285 integer, intent(in):: array(:,:,:)
286 integer, intent(in), optional:: lbounds(3)
287 integer, intent(in), optional:: ubounds(3)
288 integer, intent(in), optional:: unit
289 character(*), intent(in), optional:: indent
290 logical, intent(in), optional:: sd
291 end subroutine putlineint3
292 subroutine putlineint4( array, lbounds, ubounds, unit, indent, sd )
293 integer, intent(in):: array(:,:,:,:)
294 integer, intent(in), optional:: lbounds(4)
295 integer, intent(in), optional:: ubounds(4)
296 integer, intent(in), optional:: unit
297 character(*), intent(in), optional:: indent
298 logical, intent(in), optional:: sd
299 end subroutine putlineint4
300 subroutine putlineint5( array, lbounds, ubounds, unit, indent, sd )
301 integer, intent(in):: array(:,:,:,:,:)
302 integer, intent(in), optional:: lbounds(5)
303 integer, intent(in), optional:: ubounds(5)
304 integer, intent(in), optional:: unit
305 character(*), intent(in), optional:: indent
306 logical, intent(in), optional:: sd
307 end subroutine putlineint5
308 subroutine putlineint6( array, lbounds, ubounds, unit, indent, sd )
309 integer, intent(in):: array(:,:,:,:,:,:)
310 integer, intent(in), optional:: lbounds(6)
311 integer, intent(in), optional:: ubounds(6)
312 integer, intent(in), optional:: unit
313 character(*), intent(in), optional:: indent
314 logical, intent(in), optional:: sd
315 end subroutine putlineint6
316 subroutine putlineint7( array, lbounds, ubounds, unit, indent, sd )
317 integer, intent(in):: array(:,:,:,:,:,:,:)
318 integer, intent(in), optional:: lbounds(7)
319 integer, intent(in), optional:: ubounds(7)
320 integer, intent(in), optional:: unit
321 character(*), intent(in), optional:: indent
322 logical, intent(in), optional:: sd
323 end subroutine putlineint7
324 subroutine putlinereal1( array, lbounds, ubounds, unit, indent, sd )
325 use dc_types, only: sp
326 real(SP), intent(in):: array(:)
327 integer, intent(in), optional:: lbounds(1)
328 integer, intent(in), optional:: ubounds(1)
329 integer, intent(in), optional:: unit
330 character(*), intent(in), optional:: indent
331 logical, intent(in), optional:: sd
332 end subroutine putlinereal1
333 subroutine putlinereal2( array, lbounds, ubounds, unit, indent, sd )
334 use dc_types, only: sp
335 real(SP), intent(in):: array(:,:)
336 integer, intent(in), optional:: lbounds(2)
337 integer, intent(in), optional:: ubounds(2)
338 integer, intent(in), optional:: unit
339 character(*), intent(in), optional:: indent
340 logical, intent(in), optional:: sd
341 end subroutine putlinereal2
342 subroutine putlinereal3( array, lbounds, ubounds, unit, indent, sd )
343 use dc_types, only: sp
344 real(SP), intent(in):: array(:,:,:)
345 integer, intent(in), optional:: lbounds(3)
346 integer, intent(in), optional:: ubounds(3)
347 integer, intent(in), optional:: unit
348 character(*), intent(in), optional:: indent
349 logical, intent(in), optional:: sd
350 end subroutine putlinereal3
351 subroutine putlinereal4( array, lbounds, ubounds, unit, indent, sd )
352 use dc_types, only: sp
353 real(SP), intent(in):: array(:,:,:,:)
354 integer, intent(in), optional:: lbounds(4)
355 integer, intent(in), optional:: ubounds(4)
356 integer, intent(in), optional:: unit
357 character(*), intent(in), optional:: indent
358 logical, intent(in), optional:: sd
359 end subroutine putlinereal4
360 subroutine putlinereal5( array, lbounds, ubounds, unit, indent, sd )
361 use dc_types, only: sp
362 real(SP), intent(in):: array(:,:,:,:,:)
363 integer, intent(in), optional:: lbounds(5)
364 integer, intent(in), optional:: ubounds(5)
365 integer, intent(in), optional:: unit
366 character(*), intent(in), optional:: indent
367 logical, intent(in), optional:: sd
368 end subroutine putlinereal5
369 subroutine putlinereal6( array, lbounds, ubounds, unit, indent, sd )
370 use dc_types, only: sp
371 real(SP), intent(in):: array(:,:,:,:,:,:)
372 integer, intent(in), optional:: lbounds(6)
373 integer, intent(in), optional:: ubounds(6)
374 integer, intent(in), optional:: unit
375 character(*), intent(in), optional:: indent
376 logical, intent(in), optional:: sd
377 end subroutine putlinereal6
378 subroutine putlinereal7( array, lbounds, ubounds, unit, indent, sd )
379 use dc_types, only: sp
380 real(SP), intent(in):: array(:,:,:,:,:,:,:)
381 integer, intent(in), optional:: lbounds(7)
382 integer, intent(in), optional:: ubounds(7)
383 integer, intent(in), optional:: unit
384 character(*), intent(in), optional:: indent
385 logical, intent(in), optional:: sd
386 end subroutine putlinereal7
387 subroutine putlinedouble1( array, lbounds, ubounds, unit, indent, sd )
388 use dc_types, only: dp
389 real(DP), intent(in):: array(:)
390 integer, intent(in), optional:: lbounds(1)
391 integer, intent(in), optional:: ubounds(1)
392 integer, intent(in), optional:: unit
393 character(*), intent(in), optional:: indent
394 logical, intent(in), optional:: sd
395 end subroutine putlinedouble1
396 subroutine putlinedouble2( array, lbounds, ubounds, unit, indent, sd )
397 use dc_types, only: dp
398 real(DP), intent(in):: array(:,:)
399 integer, intent(in), optional:: lbounds(2)
400 integer, intent(in), optional:: ubounds(2)
401 integer, intent(in), optional:: unit
402 character(*), intent(in), optional:: indent
403 logical, intent(in), optional:: sd
404 end subroutine putlinedouble2
405 subroutine putlinedouble3( array, lbounds, ubounds, unit, indent, sd )
406 use dc_types, only: dp
407 real(DP), intent(in):: array(:,:,:)
408 integer, intent(in), optional:: lbounds(3)
409 integer, intent(in), optional:: ubounds(3)
410 integer, intent(in), optional:: unit
411 character(*), intent(in), optional:: indent
412 logical, intent(in), optional:: sd
413 end subroutine putlinedouble3
414 subroutine putlinedouble4( array, lbounds, ubounds, unit, indent, sd )
415 use dc_types, only: dp
416 real(DP), intent(in):: array(:,:,:,:)
417 integer, intent(in), optional:: lbounds(4)
418 integer, intent(in), optional:: ubounds(4)
419 integer, intent(in), optional:: unit
420 character(*), intent(in), optional:: indent
421 logical, intent(in), optional:: sd
422 end subroutine putlinedouble4
423 subroutine putlinedouble5( array, lbounds, ubounds, unit, indent, sd )
424 use dc_types, only: dp
425 real(DP), intent(in):: array(:,:,:,:,:)
426 integer, intent(in), optional:: lbounds(5)
427 integer, intent(in), optional:: ubounds(5)
428 integer, intent(in), optional:: unit
429 character(*), intent(in), optional:: indent
430 logical, intent(in), optional:: sd
431 end subroutine putlinedouble5
432 subroutine putlinedouble6( array, lbounds, ubounds, unit, indent, sd )
433 use dc_types, only: dp
434 real(DP), intent(in):: array(:,:,:,:,:,:)
435 integer, intent(in), optional:: lbounds(6)
436 integer, intent(in), optional:: ubounds(6)
437 integer, intent(in), optional:: unit
438 character(*), intent(in), optional:: indent
439 logical, intent(in), optional:: sd
440 end subroutine putlinedouble6
441 subroutine putlinedouble7( array, lbounds, ubounds, unit, indent, sd )
442 use dc_types, only: dp
443 real(DP), intent(in):: array(:,:,:,:,:,:,:)
444 integer, intent(in), optional:: lbounds(7)
445 integer, intent(in), optional:: ubounds(7)
446 integer, intent(in), optional:: unit
447 character(*), intent(in), optional:: indent
448 logical, intent(in), optional:: sd
449 end subroutine putlinedouble7
450 end interface putline
451contains
474 logical function strhead_cc(whole, head) result(result)
475 character(len = *), intent(in):: whole
476 character(len = *), intent(in):: head
477 continue
478 result = (len(whole) >= len(head))
479 if (.not. result) return
480 result = (whole(1:len(head)) == head)
481 end function strhead_cc
502 logical function strieq_cc(string_a, string_b) result(result)
503 !--
504 ! ※ 注意書き ※
505 !
506 ! コンパイラによっては character(len = len(string_a)):: abuf
507 ! が通らないため, 文字数を dc_types で提供される種別型
508 ! パラメタ STRING で制限
509 !++
510 character(len = *), intent(in):: string_a
511 character(len = *), intent(in):: string_b
512 character(len = STRING):: abuf
513 character(len = STRING):: bbuf
514 abuf = string_a
515 bbuf = string_b
516 call toupper(abuf)
517 call toupper(bbuf)
518 result = (abuf == bbuf)
519 end function strieq_cc
550 logical function str_include_ac( &
551 & carray, string, ignore_space, ignore_case ) result(result)
552 character(*), intent(in):: carray(:)
553 character(*), intent(in):: string
554 logical, intent(in), optional:: ignore_space
555 logical, intent(in), optional:: ignore_case
556 integer:: array_size, i
557 logical:: ignore_space_work, ignore_case_work
558 continue
559 ignore_space_work = .true.
560 if ( present(ignore_space) ) then
561 if ( .not. ignore_space ) then
562 ignore_space_work = .false.
563 end if
564 end if
565 ignore_case_work = .false.
566 if ( present(ignore_case) ) then
567 if ( ignore_case ) then
568 ignore_case_work = .true.
569 end if
570 end if
571 array_size = size(carray)
572 do i = 1, array_size
573 if ( ignore_space_work ) then
574 if ( ignore_case_work ) then
575 result = &
576 & strieq_cc( trim( adjustl( carray(i) ) ), &
577 & trim( adjustl( string ) ) )
578 else
579 result = &
580 & ( trim( adjustl( carray(i) ) ) == trim( adjustl( string ) ) )
581 end if
582 else
583 if ( ignore_case_work ) then
584 result = &
585 & strieq_cc( trim( carray(i) ), trim( string ) )
586 else
587 result = ( trim(carray(i)) == trim(string) )
588 end if
589 end if
590 if (result) return
591 end do
592 end function str_include_ac
614 logical function str2bool(string) result(result)
615 character(len = *), intent(in):: string
616 continue
617 select case(string)
618 case ("", "0", "0.0", "0.0D0", "0.0d0", ".false.", ".FALSE.", &
619 & "f", "F", "false", "FALSE")
620 result = .false.
621 case default
622 result = .true.
623 end select
624 end function str2bool
645 integer function atoi_scalar(string, default) result(result)
646 character(len = *), intent(in):: string
647 integer, intent(in), optional:: default
648 integer:: ios
649 continue
650 read(unit=string, fmt="(i80)", iostat=ios) result
651 if (ios /= 0) then
652 if (present(default)) then
653 result = default
654 else
655 result = 0
656 endif
657 endif
658 end function atoi_scalar
676 real(sp) function ator_scalar(string_in) result(result)
677 use dc_types, only: string
678 character(len = *), intent(in):: string_in
679 integer:: ios
680 character(len = STRING):: buffer
681 integer:: ipoint, iexp
682 intrinsic scan
683 continue
684 buffer = string_in
685 ! もし整定数をいれてしまった場合は小数点を附加
686 if (index(buffer, '.') == 0) then
687 iexp = scan(buffer, "eEdD")
688 if (iexp /= 0) then
689 buffer(iexp+1: len(buffer)) = buffer(iexp: len(buffer)-1)
690 ipoint = iexp
691 else
692 ipoint = len_trim(buffer) + 1
693 endif
694 buffer(ipoint: ipoint) = '.'
695 endif
696 read(unit=buffer, fmt="(g80.10)", iostat=ios) result
697 if (ios /= 0) result = 0.0
698 end function ator_scalar
716 real(dp) function atod_scalar(string_in) result(result)
717 use dc_types, only: string
718 character(len = *), intent(in):: string_in
719 integer:: ios
720 character(len = STRING):: buffer
721 integer:: ipoint, iexp
722 intrinsic scan
723 continue
724 buffer = string_in
725 ! もし整定数をいれてしまった場合は小数点を附加
726 if (index(buffer, '.') == 0) then
727 iexp = scan(buffer, "eEdD")
728 if (iexp /= 0) then
729 buffer(iexp+1: len(buffer)) = buffer(iexp: len(buffer)-1)
730 ipoint = iexp
731 else
732 ipoint = len_trim(buffer) + 1
733 endif
734 buffer(ipoint: ipoint) = '.'
735 endif
736 read(unit=buffer, fmt="(g80.10)", iostat=ios) result
737 if (ios /= 0) result = 0.0
738 end function atod_scalar
760 subroutine str2ip(int_ptr, string_in)
761 integer, pointer:: int_ptr(:) !(out)
762 character(len = *), intent(in):: string_in
763 integer:: i, j, idx, nvalues
764 continue
765 nvalues = 1
766 i = 1
767 do
768 idx = index(string_in(i: ), ',')
769 if (idx == 0) exit
770 i = i + idx - 1 + 1
771 nvalues = nvalues + 1
772 enddo
773 allocate(int_ptr(nvalues))
774 i = 1
775 j = 1
776 do
777 idx = index(string_in(i: ), ',')
778 if (idx == 0) then
779 int_ptr(j) = stoi(string_in(i: ))
780 exit
781 endif
782 int_ptr(j) = stoi(string_in(i: i+idx-2))
783 i = i + idx - 1 + 1
784 j = j + 1
785 enddo
786 end subroutine str2ip
808 subroutine str2rp(real_ptr, string_in)
809 real(SP), pointer:: real_ptr(:) !(out)
810 character(len = *), intent(in):: string_in
811 integer:: i, j, idx, nvalues
812 continue
813 nvalues = 1
814 i = 1
815 do
816 idx = index(string_in(i: ), ',')
817 if (idx == 0) exit
818 i = i + idx - 1 + 1
819 nvalues = nvalues + 1
820 enddo
821 allocate(real_ptr(nvalues))
822 i = 1
823 j = 1
824 do
825 idx = index(string_in(i: ), ',')
826 if (idx == 0) then
827 real_ptr(j) = stor(string_in(i: ))
828 exit
829 endif
830 real_ptr(j) = stor(string_in(i: i+idx-2))
831 i = i + idx - 1 + 1
832 j = j + 1
833 enddo
834 end subroutine str2rp
856 subroutine str2dp(double_ptr, string_in)
857 real(DP), pointer:: double_ptr(:) !(out)
858 character(len = *), intent(in):: string_in
859 integer:: i, j, idx, nvalues
860 continue
861 nvalues = 1
862 i = 1
863 do
864 idx = index(string_in(i: ), ',')
865 if (idx == 0) exit
866 i = i + idx - 1 + 1
867 nvalues = nvalues + 1
868 enddo
869 allocate(double_ptr(nvalues))
870 i = 1
871 j = 1
872 do
873 idx = index(string_in(i: ), ',')
874 if (idx == 0) then
875 double_ptr(j) = stod(string_in(i: ))
876 exit
877 endif
878 double_ptr(j) = stod(string_in(i: i+idx-2))
879 i = i + idx - 1 + 1
880 j = j + 1
881 enddo
882 end subroutine str2dp
883 !== 数値型、論理型から文字型への変換
884 !
885 ! 総称名称 toChar として呼び出される関数群
886 !
898 character(TOKEN) function itoa_scalar(i) result(result)
899 integer, intent(in):: i
900 character(len = 32):: buffer
901 continue
902 write(unit=buffer, fmt="(i20)") i
903 result = adjustl(buffer)
904 end function itoa_scalar
920 character(STRING) function itoa_array(ibuf) result(result)
921 integer, intent(in):: ibuf(:)
922 integer:: i
923 continue
924 if (size(ibuf) <= 0) then
925 result = ""
926 return
927 endif
928 result = tochar(ibuf(1))
929 do, i = 2, size(ibuf)
930 result = trim(result) // ", " // trim(tochar(ibuf(i)))
931 enddo
932 end function itoa_array
944 character(TOKEN) function rtoa_scalar(x) result(result)
945 real(sp), intent(in):: x
946 character(len = 16):: buffer, expbuf
947 integer:: ptr, eptr
948 continue
949 write(unit=buffer, fmt="(g16.8)") x
950 eptr = scan(buffer, "eE", back=.true.)
951 expbuf = ''
952 if (eptr > 1) then
953 expbuf = buffer(eptr: )
954 buffer(eptr: ) = " "
955 end if
956 ptr = verify(buffer, " 0", back=.true.)
957 if (ptr > 0) buffer(ptr+1: ) = " "
958 if (eptr > 1) then
959 buffer = buffer(1:len_trim(buffer)) // expbuf
960 end if
961 result = adjustl(buffer)
962 end function rtoa_scalar
978 character(STRING) function rtoa_array(rbuf) result(result)
979 real(sp), intent(in):: rbuf(:)
980 integer:: i
981 continue
982 if (size(rbuf) <= 0) then
983 result = ""
984 return
985 endif
986 result = tochar(rbuf(1))
987 do, i = 2, size(rbuf)
988 result = trim(result) // ", " // trim(tochar(rbuf(i)))
989 enddo
990 end function rtoa_array
1002 character(TOKEN) function dtoa_scalar(d) result(result)
1003 real(dp), intent(in):: d
1004 character(len = 32):: buffer, expbuf
1005 integer:: ptr, eptr
1006 continue
1007 write(unit=buffer, fmt="(g32.24)") d
1008 eptr = scan(buffer, "eE", back=.true.)
1009 expbuf = ''
1010 if (eptr > 1) then
1011 expbuf = buffer(eptr: )
1012 buffer(eptr: ) = " "
1013 end if
1014 ptr = verify(buffer, " 0", back=.true.)
1015 if (ptr > 0) buffer(ptr+1: ) = " "
1016 if (eptr > 1) then
1017 buffer = buffer(1:len_trim(buffer)) // expbuf
1018 end if
1019 result = adjustl(buffer)
1020 end function dtoa_scalar
1036 character(STRING) function dtoa_array(dbuf) result(result)
1037 real(dp), intent(in):: dbuf(:)
1038 integer:: i
1039 continue
1040 if (size(dbuf) <= 0) then
1041 result = ""
1042 return
1043 endif
1044 result = tochar(dbuf(1))
1045 do, i = 2, size(dbuf)
1046 result = trim(result) // ", " // trim(tochar(dbuf(i)))
1047 enddo
1048 end function dtoa_array
1060 character(TOKEN) function ltoa_scalar(l) result(result)
1061 logical, intent(in):: l
1062 continue
1063 if (l) then
1064 result = ".true."
1065 else
1066 result = ".false."
1067 end if
1068 end function ltoa_scalar
1084 character(STRING) function ltoa_array(lbuf) result(result)
1085 logical, intent(in):: lbuf(:)
1086 integer:: i
1087 continue
1088 if (size(lbuf) <= 0) then
1089 result = ""
1090 return
1091 endif
1092 result = tochar(lbuf(1))
1093 do, i = 2, size(lbuf)
1094 result = trim(result) // ", " // trim(tochar(lbuf(i)))
1095 enddo
1096 end function ltoa_array
1097 !-------------------------------------------------------------------
1098 ! 文字配列の連結
1099 !-------------------------------------------------------------------
1120 character(STRING) function joinchar(carray, expr) result(result)
1121 implicit none
1122 character(*) , intent(in) :: carray(:)
1123 character(*) , intent(in), optional :: expr
1124 character(2) ,parameter :: default = ', '
1125 character(STRING) :: delimiter
1126 integer :: dellen, i
1127 continue
1128 if ( present(expr) ) then
1129 delimiter = expr
1130 dellen = len(expr)
1131 else
1132 delimiter = default
1133 dellen = len(default)
1134 endif
1135 if (size(carray) <= 0) then
1136 result = ""
1137 return
1138 endif
1139 result = trim(carray(1))
1140 do, i = 2, size(carray)
1141 result = trim(result) // delimiter(1:dellen) // trim(carray(i))
1142 enddo
1143 end function joinchar
1168 subroutine concat_tail(carray, str, result)
1169 implicit none
1170 character(*), intent(in) :: carray(:)
1171 character(*), intent(in) :: str
1172 character(STRING), pointer:: result(:) ! (out)
1173 integer :: i, size_carray
1174 continue
1175 size_carray = size(carray)
1176 allocate(result(size_carray))
1177 do i = 1, size_carray
1178 result(i) = trim(carray(i)) // str
1179 end do
1180 end subroutine concat_tail
1194 function str_to_array1(c1) result(result)
1195 character(*), intent(in) :: c1
1196 character(STRING) :: result(1)
1197 continue
1198 result(1) = c1
1199 end function str_to_array1
1213 function str_to_array2(c1,c2) result(result)
1214 character(*), intent(in) :: c1,c2
1215 character(STRING) :: result(2)
1216 continue
1217 result(1) = c1
1218 result(2) = c2
1219 end function str_to_array2
1233 function str_to_array3(c1,c2,c3) result(result)
1234 character(*), intent(in) :: c1,c2,c3
1235 character(STRING) :: result(3)
1236 continue
1237 result(1) = c1
1238 result(2) = c2
1239 result(3) = c3
1240 end function str_to_array3
1254 function str_to_array4(c1,c2,c3,c4) result(result)
1255 character(*), intent(in) :: c1,c2,c3,c4
1256 character(STRING) :: result(4)
1257 continue
1258 result(1) = c1
1259 result(2) = c2
1260 result(3) = c3
1261 result(4) = c4
1262 end function str_to_array4
1276 function str_to_array5(c1,c2,c3,c4,c5) result(result)
1277 character(*), intent(in) :: c1,c2,c3,c4,c5
1278 character(STRING) :: result(5)
1279 continue
1280 result(1) = c1
1281 result(2) = c2
1282 result(3) = c3
1283 result(4) = c4
1284 result(5) = c5
1285 end function str_to_array5
1299 function str_to_array6(c1,c2,c3,c4,c5,c6) result(result)
1300 character(*), intent(in) :: c1,c2,c3,c4,c5,c6
1301 character(STRING) :: result(6)
1302 continue
1303 result(1) = c1
1304 result(2) = c2
1305 result(3) = c3
1306 result(4) = c4
1307 result(5) = c5
1308 result(6) = c6
1309 end function str_to_array6
1323 function str_to_array7(c1,c2,c3,c4,c5,c6,c7) result(result)
1324 character(*), intent(in) :: c1,c2,c3,c4,c5,c6,c7
1325 character(STRING) :: result(7)
1326 continue
1327 result(1) = c1
1328 result(2) = c2
1329 result(3) = c3
1330 result(4) = c4
1331 result(5) = c5
1332 result(6) = c6
1333 result(7) = c7
1334 end function str_to_array7
1348 function str_to_array8(c1,c2,c3,c4,c5,c6,c7,c8) result(result)
1349 character(*), intent(in) :: c1,c2,c3,c4,c5,c6,c7,c8
1350 character(STRING) :: result(8)
1351 continue
1352 result(1) = c1
1353 result(2) = c2
1354 result(3) = c3
1355 result(4) = c4
1356 result(5) = c5
1357 result(6) = c6
1358 result(7) = c7
1359 result(8) = c8
1360 end function str_to_array8
1374 function str_to_array9(c1,c2,c3,c4,c5,c6,c7,c8,c9) result(result)
1375 character(*), intent(in) :: c1,c2,c3,c4,c5,c6,c7,c8,c9
1376 character(STRING) :: result(9)
1377 continue
1378 result(1) = c1
1379 result(2) = c2
1380 result(3) = c3
1381 result(4) = c4
1382 result(5) = c5
1383 result(6) = c6
1384 result(7) = c7
1385 result(8) = c8
1386 result(9) = c9
1387 end function str_to_array9
1401 function str_to_array10(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10) result(result)
1402 character(*), intent(in) :: c1,c2,c3,c4,c5,c6,c7,c8,c9,c10
1403 character(STRING) :: result(10)
1404 continue
1405 result(1) = c1
1406 result(2) = c2
1407 result(3) = c3
1408 result(4) = c4
1409 result(5) = c5
1410 result(6) = c6
1411 result(7) = c7
1412 result(8) = c8
1413 result(9) = c9
1414 result(10) = c10
1415 end function str_to_array10
1429 function str_to_array11(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11) result(result)
1430 character(*), intent(in) :: c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11
1431 character(STRING) :: result(11)
1432 continue
1433 result(1) = c1
1434 result(2) = c2
1435 result(3) = c3
1436 result(4) = c4
1437 result(5) = c5
1438 result(6) = c6
1439 result(7) = c7
1440 result(8) = c8
1441 result(9) = c9
1442 result(10) = c10
1443 result(11) = c11
1444 end function str_to_array11
1458 function str_to_array12(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12) result(result)
1459 character(*), intent(in) :: c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12
1460 character(STRING) :: result(12)
1461 continue
1462 result(1) = c1
1463 result(2) = c2
1464 result(3) = c3
1465 result(4) = c4
1466 result(5) = c5
1467 result(6) = c6
1468 result(7) = c7
1469 result(8) = c8
1470 result(9) = c9
1471 result(10) = c10
1472 result(11) = c11
1473 result(12) = c12
1474 end function str_to_array12
1475 !-------------------------------------------------------------------
1476 ! 文字列の分解
1477 !-------------------------------------------------------------------
1509 subroutine split_cc(str, carray, sep, limit)
1510 use dc_types, only: string
1511 implicit none
1512 character(*), intent(in):: str
1513 character(*), pointer:: carray(:) !(out)
1514 character(*), intent(in):: sep
1515 integer, intent(in), optional:: limit
1516 integer :: num, cur, i, limitnum
1517 character(STRING) :: substr
1518 logical :: end_flag
1519 continue
1520 if (present(limit)) then
1521 if (limit > 0) then
1522 limitnum = limit
1523 else
1524 limitnum = 0
1525 end if
1526 else
1527 limitnum = 0
1528 end if
1529 if (len(trim(sep)) == 0) then
1530 num = 1
1531 substr = str
1532 ! 重複して無駄だが carray を allocate するため, 何分割するか
1533 ! 調べ, num に格納する.
1534 do
1535 cur = index(trim(substr), ' ')
1536 if (cur == 0) exit
1537 num = num + 1
1538 substr = adjustl(substr(cur + len(sep) :len(substr)))
1539 end do
1540 if (limitnum /= 0 .and. num > limitnum) num = limitnum
1541 allocate(carray(num))
1542 substr = str
1543 end_flag = .false.
1544 do i = 1, num
1545 cur = index(trim(substr), ' ')
1546 if (cur == 0 .or. i == num) end_flag = .true.
1547 if (end_flag) then
1548 carray(i) = substr
1549 exit
1550 else
1551 carray(i) = substr(1:cur - 1)
1552 end if
1553 substr = adjustl(substr(cur + len(sep) :len(substr)))
1554 end do
1555 else
1556 num = 1
1557 substr = str
1558 ! 重複して無駄だが carray を allocate するため, 何分割するか
1559 ! 調べ, num に格納する.
1560 do
1561 cur = index(substr, trim(sep))
1562 if (cur == 0) exit
1563 num = num + 1
1564 substr = substr(cur + len(sep) :len(substr))
1565 end do
1566 if (limitnum /= 0 .and. num > limitnum) num = limitnum
1567 allocate(carray(num))
1568 substr = str
1569 end_flag = .false.
1570 do i = 1, num
1571 cur = index(substr, trim(sep))
1572 if (cur == 0 .or. i == num) end_flag = .true.
1573 if (end_flag) then
1574 carray(i) = substr
1575 exit
1576 else
1577 carray(i) = substr(1:cur - 1)
1578 end if
1579 substr = substr(cur + len(sep) :len(substr))
1580 end do
1581 end if
1582 return
1583 end subroutine split_cc
1584 !-------------------------------------------------------------------
1585 ! 文字列の解析
1586 !-------------------------------------------------------------------
1611 integer function index_ofs(string, start, substr) result(result)
1612 character(len = *), intent(in):: string
1613 integer, intent(in):: start
1614 character(len = *), intent(in):: substr
1615 intrinsic index
1616 if (start < 1) then
1617 result = 0
1618 return
1619 endif
1620 result = index(string(start: ), substr)
1621 if (result == 0) return
1622 result = start + result - 1
1623 end function index_ofs
1658 recursive function replace( &
1659 & str, from, to, recursive, start_pos ) result(result)
1660 use dc_types, only: string
1661 implicit none
1662 character(STRING):: result
1663 character(*), intent(in):: str, from, to
1664 logical, intent(in), optional:: recursive
1665 integer, intent(in), optional:: start_pos
1666 integer:: sp
1667 integer:: i, isa, isb, iea, ieb
1668 integer:: ir
1669 continue
1670 if ( present(start_pos) ) then
1671 sp = start_pos
1672 else
1673 sp = 1
1674 end if
1675 if ( sp < 1 ) then
1676 sp = 1
1677 end if
1678 result = str
1679 i = index(result(sp:), from)
1680 if (i == 0) return
1681 i = i + sp - 1
1682 isa = i + len(from)
1683 isb = i + len(to)
1684 if (len(to) < len(from)) then
1685 iea = len(result)
1686 ieb = len(result) + len(to) - len(from)
1687 else
1688 iea = len(result) + len(from) - len(to)
1689 ieb = len(result)
1690 endif
1691 if (len(to) /= len(from)) result(isb:ieb) = result(isa:iea)
1692 result(i:i+len(to)-1) = to
1693 !-----------------------------------
1694 ! 再帰的処理
1695 ! Recursive process
1696 ir = index(result(i+len(to):), from)
1697 if ( len_trim(from) == 0 ) then
1698 ir = index(trim(result(i+len(to):)), from)
1699 end if
1700 if (ir /= 0) then
1701 if ( present(recursive) ) then
1702 if ( recursive ) then
1703 result = replace( str = result, &
1704 & from = from, to = to, &
1705 & recursive = recursive, &
1706 & start_pos = i+len(to) )
1707 end if
1708 end if
1709 end if
1710 end function replace
1711 !-------------------------------------------------------------------
1712 ! 大文字・小文字を無視した処理
1713 !-------------------------------------------------------------------
1729 subroutine cupper(ch)
1730 character(len = *), intent(inout):: ch
1731 integer:: i, lch, idx
1732 continue
1733 lch = len(ch)
1734 do, i = 1, lch
1735 idx = ichar(ch(i:i))
1736 if (97 <= idx .and. idx <= 122) then
1737 ch(i:i)=char(idx - 32)
1738 end if
1739 end do
1740 end subroutine cupper
1756 subroutine clower(ch)
1757 character(len = *), intent(inout):: ch
1758 integer:: i, lch, idx
1759 continue
1760 lch = len(ch)
1761 do, i = 1, lch
1762 idx = ichar(ch(i:i))
1763 if (65 <= idx .and. idx <= 90) then
1764 ch(i:i)=char(idx + 32)
1765 end if
1766 end do
1767 end subroutine clower
1785 character(STRING) function uchar(ch) result(result)
1786 character(len = *), intent(in):: ch
1787 continue
1788 result = ch
1789 call toupper(result)
1790 end function uchar
1808 character(STRING) function lchar(ch) result(result)
1809 character(len = *), intent(in):: ch
1810 continue
1811 result = ch
1812 call tolower(result)
1813 end function lchar
1831 character(STRING) function roundnum(num) result(result)
1832 character(*), intent(in):: num
1833 character(STRING):: nrv, enrv
1834 integer:: i, moving_up, nrvi, dig, zero_stream
1835 continue
1836 !
1837 ! 実数でないものについてはそのまま返す.
1838 !
1839 if ( scan('.', trim(num) ) == 0 ) then
1840 result = num
1841 return
1842 end if
1843 nrv = num
1844 !
1845 ! 指数部を避けておく.
1846 !
1847 enrv = ''
1848 i = scan(nrv, "eE", back=.true.)
1849 if ( i > 1 ) then
1850 enrv = nrv(i:)
1851 nrv(i:) = " "
1852 elseif ( i == 1 ) then
1853 result = nrv
1854 return
1855 end if
1856 !
1857 ! 0.30000001 などの末尾の 1 のような, ゴミの桁の数値を掃除し,
1858 ! 0.3000000 などに整形.
1859 !
1860 if ( index( trim( nrv ), '.') - len_trim( nrv ) < -7 ) then
1861 do while ( index('567890.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1862 if ( len_trim(nrv) < 2 ) exit
1863 nrv = nrv(1:len_trim(nrv)-1)
1864 end do
1865 end if
1866 !
1867 ! 0.30000001986 などの末尾の 1 以降のゴミの桁の数値を掃除し,
1868 ! 0.3000000 などに整形.
1869 !
1870 if ( index( trim( nrv ), '.') - len_trim( nrv ) < -7 ) then
1871 dig = index( trim( nrv ), '.') + 1
1872 zero_stream = 0
1873 do while ( dig < len_trim( nrv ) )
1874 if ( nrv(dig:dig) == "0" ) then
1875 zero_stream = zero_stream + 1
1876 else
1877 zero_stream = 0
1878 end if
1879 if ( zero_stream > 7 ) then
1880 nrv(dig:len_trim(nrv)) = '0'
1881 exit
1882 end if
1883 dig = dig + 1
1884 end do
1885 end if
1886 !
1887 ! 0.3000000 などの末尾の 0 を掃除し,
1888 ! 0.3 などに整形.
1889 !
1890 if ( index( trim( nrv ), '.') /= 0 ) then
1891 do while ( index('123456789.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1892 if ( len_trim(nrv) < 2 ) exit
1893 nrv = nrv(1:len_trim(nrv)-1)
1894 end do
1895 end if
1896 !
1897 ! 0.89999998 などの末尾の 8 のような, ゴミの桁の数値を掃除し,
1898 ! 0.8999999 などに整形.
1899 !
1900 moving_up = 0
1901 if ( index( trim( nrv ), '.') - len_trim( nrv ) < -7 ) then
1902 do while ( index('12345690.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1903 if ( len_trim(nrv) < 2 ) exit
1904 nrv = nrv(1:len_trim(nrv)-1)
1905 end do
1906 moving_up = 1
1907 end if
1908 !
1909 ! 0.8999999 などの末尾の 9 を掃除し, 繰り上げて
1910 ! 0.9 などに整形.
1911 !
1912 if ( moving_up > 0 ) then
1913 do while ( index('012345678.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1914 if ( len_trim(nrv) < 2 ) exit
1915 nrv = nrv(1:len_trim(nrv)-1)
1916 end do
1917 end if
1918 i = len_trim(nrv)
1919 do while ( moving_up > 0 .and. i > 0 )
1920 if ( index('.', nrv(i:i)) /= 0 ) then
1921 i = i - 1
1922 cycle
1923 end if
1924 nrvi = stoi( nrv(i:i) ) + moving_up
1925 if ( nrvi < 10 ) then
1926 nrv(i:i) = trim( tochar( nrvi ) )
1927 exit
1928 else
1929 nrv(i:i) = '0'
1930 if ( i < 2 ) then
1931 nrv = '10'
1932 exit
1933 else
1934 i = i - 1
1935 cycle
1936 end if
1937 end if
1938 if ( len_trim(nrv) < 2 ) exit
1939 nrv = nrv(1:len_trim(nrv)-1)
1940 end do
1941 !
1942 ! 0.3000000 などの末尾の 0 を掃除し,
1943 ! 0.3 などに整形.
1944 !
1945 if ( index( trim( nrv ), '.') /= 0 ) then
1946 do while ( index('123456789.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1947 if ( len_trim(nrv) < 2 ) exit
1948 nrv = nrv(1:len_trim(nrv)-1)
1949 end do
1950 end if
1951 !
1952 ! 指数部を復帰する
1953 !
1954 if ( len_trim(enrv) > 0 ) then
1955 nrv = trim(nrv) // enrv
1956 end if
1957 result = nrv
1958 end function roundnum
1960end module
character(len=string) function dcstringcprintf(fmt, i, r, d, l, n, c1, c2, c3, ca, maxlen)
書式変換出力 (関数版)
character(len=token) function dcstringcprintft(fmt, i, r, d, l, n, c1, c2, c3, ca, maxlen)
subroutine dcstringfprintf(unit, fmt, i, r, d, l, n, c1, c2, c3, ca)
書式変換出力 (装置番号版)
subroutine putlinedouble6(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinereal1(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinereal6(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint7(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinedouble4(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint6(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint5(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinedouble5(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint4(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinedouble1(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinereal3(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinereal4(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint2(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint1(array, lbounds, ubounds, unit, indent, sd)
配列の要約印字(PutLine サブルーチン)
subroutine putlinereal7(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinereal2(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinedouble2(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinereal5(array, lbounds, ubounds, unit, indent, sd)
subroutine putlineint3(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinedouble7(array, lbounds, ubounds, unit, indent, sd)
subroutine putlinedouble3(array, lbounds, ubounds, unit, indent, sd)
subroutine dcstringsprintf(unit, fmt, i, r, d, l, n, c1, c2, c3, ca)
書式変換出力 (C の sprintf 風)
文字型変数の操作
Definition dc_string.f90:83
character(string) function, public joinchar(carray, expr)
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public sp
単精度実数型変数
Definition dc_types.f90:82
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition dc_types.f90:128
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137