@@ -538,6 +538,87 @@ NC_getshape(int ncid, int varid, int ndims, size_t* shape)
538538 return status ;
539539}
540540
541+ /*! Set the fill value for a variable.
542+
543+ \ingroup variables
544+
545+ \param ncid NetCDF ID, from a previous call to nc_open or
546+ nc_create.
547+
548+ \param varid Variable ID.
549+
550+ \param no_fill Set to NC_NOFILL to turn off fill mode for this
551+ variable. Set to NC_FILL (the default) to turn on fill mode for the
552+ variable.
553+
554+ \param fill_value the fill value to be used for this variable. Must be
555+ the same type as the variable. This must point to enough free memory
556+ to hold one element of the data type of the variable. (For example, an
557+ NC_INT will require 4 bytes for it's fill value, which is also an
558+ NC_INT.)
559+
560+ * @returns ::NC_NOERR No error.
561+ * @returns ::NC_EBADID Bad ID.
562+ * @returns ::NC_ENOTINDEFINE Not in define mode. This is returned for
563+ netCDF classic, 64-bit offset, or 64-bit data files, or for netCDF-4 files,
564+ when they were created with NC_STRICT_NC3 flag. See \ref nc_create.
565+ * @returns ::NC_EPERM Attempt to create object in read-only file.
566+
567+ \section nc_def_var_fill_example Example
568+
569+ In this example from libsrc4/tst_vars.c, a variable is defined, and
570+ the fill mode turned off. Then nc_inq_fill() is used to check that the
571+ setting is correct. Then some data are written to the variable. Since
572+ the data that are written do not cover the full extent of the
573+ variable, the missing values will just be random. If fill value mode
574+ was turned on, the missing values would get the fill value.
575+
576+ \code
577+ #define DIM7_LEN 2
578+ #define DIM7_NAME "dim_7_from_Indiana"
579+ #define VAR7_NAME "var_7_from_Idaho"
580+ #define NDIMS 1
581+ int dimids[NDIMS];
582+ size_t index[NDIMS];
583+ int varid;
584+ int no_fill;
585+ unsigned short ushort_data = 42, ushort_data_in, fill_value_in;
586+
587+ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
588+ if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR;
589+ if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids,
590+ &varid)) ERR;
591+ if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR;
592+
593+ if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
594+ if (!no_fill) ERR;
595+
596+ index[0] = 1;
597+ if (nc_put_var1_ushort(ncid, varid, index, &ushort_data)) ERR;
598+
599+ index[0] = 0;
600+ if (nc_get_var1_ushort(ncid, varid, index, &ushort_data_in)) ERR;
601+
602+ if (nc_close(ncid)) ERR;
603+ \endcode
604+ */
605+ int
606+ nc_def_var_fill (int ncid , int varid , int no_fill , const void * fill_value )
607+ {
608+ NC * ncp ;
609+ int stat = NC_check_id (ncid ,& ncp );
610+ if (stat != NC_NOERR ) return stat ;
611+
612+ /* Dennis Heimbigner: (Using NC_GLOBAL is ilegal, as this API) has no
613+ * provision for specifying the type of the fillvalue, it must of necessity
614+ * be using the type of the variable to interpret the bytes of the
615+ * fill_value argument.
616+ */
617+ if (varid == NC_GLOBAL ) return NC_EGLOBAL ;
618+
619+ return ncp -> dispatch -> def_var_fill (ncid ,varid ,no_fill ,fill_value );
620+ }
621+
541622#ifdef USE_NETCDF4
542623/** \ingroup variables
543624
@@ -899,80 +980,6 @@ nc_def_var_chunking(int ncid, int varid, int storage,
899980 chunksizesp );
900981}
901982
902- /*! Set the fill value for a netCDF4/HDF5 variable.
903-
904- \ingroup variables
905-
906- \param ncid NetCDF ID, from a previous call to nc_open or
907- nc_create.
908-
909- \param varid Variable ID.
910-
911- \param no_fill Set to NC_NOFILL to turn off fill mode for this
912- variable. Set to NC_FILL (the default) to turn on fill mode for the
913- variable.
914-
915- \param fill_value the fill value to be used for this variable. Must be
916- the same type as the variable. This must point to enough free memory
917- to hold one element of the data type of the variable. (For example, an
918- NC_INT will require 4 bytes for it's fill value, which is also an
919- NC_INT.)
920-
921- * @returns ::NC_NOERR No error.
922- * @returns ::NC_EBADID Bad ID.
923- * @returns ::NC_ENOTNC4 Not a netCDF-4 file.
924- * @returns ::NC_ENOTINDEFINE Not in define mode. This is returned for
925- netCDF classic or 64-bit offset files, or for netCDF-4 files, when
926- they wwere created with NC_STRICT_NC3 flag. See \ref nc_create.
927- * @returns ::NC_EPERM Attempt to create object in read-only file.
928-
929- \section nc_def_var_fill_example Example
930-
931- In this example from libsrc4/tst_vars.c, a variable is defined, and
932- the fill mode turned off. Then nc_inq_fill() is used to check that the
933- setting is correct. Then some data are written to the variable. Since
934- the data that are written do not cover the full extent of the
935- variable, the missing values will just be random. If fill value mode
936- was turned on, the missing values would get the fill value.
937-
938- \code
939- #define DIM7_LEN 2
940- #define DIM7_NAME "dim_7_from_Indiana"
941- #define VAR7_NAME "var_7_from_Idaho"
942- #define NDIMS 1
943- int dimids[NDIMS];
944- size_t index[NDIMS];
945- int varid;
946- int no_fill;
947- unsigned short ushort_data = 42, ushort_data_in, fill_value_in;
948-
949- if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
950- if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR;
951- if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids,
952- &varid)) ERR;
953- if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR;
954-
955- if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
956- if (!no_fill) ERR;
957-
958- index[0] = 1;
959- if (nc_put_var1_ushort(ncid, varid, index, &ushort_data)) ERR;
960-
961- index[0] = 0;
962- if (nc_get_var1_ushort(ncid, varid, index, &ushort_data_in)) ERR;
963-
964- if (nc_close(ncid)) ERR;
965- \endcode
966- */
967- int
968- nc_def_var_fill (int ncid , int varid , int no_fill , const void * fill_value )
969- {
970- NC * ncp ;
971- int stat = NC_check_id (ncid ,& ncp );
972- if (stat != NC_NOERR ) return stat ;
973- return ncp -> dispatch -> def_var_fill (ncid ,varid ,no_fill ,fill_value );
974- }
975-
976983/**
977984@ingroup variables
978985
0 commit comments