@rdryne , in this instance the simple assignment is the same as u = 1.0_qp * z
and they are equivalent to u = real(z, kind(u) )
.
So you can try out the following:
use, intrinsic :: iso_fortran_env, only : dp => real64, qp => real128
character(len=*), parameter :: fmtg = "(*(g0))"
real(dp) :: z
real(qp) :: u
z = 0.123456789_dp
u = z
print fmtg, "1) u = z: ", u
u = real( z, kind(u) )
print fmtg, "2) u = real( z, .. : ", u
u = 1.0_qp * z
print fmtg, "3) u = 1.0_qp*z : ", u
call dp_to_qp( u, z )
print fmtg, "4) dp_to_qp( u, z ): ", u
contains
elemental subroutine dp_to_qp( lhs, rhs )
real(kind=qp), intent(out) :: lhs
real(kind=dp), intent(in) :: rhs
character(len=*), parameter :: fmtdp = "(1pg22.15)"
character(len=22) :: s
write( s, fmtdp ) rhs
read( s, fmt=*) lhs
end subroutine
end
which can lead to the following output:
C:\temp>ifort /standard-semantics p.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.30.30706.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:p.exe
-subsystem:console
p.obj
C:\temp>p.exe
1) u = z: .123456788999999997336054491370305
2) u = real( z, .. : .123456788999999997336054491370305
3) u = 1.0_qp*z : .123456788999999997336054491370305
4) dp_to_qp( u, z ): .123456789000000000000000000000000
Based on your original post, it appears you want the behavior with 4) and that’s why I suggested you to consider such a helper subprogram to help you achieve your goal.