@@ -67,9 +67,9 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"),
6767 endian <- match.arg(endian )
6868 checkmate :: assertFlag(rm.totim.0 )
6969
70- ans <- try(.ReadBinary(path , data.type , endian , nbytes = 4 ), silent = TRUE )
70+ ans <- try(.ReadBinary(path , data.type , endian , nbytes = 4L ), silent = TRUE )
7171 if (inherits(ans , " try-error" ))
72- ans <- .ReadBinary(path , data.type , endian , nbytes = 8 )
72+ ans <- .ReadBinary(path , data.type , endian , nbytes = 8L )
7373 if (rm.totim.0 )
7474 ans <- ans [vapply(ans , function (i ) i $ totim , 0 ) != 0 ]
7575 ans
@@ -81,7 +81,7 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"),
8181 checkmate :: assertFileExists(path )
8282 checkmate :: assertString(data.type )
8383 checkmate :: assertString(endian )
84- stopifnot(nbytes %in% c(4 , 8 ))
84+ stopifnot(nbytes %in% c(4L , 8L ))
8585
8686 con <- file(path , open = " rb" , encoding = " bytes" )
8787 on.exit(close(con , type = " rb" ))
@@ -136,33 +136,33 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"),
136136 " wells" )
137137 lst <- list ()
138138 repeat {
139- kstp <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
139+ kstp <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
140140 if (length(kstp ) == 0 ) break
141- kper <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
141+ kper <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
142142
143143 if (data.type == " array" ) {
144- pertim <- readBin(con , " numeric" , n = 1 , size = nbytes , endian = endian )
145- totim <- readBin(con , " numeric" , n = 1 , size = nbytes , endian = endian )
146- desc <- readBin(readBin(con , " raw" , n = 16 , size = 1 , endian = endian ),
147- " character" , n = 1 , endian = endian )
144+ pertim <- readBin(con , " numeric" , n = 1L , size = nbytes , endian = endian )
145+ totim <- readBin(con , " numeric" , n = 1L , size = nbytes , endian = endian )
146+ desc <- readBin(readBin(con , " raw" , n = 16L , size = 1L , endian = endian ),
147+ " character" , n = 1L , endian = endian )
148148 desc <- .TidyDescription(desc )
149149 if (! desc %in% valid.desc ) break
150- ncol <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
151- nrow <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
152- layer <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
150+ ncol <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
151+ nrow <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
152+ layer <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
153153 v <- readBin(con , " numeric" , n = nrow * ncol , size = nbytes , endian = endian )
154154 d <- matrix (v , nrow = nrow , ncol = ncol , byrow = TRUE )
155155 lst [[length(lst ) + 1 ]] <- list (d = d , kstp = kstp , kper = kper , desc = desc ,
156156 layer = layer , pertim = pertim , totim = totim )
157157
158158 } else if (data.type == " flow" ) {
159- desc <- readBin(readBin(con , " raw" , n = 16 , size = 1 , endian = endian ),
160- " character" , n = 1 , endian = endian )
159+ desc <- readBin(readBin(con , " raw" , n = 16L , size = 1L , endian = endian ),
160+ " character" , n = 1L , endian = endian )
161161 desc <- .TidyDescription(desc )
162162 if (! desc %in% valid.desc ) break
163- ncol <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
164- nrow <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
165- nlay <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
163+ ncol <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
164+ nrow <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
165+ nlay <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
166166
167167 if (nlay > 0 ) {
168168 x <- .Read3dArray(con , nrow , ncol , nlay , nbytes , endian )
@@ -173,73 +173,77 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"),
173173
174174 } else { # compact form is used
175175 nlay <- abs(nlay )
176- itype <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
177- delt <- readBin(con , " numeric" , n = 1 , size = nbytes , endian = endian )
178- pertim <- readBin(con , " numeric" , n = 1 , size = nbytes , endian = endian )
179- totim <- readBin(con , " numeric" , n = 1 , size = nbytes , endian = endian )
176+ itype <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
177+ delt <- readBin(con , " numeric" , n = 1L , size = nbytes , endian = endian )
178+ pertim <- readBin(con , " numeric" , n = 1L , size = nbytes , endian = endian )
179+ totim <- readBin(con , " numeric" , n = 1L , size = nbytes , endian = endian )
180180
181- if (itype == 5 )
182- nval <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
181+ if (itype == 5L )
182+ nval <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
183183 else
184184 nval <- 1L
185185 if (nval > 100 ) stop(" more than one-hundred varaiables for each cell" )
186186 if (nval > 1 ) {
187- ctmp <- readBin(readBin(con , " raw" , n = 16 , size = 1 , endian = endian ),
188- " character" , n = nval - 1 , endian = endian )
187+ ctmp <- readBin(readBin(con , " raw" , n = 16L , size = 1L , endian = endian ),
188+ " character" , n = nval - 1L , endian = endian )
189189 ctmp <- .TidyDescription(ctmp )
190190 } else {
191191 ctmp <- NULL
192192 }
193193
194- if (itype %in% c(0 , 1 )) {
195- nvalues <- ncol * nrow * nlay
194+ if (itype %in% c(0L , 1L )) {
196195 d <- .Read3dArray(con , nrow , ncol , nlay , nbytes , endian )
197196 for (i in seq_along(d )) {
198197 lst [[length(lst ) + 1 ]] <- list (d = d [[i ]], kstp = kstp , kper = kper ,
199198 desc = desc , layer = i , delt = delt ,
200199 pertim = pertim , totim = totim )
201200 }
202201
203- } else if (itype %in% c(2 , 5 )) {
204- nlist <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
202+ } else if (itype %in% c(2L , 5L )) {
203+ nlist <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
205204 if (nlist > (nrow * ncol * nlay ))
206205 stop(" large number of cells for which values will be stored" )
207206 if (nlist > 0 ) {
208- d <- matrix (0 , nrow = nlist , ncol = nval + 4 )
207+ d <- matrix (0 , nrow = nlist , ncol = nval + 4L )
209208 colnames(d ) <- make.names(c(" icell" , " layer" , " row" , " column" , " flow" , ctmp ),
210209 unique = TRUE )
211210 for (i in seq_len(nlist )) {
212- d [i , 1 ] <- readBin(con , " integer" , n = 1 , size = 4 , endian = endian )
211+ d [i , 1 ] <- readBin(con , " integer" , n = 1L , size = 4L , endian = endian )
213212 d [i , seq_len(nval ) + 4 ] <- readBin(con , " numeric" , n = nval ,
214213 size = nbytes , endian = endian )
215214 }
216215 nrc <- nrow * ncol
217- d [, " layer" ] <- as.integer((d [, " icell" ] - 1 ) / nrc + 1 )
218- d [, " row" ] <- as.integer(((d [, " icell" ] - (d [, " layer" ] - 1 ) * nrc ) - 1 ) / ncol + 1 )
219- d [, " column" ] <- as.integer(d [, " icell" ] - (d [, " layer" ] - 1 ) * nrc - (d [, " row" ] - 1 ) * ncol )
216+ d [, " layer" ] <- as.integer((d [, " icell" ] - 1L ) / nrc + 1L )
217+ d [, " row" ] <- as.integer(((d [, " icell" ] - (d [, " layer" ] - 1L ) * nrc )
218+ - 1L ) / ncol + 1L )
219+ d [, " column" ] <- as.integer(d [, " icell" ] - (d [, " layer" ] - 1L )
220+ * nrc - (d [, " row" ] - 1L ) * ncol )
220221 lst [[length(lst ) + 1 ]] <- list (d = d , kstp = kstp , kper = kper , desc = desc ,
221222 delt = delt , pertim = pertim , totim = totim )
222223 }
223224
224- } else if (itype == 3 ) {
225- layers <- readBin(con , " integer" , n = nrow * ncol , size = 4 , endian = endian )
225+ } else if (itype == 3L ) {
226+ layers <- readBin(con , " integer" , n = nrow * ncol , size = 4L , endian = endian )
226227 values <- readBin(con , " numeric" , n = nrow * ncol , size = nbytes , endian = endian )
227228 for (i in sort(unique(layers ))) {
228229 v <- values [layers == i ]
229230 d <- matrix (v , nrow = nrow , ncol = ncol , byrow = TRUE )
230231 lst [[length(lst ) + 1 ]] <- list (d = d , kstp = kstp , kper = kper , desc = desc ,
231- layer = i , delt = delt , pertim = pertim , totim = totim )
232+ layer = i , delt = delt , pertim = pertim ,
233+ totim = totim )
232234 }
233235
234- } else if (itype == 4 ) {
236+ } else if (itype == 4L ) {
235237 v <- readBin(con , " numeric" , n = nrow * ncol , size = nbytes , endian = endian )
236238 d <- matrix (v , nrow = nrow , ncol = ncol , byrow = TRUE )
237239 lst [[length(lst ) + 1 ]] <- list (d = d , kstp = kstp , kper = kper , desc = desc ,
238- layer = 1 , delt = delt , pertim = pertim , totim = totim )
240+ layer = 1L , delt = delt , pertim = pertim ,
241+ totim = totim )
239242 d [, ] <- 0
240243 for (i in seq_len(nlay )[- 1 ]) {
241244 lst [[length(lst ) + 1 ]] <- list (d = d , kstp = kstp , kper = kper , desc = desc ,
242- layer = i , delt = delt , pertim = pertim , totim = totim )
245+ layer = i , delt = delt , pertim = pertim ,
246+ totim = totim )
243247 }
244248
245249 } else {
0 commit comments