[R] convert from float32 to 16B

jim holtman jholtman at gmail.com
Tue May 29 02:38:05 CEST 2012


Most likely you have a bug in your program.  Have you looked at the
results of your calculations before writing them out?  Since you have
provided no data, we can not reproduce what you are doing to show
where the error might be, or the correct way of doing it.  In almost
all cases, if you think you are getting weird resutls, it is because
your calculations are producing the weird results.  It is time to
learn "debugging 101"; there are plenty of tools that will let you
examine your results and determine where your errors are.

On Mon, May 28, 2012 at 4:10 PM, sam84 <samiyemny at yahoo.co.uk> wrote:
> I want to just convert from float32 to 16b with scale factor of 10. I wonder
> why  some files were converted correctly while some were not converted
> correctly. By means, the results of some files are weird. the original files
> are all  ok!.
>
>
> 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)
>     file2[file2 != -9999] <- file2[file2 != -9999]*10
>    results[[length(results) + 1L]] <- file2
>    fileName <- sprintf("C:\\SWdown_200001_%d.bin", .files)
>    writeBin(as.integer(results[[.files]]), fileName, size = 2)}
>
> --
> View this message in context: http://r.789695.n4.nabble.com/convert-from-float32-to-16B-tp4631638.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list