Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
40cd4b73
Commit
40cd4b73
authored
Apr 11, 2008
by
Uwe Schulzweida
Browse files
add write support for netCDF4 classic with deflate
parent
79b8d2b3
Changes
18
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
40cd4b73
2008-08-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* add support for netCDF4 classic with deflate
* Version 1.1.2 released
2008-04-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using GRIB library version 1.1.1
...
...
app/cdi.c
View file @
40cd4b73
...
...
@@ -39,7 +39,7 @@ int Zlevel = 0;
static
void
version
(
void
)
{
fprintf
(
stderr
,
"CDI version 1.
6.3
\n
"
);
fprintf
(
stderr
,
"CDI version 1.
7.0
\n
"
);
cdiPrintVersion
();
fprintf
(
stderr
,
"
\n
"
);
/*
...
...
@@ -57,6 +57,7 @@ static void version(void)
1.6.1 27 Feb 2007 : short info with ltype for GENERIC zaxis
1.6.2 3 Jan 2008 : changes for CDI library version 1.1.0 (compress)
1.6.3 26 Mar 2008 : call streamDefTimestep also if ntsteps = 0 (buf fix)
1.7.0 11 Apr 2008 : add option -z zip for deflate compression of netCDF4 variables
*/
}
...
...
@@ -70,7 +71,7 @@ static void usage(void)
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
" Options:
\n
"
);
fprintf
(
stderr
,
" -d Print debugging information
\n
"
);
fprintf
(
stderr
,
" -f <format> Format of the output file. (grb, nc, nc2, src, ext or ieg)
\n
"
);
fprintf
(
stderr
,
" -f <format> Format of the output file. (grb, nc, nc2,
nc4,
src, ext or ieg)
\n
"
);
fprintf
(
stderr
,
" -s give short information if ofile is missing
\n
"
);
fprintf
(
stderr
,
" -t <table> Parameter table name/file
\n
"
);
fprintf
(
stderr
,
" Predefined tables: "
);
...
...
@@ -81,6 +82,7 @@ static void usage(void)
fprintf
(
stderr
,
" -V Print version number
\n
"
);
fprintf
(
stderr
,
" -z szip Compress GRIB records with szip
\n
"
);
fprintf
(
stderr
,
" zip Deflate compression of netCDF4 variables
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
" Report bugs to <Uwe.Schulzweida@zmaw.de>
\n
"
);
}
...
...
@@ -176,6 +178,9 @@ void printFiletype(int streamID, int vlistID)
case
FILETYPE_NC2
:
printf
(
"netCDF2"
);
break
;
case
FILETYPE_NC4
:
printf
(
"netCDF4"
);
break
;
case
FILETYPE_SRV
:
printf
(
"SERVICE"
);
break
;
...
...
@@ -202,17 +207,22 @@ void printFiletype(int streamID, int vlistID)
}
}
if
(
filetype
==
FILETYPE_GRB
)
if
(
filetype
==
FILETYPE_GRB
||
filetype
==
FILETYPE_NC4
)
{
int
nvars
,
varID
;
int
ztype
;
nvars
=
vlistNvars
(
vlistID
);
for
(
varID
=
0
;
varID
<
nvars
;
varID
++
)
{
if
(
vlistInqVar
Szip
(
vlistID
,
varID
)
)
if
(
ztype
=
vlistInqVar
Ztype
(
vlistID
,
varID
)
)
{
printf
(
" SZIP"
);
if
(
ztype
==
COMPRESS_SZIP
)
printf
(
" SZIP"
);
else
if
(
ztype
==
COMPRESS_ZIP
)
printf
(
" ZIP"
);
break
;
}
}
...
...
@@ -486,7 +496,7 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
fprintf
(
stdout
,
" %-3s"
,
pstr
);
if
(
vlistInqVar
Szip
(
vlistID
,
varID
)
)
if
(
vlistInqVar
Ztype
(
vlistID
,
varID
)
)
fprintf
(
stdout
,
"z"
);
else
fprintf
(
stdout
,
" "
);
...
...
@@ -707,6 +717,7 @@ static void setDefaultFileType(char *filetypestr)
if
(
strncmp
(
filetypestr
,
"grb"
,
3
)
==
0
)
{
ftstr
+=
3
;
DefaultFileType
=
FILETYPE_GRB
;
}
else
if
(
strncmp
(
filetypestr
,
"nc2"
,
3
)
==
0
)
{
ftstr
+=
3
;
DefaultFileType
=
FILETYPE_NC2
;
}
else
if
(
strncmp
(
filetypestr
,
"nc4"
,
3
)
==
0
)
{
ftstr
+=
3
;
DefaultFileType
=
FILETYPE_NC4
;
}
else
if
(
strncmp
(
filetypestr
,
"nc"
,
2
)
==
0
)
{
ftstr
+=
2
;
DefaultFileType
=
FILETYPE_NC
;
}
else
if
(
strncmp
(
filetypestr
,
"srv"
,
3
)
==
0
)
{
ftstr
+=
3
;
DefaultFileType
=
FILETYPE_SRV
;
}
else
if
(
strncmp
(
filetypestr
,
"ext"
,
3
)
==
0
)
{
ftstr
+=
3
;
DefaultFileType
=
FILETYPE_EXT
;
}
...
...
@@ -714,7 +725,7 @@ static void setDefaultFileType(char *filetypestr)
else
{
fprintf
(
stderr
,
"Unsupported filetype %s!
\n
"
,
filetypestr
);
fprintf
(
stderr
,
"Available filetypes: grb, nc, nc2, srv, ext and ieg
\n
"
);
fprintf
(
stderr
,
"Available filetypes: grb, nc, nc2,
nc4,
srv, ext and ieg
\n
"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -730,8 +741,8 @@ static void setDefaultFileType(char *filetypestr)
{
fprintf
(
stderr
,
"Unexpected character >%c< in file type >%s<!
\n
"
,
*
ftstr
,
filetypestr
);
fprintf
(
stderr
,
"Use format[_nbits] with:
\n
"
);
fprintf
(
stderr
,
" format = grb, nc, nc2, srv, ext or ieg
\n
"
);
fprintf
(
stderr
,
" nbits = 32/64 for nc, nc2, srv, ext, ieg; 1 - 32 for grb
\n
"
);
fprintf
(
stderr
,
" format = grb, nc, nc2,
nc4,
srv, ext or ieg
\n
"
);
fprintf
(
stderr
,
" nbits = 32/64 for nc, nc2,
nc4,
srv, ext, ieg; 1 - 32 for grb
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -770,6 +781,11 @@ void defineCompress(const char *arg)
Ztype
=
COMPRESS_GZIP
;
Zlevel
=
6
;
}
else
if
(
strncmp
(
arg
,
"zip"
,
len
)
==
0
)
{
Ztype
=
COMPRESS_ZIP
;
Zlevel
=
1
;
}
else
fprintf
(
stderr
,
"Compression %s unsupported!
\n
"
,
arg
);
}
...
...
configure
View file @
40cd4b73
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for cdi 1.1.
1
.
# Generated by GNU Autoconf 2.61 for cdi 1.1.
2
.
#
# Report bugs to <Uwe.Schulzweida@zmaw.de>.
#
...
...
@@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME
=
'cdi'
PACKAGE_TARNAME
=
'cdi'
PACKAGE_VERSION
=
'1.1.
1
'
PACKAGE_STRING
=
'cdi 1.1.
1
'
PACKAGE_VERSION
=
'1.1.
2
'
PACKAGE_STRING
=
'cdi 1.1.
2
'
PACKAGE_BUGREPORT
=
'Uwe.Schulzweida@zmaw.de'
# Factoring default headers for most tests.
...
...
@@ -1230,7 +1230,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat
<<
_ACEOF
\`
configure' configures cdi 1.1.
1
to adapt to many kinds of systems.
\`
configure' configures cdi 1.1.
2
to adapt to many kinds of systems.
Usage:
$0
[OPTION]... [VAR=VALUE]...
...
...
@@ -1301,7 +1301,7 @@ fi
if
test
-n
"
$ac_init_help
"
;
then
case
$ac_init_help
in
short
|
recursive
)
echo
"Configuration of cdi 1.1.
1
:"
;;
short
|
recursive
)
echo
"Configuration of cdi 1.1.
2
:"
;;
esac
cat
<<
\
_ACEOF
...
...
@@ -1406,7 +1406,7 @@ fi
test
-n
"
$ac_init_help
"
&&
exit
$ac_status
if
$ac_init_version
;
then
cat
<<
\
_ACEOF
cdi configure 1.1.
1
cdi configure 1.1.
2
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
...
...
@@ -1420,7 +1420,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by cdi
$as_me
1.1.
1
, which was
It was created by cdi
$as_me
1.1.
2
, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0
$@
...
...
@@ -2245,7 +2245,7 @@ fi
# Define the identity of the package.
PACKAGE
=
'cdi'
VERSION
=
'1.1.
1
'
VERSION
=
'1.1.
2
'
cat
>>
confdefs.h
<<
_ACEOF
...
...
@@ -6820,7 +6820,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by cdi
$as_me
1.1.
1
, which was
This file was extended by cdi
$as_me
1.1.
2
, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES =
$CONFIG_FILES
...
...
@@ -6873,7 +6873,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat
>>
$CONFIG_STATUS
<<
_ACEOF
ac_cs_version="
\\
cdi config.status 1.1.
1
cdi config.status 1.1.
2
configured by
$0
, generated by GNU Autoconf 2.61,
with options
\\
"`echo "
$ac_configure_args
" | sed 's/^ //; s/[
\\
""
\`\$
]/
\\\\
&/g'`
\\
"
...
...
configure.ac
View file @
40cd4b73
# Process this file with autoconf to produce a configure script.
AC_INIT(cdi, 1.1.
1
, Uwe.Schulzweida@zmaw.de)
AC_INIT(cdi, 1.1.
2
, Uwe.Schulzweida@zmaw.de)
CONFIG_ABORT=yes
...
...
src/cdf.c
View file @
40cd4b73
...
...
@@ -70,7 +70,7 @@ int cdfOpenFile(const char *filename, const char *mode, int version)
int
ncid
=
-
1
;
#if defined (HAVE_LIBNETCDF)
int
fmode
;
int
writemode
=
NC_
WRITE
;
int
writemode
=
NC_
CLOBBER
;
if
(
filename
==
NULL
)
ncid
=
CDI_EINVAL
;
...
...
@@ -87,7 +87,10 @@ int cdfOpenFile(const char *filename, const char *mode, int version)
case
'W'
:
fmode
=
'w'
;
#if defined (NC_64BIT_OFFSET)
if
(
version
==
2
)
writemode
=
NC_WRITE
|
NC_64BIT_OFFSET
;
if
(
version
==
2
)
writemode
=
NC_CLOBBER
|
NC_64BIT_OFFSET
;
#endif
#if defined (NC_NETCDF4)
if
(
version
==
4
)
writemode
=
NC_CLOBBER
|
NC_NETCDF4
|
NC_CLASSIC_MODEL
;
#endif
cdf_create
(
filename
,
writemode
,
&
ncid
);
cdfComment
(
ncid
);
...
...
@@ -126,7 +129,7 @@ int cdfOpen(const char *filename, const char *mode)
int
cdfOpen64
(
const
char
*
filename
,
const
char
*
mode
)
{
static
char
func
[]
=
"cdfOpen"
;
static
char
func
[]
=
"cdfOpen
64
"
;
int
fileID
=
-
1
;
if
(
CDF_Debug
)
...
...
@@ -135,16 +138,38 @@ int cdfOpen64(const char *filename, const char *mode)
#if defined (HAVE_LIBNETCDF)
#if ! defined (NC_64BIT_OFFSET)
fileID
=
CDI_ELIBNAVAIL
;
return
(
fileID
);
#endif
#endif
if
(
fileID
!=
CDI_ELIBNAVAIL
)
{
fileID
=
cdfOpenFile
(
filename
,
mode
,
2
);
fileID
=
cdfOpenFile
(
filename
,
mode
,
2
);
if
(
CDF_Debug
)
Message
(
func
,
"file %s opened with id %d"
,
filename
,
fileID
);
}
if
(
CDF_Debug
)
Message
(
func
,
"file %s opened with id %d"
,
filename
,
fileID
);
return
(
fileID
);
}
int
cdf4Open
(
const
char
*
filename
,
const
char
*
mode
)
{
static
char
func
[]
=
"cdf4Open"
;
int
fileID
=
-
1
;
if
(
CDF_Debug
)
Message
(
func
,
"open %s with mode %c"
,
filename
,
*
mode
);
#if defined (HAVE_LIBNETCDF)
#if ! defined (NC_NETCDF4)
fileID
=
CDI_ELIBNAVAIL
;
return
(
fileID
);
#endif
#endif
fileID
=
cdfOpenFile
(
filename
,
mode
,
4
);
if
(
CDF_Debug
)
Message
(
func
,
"file %s opened with id %d"
,
filename
,
fileID
);
return
(
fileID
);
}
...
...
src/cdf.h
View file @
40cd4b73
...
...
@@ -7,6 +7,7 @@ const char *cdfLibraryVersion(void);
int
cdfOpen
(
const
char
*
filename
,
const
char
*
mode
);
int
cdfOpen64
(
const
char
*
filename
,
const
char
*
mode
);
int
cdf4Open
(
const
char
*
filename
,
const
char
*
mode
);
void
cdfClose
(
int
fileID
);
#endif
/* _CDF_H */
src/cdi.h
View file @
40cd4b73
...
...
@@ -17,22 +17,23 @@ extern "C" {
/* Error identifier */
#define CDI_NOERR 0
/* No Error */
#define CDI_ESYSTEM -10
/* Operating system error */
#define CDI_EINVAL -20
/* Invalid argument */
#define CDI_EUFTYPE -21
/* Unsupported file type */
#define CDI_ELIBNAVAIL -22
/* xxx library not available */
#define CDI_EUFSTRUCT -23
/* Unsupported file structure */
#define CDI_NOERR 0
/* No Error
*/
#define CDI_ESYSTEM -10
/* Operating system error
*/
#define CDI_EINVAL -20
/* Invalid argument
*/
#define CDI_EUFTYPE -21
/* Unsupported file type
*/
#define CDI_ELIBNAVAIL -22
/* xxx library not available
*/
#define CDI_EUFSTRUCT -23
/* Unsupported file structure
*/
/* File types */
#define FILETYPE_GRB 1
/* File type GRIB */
#define FILETYPE_GB2 2
/* File type GRIB version 2 */
#define FILETYPE_NC 3
/* File type netCDF */
#define FILETYPE_NC2 4
/* File type netCDF version 2 */
#define FILETYPE_SRV 5
/* File type SERVICE */
#define FILETYPE_EXT 6
/* File type EXTRA */
#define FILETYPE_IEG 8
/* File type IEG */
#define FILETYPE_GRB 1
/* File type GRIB */
#define FILETYPE_GB2 2
/* File type GRIB version 2 */
#define FILETYPE_NC 3
/* File type netCDF */
#define FILETYPE_NC2 4
/* File type netCDF version 2 */
#define FILETYPE_NC4 5
/* File type netCDF version 4 (classic) */
#define FILETYPE_SRV 6
/* File type SERVICE */
#define FILETYPE_EXT 7
/* File type EXTRA */
#define FILETYPE_IEG 8
/* File type IEG */
/* Compress types */
...
...
@@ -40,6 +41,7 @@ extern "C" {
#define COMPRESS_SZIP 1
#define COMPRESS_GZIP 2
#define COMPRESS_BZIP2 3
#define COMPRESS_ZIP 4
/* external data types */
...
...
@@ -313,8 +315,10 @@ int vlistInqVarGrid(int vlistID, int varID);
int
vlistInqVarZaxis
(
int
vlistID
,
int
varID
);
int
vlistInqVarTime
(
int
vlistID
,
int
varID
);
void
vlistDefVarSzip
(
int
vlistID
,
int
varID
,
int
szip
);
int
vlistInqVarSzip
(
int
vlistID
,
int
varID
);
void
vlistDefVarZtype
(
int
vlistID
,
int
varID
,
int
ztype
);
int
vlistInqVarZtype
(
int
vlistID
,
int
varID
);
void
vlistDefVarZlevel
(
int
vlistID
,
int
varID
,
int
zlevel
);
int
vlistInqVarZlevel
(
int
vlistID
,
int
varID
);
/* vlistDefVarCode: Define the code number of a Variable */
void
vlistDefVarCode
(
int
vlistID
,
int
varID
,
int
code
);
...
...
src/cdi.inc
View file @
40cd4b73
!
!
Fortran
interface
for
CDI
library
version
1.1.
0
!
Fortran
interface
for
CDI
library
version
1.1.
1
!
INTEGER
CDI_UNDEFID
...
...
@@ -39,10 +39,12 @@
PARAMETER
(
FILETYPE_NC
=
3
)
INTEGER
FILETYPE_NC2
PARAMETER
(
FILETYPE_NC2
=
4
)
INTEGER
FILETYPE_NC4
PARAMETER
(
FILETYPE_NC4
=
5
)
INTEGER
FILETYPE_SRV
PARAMETER
(
FILETYPE_SRV
=
5
)
PARAMETER
(
FILETYPE_SRV
=
6
)
INTEGER
FILETYPE_EXT
PARAMETER
(
FILETYPE_EXT
=
6
)
PARAMETER
(
FILETYPE_EXT
=
7
)
INTEGER
FILETYPE_IEG
PARAMETER
(
FILETYPE_IEG
=
8
)
!
...
...
@@ -56,6 +58,8 @@
PARAMETER
(
COMPRESS_GZIP
=
2
)
INTEGER
COMPRESS_BZIP2
PARAMETER
(
COMPRESS_BZIP2
=
3
)
INTEGER
COMPRESS_ZIP
PARAMETER
(
COMPRESS_ZIP
=
4
)
!
!
external
data
types
!
...
...
@@ -612,16 +616,27 @@
!
INTEGER
varID
)
EXTERNAL
vlistInqVarTime
!
vlistDefVar
Szip
!
vlistDefVar
Ztype
!
(
INTEGER
vlistID
,
!
INTEGER
varID
,
!
INTEGER
szip
)
EXTERNAL
vlistDefVarSzip
!
INTEGER
ztype
)
EXTERNAL
vlistDefVarZtype
INTEGER
vlistInqVarZtype
!
(
INTEGER
vlistID
,
!
INTEGER
varID
)
EXTERNAL
vlistInqVarZtype
!
vlistDefVarZlevel
!
(
INTEGER
vlistID
,
!
INTEGER
varID
,
!
INTEGER
zlevel
)
EXTERNAL
vlistDefVarZlevel
INTEGER
vlistInqVar
Szip
INTEGER
vlistInqVar
Zlevel
!
(
INTEGER
vlistID
,
!
INTEGER
varID
)
EXTERNAL
vlistInqVar
Szip
EXTERNAL
vlistInqVar
Zlevel
!
vlistDefVarCode
!
(
INTEGER
vlistID
,
...
...
src/cdiFortran.c
View file @
40cd4b73
...
...
@@ -139,8 +139,10 @@ FCALLSCSUB5 (vlistInqVar, VLISTINQVAR, vlistinqvar, INT, INT, PINT, PINT, PINT)
FCALLSCFUN2
(
INT
,
vlistInqVarGrid
,
VLISTINQVARGRID
,
vlistinqvargrid
,
INT
,
INT
)
FCALLSCFUN2
(
INT
,
vlistInqVarZaxis
,
VLISTINQVARZAXIS
,
vlistinqvarzaxis
,
INT
,
INT
)
FCALLSCFUN2
(
INT
,
vlistInqVarTime
,
VLISTINQVARTIME
,
vlistinqvartime
,
INT
,
INT
)
FCALLSCSUB3
(
vlistDefVarSzip
,
VLISTDEFVARSZIP
,
vlistdefvarszip
,
INT
,
INT
,
INT
)
FCALLSCFUN2
(
INT
,
vlistInqVarSzip
,
VLISTINQVARSZIP
,
vlistinqvarszip
,
INT
,
INT
)
FCALLSCSUB3
(
vlistDefVarZtype
,
VLISTDEFVARZTYPE
,
vlistdefvarztype
,
INT
,
INT
,
INT
)
FCALLSCFUN2
(
INT
,
vlistInqVarZtype
,
VLISTINQVARZTYPE
,
vlistinqvarztype
,
INT
,
INT
)
FCALLSCSUB3
(
vlistDefVarZlevel
,
VLISTDEFVARZLEVEL
,
vlistdefvarzlevel
,
INT
,
INT
,
INT
)
FCALLSCFUN2
(
INT
,
vlistInqVarZlevel
,
VLISTINQVARZLEVEL
,
vlistinqvarzlevel
,
INT
,
INT
)
FCALLSCSUB3
(
vlistDefVarCode
,
VLISTDEFVARCODE
,
vlistdefvarcode
,
INT
,
INT
,
INT
)
FCALLSCFUN2
(
INT
,
vlistInqVarCode
,
VLISTINQVARCODE
,
vlistinqvarcode
,
INT
,
INT
)
FCALLSCSUB3
(
vlistDefVarDatatype
,
VLISTDEFVARDATATYPE
,
vlistdefvardatatype
,
INT
,
INT
,
INT
)
...
...
src/stream.c
View file @
40cd4b73
...
...
@@ -464,7 +464,7 @@ int streamInqByteorder(int streamID)
char
*
streamFilesuffix
(
int
filetype
)
{
static
char
*
fileSuffix
[]
=
{
""
,
".grb"
,
".g2"
,
".nc"
,
".nc2"
,
".srv"
,
".ext"
,
".h5"
,
".ieg"
};
static
char
*
fileSuffix
[]
=
{
""
,
".grb"
,
".g2"
,
".nc"
,
".nc2"
,
".nc4"
,
".srv"
,
".ext"
,
".h5"
,
".ieg"
};
int
size
=
(
int
)
(
sizeof
(
fileSuffix
)
/
sizeof
(
char
*
));
if
(
filetype
>
0
&&
filetype
<
size
)
...
...
@@ -557,6 +557,7 @@ int cdiInqContents(int streamID)
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
status
=
cdfInqContents
(
streamID
);
break
;
...
...
@@ -649,7 +650,12 @@ int streamOpen(const char *filename, const char *filemode, int filetype)
fileID
=
cdfOpen64
(
filename
,
filemode
);
break
;
}
#endif
case
FILETYPE_NC4
:
{
fileID
=
cdf4Open
(
filename
,
filemode
);
break
;
}
#endif
default:
{
if
(
CDI_Debug
)
Message
(
func
,
"%s support not compiled in!"
,
strfiletype
(
filetype
));
...
...
@@ -754,6 +760,11 @@ int streamOpenA(const char *filename, const char *filemode, int filetype)
fileID
=
cdfOpen64
(
filename
,
"r"
);
break
;
}
case
FILETYPE_NC4
:
{
fileID
=
cdf4Open
(
filename
,
"r"
);
break
;
}
#endif
default:
{
...
...
@@ -820,6 +831,7 @@ int streamOpenA(const char *filename, const char *filemode, int filetype)
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
cdfClose
(
fileID
);
break
;
...
...
@@ -873,6 +885,11 @@ int streamOpenA(const char *filename, const char *filemode, int filetype)
fileID
=
cdfOpen64
(
filename
,
filemode
);
break
;
}
case
FILETYPE_NC4
:
{
fileID
=
cdf4Open
(
filename
,
filemode
);
break
;
}
#endif
default:
{
...
...
@@ -1112,6 +1129,7 @@ void streamClose(int streamID)
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
cdfClose
(
fileID
);
break
;
...
...
@@ -1223,7 +1241,9 @@ int streamDefTimestep(int streamID, int tsID)
streamptr
->
ntsteps
=
tsID
+
1
;
if
(
(
streamptr
->
filetype
==
FILETYPE_NC
||
streamptr
->
filetype
==
FILETYPE_NC2
)
if
(
(
streamptr
->
filetype
==
FILETYPE_NC
||
streamptr
->
filetype
==
FILETYPE_NC2
||
streamptr
->
filetype
==
FILETYPE_NC4
)
&&
vlistHasTime
(
vlistID
)
)
cdfDefTimestep
(
streamID
,
tsID
);
...
...
@@ -1321,6 +1341,7 @@ int streamInqTimestep(int streamID, int tsID)
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
nrecs
=
cdfInqTimestep
(
streamID
,
tsID
);
break
;
...
...
@@ -1409,6 +1430,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
cdfReadVarDP
(
streamID
,
varID
,
data
,
nmiss
);
break
;
...
...
@@ -1489,6 +1511,7 @@ void streamWriteVar(int streamID, int varID, double *data, int nmiss)
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
if
(
streamptr
->
accessmode
==
0
)
cdfEndDef
(
streamID
);
cdfWriteVarDP
(
streamID
,
varID
,
data
,
nmiss
);
...
...
@@ -1569,6 +1592,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
ierr
=
cdfReadVarSliceDP
(
streamID
,
varID
,
levelID
,
data
,
nmiss
);
break
;
...
...
@@ -1649,6 +1673,7 @@ void streamWriteVarSlice(int streamID, int varID, int levelID, double *data, int
#if defined (HAVE_LIBNETCDF)
case
FILETYPE_NC
:
case
FILETYPE_NC2
:
case
FILETYPE_NC4
:
{
if
(
streamptr
->
accessmode
==
0
)
cdfEndDef
(
streamID
);
ierr
=
cdfWriteVarSliceDP
(
streamID
,
varID
,
levelID
,
data
,
nmiss
);
...
...
@@ -1879,7 +1904,9 @@ void streamDefVlist(int streamID, int vlistID)
if
(
streamptr
->
filemode
==
'w'
)
{
if
(
streamptr
->
filetype
==
FILETYPE_NC
||
streamptr
->
filetype
==
FILETYPE_NC2
)
if
(
streamptr
->
filetype
==
FILETYPE_NC
||
streamptr
->
filetype
==
FILETYPE_NC2
||
streamptr
->
filetype
==
FILETYPE_NC4
)
cdfDefVars
(
streamID
);
}
}
...
...
@@ -1922,8 +1949,6 @@ int streamInqVlist(int streamID)
void
streamDefZtype
(
int
streamID
,
int
ztype
)
{
static
char
func
[]
=
"streamDefZtype"
;
int
nvars
,
varID
;
int
gridID
,
zaxisID
;
STREAM
*
streamptr
;
streamptr
=
stream_to_pointer
(
streamID
);
...
...
@@ -1937,8 +1962,6 @@ void streamDefZtype(int streamID, int ztype)
void
streamDefZlevel
(
int
streamID
,
int
zlevel
)
{
static
char
func
[]
=
"streamDefZlevel"
;
int
nvars
,
varID
;
int
gridID
,
zaxisID
;
STREAM
*
streamptr
;
streamptr
=
stream_to_pointer
(
streamID
);
...
...
src/stream_cdf.c
View file @
40cd4b73
...
...
@@ -515,6 +515,42 @@ void cdfReadGridTraj(int streamID, int gridID)
}
#if defined (HAVE_LIBNETCDF)
void
cdfDefVarDeflate
(
int
ncid
,
int
ncvarid
,
int
deflate_level
)
{
static
char
func
[]
=
"cdfDefVarDeflate"
;
#if defined (NC_NETCDF4)
int
retval
;
/* Set chunking, shuffle, and deflate. */
int
shuffle
=
1
;
int
deflate
=
1
;
if
(
deflate_level
<
1
||
deflate_level
>
9
)
deflate_level
=
1
;
/*
if ((retval = nc_def_var_chunking(fileID, ncvarid, 0, &chunks[0])))
{
fprintf(stderr, "nc_def_var_chunking status = %d\n", retval);
exit(-1);
}
*/
if
((
retval
=
nc_def_var_deflate
(
ncid
,
ncvarid
,
shuffle
,
deflate
,
deflate_level
)))
{
Error
(
func
,
"nc_def_var_deflate failed, status = %d
\n
"
,
retval
);
}
#else
static
int
lwarn
=
TRUE
;
if
(
lwarn
)
{
lwarn
=
FALSE
;
Warning
(
func
,
"Compression failed, netCDF4 not available!"
);
}
#endif
}
#endif
void
cdfDefMissval
(
int
streamID
,
int
varID
,
int
dtype
)
{
#if defined (HAVE_LIBNETCDF)
...
...
@@ -2212,6 +2248,22 @@ int cdfDefVar(int streamID, int varID)
cdf_def_var
(
fileID
,
name
,
(
nc_type
)
xtype
,
ndims
,
dims
,
&
ncvarid
);
if
(
streamptr
->
ztype
==
COMPRESS_ZIP
)
{
if
(
streamptr
->
filetype
==
FILETYPE_NC4
)
cdfDefVarDeflate
(
fileID
,
ncvarid
,
streamptr
->
zlevel
);
else
{
static
int
lwarn
=
TRUE
;
if
(
lwarn
)
{
lwarn
=
FALSE
;
Warning
(
func
,
"Compression is only available for netCDF4!"
);
}
}
}
if
(
longname
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"long_name"
,
strlen
(
longname
),
longname
);
...
...
src/stream_grb.c