1\name{Programming}
2
3\alias{readStart}
4\alias{readStop}
5\alias{readStart,Raster-method}
6\alias{readStart,RasterStack-method}
7\alias{readStop,Raster-method}
8\alias{readStop,RasterStack-method}
9
10\alias{canProcessInMemory}
11\alias{pbCreate}
12\alias{pbStep}
13\alias{pbClose}
14\alias{getCluster}
15\alias{returnCluster}
16
17\title{Helper functions for programming}
18
19\description{
20These are low level functions that can be used by programmers to develop new functions. If in doubt, it is almost certain that you do not need these functions as these are already embedded in all other functions in the raster package.
21
22\code{canProcessInMemory} is typically used within functions. In the raster package this function is used to determine if the amount of memory needed for the function is available. If there is not enough memory available, the function returns \code{FALSE}, and the function that called it will write the results to a temporary file.
23
24readStart opens file connection(s) for reading, readStop removes it.
25
26pbCreate creates a progress bar, pbStep sets the progress, and pbClose closes it.
27}
28
29\usage{
30canProcessInMemory(x, n=4, verbose=FALSE)
31pbCreate(nsteps, progress, style=3, label='Progress', ...)
32pbStep(pb, step=NULL, label='')
33pbClose(pb, timer)
34readStart(x, ...)
35readStop(x)
36getCluster()
37returnCluster()
38}
39
40\arguments{
41  \item{x}{RasterLayer or RasterBrick object (for connections) or RasterStack object (canProcessInMemory)}
42  \item{n}{integer. The number of copies of the Raster* object cell values that a function needs to be able to have in memory}
43  \item{verbose}{logical. If \code{TRUE} the amount of memory needed and available is printed}
44  \item{nsteps}{integer. Number of steps the progress bar will make from start to end (e.g. nrow(raster)) }
45  \item{progress}{character. 'text', 'window', or ''}
46  \item{style}{style for text progress bar. See \code{\link[utils]{txtProgressBar}} }
47  \item{label}{character. Label for the window type progress bar}
48  \item{...}{additional arguments (None implemented, except for 'silent=TRUE' for readStart for files read with gdal, and other arguments passed to gdal.open)}
49  \item{pb}{ progress bar object created with pbCreate }
50  \item{step}{which step is this ( 1 <= step <= nsteps ). If step is \code{NULL}, a single step is taken }
51  \item{timer}{logical. If \code{TRUE}, time to completion will be printed. If missing, the value will be taken from the rasterOptions}
52}
53
54\value{
55canProcessInMemory: logical
56
57closeConnection: RasterLayer or RasterBrick object
58
59getCluster: snow cluster object
60}
61
62
63\examples{
64r <- raster(nrow=100, ncol=100)
65canProcessInMemory(r, 4)
66r <- raster(nrow=50000, ncol=50000)
67canProcessInMemory(r, 2, verbose=TRUE)
68rasterOptions(maxmem=Inf, memfrac=.8)
69rasterOptions(default=TRUE)
70}
71
72\keyword{ spatial }
73
74