Writing from floating point to byte values :
/* Create the icv */ icv=miicv_create(); (void) miicv_setint(icv, MI_ICV_TYPE, NC_FLOAT); (void) miicv_setint(icv, MI_ICV_DO_NORM, TRUE); /* Create the file */ cdf=nccreate(filename, NC_CLOBBER); /* Define the dimensions */ dim[0]=ncdimdef(cdf, MIyspace, ysize); dim[1]=ncdimdef(cdf, MIxspace, xsize); /* Define the variables */ img=micreate_std_variable(cdf, MIimage, NC_BYTE, 2, dim); (void) miattputstr(cdf, img, MIsigntype, MI_UNSIGNED); vrange[0]=0; vrange[1]=200; (void) ncattput(cdf, img, MIvalid_range, NC_DOUBLE, 2, vrange); max=micreate_std_variable(cdf, MIimagemax, NC_DOUBLE, 0, NULL); min=micreate_std_variable(cdf, MIimagemin, NC_DOUBLE, 0, NULL); /* End definition mode */ ncendef(cdf); /* Attach image variable */ (void) miicv_attach(icv, cdf, img); /* Write the image max and min */ ncvarput1(cdf, max, NULL, &image_maximum); ncvarput1(cdf, min, NULL, &image_minimum); /* Write the image */ start[0]=start[1]=0; count[0]=ysize; count[1]=xsize; miicv_put(icv, start, count, vals); /* Close the file and free the icv */ (void) ncclose(cdf); (void) miicv_free(icv);
If we were writing a floating point image, the only difference (apart
from changing NC_BYTE
to NC_FLOAT
) would be that we
would rewrite MIvalid_range
at the end of the file with the
full range of floating point values.