code(3f) - [M_datapac:VECTOR_OPERATIONS] code the elements of a vector (1 for the minimum, 2 for the next larger value, and so on)
Synopsis
Description
Input Arguments
Output Arguments
Examples
Author
Maintainer
License
SUBROUTINE CODE(X,N,Y)
REAL(kind=wp),intent(in) :: X(:) INTEGER,intent(in) :: N REAL(kind=wp),intent(out) :: Y(:)
CODE(3f) codes the elements of the input vector X and puts the coded values into the output vector Y. This essentially ranks the array elements so they can be accessed in ascending order like RANK(3f), but allowing duplicate ranks.
The coding is as follows--
o the minimum is coded as 1.0. o the next larger value as 2.0, o the next larger value as 3.0, o etc.
X The vector of observations to be coded. The input vector X remains unaltered. N The integer number of observations in the vector X. The maximum allowable value of N for this subroutine is 15000.
Y The vector Y which will contain the coded values corresponding to the observations in the vector X. It must be at least as large as X.
o All occurrences of the minimum are coded as 1.0; o All occurrences of the next larger value are coded as 2.0; o All occurrences of the next larger value are coded as 3.0, etc.
Sample program:
program demo_code use M_datapac, only : code implicit none integer,parameter :: isz=20 real :: vals(isz) real :: rndx(isz) integer :: i write(*,*) initializing array with ,isz, random numbers call random_seed() CALL RANDOM_NUMBER(vals) vals=vals*450000.0 ! make sure some duplicates vals(3)=vals(6) vals(4)=vals(15)Results:call code(vals,isz,rndx) ! code data ! check order write(*,*) write(*,(2(5x,g0.10,1x)))Values,Code,(vals(i),nint(rndx(i)),i=1,isz)
end program demo_code
> initializing array with 20 random numbers > > Output from the code subroutine > Number of distinct code values = 18 > > Value Coded Value > 3137.9548340 1. > 39334.0585938 2. > 58048.1054688 3. > 60169.2890625 4. > 61479.1015625 5. > 92335.1250000 6. > 101141.3671875 7. > 107306.5859375 8. > 135199.7343750 9. > 185223.0625000 10. > 214747.2656250 11. > 251820.6718750 12. > 267047.5000000 13. > 277210.9062500 14. > 296296.5625000 15. > 382931.3437500 16. > 414374.2187500 17. > 427620.9375000 18. > > Values Code > 277210.9062 14 > 60169.28906 4 > 101141.3672 7 > 382931.3438 16 > 61479.10156 5 > 101141.3672 7 > 296296.5625 15 > 214747.2656 11 > 3137.954834 1 > 267047.5000 13 > 107306.5859 8 > 427620.9375 18 > 414374.2188 17 > 251820.6719 12 > 382931.3438 16 > 58048.10547 3 > 39334.05859 2 > 135199.7344 9 > 185223.0625 10 > 92335.12500 6
The original DATAPAC library was written by James Filliben of the Statistical Engineering Division, National Institute of Standards and Technology.
John Urban, 2022.05.31
CC0-1.0
Nemo Release 3.1 | code (3) | February 23, 2025 |