I want to just convert from float32 to 16b with scale factor of 10. I am supposed to get files with size of 507kb(720*360*2) not 131kb. Any help?
dir1 <- list.files("C:\\New folder (13)", "*.img", full.names = TRUE)
results <- list()
for (.files in seq_along(dir1)){
file2 <- readBin(dir1[.files], double(), size = 4, n = 360*720, signed = TRUE)
results[[length(results) + 1L]] <- file2[file2 != -9999]*10
fileName <- sprintf("C:\\SWdown_200001_%d.bin", .files)
writeBin(as.integer(results[[.files]]), fileName, size = 2)
}
Each element in ‘file2’ which equals -9999 will not be present in results[[.files]]. Looks like approximately 3/4 of the elements in ‘file2’ equal this value. Perhaps you want to assign a different value to these elements, rather than dropping them when assigning to results[[…]].
To do what you want, try this: