Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • c9cdf94
  • /
  • R
  • /
  • setup.prop.1D.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:d60abda5d7d8ff5916d92d16c04b8fa01bd151f7
directory badge
swh:1:dir:ea81c1bd99d45a5de927f2a33db1e3540a6d20a0

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
setup.prop.1D.R

##==============================================================================
## Attaches a property to a 1D grid
##==============================================================================

setup.prop.1D <- function(func = NULL, value = NULL, xy = NULL,
  interpolate = "spline", grid, ...) {

## check input
  gn <- names(grid)
  if (! "x.up"   %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains x.up")
  if (! "x.down" %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains x.down")
  if (! "x.mid"  %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains x.mid")
  if (! "x.int"  %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains x.int")
  if (! "dx"     %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains dx")
  if (! "dx.aux" %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains dx.aux")
  if (! "N"      %in% gn)
    stop("error in setup.prop.1D: grid should be a list that contains N")


  if (is.null(xy) && is.null(value) && is.null(func))
    stop("error in setup.prop.1D: function, value and xy cannot be NULL together")

## profile specification via function
  if (! is.null(func)) {   
  	y.int <- func(grid$x.int,...)
    ## KS ##
  	if (length(y.int)==0)
      stop (" error in setup.prop.1D: 'func' should return a vector ")
      
	  y.mid <- func(grid$x.mid,...)
  }

  if (! is.null(value)) { # profile specification via value
	  y.int <- rep(value,times=length(grid$x.int))
	  y.mid <- rep(value,times=length(grid$x.mid))
  }

## profile speficication via data series input
  if (! is.null(xy)) { 
    if (! is.matrix(xy))
      stop("error in setup.prop.1D: xy should be a 2-columned matrix or NULL")
	  if (!(interpolate %in% c("linear","spline")))
      stop("error in setup.prop.1D: 'interpolate' not properly specified, should be 'linear' or 'spline'")
		
    if (interpolate=="linear") {
      # check the range of input data-series (inr))
      # this range should span the range of grid$x.int (outr)
      outr <- range(grid$x.int) # output range
      inr  <- range(xy[,1])     # input range
	    # extend the xy matrix if necessary
	    if (outr[1]<inr[1]) {
        xy <- rbind(c(outr[1],xy[which.min(xy[,1]),2]),xy)
      }
      if (outr[2]>inr[2]) {
        xy <- rbind(xy,c(outr[2],xy[which.max(xy[,1]),2]))
      }
      # linear interpolation
    	y.int <- approx(x=xy[,1],y=xy[,2],xout = grid$x.int)$y
      y.mid <- approx(x=xy[,1],y=xy[,2],xout = grid$x.mid)$y
    } else {

	    # spline interpolation
	    f <- splinefun(xy[,1],xy[,2])
      y.int <- f(grid$x.int)
      y.mid <- f(grid$x.mid)
    }
  }

  Res <- list(mid  = y.mid,
              int  = y.int)
  class(Res) <- "prop.1D"
  return(Res)
}


##==============================================================================
## S3 method: Plotting of a one-dimensional grid property
##==============================================================================


plot.prop.1D <- function(x, grid, xyswap =FALSE, ...) {
  if (xyswap)
    plot(x$int, grid$x.int, ylim = rev(range(grid$x.int)),
      xlab="prop",ylab="x",...)
  else
    plot(grid$x.int,x$int, ylab="prop",xlab="x",...)
}

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API