Commit 545f50f0 authored by David Partyka's avatar David Partyka
Browse files

ENH: First pass at upgrading vtknetcdf to 4.1.1

parent a7ddae2d
......@@ -2,6 +2,9 @@ PROJECT(VTKNETCDF)
INCLUDE_REGULAR_EXPRESSION(".*")
SET(VERSION "4.1.1")
SET(PACKAGE "netcdf")
SET(netcdf_SRCS
attr.c
dim.c
......@@ -12,6 +15,7 @@ SET(netcdf_SRCS
ncx.c
putget.c
string.c
utf8proc.c
v1hpg.c
v2i.c
var.c
......@@ -117,6 +121,7 @@ FOREACH(file
"string.h"
"stddef.h"
"stdint.h"
"inttypes.h"
)
CHECK_INCLUDE_FILE_CONCAT("${file}")
ENDFOREACH(file)
......@@ -237,9 +242,9 @@ ENDIF(NOT HAVE_SIZEOF_SSIZE_T)
IF(NOT HAVE_SIZEOF_PTRDIFF_T)
SET(ptrdiff_t int)
ENDIF(NOT HAVE_SIZEOF_PTRDIFF_T)
IF(NOT HAVE_SIZEOF_UCHAR)
SET(uchar "unsigned char")
ENDIF(NOT HAVE_SIZEOF_UCHAR)
#IF(NOT HAVE_SIZEOF_UCHAR)
# SET(uchar "unsigned char")
#ENDIF(NOT HAVE_SIZEOF_UCHAR)
# use the same name for the variable as in VTK, so the result is reused
TEST_BIG_ENDIAN(CMAKE_WORDS_BIGENDIAN)
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,19 +8,18 @@ dnl
* Copyright 1996, University Corporation for Atmospheric Research
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*/
/* Id */
/* $Id: attr.m4,v 2.33 2010/04/11 04:15:37 dmh Exp $ */
#include "nc.h"
#include "rename.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "ncx.h"
#include "fbits.h"
#include "rnd.h"
#include "utf8proc.h"
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
# pragma warning ( disable : 4130 ) /* logical operation on address of string constant */
#endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
/*
* Free attr
......@@ -57,11 +56,9 @@ ncx_len_NC_attrV(nc_type type, size_t nelems)
return ncx_len_float(nelems);
case NC_DOUBLE:
return ncx_len_double(nelems);
case NC_NAT:
break; /* Some compilers complain if enums are missing from a switch */
default:
assert("ncx_len_NC_attr bad type" == 0);
}
/* default */
assert("ncx_len_NC_attr bad type" == 0);
return 0;
}
......@@ -104,19 +101,23 @@ NC_new_attr(name,type,count,value)
*/
static NC_attr *
new_NC_attr(
const char *name,
const char *uname,
nc_type type,
size_t nelems)
{
NC_string *strp;
NC_attr *attrp;
char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
if(name == NULL)
return NULL;
assert(name != NULL && *name != 0);
strp = new_NC_string(strlen(name), name);
free(name);
if(strp == NULL)
return NULL;
attrp = new_x_NC_attr(strp, type, nelems);
if(attrp == NULL)
{
......@@ -177,7 +178,7 @@ void
free_NC_attrarrayV(NC_attrarray *ncap)
{
assert(ncap != NULL);
if(ncap->nalloc == 0)
return;
......@@ -266,7 +267,7 @@ incr_NC_attrarray(NC_attrarray *ncap, NC_attr *newelemp)
(ncap->nalloc + NC_ARRAY_GROWBY) * sizeof(NC_attr *));
if(vp == NULL)
return NC_ENOMEM;
ncap->value = vp;
ncap->nalloc += NC_ARRAY_GROWBY;
}
......@@ -323,14 +324,15 @@ NC_attrarray0( NC *ncp, int varid)
/*
* Step thru NC_ATTRIBUTE array, seeking match on name.
* return match or NULL if Not Found.
* return match or NULL if Not Found or out of memory.
*/
NC_attr **
NC_findattr(const NC_attrarray *ncap, const char *name)
NC_findattr(const NC_attrarray *ncap, const char *uname)
{
NC_attr **attrpp;
size_t attrid;
size_t slen;
char *name;
assert(ncap != NULL);
......@@ -339,6 +341,10 @@ NC_findattr(const NC_attrarray *ncap, const char *name)
attrpp = (NC_attr **) ncap->value;
/* normalized version of uname */
name = (char *)utf8proc_NFC((const unsigned char *)uname);
if(name == NULL)
return NULL; /* TODO: need better way to indicate no memory */
slen = strlen(name);
for(attrid = 0; attrid < ncap->nelems; attrid++, attrpp++)
......@@ -346,9 +352,11 @@ NC_findattr(const NC_attrarray *ncap, const char *name)
if(strlen((*attrpp)->name->cp) == slen &&
strncmp((*attrpp)->name->cp, name, slen) == 0)
{
free(name);
return(attrpp); /* Normal return */
}
}
free(name);
return(NULL);
}
......@@ -356,7 +364,7 @@ NC_findattr(const NC_attrarray *ncap, const char *name)
/*
* Look up by ncid, varid and name, return NULL if not found
*/
static int
static int
NC_lookupattr(int ncid,
int varid,
const char *name, /* attribute name */
......@@ -388,7 +396,7 @@ NC_lookupattr(int ncid,
/* Public */
int
nc_inq_attname(int ncid, int varid, int attnum, char *name)
DISPNAME(inq_attname)(int ncid, int varid, int attnum, char *name)
{
int status;
NC *ncp;
......@@ -414,8 +422,8 @@ nc_inq_attname(int ncid, int varid, int attnum, char *name)
}
int
nc_inq_attid(int ncid, int varid, const char *name, int *attnump)
int
DISPNAME(inq_attid)(int ncid, int varid, const char *name, int *attnump)
{
int status;
NC *ncp;
......@@ -429,7 +437,7 @@ nc_inq_attid(int ncid, int varid, const char *name, int *attnump)
ncap = NC_attrarray0(ncp, varid);
if(ncap == NULL)
return NC_ENOTVAR;
attrpp = NC_findattr(ncap, name);
if(attrpp == NULL)
......@@ -441,7 +449,7 @@ nc_inq_attid(int ncid, int varid, const char *name, int *attnump)
return NC_NOERR;
}
int
int
nc_inq_atttype(int ncid, int varid, const char *name, nc_type *datatypep)
{
int status;
......@@ -457,7 +465,7 @@ nc_inq_atttype(int ncid, int varid, const char *name, nc_type *datatypep)
return NC_NOERR;
}
int
int
nc_inq_attlen(int ncid, int varid, const char *name, size_t *lenp)
{
int status;
......@@ -474,7 +482,7 @@ nc_inq_attlen(int ncid, int varid, const char *name, size_t *lenp)
}
int
nc_inq_att(int ncid,
DISPNAME(inq_att)(int ncid,
int varid,
const char *name, /* input, attribute name */
nc_type *datatypep,
......@@ -497,7 +505,7 @@ nc_inq_att(int ncid,
int
nc_rename_att( int ncid, int varid, const char *name, const char *newname)
DISPNAME(rename_att)( int ncid, int varid, const char *name, const char *unewname)
{
int status;
NC *ncp;
......@@ -505,6 +513,7 @@ nc_rename_att( int ncid, int varid, const char *name, const char *newname)
NC_attr **tmp;
NC_attr *attrp;
NC_string *newStr, *old;
char *newname; /* normalized version */
/* sortof inline clone of NC_lookupattr() */
status = NC_check_id(ncid, &ncp);
......@@ -518,7 +527,7 @@ nc_rename_att( int ncid, int varid, const char *name, const char *newname)
if(ncap == NULL)
return NC_ENOTVAR;
status = NC_check_name(newname);
status = NC_check_name(unewname);
if(status != NC_NOERR)
return status;
......@@ -528,16 +537,20 @@ nc_rename_att( int ncid, int varid, const char *name, const char *newname)
attrp = *tmp;
/* end inline clone NC_lookupattr() */
if(NC_findattr(ncap, newname) != NULL)
if(NC_findattr(ncap, unewname) != NULL)
{
/* name in use */
return NC_ENAMEINUSE;
}
old = attrp->name;
newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
if(newname == NULL)
return NC_EBADNAME;
if(NC_indef(ncp))
{
newStr = new_NC_string(strlen(newname), newname);
free(newname);
if( newStr == NULL)
return NC_ENOMEM;
attrp->name = newStr;
......@@ -546,6 +559,7 @@ nc_rename_att( int ncid, int varid, const char *name, const char *newname)
}
/* else */
status = set_NC_string(old, newname);
free(newname);
if( status != NC_NOERR)
return status;
......@@ -594,18 +608,18 @@ nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int ovari
if(!NC_indef(ncp) )
{
attrp = *attrpp; /* convenience */
if(iattrp->xsz > attrp->xsz)
return NC_ENOTINDEFINE;
/* else, we can reuse existing without redef */
attrp->xsz = iattrp->xsz;
attrp->type = iattrp->type;
attrp->nelems = iattrp->nelems;
(void) memcpy(attrp->xvalue, iattrp->xvalue,
iattrp->xsz);
set_NC_hdirty(ncp);
if(NC_doHsync(ncp))
......@@ -619,7 +633,7 @@ nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int ovari
}
/* else, redefine using existing array slot */
old = *attrpp;
}
}
else
{
if(!NC_indef(ncp))
......@@ -657,7 +671,7 @@ nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int ovari
int
nc_del_att(int ncid, int varid, const char *name)
DISPNAME(del_att)(int ncid, int varid, const char *uname)
{
int status;
NC *ncp;
......@@ -678,18 +692,25 @@ nc_del_att(int ncid, int varid, const char *name)
if(ncap == NULL)
return NC_ENOTVAR;
{
char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
if(name == NULL)
return NC_ENOMEM;
/* sortof inline NC_findattr() */
slen = strlen(name);
attrpp = (NC_attr **) ncap->value;
for(attrid = 0; (size_t) attrid < ncap->nelems; attrid++, attrpp++)
{
{
if( slen == (*attrpp)->name->nchars &&
strncmp(name, (*attrpp)->name->cp, slen) == 0)
{
old = *attrpp;
break;
}
}
free(name);
}
if( (size_t) attrid == ncap->nelems )
return NC_ENOTATT;
......@@ -731,10 +752,9 @@ ncx_pad_putn_I$1(void **xpp, size_t nelems, const $1 *tp, nc_type type)
return ncx_putn_float_$1(xpp, nelems, tp);
case NC_DOUBLE:
return ncx_putn_double_$1(xpp, nelems, tp);
case NC_NAT:
break; /* Some compilers complain if enums are missing from a switch */
default:
assert("ncx_pad_putn_I$1 invalid type" == 0);
}
assert("ncx_pad_putn_I$1 invalid type" == 0);
return NC_EBADTYPE;
}
')dnl
......@@ -759,10 +779,9 @@ ncx_pad_getn_I$1(const void **xpp, size_t nelems, $1 *tp, nc_type type)
return ncx_getn_float_$1(xpp, nelems, tp);
case NC_DOUBLE:
return ncx_getn_double_$1(xpp, nelems, tp);
case NC_NAT:
break; /* Some compilers complain if enums are missing from a switch */
default:
assert("ncx_pad_getn_I$1 invalid type" == 0);
}
assert("ncx_pad_getn_I$1 invalid type" == 0);
return NC_EBADTYPE;
}
')dnl
......@@ -830,11 +849,11 @@ nc_put_att_text(int ncid, int varid, const char *name,
{
const size_t xsz = ncx_len_NC_attrV(NC_CHAR, nelems);
attrp = *attrpp; /* convenience */
if(xsz > attrp->xsz)
return NC_ENOTINDEFINE;
/* else, we can reuse existing without redef */
attrp->xsz = xsz;
attrp->type = NC_CHAR;
attrp->nelems = nelems;
......@@ -846,7 +865,7 @@ nc_put_att_text(int ncid, int varid, const char *name,
if(status != NC_NOERR)
return status;
}
set_NC_hdirty(ncp);
if(NC_doHsync(ncp))
......@@ -860,7 +879,7 @@ nc_put_att_text(int ncid, int varid, const char *name,
}
/* else, redefine using existing array slot */
old = *attrpp;
}
}
else
{
if(!NC_indef(ncp))
......@@ -974,11 +993,11 @@ nc_put_att_$1(int ncid, int varid, const char *name,
{
const size_t xsz = ncx_len_NC_attrV(type, nelems);
attrp = *attrpp; /* convenience */
if(xsz > attrp->xsz)
return NC_ENOTINDEFINE;
/* else, we can reuse existing without redef */
attrp->xsz = xsz;
attrp->type = type;
attrp->nelems = nelems;
......@@ -989,7 +1008,7 @@ nc_put_att_$1(int ncid, int varid, const char *name,
status = ncx_pad_putn_I$1(&xp, nelems,
value, type);
}
set_NC_hdirty(ncp);
if(NC_doHsync(ncp))
......@@ -1007,7 +1026,7 @@ nc_put_att_$1(int ncid, int varid, const char *name,
}
/* else, redefine using existing array slot */
old = *attrpp;
}
}
else
{
if(!NC_indef(ncp))
......
......@@ -2,18 +2,16 @@
* Copyright 1996, University Corporation for Atmospheric Research
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*/
/* Id */
/* $Id: dim.c,v 1.79 2010/04/11 04:15:38 dmh Exp $ */
#include "nc.h"
#include "rename.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "ncx.h"
#include "fbits.h"
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
# pragma warning ( disable : 4127 ) /* conditional expression is constant */
#endif /* MSVC 7.1 */
#include "utf8proc.h"
/*
* Free dim
......@@ -48,15 +46,19 @@ new_x_NC_dim(NC_string *name)
/*
* Formerly
NC_new_dim(const char *name, long size)
NC_new_dim(const char *uname, long size)
*/
static NC_dim *
new_NC_dim(const char *name, size_t size)
new_NC_dim(const char *uname, size_t size)
{
NC_string *strp;
NC_dim *dimp;
char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
if(name == NULL)
return NULL;
strp = new_NC_string(strlen(name), name);
free(name);
if(strp == NULL)
return NULL;
......@@ -103,7 +105,7 @@ find_NC_Udim(const NC_dimarray *ncap, NC_dim **dimpp)
{
/*EMPTY*/
}
if((size_t)dimid >= ncap->nelems)
if(dimid >= ncap->nelems)
return(-1); /* not found */
/* else, normal return */
if(dimpp != NULL)
......@@ -114,40 +116,50 @@ find_NC_Udim(const NC_dimarray *ncap, NC_dim **dimpp)
/*
* Step thru NC_DIMENSION array, seeking match on name.
* Step thru NC_DIMENSION array, seeking match on uname.
* Return dimid or -1 on not found.
* *dimpp is set to the appropriate NC_dim.
* The loop structure is odd. In order to parallelize,
* we moved a clearer 'break' inside the loop body to the loop test.
*/
static int
NC_finddim(const NC_dimarray *ncap, const char *name, NC_dim **dimpp)
NC_finddim(const NC_dimarray *ncap, const char *uname, NC_dim **dimpp)
{
assert(ncap != NULL);
if(ncap->nelems == 0)
return -1;
{
size_t slen = strlen(name);
int dimid = 0;
NC_dim **loc = (NC_dim **) ncap->value;
for(; (size_t) dimid < ncap->nelems
&& (strlen((*loc)->name->cp) != slen
|| strncmp((*loc)->name->cp, name, slen) != 0);
dimid++, loc++)
{
/*EMPTY*/
}
if((size_t)dimid >= ncap->nelems)
return(-1); /* not found */
/* else, normal return */
if(dimpp != NULL)
*dimpp = *loc;
return(dimid);
}
int dimid;
size_t slen;
NC_dim ** loc;
char *name;
assert(ncap != NULL);
if(ncap->nelems == 0)
return -1;
{
dimid = 0;
loc = (NC_dim **) ncap->value;
/* normalized version of uname */
name = (char *)utf8proc_NFC((const unsigned char *)uname);
if(name == NULL)
return NC_ENOMEM;
slen = strlen(name);
for(; (size_t) dimid < ncap->nelems
&& (strlen((*loc)->name->cp) != slen
|| strncmp((*loc)->name->cp, name, slen) != 0);
dimid++, loc++)
{
/*EMPTY*/
}
free(name);
if(dimid >= ncap->nelems)
return(-1); /* not found */
/* else, normal return */
if(dimpp != NULL)
*dimpp = *loc;
return(dimid);
}
}
......@@ -190,7 +202,7 @@ void
free_NC_dimarrayV(NC_dimarray *ncap)
{
assert(ncap != NULL);
if(ncap->nalloc == 0)
return;
......@@ -307,14 +319,14 @@ elem_NC_dimarray(const NC_dimarray *ncap, size_t elem)
/* Public */
int
nc_def_dim(int ncid, const char *name, size_t size, int *dimidp)
DISPNAME(def_dim)(int ncid, const char *name, size_t size, int *dimidp)
{
int status;
NC *ncp;
int dimid;
NC_dim *dimp;
status = NC_check_id(ncid, &ncp);
status = NC_check_id(ncid, &ncp);
if(status != NC_NOERR)
return status;
......@@ -351,7 +363,7 @@ nc_def_dim(int ncid, const char *name, size_t size, int *dimidp)
dimid = NC_finddim(&ncp->dims, name, &dimp);
if(dimid != -1)
return NC_ENAMEINUSE;
dimp = new_NC_dim(name, size);
if(dimp == NULL)
return NC_ENOMEM;
......@@ -369,13 +381,13 @@ nc_def_dim(int ncid, const char *name, size_t size, int *dimidp)
int
nc_inq_dimid(int ncid, const char *name, int *dimid_ptr)
DISPNAME(inq_dimid)(int ncid, const char *name, int *dimid_ptr)
{
int status;
NC *ncp;
int dimid;
status = NC_check_id(ncid, &ncp);
status = NC_check_id(ncid, &ncp);
if(status != NC_NOERR)
return status;
......@@ -396,7 +408,7 @@ nc_inq_dim(int ncid, int dimid, char *name, size_t *sizep)
NC *ncp;
NC_dim *dimp;
status = NC_check_id(ncid, &ncp);
status = NC_check_id(ncid, &ncp);
if(status != NC_NOERR)
return status;
......@@ -406,7 +418,7 @@ nc_inq_dim(int ncid, int dimid, char *name, size_t *sizep)
if(name != NULL)
{
(void)strncpy(name, dimp->name->cp,
(void)strncpy(name, dimp->name->cp,
dimp->name->nchars);
name[dimp->name->nchars] = 0;
}
......@@ -415,20 +427,20 @@ nc_inq_dim(int ncid, int dimid, char *name, size_t *sizep)
if(dimp->size == NC_UNLIMITED)
*sizep = NC_get_numrecs(ncp);
else
*sizep = dimp->size;
*sizep = dimp->size;
}
return NC_NOERR;
}
int
int
nc_inq_dimname(int ncid, int dimid, char *name)
{
int status;
NC *ncp;
NC_dim *dimp;
status = NC_check_id(ncid, &ncp);
status = NC_check_id(ncid, &ncp);
if(status != NC_NOERR)
return status;
......@@ -438,7 +450,7 @@ nc_inq_dimname(int ncid, int dimid, char *name)
if(name != NULL)
{
(void)strncpy(name, dimp->name->cp,
(void)strncpy(name, dimp->name->cp,
dimp->name->nchars);
name[dimp->name->nchars] = 0;
}
......@@ -447,14 +459,14 @@ nc_inq_dimname(int ncid, int dimid, char *name)
}