Disclaimer:
Someone has already pointed (correctly) in the comments that use rename => name
can be used independently of use, only
. Like this:
use module, f354 => function354
I am keeping the answer because it could be useful as complementary information on the use
statement for someone that lands here.
Original Answer:
Just for completeness, there is another feature that use, only
provides, that is the ability to rename imported names with locally-bound names (only is not needed for this, see disclaimer above).
Like this:
use module, only: f354 => function354
That has proven useful for me in several different scenarios:
Resolve specific name ambiguities when two used modules provide types or functions with the same name.
Example:
use module1, only: m1_init => initialize
use module2, only: m2_init => initialize
Use short names when the original name is too long, too cryptic or when it is used very often in your program.
Example (from fgsl and lapack):
use fgsl, only: stride => fgsl_aux_vector_double_stride ! too long
use lapack, only: solve => dgesvx ! too cryptic
use iso_c_binding, only: i32 => c_int32_t, i64 => c_int64_t ! too frequent
Make it easier to refactor or use conditional compilation / templating:
Example (from Fortran-lang/stdlib):
use iso_fortran_env, only: sp => real32, dp => real64, qp => real128
! If we decide later to use iso_c_binding instead of iso_fortran_env:
! use iso_c_binding, only: sp => c_float, dp => c_double, qp => c_float128