Skip to content

Instantly share code, notes, and snippets.

@DSCF-1224
Last active March 27, 2022 22:18
Show Gist options
  • Save DSCF-1224/b21e629c983f298a14afd366e03a07a2 to your computer and use it in GitHub Desktop.
Save DSCF-1224/b21e629c983f298a14afd366e03a07a2 to your computer and use it in GitHub Desktop.
組み込み関数 TRIM の挙動の確認
! gfortran, gcc version 7.4.0
! https://stdlib.fortran-lang.org/sourcefile/stdlib_strings.fypp.html
program test
use , intrinsic :: iso_fortran_env
implicit none
character(len=1) , parameter :: ASCII_HT = achar(int(Z'09'))
character(len=1) , parameter :: ASCII_LF = achar(int(Z'0A'))
character(len=1) , parameter :: ASCII_VT = achar(int(Z'0B'))
character(len=1) , parameter :: ASCII_FF = achar(int(Z'0C'))
character(len=1) , parameter :: ASCII_CR = achar(int(Z'0D'))
call test_trim('A' // ASCII_HT // 'Z')
call test_trim('A' // ASCII_LF // 'Z')
call test_trim('A' // ASCII_VT // 'Z')
call test_trim('A' // ASCII_FF // 'Z')
call test_trim('A' // ASCII_CR // 'Z')
contains
subroutine test_trim (string)
! arguments
character(len=3) , intent(in) :: string
print * , ''
print * , string , len(string)
print * , trim(string) , len(trim(string))
print * , '12345678'
return
end subroutine test_trim
end program test
A Z 3
A Z 3
12345678
A
Z 3
A
Z 3
12345678
A Z 3
A Z 3
12345678
A Z 3
A Z 3
12345678
AZ 3
AZ 3
12345678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment