
Objects of the Compression class can be used to compress and decompress field data. In addition, they can be added or subtracted to create new Compression objects.
MODULE Compression_Class
TYPE Compression
INTERFACE isValid
INTERFACE initialize
INTERFACE finalize
INTERFACE equal
INTERFACE unequal
INTERFACE get
INTERFACE set
INTERFACE print
INTERFACE clear
INTERFACE getOffset
INTERFACE getScale
INTERFACE setOffset
INTERFACE setScale
INTERFACE ASSIGNMENT (=)
INTERFACE OPERATOR (==)
INTERFACE OPERATOR (/=)
INTERFACE OPERATOR (+)
INTERFACE OPERATOR (-)
INTERFACE OPERATOR (*)
INTERFACE OPERATOR (/)
INTERFACE OPERATOR (.decompress.)
INTERFACE OPERATOR (.compress.)
END MODULE Compression_Class
FUNCTION isValid(this) RESULT(result)
LOGICAL :: result
TYPE(Compression), INTENT(in) :: this
This function checks whether the parameter this contains a valid Compression object. It may be applied to any Compression object at any time.
SUBROUTINE
initialize(this,offset,scale)
TYPE(Compression), INTENT(out)
:: this
REAL,
INTENT(in), OPTIONAL :: offset
REAL,
INTENT(in), OPTIONAL :: scale
This subroutine initializes an (invalid) Compression object. This subroutine should be invoked on an object before any other function or subroutine except isValid. After initialization, the parameter this contains a valid Compression object. Compression is performed by subtracting the offset followed by a division by scale.
SUBROUTINE finalize(this)
TYPE(Compression), INTENT(inout) :: this
This subroutine finalizes the (valid) Compression object, this. This object should have been initialized earlier in the program. After finalization, the object is invalid and should not be used anymore.
FUNCTION equal(left,right) RESULT(result)
LOGICAL :: result
TYPE(Compression), INTENT(in) :: left
TYPE(Compression), INTENT(in) :: right
This function compares two Compression objects. When the two objects are equal, the value .TRUE. is returned. Otherwise, the return value is .FALSE.. Two Compression object are equal when their offset and scale values are equal.
This function can also be invoked via the binary operator ==.
FUNCTION unequal(left,right)
RESULT(result)
LOGICAL :: result
TYPE(Compression), INTENT(in) :: left
TYPE(Compression), INTENT(in) :: right
This function checks whether two Compression objects are different, i.e. whether their offset or scale values differ.
This function can also be invoked via the binary operator /=.
SUBROUTINE get(this,offset,scale)
TYPE(Compression), INTENT(in)
:: this
REAL,
INTENT(out), OPTIONAL :: offset
REAL,
INTENT(out), OPTIONAL :: scale
This subroutine retrieves information from the Compression object, this. The object itself is not modified. The optional parameters determine which information will be retrieved. This subroutine can be invoked without any parameters. In this case, the subroutine is as a no-op.
SUBROUTINE set(this,offset,scale)
TYPE(Compression), INTENT(inout)
:: this
REAL,
INTENT(in), OPTIONAL :: offset
REAL,
INTENT(in), OPTIONAL :: scale
This subroutine modifies the Compression object, this. The optional parameters determine which information is modified. This subroutine can be invoked without any parameters. In this case, the subroutine is as a no-op.
SUBROUTINE print(this)
TYPE(Compression), INTENT(in) :: this
This subroutine is the equivalent of the Fortran PRINT statement. It prints the Compression object, this, to the standard output unit in standardized format. The object is not modified.
SUBROUTINE clear(this)
TYPE(Compression), INTENT(inout) :: this
This subroutine clears this Compression object. This means that the offset is set to zero and the scale to one.
FUNCTION getOffset(this)
RESULT(result)
REAL :: result
TYPE(Compression), INTENT(in) :: this
This function returns the offset of this Compression object.
FUNCTION getScale(this) RESULT(result)
REAL :: result
TYPE(Compression), INTENT(in) :: this
This function returns the scale of this Compression object.
SUBROUTINE setOffset(this,offset)
TYPE(Compression), INTENT(in) :: this
REAL,
INTENT(in) :: offset
This subroutine sets the offset of this Compression object.
SUBROUTINE setScale(this,scale)
TYPE(Compression), INTENT(in) :: this
REAL,
INTENT(in) :: scale
This subroutine sets the scale of this Compression object.
ASSIGNMENT (=) <left> = <right>
This operator copies the content of the Compression object at the right of the assignment operator to the one at the left. The object at the left can be invalid before the assignment. If the left object was valid before the assignment, it is finalized first. After the assignment it is valid and equal to the right object.
OPERATOR (==) <left> == <right>
This operator compares two Compression objects for equality. This is an alternative for the equal function.
OPERATOR (/=) <left> /= <right>
This operator compares two Compression objects for inequality. This is an alias for the unequal function.
This operator adds two Compression objects. Addition is performed by adding offset and scale values.
This operator subtracts two Compression objects. Subtraction is performed by subtracting offset and scale values.
OPERATOR
(*)
<left> * <right>
OPERATOR (.decompress.)
<left> .decompress. <right>
These operators decompress the data at the left using the Compression object at the right.
OPERATOR
(/)
<left> / <right>
OPERATOR (.compress.)
<left> .compress. <right>
These operators compress the data at the left using the Compression object given at the right.
The example program shows how you can create Compression objects and how to use them to compress and decompress data.
PROGRAM Compression_Class_Example USE Compression_Class IMPLICIT NONE TYPE(Compression) :: c1, c2, c3 REAL :: value CALL initialize(c1,offset= 1.5,scale=0.5) CALL initialize(c2,offset=-1.0,scale=2.5) c3 = c1 + c2 value = 5.0 PRINT*,'Value=',value value = value/c3 ! Or value .compress. c3 PRINT*,'Compressed value=',value value = value*c3 ! Or value .decompress. c3 PRINT*,'Decompressed value=',value CALL finalize(c3) CALL finalize(c2) CALL finalize(c1) END PROGRAM Compression_Class_Example