Commit 7c2e8a1b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added pmlist.c pmlist.h.

parent 75364fbb
......@@ -104,6 +104,8 @@ libcdo_la_SOURCES = \
pipe.h \
pml.c \
pml.h \
pmlist.c \
pmlist.h \
pragma_omp_atomic_update.h \
printinfo.h \
process.c \
......
......@@ -128,11 +128,12 @@ am_libcdo_la_OBJECTS = libcdo_la-cdo_pthread.lo libcdo_la-cdo_vlist.lo \
libcdo_la-namelist.lo libcdo_la-normal.lo \
libcdo_la-nth_element.lo libcdo_la-par_io.lo \
libcdo_la-percentiles_hist.lo libcdo_la-percentiles.lo \
libcdo_la-pipe.lo libcdo_la-pml.lo libcdo_la-process.lo \
libcdo_la-pstream.lo libcdo_la-pthread_debug.lo \
libcdo_la-readline.lo libcdo_la-realtime.lo \
libcdo_la-remaplib.lo libcdo_la-remapsort.lo \
libcdo_la-remap_scrip_io.lo libcdo_la-remap_search_reg2d.lo \
libcdo_la-pipe.lo libcdo_la-pml.lo libcdo_la-pmlist.lo \
libcdo_la-process.lo libcdo_la-pstream.lo \
libcdo_la-pthread_debug.lo libcdo_la-readline.lo \
libcdo_la-realtime.lo libcdo_la-remaplib.lo \
libcdo_la-remapsort.lo libcdo_la-remap_scrip_io.lo \
libcdo_la-remap_search_reg2d.lo \
libcdo_la-remap_search_latbins.lo \
libcdo_la-remap_store_link.lo \
libcdo_la-remap_store_link_cnsrv.lo libcdo_la-remap_conserv.lo \
......@@ -517,18 +518,18 @@ libcdo_la_SOURCES = cdo_int.h compare.h cdo_pthread.c cdo_vlist.c \
namelist.h normal.c nth_element.c nth_element.h \
operator_help.h par_io.c par_io.h percentiles_hist.c \
percentiles_hist.h percentiles.c percentiles.h pipe.c pipe.h \
pml.c pml.h pragma_omp_atomic_update.h printinfo.h process.c \
process.h pstream.c pstream.h pstream_write.h pstream_int.h \
pthread_debug.c pthread_debug.h readline.c realtime.c remap.h \
remaplib.c remapsort.c remap_scrip_io.c remap_search_reg2d.c \
remap_search_latbins.c remap_store_link.c remap_store_link.h \
remap_store_link_cnsrv.c remap_store_link_cnsrv.h \
remap_conserv.c remap_conserv_scrip.c remap_distwgt.c \
remap_bicubic_scrip.c remap_bilinear_scrip.c stdnametable.c \
stdnametable.h specspace.c specspace.h statistic.c statistic.h \
table.c text.c text.h timebase.h timer.c userlog.c uthash.h \
util.c util.h zaxis.c json/jsmn.h json/jsmn.c \
kdtreelib/kdtree.h kdtreelib/kdtree_cartesian.c \
pml.c pml.h pmlist.c pmlist.h pragma_omp_atomic_update.h \
printinfo.h process.c process.h pstream.c pstream.h \
pstream_write.h pstream_int.h pthread_debug.c pthread_debug.h \
readline.c realtime.c remap.h remaplib.c remapsort.c \
remap_scrip_io.c remap_search_reg2d.c remap_search_latbins.c \
remap_store_link.c remap_store_link.h remap_store_link_cnsrv.c \
remap_store_link_cnsrv.h remap_conserv.c remap_conserv_scrip.c \
remap_distwgt.c remap_bicubic_scrip.c remap_bilinear_scrip.c \
stdnametable.c stdnametable.h specspace.c specspace.h \
statistic.c statistic.h table.c text.c text.h timebase.h \
timer.c userlog.c uthash.h util.c util.h zaxis.c json/jsmn.h \
json/jsmn.c kdtreelib/kdtree.h kdtreelib/kdtree_cartesian.c \
kdtreelib/kdtree_common.c kdtreelib/kdtree_spherical.c \
kdtreelib/qsort.c kdtreelib/pmergesort.c kdtreelib/pqueue.c \
kdtreelib/pqueue.h clipping/clipping.c clipping/clipping.h \
......@@ -1045,6 +1046,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-percentiles_hist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-pipe.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-pml.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-pmlist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-process.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-pstream.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-pthread_debug.Plo@am__quote@
......@@ -1515,6 +1517,13 @@ libcdo_la-pml.lo: pml.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libcdo_la-pml.lo `test -f 'pml.c' || echo '$(srcdir)/'`pml.c
libcdo_la-pmlist.lo: pmlist.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libcdo_la-pmlist.lo -MD -MP -MF $(DEPDIR)/libcdo_la-pmlist.Tpo -c -o libcdo_la-pmlist.lo `test -f 'pmlist.c' || echo '$(srcdir)/'`pmlist.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-pmlist.Tpo $(DEPDIR)/libcdo_la-pmlist.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pmlist.c' object='libcdo_la-pmlist.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libcdo_la-pmlist.lo `test -f 'pmlist.c' || echo '$(srcdir)/'`pmlist.c
libcdo_la-process.lo: process.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libcdo_la-process.lo -MD -MP -MF $(DEPDIR)/libcdo_la-process.Tpo -c -o libcdo_la-process.lo `test -f 'process.c' || echo '$(srcdir)/'`process.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-process.Tpo $(DEPDIR)/libcdo_la-process.Plo
......
......@@ -15,8 +15,8 @@
GNU General Public License for more details.
*/
#ifndef _PMLIST_H
#define _PMLIST_H
#ifndef _PML_H
#define _PML_H
#define PML_INT 1
#define PML_FLT 2
......
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "pmlist.h"
keyValues_t *kvlist_search(list_t *kvl, const char *key)
{
if ( key )
{
listNode_t *node = kvl->head;
while ( node )
{
keyValues_t *kv = *(keyValues_t **)node->data;
if ( kv->key && *(kv->key) == *key && strcmp(kv->key, key) == 0 ) return kv;
node = node->next;
}
}
return NULL;
}
list_t *pml_search_kvl(list_t *pml, const char *key, const char *value)
{
if ( pml && key && value )
{
listNode_t *node = pml->head;
while ( node )
{
if ( node->data )
{
list_t *kvl = *(list_t **)node->data;
keyValues_t *kv = kvlist_search(kvl, key);
if ( kv && kv->nvalues > 0 && *(kv->values[0]) == *value && strcmp(kv->values[0], value) == 0 ) return kvl;
}
node = node->next;
}
}
return NULL;
}
bool kvl_print_iter(void *data)
{
keyValues_t *keyval = *(keyValues_t **)data;
// printf("Found %s list with %d keys: \n", list_name(keyval), list_size(keyval));
printf(" key=%s val0=%s\n", keyval->key, keyval->values[0]);
return true;
}
bool pml_print_iter(void *data)
{
list_t *kvl = *(list_t **)data;
printf("Found %s list with %d keys: \n", list_name(kvl), list_size(kvl));
list_for_each(kvl, kvl_print_iter);
return true;
}
void free_keyval(void *data)
{
keyValues_t *keyval = *(keyValues_t **)data;
if ( keyval->key ) free(keyval->key);
int nvalues = keyval->nvalues;
for ( int i = 0; i < nvalues; ++i )
if ( keyval->values[i] ) free(keyval->values[i]);
free(keyval->values);
free(keyval);
}
void free_kvlist(void *data)
{
list_t *kvl = *(list_t **)data;
int n = list_size(kvl);
list_destroy(kvl);
printf("Successfully freed %d keyvalues...\n", n);
}
void kvlist_append(list_t *kvl, const char *key, const char *values[], int nvalues)
{
keyValues_t *keyval = (keyValues_t *) malloc(sizeof(keyValues_t));
keyval->key = strdup(key);
keyval->nvalues = nvalues;
keyval->values = (char **) malloc(nvalues*sizeof(char*));
for ( int i = 0; i < nvalues; ++i ) keyval->values[i] = strdup(values[i]);
list_append(kvl, &keyval);
}
/*
int main(void)
{
int numLists = 0;
printf("Generating list with lists of keyValues...\n");
list_t *pml = list_new(sizeof(list_t *), free_kvlist, "parameter");
{
const char *k1 = "longname", *k1vals[] = {"surface temperature"};
const char *k2 = "name", *k2vals[] = {"temperature"};
const char *k3 = "values", *k3vals[] = {"273.15", "292.5", "301.4"};
list_t *kvl = list_new(sizeof(keyValues_t *), free_keyval, "p1");
kvlist_append(kvl, k1, k1vals, sizeof(k1vals)/sizeof(k1vals[0]));
kvlist_append(kvl, k2, k2vals, sizeof(k2vals)/sizeof(k2vals[0]));
kvlist_append(kvl, k3, k3vals, sizeof(k3vals)/sizeof(k3vals[0]));
list_append(pml, &kvl);
numLists++;
}
{
const char *k1 = "longname", *k1vals[] = {"surface pressure"};
const char *k2 = "name", *k2vals[] = {"pressure"};
const char *k3 = "values", *k3vals[] = {"1000", "850", "500"};
const char *k4 = "units", *k4vals[] = {"hPa"};
list_t *kvl = list_new(sizeof(keyValues_t *), free_keyval, "p1");
kvlist_append(kvl, k1, k1vals, sizeof(k1vals)/sizeof(k1vals[0]));
kvlist_append(kvl, k2, k2vals, sizeof(k2vals)/sizeof(k2vals[0]));
kvlist_append(kvl, k3, k3vals, sizeof(k3vals)/sizeof(k3vals[0]));
kvlist_append(kvl, k4, k4vals, sizeof(k4vals)/sizeof(k4vals[0]));
list_append(pml, &kvl);
numLists++;
}
{
const char *k1 = "longname", *k1vals[] = {"Air Temperature"};
const char *k2 = "name", *k2vals[] = {"ta"};
const char *k3 = "valid_max",*k3vals[] = {"336"};
const char *k4 = "units", *k4vals[] = {"K"};
list_t *kvl = list_new(sizeof(keyValues_t *), free_keyval, "p1");
kvlist_append(kvl, k1, k1vals, sizeof(k1vals)/sizeof(k1vals[0]));
kvlist_append(kvl, k2, k2vals, sizeof(k2vals)/sizeof(k2vals[0]));
kvlist_append(kvl, k3, k3vals, sizeof(k3vals)/sizeof(k3vals[0]));
kvlist_append(kvl, k4, k4vals, sizeof(k4vals)/sizeof(k4vals[0]));
list_append(pml, &kvl);
numLists++;
}
printf("pmlist=%s n=%d:\n", list_name(pml), list_size(pml));
list_for_each(pml, pml_print_iter);
list_t *kvl = pml_search_kvl(pml, "name", "pressure");
printf("kvlist of name=pressure:\n");
if ( kvl ) list_for_each(kvl, kvl_print_iter);
printf("\n");
int n = list_size(kvl);
for ( int i = 0; i < n; ++i )
{
keyValues_t *kv = (keyValues_t *) list_entry(kvl, i);
if ( kv ) printf(" %d: key=%s val0=%s\n", i+1, kv->key, kv->values[0]);
}
printf("\n");
int i = 0;
for ( listNode_t *node = kvl->head; node; node=node->next )
{
keyValues_t *kv = *(keyValues_t **)node->data;
if ( kv ) printf(" %d: key=%s val0=%s\n", i+1, kv->key, kv->values[0]);
++i;
}
list_destroy(pml);
printf("Successfully freed %d kvlists...\n", numLists);
return 0;
}
*/
#ifndef _PMLIST_H
#define _PMLIST_H
#include "list.h"
typedef struct {
int nvalues;
char *key;
char **values;
} keyValues_t;
keyValues_t *kvlist_search(list_t *kvl, const char *key);
list_t *pml_search_kvl(list_t *pml, const char *key, const char *value);
bool kvl_print_iter(void *data);
bool pml_print_iter(void *data);
void free_keyval(void *data);
void free_kvlist(void *data);
void kvlist_append(list_t *kvl, const char *key, const char *values[], int nvalues);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment