Commit 8507e4b8 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added listbuf.c and listbuf.h.

parent 5c681904
......@@ -179,16 +179,16 @@ void apply_cmor_table(const char *filename, int nvars, int vlistID2, var_t *vars
int nhentry = (int) sizeof(hentry)/sizeof(hentry[0]);
char varname[CDI_MAX_NAME];
list_t *pml = cdo_parse_cmor_file(filename);
if ( pml == NULL ) return;
list_t *pmlist = cdo_parse_cmor_file(filename);
if ( pmlist == NULL ) return;
// search for global missing value
bool lmissval = false;
double missval;
list_t *kvl = pml_get_kvl_ventry(pml, nhentry, hentry);
if ( kvl )
list_t *kvlist = pmlist_get_kvlist_ventry(pmlist, nhentry, hentry);
if ( kvlist )
{
for ( listNode_t *kvnode = kvl->head; kvnode; kvnode = kvnode->next )
for ( listNode_t *kvnode = kvlist->head; kvnode; kvnode = kvnode->next )
{
keyValues_t *kv = *(keyValues_t **)kvnode->data;
const char *key = kv->key;
......@@ -228,12 +228,12 @@ void apply_cmor_table(const char *filename, int nvars, int vlistID2, var_t *vars
}
}
list_t *kvl = pml_search_kvl_ventry(pml, "name", varname, nventry, ventry);
if ( kvl )
list_t *kvlist = pmlist_search_kvlist_ventry(pmlist, "name", varname, nventry, ventry);
if ( kvlist )
{
bool lvalid_min = false, lvalid_max = false;
for ( listNode_t *kvnode = kvl->head; kvnode; kvnode = kvnode->next )
for ( listNode_t *kvnode = kvlist->head; kvnode; kvnode = kvnode->next )
{
keyValues_t *kv = *(keyValues_t **)kvnode->data;
const char *key = kv->key;
......@@ -315,7 +315,7 @@ void apply_cmor_table(const char *filename, int nvars, int vlistID2, var_t *vars
}
}
list_destroy(pml);
list_destroy(pmlist);
}
......
......@@ -84,6 +84,8 @@ libcdo_la_SOURCES = \
listarray.h \
list.c \
list.h \
listbuf.c \
listbuf.h \
merge_sort2.c \
merge_sort2.h \
modules.c \
......
......@@ -124,8 +124,9 @@ am_libcdo_la_OBJECTS = libcdo_la-cdo_pthread.lo libcdo_la-cdo_vlist.lo \
libcdo_la-hetaeta.lo libcdo_la-institution.lo \
libcdo_la-interpol.lo libcdo_la-job.lo libcdo_la-juldate.lo \
libcdo_la-grid_search.lo libcdo_la-listarray.lo \
libcdo_la-list.lo libcdo_la-merge_sort2.lo \
libcdo_la-modules.lo libcdo_la-namelist.lo libcdo_la-normal.lo \
libcdo_la-list.lo libcdo_la-listbuf.lo \
libcdo_la-merge_sort2.lo libcdo_la-modules.lo \
libcdo_la-namelist.lo libcdo_la-normal.lo \
libcdo_la-nth_element.lo libcdo_la-par_io.lo \
libcdo_la-parse_cmor_table.lo libcdo_la-parse_namelist.lo \
libcdo_la-parse_literal.lo libcdo_la-percentiles_hist.lo \
......@@ -516,23 +517,24 @@ libcdo_la_SOURCES = cdo_int.h compare.h cdo_pthread.c cdo_vlist.c \
gridreference.c griddes.c griddes.h griddes_h5.c griddes_nc.c \
hetaeta.c hetaeta.h institution.c interpol.c interpol.h job.c \
juldate.c grid_search.c grid_search.h listarray.c listarray.h \
list.c list.h merge_sort2.c merge_sort2.h modules.c modules.h \
namelist.c namelist.h normal.c nth_element.c nth_element.h \
operator_help.h par_io.c par_io.h parse_cmor_table.c \
parse_namelist.c parse_literal.c percentiles_hist.c \
percentiles_hist.h percentiles.c percentiles.h pipe.c pipe.h \
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 \
list.c list.h listbuf.c listbuf.h merge_sort2.c merge_sort2.h \
modules.c modules.h namelist.c namelist.h normal.c \
nth_element.c nth_element.h operator_help.h par_io.c par_io.h \
parse_cmor_table.c parse_namelist.c parse_literal.c \
percentiles_hist.c percentiles_hist.h percentiles.c \
percentiles.h pipe.c pipe.h 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 \
......@@ -1040,6 +1042,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-juldate.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-list.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-listarray.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-listbuf.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-merge_sort2.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-modules.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-namelist.Plo@am__quote@
......@@ -1454,6 +1457,13 @@ libcdo_la-list.lo: list.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-list.lo `test -f 'list.c' || echo '$(srcdir)/'`list.c
libcdo_la-listbuf.lo: listbuf.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-listbuf.lo -MD -MP -MF $(DEPDIR)/libcdo_la-listbuf.Tpo -c -o libcdo_la-listbuf.lo `test -f 'listbuf.c' || echo '$(srcdir)/'`listbuf.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-listbuf.Tpo $(DEPDIR)/libcdo_la-listbuf.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='listbuf.c' object='libcdo_la-listbuf.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-listbuf.lo `test -f 'listbuf.c' || echo '$(srcdir)/'`listbuf.c
libcdo_la-merge_sort2.lo: merge_sort2.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-merge_sort2.lo -MD -MP -MF $(DEPDIR)/libcdo_la-merge_sort2.Tpo -c -o libcdo_la-merge_sort2.lo `test -f 'merge_sort2.c' || echo '$(srcdir)/'`merge_sort2.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-merge_sort2.Tpo $(DEPDIR)/libcdo_la-merge_sort2.Plo
......
......@@ -22,19 +22,18 @@
#include "cdo.h"
#include "cdo_int.h"
#include "pmlist.h"
void *Nmltest(void *argument)
{
cdoInitialize(argument);
// list_t *pml = cdo_parse_namelist(stdin);
list_t *pml = cdo_parse_namelist("test.tab");
if ( pml == NULL ) return;
list_t *pmlist = namelist_to_pmlist(stdin, "STDIN");
list_for_each(pmlist, pmlist_print_iter);
list_destroy(pmlist);
list_for_each(pml, pml_print_iter);
cdoFinish();
return 0;
......
......@@ -70,7 +70,7 @@ void cdo_check_data(int vlistID2, int varID2, var_t *var, long gridsize, double
static
void apply_partab(pt_mode_t ptmode, const char *filename, int nvars, int vlistID2, var_t *vars)
void apply_parameterlist(pt_mode_t ptmode, list_t *pmlist, int nvars, int vlistID2, var_t *vars)
{
const char *hentry[] = {"Header"};
const char *ventry[] = {"variable_entry", "parameter"};
......@@ -80,16 +80,13 @@ void apply_partab(pt_mode_t ptmode, const char *filename, int nvars, int vlistID
char varname[CDI_MAX_NAME];
int codenum;
list_t *pml = cdo_parse_namelist(filename);
if ( pml == NULL ) return;
// search for global missing value
bool lmissval = false;
double missval;
list_t *kvl = pml_get_kvl_ventry(pml, nhentry, hentry);
if ( kvl )
list_t *kvlist = pmlist_get_kvlist_ventry(pmlist, nhentry, hentry);
if ( kvlist )
{
keyValues_t *kv = kvlist_search(kvl, "missing_value");
keyValues_t *kv = kvlist_search(kvlist, "missing_value");
if ( kv && kv->nvalues > 0 )
{
lmissval = true;
......@@ -114,24 +111,24 @@ void apply_partab(pt_mode_t ptmode, const char *filename, int nvars, int vlistID
}
}
list_t *kvl = NULL;
list_t *kvlist = NULL;
if ( ptmode == CODE_NUMBER )
{
codenum = vlistInqVarCode(vlistID2, varID);
snprintf(valstr, sizeof(valstr), "%d", codenum);
kvl = pml_search_kvl_ventry(pml, "code", valstr, nventry, ventry);
if ( kvl )
kvlist = pmlist_search_kvlist_ventry(pmlist, "code", valstr, nventry, ventry);
if ( kvlist )
{
int tableID = vlistInqVarTable(vlistID2, varID);
int tabnum = tableInqNum(tableID);
int levtype = zaxisInqLtype(vlistInqVarZaxis(vlistID2, varID));
int table = tabnum;
int ltype = levtype;
keyValues_t *kv = kvlist_search(kvl, "table");
keyValues_t *kv = kvlist_search(kvlist, "table");
if ( kv && kv->nvalues == 1 ) table = parameter2int(kv->values[0]);
kv = kvlist_search(kvl, "ltype");
kv = kvlist_search(kvlist, "ltype");
if ( kv && kv->nvalues == 1 ) ltype = parameter2int(kv->values[0]);
if ( !(tabnum == table && levtype == ltype) ) kvl = NULL;
if ( !(tabnum == table && levtype == ltype) ) kvlist = NULL;
}
}
else if ( ptmode == PARAMETER_ID )
......@@ -140,28 +137,28 @@ void apply_partab(pt_mode_t ptmode, const char *filename, int nvars, int vlistID
int param = vlistInqVarParam(vlistID2, varID);
paramToStringLong(param, paramstr, sizeof(paramstr));
snprintf(valstr, sizeof(valstr), "%s", paramstr);
kvl = pml_search_kvl_ventry(pml, "param", valstr, nventry, ventry);
if ( kvl )
kvlist = pmlist_search_kvlist_ventry(pmlist, "param", valstr, nventry, ventry);
if ( kvlist )
{
int levtype = zaxisInqLtype(vlistInqVarZaxis(vlistID2, varID));
int ltype = levtype;
keyValues_t *kv = kvlist_search(kvl, "ltype");
keyValues_t *kv = kvlist_search(kvlist, "ltype");
if ( kv && kv->nvalues == 1 ) ltype = parameter2int(kv->values[0]);
if ( !(levtype == ltype) ) kvl = NULL;
if ( !(levtype == ltype) ) kvlist = NULL;
}
}
else if ( ptmode == VARIABLE_NAME )
{
kvl = pml_search_kvl_ventry(pml, "name", varname, nventry, ventry);
kvlist = pmlist_search_kvlist_ventry(pmlist, "name", varname, nventry, ventry);
}
if ( kvl )
if ( kvlist )
{
int pnum, ptab, pdum;
cdiDecodeParam(vlistInqVarParam(vlistID2, varID), &pnum, &ptab, &pdum);
bool lvalid_min = false, lvalid_max = false;
for ( listNode_t *kvnode = kvl->head; kvnode; kvnode = kvnode->next )
for ( listNode_t *kvnode = kvlist->head; kvnode; kvnode = kvnode->next )
{
keyValues_t *kv = *(keyValues_t **)kvnode->data;
const char *key = kv->key;
......@@ -288,11 +285,9 @@ void apply_partab(pt_mode_t ptmode, const char *filename, int nvars, int vlistID
}
else
{
cdoPrint("Variable %s not found!", varname);
cdoPrint("Variable %s not found in parameter table!", varname);
}
}
list_destroy(pml);
}
......@@ -411,7 +406,14 @@ void *Setpartab(void *argument)
else
{
const char *filename = operatorArgv()[0];
apply_partab(ptmode, filename, nvars, vlistID2, vars);
FILE *fp = fopen(filename, "r");
if ( fp == NULL ) cdoAbort("Open failed on: %s\n", filename);
list_t *pmlist = namelist_to_pmlist(fp, "filename");
apply_parameterlist(ptmode, pmlist, nvars, vlistID2, vars);
list_destroy(pmlist);
for ( int varID = 0; varID < nvars; ++varID )
if ( vars[varID].remove )
......
......@@ -32,7 +32,8 @@
#include <ctype.h>
#include <stdarg.h>
#include "list.h"
#include "pmlist.h"
#include "listbuf.h"
#include "compare.h"
#include "timebase.h"
#include "field.h"
......@@ -171,8 +172,8 @@ double cdoZaxisInqLevel(int zaxisID, int levelID);
int cdoZaxisInqLevels(int zaxisID, double *levels);
list_t *cdo_parse_cmor_file(const char *filename);
list_t *cdo_parse_namelist(const char *filename);
list_t *namelistbuf_to_pmlist(listbuf_t *listbuf);
list_t *namelist_to_pmlist(FILE *fp, const char *name);
int literal_get_datatype(const char *literal);
int literal_to_int(const char *literal);
......
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "listbuf.h"
listbuf_t *listbuf_new(void)
{
listbuf_t *listbuf = (listbuf_t *) malloc(sizeof(listbuf_t));
if ( listbuf )
{
listbuf->size = 0;
listbuf->buffer = NULL;
listbuf->name = NULL;
}
return listbuf;
}
int listbuf_read(listbuf_t *listbuf, FILE *fp, const char *name)
{
int filedes = fileno(fp);
struct stat buf;
size_t filesize = 0;
if ( fstat(filedes, &buf) == 0 ) filesize = (size_t) buf.st_size;
if ( filesize > MAX_LISTBUF_SIZE )
{
fprintf(stderr, "%s: max buffer size of %d exceeded (%s)!\n", __func__, (int)MAX_LISTBUF_SIZE, name);
return -1;
}
else if ( filesize == 0 )
{
fprintf(stderr, "%s: empty stream: %s\n", __func__, name);
return -1;
}
char *buffer = (char*) malloc(filesize);
size_t nitems = fread(buffer, 1, filesize, fp);
if ( nitems != filesize )
{
free(buffer);
fprintf(stderr, "%s: read failed on %s!\n", __func__, name);
return -1;
}
listbuf->size = filesize;
listbuf->buffer = buffer;
if ( name ) listbuf->name = strdup(name);
return 0;
}
void listbuf_destroy(listbuf_t *listbuf)
{
if ( listbuf )
{
if ( listbuf->buffer ) free(listbuf->buffer);
if ( listbuf->name ) free(listbuf->name);
listbuf->size = 0;
listbuf->buffer = NULL;
listbuf->name = NULL;
free(listbuf);
}
}
#ifndef _LISTBUF_H
#define _LISTBUF_H
#include <stdio.h>
#define MAX_LISTBUF_SIZE (128*1024*1024)
typedef struct
{
size_t size;
char *buffer;
char *name;
} listbuf_t;
listbuf_t *listbuf_new();
void listbuf_destroy(listbuf_t *listbuf);
int listbuf_read(listbuf_t *listbuf, FILE *fp, const char *name);
#endif
......@@ -39,12 +39,11 @@ static
namelisttok_t *namelist_alloc_token(namelist_parser *parser)
{
const unsigned int TOK_MEM_INCR = 64;
namelisttok_t *tok;
if ( parser->toknext >= parser->num_tokens )
{
parser->num_tokens += TOK_MEM_INCR;
parser->tokens = (namelisttok_t *) realloc(parser->tokens, sizeof(*tok) * parser->num_tokens);
parser->tokens = (namelisttok_t *) realloc(parser->tokens, sizeof(namelisttok_t) * parser->num_tokens);
if ( parser->tokens == NULL )
{
fprintf(stderr, "%s: Failed to allocated more memory!", __func__);
......@@ -52,7 +51,7 @@ namelisttok_t *namelist_alloc_token(namelist_parser *parser)
}
}
tok = &parser->tokens[parser->toknext++];
namelisttok_t *tok = &parser->tokens[parser->toknext++];
tok->start = tok->end = -1;
return tok;
}
......@@ -112,7 +111,6 @@ int namelist_parse_word(namelist_parser *parser, const char *buf, size_t len)
static
int namelist_parse_string(namelist_parser *parser, const char *buf, size_t len)
{
namelisttok_t *token;
int start = parser->pos;
parser->pos++;
......@@ -125,7 +123,7 @@ int namelist_parse_string(namelist_parser *parser, const char *buf, size_t len)
/* Quote: end of string */
if ( c == '\"' )
{
token = namelist_alloc_token(parser);
namelisttok_t *token = namelist_alloc_token(parser);
namelist_fill_token(token, NAMELIST_STRING, start+1, parser->pos);
return 0;
}
......
#include <errno.h>
#include "cdo_int.h"
#include "pmlist.h"
#include "namelist.h"
static
void kvlist_append_namelist(list_t *kvl, const char *key, const char *buffer, namelisttok_t *t, int nvalues)
void kvlist_append_namelist(list_t *kvlist, const char *key, const char *buffer, namelisttok_t *t, int nvalues)
{
keyValues_t *keyval = (keyValues_t *) malloc(sizeof(keyValues_t));
keyval->key = strdup(key);
......@@ -23,7 +22,7 @@ void kvlist_append_namelist(list_t *kvl, const char *key, const char *buffer, na
value[len] = 0;
keyval->values[i] = value;
}
list_append(kvl, &keyval);
list_append(kvlist, &keyval);
}
}
......@@ -37,17 +36,15 @@ int get_number_of_values(int ntok, namelisttok_t *tokens)
namelisttok_t *t = &tokens[it];
if ( t->type != NAMELIST_WORD && t->type != NAMELIST_STRING ) break;
}
if ( it == ntok ) it = 0;
return it;
}
static
int namelist_to_pml(list_t *pml, namelist_parser *parser, char *buf)
int namelist_to_pml(list_t *pmlist, namelist_parser *parser, char *buf)
{
char name[4096];
list_t *kvl = NULL;
list_t *kvlist = NULL;
namelisttok_t *t;
namelisttok_t *tokens = parser->tokens;
unsigned int ntok = parser->toknext;
......@@ -67,17 +64,17 @@ int namelist_to_pml(list_t *pml, namelist_parser *parser, char *buf)
snprintf(name, sizeof(name), "%.*s", t->end - t->start, buf+t->start);
name[sizeof(name)-1] = 0;
}
kvl = kvlist_new(name);
list_append(pml, &kvl);
kvlist = kvlist_new(name);
list_append(pmlist, &kvlist);
}
else if ( t->type == NAMELIST_KEY )
{
// printf(" key >%.*s<\n", t->end - t->start, buf+t->start);
snprintf(name, sizeof(name), "%.*s", t->end - t->start, buf+t->start);
name[sizeof(name)-1] = 0;
if ( kvl == NULL ) printf("kvl not defined\n");
int nvalues = get_number_of_values(ntok-it, &tokens[it+1]);
kvlist_append_namelist(kvl, name, buf, &tokens[it+1], nvalues);
if ( kvlist == NULL ) printf("kvlist not defined\n");
int nvalues = get_number_of_values(ntok-it-1, &tokens[it+1]);
kvlist_append_namelist(kvlist, name, buf, &tokens[it+1], nvalues);
it += nvalues;
}
else
......@@ -91,32 +88,48 @@ int namelist_to_pml(list_t *pml, namelist_parser *parser, char *buf)
}
void parse_namelist_buffer_to_pml(list_t *pml, const char *filename, size_t buffersize, char *buffer)
list_t *namelistbuf_to_pmlist(listbuf_t *listbuf)
{
const char *name = listbuf->name;
namelist_parser *p = namelist_new();
int status = namelist_parse(p, buffer, buffersize);
int status = namelist_parse(p, listbuf->buffer, listbuf->size);
if ( status )
switch (status)
{
case NAMELIST_ERROR_INVAL: fprintf(stderr, "Namelist error: Invalid character in %s (line=%d character='%c')!\n", filename, p->lineno, buffer[p->pos]); break;
case NAMELIST_ERROR_PART: fprintf(stderr, "Namelist error: End of string not found in %s (line=%d)!\n", filename, p->lineno); break;
case NAMELIST_ERROR_INKEY: fprintf(stderr, "Namelist error: Invalid key word in %s (line=%d)!\n", filename, p->lineno); break;
case NAMELIST_ERROR_INTYP: fprintf(stderr, "Namelist error: Invalid key word type in %s (line=%d)!\n", filename, p->lineno); break;
case NAMELIST_ERROR_INOBJ: fprintf(stderr, "Namelist error: Invalid object in %s (line=%d)!\n", filename, p->lineno); break;
case NAMELIST_ERROR_EMKEY: fprintf(stderr, "Namelsit error: Emtry key name in %s (line=%d)!\n", filename, p->lineno); break;
default: fprintf(stderr, "Namelsit error in %s (line=%d)!\n", filename, p->lineno); break;
case NAMELIST_ERROR_INVAL: fprintf(stderr, "Namelist error: Invalid character in %s (line=%d character='%c')!\n", name, p->lineno, listbuf->buffer[p->pos]); break;
case NAMELIST_ERROR_PART: fprintf(stderr, "Namelist error: End of string not found in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_INKEY: fprintf(stderr, "Namelist error: Invalid key word in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_INTYP: fprintf(stderr, "Namelist error: Invalid key word type in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_INOBJ: fprintf(stderr, "Namelist error: Invalid object in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_EMKEY: fprintf(stderr, "Namelsit error: Emtry key name in %s (line=%d)!\n", name, p->lineno); break;
default: fprintf(stderr, "Namelsit error in %s (line=%d)!\n", name, p->lineno); break;
}
// namelist_dump(p, buffer);
namelist_to_pml(pml, p, buffer);
list_t *pmlist = list_new(sizeof(list_t *), free_kvlist, listbuf->name);
namelist_to_pml(pmlist, p, listbuf->buffer);
namelist_destroy(p);
return pmlist;
}
list_t *namelist_to_pmlist(FILE *fp, const char *name)
{
listbuf_t *listbuf = listbuf_new();
if ( listbuf_read(listbuf, fp, name) ) cdoAbort("Namelist read error!");
list_t *pmlist = namelistbuf_to_pmlist(listbuf);
if ( pmlist == NULL ) cdoAbort("Namelist not found!");
listbuf_destroy(listbuf);
return pmlist;
}
/*
list_t *cdo_parse_namelist(const char *filename)
{
assert(filename != NULL);
......@@ -154,3 +167,4 @@ list_t *cdo_parse_namelist(const char *filename)
return pml;
}
*/
......@@ -4,11 +4,11 @@
#include "pmlist.h"
keyValues_t *kvlist_search(list_t *kvl, const char *key)
keyValues_t *kvlist_search(list_t *kvlist, const char *key)
{
if ( key )
{
listNode_t *node = kvl->head;
listNode_t *node = kvlist->head;
while ( node )
{
keyValues_t *kv = *(keyValues_t **)node->data;
......@@ -21,18 +21,18 @@ keyValues_t *kvlist_search(list_t *kvl, const char *key)
}
list_t *pml_search_kvl(list_t *pml, const char *key, const char *value)
list_t *pmlist_search_kvlist(list_t *pmlist, const char *key, const char *value)
{
if ( pml && key && value )
if ( pmlist && key && value )
{
listNode_t *node = pml->head;
listNode_t *node = pmlist->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;
list_t *kvlist = *(list_t **)node->data;
keyValues_t *kv = kvlist_search(kvlist, key);
if ( kv && kv->nvalues > 0 && *(kv->values[0]) == *value && strcmp(kv->values[0], value) == 0 ) return kvlist;
}
node = node->next;
}
......@@ -42,7 +42,7 @@ list_t *pml_search_kvl(list_t *pml, const char *key, const char *value)
}
bool kvl_print_iter(void *data)
bool kvlist_print_iter(void *data)
{
keyValues_t *keyval = *(keyValues_t **)data;
char *key = keyval->key;
......@@ -56,18 +56,18 @@ bool kvl_print_iter(void *data)
}
void kvlist_print(list_t *kvl)
void kvlist_print(list_t *kvlist)
{
printf("Key/Value list %s:\n", list_name(kvl));
list_for_each(kvl, kvl_print_iter);
printf("Key/Value list %s:\n", list_name(kvlist));
list_for_each(kvlist, kvlist_print_iter);
}