gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dc_units Module Reference

Unit system processing module. More...

Data Types

type  units
interface  clear
interface  deallocate
interface  operator(*)
interface  operator(/)
interface  operator(+)

Functions/Subroutines

logical function, public add_okay (u1, u2)

Detailed Description

Unit system processing module.

Author
Youhei SASAKI, Eizi TOYODA, Yasuhiro MORIKAWA

This module provides procedures for unit system processing. It includes a derived type UNITS for representing physical units and operators for unit arithmetic (multiplication, division, addition).

Operators and Procedures

Operator/Procedure Description
assignment(=) Build UNITS from string or convert to string
operator(*) Multiply two UNITS
operator(/) Divide two UNITS
operator(+) Add two UNITS (with compatibility check)
clear Initialize UNITS variable
deallocate Deallocate UNITS variable
add_okay Check if two UNITS are compatible for addition

Function/Subroutine Documentation

◆ add_okay()

logical function, public dc_units::add_okay ( type(units), intent(in) u1,
type(units), intent(in) u2 )

Check if two UNITS are compatible for addition

Two units are compatible if they have the same dimensions (i.e., the same unit elements with the same powers).

Parameters
[in]u1First UNITS variable
[in]u2Second UNITS variable
Returns
.true. if compatible, .false. otherwise

Definition at line 307 of file dc_units.f90.

308 type(UNITS), intent(in):: u1, u2
309 type(UNITS):: x
310 character(STRING):: debug
311 call clear(x)
312 x = u1 / u2
313 debug = u1
314 debug = u2
315 debug = x
316 if (x%nelems == 0) then
317 result = .true.
318 else if (all(abs(x%power(1:x%nelems)) < tiny(0.0_dp))) then
319 result = .true.
320 else
321 result = .false.
322 endif
323 call deallocate(x)