converting float to byte in netcdf file

狂风中的少年 提交于 2019-12-11 06:17:18

问题


I have a large netcdf file with a standard float field which consists of only 0.0 or 1.0. I would like to convert it to a byte type from the command line to save some space and also make it easier to read in the array to a byte type in fortran.

I tried to use ncap

ncap -s 'fire=byte(fire)' CAMS_2003-2017_frp_mask2_africa_zip.nc test.nc

but it just seems to zero all the fields. I was using zip_6 netcdf4 compression on the source file, I'm not sure if that complicates matters?

UPDATE: I found that ncap2 works with byte

ncap2 -s 'fire=byte(fire)' CAMS_2003-2017_frp_mask2_africa_zip.nc test.nc

But I don't understand why the two differ? It may be a memory issue, as both ncap and ncap2 fail with memory allocation when trying to convert to "int" instead of "byte".


回答1:


I found two ways of doing this:

cdo -b I8 copy in.nc out.nc 

or

ncap2 -s 'fire=byte(fire)' in.nc out.nc 


来源:https://stackoverflow.com/questions/45332613/converting-float-to-byte-in-netcdf-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!