https://github.com/cran/fields
Raw File
Tip revision: 6c8b30169bba182a68765ee3cb9b4e2ef7d38332 authored by Doug Nychka on 16 November 2011, 00:00:00 UTC
version 6.6.3
Tip revision: 6c8b301
Wtransform.R
# fields, Tools for spatial data
# Copyright 2004-2011, Institute for Mathematics Applied Geosciences
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
"Wtransform" <- function(x, inv = FALSE, transpose = FALSE, 
    cut.min = 8) {
    # coerce to one column matrix if x is not already a matrix
    if (!is.matrix(x)) {
        x <- matrix(x, ncol = 1)
    }
    # tranpose operation requires similar recursion to the inverse
    if (transpose) 
        inv <- !inv
    nn <- n <- dim(x)[1]
    #
    # check that n is the product of a dyadic and an integer less or equal
    #to than cut.min
    #
    if (dyadic.check(n, cut.min) == FALSE) {
        stop("error in column dimension ")
    }
    if (!inv) {
        while (nn > cut.min) {
            if (!transpose) {
                x[1:nn, ] <- WQS(x[1:nn, ])
            }
            else {
                x[1:nn, ] <- WQSi.T(x[1:nn, ])
            }
            nn <- nn/2
        }
    }
    if (inv) {
        NN <- n
        while (NN > cut.min) {
            NN <- NN/2
        }
        nn <- NN * 2
        while (nn <= n) {
            if (!transpose) {
                x[1:nn, ] <- WQSi(x[1:nn, ])
            }
            else {
                x[1:nn, ] <- WQS.T(x[1:nn, ])
            }
            nn <- nn * 2
        }
    }
    return(x)
}
back to top