netcdf-c/libdap2/dapodom.c

162 lines
3.9 KiB
C
Raw Normal View History

2011-04-18 02:56:10 +08:00
/*********************************************************************
2018-12-07 05:21:03 +08:00
* Copyright 2018, UCAR/Unidata
2011-04-18 02:56:10 +08:00
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
#include "dapincludes.h"
2011-04-18 02:56:10 +08:00
#include "dapodom.h"
/**********************************************/
/* Define methods for a dimension dapodometer*/
2019-09-18 10:27:43 +08:00
/* Build an odometer covering slices startslice up to, but not including, stopslice */
2011-04-18 02:56:10 +08:00
Dapodometer*
2013-04-24 04:18:16 +08:00
dapodom_fromsegment(DCEsegment* segment, size_t startindex, size_t stopindex)
2011-04-18 02:56:10 +08:00
{
int i;
Dapodometer* odom;
2013-04-24 04:18:16 +08:00
assert(stopindex > startindex);
assert((stopindex - startindex) <= NC_MAX_VAR_DIMS);
odom = (Dapodometer*)calloc(1,sizeof(Dapodometer));
2011-04-18 02:56:10 +08:00
MEMCHECK(odom,NULL);
2013-04-24 04:18:16 +08:00
odom->rank = (stopindex - startindex);
2011-04-18 02:56:10 +08:00
for(i=0;i<odom->rank;i++) {
2013-04-24 04:18:16 +08:00
odom->start[i] = segment->slices[i+startindex].first;
odom->stride[i] = segment->slices[i+startindex].stride;
odom->stop[i] = (segment->slices[i+startindex].last + 1);
2013-02-26 12:31:06 +08:00
/* should the above line be instead?
odom->stop[i] = odom->start[i] + (odom->count[i]*odom->stride[i]);
*/
2013-04-24 04:18:16 +08:00
#if 0
odom->count[i] = segment->slices[i+startindex].count;
#endif
odom->declsize[i] = segment->slices[i+startindex].declsize;
odom->index[i] = odom->start[i];
2011-04-18 02:56:10 +08:00
}
return odom;
}
Dapodometer*
dapodom_new(size_t rank,
const size_t* start, const size_t* count,
const ptrdiff_t* stride, const size_t* size)
2011-04-18 02:56:10 +08:00
{
int i;
Dapodometer* odom = (Dapodometer*)calloc(1,sizeof(Dapodometer));
MEMCHECK(odom,NULL);
odom->rank = rank;
assert(odom->rank <= NC_MAX_VAR_DIMS);
for(i=0;i<odom->rank;i++) {
2013-04-24 04:18:16 +08:00
size_t istart,icount,istop,ideclsize;
ptrdiff_t istride;
istart = (start != NULL ? start[i] : 0);
icount = (count != NULL ? count[i] : (size != NULL ? size[i] : 1));
istride = (size_t)(stride != NULL ? stride[i] : 1);
istop = istart + icount*istride;
ideclsize = (size != NULL ? size[i]: (istop - istart));
odom->start[i] = istart;
odom->stop[i] = istop;
odom->stride[i] = istride;
odom->declsize[i] = ideclsize;
odom->index[i] = odom->start[i];
2011-04-18 02:56:10 +08:00
}
return odom;
}
void
dapodom_free(Dapodometer* odom)
2011-04-18 02:56:10 +08:00
{
if(odom) free(odom);
}
#if 0
2011-04-18 02:56:10 +08:00
char*
dapodom_print(Dapodometer* odom)
2011-04-18 02:56:10 +08:00
{
int i;
static char line[1024];
char tmp[64];
line[0] = '\0';
if(odom->rank == 0) {
strlcat(line,"[]",sizeof(line));
2011-04-18 02:56:10 +08:00
} else for(i=0;i<odom->rank;i++) {
snprintf(tmp,sizeof(tmp),"[%lu/%lu:%lu:%lu]",
(size_t)odom->index[i],
(size_t)odom->start[i],
(size_t)odom->stride[i],
(size_t)odom->length[i]);
strlcat(line,tmp,sizeof(line));
2011-04-18 02:56:10 +08:00
}
return line;
}
#endif
2011-04-18 02:56:10 +08:00
int
dapodom_more(Dapodometer* odom)
2011-04-18 02:56:10 +08:00
{
return (odom->index[0] < odom->stop[0]);
2011-04-18 02:56:10 +08:00
}
/* Convert current dapodometer settings to a single integer count*/
off_t
dapodom_count(Dapodometer* odom)
2011-04-18 02:56:10 +08:00
{
int i;
off_t offset = 0;
2011-04-18 02:56:10 +08:00
for(i=0;i<odom->rank;i++) {
offset *= odom->declsize[i];
2011-04-18 02:56:10 +08:00
offset += odom->index[i];
}
return offset;
}
int
dapodom_next(Dapodometer* odom)
2011-04-18 02:56:10 +08:00
{
int i; /* do not make unsigned */
if(odom->rank == 0) return 0;
for(i=odom->rank-1;i>=0;i--) {
odom->index[i] += odom->stride[i];
if(odom->index[i] < odom->stop[i]) break;
2011-04-18 02:56:10 +08:00
if(i == 0) return 0; /* leave the 0th entry if it overflows*/
odom->index[i] = odom->start[i]; /* reset this position*/
2011-04-18 02:56:10 +08:00
}
return 1;
}
/**************************************************/
size_t
dapodom_varmcount(Dapodometer* odom, const ptrdiff_t* steps, const size_t* declsizes)
2011-04-18 02:56:10 +08:00
{
int i;
size_t offset = 0;
for(i=0;i<odom->rank;i++) {
size_t tmp;
tmp = odom->index[i];
tmp = tmp - odom->start[i];
tmp = tmp / odom->stride[i];
2011-04-18 02:56:10 +08:00
tmp = tmp * steps[i];
offset += tmp;
}
return offset;
}
/*
Given a dapodometer, compute the total
number of elements in its space.
*/
2011-04-18 02:56:10 +08:00
#if 0
off_t
dapodom_space(Dapodometer* odom)
2011-04-18 02:56:10 +08:00
{
size_t i;
off_t count = 1;
2011-04-18 02:56:10 +08:00
for(i=0;i<odom->rank;i++) {
count *= odom->size[i];
2011-04-18 02:56:10 +08:00
}
return count;
2011-04-18 02:56:10 +08:00
}
#endif