Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
11c18c9d
Commit
11c18c9d
authored
Oct 18, 2016
by
Uwe Schulzweida
Browse files
Added parse_cmor_table.c.
parent
2a24e3b2
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/CMOR_table.c
View file @
11c18c9d
...
...
@@ -20,200 +20,15 @@
*/
#include
<errno.h>
#include
"cdo.h"
#include
"cdo_int.h"
#include
"pmlist.h"
static
char
*
readLineFromBuffer
(
char
*
buffer
,
size_t
*
buffersize
,
char
*
line
,
size_t
len
)
{
int
ichar
;
size_t
ipos
=
0
;
while
(
*
buffersize
)
{
ichar
=
*
buffer
;
(
*
buffersize
)
--
;
buffer
++
;
if
(
ichar
==
'\r'
)
{
if
(
*
buffersize
)
{
ichar
=
*
buffer
;
if
(
ichar
==
'\n'
)
{
(
*
buffersize
)
--
;
buffer
++
;
}
}
break
;
}
if
(
ichar
==
'\n'
)
break
;
line
[
ipos
++
]
=
ichar
;
if
(
ipos
>=
len
)
{
fprintf
(
stderr
,
"readLineFromBuffer: end of line not found (maxlen = %ld)!
\n
"
,
len
);
break
;
}
}
line
[
ipos
]
=
0
;
if
(
*
buffersize
==
0
&&
ipos
==
0
)
buffer
=
NULL
;
return
buffer
;
}
static
char
*
skipSeparator
(
char
*
pline
)
{
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
if
(
*
pline
==
'='
||
*
pline
==
':'
)
pline
++
;
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
return
pline
;
}
static
char
*
getElementName
(
char
*
pline
,
char
*
name
)
{
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
size_t
len
=
strlen
(
pline
);
size_t
pos
=
0
;
while
(
pos
<
len
&&
!
isspace
((
int
)
*
(
pline
+
pos
))
&&
*
(
pline
+
pos
)
!=
'='
&&
*
(
pline
+
pos
)
!=
':'
)
pos
++
;
strncpy
(
name
,
pline
,
pos
);
name
[
pos
]
=
0
;
pline
+=
pos
;
return
pline
;
}
static
char
*
getElementValue
(
char
*
pline
)
{
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
size_t
len
=
strlen
(
pline
);
while
(
isspace
((
int
)
*
(
pline
+
len
-
1
))
&&
len
)
{
*
(
pline
+
len
-
1
)
=
0
;
len
--
;}
return
pline
;
}
void
pml_parse_buffer
(
list_t
*
pml
,
size_t
buffersize
,
char
*
buffer
)
{
char
line
[
4096
];
char
name
[
256
];
char
*
pline
;
char
listkey1
[]
=
"axis_entry:"
;
char
listkey2
[]
=
"variable_entry:"
;
int
linenumber
=
0
;
int
listtype
=
0
;
list_t
*
kvl
=
NULL
;
while
(
(
buffer
=
readLineFromBuffer
(
buffer
,
&
buffersize
,
line
,
sizeof
(
line
)))
)
{
linenumber
++
;
pline
=
line
;
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
if
(
*
pline
==
'#'
||
*
pline
==
'!'
||
*
pline
==
'\0'
)
continue
;
// len = (int) strlen(pline);
if
(
listtype
==
0
&&
*
pline
==
'&'
)
{
listtype
=
1
;
}
if
(
strncmp
(
pline
,
listkey1
,
strlen
(
listkey1
))
==
0
)
{
pline
+=
strlen
(
listkey1
);
listtype
=
2
;
kvl
=
list_new
(
sizeof
(
keyValues_t
*
),
free_keyval
,
"axis"
);
list_append
(
pml
,
&
kvl
);
pline
=
skipSeparator
(
pline
);
pline
=
getElementValue
(
pline
);
if
(
*
pline
)
kvlist_append
(
kvl
,
"name"
,
(
const
char
**
)
&
pline
,
1
);
}
else
if
(
strncmp
(
pline
,
listkey2
,
strlen
(
listkey2
))
==
0
)
{
pline
+=
strlen
(
listkey2
);
listtype
=
2
;
kvl
=
list_new
(
sizeof
(
keyValues_t
*
),
free_keyval
,
"variable"
);
list_append
(
pml
,
&
kvl
);
pline
=
skipSeparator
(
pline
);
pline
=
getElementValue
(
pline
);
if
(
*
pline
)
kvlist_append
(
kvl
,
"name"
,
(
const
char
**
)
&
pline
,
1
);
}
else
{
pline
=
getElementName
(
pline
,
name
);
pline
=
skipSeparator
(
pline
);
pline
=
getElementValue
(
pline
);
if
(
kvl
==
NULL
)
{
kvl
=
list_new
(
sizeof
(
keyValues_t
*
),
free_keyval
,
"global"
);
list_append
(
pml
,
&
kvl
);
}
if
(
*
pline
)
kvlist_append
(
kvl
,
name
,
(
const
char
**
)
&
pline
,
1
);
{
//fprintf(stderr, "%d skip line %3d: %s\n", newlist, linenumber, pline);
}
}
// printf("%s\n", pline);
}
}
list_t
*
pml_parse_cmor_file
(
const
char
*
filename
)
{
assert
(
filename
!=
NULL
);
size_t
filesize
=
fileSize
(
filename
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"Open failed on %s: %s
\n
"
,
filename
,
strerror
(
errno
));
return
NULL
;
}
char
*
buffer
=
(
char
*
)
Malloc
(
filesize
);
size_t
nitems
=
fread
(
buffer
,
1
,
filesize
,
fp
);
fclose
(
fp
);
if
(
nitems
!=
filesize
)
{
fprintf
(
stderr
,
"Read failed on %s!
\n
"
,
filename
);
return
NULL
;
}
list_t
*
pml
=
list_new
(
sizeof
(
list_t
*
),
free_kvlist
,
filename
);
/*
if ( buffer[0] == '{' )
kvlParseBufferJson(kvl);
else
*/
pml_parse_buffer
(
pml
,
filesize
,
buffer
);
return
pml
;
}
static
int
read_cmor_table
(
const
char
*
filename
)
{
list_t
*
pml
=
pml
_parse_cmor_file
(
filename
);
list_t
*
pml
=
cdo
_parse_cmor_file
(
filename
);
if
(
pml
==
NULL
)
return
-
1
;
printf
(
"# Number of lists: %d
\n
"
,
list_size
(
pml
));
...
...
@@ -240,7 +55,7 @@ int read_cmor_table(const char *filename)
static
int
conv_cmor_table
(
const
char
*
filename
)
{
list_t
*
pml
=
pml
_parse_cmor_file
(
filename
);
list_t
*
pml
=
cdo
_parse_cmor_file
(
filename
);
if
(
pml
==
NULL
)
return
-
1
;
bool
hasmissval
=
false
;
...
...
src/Makefile.am
View file @
11c18c9d
...
...
@@ -94,6 +94,7 @@ libcdo_la_SOURCES = \
operator_help.h
\
par_io.c
\
par_io.h
\
parse_cmor_table.c
\
percentiles_hist.c
\
percentiles_hist.h
\
percentiles.c
\
...
...
src/Makefile.in
View file @
11c18c9d
...
...
@@ -126,9 +126,9 @@ am_libcdo_la_OBJECTS = libcdo_la-cdo_pthread.lo libcdo_la-cdo_vlist.lo \
libcdo_la-list.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-p
ercentiles_hist
.lo libcdo_la-percentiles.lo \
libcdo_la-p
ipe
.lo libcdo_la-p
ml
.lo libcdo_la-pml
ist
.lo \
libcdo_la-process.lo libcdo_la-pstream.lo \
libcdo_la-p
arse_cmor_table
.lo libcdo_la-percentiles
_hist
.lo
\
libcdo_la-p
ercentiles
.lo libcdo_la-p
ipe
.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
\
...
...
@@ -515,20 +515,20 @@ libcdo_la_SOURCES = cdo_int.h compare.h cdo_pthread.c cdo_vlist.c \
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 p
ercentiles_hist
.c percentiles_hist.
h percentiles.
c \
percentiles
.h pipe.c pipe.h pml.c pml.h pmlist.c pmlist
.h \
p
ragma_omp_atomic_update.h printinfo.h process.c process
.h \
p
stream.c pstream
.h pstream
_write.h
pstream
_int
.h \
pt
h
rea
d_debug.c pthread_debug.h readline.c realtime.c remap
.h \
re
maplib.c remapsort.c remap_scrip_io.c remap_search_reg2d
.c \
remap_s
earch_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 \
par_io.h p
arse_cmor_table
.c percentiles_hist.c
\
percentiles
_hist.h percentiles.c percentiles.h pipe.c pipe
.h
\
p
ml.c pml.h pmlist.c pmlist.h pragma_omp_atomic_update
.h
\
p
rintinfo.h process.c process
.h pstream
.c
pstream.h
\
p
s
trea
m_write.h pstream_int.h pthread_debug.c pthread_debug
.h
\
re
adline.c realtime.c remap.h remaplib.c remapsort
.c
\
remap_s
crip_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 +1040,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/libcdo_la-normal.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/libcdo_la-nth_element.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/libcdo_la-par_io.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/libcdo_la-parse_cmor_table.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/libcdo_la-percentiles.Plo@am__quote@
@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@
...
...
@@ -1480,6 +1481,13 @@ libcdo_la-par_io.lo: par_io.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-par_io.lo
`
test
-f
'par_io.c'
||
echo
'
$(srcdir)
/'
`
par_io.c
libcdo_la-parse_cmor_table.lo
:
parse_cmor_table.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-parse_cmor_table.lo
-MD
-MP
-MF
$(DEPDIR)
/libcdo_la-parse_cmor_table.Tpo
-c
-o
libcdo_la-parse_cmor_table.lo
`
test
-f
'parse_cmor_table.c'
||
echo
'
$(srcdir)
/'
`
parse_cmor_table.c
@am__fastdepCC_TRUE@
$(AM_V_at)$(am__mv)
$(DEPDIR)/libcdo_la-parse_cmor_table.Tpo
$(DEPDIR)/libcdo_la-parse_cmor_table.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@
$(AM_V_CC)source
=
'parse_cmor_table.c'
object
=
'libcdo_la-parse_cmor_table.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-parse_cmor_table.lo
`
test
-f
'parse_cmor_table.c'
||
echo
'
$(srcdir)
/'
`
parse_cmor_table.c
libcdo_la-percentiles_hist.lo
:
percentiles_hist.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-percentiles_hist.lo
-MD
-MP
-MF
$(DEPDIR)
/libcdo_la-percentiles_hist.Tpo
-c
-o
libcdo_la-percentiles_hist.lo
`
test
-f
'percentiles_hist.c'
||
echo
'
$(srcdir)
/'
`
percentiles_hist.c
@am__fastdepCC_TRUE@
$(AM_V_at)$(am__mv)
$(DEPDIR)/libcdo_la-percentiles_hist.Tpo
$(DEPDIR)/libcdo_la-percentiles_hist.Plo
...
...
src/cdo_int.h
View file @
11c18c9d
...
...
@@ -32,6 +32,7 @@
#include
<ctype.h>
#include
<stdarg.h>
#include
"list.h"
#include
"compare.h"
#include
"timebase.h"
#include
"field.h"
...
...
@@ -168,6 +169,7 @@ void cdo_read_field(const char *name, char *pline, int size, double *field, int
double
cdoZaxisInqLevel
(
int
zaxisID
,
int
levelID
);
int
cdoZaxisInqLevels
(
int
zaxisID
,
double
*
levels
);
list_t
*
cdo_parse_cmor_file
(
const
char
*
filename
);
#ifdef __cplusplus
extern
"C"
{
...
...
src/parse_cmor_table.c
0 → 100644
View file @
11c18c9d
#include
<errno.h>
#include
"cdo_int.h"
#include
"pmlist.h"
static
char
*
readLineFromBuffer
(
char
*
buffer
,
size_t
*
buffersize
,
char
*
line
,
size_t
len
)
{
int
ichar
;
size_t
ipos
=
0
;
while
(
*
buffersize
)
{
ichar
=
*
buffer
;
(
*
buffersize
)
--
;
buffer
++
;
if
(
ichar
==
'\r'
)
{
if
(
*
buffersize
)
{
ichar
=
*
buffer
;
if
(
ichar
==
'\n'
)
{
(
*
buffersize
)
--
;
buffer
++
;
}
}
break
;
}
if
(
ichar
==
'\n'
)
break
;
line
[
ipos
++
]
=
ichar
;
if
(
ipos
>=
len
)
{
fprintf
(
stderr
,
"readLineFromBuffer: end of line not found (maxlen = %ld)!
\n
"
,
len
);
break
;
}
}
line
[
ipos
]
=
0
;
if
(
*
buffersize
==
0
&&
ipos
==
0
)
buffer
=
NULL
;
return
buffer
;
}
static
char
*
skipSeparator
(
char
*
pline
)
{
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
if
(
*
pline
==
'='
||
*
pline
==
':'
)
pline
++
;
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
return
pline
;
}
static
char
*
getElementName
(
char
*
pline
,
char
*
name
)
{
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
size_t
len
=
strlen
(
pline
);
size_t
pos
=
0
;
while
(
pos
<
len
&&
!
isspace
((
int
)
*
(
pline
+
pos
))
&&
*
(
pline
+
pos
)
!=
'='
&&
*
(
pline
+
pos
)
!=
':'
)
pos
++
;
strncpy
(
name
,
pline
,
pos
);
name
[
pos
]
=
0
;
pline
+=
pos
;
return
pline
;
}
static
char
*
getElementValue
(
char
*
pline
)
{
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
size_t
len
=
strlen
(
pline
);
while
(
isspace
((
int
)
*
(
pline
+
len
-
1
))
&&
len
)
{
*
(
pline
+
len
-
1
)
=
0
;
len
--
;}
return
pline
;
}
void
pml_parse_buffer
(
list_t
*
pml
,
size_t
buffersize
,
char
*
buffer
)
{
char
line
[
4096
];
char
name
[
256
];
char
*
pline
;
char
listkey1
[]
=
"axis_entry:"
;
char
listkey2
[]
=
"variable_entry:"
;
int
linenumber
=
0
;
int
listtype
=
0
;
list_t
*
kvl
=
NULL
;
while
(
(
buffer
=
readLineFromBuffer
(
buffer
,
&
buffersize
,
line
,
sizeof
(
line
)))
)
{
linenumber
++
;
pline
=
line
;
while
(
isspace
((
int
)
*
pline
)
)
pline
++
;
if
(
*
pline
==
'#'
||
*
pline
==
'!'
||
*
pline
==
'\0'
)
continue
;
// len = (int) strlen(pline);
if
(
listtype
==
0
&&
*
pline
==
'&'
)
{
listtype
=
1
;
}
if
(
strncmp
(
pline
,
listkey1
,
strlen
(
listkey1
))
==
0
)
{
pline
+=
strlen
(
listkey1
);
listtype
=
2
;
kvl
=
list_new
(
sizeof
(
keyValues_t
*
),
free_keyval
,
"axis"
);
list_append
(
pml
,
&
kvl
);
pline
=
skipSeparator
(
pline
);
pline
=
getElementValue
(
pline
);
if
(
*
pline
)
kvlist_append
(
kvl
,
"name"
,
(
const
char
**
)
&
pline
,
1
);
}
else
if
(
strncmp
(
pline
,
listkey2
,
strlen
(
listkey2
))
==
0
)
{
pline
+=
strlen
(
listkey2
);
listtype
=
2
;
kvl
=
list_new
(
sizeof
(
keyValues_t
*
),
free_keyval
,
"variable"
);
list_append
(
pml
,
&
kvl
);
pline
=
skipSeparator
(
pline
);
pline
=
getElementValue
(
pline
);
if
(
*
pline
)
kvlist_append
(
kvl
,
"name"
,
(
const
char
**
)
&
pline
,
1
);
}
else
{
pline
=
getElementName
(
pline
,
name
);
pline
=
skipSeparator
(
pline
);
pline
=
getElementValue
(
pline
);
if
(
kvl
==
NULL
)
{
kvl
=
list_new
(
sizeof
(
keyValues_t
*
),
free_keyval
,
"global"
);
list_append
(
pml
,
&
kvl
);
}
if
(
*
pline
)
kvlist_append
(
kvl
,
name
,
(
const
char
**
)
&
pline
,
1
);
{
//fprintf(stderr, "%d skip line %3d: %s\n", newlist, linenumber, pline);
}
}
// printf("%s\n", pline);
}
}
list_t
*
cdo_parse_cmor_file
(
const
char
*
filename
)
{
assert
(
filename
!=
NULL
);
size_t
filesize
=
fileSize
(
filename
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"Open failed on %s: %s
\n
"
,
filename
,
strerror
(
errno
));
return
NULL
;
}
char
*
buffer
=
(
char
*
)
Malloc
(
filesize
);
size_t
nitems
=
fread
(
buffer
,
1
,
filesize
,
fp
);
fclose
(
fp
);
if
(
nitems
!=
filesize
)
{
fprintf
(
stderr
,
"Read failed on %s!
\n
"
,
filename
);
return
NULL
;
}
list_t
*
pml
=
list_new
(
sizeof
(
list_t
*
),
free_kvlist
,
filename
);
/*
if ( buffer[0] == '{' )
kvlParseBufferJson(kvl);
else
*/
pml_parse_buffer
(
pml
,
filesize
,
buffer
);
return
pml
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment