FNLMath : Introduction : Overloaded =, /=, etc., for Derived Types
Overloaded =, /=, etc., for Derived Types
To assist users in writing compact and readable code, the IMSL Fortran Numerical Library provides overloaded assignment and logical operations for the derived types s_options, d_options, s_error, and d_error. Each of these derived types has an individual record consisting of an integer and a floating-point number. The components of the derived types, in all cases, are named idummy followed by rdummy. In many cases, the item referenced is the component idummy. This integer value can be used exactly as any integer by use of the component selector character (%). Thus, a program could assign a value and test after calling a routine:
s_epack(1)%idummy = 0
call lin_sol_gen(A,b,x,epack=s_epack)
if (s_epack(1)%idummy > 0) call error_post(s_epack)
Using the overloaded assignment and logical operations, this code fragment can be written in the equivalent and more readable form:
s_epack(1) = 0
call lin_sol_gen(A,b,x,epack=s_epack)
if (s_epack(1) > 0) call error_post(s_epack)
Generally the assignments and logical operations refer only to component idummy. The assignment “s_epack(1)=0” is equivalent to “s_epack(1)=s_error(0,0E0)”. Thus, the floating-point component rdummy is assigned the value 0E0. The assignment statement “I=s_epack(1)”, for I an integer type, is equivalent to “I=s_epack(1)%idummy”. The value of component rdummy is ignored in this assignment. For the logical operators, a single element of any of the IMSL Fortran Numerical Library derived types can be in either the first or second operand.
Derived Type
Overloaded Assignments and Tests
s_options
I=s_options(1);s_options(1)=I
= =
/=
<
<=
>
>=
d_options
I=d_options(1);d_options(1)=I
= =
/=
<
<=
>
>=
s_epack
I=s_epack(1);s_epack(1)=I
= =
/=
<
<=
>
>=
d_epack
I=d_epack(1);d_epack(1)=I
= =
/=
<
<=
>
>=
In the examples, operator_ex01, , _ex37, the overloaded assignments and tests have been used whenever they improve the readability of the code.
Published date: 03/19/2020
Last modified date: 03/19/2020