Skip to content

Commit db854cb

Browse files
committed
merged 731 again
2 parents ce46217 + d1296e5 commit db854cb

File tree

18 files changed

+393
-117
lines changed

18 files changed

+393
-117
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,11 @@ IF(SIZEOF_UINT)
13031303
SET(HAVE_UINT TRUE)
13041304
ENDIF(SIZEOF_UINT)
13051305

1306+
CHECK_TYPE_SIZE("schar" SIZEOF_SCHAR)
1307+
IF(SIZEOF_SCHAR)
1308+
SET(HAVE_SCHAR TRUE)
1309+
ENDIF(SIZEOF_SCHAR)
1310+
13061311
CHECK_TYPE_SIZE("long" SIZEOF_LONG)
13071312
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
13081313
IF(SIZEOF_LONG_LONG)

include/nc3dispatch.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,17 @@ NC3_def_var(int ncid, const char *name,
158158

159159
extern int
160160
NC3_inq_var(int ncid, int varid, char *name,
161-
nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp);
161+
nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp,
162+
int *no_fill, void *fill_valuep);
162163

163164
extern int
164165
NC3_inq_varid(int ncid, const char *name, int *varidp);
165166

166167
extern int
167168
NC3_rename_var(int ncid, int varid, const char *name);
168169

170+
extern int
171+
NC3_def_var_fill(int,int,int,const void*);
169172

170173
extern int
171174
NC3_put_vara(int ncid, int varid,

include/nc3internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ typedef struct NC_var {
186186
nc_type type; /* the discriminant */
187187
size_t len; /* the total length originally allocated */
188188
off_t begin;
189+
int no_fill; /* whether fill mode is ON or OFF */
189190
} NC_var;
190191

191192
typedef struct NC_vararray {

include/ncdispatch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifndef _DISPATCH_H
1010
#define _DISPATCH_H
1111

12+
#if HAVE_CONFIG_H
1213
#include "config.h"
14+
#endif
1315
#include <stdlib.h>
1416
#include <stdio.h>
1517
#include <string.h>
@@ -250,6 +252,7 @@ int (*inq_var_all)(int ncid, int varid, char *name, nc_type *xtypep,
250252
);
251253

252254
int (*var_par_access)(int, int, int);
255+
int (*def_var_fill)(int, int, int, const void*);
253256

254257
/* Note the following may still be invoked by netcdf client code
255258
even when the file is a classic file; they will just return an error or
@@ -289,7 +292,6 @@ int (*def_opaque)(int, size_t, const char*, nc_type*);
289292
int (*def_var_deflate)(int, int, int, int, int);
290293
int (*def_var_fletcher32)(int, int, int);
291294
int (*def_var_chunking)(int, int, int, const size_t*);
292-
int (*def_var_fill)(int, int, int, const void*);
293295
int (*def_var_endian)(int, int, int);
294296
int (*def_var_filter)(int, int, unsigned int, size_t, const unsigned int*);
295297
int (*set_var_chunk_cache)(int, int, size_t, size_t, float);

libdap2/ncd2dispatch.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ NCDEFAULT_put_varm,
137137
NCD2_inq_var_all,
138138

139139
NCD2_var_par_access,
140+
NCD2_def_var_fill,
140141

141142
#ifdef USE_NETCDF4
142143
NCD2_show_metadata,
@@ -172,7 +173,6 @@ NCD2_def_opaque,
172173
NCD2_def_var_deflate,
173174
NCD2_def_var_fletcher32,
174175
NCD2_def_var_chunking,
175-
NCD2_def_var_fill,
176176
NCD2_def_var_endian,
177177
NCD2_def_var_filter,
178178
NCD2_set_var_chunk_cache,
@@ -2434,6 +2434,15 @@ NCD2_var_par_access(int ncid, int p2, int p3)
24342434
return THROW(NC_ENOPAR);
24352435
}
24362436

2437+
int
2438+
NCD2_def_var_fill(int ncid, int p2, int p3, const void* p4)
2439+
{
2440+
NC* drno;
2441+
int ret;
2442+
if((ret = NC_check_id(ncid, (NC**)&drno)) != NC_NOERR) return THROW(ret);
2443+
ret = nc_def_var_fill(getnc3id(drno), p2, p3, p4);
2444+
return THROW(ret);
2445+
}
24372446

24382447
#ifdef USE_NETCDF4
24392448

@@ -2763,16 +2772,6 @@ NCD2_def_var_chunking(int ncid, int p2, int p3, const size_t* p4)
27632772
return THROW(ret);
27642773
}
27652774

2766-
int
2767-
NCD2_def_var_fill(int ncid, int p2, int p3, const void* p4)
2768-
{
2769-
NC* drno;
2770-
int ret;
2771-
if((ret = NC_check_id(ncid, (NC**)&drno)) != NC_NOERR) return THROW(ret);
2772-
ret = nc_def_var_fill(getnc3id(drno), p2, p3, p4);
2773-
return THROW(ret);
2774-
}
2775-
27762775
int
27772776
NCD2_def_var_endian(int ncid, int p2, int p3)
27782777
{

libdap2/ncd2dispatch.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ NCD2_rename_var(int ncid, int varid, const char *name);
158158
extern int
159159
NCD2_var_par_access(int, int, int);
160160

161+
extern int
162+
NCD2_def_var_fill(int, int, int, const void *);
163+
161164
/* netCDF4 API only */
162165
#ifdef USE_NETCDF4
163166
extern int
@@ -241,9 +244,6 @@ NCD2_var_par_access(int, int, int);
241244
extern int
242245
NCD2_def_var_chunking(int, int, int, const size_t *);
243246

244-
extern int
245-
NCD2_def_var_fill(int, int, int, const void *);
246-
247247
extern int
248248
NCD2_def_var_endian(int, int, int);
249249

libdap4/ncd4dispatch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ NCDEFAULT_put_varm,
853853
NCD4_inq_var_all,
854854

855855
NCD4_var_par_access,
856+
NCD4_def_var_fill,
856857

857858
#ifdef USE_NETCDF4
858859
NCD4_show_metadata,
@@ -888,7 +889,6 @@ NCD4_def_opaque,
888889
NCD4_def_var_deflate,
889890
NCD4_def_var_fletcher32,
890891
NCD4_def_var_chunking,
891-
NCD4_def_var_fill,
892892
NCD4_def_var_endian,
893893
NCD4_def_var_filter,
894894
NCD4_set_var_chunk_cache,

libdispatch/dvar.c

Lines changed: 81 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -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

libsrc/attr.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,18 @@ NC3_put_att(
836836
if(nelems != 0 && value == NULL)
837837
return NC_EINVAL; /* Null arg */
838838

839+
if (varid != NC_GLOBAL && !strcmp(name, _FillValue)) {
840+
/* Fill value must be of the same data type */
841+
if (type != ncp->vars.value[varid]->type) return NC_EBADTYPE;
842+
843+
/* Fill value must have exactly one value */
844+
if (nelems != 1) return NC_EINVAL;
845+
846+
/* Only allow for variables defined in initial define mode */
847+
if (ncp->old != NULL && varid < ncp->old->vars.nelems)
848+
return NC_ELATEFILL; /* try put attribute for an old variable */
849+
}
850+
839851
attrpp = NC_findattr(ncap, name);
840852

841853
/* 4 cases: exists X indef */

libsrc/nc3dispatch.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ static int NC3_def_opaque(int,size_t,const char*,nc_type*);
7373
static int NC3_def_var_deflate(int,int,int,int,int);
7474
static int NC3_def_var_fletcher32(int,int,int);
7575
static int NC3_def_var_chunking(int,int,int,const size_t*);
76-
static int NC3_def_var_fill(int,int,int,const void*);
7776
static int NC3_def_var_endian(int,int,int);
7877
static int NC3_def_var_filter(int, int, unsigned int, size_t, const unsigned int*);
7978

@@ -129,6 +128,7 @@ NCDEFAULT_put_varm,
129128
NC3_inq_var_all,
130129

131130
NC3_var_par_access,
131+
NC3_def_var_fill,
132132

133133
#ifdef USE_NETCDF4
134134
NC3_show_metadata,
@@ -164,7 +164,6 @@ NC3_def_opaque,
164164
NC3_def_var_deflate,
165165
NC3_def_var_fletcher32,
166166
NC3_def_var_chunking,
167-
NC3_def_var_fill,
168167
NC3_def_var_endian,
169168
NC3_def_var_filter,
170169
NC3_set_var_chunk_cache,
@@ -198,13 +197,12 @@ NC3_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
198197
unsigned int* idp, size_t* nparamsp, unsigned int* params
199198
)
200199
{
201-
int stat = NC3_inq_var(ncid,varid,name,xtypep,ndimsp,dimidsp,nattsp);
200+
int stat = NC3_inq_var(ncid,varid,name,xtypep,ndimsp,dimidsp,nattsp,no_fill,fill_valuep);
202201
if(stat) return stat;
203202
if(shufflep) *shufflep = 0;
204203
if(deflatep) *deflatep = 0;
205204
if(fletcher32p) *fletcher32p = 0;
206205
if(contiguousp) *contiguousp = NC_CONTIGUOUS;
207-
if(no_fill) *no_fill = 1;
208206
if(endiannessp) return NC_ENOTNC4;
209207
if(idp) return NC_ENOTNC4;
210208
if(nparamsp) return NC_ENOTNC4;
@@ -506,12 +504,6 @@ NC3_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksiz
506504
return NC_ENOTNC4;
507505
}
508506

509-
static int
510-
NC3_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
511-
{
512-
return NC_ENOTNC4;
513-
}
514-
515507
static int
516508
NC3_def_var_endian(int ncid, int varid, int endianness)
517509
{

0 commit comments

Comments
 (0)