gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
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!-----------------------------------------------------------------------
5!>
6!> @author Youhei SASAKI, Yasuhiro MORIKAWA, Eizi TOYODA
7!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!>
10!> **Important**
11!>
12!> This file is generated from ../../../../src/dc_utils/dc_string.erb by ERB included Ruby 3.3.8.
13!> Please do not edit this file directly.
14!>
15!> @en
16!> @brief Handling character types
17!> @details
18!> This module provides subroutines to handle character type variables.
19!>
20!> @section string_procedures Procedures List
21!>
22!> | Procedure | Description |
23!> |-----------------|----------------------------------------------------------|
24!> | StoI | Convert string to integer |
25!> | StoD | Convert string to double precision real |
26!> | get_array | Parse comma-separated string to array pointer |
27!> | Str_to_Logical | Convert string to logical |
28!> | toChar | Convert numeric/logical to string |
29!> | RoundNum | Round numeric string representation |
30!> | JoinChar | Join character array with delimiter |
31!> | Concat | Concatenate string to array elements |
32!> | StoA | Convert multiple strings to array |
33!> | Split | Split string by separator |
34!> | Index_Ofs | Find substring position with offset |
35!> | Replace | Replace substring in string |
36!> | toUpper | Convert string to uppercase (in-place) |
37!> | toLower | Convert string to lowercase (in-place) |
38!> | UChar | Return uppercase copy of string |
39!> | LChar | Return lowercase copy of string |
40!> | StriEq | Case-insensitive string comparison |
41!> | StrHead | Check if string starts with prefix |
42!> | StrInclude | Check if array contains string |
43!> | CPrintf | C-style printf returning string |
44!> | Printf | C-style printf to unit or string |
45!> | PutLine | Print array summary (size, max, min, avg) |
46!>
47!> @enden
48!>
49!> @ja
50!> @brief 文字型変数の操作
51!> @details
52!> 本モジュールは文字列を操作するためのサブルーチン群を提供します。
53!>
54!> @section string_procedures_ja 手続一覧
55!>
56!> | 手続名 | 説明 |
57!> |-----------------|----------------------------------------------------------|
58!> | StoI | 文字列を整数に変換 |
59!> | StoD | 文字列を倍精度実数に変換 |
60!> | get_array | カンマ区切り文字列を配列ポインタに変換 |
61!> | Str_to_Logical | 文字列を論理値に変換 |
62!> | toChar | 数値・論理値を文字列に変換 |
63!> | RoundNum | 数値文字列の端数を除去 |
64!> | JoinChar | 文字配列を区切り文字で連結 |
65!> | Concat | 配列各要素の末尾に文字列を連結 |
66!> | StoA | 複数の文字列を配列に変換 |
67!> | Split | 文字列を区切り文字で分割 |
68!> | Index_Ofs | オフセット付き部分文字列検索 |
69!> | Replace | 文字列の置換 |
70!> | toUpper | 文字列を大文字に変換(上書き) |
71!> | toLower | 文字列を小文字に変換(上書き) |
72!> | UChar | 大文字に変換した文字列を返す |
73!> | LChar | 小文字に変換した文字列を返す |
74!> | StriEq | 大文字小文字を無視した文字列比較 |
75!> | StrHead | 文字列が指定接頭辞で始まるか確認 |
76!> | StrInclude | 配列に指定文字列が含まれるか確認 |
77!> | CPrintf | C言語風printf(文字列を返す) |
78!> | Printf | C言語風printf(装置番号または文字列に出力) |
79!> | PutLine | 配列の要約印字(サイズ、最大、最小、平均) |
80!>
81!> @endja
82!>
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
452 !> @en
453 !> @brief Check if string starts with head
454 !> @details
455 !> Compares the beginning of string `whole` with string `head`.
456 !> Returns .true. if they match, .false. otherwise.
457 !> Returns .false. if `whole` is shorter than `head`.
458 !> @param[in] whole String to check
459 !> @param[in] head Prefix string to match
460 !> @return .true. if whole starts with head
461 !> @enden
462 !>
463 !> @ja
464 !> @brief 文字列が指定接頭辞で始まるか確認
465 !> @details
466 !> 文字列 whole の先頭部分(head と同じ文字列長)と
467 !> 文字列 head とを比較し、同じならば .true. を、
468 !> 異なる場合には .false. を返します。
469 !> whole の文字列長が head の文字列長よりも短い場合には .false. を返します。
470 !> @param[in] whole チェックする文字列
471 !> @param[in] head 一致させる接頭辞
472 !> @return whole が head で始まる場合は .true.
473 !> @endja
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
482 !> @en
483 !> @brief Case-insensitive string comparison
484 !> @details
485 !> Compares string_a and string_b ignoring case.
486 !> Returns .true. if they are equal, .false. otherwise.
487 !> @param[in] string_a First string to compare
488 !> @param[in] string_b Second string to compare
489 !> @return .true. if strings are equal (case-insensitive)
490 !> @enden
491 !>
492 !> @ja
493 !> @brief 大文字小文字を無視した文字列比較
494 !> @details
495 !> 大文字・小文字を無視して文字列の比較を行います。
496 !> 文字列 string_a と文字列 string_b を比較し、同じものならば
497 !> .true. を、異なる場合には .false. を返します。
498 !> @param[in] string_a 比較する1つ目の文字列
499 !> @param[in] string_b 比較する2つ目の文字列
500 !> @return 文字列が等しい場合(大文字小文字無視)は .true.
501 !> @endja
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
520 !> @en
521 !> @brief Check if array contains string
522 !> @details
523 !> Returns .true. if character array carray has an element equal to string.
524 !> Beginning and trailing spaces are ignored by default.
525 !> If ignore_space is .false., beginning spaces are not ignored.
526 !> If ignore_case is .true., comparison is case-insensitive.
527 !> @param[in] carray Character array to search
528 !> @param[in] string String to find
529 !> @param[in] ignore_space If .false., do not ignore leading spaces (default: .true.)
530 !> @param[in] ignore_case If .true., ignore case (default: .false.)
531 !> @return .true. if string is found in carray
532 !> @enden
533 !>
534 !> @ja
535 !> @brief 配列に指定文字列が含まれるか確認
536 !> @details
537 !> 文字型配列引数 carray が文字型引数 string と等しい要素を持つ場合に
538 !> .true. を返します。
539 !> 文字列の前後の空白は無視されます。
540 !> オプショナル引数 ignore_space に .false. を与えた場合には
541 !> 文字列先頭の空白を無視しません。
542 !> オプショナル引数 ignore_case に .true. を与えた場合には
543 !> 大文字、小文字の違いを無視して比較します。
544 !> @param[in] carray 検索する文字配列
545 !> @param[in] string 検索する文字列
546 !> @param[in] ignore_space .false.の場合、先頭空白を無視しない(デフォルト: .true.)
547 !> @param[in] ignore_case .true.の場合、大文字小文字を無視(デフォルト: .false.)
548 !> @return string が carray に含まれる場合は .true.
549 !> @endja
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
593 !> @en
594 !> @brief Convert string to logical
595 !> @details
596 !> Converts the character variable string to logical.
597 !> Returns .false. if string is empty, "0", "0.0", "0.0D0", "0.0d0",
598 !> ".false.", ".FALSE.", "f", "F", "false", or "FALSE".
599 !> Returns .true. otherwise.
600 !> @param[in] string String to convert
601 !> @return Logical value
602 !> @enden
603 !>
604 !> @ja
605 !> @brief 文字列を論理値に変換
606 !> @details
607 !> string で与えられる文字型変数を論理型にして返します。
608 !> string が空、または 0、0.0、0.0D0、0.0d0、.false.、.FALSE.、
609 !> f、F、false、FALSE の場合には .false. が返ります。
610 !> それ以外の場合には .true. が返ります。
611 !> @param[in] string 変換する文字列
612 !> @return 論理値
613 !> @endja
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
625 !> @en
626 !> @brief Convert string to integer
627 !> @details
628 !> Converts the character variable string to integer.
629 !> If string cannot be converted, returns default (or 0 if not specified).
630 !> @param[in] string String to convert
631 !> @param[in] default Default value if conversion fails (optional)
632 !> @return Integer value
633 !> @enden
634 !>
635 !> @ja
636 !> @brief 文字列を整数に変換
637 !> @details
638 !> string で与えられる文字型変数を、整数型変数にして返します。
639 !> もしも string が数値に変換できない場合、default が返ります。
640 !> default を指定しない場合は 0 が返ります。
641 !> @param[in] string 変換する文字列
642 !> @param[in] default 変換失敗時のデフォルト値(省略可能)
643 !> @return 整数値
644 !> @endja
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
659 !> @en
660 !> @brief Convert string to single precision real
661 !> @details
662 !> Converts the character variable string_in to single precision real.
663 !> If string cannot be converted, returns 0.0.
664 !> @param[in] string_in String to convert
665 !> @return Single precision real value
666 !> @enden
667 !>
668 !> @ja
669 !> @brief 文字列を単精度実数に変換
670 !> @details
671 !> string で与えられる文字型変数を、単精度実数型変数にして返します。
672 !> もしも string が数値に変換できない場合、0.0 が返ります。
673 !> @param[in] string_in 変換する文字列
674 !> @return 単精度実数値
675 !> @endja
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
699 !> @en
700 !> @brief Convert string to double precision real
701 !> @details
702 !> Converts the character variable string_in to double precision real.
703 !> If string cannot be converted, returns 0.0.
704 !> @param[in] string_in String to convert
705 !> @return Double precision real value
706 !> @enden
707 !>
708 !> @ja
709 !> @brief 文字列を倍精度実数に変換
710 !> @details
711 !> string で与えられる文字型変数を、倍精度実数型変数にして返します。
712 !> もしも string が数値に変換できない場合、0.0 が返ります。
713 !> @param[in] string_in 変換する文字列
714 !> @return 倍精度実数値
715 !> @endja
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
739 !> @en
740 !> @brief Parse comma-separated string to integer array pointer
741 !> @details
742 !> Parses string_in separated by comma "," and returns integer array pointer int_ptr(:).
743 !> The array size is determined automatically based on string content.
744 !> int_ptr must be null or undefined when passed. Memory leak occurs if already allocated.
745 !> @param[out] int_ptr Integer array pointer
746 !> @param[in] string_in Comma-separated string
747 !> @enden
748 !>
749 !> @ja
750 !> @brief カンマ区切り文字列を整数配列ポインタに変換
751 !> @details
752 !> string で与えられる文字型変数をカンマ「,」で区切り、
753 !> 整数型配列ポインタ int_ptr(:) にして返します。
754 !> int_ptr(:) の配列サイズは string の内容に応じて自動的に決まります。
755 !> ただし、int_ptr(:) は必ず空状態または不定状態で与えてください。
756 !> 既に割り付けられている場合、メモリリークを起こします。
757 !> @param[out] int_ptr 整数配列ポインタ
758 !> @param[in] string_in カンマ区切り文字列
759 !> @endja
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
787 !> @en
788 !> @brief Parse comma-separated string to single precision real array pointer
789 !> @details
790 !> Parses string_in separated by comma "," and returns single precision real array pointer real_ptr(:).
791 !> The array size is determined automatically based on string content.
792 !> real_ptr must be null or undefined when passed. Memory leak occurs if already allocated.
793 !> @param[out] real_ptr Single precision real array pointer
794 !> @param[in] string_in Comma-separated string
795 !> @enden
796 !>
797 !> @ja
798 !> @brief カンマ区切り文字列を単精度実数配列ポインタに変換
799 !> @details
800 !> string で与えられる文字型変数をカンマ「,」で区切り、
801 !> 単精度実数型配列ポインタ real_ptr(:) にして返します。
802 !> real_ptr(:) の配列サイズは string の内容に応じて自動的に決まります。
803 !> ただし、real_ptr(:) は必ず空状態または不定状態で与えてください。
804 !> 既に割り付けられている場合、メモリリークを起こします。
805 !> @param[out] real_ptr 単精度実数配列ポインタ
806 !> @param[in] string_in カンマ区切り文字列
807 !> @endja
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
835 !> @en
836 !> @brief Parse comma-separated string to double precision real array pointer
837 !> @details
838 !> Parses string_in separated by comma "," and returns double precision real array pointer double_ptr(:).
839 !> The array size is determined automatically based on string content.
840 !> double_ptr must be null or undefined when passed. Memory leak occurs if already allocated.
841 !> @param[out] double_ptr Double precision real array pointer
842 !> @param[in] string_in Comma-separated string
843 !> @enden
844 !>
845 !> @ja
846 !> @brief カンマ区切り文字列を倍精度実数配列ポインタに変換
847 !> @details
848 !> string で与えられる文字型変数をカンマ「,」で区切り、
849 !> 倍精度実数型配列ポインタ double_ptr(:) にして返します。
850 !> double_ptr(:) の配列サイズは string の内容に応じて自動的に決まります。
851 !> ただし、double_ptr(:) は必ず空状態または不定状態で与えてください。
852 !> 既に割り付けられている場合、メモリリークを起こします。
853 !> @param[out] double_ptr 倍精度実数配列ポインタ
854 !> @param[in] string_in カンマ区切り文字列
855 !> @endja
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 !
887 !> @en
888 !> @brief Convert integer scalar to string
889 !> @param[in] i Integer value to convert
890 !> @return String representation
891 !> @enden
892 !>
893 !> @ja
894 !> @brief 整数スカラーを文字列に変換
895 !> @param[in] i 変換する整数値
896 !> @return 文字列表現
897 !> @endja
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
905 !> @en
906 !> @brief Convert integer array to string
907 !> @details
908 !> Elements are separated by ", ".
909 !> @param[in] ibuf Integer array to convert
910 !> @return String representation
911 !> @enden
912 !>
913 !> @ja
914 !> @brief 整数配列を文字列に変換
915 !> @details
916 !> 各要素をカンマと空白「, 」で区切って返します。
917 !> @param[in] ibuf 変換する整数配列
918 !> @return 文字列表現
919 !> @endja
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
933 !> @en
934 !> @brief Convert single precision real scalar to string
935 !> @param[in] x Single precision real value to convert
936 !> @return String representation
937 !> @enden
938 !>
939 !> @ja
940 !> @brief 単精度実数スカラーを文字列に変換
941 !> @param[in] x 変換する単精度実数値
942 !> @return 文字列表現
943 !> @endja
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
963 !> @en
964 !> @brief Convert single precision real array to string
965 !> @details
966 !> Elements are separated by ", ".
967 !> @param[in] rbuf Single precision real array to convert
968 !> @return String representation
969 !> @enden
970 !>
971 !> @ja
972 !> @brief 単精度実数配列を文字列に変換
973 !> @details
974 !> 各要素をカンマと空白「, 」で区切って返します。
975 !> @param[in] rbuf 変換する単精度実数配列
976 !> @return 文字列表現
977 !> @endja
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
991 !> @en
992 !> @brief Convert double precision real scalar to string
993 !> @param[in] d Double precision real value to convert
994 !> @return String representation
995 !> @enden
996 !>
997 !> @ja
998 !> @brief 倍精度実数スカラーを文字列に変換
999 !> @param[in] d 変換する倍精度実数値
1000 !> @return 文字列表現
1001 !> @endja
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
1021 !> @en
1022 !> @brief Convert double precision real array to string
1023 !> @details
1024 !> Elements are separated by ", ".
1025 !> @param[in] dbuf Double precision real array to convert
1026 !> @return String representation
1027 !> @enden
1028 !>
1029 !> @ja
1030 !> @brief 倍精度実数配列を文字列に変換
1031 !> @details
1032 !> 各要素をカンマと空白「, 」で区切って返します。
1033 !> @param[in] dbuf 変換する倍精度実数配列
1034 !> @return 文字列表現
1035 !> @endja
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
1049 !> @en
1050 !> @brief Convert logical scalar to string
1051 !> @param[in] l Logical value to convert
1052 !> @return ".true." or ".false."
1053 !> @enden
1054 !>
1055 !> @ja
1056 !> @brief 論理値スカラーを文字列に変換
1057 !> @param[in] l 変換する論理値
1058 !> @return ".true." または ".false."
1059 !> @endja
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
1069 !> @en
1070 !> @brief Convert logical array to string
1071 !> @details
1072 !> Elements are separated by ", ".
1073 !> @param[in] lbuf Logical array to convert
1074 !> @return String representation
1075 !> @enden
1076 !>
1077 !> @ja
1078 !> @brief 論理値配列を文字列に変換
1079 !> @details
1080 !> 各要素をカンマと空白「, 」で区切って返します。
1081 !> @param[in] lbuf 変換する論理値配列
1082 !> @return 文字列表現
1083 !> @endja
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 !-------------------------------------------------------------------
1100 !> @en
1101 !> @brief Join character array with delimiter
1102 !> @details
1103 !> Joins elements of character array carray with ", " delimiter.
1104 !> If expr is given, uses that string as delimiter.
1105 !> @param[in] carray Character array to join
1106 !> @param[in] expr Delimiter string (optional, default: ", ")
1107 !> @return Joined string
1108 !> @enden
1109 !>
1110 !> @ja
1111 !> @brief 文字配列を区切り文字で連結
1112 !> @details
1113 !> 文字型配列 carray に与えた複数の文字列をカンマと空白「, 」で
1114 !> 区切った1つの文字列にして返します。
1115 !> expr に文字列を与えると、その文字列を区切り文字として用います。
1116 !> @param[in] carray 連結する文字配列
1117 !> @param[in] expr 区切り文字列(省略可能、デフォルト: ", ")
1118 !> @return 連結された文字列
1119 !> @endja
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
1144 !> @en
1145 !> @brief Concatenate string to array elements
1146 !> @details
1147 !> Appends str to the end of each element of character array carray
1148 !> and returns in result. Trailing spaces of carray elements are ignored.
1149 !> The array size of result(:) is determined automatically based on carray size.
1150 !> result(:) must be null or undefined when passed. Memory leak occurs if already allocated.
1151 !> @param[in] carray Character array
1152 !> @param[in] str String to append
1153 !> @param[out] result Result array pointer
1154 !> @enden
1155 !>
1156 !> @ja
1157 !> @brief 配列各要素の末尾に文字列を連結
1158 !> @details
1159 !> 文字型配列 carray の各成分の末尾に str を追加して result に返します。
1160 !> carray の各成分の末尾の空白は無視されます。
1161 !> result(:) の配列サイズは carray のサイズに応じて自動的に決まります。
1162 !> ただし、result(:) は必ず空状態または不定状態で与えてください。
1163 !> 既に割り付けられている場合、メモリリークを起こします。
1164 !> @param[in] carray 文字配列
1165 !> @param[in] str 追加する文字列
1166 !> @param[out] result 結果の配列ポインタ
1167 !> @endja
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
1181 !> @en
1182 !> @brief Convert 1 string(s) to array
1183 !> @details
1184 !> Converts multiple character variables of different lengths into a single character array.
1185 !> @return Character array of size 1
1186 !> @enden
1187 !>
1188 !> @ja
1189 !> @brief 1 個の文字列を配列に変換
1190 !> @details
1191 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1192 !> @return サイズ 1 の文字配列
1193 !> @endja
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
1200 !> @en
1201 !> @brief Convert 2 string(s) to array
1202 !> @details
1203 !> Converts multiple character variables of different lengths into a single character array.
1204 !> @return Character array of size 2
1205 !> @enden
1206 !>
1207 !> @ja
1208 !> @brief 2 個の文字列を配列に変換
1209 !> @details
1210 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1211 !> @return サイズ 2 の文字配列
1212 !> @endja
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
1220 !> @en
1221 !> @brief Convert 3 string(s) to array
1222 !> @details
1223 !> Converts multiple character variables of different lengths into a single character array.
1224 !> @return Character array of size 3
1225 !> @enden
1226 !>
1227 !> @ja
1228 !> @brief 3 個の文字列を配列に変換
1229 !> @details
1230 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1231 !> @return サイズ 3 の文字配列
1232 !> @endja
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
1241 !> @en
1242 !> @brief Convert 4 string(s) to array
1243 !> @details
1244 !> Converts multiple character variables of different lengths into a single character array.
1245 !> @return Character array of size 4
1246 !> @enden
1247 !>
1248 !> @ja
1249 !> @brief 4 個の文字列を配列に変換
1250 !> @details
1251 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1252 !> @return サイズ 4 の文字配列
1253 !> @endja
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
1263 !> @en
1264 !> @brief Convert 5 string(s) to array
1265 !> @details
1266 !> Converts multiple character variables of different lengths into a single character array.
1267 !> @return Character array of size 5
1268 !> @enden
1269 !>
1270 !> @ja
1271 !> @brief 5 個の文字列を配列に変換
1272 !> @details
1273 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1274 !> @return サイズ 5 の文字配列
1275 !> @endja
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
1286 !> @en
1287 !> @brief Convert 6 string(s) to array
1288 !> @details
1289 !> Converts multiple character variables of different lengths into a single character array.
1290 !> @return Character array of size 6
1291 !> @enden
1292 !>
1293 !> @ja
1294 !> @brief 6 個の文字列を配列に変換
1295 !> @details
1296 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1297 !> @return サイズ 6 の文字配列
1298 !> @endja
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
1310 !> @en
1311 !> @brief Convert 7 string(s) to array
1312 !> @details
1313 !> Converts multiple character variables of different lengths into a single character array.
1314 !> @return Character array of size 7
1315 !> @enden
1316 !>
1317 !> @ja
1318 !> @brief 7 個の文字列を配列に変換
1319 !> @details
1320 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1321 !> @return サイズ 7 の文字配列
1322 !> @endja
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
1335 !> @en
1336 !> @brief Convert 8 string(s) to array
1337 !> @details
1338 !> Converts multiple character variables of different lengths into a single character array.
1339 !> @return Character array of size 8
1340 !> @enden
1341 !>
1342 !> @ja
1343 !> @brief 8 個の文字列を配列に変換
1344 !> @details
1345 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1346 !> @return サイズ 8 の文字配列
1347 !> @endja
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
1361 !> @en
1362 !> @brief Convert 9 string(s) to array
1363 !> @details
1364 !> Converts multiple character variables of different lengths into a single character array.
1365 !> @return Character array of size 9
1366 !> @enden
1367 !>
1368 !> @ja
1369 !> @brief 9 個の文字列を配列に変換
1370 !> @details
1371 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1372 !> @return サイズ 9 の文字配列
1373 !> @endja
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
1388 !> @en
1389 !> @brief Convert 10 string(s) to array
1390 !> @details
1391 !> Converts multiple character variables of different lengths into a single character array.
1392 !> @return Character array of size 10
1393 !> @enden
1394 !>
1395 !> @ja
1396 !> @brief 10 個の文字列を配列に変換
1397 !> @details
1398 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1399 !> @return サイズ 10 の文字配列
1400 !> @endja
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
1416 !> @en
1417 !> @brief Convert 11 string(s) to array
1418 !> @details
1419 !> Converts multiple character variables of different lengths into a single character array.
1420 !> @return Character array of size 11
1421 !> @enden
1422 !>
1423 !> @ja
1424 !> @brief 11 個の文字列を配列に変換
1425 !> @details
1426 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1427 !> @return サイズ 11 の文字配列
1428 !> @endja
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
1445 !> @en
1446 !> @brief Convert 12 string(s) to array
1447 !> @details
1448 !> Converts multiple character variables of different lengths into a single character array.
1449 !> @return Character array of size 12
1450 !> @enden
1451 !>
1452 !> @ja
1453 !> @brief 12 個の文字列を配列に変換
1454 !> @details
1455 !> 異なる長さの複数の文字型変数を1つの文字型配列に変換します。
1456 !> @return サイズ 12 の文字配列
1457 !> @endja
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 !-------------------------------------------------------------------
1478 !> @en
1479 !> @brief Split string by separator
1480 !> @details
1481 !> Splits string str by separator sep and returns in pointer array carray.
1482 !> carray must be null when passed. Error is returned if already allocated.
1483 !> If limit is a positive number, splits into at most limit fields.
1484 !> If limit is negative or 0, same as omitting it.
1485 !> Trailing spaces of str are removed.
1486 !> If sep is empty string, splits by whitespace.
1487 !> @param[in] str String to split
1488 !> @param[out] carray Result pointer array
1489 !> @param[in] sep Separator string
1490 !> @param[in] limit Maximum number of fields (optional)
1491 !> @enden
1492 !>
1493 !> @ja
1494 !> @brief 文字列を区切り文字で分割
1495 !> @details
1496 !> str で与えられた文字列を文字列 sep で分解し、
1497 !> ポインタ配列 carray に返します。
1498 !> carray は必ず空状態にして与えてください。
1499 !> 割り付け状態の場合にはエラーを返します。
1500 !> limit に正の数を与えた場合、最大 limit 個のフィールドに分割します。
1501 !> 負の数や 0 の場合は省略した場合と同じになります。
1502 !> str の末尾の空白は除去されます。
1503 !> sep に空文字を代入する場合、空白文字で分割されます。
1504 !> @param[in] str 分割する文字列
1505 !> @param[out] carray 結果のポインタ配列
1506 !> @param[in] sep 区切り文字列
1507 !> @param[in] limit 最大フィールド数(省略可能)
1508 !> @endja
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 !-------------------------------------------------------------------
1587 !> @en
1588 !> @brief Find substring position with offset
1589 !> @details
1590 !> Returns the starting position where substr is found in string,
1591 !> searching from position start. Returns 0 if not found.
1592 !> The returned position is counted from the beginning of string.
1593 !> @param[in] string String to search in
1594 !> @param[in] start Starting position for search
1595 !> @param[in] substr Substring to find
1596 !> @return Position of substr, or 0 if not found
1597 !> @enden
1598 !>
1599 !> @ja
1600 !> @brief オフセット付き部分文字列検索
1601 !> @details
1602 !> 文字列 string の start 文字目以降の文字列の中に substr の文字列が
1603 !> 含まれている時、その開始文字位置を返します。
1604 !> 含まれない場合は 0 を返します。
1605 !> 返される開始文字位置は文字列 string の先頭から数えます。
1606 !> @param[in] string 検索対象の文字列
1607 !> @param[in] start 検索開始位置
1608 !> @param[in] substr 検索する部分文字列
1609 !> @return substr の位置、見つからない場合は 0
1610 !> @endja
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
1624 !> @en
1625 !> @brief Replace substring in string
1626 !> @details
1627 !> If string from is included in str, replaces it with string to and returns.
1628 !> If from is not included, returns str without change.
1629 !> When multiple from are included, only the first one is replaced.
1630 !> To replace all from to to, give .true. to optional argument recursive.
1631 !> By default, the string is searched from the top.
1632 !> If optional argument start_pos is given, the search starts from start_pos.
1633 !> @param[in] str Source string
1634 !> @param[in] from String to find
1635 !> @param[in] to Replacement string
1636 !> @param[in] recursive If .true., replace all occurrences (optional)
1637 !> @param[in] start_pos Starting position for search (optional)
1638 !> @return Replaced string
1639 !> @enden
1640 !>
1641 !> @ja
1642 !> @brief 文字列の置換
1643 !> @details
1644 !> 文字列 str に文字列 from が含まれる場合、その部分を文字列 to に置換して返します。
1645 !> 文字列 from が含まれない場合は str をそのまま返します。
1646 !> from が複数含まれる場合、先頭の from のみが置換されます。
1647 !> 全ての from を to へ変換したい場合には、
1648 !> オプショナル引数 recursive に .true. を与えてください。
1649 !> デフォルトでは、文字列の最初から検索を行います。
1650 !> オプショナル引数 start_pos を与える場合、start_pos 文字目から検索を行います。
1651 !> @param[in] str 元の文字列
1652 !> @param[in] from 検索する文字列
1653 !> @param[in] to 置換後の文字列
1654 !> @param[in] recursive .true.の場合、全ての出現箇所を置換(省略可能)
1655 !> @param[in] start_pos 検索開始位置(省略可能)
1656 !> @return 置換後の文字列
1657 !> @endja
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 !-------------------------------------------------------------------
1714 !> @en
1715 !> @brief Convert string to uppercase (in-place)
1716 !> @details
1717 !> Converts all lowercase letters in ch to uppercase.
1718 !> Non-alphabetic characters and already uppercase characters are unchanged.
1719 !> @param[in,out] ch String to convert
1720 !> @enden
1721 !>
1722 !> @ja
1723 !> @brief 文字列を大文字に変換(上書き)
1724 !> @details
1725 !> 文字列 ch に英字が含まれる場合、その英字を大文字に変換して ch に返します。
1726 !> 英字でない文字や既に大文字になっている文字はそのまま返します。
1727 !> @param[in,out] ch 変換する文字列
1728 !> @endja
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
1741 !> @en
1742 !> @brief Convert string to lowercase (in-place)
1743 !> @details
1744 !> Converts all uppercase letters in ch to lowercase.
1745 !> Non-alphabetic characters and already lowercase characters are unchanged.
1746 !> @param[in,out] ch String to convert
1747 !> @enden
1748 !>
1749 !> @ja
1750 !> @brief 文字列を小文字に変換(上書き)
1751 !> @details
1752 !> 文字列 ch に英字が含まれる場合、その英字を小文字に変換して ch に返します。
1753 !> 英字でない文字や既に小文字になっている文字はそのまま返します。
1754 !> @param[in,out] ch 変換する文字列
1755 !> @endja
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
1768 !> @en
1769 !> @brief Return uppercase copy of string
1770 !> @details
1771 !> Returns a copy of ch with all lowercase letters converted to uppercase.
1772 !> Non-alphabetic characters and already uppercase characters are unchanged.
1773 !> @param[in] ch String to convert
1774 !> @return Uppercase string
1775 !> @enden
1776 !>
1777 !> @ja
1778 !> @brief 大文字に変換した文字列を返す
1779 !> @details
1780 !> 文字列 ch に英字が含まれる場合、その英字を大文字に変換して返します。
1781 !> 英字でない文字や既に大文字になっている文字はそのまま返します。
1782 !> @param[in] ch 変換する文字列
1783 !> @return 大文字に変換された文字列
1784 !> @endja
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
1791 !> @en
1792 !> @brief Return lowercase copy of string
1793 !> @details
1794 !> Returns a copy of ch with all uppercase letters converted to lowercase.
1795 !> Non-alphabetic characters and already lowercase characters are unchanged.
1796 !> @param[in] ch String to convert
1797 !> @return Lowercase string
1798 !> @enden
1799 !>
1800 !> @ja
1801 !> @brief 小文字に変換した文字列を返す
1802 !> @details
1803 !> 文字列 ch に英字が含まれる場合、その英字を小文字に変換して返します。
1804 !> 英字でない文字や既に小文字になっている文字はそのまま返します。
1805 !> @param[in] ch 変換する文字列
1806 !> @return 小文字に変換された文字列
1807 !> @endja
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
1814 !> @en
1815 !> @brief Round numeric string representation
1816 !> @details
1817 !> Formats numeric strings like '0.30000001' or '12.999998' that have
1818 !> rounding errors to cleaner representations like '0.3' or '13.'.
1819 !> @param[in] num Numeric string to round
1820 !> @return Rounded numeric string
1821 !> @enden
1822 !>
1823 !> @ja
1824 !> @brief 数値文字列の端数を除去
1825 !> @details
1826 !> '0.30000001' や '12.999998' などの丸め誤差によって端数が残っている
1827 !> 数値表記を '0.3' や '13.' などに整形して返します。
1828 !> @param[in] num 端数を除去する数値文字列
1829 !> @return 整形された数値文字列
1830 !> @endja
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
1959 !> @namespace dc_string
1960end module
character(len=string) function dcstringcprintf(fmt, i, r, d, l, n, c1, c2, c3, ca, maxlen)
Formatted output conversion (function version).
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)
Formatted output conversion to file unit.
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)
Print array summary (PutLine subroutines).
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)
Formatted output conversion (similar to C sprintf).
Handling character types.
Definition dc_string.f90:83
character(string) function, public joinchar(carray, expr)
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public token
Character length for word, token
Definition dc_types.f90:128
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92
integer, parameter, public sp
Single Precision Real number.
Definition dc_types.f90:82