Append
Append is a generic subroutine to append entries to vector of real or integer.
While calling Append the initial vector can be unallocated in the begining.
Calling examples:
CALL Append(A, entry)
CALL Append(C, A, B)
CALL Append(A, entry, mask)
CALL Append(C, A, B, mask)
Interface 1
- Append (1)
- Example 1
- Example 2
- ↢
CALL Append(A, entry)
Here,
A
can be an allocatable vector of real or integer.entry
can be a scalar of real or integer.entry
can be a vector of real or integer.
We can:
- Append a scalar-integer to an integer-vector
- Append an integer-vector and scalar to an integer-vector
- Append a scalar-real to a real-vector
- Append a real-vector to a real-vector
We can also use this method as:
A = A .append. entry
PROGRAM main
USE easifemBase
IMPLICIT NONE
INTEGER(I4B), ALLOCATABLE :: intvec1(:)
REAL( DFP ), ALLOCATABLE :: realvec1(:)
Now lets us append a single ENTRY to a vector of integers.
CALL Append(intvec1, 1)
CALL OK( ALL(intvec1 .EQ. [1]), "Append single ENTRY" )
Appending a vector to a vector.
CALL Append(intvec1, [2,3])
CALL OK( ALL(intvec1 .EQ. [1,2,3]), "Append a vector" )
Now lets us append a single real value to realvec.
CALL Append(realvec1, 1.0_DFP)
CALL OK( ALL(realvec1 .EQ. [1.0_DFP]), "Append single ENTRY" )
Appending vector to a vector.
CALL Append(realvec1, [2.0_DFP,3.0_DFP])
CALL OK( ALL(realvec1 .EQ. [1.0_DFP,2.0_DFP,3.0_DFP]), "Append a vector" )
Cleanup
DEALLOCATE(intvec1, realvec1)
END PROGRAM main
PROGRAM main
USE easifemBase
IMPLICIT NONE
INTEGER(I4B), ALLOCATABLE :: intvec1(:)
REAL( DFP ), ALLOCATABLE :: realvec1(:)
Now lets us append a single ENTRY to a vector of integers.
intvec1 = [1] .append. 2
CALL OK( ALL(intvec1 .EQ. [1, 2]), "Append single ENTRY" )
Appending a vector to a vector.
intvec1 = intvec1 .append. [3]
CALL OK( ALL(intvec1 .EQ. [1,2,3]), "Append a vector" )
Now lets us append a single real value to realvec.
realvec1 = [1.0_DFP] .append. 2.0_DFP
CALL OK( ALL(realvec1 .EQ. [1.0_DFP, 2.0_DFP]), "Append single ENTRY" )
Appending vector to a vector.
realvec1 = realvec1 .append. [3.0_DFP]
CALL OK( ALL(realvec1 .EQ. [1.0_DFP,2.0_DFP,3.0_DFP]), "Append a vector" )
Cleanup
DEALLOCATE(intvec1, realvec1)
END PROGRAM main
Interface 2
- Append (2)
- See example
- ↢
CALL Append(C, A, B)
where,
- Append A and B, then assign it to
C
C
can be an allocatable vector of real or integerA
can be a vector of real or integerB
can be a scalar of real or integerB
can be a vector of real or integer
Currently, A
cannot be scalar in the above interface.
We can:
- Append a scalar and a vector of int to another vector of int
- Append two vectors of int to another vector of int
- Append a scalar and a vector of real to another vector of real
- Append two vectors of real to another vector of real
PROGRAM main
USE easifemBase
IMPLICIT NONE
INTEGER(I4B), ALLOCATABLE :: C(:), B(:), A(:)
A = [1]
B = [2]
CALL Append(C, A, B)
CALL OK( ALL(C .EQ. [1, 2]), "tests(1):" )
A = [1]
CALL Append(C, A, 2)
CALL OK( ALL(C .EQ. [1, 2]), "tests(2):" )
END PROGRAM main
Interface 3
- Append (3)
- See example
- ↢
CALL Append(A, entry, mask)
here,
A
is an allocatable vector of real or integer.entry
can be a scalar of real or integer. In this casemask
is a scalar of logical typeentry
can be a vector of real or integer. In this case,mask
will be a vector of logical types.
The size of mask
should be same as the size of entry
.
We can:
- Masked append a scalar integer to a vector of int
- Masked append a scalar real to a vector of reals
- Masked append a vector of integer to a vector of integer
- Masked append a vector of real to a vector of real
PROGRAM main
USE easifemBase
IMPLICIT NONE
INTEGER(I4B), ALLOCATABLE :: intvec1(:)
Now lets us append a single ENTRY to a vector.
CALL Append(intvec1, 1, mask=.true.)
CALL Append(intvec1, 1, mask=.false.)
CALL OK( ALL(intvec1 .EQ. [1]), "Append single ENTRY" )
Appending a vector to a vector.
CALL Append(intvec1, [2,3], mask=[.true., .true.])
CALL Append(intvec1, [4,5], mask=[.true., .false.])
CALL OK( ALL(intvec1 .EQ. [1,2,3,4]), "Append a vector" )
END PROGRAM main
Interface 4
- Append (4)
- See example
- ↢
CALL Append(C, A, B, mask)
where,
C
is an allocatable vector of real or integerA
is a vector of real or integerB
is a vector of real or integer
Currently, we do not allow A
to be a scalar in the above call.
We can:
- Masked append a scalar and vector of int to another vector of int
- Masked append a scalar and vector real to another vector of real
- Masked append two vectors of integer to another vector of integer
- Masked append two vectors of real to another vector of real
PROGRAM main
USE easifemBase
IMPLICIT NONE
INTEGER(I4B), ALLOCATABLE :: C(:), B(:), A(:)
A = [1, 2]
B = [3, 4]
!!
!! Append B(1) and B(2) to A and assign to C.
!!
CALL Append(C, A, B, mask=[.true., .true.])
CALL OK( ALL(C .EQ. [1, 2, 3, 4]), "Append:" )
!!
!! Append B(1) to A and assign to C.
!!
CALL Append(C, A, B, mask=[.true., .false.])
CALL OK( ALL(C .EQ. [1, 2, 3]), "Append:" )
!!
!! Do not append B to A, just assign A to C.
!!
CALL Append(C, A, B, mask=[.false., .false.])
CALL OK( ALL(C .EQ. [1, 2]), "Append:" )
!!
!! Append 3 to A and then assign result to C
!!
CALL Append(C, A, 3, mask=.true.)
CALL OK( ALL(C .EQ. [1, 2, 3]), "Append:" )
!!
!! Do not append 3 to A, assign result to C, that is C =A
!!
CALL Append(C, A, 3, mask=.false.)
CALL OK( ALL(C .EQ. [1, 2]), "Append:" )
END PROGRAM main