From de36c84f3f47b95eb858f2e62bd82a75f857abf5 Mon Sep 17 00:00:00 2001 From: Thomas Jahns <jahns@dkrz.de> Date: Tue, 2 Apr 2013 11:17:55 +0000 Subject: [PATCH] Merge of trunk into branch cdi-pio. --- .gitattributes | 7 +- ChangeLog | 189 +++ Makefile.am | 2 +- Makefile.in | 2 +- NEWS | 42 + README | 12 + aclocal.m4 | 16 +- app/cdi.c | 201 +-- app/createtable.c | 6 +- app/printinfo.h | 54 +- config/default | 19 +- config/ltmain.sh | 98 +- configure | 497 +++---- configure.ac | 8 +- doc/Doxyfile | 1514 +++++++++++++++++++ doc/tex/c_quick_ref.tex | 36 + doc/tex/c_stream.tex | 2 +- doc/tex/c_vlist_att.tex | 2 +- doc/tex/c_zaxis.tex | 6 + doc/tex/cdi_cman.tex | 2 +- doc/tex/cdi_fman.tex | 2 +- doc/tex/f_quick_ref.tex | 40 +- doc/tex/f_stream.tex | 2 +- doc/tex/f_vlist_att.tex | 2 +- doc/tex/f_zaxis.tex | 6 + doc/tex/formats.tex | 29 +- doc/tex/zaxis.tex | 10 +- examples/Makefile.am | 10 +- examples/Makefile.in | 18 +- examples/cdi_write_reset.c | 109 ++ examples/pio/Makefile.am | 7 +- examples/pio/Makefile.in | 2 +- examples/pio/collectDataNStreams.c | 4 +- m4/acx_options.m4 | 10 +- m4/ltversion.m4 | 10 +- src/Makefile.am | 7 +- src/Makefile.in | 7 +- src/cdf_int.c | 226 ++- src/cdi.h | 52 +- src/cdi.inc | 110 +- src/cdiFortran.c | 30 +- src/cdi_error.c | 1 + src/cgribex.h | 7 +- src/cgribexlib.c | 2156 +++++++++++++++++----------- src/config.h.in | 14 +- src/extralib.c | 8 +- src/file.c | 23 +- src/getline.c | 89 ++ src/gribapi.c | 73 +- src/gribapi.h | 7 +- src/grid.c | 158 +- src/grid.h | 4 +- src/ieglib.c | 44 +- src/institution.c | 23 +- src/make_cdilib | 60 +- src/make_fint.c | 10 +- src/model.c | 23 +- src/pio_dbuffer.c | 6 +- src/pio_util.c | 31 +- src/pio_util.h | 6 +- src/resource_handle.c | 36 +- src/resource_handle.h | 3 +- src/servicelib.c | 8 +- src/stream.c | 172 ++- src/stream_cdf.c | 1502 ++++++++++--------- src/stream_cdf.h | 34 +- src/stream_cgribex.c | 332 ++--- src/stream_cgribex.h | 6 +- src/stream_ext.c | 214 +-- src/stream_ext.h | 22 +- src/stream_grb.c | 193 +-- src/stream_grb.h | 22 +- src/stream_gribapi.c | 1177 ++++++++------- src/stream_gribapi.h | 6 +- src/stream_history.c | 6 +- src/stream_ieg.c | 203 +-- src/stream_ieg.h | 22 +- src/stream_int.c | 80 +- src/stream_int.h | 131 +- src/stream_record.c | 90 +- src/stream_srv.c | 207 +-- src/stream_srv.h | 22 +- src/stream_var.c | 30 +- src/table.h | 359 +++-- src/taxis.c | 103 +- src/taxis.h | 2 + src/timebase.c | 70 +- src/timebase.h | 15 +- src/tsteps.c | 33 +- src/util.c | 61 +- src/varscan.c | 127 +- src/varscan.h | 3 +- src/vlist.c | 205 ++- src/vlist.h | 20 + src/vlist_var.c | 197 ++- src/vlist_var.h | 2 + src/zaxis.c | 25 +- src/zaxis.h | 6 + tables/echam6 | 355 +++-- tables/echam6cmip5 | 170 +++ tests/Makefile.am | 2 +- tests/Makefile.in | 2 +- write_tornado.job | 35 - 103 files changed, 7927 insertions(+), 4534 deletions(-) mode change 100755 => 100644 config/ltmain.sh create mode 100644 doc/Doxyfile create mode 100644 examples/cdi_write_reset.c create mode 100644 src/getline.c create mode 100644 src/zaxis.h create mode 100644 tables/echam6cmip5 delete mode 100755 write_tornado.job diff --git a/.gitattributes b/.gitattributes index 3e523bbd4..dd9210965 100644 --- a/.gitattributes +++ b/.gitattributes @@ -28,6 +28,7 @@ config/missing -text config/mkinstalldirs -text /configure -text /configure.ac -text +doc/Doxyfile -text doc/cdi_cman.pdf -text doc/cdi_fman.pdf -text doc/coding_standards/README -text @@ -114,6 +115,7 @@ examples/cdi_write.c -text examples/cdi_write_ens.c -text examples/cdi_write_f.f -text examples/cdi_write_f2003.f90 -text +examples/cdi_write_reset.c -text examples/compf -text examples/pio/Makefile.am -text examples/pio/Makefile.in -text @@ -181,6 +183,7 @@ src/cdiFortran.c -text src/cdi_error.c -text src/cdi_limits.h -text src/cdi_util.c -text +src/cdilib.c -text src/cfortran.doc -text src/cfortran.h -text src/cgribex.h -text @@ -199,6 +202,7 @@ src/file.c -text src/file.h -text src/gaussgrid.c -text src/gaussgrid.h -text +src/getline.c -text src/gribapi.c -text src/gribapi.h -text src/grid.c -text @@ -282,6 +286,7 @@ src/vlist_att.h -text src/vlist_var.c -text src/vlist_var.h -text src/zaxis.c -text +src/zaxis.h -text tables/cosmo002 -text tables/cosmo201 -text tables/cosmo202 -text @@ -292,6 +297,7 @@ tables/default_tables -text tables/echam4 -text tables/echam5 -text tables/echam6 -text +tables/echam6cmip5 -text tables/ecmwf -text tables/gen_tableheaderfile -text tables/grib_api/grib2/4.5.78.150.table -text @@ -333,4 +339,3 @@ util/serialrun.in -text util/sunf95preproc-wrapper -text util/sxpreproc-wrapper -text util/xlfpreproc-wrapper -text -/write_tornado.job -text diff --git a/ChangeLog b/ChangeLog index 8075da991..c64a7e062 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,192 @@ +2013-03-14 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * Version 1.6.0 released + * using CGRIBEX library version 1.6.0 + +2013-03-13 Florian Prill <Florian.Prill@dwd.de> + + * Read arbitrary GRIB keys [Feature #3267] + +2013-03-13 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * GRIB: added support for time step unit: seconds [Bug #3352] + +2013-03-12 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * Added support for level type CLOUD_BASE, CLOUD_TOP and ISOTHERM_ZERO [Feature #3247] + * stream_gribapi: changed units for level type GRIB2_LTYPE_LANDDEPTH to m (internally mm) [Bug #3287] + * gribapiGetGrid: get gridDescriptionFile with grib_get_string() instead of grib_get_bytes() (bug fix) + +2013-03-11 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * stream_gribapi: added support for local table shortName.def [Bug #3343] + +2013-03-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * vtime2timeval: check validity of month + +2013-03-07 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * cdfDefGrid: bug fix for generic grids with nx or ny > 0 + * netCDF: ignore the attribute valid_min/valid_max, if the data type is inconsistent + +2013-02-18 Florian Prill <Florian.Prill@dwd.de> + + * Added function vlistDefVarIntKey() and vlistDefVarDblKey() to set GRIB_API Key/Value pairs + +2013-02-13 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * cgribexGetTsteptype: changed default to TSTEP_INSTANT [Bug #3211] + +2013-02-04 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * netCDF: ignore the attribute valid_range, if the data type is inconsistent + * netCDF: added env IGNORE_VALID_RANGE to ignore the attribute valid_range + +2013-01-31 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * stream_cgribex::cgribexGetGrid: add 360 to lastLon, if lastlon <firstLon [Bug #3189] + +2013-01-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * netCDF: check position of time dimension + +2013-01-15 Thomas Jahns <jahns@dkrz.de> + + * make_fint.c: added regexec support + +2013-01-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * global netCDF attribute "source" missing (bug fix) + +2012-12-18 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * reshGetValue: added caller function name to error message + +2012-12-17 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * Version 1.5.9 released + * using CGRIBEX library version 1.5.6 + +2012-12-13 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * removed unused function streamDefineTaxis() + * fix warning in streamDefTimestep() for stream with constant fields only + +2012-12-11 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * added cdfGridCompress() to compress coordinates + * added vlistDefVarChunkType() and vlistInqVarChunkType() + +2012-12-03 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * vlistCopyFlag: added support for level bounds + +2012-11-26 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * netCDF: added support for time axis name and long_name + +2012-11-17 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * stream_cdf::define_all_vars: added txt attributes to vlistDefAttTxt() without trailing 0 [Bug #3004] + +2012-11-16 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * file.c: added support for unbuffered write + +2012-11-15 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * cdfReadVarSliceDP: store DATATYPE_FLT32 in a float array and convert it to double (speedup 2x) + * cdfInqTimestep: added check for timevalue = NC_FILL_DOUBLE + +2012-11-14 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * app/cdi: added optional compression level -z zip[_1-9] + +2012-11-09 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * file.c::file_initialize: added support for env GRIB_API_IO_BUFFER_SIZE [request: Florian Prill] + +2012-11-07 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * gridGenXvals/gridGenYvals: removed changes from 1.5.8 (bug fix) + * cgribexGetGrid: bug fix for xinc/yinc recomputation + +2012-11-05 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * grib2: correct endStep if timeunits is not equal stepUnits (bug fix) + * cgribexGetGrid: bug fix for yinc for odd ysize + +2012-10-30 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * Version 1.5.8 released + * using CGRIBEX library version 1.5.5 + +2012-10-29 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * stream_cgribex.c: do not check fraction of xinc/yinc" stream_cgribex.c + * gridGenXvals/gridGenYvals: recheck xinc/yinc if (first+(size-1)*inc) > last + +2012-10-26 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * stream_gribapi.c::gribapiScanTimestep: changed GRIBAPI_MISSVAL to cdiDefaultMissval + +2012-10-18 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * vlistCopyFlag: copy ensdata (bug fix) [report: Jaison Ambadan] + +2012-10-16 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * grib2: changed packingType from grid_jpeg to grid_simple if nmiss > 0 (bug fix) + +2012-10-18 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * grib2: added stepType support for absolute time axis + +2012-10-15 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * pio.h remove line 'typedef int MPI_Comm;' [Bug #2882] + +2012-09-21 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * vlistInqZaxis: use zaxisGetIndexList() to get global zaxisIDs (bug fix) + +2012-09-20 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * listSizeExtend: init ops, val and status + +2012-09-20 Thomas Jahns <jahns@dkrz.de> + + * listInitialize: set mutex type to PTHREAD_MUTEX_RECURSIVE + +2012-09-11 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * cdfInqContents: make ncid local to varid + * cdfInqContents: group reading of global attribute to read_global_attributtes() + * cdfInqContents: set ntsteps to 0 if no data variable found + * netCDF: set 1D arrays to coordinate variables if axis attribute is available + +2012-09-10 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * unreduced: compute nlon and nvalues from rowlon[] (bug fix) + +2012-09-05 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * cgribexEncode: initialize the first 256 entries of isec1 to zero + +2012-08-30 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * app/cdi: changed output format of option -s (sinfo) + +2012-08-27 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> + + * Version 1.5.7 released + * model.c::modelInq*: check instID != UNDEFID (buf fix) + * institution.c::insitutInq*: check instID != UNDEFID (buf fix) + * Merge of branch cdo-pio into trunk cdi + * using CGRIBEX library version 1.5.4 + * using EXSE library version 1.3.1 + 2012-07-23 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> * Version 1.5.6 released diff --git a/Makefile.am b/Makefile.am index 6a1e6ecb0..b9848a796 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in # -SUBDIRS = src interfaces app examples tests examples/pio +SUBDIRS = src interfaces app examples examples/pio tests # EXTRA_DIST=config/default \ doc/cdi_cman.pdf \ diff --git a/Makefile.in b/Makefile.in index c32265929..46e5528b7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -328,7 +328,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ # -SUBDIRS = src interfaces app examples tests examples/pio +SUBDIRS = src interfaces app examples examples/pio tests # EXTRA_DIST = config/default \ doc/cdi_cman.pdf \ diff --git a/NEWS b/NEWS index abb664f9e..ae614eb7b 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,48 @@ CDI NEWS -------- +Version 1.6.0 (14 March 2013): + + New features: + * Added support for level type CLOUD_BASE, CLOUD_TOP and ISOTHERM_ZERO [Feature #3247] + * Read arbitrary GRIB keys [Feature #3267] + New functions: + * vlistDefVarIntKey(): Set an arbitrary keyword/integer value pair for GRIB API + * vlistDefVarDblKey(): Set an arbitrary keyword/double value pair for GRIB API + Fixed bugs: + * GRIB: added support for time step unit: seconds [Bug #3352] + * stream_gribapi: added support for local table shortName.def [Bug #3343] + * stream_gribapi: changed units for level type GRIB2_LTYPE_LANDDEPTH to m (internally mm) [Bug #3287] + * netCDF: ignore the attribute valid_range, if the data type is inconsistent + * global netCDF attribute "source" missing + * cgribexGetTsteptype: changed default to TSTEP_INSTANT [Bug #3211] + +Version 1.5.9 (17 December 2012): + + New features: + * file.c::file_initialize: added support for env GRIB_API_IO_BUFFER_SIZE + New functions: + * vlistDefVarChunktype(): set chunktype to CHUNK_AUTO, CHUNK_GRID, CHUNK_LINES + * vlistInqVarChunktype(): returns the chunktype + Fixed bugs: + * vlistCopyFlag: added support for level bounds + * netCDF: added support for time axis name and long_name + * cgribexGetGrid: bug fix for xinc/yinc recomputation + * stream_cdf::define_all_vars: added txt attributes to vlistDefAttTxt() without trailing 0 [Bug #3004] + +Version 1.5.8 (30 October 2012): + + New features: + * grib2: added stepType support for absolute time axis + * netCDF: set 1D arrays to coordinate variables if axis attribute is available + Fixed bugs: + * grib2: changed packingType from grid_jpeg to grid_simple if nmiss > 0 + +Version 1.5.7 (27 August 2012): + + New features: + * Merge of branch cdo-pio into trunk cdi + Version 1.5.6 (27 July 2012): New features: diff --git a/README b/README index 9ae93736a..de23134f8 100644 --- a/README +++ b/README @@ -10,6 +10,18 @@ CDI - Climate Data Interface CDI is licensed under the GNU General Public License, version 2. Read the file COPYING in the source distribution for details. + MPI-M makes no representations or warranties of any kind concerning the Software and any results + (including but not limited to any data) generated by use of the Software (hereinafter "Results"), + express or implied, and the absence of any legal or actual defects, whether discoverable or not. + The use of the Software and the Results is at your own risk. + + Specifically, and not to limit the foregoing, MPI-M makes no representations or warranties + (i) regarding the fitness for a particular purpose of the Software and the Results, + (ii) that the use of the Software and the Results will not infringe any patents or other + intellectual property rights of any third party, and + (iii) that the use of the Software and the Results will not cause any damages of any kind + to you or to any third party. + Documentation: CDI C Manual: ./doc/cdi_cman.pdf diff --git a/aclocal.m4 b/aclocal.m4 index 21e4db823..5c27e11ef 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -14,8 +14,8 @@ m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, -[m4_warning([this file was generated for autoconf 2.69. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],, +[m4_warning([this file was generated for autoconf 2.68. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.])]) @@ -574,18 +574,6 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) ]) -# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 -# Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# serial 8 - -# AM_CONFIG_HEADER is obsolete. It has been replaced by AC_CONFIG_HEADERS. -AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)]) - # Do all the work for Automake. -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, diff --git a/app/cdi.c b/app/cdi.c index 2be9e2566..92138b02e 100644 --- a/app/cdi.c +++ b/app/cdi.c @@ -56,7 +56,7 @@ int complevel = 0; // Compression level static void version(void) { - fprintf(stderr, "CDI version 1.7.1\n"); + fprintf(stderr, "CDI version 1.8\n"); #if defined (COMPILER) fprintf(stderr, "Compiler: %s\n", COMPILER); #endif @@ -111,13 +111,14 @@ void version(void) 1.4.2 22 Mar 2005 : change level from int to double 1.4.3 11 Apr 2005 : change date and time format to ISO 1.5.0 22 Nov 2005 : IEG support - 1.5.1 21 Feb 2006 : add option -s for short info - 1.6.0 1 Aug 2006 : add option -z szip for SZIP compression of GRIB records + 1.5.1 21 Feb 2006 : added option -s for short info + 1.6.0 1 Aug 2006 : added option -z szip for SZIP compression of GRIB records 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 - 1.7.1 1 Nov 2009 : add option -z jpeg for JPEG compression of GRIB2 records + 1.7.0 11 Apr 2008 : added option -z zip for deflate compression of netCDF4 variables + 1.7.1 1 Nov 2009 : added option -z jpeg for JPEG compression of GRIB2 records + 1.7.2 14 Nov 2012 : added optional compression level -z zip[_1-9] */ } @@ -144,7 +145,7 @@ void usage(void) fprintf(stderr, " -V Print version number\n"); fprintf(stderr, " -z szip SZIP compression of GRIB1 records\n"); fprintf(stderr, " jpeg JPEG compression of GRIB2 records\n"); - fprintf(stderr, " zip Deflate compression of netCDF4 variables\n"); + fprintf(stderr, " zip[_1-9] Deflate compression of netCDF4 variables\n"); fprintf(stderr, "\n"); fprintf(stderr, " Report bugs to <http://code.zmaw.de/projects/cdi>\n"); } @@ -158,25 +159,25 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level, int i, ivals = 0, imiss = 0; double arrmean, arrmin, arrmax; char vdatestr[32], vtimestr[32]; - + if ( ! rec ) { if ( vardis ) - fprintf(stdout, - " Rec : Date Time Varname Level Size Miss : Minimum Mean Maximum\n"); + fprintf(stdout, + " Rec : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name\n"); /* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+ */ else - fprintf(stdout, - " Rec : Date Time Param Level Size Miss : Minimum Mean Maximum\n"); + fprintf(stdout, + " Rec : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter ID\n"); /* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+ */ } date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); - fprintf(stdout, "%6d :%s %s %-10s %7g ", ++rec, vdatestr, vtimestr, varname, level); + fprintf(stdout, "%6d :%s %s %7g ", ++rec, vdatestr, vtimestr, level); - fprintf(stdout, "%7d ", datasize); + fprintf(stdout, "%8d ", datasize); fprintf(stdout, "%7d :", nmiss); @@ -222,7 +223,7 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level, if ( datasize > 0 ) arrmean /= datasize; - fprintf(stdout, "%#12.5g%#12.5g%#12.5g\n", arrmin, arrmean, arrmax); + fprintf(stdout, "%#12.5g%#12.5g%#12.5g", arrmin, arrmean, arrmax); } else { @@ -249,15 +250,42 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level, if ( nvals_r > 0 ) arrmean_r = arrsum_r / nvals_r; if ( nvals_i > 0 ) arrmean_i = arrsum_i / nvals_i; - fprintf(stdout, " - (%#12.5g,%#12.5g) -\n", arrmean_r, arrmean_i); + fprintf(stdout, " - (%#12.5g,%#12.5g) -", arrmean_r, arrmean_i); } + fprintf(stdout, " : %-11s\n", varname); + if ( imiss != nmiss && nmiss > 0 ) fprintf(stdout, "Found %d of %d missing values!\n", imiss, nmiss); } #define MAXCHARS 82 +const char * tunit2str(int tunits) +{ + if ( tunits == TUNIT_YEAR ) return ("years"); + else if ( tunits == TUNIT_MONTH ) return ("months"); + else if ( tunits == TUNIT_DAY ) return ("days"); + else if ( tunits == TUNIT_12HOURS ) return ("12hours"); + else if ( tunits == TUNIT_6HOURS ) return ("6hours"); + else if ( tunits == TUNIT_3HOURS ) return ("3hours"); + else if ( tunits == TUNIT_HOUR ) return ("hours"); + else if ( tunits == TUNIT_MINUTE ) return ("minutes"); + else if ( tunits == TUNIT_SECOND ) return ("seconds"); + else return ("unknown"); +} + + +const char * calendar2str(int calendar) +{ + if ( calendar == CALENDAR_STANDARD ) return ("standard"); + else if ( calendar == CALENDAR_PROLEPTIC ) return ("proleptic_gregorian"); + else if ( calendar == CALENDAR_360DAYS ) return ("360_day"); + else if ( calendar == CALENDAR_365DAYS ) return ("365_day"); + else if ( calendar == CALENDAR_366DAYS ) return ("366_day"); + else return ("unknown"); +} + static void printShortinfo(int streamID, int vlistID, int vardis) { @@ -287,10 +315,10 @@ void printShortinfo(int streamID, int vlistID, int vardis) if ( vardis ) fprintf(stdout, - " Var : Institut Source Varname Ttype Dtype Gridsize Num Levels Num\n"); + " Var : Institut Source Ttype Levels Num Gridsize Num Dtype : Parameter name\n"); else fprintf(stdout, - " Var : Institut Source Param Ttype Dtype Gridsize Num Levels Num\n"); + " Var : Institut Source Ttype Levels Num Gridsize Num Dtype : Parameter ID\n"); nvars = vlistNvars(vlistID); @@ -300,41 +328,45 @@ void printShortinfo(int streamID, int vlistID, int vardis) gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); - cdiParamToString(param, paramstr, sizeof(paramstr)); - - if ( vardis ) vlistInqVarName(vlistID, varID, varname); - - gridsize = gridInqSize(gridID); - fprintf(stdout, "%6d : ", varID + 1); + /* institute info */ instptr = institutInqNamePtr(vlistInqVarInstitut(vlistID, varID)); if ( instptr ) fprintf(stdout, "%-8s ", instptr); else fprintf(stdout, "unknown "); + /* source info */ modelptr = modelInqNamePtr(vlistInqVarModel(vlistID, varID)); if ( modelptr ) fprintf(stdout, "%-8s ", modelptr); else fprintf(stdout, "unknown "); - if ( vardis ) - fprintf(stdout, "%-11s ", varname); - else - fprintf(stdout, "%-11s ", paramstr); - + /* tsteptype */ tsteptype = vlistInqVarTsteptype(vlistID, varID); - if ( tsteptype == TSTEP_CONSTANT ) fprintf(stdout, "%-8s", "constant"); - else if ( tsteptype == TSTEP_INSTANT ) fprintf(stdout, "%-8s", "instant"); - else if ( tsteptype == TSTEP_MIN ) fprintf(stdout, "%-8s", "min"); - else if ( tsteptype == TSTEP_MAX ) fprintf(stdout, "%-8s", "max"); - else if ( tsteptype == TSTEP_ACCUM ) fprintf(stdout, "%-8s", "accum"); - else fprintf(stdout, "%-8s", "unknown"); + if ( tsteptype == TSTEP_CONSTANT ) fprintf(stdout, "%-8s ", "constant"); + else if ( tsteptype == TSTEP_INSTANT ) fprintf(stdout, "%-8s ", "instant"); + else if ( tsteptype == TSTEP_INSTANT2 ) fprintf(stdout, "%-8s ", "instant"); + else if ( tsteptype == TSTEP_INSTANT3 ) fprintf(stdout, "%-8s ", "instant"); + else if ( tsteptype == TSTEP_MIN ) fprintf(stdout, "%-8s ", "min"); + else if ( tsteptype == TSTEP_MAX ) fprintf(stdout, "%-8s ", "max"); + else if ( tsteptype == TSTEP_ACCUM ) fprintf(stdout, "%-8s ", "accum"); + else fprintf(stdout, "%-8s ", "unknown"); + + /* layer info */ + levelsize = zaxisInqSize(zaxisID); + fprintf(stdout, "%6d ", levelsize); + fprintf(stdout, "%3d ", vlistZaxisIndex(vlistID, zaxisID) + 1); - datatype = vlistInqVarDatatype(vlistID, varID); + /* grid info */ + gridsize = gridInqSize(gridID); + fprintf(stdout, "%9d ", gridsize); + fprintf(stdout, "%3d ", vlistGridIndex(vlistID, gridID) + 1); + /* datatype */ + datatype = vlistInqVarDatatype(vlistID, varID); if ( datatype == DATATYPE_PACK ) strcpy(pstr, "P0"); else if ( datatype > 0 && datatype <= 32 ) sprintf(pstr, "P%d", datatype); else if ( datatype == DATATYPE_CPX32 ) strcpy(pstr, "C32"); @@ -352,26 +384,30 @@ void printShortinfo(int streamID, int vlistID, int vardis) fprintf(stdout, " %-3s", pstr); if ( vlistInqVarCompType(vlistID, varID) == COMPRESS_NONE ) - fprintf(stdout, " "); + fprintf(stdout, " "); else - fprintf(stdout, "z"); + fprintf(stdout, "z "); - fprintf(stdout, "%9d", gridsize); + /* parameter info */ + fprintf(stdout, ": "); - fprintf(stdout, " %3d ", vlistGridIndex(vlistID, gridID) + 1); + cdiParamToString(param, paramstr, sizeof(paramstr)); - levelsize = zaxisInqSize(zaxisID); - fprintf(stdout, " %6d", levelsize); - fprintf(stdout, " %3d", vlistZaxisIndex(vlistID, zaxisID) + 1); + if ( vardis ) vlistInqVarName(vlistID, varID, varname); + + if ( vardis ) + fprintf(stdout, "%-11s", varname); + else + fprintf(stdout, "%-11s", paramstr); fprintf(stdout, "\n"); } - fprintf(stdout, " Horizontal grids :\n"); + fprintf(stdout, " Grid coordinates :\n"); printGridInfo(vlistID); nzaxis = vlistNzaxis(vlistID); - fprintf(stdout, " Vertical grids :\n"); + fprintf(stdout, " Vertical coordinates :\n"); for ( index = 0; index < nzaxis; index++) { zaxisID = vlistZaxis(vlistID, index); @@ -427,16 +463,16 @@ void printShortinfo(int streamID, int vlistID, int vardis) if ( ntsteps != 0 ) { if ( ntsteps == CDI_UNDEFID ) - fprintf(stdout, " Time axis : unlimited steps\n"); + fprintf(stdout, " Time coordinate : unlimited steps\n"); else - fprintf(stdout, " Time axis : %d step%s\n", ntsteps, ntsteps == 1 ? "" : "s"); + fprintf(stdout, " Time coordinate : %d step%s\n", ntsteps, ntsteps == 1 ? "" : "s"); if ( taxisID != CDI_UNDEFID ) { - int calendar, tunits; - if ( taxisInqType(taxisID) == TAXIS_RELATIVE ) { + int calendar, tunits; + vdate = taxisInqRdate(taxisID); vtime = taxisInqRtime(taxisID); @@ -447,46 +483,10 @@ void printShortinfo(int streamID, int vlistID, int vardis) year, month, day, hour, minute, second); tunits = taxisInqTunit(taxisID); - if ( tunits != CDI_UNDEFID ) - { - if ( tunits == TUNIT_YEAR ) - fprintf(stdout, " Units = years"); - else if ( tunits == TUNIT_MONTH ) - fprintf(stdout, " Units = months"); - else if ( tunits == TUNIT_DAY ) - fprintf(stdout, " Units = days"); - else if ( tunits == TUNIT_12HOURS ) - fprintf(stdout, " Units = 12hours"); - else if ( tunits == TUNIT_6HOURS ) - fprintf(stdout, " Units = 6hours"); - else if ( tunits == TUNIT_3HOURS ) - fprintf(stdout, " Units = 3hours"); - else if ( tunits == TUNIT_HOUR ) - fprintf(stdout, " Units = hours"); - else if ( tunits == TUNIT_MINUTE ) - fprintf(stdout, " Units = minutes"); - else if ( tunits == TUNIT_SECOND ) - fprintf(stdout, " Units = seconds"); - else - fprintf(stdout, " Units = unknown"); - } + if ( tunits != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(tunits)); calendar = taxisInqCalendar(taxisID); - if ( calendar != CDI_UNDEFID ) - { - if ( calendar == CALENDAR_STANDARD ) - fprintf(stdout, " Calendar = STANDARD"); - else if ( calendar == CALENDAR_PROLEPTIC ) - fprintf(stdout, " Calendar = PROLEPTIC"); - else if ( calendar == CALENDAR_360DAYS ) - fprintf(stdout, " Calendar = 360DAYS"); - else if ( calendar == CALENDAR_365DAYS ) - fprintf(stdout, " Calendar = 365DAYS"); - else if ( calendar == CALENDAR_366DAYS ) - fprintf(stdout, " Calendar = 366DAYS"); - else - fprintf(stdout, " Calendar = unknown"); - } + if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar)); if ( taxisHasBounds(taxisID) ) fprintf(stdout, " Bounds = true"); @@ -729,10 +729,13 @@ void defineCompress(const char *arg) comptype = COMPRESS_GZIP; complevel = 6; } - else if ( strncmp(arg, "zip", len) == 0 ) + else if ( strncmp(arg, "zip", 3) == 0 ) { comptype = COMPRESS_ZIP; - complevel = 1; + if ( len == 5 && arg[3] == '_' && isdigit(arg[4]) ) + complevel = atoi(&arg[4]); + else + complevel = 1; } else fprintf(stderr, "%s compression unsupported!\n", arg); @@ -862,7 +865,7 @@ int main(int argc, char *argv[]) int recID; int tsID; int ntsteps = 0; - int taxisID; + int taxisID1, taxisID2 = CDI_UNDEFID; int gridtype; int vlistID1, vlistID2 = CDI_UNDEFID; @@ -883,13 +886,18 @@ int main(int argc, char *argv[]) } nvars = vlistNvars(vlistID1); - taxisID = vlistInqTaxis(vlistID1); + taxisID1 = vlistInqTaxis(vlistID1); ntsteps = vlistNtsteps(vlistID1); if ( Debug ) fprintf(stderr, "nvars = %d\n", nvars); if ( Debug ) fprintf(stderr, "ntsteps = %d\n", ntsteps); - if ( fname2 ) vlistID2 = vlistDuplicate(vlistID1); + if ( fname2 ) + { + vlistID2 = vlistDuplicate(vlistID1); + taxisID2 = taxisDuplicate(taxisID1); + vlistDefTaxis(vlistID2, taxisID2); + } for ( varID = 0; varID < nvars; varID++) { @@ -952,10 +960,12 @@ int main(int argc, char *argv[]) while ( (nrecs = streamInqTimestep(streamID1, tsID)) > 0 ) { if ( fname2 /* && ntsteps != 0*/ ) - streamDefTimestep(streamID2, tsID); - - vdate = taxisInqVdate(taxisID); - vtime = taxisInqVtime(taxisID); + { + taxisCopyTimestep(taxisID2, taxisID1); + streamDefTimestep(streamID2, tsID); + } + vdate = taxisInqVdate(taxisID1); + vtime = taxisInqVtime(taxisID1); if ( Debug ) fprintf(stdout, "tsID = %d nrecs = %d date = %d time = %d\n", tsID, nrecs, vdate, vtime); @@ -1047,6 +1057,7 @@ int main(int argc, char *argv[]) { streamClose(streamID2); vlistDestroy(vlistID2); + taxisDestroy(taxisID2); } streamClose(streamID1); } diff --git a/app/createtable.c b/app/createtable.c index f7e209069..e3a829c48 100644 --- a/app/createtable.c +++ b/app/createtable.c @@ -44,22 +44,22 @@ int main(int argc, char *argv[]) if ( !strncmp(cstring, "debug", len) ) { debug = 1; - break; } + break; case 'h': if ( !strncmp(cstring, "help", len) ) { usage( ); return( 0 ); - break; } + break; case 'v': if ( !strncmp(cstring, "version", len) ) { version(); return (0); - break; } + break; default: usage(); fprintf(stderr, "illegal option %s\n", cstring); diff --git a/app/printinfo.h b/app/printinfo.h index ed53588c4..c7ab8e73b 100644 --- a/app/printinfo.h +++ b/app/printinfo.h @@ -1,6 +1,8 @@ #define DATE_FORMAT "%5.4d-%2.2d-%2.2d" #define TIME_FORMAT "%2.2d:%2.2d:%2.2d" +void uuid2str(const char *uuid, char *uuidstr); + void date2str(int date, char *datestr, int maxlen) { int year, month, day; @@ -66,6 +68,7 @@ void printFiletype(int streamID, int vlistID) break; default: printf(" File format: unsupported filetype %d" , filetype); + break; } if ( filetype == FILETYPE_SRV || filetype == FILETYPE_EXT || filetype == FILETYPE_IEG ) @@ -133,6 +136,7 @@ void printGridInfo(int vlistID) int gridID, gridtype, trunc, gridsize, xsize, ysize; int nbyte0; char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME]; + char uuidOfHGrid[17]; ngrids = vlistNgrids(vlistID); for ( index = 0; index < ngrids; index++ ) @@ -154,9 +158,11 @@ void printGridInfo(int vlistID) gridtype == GRID_LCC2 || gridtype == GRID_LAEA || gridtype == GRID_SINUSOIDAL || + gridtype == GRID_GENERIC || gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) { + int lxcoord = 1, lycoord = 1; double xfirst = 0.0, xlast = 0.0; double yfirst = 0.0, ylast = 0.0; double xinc = 0.0, yinc = 0.0; @@ -168,14 +174,17 @@ void printGridInfo(int vlistID) if ( gridtype == GRID_GAUSSIAN_REDUCED ) fprintf(stdout, "size : dim = %d nlat = %d", gridsize, ysize); else - fprintf(stdout, "size : dim = %d nlon = %d nlat = %d", gridsize, xsize, ysize); - + fprintf(stdout, "size : dim = %d nx = %d ny = %d", gridsize, xsize, ysize); + if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) fprintf(stdout, " np = %d", gridInqNP(gridID)); fprintf(stdout, "\n"); - if ( xsize > 0 ) + if ( gridInqXvals(gridID, NULL) == 0 ) lxcoord = 0; + if ( gridInqYvals(gridID, NULL) == 0 ) lycoord = 0; + + if ( xsize > 0 && lxcoord ) { if ( gridtype == GRID_GAUSSIAN_REDUCED ) { @@ -194,19 +203,18 @@ void printGridInfo(int vlistID) if ( IS_NOT_EQUAL(xinc, 0) ) fprintf(stdout, " inc = %.9g", xinc); fprintf(stdout, " %s", xunits); - if ( gridIsCircular(gridID) ) - fprintf(stdout, " circular"); + if ( gridIsCircular(gridID) ) fprintf(stdout, " circular"); fprintf(stdout, "\n"); } } - if ( ysize > 0 ) + if ( ysize > 0 && lycoord ) { fprintf(stdout, "%*s", nbyte0, ""); fprintf(stdout, "%-9s : first = %.9g", yname, yfirst); if ( ysize > 1 ) fprintf(stdout, " last = %.9g", ylast); - if ( IS_NOT_EQUAL(yinc, 0) && - (gridtype == GRID_LONLAT || gridtype == GRID_SINUSOIDAL || + if ( IS_NOT_EQUAL(yinc, 0) && + (gridtype == GRID_LONLAT || gridtype == GRID_SINUSOIDAL || gridtype == GRID_LCC2 || gridtype == GRID_LAEA) ) fprintf(stdout, " inc = %.9g", yinc); fprintf(stdout, " %s", yunits); @@ -231,6 +239,7 @@ void printGridInfo(int vlistID) fprintf(stdout, "available :"); if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds"); if ( gridInqYbounds(gridID, NULL) ) fprintf(stdout, " ybounds"); + if ( gridHasArea(gridID) ) fprintf(stdout, " area"); if ( gridInqMask(gridID, NULL) ) fprintf(stdout, " mask"); fprintf(stdout, "\n"); } @@ -317,12 +326,11 @@ void printGridInfo(int vlistID) fprintf(stdout, "%*s", nbyte0, ""); fprintf(stdout, "%-9s : min = %.9g max = %.9g %s", xname, xfirst, xlast, xunits); - if ( gridIsCircular(gridID) ) - fprintf(stdout, " circular"); + if ( gridIsCircular(gridID) ) fprintf(stdout, " circular"); fprintf(stdout, "\n"); fprintf(stdout, "%*s", nbyte0, ""); fprintf(stdout, "%-9s : min = %.9g max = %.9g %s\n", yname, yfirst, ylast, yunits); - + free(xvals); free(yvals); } @@ -352,18 +360,10 @@ void printGridInfo(int vlistID) if ( ysize == 0 ) fprintf(stdout, "size : dim = %d\n", gridsize); else - { - fprintf(stdout, "size : dim = %d nx = %d ny = %d\n", gridsize, xsize, ysize); - if ( gridIsCircular(gridID) ) - { - fprintf(stdout, "%*s", nbyte0, ""); - fprintf(stdout, "longitude : circular\n"); - } - } + fprintf(stdout, "size : dim = %d nx = %d ny = %d\n", gridsize, xsize, ysize); } - if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || - gridtype == GRID_GENERIC || gridtype == GRID_LCC ) + if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC ) { if ( gridInqXvals(gridID, NULL) || gridInqYvals(gridID, NULL) || gridHasArea(gridID) || gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) ) @@ -379,6 +379,18 @@ void printGridInfo(int vlistID) fprintf(stdout, "\n"); } } + + gridInqUUID(gridID, uuidOfHGrid); + if ( uuidOfHGrid[0] != 0 ) + { + char uuidOfHGridStr[37]; + uuid2str(uuidOfHGrid, uuidOfHGridStr); + if ( uuidOfHGridStr[0] != 0 && strlen(uuidOfHGridStr) == 36 ) + { + fprintf(stdout, "%*s", nbyte0, ""); + fprintf(stdout, "uuid : %s\n", uuidOfHGridStr); + } + } } } /* diff --git a/config/default b/config/default index e9303e2b5..0599021e1 100755 --- a/config/default +++ b/config/default @@ -21,7 +21,7 @@ case "${HOSTNAME}" in --with-grib_api=$HOME/local/gribapi-1.9.16 \ --with-netcdf=$HOME/local \ --with-szlib=$HOME/local \ - CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -Df2cFortran" LIBS="-L/opt/local/lib -lopenjpeg" + CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -march=native -Df2cFortran" LIBS="-L/opt/local/lib -lopenjpeg" ;; cinglung*|feilung*|wanglung*) ./configure --prefix=$HOME/local \ @@ -44,10 +44,10 @@ case "${HOSTNAME}" in --enable-swig \ --enable-python \ --with-jasper=/opt/local \ - --with-grib_api=$HOME/local/gribapi-1.9.8 \ + --with-grib_api=$HOME/local/gribapi-1.9.16 \ --with-netcdf=/opt/local \ --with-szlib=$HOME/local \ - CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -Df2cFortran" + CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -march=native -Df2cFortran" ;; # ia64-nec-linux ds*) @@ -73,13 +73,12 @@ case "${HOSTNAME}" in ;; thingol) ./configure --prefix=`pwd`/build \ - --with-netcdf=$HOME/local/libs4cdo-0.0.8 \ - --with-hdf5=$HOME/local/libs4cdo-0.0.8 \ - --with-szlib=$HOME/local/libs4cdo-0.0.8 \ - --with-proj=$HOME/local/libs4cdo-0.0.8 \ - --with-grib_api=$HOME/local/libs4cdo-0.0.8 \ - --with-jasper=$HOME/local/libs4cdo-0.0.8 \ - --with-pic \ + --with-netcdf=$HOME/builds/libs4cdo \ + --with-hdf5=$HOME/builds/libs4cdo \ + --with-szlib=$HOME/builds/libs4cdo \ + --with-grib_api=$HOME/builds/libs4cdo \ + --with-jasper=$HOME/builds/libs4cdo \ + --with-pic --enable-swig --enable-ruby --enable-python \ CC=gcc CFLAGS="-g -O2 -Wall" LIBS=-lopenjpeg ;; # sparc-sun-solaris2.9 diff --git a/config/ltmain.sh b/config/ltmain.sh old mode 100755 new mode 100644 index 3061e3c5a..9ae038c24 --- a/config/ltmain.sh +++ b/config/ltmain.sh @@ -1,9 +1,9 @@ -# libtool (GNU libtool) 2.4 +# libtool (GNU libtool) 2.4.2 # Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +# 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -41,6 +41,7 @@ # --quiet, --silent don't print informational messages # --no-quiet, --no-silent # print informational messages (default) +# --no-warn don't display warning messages # --tag=TAG use configuration variables from tag TAG # -v, --verbose print more informational messages than default # --no-verbose don't print the extra informational messages @@ -69,7 +70,7 @@ # compiler: $LTCC # compiler flags: $LTCFLAGS # linker: $LD (gnu? $with_gnu_ld) -# $progname: (GNU libtool) 2.4 +# $progname: (GNU libtool) 2.4.2 # automake: $automake_version # autoconf: $autoconf_version # @@ -79,9 +80,9 @@ PROGRAM=libtool PACKAGE=libtool -VERSION=2.4 +VERSION=2.4.2 TIMESTAMP="" -package_revision=1.3293 +package_revision=1.3337 # Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -136,15 +137,10 @@ progpath="$0" : ${CP="cp -f"} test "${ECHO+set}" = set || ECHO=${as_echo-'printf %s\n'} -: ${EGREP="grep -E"} -: ${FGREP="grep -F"} -: ${GREP="grep"} -: ${LN_S="ln -s"} : ${MAKE="make"} : ${MKDIR="mkdir"} : ${MV="mv -f"} : ${RM="rm -f"} -: ${SED="sed"} : ${SHELL="${CONFIG_SHELL-/bin/sh}"} : ${Xsed="$SED -e 1s/^X//"} @@ -387,7 +383,7 @@ case $progpath in ;; *) save_IFS="$IFS" - IFS=: + IFS=${PATH_SEPARATOR-:} for progdir in $PATH; do IFS="$save_IFS" test -x "$progdir/$progname" && break @@ -771,8 +767,8 @@ func_help () s*\$LTCFLAGS*'"$LTCFLAGS"'* s*\$LD*'"$LD"'* s/\$with_gnu_ld/'"$with_gnu_ld"'/ - s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/ - s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/ + s/\$automake_version/'"`(${AUTOMAKE-automake} --version) 2>/dev/null |$SED 1q`"'/ + s/\$autoconf_version/'"`(${AUTOCONF-autoconf} --version) 2>/dev/null |$SED 1q`"'/ p d } @@ -1052,6 +1048,7 @@ opt_finish=false opt_help=false opt_help_all=false opt_silent=: +opt_warning=: opt_verbose=: opt_silent=false opt_verbose=false @@ -1118,6 +1115,10 @@ esac ;; --no-silent|--no-quiet) opt_silent=false +func_append preserve_args " $opt" + ;; + --no-warning|--no-warn) + opt_warning=false func_append preserve_args " $opt" ;; --no-verbose) @@ -2059,7 +2060,7 @@ func_mode_compile () *.[cCFSifmso] | \ *.ada | *.adb | *.ads | *.asm | \ *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \ - *.[fF][09]? | *.for | *.java | *.obj | *.sx | *.cu | *.cup) + *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup) func_xform "$libobj" libobj=$func_xform_result ;; @@ -3201,11 +3202,13 @@ func_mode_install () # Set up the ranlib parameters. oldlib="$destdir/$name" + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result func_show_eval "$install_prog \$file \$oldlib" 'exit $?' if test -n "$stripme" && test -n "$old_striplib"; then - func_show_eval "$old_striplib $oldlib" 'exit $?' + func_show_eval "$old_striplib $tool_oldlib" 'exit $?' fi # Do each command in the postinstall commands. @@ -3470,7 +3473,7 @@ static const void *lt_preloaded_setup() { # linked before any other PIC object. But we must not use # pic_flag when linking with -static. The problem exists in # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. - *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; *-*-hpux*) pic_flag_for_symtable=" $pic_flag" ;; @@ -3982,14 +3985,17 @@ func_exec_program_core () # launches target application with the remaining arguments. func_exec_program () { - for lt_wr_arg - do - case \$lt_wr_arg in - --lt-*) ;; - *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; - esac - shift - done + case \" \$* \" in + *\\ --lt-*) + for lt_wr_arg + do + case \$lt_wr_arg in + --lt-*) ;; + *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; + esac + shift + done ;; + esac func_exec_program_core \${1+\"\$@\"} } @@ -5057,9 +5063,15 @@ void lt_dump_script (FILE* f) { EOF func_emit_wrapper yes | - $SED -e 's/\([\\"]\)/\\\1/g' \ - -e 's/^/ fputs ("/' -e 's/$/\\n", f);/' - + $SED -n -e ' +s/^\(.\{79\}\)\(..*\)/\1\ +\2/ +h +s/\([\\"]\)/\\\1/g +s/$/\\n/ +s/\([^\n]*\).*/ fputs ("\1", f);/p +g +D' cat <<"EOF" } EOF @@ -5643,7 +5655,8 @@ func_mode_link () continue ;; - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) func_append compiler_flags " $arg" func_append compile_command " $arg" func_append finalize_command " $arg" @@ -5838,9 +5851,10 @@ func_mode_link () # -tp=* Portland pgcc target processor selection # --sysroot=* for sysroot support # -O*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -stdlib=* select c++ std lib with clang -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ - -O*|-flto*|-fwhopr*|-fuse-linker-plugin) + -O*|-flto*|-fwhopr*|-fuse-linker-plugin|-stdlib=*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" func_append compile_command " $arg" @@ -6147,7 +6161,8 @@ func_mode_link () lib= found=no case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" @@ -6831,7 +6846,7 @@ func_mode_link () test "$hardcode_direct_absolute" = no; then add="$dir/$linklib" elif test "$hardcode_minus_L" = yes; then - add_dir="-L$dir" + add_dir="-L$absdir" # Try looking first in the location we're being installed to. if test -n "$inst_prefix_dir"; then case $libdir in @@ -7316,6 +7331,7 @@ func_mode_link () # which has an extra 1 added just for fun # case $version_type in + # correct linux to gnu/linux during the next big refactor darwin|linux|osf|windows|none) func_arith $number_major + $number_minor current=$func_arith_result @@ -7432,7 +7448,7 @@ func_mode_link () versuffix="$major.$revision" ;; - linux) + linux) # correct to gnu/linux during the next big refactor func_arith $current - $age major=.$func_arith_result versuffix="$major.$age.$revision" @@ -8020,6 +8036,11 @@ EOF # Test again, we may have decided not to build it any more if test "$build_libtool_libs" = yes; then + # Remove ${wl} instances when linking with ld. + # FIXME: should test the right _cmds variable. + case $archive_cmds in + *\$LD\ *) wl= ;; + esac if test "$hardcode_into_libs" = yes; then # Hardcode the library paths hardcode_libdirs= @@ -8050,7 +8071,7 @@ EOF elif test -n "$runpath_var"; then case "$perm_rpath " in *" $libdir "*) ;; - *) func_apped perm_rpath " $libdir" ;; + *) func_append perm_rpath " $libdir" ;; esac fi done @@ -8058,11 +8079,7 @@ EOF if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" - if test -n "$hardcode_libdir_flag_spec_ld"; then - eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" - else - eval dep_rpath=\"$hardcode_libdir_flag_spec\" - fi + eval "dep_rpath=\"$hardcode_libdir_flag_spec\"" fi if test -n "$runpath_var" && test -n "$perm_rpath"; then # We should set the runpath_var. @@ -9152,6 +9169,8 @@ EOF esac done fi + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result eval cmds=\"$old_archive_cmds\" func_len " $cmds" @@ -9261,7 +9280,8 @@ EOF *.la) func_basename "$deplib" name="$func_basename_result" - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + func_resolve_sysroot "$deplib" + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result` test -z "$libdir" && \ func_fatal_error "\`$deplib' is not a valid libtool archive" func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name" diff --git a/configure b/configure index 2f4dd154a..020d7627a 100755 --- a/configure +++ b/configure @@ -1,11 +1,13 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for cdi 1.5.6. +# Generated by GNU Autoconf 2.68 for cdi 1.6.0. # # Report bugs to <http://code.zmaw.de/projects/cdi>. # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -134,31 +136,6 @@ export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -192,8 +169,7 @@ if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -246,25 +222,21 @@ IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -367,14 +339,6 @@ $as_echo X"$as_dir" | } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -496,10 +460,6 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -534,16 +494,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -555,8 +515,28 @@ else as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -590,8 +570,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='cdi' PACKAGE_TARNAME='cdi' -PACKAGE_VERSION='1.5.6' -PACKAGE_STRING='cdi 1.5.6' +PACKAGE_VERSION='1.6.0' +PACKAGE_STRING='cdi 1.6.0' PACKAGE_BUGREPORT='http://code.zmaw.de/projects/cdi' PACKAGE_URL='' @@ -1354,6 +1334,8 @@ target=$target_alias if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1439,7 +1421,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.5.6 to adapt to many kinds of systems. +\`configure' configures cdi 1.6.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1509,7 +1491,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of cdi 1.5.6:";; + short | recursive ) echo "Configuration of cdi 1.6.0:";; esac cat <<\_ACEOF @@ -1677,10 +1659,10 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -cdi configure 1.5.6 -generated by GNU Autoconf 2.69 +cdi configure 1.6.0 +generated by GNU Autoconf 2.68 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1756,7 +1738,7 @@ $as_echo "$ac_try_echo"; } >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - test -x conftest$ac_exeext + $as_test_x conftest$ac_exeext }; then : ac_retval=0 else @@ -2017,7 +1999,7 @@ $as_echo "$ac_try_echo"; } >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - test -x conftest$ac_exeext + $as_test_x conftest$ac_exeext }; then : ac_retval=0 else @@ -2101,7 +2083,7 @@ $as_echo "$ac_try_echo"; } >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - test -x conftest$ac_exeext + $as_test_x conftest$ac_exeext }; then : ac_retval=0 else @@ -2222,7 +2204,7 @@ $as_echo "$ac_try_echo"; } >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - test -x conftest$ac_exeext + $as_test_x conftest$ac_exeext }; then : ac_retval=0 else @@ -2438,8 +2420,8 @@ 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.5.6, which was -generated by GNU Autoconf 2.69. Invocation command line was +It was created by cdi $as_me 1.6.0, which was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2971,7 +2953,7 @@ case $as_dir/ in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -3140,7 +3122,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3180,7 +3162,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3231,7 +3213,7 @@ do test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do - as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ @@ -3284,7 +3266,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3370,7 +3352,7 @@ fi # Define the identity of the package. PACKAGE='cdi' - VERSION='1.5.6' + VERSION='1.6.0' cat >>confdefs.h <<_ACEOF @@ -3447,8 +3429,8 @@ esac -macro_version='2.4' -macro_revision='1.3293' +macro_version='2.4.2' +macro_revision='1.3337' @@ -3618,7 +3600,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3658,7 +3640,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3711,7 +3693,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3752,7 +3734,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -3810,7 +3792,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3854,7 +3836,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -4300,7 +4282,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <stdarg.h> #include <stdio.h> -struct stat; +#include <sys/types.h> +#include <sys/stat.h> /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -4535,7 +4518,7 @@ do for ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_SED" || continue + { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in @@ -4611,7 +4594,7 @@ do for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_GREP" || continue + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in @@ -4677,7 +4660,7 @@ do for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -4744,7 +4727,7 @@ do for ac_prog in fgrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_FGREP" || continue + { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue # Check for GNU ac_path_FGREP and select it if it is found. # Check for GNU $ac_path_FGREP case `"$ac_path_FGREP" --version 2>&1` in @@ -5000,7 +4983,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5044,7 +5027,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5463,7 +5446,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5503,7 +5486,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OBJDUMP="objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5809,7 +5792,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5849,7 +5832,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5953,7 +5936,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5997,7 +5980,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_AR="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6122,7 +6105,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6162,7 +6145,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6221,7 +6204,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6261,7 +6244,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6896,7 +6879,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6936,7 +6919,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7016,7 +6999,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7056,7 +7039,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7108,7 +7091,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7148,7 +7131,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_NMEDIT="nmedit" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7200,7 +7183,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_LIPO="${ac_tool_prefix}lipo" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7240,7 +7223,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_LIPO="lipo" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7292,7 +7275,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OTOOL="${ac_tool_prefix}otool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7332,7 +7315,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OTOOL="otool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7384,7 +7367,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7424,7 +7407,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OTOOL64="otool64" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -11894,7 +11877,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -11934,7 +11917,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -12115,7 +12098,7 @@ main () return 0; } _ACEOF -for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc99 +for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99 do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : @@ -12151,7 +12134,7 @@ ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5' ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_fc_compiler_gnu if test -n "$ac_tool_prefix"; then - for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 + for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 @@ -12169,7 +12152,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_FC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -12195,7 +12178,7 @@ fi fi if test -z "$FC"; then ac_ct_FC=$FC - for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 + for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -12213,7 +12196,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_FC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -12346,11 +12329,6 @@ else fi fi -if test $ac_compiler_gnu = yes; then - GFC=yes -else - GFC= -fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -15258,11 +15236,7 @@ else ac_fcflags_srcext_save=$ac_fcflags_srcext ac_fcflags_srcext= ac_cv_fc_srcext_f90=unknown -case $ac_ext in #( - [fF]77) ac_try=f77;; #( - *) ac_try=f95;; -esac -for ac_flag in none -qsuffix=f=f90 -Tf "-x $ac_try"; do +for ac_flag in none -qsuffix=f=f90 -Tf; do test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag" cat > conftest.$ac_ext <<_ACEOF program main @@ -16046,7 +16020,7 @@ ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5' ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_f77_compiler_gnu if test -n "$ac_tool_prefix"; then - for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor + for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 @@ -16064,7 +16038,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_F77="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -16090,7 +16064,7 @@ fi fi if test -z "$F77"; then ac_ct_F77=$F77 - for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor + for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -16108,7 +16082,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_F77="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -18964,98 +18938,6 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_RANLIB+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 -$as_echo "$RANLIB" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_RANLIB="ranlib" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 -$as_echo "$ac_ct_RANLIB" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - if test "x$ac_ct_RANLIB" = x; then - RANLIB=":" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - RANLIB=$ac_ct_RANLIB - fi -else - RANLIB="$ac_cv_prog_RANLIB" -fi - ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -19084,7 +18966,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -19128,7 +19010,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CXX="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22630,7 +22512,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_SED="sed" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22668,7 +22550,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_GREP="grep" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22708,7 +22590,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AR="${ac_tool_prefix}ar" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22748,7 +22630,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_AR="ar" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22800,7 +22682,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CPP="${ac_tool_prefix}cpp" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22840,7 +22722,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CPP="cpp" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22892,7 +22774,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_LD="${ac_tool_prefix}ld" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22932,7 +22814,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_LD="ld" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -22984,7 +22866,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NM="${ac_tool_prefix}nm" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23024,7 +22906,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_NM="nm" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23076,7 +22958,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AS="${ac_tool_prefix}as" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23116,7 +22998,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_AS="as" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23168,7 +23050,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23208,7 +23090,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23260,7 +23142,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23300,7 +23182,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OBJDUMP="objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23352,7 +23234,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23392,7 +23274,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23444,7 +23326,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23484,7 +23366,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -23717,8 +23599,6 @@ _ACEOF esac rm -rf conftest* fi - - fi # ---------------------------------------------------------------------- @@ -24010,6 +23890,17 @@ _ACEOF fi done +for ac_func in getline +do : + ac_fn_c_check_func "$LINENO" "getline" "ac_cv_func_getline" +if test "x$ac_cv_func_getline" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_GETLINE 1 +_ACEOF + +fi +done + # ---------------------------------------------------------------------- # Checks for the availability of ANSI-C99 functions ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "$ac_includes_default @@ -24235,7 +24126,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ax_pthread_config="yes" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -24396,7 +24287,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_PTHREAD_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -25371,7 +25262,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NC_CONFIG="nc-config" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -25520,7 +25411,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NC_CONFIG="$NETCDF_ROOT/bin/nc-config" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -25951,12 +25842,12 @@ $as_echo_n "checking for libpng library... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: suppressed" >&5 $as_echo "suppressed" >&6; } ;; #( yes) : - for ac_header in libpng14/png.h + for ac_header in png.h do : - ac_fn_c_check_header_mongrel "$LINENO" "libpng14/png.h" "ac_cv_header_libpng14_png_h" "$ac_includes_default" -if test "x$ac_cv_header_libpng14_png_h" = xyes; then : + ac_fn_c_check_header_mongrel "$LINENO" "png.h" "ac_cv_header_png_h" "$ac_includes_default" +if test "x$ac_cv_header_png_h" = xyes; then : cat >>confdefs.h <<_ACEOF -#define HAVE_LIBPNG14_PNG_H 1 +#define HAVE_PNG_H 1 _ACEOF fi @@ -25987,7 +25878,7 @@ return png_warning (); return 0; } _ACEOF -for ac_lib in '' png14; do +for ac_lib in '' png; do if test -z "$ac_lib"; then ac_res="none required" else @@ -26023,7 +25914,7 @@ else as_fn_error $? "Could not link to libpng library! Required for GRIB_API" "$LINENO" 5 fi - LIBPNG_LIBS=" -lpng14" + LIBPNG_LIBS=" -lpng" ;; #( *) : LIBPNG_ROOT=$with_libpng @@ -26054,7 +25945,7 @@ return png_warning (); return 0; } _ACEOF -for ac_lib in '' png14; do +for ac_lib in '' png; do if test -z "$ac_lib"; then ac_res="none required" else @@ -26090,7 +25981,7 @@ else as_fn_error $? "Could not link to libpng library! Required for GRIB_API" "$LINENO" 5 fi - LIBPNG_LIBS=" -L$LIBPNG_ROOT/lib -lpng14" + LIBPNG_LIBS=" -L$LIBPNG_ROOT/lib -lpng" else as_fn_error $? "$LIBPNG_ROOT is not a directory! LIBPNG suppressed" "$LINENO" 5 fi ;; #( @@ -26491,7 +26382,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -26534,7 +26425,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -26608,7 +26499,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_MPI_LAUNCH="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -27103,7 +26994,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_SWIG="swig" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -27156,7 +27047,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RUBY="ruby" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -27243,7 +27134,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_PYTHON="python" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -27851,16 +27742,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -27920,16 +27811,28 @@ else as_mkdir_p=false fi - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -27950,8 +27853,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=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.5.6, which was -generated by GNU Autoconf 2.69. Invocation command line was +This file was extended by cdi $as_me 1.6.0, which was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -28016,11 +27919,11 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -cdi config.status 1.5.6 -configured by $0, generated by GNU Autoconf 2.69, +cdi config.status 1.6.0 +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -28111,7 +28014,7 @@ fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' diff --git a/configure.ac b/configure.ac index bc97fbded..784a86952 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([cdi], [1.5.6], [http://code.zmaw.de/projects/cdi]) +AC_INIT([cdi], [1.6.0], [http://code.zmaw.de/projects/cdi]) echo "configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" @@ -27,7 +27,7 @@ AC_DEFINE_UNQUOTED([SYSTEM_TYPE],["$ac_cv_build"], [System type]) AC_SUBST([SYSTEM_TYPE],["$ac_cv_build"]) AM_INIT_AUTOMAKE -AM_CONFIG_HEADER([src/config.h]) +AC_CONFIG_HEADERS([src/config.h]) AM_MAINTAINER_MODE([disable]) # Set up libtool. @@ -44,7 +44,6 @@ AS_IF([test -n "$FC" && test "X$FC" != "Xno"], AC_PROG_FPP AC_LANG_POP([Fortran])]) AC_PROG_F77 -AC_PROG_RANLIB AC_PROG_CXX AC_CHECK_PROG(SED,sed,sed,false) AC_CHECK_PROG(GREP,grep,grep,false) @@ -75,7 +74,8 @@ AC_CHECK_MEMBERS([struct stat.st_blksize]) AC_CHECK_HEADERS(malloc.h) # ---------------------------------------------------------------------- # Checks for the availability of functions -AC_CHECK_FUNCS(mallinfo) +AC_CHECK_FUNCS([mallinfo]) +AC_CHECK_FUNCS([getline]) # ---------------------------------------------------------------------- # Checks for the availability of ANSI-C99 functions AC_CHECK_DECLS([isnan],,,[AC_INCLUDES_DEFAULT diff --git a/doc/Doxyfile b/doc/Doxyfile new file mode 100644 index 000000000..5da4efb46 --- /dev/null +++ b/doc/Doxyfile @@ -0,0 +1,1514 @@ +# Doxyfile 1.6.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = Climate Data Interface + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 1.6 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = YES + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = YES + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it parses. +# With this tag you can assign which parser to use for a given extension. +# Doxygen has a built-in mapping, but you can override or extend it using this tag. +# The format is ext=language, where ext is a file extension, and language is one of +# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, +# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat +# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. + +EXTENSION_MAPPING = inc=Fortran F90=Fortran + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen to replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penality. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will rougly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols + +SYMBOL_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. +# This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command <command> <input-file>, where <command> is the value of +# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by +# doxygen. The layout file controls the global structure of the generated output files +# in an output format independent way. The create the layout file that represents +# doxygen's defaults, run doxygen with the -l option. You can optionally specify a +# file name after the option, if omitted DoxygenLayout.xml will be used as the name +# of the layout file. + +LAYOUT_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = NO + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = src doc/src + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 + +FILE_PATTERNS = *.c *.f *.F *.F90 *.f90 *.h *.inc *.dox + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = src/cfortran.h src/cdilib.c + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = tests examples + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = doc/Figures + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command <filter> <input-file>, where <filter> +# is the value of the INPUT_FILTER tag, and <input-file> is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. +# If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. +# Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. +# The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. +# Otherwise they will link to the documentation. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = NO + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER +# are set, an additional index file will be generated that can be used as input for +# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated +# HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#namespace + +QHP_NAMESPACE = + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#virtual-folders + +QHP_VIRTUAL_FOLDER = doc + +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. +# For more information please see +# http://doc.trolltech.com/qthelpproject.html#custom-filters + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see +# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's +# filter section matches. +# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>. + +QHP_SECT_FILTER_ATTRS = + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file. + +QHG_LOCATION = + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to YES, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, +# and Class Hierarchy pages using a tree view instead of an ordered list. + +USE_INLINE_TREES = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +# When the SEARCHENGINE tag is enable doxygen will generate a search box for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP) or Qt help (GENERATE_QHP) +# there is already a search function so this one should typically +# be disabled. + +SEARCHENGINE = YES + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +# If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. +# This is useful +# if you want to understand what is going on. +# On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = NO + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = YES + +# By default doxygen will write a font called FreeSans.ttf to the output +# directory and reference it in all dot files that doxygen generates. This +# font does not include all possible unicode characters however, so when you need +# these (or just want a differently looking font) you can specify the font name +# using DOT_FONTNAME. You need need to make sure dot is able to find the font, +# which can be done by putting it in a standard location or by setting the +# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory +# containing the font. + +DOT_FONTNAME = FreeSans + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the output directory to look for the +# FreeSans.ttf font (which doxygen will put there itself). If you specify a +# different font using DOT_FONTNAME you can set the path where dot +# can find it using this tag. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = YES + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = YES + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = YES + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 100 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = YES + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES diff --git a/doc/tex/c_quick_ref.tex b/doc/tex/c_quick_ref.tex index e78cb5391..c5f97fa63 100644 --- a/doc/tex/c_quick_ref.tex +++ b/doc/tex/c_quick_ref.tex @@ -748,6 +748,24 @@ Define the code number of a Variable. Define the data type of a Variable. +\section*{\tt \htmlref{vlistDefVarDblKey}{vlistDefVarDblKey}} + +\begin{verbatim} + void vlistDefVarDblKey (int vlistID, int varID, const char *name, double value); +\end{verbatim} + +Set an arbitrary keyword/double value pair for GRIB API. + + +\section*{\tt \htmlref{vlistDefVarIntKey}{vlistDefVarIntKey}} + +\begin{verbatim} + void vlistDefVarIntKey (int vlistID, int varID, const char *name, int value); +\end{verbatim} + +Set an arbitrary keyword/integer value pair for GRIB API. + + \section*{\tt \htmlref{vlistDefVarLongname}{vlistDefVarLongname}} \begin{verbatim} @@ -931,6 +949,24 @@ Get the name of a Variable. Get the parameter number of a Variable. +\section*{\tt \htmlref{vlistInqVarRawBegin}{vlistInqVarRawBegin}} + +\begin{verbatim} + void vlistInqVarRawBegin (int streamID, int varID); +\end{verbatim} + +Open GRIB record to retrieve raw meta-data in subsequent calls. + + +\section*{\tt \htmlref{vlistInqVarRawEnd}{vlistInqVarRawEnd}} + +\begin{verbatim} + void vlistInqVarRawEnd (int streamID); +\end{verbatim} + +Free previously opened GRIB record. + + \section*{\tt \htmlref{vlistInqVarStdname}{vlistInqVarStdname}} \begin{verbatim} diff --git a/doc/tex/c_stream.tex b/doc/tex/c_stream.tex index 47eef36f5..b2d2136c3 100644 --- a/doc/tex/c_stream.tex +++ b/doc/tex/c_stream.tex @@ -49,7 +49,7 @@ Library support not compiled in. \subsubsection*{Example} -Here is an example using {\tt streamOpenWrite} to create a new netCDF file +Here is an example using {\tt streamOpenWrite} to create a new netCDF file named {\tt foo.nc} for writing: \begin{lstlisting}[language=C, backgroundcolor=\color{pyellow}, basicstyle=\small, columns=flexible] diff --git a/doc/tex/c_vlist_att.tex b/doc/tex/c_vlist_att.tex index 10121b929..6da719808 100644 --- a/doc/tex/c_vlist_att.tex +++ b/doc/tex/c_vlist_att.tex @@ -29,7 +29,7 @@ Pointer to location for returned number of variable attributes. \index{vlistInqAtt} \label{vlistInqAtt} -The function {\tt vlistInqNatts} gets information about an attribute. +The function {\tt vlistInqAtt} gets information about an attribute. \subsubsection*{Usage} diff --git a/doc/tex/c_zaxis.tex b/doc/tex/c_zaxis.tex index cae0a163b..b143fca04 100644 --- a/doc/tex/c_zaxis.tex +++ b/doc/tex/c_zaxis.tex @@ -18,6 +18,9 @@ The function {\tt zaxisCreate} creates a vertical Z-axis. The type of the Z-axis, one of the set of predefined {\CDI} Z-axis types. The valid {\CDI} Z-axis types are {\tt ZAXIS\_GENERIC}, {\tt ZAXIS\_SURFACE}, {\tt ZAXIS\_HYBRID}, {\tt ZAXIS\_SIGMA}, {\tt ZAXIS\_PRESSURE}, {\tt ZAXIS\_HEIGHT}, + {\tt ZAXIS\_ISENTROPIC}, {\tt ZAXIS\_ALTITUDE}, {\tt ZAXIS\_MEANSEA}, {\tt ZAXIS\_TOA}, + {\tt ZAXIS\_SEA\_BOTTOM}, {\tt ZAXIS\_ATMOSPHERE}, {\tt ZAXIS\_CLOUD\_BASE}, + {\tt ZAXIS\_CLOUD\_TOP}, {\tt ZAXIS\_ISOTHERM\_ZERO}, {\tt ZAXIS\_DEPTH\_BELOW\_SEA} and {\tt ZAXIS\_DEPTH\_BELOW\_LAND}. \item[{\tt size}] Number of levels. @@ -93,6 +96,9 @@ Z-axis ID, from a previous call to {\htmlref{\tt zaxisCreate}{zaxisCreate}}. one of the set of predefined {\CDI} Z-axis types. The valid {\CDI} Z-axis types are {\tt ZAXIS\_GENERIC}, {\tt ZAXIS\_SURFACE}, {\tt ZAXIS\_HYBRID}, {\tt ZAXIS\_SIGMA}, {\tt ZAXIS\_PRESSURE}, {\tt ZAXIS\_HEIGHT}, +{\tt ZAXIS\_ISENTROPIC}, {\tt ZAXIS\_ALTITUDE}, {\tt ZAXIS\_MEANSEA}, {\tt ZAXIS\_TOA}, +{\tt ZAXIS\_SEA\_BOTTOM}, {\tt ZAXIS\_ATMOSPHERE}, {\tt ZAXIS\_CLOUD\_BASE}, +{\tt ZAXIS\_CLOUD\_TOP}, {\tt ZAXIS\_ISOTHERM\_ZERO}, {\tt ZAXIS\_DEPTH\_BELOW\_SEA} and {\tt ZAXIS\_DEPTH\_BELOW\_LAND}. diff --git a/doc/tex/cdi_cman.tex b/doc/tex/cdi_cman.tex index 54a3461e1..c3f8e7a54 100644 --- a/doc/tex/cdi_cman.tex +++ b/doc/tex/cdi_cman.tex @@ -135,7 +135,7 @@ \end{picture} \begin{flushright} -\large\bf{Climate Data Interface \\ Version 1.5.6 \\ July 2012} +\large\bf{Climate Data Interface \\ Version 1.6.0 \\ March 2013} \end{flushright} \vfill diff --git a/doc/tex/cdi_fman.tex b/doc/tex/cdi_fman.tex index 425caec13..2cc452df6 100644 --- a/doc/tex/cdi_fman.tex +++ b/doc/tex/cdi_fman.tex @@ -132,7 +132,7 @@ \end{picture} \begin{flushright} -\large\bf{Climate Data Interface \\ Version 1.5.6 \\ July 2012} +\large\bf{Climate Data Interface \\ Version 1.6.0 \\ March 2013} \end{flushright} \vfill diff --git a/doc/tex/f_quick_ref.tex b/doc/tex/f_quick_ref.tex index 32b7beecc..1e4bfd5c1 100644 --- a/doc/tex/f_quick_ref.tex +++ b/doc/tex/f_quick_ref.tex @@ -755,6 +755,26 @@ Define the code number of a Variable. Define the data type of a Variable. +\section*{\tt \htmlref{vlistDefVarDblKey}{vlistDefVarDblKey}} + +\begin{verbatim} + SUBROUTINE vlistDefVarDblKey (INTEGER vlistID, INTEGER varID, CHARACTER*(*) name, + DOUBLEPRECISION value) +\end{verbatim} + +Set an arbitrary keyword/double value pair for GRIB API. + + +\section*{\tt \htmlref{vlistDefVarIntKey}{vlistDefVarIntKey}} + +\begin{verbatim} + SUBROUTINE vlistDefVarIntKey (INTEGER vlistID, INTEGER varID, CHARACTER*(*) name, + INTEGER value) +\end{verbatim} + +Set an arbitrary keyword/integer value pair for GRIB API. + + \section*{\tt \htmlref{vlistDefVarLongname}{vlistDefVarLongname}} \begin{verbatim} @@ -946,6 +966,24 @@ Get the name of a Variable. Get the parameter number of a Variable. +\section*{\tt \htmlref{vlistInqVarRawBegin}{vlistInqVarRawBegin}} + +\begin{verbatim} + SUBROUTINE vlistInqVarRawBegin (INTEGER streamID, INTEGER varID) +\end{verbatim} + +Open GRIB record to retrieve raw meta-data in subsequent calls. + + +\section*{\tt \htmlref{vlistInqVarRawEnd}{vlistInqVarRawEnd}} + +\begin{verbatim} + SUBROUTINE vlistInqVarRawEnd (INTEGER streamID) +\end{verbatim} + +Free previously opened GRIB record. + + \section*{\tt \htmlref{vlistInqVarStdname}{vlistInqVarStdname}} \begin{verbatim} @@ -1176,7 +1214,7 @@ Get the type of a Z-axis. \section*{\tt \htmlref{zaxisInqUUID}{zaxisInqUUID}} \begin{verbatim} - CHARACTER*80 FUNCTION zaxisInqUUID (INTEGER zaxisID, CHARACTER*(*) uuid) + CHARACTER(80) FUNCTION zaxisInqUUID (INTEGER zaxisID, CHARACTER*(*) uuid) \end{verbatim} Get the reference of a generalized Z-axis. diff --git a/doc/tex/f_stream.tex b/doc/tex/f_stream.tex index 8642e9c57..da1cda688 100644 --- a/doc/tex/f_stream.tex +++ b/doc/tex/f_stream.tex @@ -49,7 +49,7 @@ Library support not compiled in. \subsubsection*{Example} -Here is an example using {\tt streamOpenWrite} to create a new netCDF file +Here is an example using {\tt streamOpenWrite} to create a new netCDF file named {\tt foo.nc} for writing: \begin{lstlisting}[language=Fortran, backgroundcolor=\color{pyellow}, basicstyle=\small, columns=flexible] diff --git a/doc/tex/f_vlist_att.tex b/doc/tex/f_vlist_att.tex index 5ea8d20eb..39a65cd57 100644 --- a/doc/tex/f_vlist_att.tex +++ b/doc/tex/f_vlist_att.tex @@ -29,7 +29,7 @@ Pointer to location for returned number of variable attributes. \index{vlistInqAtt} \label{vlistInqAtt} -The function {\tt vlistInqNatts} gets information about an attribute. +The function {\tt vlistInqAtt} gets information about an attribute. \subsubsection*{Usage} diff --git a/doc/tex/f_zaxis.tex b/doc/tex/f_zaxis.tex index b85817355..26dfacac6 100644 --- a/doc/tex/f_zaxis.tex +++ b/doc/tex/f_zaxis.tex @@ -18,6 +18,9 @@ The function {\tt zaxisCreate} creates a vertical Z-axis. The type of the Z-axis, one of the set of predefined {\CDI} Z-axis types. The valid {\CDI} Z-axis types are {\tt ZAXIS\_GENERIC}, {\tt ZAXIS\_SURFACE}, {\tt ZAXIS\_HYBRID}, {\tt ZAXIS\_SIGMA}, {\tt ZAXIS\_PRESSURE}, {\tt ZAXIS\_HEIGHT}, + {\tt ZAXIS\_ISENTROPIC}, {\tt ZAXIS\_ALTITUDE}, {\tt ZAXIS\_MEANSEA}, {\tt ZAXIS\_TOA}, + {\tt ZAXIS\_SEA\_BOTTOM}, {\tt ZAXIS\_ATMOSPHERE}, {\tt ZAXIS\_CLOUD\_BASE}, + {\tt ZAXIS\_CLOUD\_TOP}, {\tt ZAXIS\_ISOTHERM\_ZERO}, {\tt ZAXIS\_DEPTH\_BELOW\_SEA} and {\tt ZAXIS\_DEPTH\_BELOW\_LAND}. \item[{\tt size}] Number of levels. @@ -93,6 +96,9 @@ Z-axis ID, from a previous call to {\htmlref{\tt zaxisCreate}{zaxisCreate}}. one of the set of predefined {\CDI} Z-axis types. The valid {\CDI} Z-axis types are {\tt ZAXIS\_GENERIC}, {\tt ZAXIS\_SURFACE}, {\tt ZAXIS\_HYBRID}, {\tt ZAXIS\_SIGMA}, {\tt ZAXIS\_PRESSURE}, {\tt ZAXIS\_HEIGHT}, +{\tt ZAXIS\_ISENTROPIC}, {\tt ZAXIS\_ALTITUDE}, {\tt ZAXIS\_MEANSEA}, {\tt ZAXIS\_TOA}, +{\tt ZAXIS\_SEA\_BOTTOM}, {\tt ZAXIS\_ATMOSPHERE}, {\tt ZAXIS\_CLOUD\_BASE}, +{\tt ZAXIS\_CLOUD\_TOP}, {\tt ZAXIS\_ISOTHERM\_ZERO}, {\tt ZAXIS\_DEPTH\_BELOW\_SEA} and {\tt ZAXIS\_DEPTH\_BELOW\_LAND}. diff --git a/doc/tex/formats.tex b/doc/tex/formats.tex index bb8967f53..5c6588b52 100644 --- a/doc/tex/formats.tex +++ b/doc/tex/formats.tex @@ -50,18 +50,25 @@ GRIB1 & GRIB2 & & \\ GRIB1 & GRIB2 & & \\ \rowcolor[gray]{.9} level type & level type & GRIB\_API name & description \\ - 1 & 1 & surface & Surface level \\ - 99 & -- & -- & Isobaric level in Pa \\ - 100 & 100 & isobaricInhPa & Isobaric level in hPa \\ - 103 & 102 & heightAboveSea & Altitude above mean sea level \\ - 105 & 103 & heightAboveGround & Height level above ground \\ - 107 & 104 & sigma & Sigma level \\ - 109 & 105 & hybrid & Hybrid level \\ - 110 & 105 & hybridLayer & Layer between two hybrid levels \\ - 111 & 106 & depthBelowLand & Depth below land surface \\ + 1 & 1 & surface & Surface level \\ + 2 & 2 & cloudBase & Cloud base level \\ + 3 & 3 & cloudTop & Level of cloud tops \\ + 4 & 4 & isothermZero & Level of 0$^{\circ}$ C isotherm \\ + 8 & 8 & nominalTop & Norminal top of atmosphere \\ + 9 & 9 & seaBottom & Sea bottom \\ + 10 & 10 & entireAtmosphere & Entire atmosphere \\ + 99 & -- & -- & Isobaric level in Pa \\ + 100 & 100 & isobaricInhPa & Isobaric level in hPa \\ + 102 & 101 & meanSea & Mean sea level \\ + 103 & 102 & heightAboveSea & Altitude above mean sea level \\ + 105 & 103 & heightAboveGround & Height level above ground \\ + 107 & 104 & sigma & Sigma level \\ + 109 & 105 & hybrid & Hybrid level \\ + 110 & 105 & hybridLayer & Layer between two hybrid levels \\ + 111 & 106 & depthBelowLand & Depth below land surface \\ 112 & 106 & depthBelowLandLayer & Layer between two depths below land surface \\ - 113 & 107 & theta & Isentropic (theta) level \\ - 160 & 160 & depthBelowSea & Depth below sea level \\ + 113 & 107 & theta & Isentropic (theta) level \\ + 160 & 160 & depthBelowSea & Depth below sea level \\ \hline \end{tabular} diff --git a/doc/tex/zaxis.tex b/doc/tex/zaxis.tex index 54101478c..bbcbcb164 100644 --- a/doc/tex/zaxis.tex +++ b/doc/tex/zaxis.tex @@ -8,11 +8,19 @@ The following different Z-axis types are available: \begin{deflist}{{\large\tt ZAXIS\_DEPTH\_BELOW\_LAND \ \ }} \item[{\large\tt ZAXIS\_GENERIC }] Generic user defined level \item[{\large\tt ZAXIS\_SURFACE }] Surface level +\item[{\large\tt ZAXIS\_MEANSEA }] Mean sea level +\item[{\large\tt ZAXIS\_TOA }] Norminal top of atmosphere +\item[{\large\tt ZAXIS\_ATMOSPHERE }] Entire atmosphere +\item[{\large\tt ZAXIS\_SEA\_BOTTOM }] Sea bottom +\item[{\large\tt ZAXIS\_ISENTROPIC }] Isentropic (theta) level \item[{\large\tt ZAXIS\_HYBRID }] Hybrid level -\item[{\large\tt ZAXIS\_SIGMA }] Sigma level +\item[{\large\tt ZAXIS\_SIGMA }] Sigma level \item[{\large\tt ZAXIS\_PRESSURE }] Isobaric pressure level in Pascal \item[{\large\tt ZAXIS\_HEIGHT }] Height above ground in meters \item[{\large\tt ZAXIS\_ALTITUDE }] Altitude above mean sea level in meters +\item[{\large\tt ZAXIS\_CLOUD\_BASE }] Cloud base level +\item[{\large\tt ZAXIS\_CLOUD\_TOP }] Level of cloud tops +\item[{\large\tt ZAXIS\_ISOTHERM\_ZERO }] Level of 0$^{\circ}$ C isotherm \item[{\large\tt ZAXIS\_DEPTH\_BELOW\_SEA }] Depth below sea level in meters \item[{\large\tt ZAXIS\_DEPTH\_BELOW\_LAND}] Depth below land surface in centimeters \end{deflist} diff --git a/examples/Makefile.am b/examples/Makefile.am index 0d64017d6..850875f3b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -2,7 +2,7 @@ # EXTRA_DIST = cdi_read_f2003.f90 cdi_write_f2003.f90 # -noinst_PROGRAMS = cdi_write cdi_read cdi_copy +noinst_PROGRAMS = cdi_write cdi_write_ens cdi_read cdi_copy if CREATE_ISOC noinst_PROGRAMS += cdi_read_f2003 cdi_write_f2003 endif @@ -13,6 +13,9 @@ AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src $(FC_MOD_FLAG)../src cdi_write_SOURCES = cdi_write.c cdi_write_LDADD = $(top_builddir)/src/libcdi.la # +cdi_write_ens_SOURCES = cdi_write_ens.c +cdi_write_ens_LDADD = $(top_builddir)/src/libcdi.la +# cdi_read_SOURCES = cdi_read.c cdi_read_LDADD = $(top_builddir)/src/libcdi.la # @@ -25,9 +28,10 @@ cdi_read_LDFLAGS = -all-static cdi_copy_LDFLAGS = -all-static endif cdi_read_f2003_SOURCES = cdi_read_f2003.f90 -cdi_read_f2003_LDADD = $(top_builddir)/src/libcdi.la $(top_builddir)/src/mo_cdi.o -cdi_read_f2003_LDFLAGS = -all-static +cdi_read_f2003_LDADD = $(top_builddir)/src/libcdi.la $(top_builddir)/src/mo_cdi.o +cdi_read_f2003_LDFLAGS = -all-static cdi_write_f2003_SOURCES = cdi_write_f2003.f90 cdi_write_f2003_LDADD = $(top_builddir)/src/libcdi.la $(top_builddir)/src/mo_cdi.o cdi_write_f2003_LDFLAGS = -all-static + diff --git a/examples/Makefile.in b/examples/Makefile.in index 4e0adb45f..d294de129 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -51,8 +51,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -noinst_PROGRAMS = cdi_write$(EXEEXT) cdi_read$(EXEEXT) \ - cdi_copy$(EXEEXT) $(am__EXEEXT_1) +noinst_PROGRAMS = cdi_write$(EXEEXT) cdi_write_ens$(EXEEXT) \ + cdi_read$(EXEEXT) cdi_copy$(EXEEXT) $(am__EXEEXT_1) @CREATE_ISOC_TRUE@am__append_1 = cdi_read_f2003 cdi_write_f2003 subdir = examples DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in @@ -103,6 +103,9 @@ cdi_write_DEPENDENCIES = $(top_builddir)/src/libcdi.la cdi_write_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(cdi_write_LDFLAGS) $(LDFLAGS) -o $@ +am_cdi_write_ens_OBJECTS = cdi_write_ens.$(OBJEXT) +cdi_write_ens_OBJECTS = $(am_cdi_write_ens_OBJECTS) +cdi_write_ens_DEPENDENCIES = $(top_builddir)/src/libcdi.la am_cdi_write_f2003_OBJECTS = cdi_write_f2003.$(OBJEXT) cdi_write_f2003_OBJECTS = $(am_cdi_write_f2003_OBJECTS) cdi_write_f2003_DEPENDENCIES = $(top_builddir)/src/libcdi.la \ @@ -132,10 +135,10 @@ FCLINK = $(LIBTOOL) --tag=FC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(cdi_copy_SOURCES) $(cdi_read_SOURCES) \ $(cdi_read_f2003_SOURCES) $(cdi_write_SOURCES) \ - $(cdi_write_f2003_SOURCES) + $(cdi_write_ens_SOURCES) $(cdi_write_f2003_SOURCES) DIST_SOURCES = $(cdi_copy_SOURCES) $(cdi_read_SOURCES) \ $(cdi_read_f2003_SOURCES) $(cdi_write_SOURCES) \ - $(cdi_write_f2003_SOURCES) + $(cdi_write_ens_SOURCES) $(cdi_write_f2003_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -339,6 +342,9 @@ AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src $(FC_MOD_FLAG)../src cdi_write_SOURCES = cdi_write.c cdi_write_LDADD = $(top_builddir)/src/libcdi.la # +cdi_write_ens_SOURCES = cdi_write_ens.c +cdi_write_ens_LDADD = $(top_builddir)/src/libcdi.la +# cdi_read_SOURCES = cdi_read.c cdi_read_LDADD = $(top_builddir)/src/libcdi.la # @@ -409,6 +415,9 @@ cdi_read_f2003$(EXEEXT): $(cdi_read_f2003_OBJECTS) $(cdi_read_f2003_DEPENDENCIES cdi_write$(EXEEXT): $(cdi_write_OBJECTS) $(cdi_write_DEPENDENCIES) $(EXTRA_cdi_write_DEPENDENCIES) @rm -f cdi_write$(EXEEXT) $(cdi_write_LINK) $(cdi_write_OBJECTS) $(cdi_write_LDADD) $(LIBS) +cdi_write_ens$(EXEEXT): $(cdi_write_ens_OBJECTS) $(cdi_write_ens_DEPENDENCIES) $(EXTRA_cdi_write_ens_DEPENDENCIES) + @rm -f cdi_write_ens$(EXEEXT) + $(LINK) $(cdi_write_ens_OBJECTS) $(cdi_write_ens_LDADD) $(LIBS) cdi_write_f2003$(EXEEXT): $(cdi_write_f2003_OBJECTS) $(cdi_write_f2003_DEPENDENCIES) $(EXTRA_cdi_write_f2003_DEPENDENCIES) @rm -f cdi_write_f2003$(EXEEXT) $(cdi_write_f2003_LINK) $(cdi_write_f2003_OBJECTS) $(cdi_write_f2003_LDADD) $(LIBS) @@ -422,6 +431,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_copy.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_read.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write_ens.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/examples/cdi_write_reset.c b/examples/cdi_write_reset.c new file mode 100644 index 000000000..e0d7bd8b1 --- /dev/null +++ b/examples/cdi_write_reset.c @@ -0,0 +1,109 @@ +#include <stdio.h> +#include "cdi.h" + +#define nrun 100 // Number of runs +#define nlon 12 // Number of longitudes +#define nlat 6 // Number of latitudes +#define nlev 5 // Number of levels +#define nts 3 // Number of time steps + +static +int run(int irun) +{ + int gridID, zaxisID1, zaxisID2, taxisID; + int vlistID, varID1, varID2, streamID, tsID; + int i, nmiss = 0; + double lons[nlon] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330}; + double lats[nlat] = {-75, -45, -15, 15, 45, 75}; + double levs[nlev] = {101300, 92500, 85000, 50000, 20000}; + double var1[nlon*nlat]; + double var2[nlon*nlat*nlev]; + + // Create a regular lon/lat grid + gridID = gridCreate(GRID_LONLAT, nlon*nlat); + gridDefXsize(gridID, nlon); + gridDefYsize(gridID, nlat); + gridDefXvals(gridID, lons); + gridDefYvals(gridID, lats); + + // Create a surface level Z-axis + zaxisID1 = zaxisCreate(ZAXIS_SURFACE, 1); + + // Create a pressure level Z-axis + zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, nlev); + zaxisDefLevels(zaxisID2, levs); + + // Create a variable list + vlistID = vlistCreate(); + + // Define the variables + varID1 = vlistDefVar(vlistID, gridID, zaxisID1, TIME_VARIABLE); + varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TIME_VARIABLE); + + // Define the variable names + vlistDefVarName(vlistID, varID1, "varname1"); + vlistDefVarName(vlistID, varID2, "varname2"); + + // Create a Time axis + taxisID = taxisCreate(TAXIS_ABSOLUTE); + + // Assign the Time axis to the variable list + vlistDefTaxis(vlistID, taxisID); + + // Create a dataset in netCDF format + streamID = streamOpenWrite("example.nc", FILETYPE_NC); + if ( streamID < 0 ) + { + fprintf(stderr, "%s\n", cdiStringError(streamID)); + return(1); + } + + // Assign the variable list to the dataset + streamDefVlist(streamID, vlistID); + + // Loop over the number of time steps + for ( tsID = 0; tsID < nts; tsID++ ) + { + // Set the verification date to 1985-01-01 + tsID + taxisDefVdate(taxisID, 19850101+tsID); + // Set the verification time to 12:00:00 + taxisDefVtime(taxisID, 120000); + // Define the time step + streamDefTimestep(streamID, tsID); + + // Init var1 and var2 + for ( i = 0; i < nlon*nlat; i++ ) var1[i] = 1.1; + for ( i = 0; i < nlon*nlat*nlev; i++ ) var2[i] = 2.2; + + // Write var1 and var2 + streamWriteVar(streamID, varID1, var1, nmiss); + streamWriteVar(streamID, varID2, var2, nmiss); + } + + fprintf(stderr, "%d gridID=%d, zaxisID1=%d, vlistID=%d, streamID=%d\n", irun, gridID, zaxisID1, vlistID, streamID); + + // Close the output stream + streamClose(streamID); + + // Destroy the objects + vlistDestroy(vlistID); + taxisDestroy(taxisID); + zaxisDestroy(zaxisID1); + zaxisDestroy(zaxisID2); + gridDestroy(gridID); + + return 0; +} + +int main(void) +{ + int irun; + + for ( irun = 0; irun < nrun; ++irun ) + { + run(irun); + cdiReset(); + } + + return 0; +} diff --git a/examples/pio/Makefile.am b/examples/pio/Makefile.am index 93afccc23..42efdf9d2 100644 --- a/examples/pio/Makefile.am +++ b/examples/pio/Makefile.am @@ -8,9 +8,8 @@ if USE_FC noinst_PROGRAMS+=collectData2003 endif -AM_CFLAGS=-I$(top_srcdir)/src $(YAXT_CFLAGS) - -AM_FCFLAGS=$(FPP_INCOPT)$(top_srcdir)/src +AM_CPPFLAGS = -I$(top_srcdir)/src $(YAXT_CFLAGS) +AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src collectData_SOURCES=collectData.c @@ -26,4 +25,4 @@ collectDataNStreams_LDADD=$(top_builddir)/src/libcdi.la compareResourcesArray_SOURCES=compareResourcesArray.c -compareResourcesArray_LDADD=$(top_builddir)/src/libcdi.la \ No newline at end of file +compareResourcesArray_LDADD=$(top_builddir)/src/libcdi.la diff --git a/examples/pio/Makefile.in b/examples/pio/Makefile.in index 0ffbb0c67..c0428835a 100644 --- a/examples/pio/Makefile.in +++ b/examples/pio/Makefile.in @@ -312,7 +312,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -AM_CFLAGS = -I$(top_srcdir)/src $(YAXT_CFLAGS) +AM_CPPFLAGS = -I$(top_srcdir)/src $(YAXT_CFLAGS) AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src collectData_SOURCES = collectData.c collectData_LDADD = $(top_builddir)/src/libcdi.la diff --git a/examples/pio/collectDataNStreams.c b/examples/pio/collectDataNStreams.c index dcc0a0da1..2b34caf69 100644 --- a/examples/pio/collectDataNStreams.c +++ b/examples/pio/collectDataNStreams.c @@ -13,7 +13,7 @@ void hoursPassingHack ( int * vdate, int * vtime, int hoursPassed ) { int sum, days, hours, oldDays; - + xassert ( hoursPassed % 10000 == 0 ); sum = * vtime + hoursPassed; days = sum / 240000; @@ -23,7 +23,7 @@ void hoursPassingHack ( int * vdate, int * vtime, int hoursPassed ) * vtime = hours; * vdate = * vdate + days; } - + void modelRun () { enum { diff --git a/m4/acx_options.m4 b/m4/acx_options.m4 index 25eddf263..aecd0121b 100644 --- a/m4/acx_options.m4 +++ b/m4/acx_options.m4 @@ -267,19 +267,19 @@ AC_ARG_WITH([libpng], [AS_CASE(["$with_libpng"], [no],[AC_MSG_CHECKING([for libpng library]) AC_MSG_RESULT([suppressed])], - [yes],[AC_CHECK_HEADERS([libpng14/png.h]) - AC_SEARCH_LIBS([png_warning],[png14],[AC_DEFINE([HAVE_LIBLIBPNG],[1],[Define to 1 for PNG compression for GRIB2])], + [yes],[AC_CHECK_HEADERS([png.h]) + AC_SEARCH_LIBS([png_warning],[png],[AC_DEFINE([HAVE_LIBLIBPNG],[1],[Define to 1 for PNG compression for GRIB2])], [AC_MSG_ERROR([Could not link to libpng library! Required for GRIB_API])]) - AC_SUBST([LIBPNG_LIBS],[" -lpng14"])], + AC_SUBST([LIBPNG_LIBS],[" -lpng"])], [*],[LIBPNG_ROOT=$with_libpng AS_IF([test -d "$LIBPNG_ROOT"], [LDFLAGS="$LDFLAGS -L$LIBPNG_ROOT/lib" CPPFLAGS="$CPPFLAGS -I$LIBPNG_ROOT/include" AC_SEARCH_LIBS([png_warning], - [png14], + [png], [AC_DEFINE([HAVE_LIBLIBPNG],[1],[Define to 1 for PNG compression for GRIB2])], [AC_MSG_ERROR([Could not link to libpng library! Required for GRIB_API])]) - LIBPNG_LIBS=" -L$LIBPNG_ROOT/lib -lpng14"], + LIBPNG_LIBS=" -L$LIBPNG_ROOT/lib -lpng"], [AC_MSG_ERROR([$LIBPNG_ROOT is not a directory! LIBPNG suppressed])])])], [AC_MSG_CHECKING([for the LIBPNG library]) AC_MSG_RESULT([suppressed])]) diff --git a/m4/ltversion.m4 b/m4/ltversion.m4 index 9c7b5d411..07a8602d4 100644 --- a/m4/ltversion.m4 +++ b/m4/ltversion.m4 @@ -9,15 +9,15 @@ # @configure_input@ -# serial 3293 ltversion.m4 +# serial 3337 ltversion.m4 # This file is part of GNU Libtool -m4_define([LT_PACKAGE_VERSION], [2.4]) -m4_define([LT_PACKAGE_REVISION], [1.3293]) +m4_define([LT_PACKAGE_VERSION], [2.4.2]) +m4_define([LT_PACKAGE_REVISION], [1.3337]) AC_DEFUN([LTVERSION_VERSION], -[macro_version='2.4' -macro_revision='1.3293' +[macro_version='2.4.2' +macro_revision='1.3337' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) diff --git a/src/Makefile.am b/src/Makefile.am index 17c4aaad7..f2c5649e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in # -EXTRA_DIST = make_cdilib mo_cdi.f90 +EXTRA_DIST = cdilib.c mo_cdi.f90 if ENABLE_CDI_LIB lib_LTLIBRARIES = libcdi.la @@ -49,7 +49,9 @@ libcdi_la_SOURCES = \ ieg.h \ ieglib.c \ institution.c \ + institution.h \ model.c \ + model.h \ namespace.c \ namespace.h \ pio.c \ @@ -112,8 +114,11 @@ libcdi_la_SOURCES = \ vlist.c \ vlist.h \ vlist_att.c \ + vlist_att.h \ vlist_var.c \ + vlist_var.h \ zaxis.c \ + zaxis.h \ stream.c \ swap.c diff --git a/src/Makefile.in b/src/Makefile.in index 1dd7d5545..57cb6c4d5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -339,7 +339,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ # -EXTRA_DIST = make_cdilib mo_cdi.f90 +EXTRA_DIST = cdilib.c mo_cdi.f90 @ENABLE_CDI_LIB_TRUE@lib_LTLIBRARIES = libcdi.la @ENABLE_CDI_LIB_TRUE@include_HEADERS = cdi.h cdi.inc @ENABLE_CDI_LIB_FALSE@noinst_LTLIBRARIES = libcdi.la @@ -382,7 +382,9 @@ libcdi_la_SOURCES = \ ieg.h \ ieglib.c \ institution.c \ + institution.h \ model.c \ + model.h \ namespace.c \ namespace.h \ pio.c \ @@ -445,8 +447,11 @@ libcdi_la_SOURCES = \ vlist.c \ vlist.h \ vlist_att.c \ + vlist_att.h \ vlist_var.c \ + vlist_var.h \ zaxis.c \ + zaxis.h \ stream.c \ swap.c diff --git a/src/cdf_int.c b/src/cdf_int.c index 4806a030d..7346fe9fe 100644 --- a/src/cdf_int.c +++ b/src/cdf_int.c @@ -162,8 +162,7 @@ void cdf_close(int ncid) status = nc_close(ncid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -173,8 +172,7 @@ void cdf_redef(int ncid) status = nc_redef(ncid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -184,8 +182,7 @@ void cdf_enddef(int ncid) status = nc_enddef(ncid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -195,8 +192,7 @@ void cdf_sync(int ncid) status = nc_sync(ncid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -210,8 +206,7 @@ void cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp) Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d", ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -224,8 +219,7 @@ void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d name = %s len = %d", ncid, name, len); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -235,11 +229,10 @@ void cdf_inq_dimid(int ncid, const char *name, int *dimidp) status = nc_inq_dimid(ncid, name, dimidp); - if (CDF_Debug || status != NC_NOERR) + if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d name = %s dimid= %d", ncid, name, *dimidp); - if (status != NC_NOERR) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -250,11 +243,9 @@ void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp) status = nc_inq_dim(ncid, dimid, name, lengthp); if ( CDF_Debug || status != NC_NOERR ) - Message("ncid = %d dimid = %d length = %d name = %s", - ncid, dimid, *lengthp, name); + Message("ncid = %d dimid = %d length = %d name = %s", ncid, dimid, *lengthp, name); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -267,8 +258,7 @@ void cdf_inq_dimname(int ncid, int dimid, char *name) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d dimid = %d name = %s", ncid, dimid, name); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -281,8 +271,7 @@ void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d dimid = %d length = %d", ncid, dimid, *lengthp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -325,8 +314,7 @@ void cdf_inq_varid(int ncid, const char *name, int *varidp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d name = %s varid = %d ", ncid, name, *varidp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -339,8 +327,7 @@ void cdf_inq_nvars(int ncid, int *nvarsp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d nvars = %d", ncid, *nvarsp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -355,8 +342,7 @@ void cdf_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, Message("ncid = %d varid = %d ndims = %d xtype = %d natts = %d name = %s", ncid, varid, *ndimsp, *xtypep, *nattsp, name); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -369,8 +355,7 @@ void cdf_inq_varname(int ncid, int varid, char *name) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d name = %s", ncid, varid, name); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -383,8 +368,7 @@ void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d xtype = %s", ncid, varid, *xtypep); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -397,8 +381,7 @@ void cdf_inq_varndims(int ncid, int varid, int *ndimsp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -411,8 +394,7 @@ void cdf_inq_vardimid(int ncid, int varid, int dimids[]) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -422,11 +404,10 @@ void cdf_inq_varnatts(int ncid, int varid, int *nattsp) status = nc_inq_varnatts(ncid, varid, nattsp); - if (CDF_Debug || status != NC_NOERR) + if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d nattsp = %d", ncid, varid, *nattsp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -436,11 +417,10 @@ void cdf_put_var_text(int ncid, int varid, const char *tp) status = nc_put_var_text(ncid, varid, tp); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_put_var_text : %d %d %s \n", ncid, varid, tp); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %s", ncid, varid, tp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -450,11 +430,10 @@ void cdf_put_var_short(int ncid, int varid, const short *sp) status = nc_put_var_short(ncid, varid, sp); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_put_var_short : %d %d %hd \n", ncid, varid, *sp); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %hd", ncid, varid, *sp); - if (status != NC_NOERR) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -464,11 +443,10 @@ void cdf_put_var_int(int ncid, int varid, const int *ip) status = nc_put_var_int(ncid, varid, ip); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_put_var_int : %d %d %d \n", ncid, varid, *ip); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %d", ncid, varid, *ip); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -478,11 +456,10 @@ void cdf_put_var_long(int ncid, int varid, const long *lp) status = nc_put_var_long(ncid, varid, lp); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_put_var_long : %d %d %ld \n", ncid, varid, *lp); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %ld", ncid, varid, *lp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -492,16 +469,15 @@ void cdf_put_var_float(int ncid, int varid, const float *fp) status = nc_put_var_float(ncid, varid, fp); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_put_var_float : %d %d %f \n", ncid, varid, *fp); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %f", ncid, varid, *fp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } -void cdf_put_vara_double(int ncid, int varid, const size_t start[], - const size_t count[], const double *dp) +void cdf_put_vara_double(int ncid, int varid, const size_t start[], + const size_t count[], const double *dp) { int status; @@ -511,7 +487,13 @@ void cdf_put_vara_double(int ncid, int varid, const size_t start[], Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp); if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + { + char name[256]; + nc_inq_varname(ncid, varid, name); + Message("varname = %s", name); + } + + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -525,8 +507,7 @@ void cdf_put_vara_float(int ncid, int varid, const size_t start[], if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d val0 = %f", ncid, varid, *fp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -540,8 +521,7 @@ void cdf_get_vara_int(int ncid, int varid, const size_t start[], if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -555,8 +535,7 @@ void cdf_get_vara_double(int ncid, int varid, const size_t start[], if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -570,8 +549,7 @@ void cdf_get_vara_float(int ncid, int varid, const size_t start[], if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -585,12 +563,11 @@ void cdf_get_vara_text(int ncid, int varid, const size_t start[], if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } -void cdf_put_var_double (int ncid, int varid, const double *dp) +void cdf_put_var_double(int ncid, int varid, const double *dp) { int status; @@ -599,8 +576,7 @@ void cdf_put_var_double (int ncid, int varid, const double *dp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -613,8 +589,7 @@ void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -627,8 +602,7 @@ void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -641,8 +615,7 @@ void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d val = %f", ncid, varid, *dp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -655,8 +628,7 @@ void cdf_get_var_text(int ncid, int varid, char *tp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if (status != NC_NOERR) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -669,8 +641,7 @@ void cdf_get_var_short(int ncid, int varid, short *sp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -683,8 +654,7 @@ void cdf_get_var_int(int ncid, int varid, int *ip) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -697,8 +667,7 @@ void cdf_get_var_long(int ncid, int varid, long *lp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -711,8 +680,7 @@ void cdf_get_var_float(int ncid, int varid, float *fp) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -722,11 +690,10 @@ void cdf_get_var_double(int ncid, int varid, double *dp) status = nc_get_var_double(ncid, varid, dp); - if (CDF_Debug || status != NC_NOERR) + if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d val[0] = %f", ncid, varid, *dp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -737,12 +704,10 @@ void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_copy_att : %d %d %s %d %d\n", ncid_in, varid_out, - name, ncid_out, varid_out); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %s %d %d", ncid_in, varid_out, name, ncid_out, varid_out); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -753,12 +718,11 @@ void cdf_put_att_text(int ncid, int varid, const char *name, size_t len, status = nc_put_att_text(ncid, varid, name, len, tp); - if (CDF_Debug || status != NC_NOERR) + if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d att = %s text = %s", ncid, varid, name, tp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -769,12 +733,10 @@ void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype, status = nc_put_att_int(ncid, varid, name, xtype, len, ip); - if (CDF_Debug || status != NC_NOERR) - Message("ncid = %d varid = %d att = %s val = %d", - ncid, varid, name, *ip); + if ( CDF_Debug || status != NC_NOERR ) + Message("ncid = %d varid = %d att = %s val = %d", ncid, varid, name, *ip); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -785,11 +747,10 @@ void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype, status = nc_put_att_double(ncid, varid, name, xtype, len, dp); - if (CDF_Debug || status != NC_NOERR) - fprintf (stderr, "cdf_put_att_double : %d %d %f \n", ncid, varid, *dp); + if ( CDF_Debug || status != NC_NOERR ) + Message("%d %d %f", ncid, varid, *dp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -799,11 +760,10 @@ void cdf_get_att_text(int ncid, int varid, char *name, char *tp) status = nc_get_att_text(ncid, varid, name, tp); - if (CDF_Debug || status != NC_NOERR) + if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d name = %s", ncid, varid, name); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -813,12 +773,10 @@ void cdf_get_att_int(int ncid, int varid, char *name, int *ip) status = nc_get_att_int(ncid, varid, name, ip); - if (CDF_Debug || status != NC_NOERR) - Message("ncid = %d varid = %d att = %s val = %d", - ncid, varid, name, *ip); + if ( CDF_Debug || status != NC_NOERR ) + Message("ncid = %d varid = %d att = %s val = %d", ncid, varid, name, *ip); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -832,8 +790,7 @@ void cdf_get_att_double(int ncid, int varid, char *name, double *dp) Message("ncid = %d varid = %d att = %s val = %.9g", ncid, varid, name, *dp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -847,8 +804,7 @@ void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -861,8 +817,7 @@ void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -872,12 +827,10 @@ void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp) status = nc_inq_attlen(ncid, varid, name, lenp); - if (CDF_Debug || status != NC_NOERR) - Message("ncid = %d varid = %d name = %s len = %d", - ncid, varid, name, *lenp); + if ( CDF_Debug || status != NC_NOERR ) + Message("ncid = %d varid = %d name = %s len = %d", ncid, varid, name, *lenp); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -887,12 +840,10 @@ void cdf_inq_attname(int ncid, int varid, int attnum, char *name) status = nc_inq_attname(ncid, varid, attnum, name); - if (CDF_Debug || status != NC_NOERR) - Message("ncid = %d varid = %d attnum = %d name = %s", - ncid, varid, attnum, name); + if ( CDF_Debug || status != NC_NOERR ) + Message("ncid = %d varid = %d attnum = %d name = %s", ncid, varid, attnum, name); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } @@ -905,8 +856,7 @@ void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump) if ( CDF_Debug || status != NC_NOERR ) Message("ncid = %d varid = %d", ncid, varid); - if ( status != NC_NOERR ) - Error("%s", nc_strerror(status)); + if ( status != NC_NOERR ) Error("%s", nc_strerror(status)); } #endif diff --git a/src/cdi.h b/src/cdi.h index c0509e8b8..151fcfa00 100644 --- a/src/cdi.h +++ b/src/cdi.h @@ -112,6 +112,11 @@ extern "C" { #define DATATYPE_TXT 253 #define DATATYPE_CPX 254 +/* Chunks */ + +#define CHUNK_AUTO 1 /* use default chunk size */ +#define CHUNK_GRID 2 +#define CHUNK_LINES 3 /* GRID types */ @@ -150,7 +155,10 @@ extern "C" { #define ZAXIS_TOA 13 /* Norminal top of atmosphere */ #define ZAXIS_SEA_BOTTOM 14 /* Sea bottom */ #define ZAXIS_ATMOSPHERE 15 /* Entire atmosphere */ -#define ZAXIS_REFERENCE 16 /* zaxis reference number */ +#define ZAXIS_CLOUD_BASE 16 /* Cloud base level */ +#define ZAXIS_CLOUD_TOP 17 /* Level of cloud tops */ +#define ZAXIS_ISOTHERM_ZERO 18 /* Level of 0o C isotherm */ +#define ZAXIS_REFERENCE 19 /* zaxis reference number */ /* TIME types */ @@ -201,8 +209,8 @@ extern "C" { #define CALENDAR_366DAYS 4 #define CALENDAR_NONE 5 - /* parallel IO IOMode */ - +/* parallel IO IOMode */ + #define PIO_NONE 0 #define PIO_MPI 1 #define PIO_WRITER 2 @@ -211,9 +219,9 @@ extern "C" { #define PIO_MINIOMODE PIO_NONE #define PIO_MAXIOMODE PIO_FPGUARD -#define PIO_MINIOMODEWITHSPECIALPROCS PIO_WRITER - - /* parallel IO routines */ +#define PIO_MINIOMODEWITHSPECIALPROCS PIO_WRITER + +/* parallel IO routines */ #ifdef MPI_VERSION # include <yaxt.h> #endif @@ -236,7 +244,9 @@ int pioInqVarDecoChunk ( int, int ); int pioInqVarDecoOff ( int, int ); void pioNamespaceSetActive ( int ); - /* CDI control routines */ +/* CDI control routines */ + +void cdiReset(void); char *cdiStringError(int cdiErrno); @@ -463,6 +473,9 @@ void vlistDefVarDatatype(int vlistID, int varID, int datatype); /* vlistInqVarDatatype: Get the data type of a Variable */ int vlistInqVarDatatype(int vlistID, int varID); +void vlistDefVarChunkType(int vlistID, int varID, int chunktype); +int vlistInqVarChunkType(int vlistID, int varID); + void vlistDefVarXYZ(int vlistID, int varID, int xyz); int vlistInqVarXYZ(int vlistID, int varID); @@ -530,6 +543,29 @@ int vlistMergedLevel(int vlistID, int varID, int levelID); void vlistDefVarEnsemble(int vlistID, int varID, int ensID, int ensCount, int forecast_type); int vlistInqVarEnsemble(int vlistID, int varID, int *ensID, int *ensCount, int *forecast_type); +/* ---------------------------------- */ +/* Local change: 2013-01-28, FP (DWD) */ +/* ---------------------------------- */ + +/* vlistDefVarIntKey: Set an arbitrary keyword/integer value pair for GRIB API */ +void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value); +/* vlistDefVarDblKey: Set an arbitrary keyword/double value pair for GRIB API */ +void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value); + + /* ---------------------------------- */ + /* Local change: 2013-02-18, FP (DWD) */ + /* ---------------------------------- */ + +/* vlistInqVarRawBegin: Open GRIB record to retrieve raw meta-data in subsequent calls */ +void vlistInqVarRawBegin(int streamID, int varID); +/* vlistInqVarDblKey: raw access to GRIB meta-data */ +double vlistInqVarDblKey(int streamID, const char* name); +/* vlistInqVarIntKey: raw access to GRIB meta-data */ +int vlistInqVarIntKey(int streamID, const char* name); +/* vlistInqVarRawEnd: Free previously opened GRIB record */ +void vlistInqVarRawEnd(int streamID); + + /* VLIST attributes */ /* vlistInqNatts: Get number of variable attributes assigned to this variable */ @@ -567,7 +603,6 @@ void gridDefMask(int gridID, const int *mask_vec); int gridInqMask(int gridID, int *mask_vec); void gridPrint(int gridID, int opt); -int gridSize(void); /* gridCreate: Create a horizontal Grid */ int gridCreate(int gridtype, int size); @@ -766,7 +801,6 @@ int zaxisDuplicate(int zaxisID); void zaxisResize(int zaxisID, int size); void zaxisPrint(int zaxisID); -int zaxisSize(void); /* zaxisDefLevels: Define the levels of a Z-axis */ void zaxisDefLevels(int zaxisID, const double *levels_vec); diff --git a/src/cdi.inc b/src/cdi.inc index 2c129dc4f..62ac35abc 100644 --- a/src/cdi.inc +++ b/src/cdi.inc @@ -1,6 +1,6 @@ ! This file was automatically generated, don't edit! ! -! Fortran interface for CDI library version 1.5.6.1 +! Fortran interface for CDI library version 1.6.0 ! ! Author: ! ------- @@ -182,6 +182,15 @@ INTEGER DATATYPE_CPX PARAMETER (DATATYPE_CPX = 254) ! +! Chunks +! + INTEGER CHUNK_AUTO + PARAMETER (CHUNK_AUTO = 1) + INTEGER CHUNK_GRID + PARAMETER (CHUNK_GRID = 2) + INTEGER CHUNK_LINES + PARAMETER (CHUNK_LINES = 3) +! ! GRID types ! INTEGER GRID_GENERIC @@ -251,8 +260,14 @@ PARAMETER (ZAXIS_SEA_BOTTOM = 14) INTEGER ZAXIS_ATMOSPHERE PARAMETER (ZAXIS_ATMOSPHERE = 15) + INTEGER ZAXIS_CLOUD_BASE + PARAMETER (ZAXIS_CLOUD_BASE = 16) + INTEGER ZAXIS_CLOUD_TOP + PARAMETER (ZAXIS_CLOUD_TOP = 17) + INTEGER ZAXIS_ISOTHERM_ZERO + PARAMETER (ZAXIS_ISOTHERM_ZERO = 18) INTEGER ZAXIS_REFERENCE - PARAMETER (ZAXIS_REFERENCE = 16) + PARAMETER (ZAXIS_REFERENCE = 19) ! ! TIME types ! @@ -402,7 +417,10 @@ ! ! CDI control routines ! - CHARACTER*80 cdiStringError +! cdiReset + EXTERNAL cdiReset + + CHARACTER(80) cdiStringError ! (INTEGER cdiErrno) EXTERNAL cdiStringError @@ -410,7 +428,7 @@ ! (INTEGER debug) EXTERNAL cdiDebug - CHARACTER*80 cdiLibraryVersion + CHARACTER(80) cdiLibraryVersion EXTERNAL cdiLibraryVersion ! cdiPrintVersion @@ -563,11 +581,11 @@ ! INTEGER tsID) EXTERNAL streamInqTimestep - CHARACTER*80 streamFilename + CHARACTER(80) streamFilename ! (INTEGER streamID) EXTERNAL streamFilename - CHARACTER*80 streamFilesuffix + CHARACTER(80) streamFilesuffix ! (INTEGER filetype) EXTERNAL streamFilesuffix @@ -948,6 +966,17 @@ ! INTEGER varID) EXTERNAL vlistInqVarDatatype +! vlistDefVarChunkType +! (INTEGER vlistID, +! INTEGER varID, +! INTEGER chunktype) + EXTERNAL vlistDefVarChunkType + + INTEGER vlistInqVarChunkType +! (INTEGER vlistID, +! INTEGER varID) + EXTERNAL vlistInqVarChunkType + ! vlistDefVarXYZ ! (INTEGER vlistID, ! INTEGER varID, @@ -1172,6 +1201,47 @@ ! INTEGER forecast_type) EXTERNAL vlistInqVarEnsemble +! +! ---------------------------------- +! +! +! Local change: 2013-01-28, FP (DWD) +! +! +! ---------------------------------- +! +! vlistDefVarIntKey +! (INTEGER vlistID, +! INTEGER varID, +! CHARACTER*(*) name, +! INTEGER value) + EXTERNAL vlistDefVarIntKey + +! vlistDefVarDblKey +! (INTEGER vlistID, +! INTEGER varID, +! CHARACTER*(*) name, +! DOUBLEPRECISION value) + EXTERNAL vlistDefVarDblKey + +! +! ---------------------------------- +! +! +! Local change: 2013-02-18, FP (DWD) +! +! +! ---------------------------------- +! +! vlistInqVarRawBegin +! (INTEGER streamID, +! INTEGER varID) + EXTERNAL vlistInqVarRawBegin + +! vlistInqVarRawEnd +! (INTEGER streamID) + EXTERNAL vlistInqVarRawEnd + ! ! VLIST attributes ! @@ -1254,7 +1324,7 @@ ! CHARACTER*(*) gridname) EXTERNAL gridName - CHARACTER*80 gridNamePtr + CHARACTER(80) gridNamePtr ! (INTEGER gridtype) EXTERNAL gridNamePtr @@ -1287,9 +1357,6 @@ ! INTEGER opt) EXTERNAL gridPrint - INTEGER gridSize - EXTERNAL gridSize - INTEGER gridCreate ! (INTEGER gridtype, ! INTEGER size) @@ -1569,7 +1636,7 @@ ! CHARACTER*(*) reference) EXTERNAL gridDefReference - CHARACTER*80 gridInqUUID + CHARACTER(80) gridInqUUID ! (INTEGER gridID, ! CHARACTER*(*) uuid) EXTERNAL gridInqUUID @@ -1752,9 +1819,6 @@ ! (INTEGER zaxisID) EXTERNAL zaxisPrint - INTEGER zaxisSize - EXTERNAL zaxisSize - ! zaxisDefLevels ! (INTEGER zaxisID, ! DOUBLEPRECISION levels_vec) @@ -1786,7 +1850,7 @@ ! CHARACTER*(*) uuid) EXTERNAL zaxisDefUUID - CHARACTER*80 zaxisInqUUID + CHARACTER(80) zaxisInqUUID ! (INTEGER zaxisID, ! CHARACTER*(*) uuid) EXTERNAL zaxisInqUUID @@ -2036,7 +2100,7 @@ ! (INTEGER taxisID) EXTERNAL taxisInqNumavg - CHARACTER*80 tunitNamePtr + CHARACTER(80) tunitNamePtr ! (INTEGER tunitID) EXTERNAL tunitNamePtr @@ -2068,11 +2132,11 @@ ! (INTEGER instID) EXTERNAL institutInqSubcenter - CHARACTER*80 institutInqNamePtr + CHARACTER(80) institutInqNamePtr ! (INTEGER instID) EXTERNAL institutInqNamePtr - CHARACTER*80 institutInqLongnamePtr + CHARACTER(80) institutInqLongnamePtr ! (INTEGER instID) EXTERNAL institutInqLongnamePtr @@ -2099,7 +2163,7 @@ ! (INTEGER modelID) EXTERNAL modelInqGribID - CHARACTER*80 modelInqNamePtr + CHARACTER(80) modelInqNamePtr ! (INTEGER modelID) EXTERNAL modelInqNamePtr @@ -2126,7 +2190,7 @@ ! CHARACTER*(*) tablename) EXTERNAL tableDef - CHARACTER*80 tableInqNamePtr + CHARACTER(80) tableInqNamePtr ! (INTEGER tableID) EXTERNAL tableInqNamePtr @@ -2187,17 +2251,17 @@ ! CHARACTER*(*) units) EXTERNAL tableInqParUnits - CHARACTER*80 tableInqParNamePtr + CHARACTER(80) tableInqParNamePtr ! (INTEGER tableID, ! INTEGER parID) EXTERNAL tableInqParNamePtr - CHARACTER*80 tableInqParLongnamePtr + CHARACTER(80) tableInqParLongnamePtr ! (INTEGER tableID, ! INTEGER parID) EXTERNAL tableInqParLongnamePtr - CHARACTER*80 tableInqParUnitsPtr + CHARACTER(80) tableInqParUnitsPtr ! (INTEGER tableID, ! INTEGER parID) EXTERNAL tableInqParUnitsPtr diff --git a/src/cdiFortran.c b/src/cdiFortran.c index 888335a36..e40ca346f 100644 --- a/src/cdiFortran.c +++ b/src/cdiFortran.c @@ -42,6 +42,9 @@ /* internal data types */ +/* Chunks */ + + /* GRID types */ @@ -92,6 +95,7 @@ FCALLSCSUB1 (pioNamespaceSetActive, PIONAMESPACESETACTIVE, pionamespacesetactive /* CDI control routines */ +FCALLSCSUB0 (cdiReset, CDIRESET, cdireset) FCALLSCFUN1 (STRING, cdiStringError, CDISTRINGERROR, cdistringerror, INT) FCALLSCSUB1 (cdiDebug, CDIDEBUG, cdidebug, INT) FCALLSCFUN0 (STRING, cdiLibraryVersion, CDILIBRARYVERSION, cdilibraryversion) @@ -223,6 +227,8 @@ FCALLSCSUB3 (vlistDefVarCode, VLISTDEFVARCODE, vlistdefvarcode, INT, INT, INT) FCALLSCFUN2 (INT, vlistInqVarCode, VLISTINQVARCODE, vlistinqvarcode, INT, INT) FCALLSCSUB3 (vlistDefVarDatatype, VLISTDEFVARDATATYPE, vlistdefvardatatype, INT, INT, INT) FCALLSCFUN2 (INT, vlistInqVarDatatype, VLISTINQVARDATATYPE, vlistinqvardatatype, INT, INT) +FCALLSCSUB3 (vlistDefVarChunkType, VLISTDEFVARCHUNKTYPE, vlistdefvarchunktype, INT, INT, INT) +FCALLSCFUN2 (INT, vlistInqVarChunkType, VLISTINQVARCHUNKTYPE, vlistinqvarchunktype, INT, INT) FCALLSCSUB3 (vlistDefVarXYZ, VLISTDEFVARXYZ, vlistdefvarxyz, INT, INT, INT) FCALLSCFUN2 (INT, vlistInqVarXYZ, VLISTINQVARXYZ, vlistinqvarxyz, INT, INT) FCALLSCFUN2 (INT, vlistInqVarNumber, VLISTINQVARNUMBER, vlistinqvarnumber, INT, INT) @@ -265,6 +271,28 @@ FCALLSCFUN3 (INT, vlistMergedLevel, VLISTMERGEDLEVEL, vlistmergedlevel, INT, INT FCALLSCSUB5 (vlistDefVarEnsemble, VLISTDEFVARENSEMBLE, vlistdefvarensemble, INT, INT, INT, INT, INT) FCALLSCFUN5 (INT, vlistInqVarEnsemble, VLISTINQVARENSEMBLE, vlistinqvarensemble, INT, INT, PINT, PINT, PINT) +/* ---------------------------------- */ + + +/* Local change: 2013-01-28, FP (DWD) */ + + +/* ---------------------------------- */ + +FCALLSCSUB4 (vlistDefVarIntKey, VLISTDEFVARINTKEY, vlistdefvarintkey, INT, INT, STRING, INT) +FCALLSCSUB4 (vlistDefVarDblKey, VLISTDEFVARDBLKEY, vlistdefvardblkey, INT, INT, STRING, DOUBLE) + +/* ---------------------------------- */ + + +/* Local change: 2013-02-18, FP (DWD) */ + + +/* ---------------------------------- */ + +FCALLSCSUB2 (vlistInqVarRawBegin, VLISTINQVARRAWBEGIN, vlistinqvarrawbegin, INT, INT) +FCALLSCSUB1 (vlistInqVarRawEnd, VLISTINQVARRAWEND, vlistinqvarrawend, INT) + /* VLIST attributes */ FCALLSCFUN3 (INT, vlistInqNatts, VLISTINQNATTS, vlistinqnatts, INT, INT, PINT) @@ -287,7 +315,6 @@ FCALLSCFUN2 (INT, gridInqMaskGME, GRIDINQMASKGME, gridinqmaskgme, INT, PINT) FCALLSCSUB2 (gridDefMask, GRIDDEFMASK, griddefmask, INT, PINT) FCALLSCFUN2 (INT, gridInqMask, GRIDINQMASK, gridinqmask, INT, PINT) FCALLSCSUB2 (gridPrint, GRIDPRINT, gridprint, INT, INT) -FCALLSCFUN0 (INT, gridSize, GRIDSIZE, gridsize) FCALLSCFUN2 (INT, gridCreate, GRIDCREATE, gridcreate, INT, INT) FCALLSCSUB1 (gridDestroy, GRIDDESTROY, griddestroy, INT) FCALLSCFUN1 (INT, gridDuplicate, GRIDDUPLICATE, gridduplicate, INT) @@ -395,7 +422,6 @@ FCALLSCFUN1 (INT, zaxisInqSize, ZAXISINQSIZE, zaxisinqsize, INT) FCALLSCFUN1 (INT, zaxisDuplicate, ZAXISDUPLICATE, zaxisduplicate, INT) FCALLSCSUB2 (zaxisResize, ZAXISRESIZE, zaxisresize, INT, INT) FCALLSCSUB1 (zaxisPrint, ZAXISPRINT, zaxisprint, INT) -FCALLSCFUN0 (INT, zaxisSize, ZAXISSIZE, zaxissize) FCALLSCSUB2 (zaxisDefLevels, ZAXISDEFLEVELS, zaxisdeflevels, INT, PDOUBLE) FCALLSCSUB2 (zaxisInqLevels, ZAXISINQLEVELS, zaxisinqlevels, INT, PDOUBLE) FCALLSCSUB3 (zaxisDefLevel, ZAXISDEFLEVEL, zaxisdeflevel, INT, INT, DOUBLE) diff --git a/src/cdi_error.c b/src/cdi_error.c index e09220814..0488bd4fd 100644 --- a/src/cdi_error.c +++ b/src/cdi_error.c @@ -2,6 +2,7 @@ # include "config.h" #endif +#include <stdio.h> #include <string.h> #include <errno.h> #include "cdi.h" diff --git a/src/cgribex.h b/src/cgribex.h index 21683165d..dc3b599b7 100644 --- a/src/cgribex.h +++ b/src/cgribex.h @@ -8,7 +8,10 @@ /* GRIB1 Level Types */ #define GRIB1_LTYPE_SURFACE 1 -#define GRIB1_LTYPE_TOA 8 +#define GRIB1_LTYPE_CLOUDBASE 2 +#define GRIB1_LTYPE_CLOUDTOP 3 +#define GRIB1_LTYPE_ISOTHERM0 4 +#define GRIB1_LTYPE_TOA 8 #define GRIB1_LTYPE_SEA_BOTTOM 9 #define GRIB1_LTYPE_ATMOSPHERE 10 #define GRIB1_LTYPE_99 99 @@ -212,7 +215,7 @@ void gribPrintGDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe void gribPrintBMS(int nrec, long recpos, long recsize, unsigned char *gribbuffer); void gribPrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffer); void gribCheck1(int nrec, long recpos, long recsize, unsigned char *gribbuffer); -void gribRepair1(int nrec, long recpos, long recsize, unsigned char *gribbuffer); +void gribRepair1(int nrec, long recsize, unsigned char *gribbuffer); int grib1Sections(unsigned char *gribbuffer, long recsize, unsigned char **pdsp, unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp); diff --git a/src/cgribexlib.c b/src/cgribexlib.c index 75b6e1fc8..9eca8f429 100644 --- a/src/cgribexlib.c +++ b/src/cgribexlib.c @@ -1,7 +1,7 @@ -/* Automatically generated by m214003 at 2012-06-14, do not edit */ +/* Automatically generated by m214003 at 2013-03-05, do not edit */ -/* CGRIBEXLIB_VERSION="1.5.3" */ +/* CGRIBEXLIB_VERSION="1.6.0" */ #ifdef _ARCH_PWR6 #pragma options nostrict @@ -16,48 +16,6 @@ #include <stdarg.h> #include <sys/types.h> -//#undef _GET_X86_COUNTER -//#undef _GET_IBM_COUNTER -//#undef _ARCH_PWR6 - -#if defined(__GNUC__) && (__GNUC__ >= 4) -#elif defined(__ICC) && (__ICC >= 1100) -#else -#define DISABLE_SIMD -#endif - -#ifdef DISABLE_SIMD -#ifndef ENABLE_AVX -#undef __AVX__ -#endif -#ifndef ENABLE_SSE2 -#undef __SSE2__ -#endif -#endif - -#ifdef _GET_IBM_COUNTER -#include <libhpc.h> -#endif - -#ifdef __AVX__ -#include <float.h> -#include <stdint.h> -#include <inttypes.h> -#include <immintrin.h> -#ifdef _GET_X86_COUNTER -#include <x86intrin.h> -#endif -#else -#ifdef __SSE2__ -#include <float.h> -#include <stdint.h> -#include <inttypes.h> -#include <emmintrin.h> -#ifdef _GET_X86_COUNTER -#include <x86intrin.h> -#endif -#endif -#endif #include "file.h" #include "dmemory.h" @@ -107,6 +65,7 @@ # define VECTORCODE #endif + #if defined (VECTORCODE) #if defined (INT32) # define GRIBPACK unsigned INT32 @@ -405,9 +364,11 @@ void gribDecode(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, } #endif /* _GRIBENCODE_H */ +#include <stdio.h> +#include <math.h> -double _pow2tab[158] = { +const double const _pow2tab[158] = { /* pow(2.0, 0.0) */ 1.0, /* pow(2.0, 1.0) */ 2.0, /* pow(2.0, 2.0) */ 4.0, @@ -569,7 +530,7 @@ double _pow2tab[158] = { }; -double _pow16tab[71] = { +const double const _pow16tab[71] = { /* pow(16.0, 0.0) */ 1.0, /* pow(16.0, 1.0) */ 16.0, /* pow(16.0, 2.0) */ 256.0, @@ -676,14 +637,26 @@ double intpow2(int x) } //#undef _GET_X86_COUNTER //#undef _GET_IBM_COUNTER +//#undef _GET_MACH_COUNTER //#undef _ARCH_PWR6 #if defined(__GNUC__) && (__GNUC__ >= 4) #elif defined(__ICC) && (__ICC >= 1100) +#elif defined(__clang__) #else #define DISABLE_SIMD #endif +#if defined _GET_IBM_COUNTER +#include <libhpc.h> +#elif defined _GET_X86_COUNTER +#include <x86intrin.h> +#elif defined _GET_MACH_COUNTER +#include <mach/mach_time.h> +#endif + +//#define DISABLE_SIMD + #ifdef DISABLE_SIMD #ifndef ENABLE_AVX #undef __AVX__ @@ -693,27 +666,27 @@ double intpow2(int x) #endif #endif -#ifdef _GET_IBM_COUNTER -#endif - -#ifdef __AVX__ -#ifdef _GET_X86_COUNTER -#endif -#else -#ifdef __SSE2__ -#ifdef _GET_X86_COUNTER -#endif -#endif +#if defined __AVX__ +#include <float.h> +#include <stdint.h> +#include <inttypes.h> +#include <immintrin.h> +#elif defined __SSE2__ +#include <float.h> +#include <stdint.h> +#include <inttypes.h> +#include <emmintrin.h> #endif +#if defined __AVX__ -#ifdef __AVX__ static -void avx_minmax_val(const double *restrict buf, long nframes, double *min, double *max) +void avx_minmax_val(const double *restrict buf, size_t nframes, double *min, double *max) { + double fmin[4], fmax[4]; __m256d current_max, current_min, work; - // load max and min values into all four slots of the XMM registers + // load max and min values into all four slots of the YMM registers current_min = _mm256_set1_pd(*min); current_max = _mm256_set1_pd(*max); @@ -729,24 +702,26 @@ void avx_minmax_val(const double *restrict buf, long nframes, double *min, doubl } while (nframes >= 16) { - // use 64 byte prefetch? - __builtin_prefetch(buf+64,0,0); // for GCC 4.3.2+ + + (void) _mm_prefetch(buf+8, _MM_HINT_NTA); work = _mm256_load_pd(buf); current_min = _mm256_min_pd(current_min, work); current_max = _mm256_max_pd(current_max, work); buf += 4; - __builtin_prefetch(buf+64,0,0); // for GCC 4.3.2+ + work = _mm256_load_pd(buf); current_min = _mm256_min_pd(current_min, work); current_max = _mm256_max_pd(current_max, work); buf += 4; - __builtin_prefetch(buf+64,0,0); // for GCC 4.3.2+ + + (void) _mm_prefetch(buf+8, _MM_HINT_NTA); + work = _mm256_load_pd(buf); current_min = _mm256_min_pd(current_min, work); current_max = _mm256_max_pd(current_max, work); buf += 4; - __builtin_prefetch(buf+64,0,0); // for GCC 4.3.2+ + work = _mm256_load_pd(buf); current_min = _mm256_min_pd(current_min, work); current_max = _mm256_max_pd(current_max, work); @@ -775,28 +750,32 @@ void avx_minmax_val(const double *restrict buf, long nframes, double *min, doubl // find min & max value through shuffle tricks work = current_min; - work = _mm256_shuffle_pd(work, work, _MM_SHUFFLE(2, 3, 0, 1)); + work = _mm256_shuffle_pd(work, work, 5); work = _mm256_min_pd (work, current_min); current_min = work; - work = _mm256_shuffle_pd(work, work, _MM_SHUFFLE(1, 0, 3, 2)); + work = _mm256_permute2f128_pd(work, work, 1); work = _mm256_min_pd (work, current_min); - _mm256_store_pd(min, work); + _mm256_storeu_pd(fmin, work); + work = current_max; - work = _mm256_shuffle_pd(work, work, _MM_SHUFFLE(2, 3, 0, 1)); + work = current_max; + work = _mm256_shuffle_pd(work, work, 5); work = _mm256_max_pd (work, current_max); current_max = work; - work = _mm256_shuffle_pd(work, work, _MM_SHUFFLE(1, 0, 3, 2)); + work = _mm256_permute2f128_pd(work, work, 1); work = _mm256_max_pd (work, current_max); - _mm256_store_pd(max, work); + _mm256_storeu_pd(fmax, work); + + *min = fmin[0]; + *max = fmax[0]; return; } -#else +#elif defined __SSE2__ -#ifdef __SSE2__ static -void sse2_minmax_val(const double *restrict buf, long nframes, double *min, double *max) +void sse2_minmax_val(const double *restrict buf, size_t nframes, double *min, double *max) { __m128d current_max, current_min, work; @@ -817,7 +796,7 @@ void sse2_minmax_val(const double *restrict buf, long nframes, double *min, doub while (nframes >= 8) { // use 64 byte prefetch for double octetts - __builtin_prefetch(buf+64,0,0); // for GCC 4.3.2 + + // __builtin_prefetch(buf+64,0,0); // for GCC 4.3.2 + work = _mm_load_pd(buf); current_min = _mm_min_pd(current_min, work); @@ -869,30 +848,31 @@ void sse2_minmax_val(const double *restrict buf, long nframes, double *min, doub return; } -#endif #endif static -void minmax_val(const double *restrict data, long datasize, double *fmin, double *fmax) +void minmax_val(const double *restrict data, long idatasize, double *fmin, double *fmax) { -#ifdef _GET_X86_COUNTER +#if defined _GET_X86_COUNTER || defined _GET_MACH_COUNTER uint64_t start_minmax, end_minmax; #endif + size_t datasize = idatasize; - if ( datasize < 1 ) return; + if ( idatasize < 1 ) return; #ifdef _GET_X86_COUNTER start_minmax = _rdtsc(); #endif +#ifdef _GET_MACH_COUNTER + start_minmax = mach_absolute_time(); +#endif -#ifdef __AVX__ +#if defined __AVX__ avx_minmax_val(data, datasize, fmin, fmax); -#else - -#ifdef __SSE2__ +#elif defined __SSE2__ sse2_minmax_val(data, datasize, fmin, fmax); @@ -907,9 +887,9 @@ void minmax_val(const double *restrict data, long datasize, double *fmin, double hpmStart(1, "minmax fsel"); #endif { - long i, j; - long residual = datasize % __UNROLL_DEPTH_1; - long ofs = datasize - residual; + size_t i, j; + size_t residual = datasize % __UNROLL_DEPTH_1; + size_t ofs = datasize - residual; double register dmin[__UNROLL_DEPTH_1]; double register dmax[__UNROLL_DEPTH_1]; @@ -952,7 +932,7 @@ void minmax_val(const double *restrict data, long datasize, double *fmin, double hpmStart(1, "minmax base"); #endif { - long i; + size_t i; #if defined (CRAY) #pragma _CRI ivdep @@ -976,58 +956,182 @@ void minmax_val(const double *restrict data, long datasize, double *fmin, double #endif #endif // _ARCH_PWR6 && original loop -#endif // __SSE2__ -#endif // __AVX__ +#endif // SIMD +#if defined _GET_X86_COUNTER || defined _GET_MACH_COUNTER #ifdef _GET_X86_COUNTER end_minmax = _rdtsc(); -#ifdef __AVX__ - printf("AVX cycles:: %" PRIu64 "\n", +#endif +#ifdef _GET_MACH_COUNTER + end_minmax = mach_absolute_time(); +#endif +#if defined __AVX__ + printf("AVX minmax cycles:: %" PRIu64 "\n", end_minmax-start_minmax); -#else -#ifdef __SSE2__ - printf("SSE2 cycles:: %" PRIu64 "\n", + fprintf (stderr, "AVX min: %lf max: %lf\n", *fmin, *fmax); +#elif defined __SSE2__ + printf("SSE2 minmax cycles:: %" PRIu64 "\n", end_minmax-start_minmax); + fprintf (stderr, "SSE2 min: %lf max: %lf\n", *fmin, *fmax); #else - printf("loop cycles:: %" PRIu64 "\n", + printf("loop minmax cycles:: %" PRIu64 "\n", end_minmax-start_minmax); -#endif + fprintf (stderr, "loop min: %lf max: %lf\n", *fmin, *fmax); #endif #endif return; } +//#undef _GET_X86_COUNTER +//#undef _GET_MACH_COUNTER //#undef _GET_IBM_COUNTER +//#undef _ARCH_PWR6 - -#ifdef _GET_IBM_COUNTER -#endif +#include <stdint.h> #if defined(__GNUC__) && (__GNUC__ >= 4) #elif defined(__ICC) && (__ICC >= 1100) +#elif defined(__clang__) #else #define DISABLE_SIMD #endif +#if defined _GET_IBM_COUNTER +#include <libhpc.h> +#elif defined _GET_X86_COUNTER +#include <x86intrin.h> +#elif defined _GET_MACH_COUNTER +#include <mach/mach_time.h> +#endif + +//#define DISABLE_SIMD + #ifdef DISABLE_SIMD +#ifndef ENABLE_AVX +#undef __AVX__ +#endif #ifndef ENABLE_SSE4_1 #undef __SSE4_1__ #endif #endif -// SSE4.1 -#if 0 -#ifdef __SSE4_1__ +#if defined __AVX__ +#include <immintrin.h> +#elif defined __SSE4_1__ +#include <smmintrin.h> +#endif + +#if defined __AVX__ + +static +void avx_encode_double_array_2byte(size_t datasize, + unsigned char * restrict lGrib, + const double * restrict data, + double zref, double factor, size_t *gz) +{ + size_t i, j; + const double *dval = data; + __m128i *sgrib = (__m128i *) (lGrib+(*gz)); + + const __m128i swap = _mm_set_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); + + const __m256d c0 = _mm256_set1_pd(zref); + const __m256d c1 = _mm256_set1_pd(factor); + const __m256d c2 = _mm256_set1_pd(0.5); + + __m256d d0, d3, d2, d1; + __m128i i0, i1, i2, i3; + __m128i s0, s1; + + for (i = 0; i < datasize; i += 16) + { + (void) _mm_prefetch(dval+8, _MM_HINT_NTA); + //_____________________________________________________________________________ + + d0 = _mm256_loadu_pd (dval); + d0 = _mm256_sub_pd (d0, c0); + d0 = _mm256_mul_pd (d0, c1); + d0 = _mm256_add_pd (d0, c2); + + i0 = _mm256_cvttpd_epi32 (d0); + + //_____________________________________________________________________________ + + d1 = _mm256_loadu_pd (dval+4); + d1 = _mm256_sub_pd (d1, c0); + d1 = _mm256_mul_pd (d1, c1); + d1 = _mm256_add_pd (d1, c2); + + i1 = _mm256_cvttpd_epi32 (d1); + + //_____________________________________________________________________________ + + s0 = _mm_packus_epi32(i0, i1); + s0 = _mm_shuffle_epi8 (s0, swap); + (void) _mm_storeu_si128 (sgrib, s0); + + //_____________________________________________________________________________ + + (void) _mm_prefetch(dval+16, _MM_HINT_NTA); + + //_____________________________________________________________________________ + + d2 = _mm256_loadu_pd (dval+8); + d2 = _mm256_sub_pd (d2, c0); + d2 = _mm256_mul_pd (d2, c1); + d2 = _mm256_add_pd (d2, c2); + + i2 = _mm256_cvttpd_epi32 (d2); + + //_____________________________________________________________________________ + + d3 = _mm256_loadu_pd (dval+12); + d3 = _mm256_sub_pd (d3, c0); + d3 = _mm256_mul_pd (d3, c1); + d3 = _mm256_add_pd (d3, c2); + + i3 = _mm256_cvttpd_epi32 (d3); + + //_____________________________________________________________________________ + + s1 = _mm_packus_epi32(i2, i3); + s1 = _mm_shuffle_epi8 (s1, swap); + (void) _mm_storeu_si128 (sgrib+1, s1); + + //_____________________________________________________________________________ + + dval += 16; + sgrib += 2; + } + + if (i != datasize) + { + uint16_t ui16; + i -= 16; + for ( j = i; j < datasize; j++ ) + { + ui16 = (uint16_t) ((data[j] - zref) * factor + 0.5); + lGrib[*gz+2*j ] = ui16 >> 8; + lGrib[*gz+2*j+1] = ui16; + } + } + + *gz += 2*datasize; + + return; +} + +#elif defined __SSE4_1__ static -void sse41_encode_double_array_2byte(long datasize, +void sse41_encode_double_array_2byte(size_t datasize, unsigned char * restrict lGrib, const double * restrict data, - double zref, double factor, long * restrict gz) + double zref, double factor, size_t *gz) { - long i; + size_t i, j; const double *dval = data; - __m128i *sgrib = (__m128i *) lGrib; + __m128i *sgrib = (__m128i *) (lGrib+(*gz)); const __m128i swap = _mm_set_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); @@ -1044,12 +1148,12 @@ void sse41_encode_double_array_2byte(long datasize, (void) _mm_prefetch(dval+8, _MM_HINT_NTA); //_____________________________________________________________________________ - d0 = _mm_load_pd (dval); + d0 = _mm_loadu_pd (dval); d0 = _mm_sub_pd (d0, c0); d0 = _mm_mul_pd (d0, c1); d0 = _mm_add_pd (d0, c2); - d4 = _mm_load_pd (dval+2); + d4 = _mm_loadu_pd (dval+2); d4 = _mm_sub_pd (d4, c0); d4 = _mm_mul_pd (d4, c1); d4 = _mm_add_pd (d4, c2); @@ -1057,28 +1161,28 @@ void sse41_encode_double_array_2byte(long datasize, i0 = _mm_cvttpd_epi32 (d0); i4 = _mm_cvttpd_epi32 (d4); i0 = _mm_unpacklo_epi64 (i0, i4); - + //_____________________________________________________________________________ - d1 = _mm_load_pd (dval+4); + d1 = _mm_loadu_pd (dval+4); d1 = _mm_sub_pd (d1, c0); d1 = _mm_mul_pd (d1, c1); d1 = _mm_add_pd (d1, c2); - d4 = _mm_load_pd (dval+6); + d4 = _mm_loadu_pd (dval+6); d4 = _mm_sub_pd (d4, c0); d4 = _mm_mul_pd (d4, c1); d4 = _mm_add_pd (d4, c2); i1 = _mm_cvttpd_epi32 (d1); - i4 = _mm_cvttpd_epi32 (d4); + i4 = _mm_cvttpd_epi32 (d4); i1 = _mm_unpacklo_epi64 (i1, i4); //_____________________________________________________________________________ s0 = _mm_packus_epi32(i0, i1); s0 = _mm_shuffle_epi8 (s0, swap); - (void) _mm_stream_si128 (sgrib, s0); + (void) _mm_storeu_si128 (sgrib, s0); //_____________________________________________________________________________ @@ -1086,12 +1190,12 @@ void sse41_encode_double_array_2byte(long datasize, //_____________________________________________________________________________ - d2 = _mm_load_pd (dval+8); + d2 = _mm_loadu_pd (dval+8); d2 = _mm_sub_pd (d2, c0); d2 = _mm_mul_pd (d2, c1); d2 = _mm_add_pd (d2, c2); - d4 = _mm_load_pd (dval+10); + d4 = _mm_loadu_pd (dval+10); d4 = _mm_sub_pd (d4, c0); d4 = _mm_mul_pd (d4, c1); d4 = _mm_add_pd (d4, c2); @@ -1099,15 +1203,15 @@ void sse41_encode_double_array_2byte(long datasize, i2 = _mm_cvttpd_epi32 (d2); i4 = _mm_cvttpd_epi32 (d4); i2 = _mm_unpacklo_epi64 (i2, i4); - + //_____________________________________________________________________________ - d3 = _mm_load_pd (dval+12); + d3 = _mm_loadu_pd (dval+12); d3 = _mm_sub_pd (d3, c0); d3 = _mm_mul_pd (d3, c1); d3 = _mm_add_pd (d3, c2); - d4 = _mm_load_pd (dval+14); + d4 = _mm_loadu_pd (dval+14); d4 = _mm_sub_pd (d4, c0); d4 = _mm_mul_pd (d4, c1); d4 = _mm_add_pd (d4, c2); @@ -1120,7 +1224,7 @@ void sse41_encode_double_array_2byte(long datasize, s1 = _mm_packus_epi32(i2, i3); s1 = _mm_shuffle_epi8 (s1, swap); - (void) _mm_stream_si128 (sgrib+1, s1); + (void) _mm_storeu_si128 (sgrib+1, s1); //_____________________________________________________________________________ @@ -1128,16 +1232,30 @@ void sse41_encode_double_array_2byte(long datasize, sgrib += 2; } + if (i != datasize) + { + uint16_t ui16; + i -= 16; + for ( j = i; j < datasize; j++ ) + { + ui16 = (uint16_t) ((data[j] - zref) * factor + 0.5); + lGrib[*gz+2*j ] = ui16 >> 8; + lGrib[*gz+2*j+1] = ui16; + } + } + + *gz += 2*datasize; + return; } -#endif // SSE4.1 -#endif + +#endif // SIMD variants static -void encode_double_array_common(int numBits, long packStart, long datasize, GRIBPACK *lGrib, - const double *data, double zref, double factor, long *gz) +void encode_double_array_common(int numBits, size_t packStart, size_t datasize, GRIBPACK *lGrib, + const double *data, double zref, double factor, size_t *gz) { - long i, z = *gz; + size_t i, z = *gz; unsigned int ival; int cbits, jbits; unsigned int c; @@ -1184,13 +1302,17 @@ void encode_double_array_common(int numBits, long packStart, long datasize, GRIB } static -void encode_double_array_byte(int numBits, long packStart, long datasize, +void encode_double_array_byte(int numBits, size_t packStart, size_t datasize, GRIBPACK *restrict lGrib, const double *restrict data, - double zref, double factor, long *restrict gz) + double zref, double factor, size_t *gz) { - long i, z = *gz; - unsigned long ival; +#if defined _GET_X86_COUNTER || defined _GET_MACH_COUNTER + uint64_t start_minmax, end_minmax; +#endif + + uint32_t ui32; + size_t i, z = *gz; double tmp; data += packStart; @@ -1201,7 +1323,8 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, #ifdef _GET_IBM_COUNTER hpmStart(2, "pack 8 bit base"); #endif -#if defined (CRAY) + +#if defined (CRAY) #pragma _CRI ivdep #elif defined (SX) #pragma vdir nodep @@ -1211,10 +1334,10 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, for ( i = 0; i < datasize; i++ ) { tmp = ((data[i] - zref) * factor + 0.5); - ival = (unsigned long) tmp; - lGrib[z ] = ival; + lGrib[z ] = (uint16_t) tmp; z++; } + #ifdef _GET_IBM_COUNTER hpmStop(2); #endif @@ -1223,14 +1346,24 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, { #ifdef _GET_IBM_COUNTER hpmStart(3, "pack 16 bit base"); +#elif defined _GET_X86_COUNTER + start_minmax = _rdtsc(); +#elif defined _GET_MACH_COUNTER + start_minmax = mach_absolute_time(); #endif -#if 0 +#if defined __AVX__ + + avx_encode_double_array_2byte(datasize, lGrib, data, zref, factor, &z); + +#elif defined __SSE4_1__ sse41_encode_double_array_2byte(datasize, lGrib, data, zref, factor, &z); #else + uint16_t ui16; + #if defined (CRAY) #pragma _CRI ivdep #elif defined (SX) @@ -1241,13 +1374,31 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, for ( i = 0; i < datasize; i++ ) { tmp = ((data[i] - zref) * factor + 0.5); - ival = (unsigned long) tmp; - lGrib[z ] = ival >> 8; - lGrib[z+1] = ival; + ui16 = (uint16_t) tmp; + lGrib[z ] = ui16 >> 8; + lGrib[z+1] = ui16; z += 2; } #endif +#if defined _GET_X86_COUNTER || defined _GET_MACH_COUNTER +#if defined _GET_X86_COUNTER + end_minmax = _rdtsc(); +#elif defined _GET_MACH_COUNTER + end_minmax = mach_absolute_time(); +#endif +#if defined __AVX__ + printf("AVX encoding cycles:: %" PRIu64 "\n", + end_minmax-start_minmax); +#elif defined __SSE4_1__ + printf("SSE 4.1 encoding cycles:: %" PRIu64 "\n", + end_minmax-start_minmax); +#else + printf("loop encoding cycles:: %" PRIu64 "\n", + end_minmax-start_minmax); +#endif +#endif + #ifdef _GET_IBM_COUNTER hpmStop(3); #endif @@ -1257,6 +1408,7 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, #ifdef _GET_IBM_COUNTER hpmStart(4, "pack 24 bit base"); #endif + #if defined (CRAY) #pragma _CRI ivdep #elif defined (SX) @@ -1267,12 +1419,13 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, for ( i = 0; i < datasize; i++ ) { tmp = ((data[i] - zref) * factor + 0.5); - ival = (unsigned long) tmp; - lGrib[z ] = ival >> 16; - lGrib[z+1] = ival >> 8; - lGrib[z+2] = ival; + ui32 = (uint32_t) tmp; + lGrib[z ] = ui32 >> 16; + lGrib[z+1] = ui32 >> 8; + lGrib[z+2] = ui32; z += 3; } + #ifdef _GET_IBM_COUNTER hpmStop(4); #endif @@ -1282,6 +1435,7 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, #ifdef _GET_IBM_COUNTER hpmStart(5, "pack 32 bit base"); #endif + #if defined (CRAY) #pragma _CRI ivdep #elif defined (SX) @@ -1292,13 +1446,14 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, for ( i = 0; i < datasize; i++ ) { tmp = ((data[i] - zref) * factor + 0.5); - ival = (unsigned long) tmp; - lGrib[z ] = ival >> 24; - lGrib[z+1] = ival >> 16; - lGrib[z+2] = ival >> 8; - lGrib[z+3] = ival; + ui32 = (uint32_t) tmp; + lGrib[z ] = ui32 >> 24; + lGrib[z+1] = ui32 >> 16; + lGrib[z+2] = ui32 >> 8; + lGrib[z+3] = ui32; z += 4; } + #ifdef _GET_IBM_COUNTER hpmStop(5); #endif @@ -1320,238 +1475,689 @@ void encode_double_array_byte(int numBits, long packStart, long datasize, } static -void encode_double_array_unrolled(int numBits, long packStart, long datasize, +void encode_double_array_unrolled(int numBits, size_t packStart, size_t datasize, GRIBPACK *restrict lGrib, const double *restrict data, - double zref, double factor, long *restrict gz) + double zref, double factor, size_t *gz) { U_BYTEORDER; - long i, j, z = *gz; - double tmp; + size_t i, j, z = *gz; #ifdef _ARCH_PWR6 #define __UNROLL_DEPTH_2 8 #else #define __UNROLL_DEPTH_2 8 #endif + size_t residual; + size_t ofs; + double dval[__UNROLL_DEPTH_2]; + unsigned long ival; data += packStart; datasize -= packStart; + residual = datasize % __UNROLL_DEPTH_2; + ofs = datasize - residual; - { - long residual = datasize % __UNROLL_DEPTH_2; - long ofs = datasize - residual; - double dval[__UNROLL_DEPTH_2]; - unsigned long ival; + // reducing FP operations to single FMA is slowing down on pwr6 ... - // reducing FP operations to single FMA is slowing down on pwr6 ... + if ( numBits == 8 ) + { + unsigned char *cgrib = (unsigned char *) (lGrib + z); +#ifdef _GET_IBM_COUNTER + hpmStart(2, "pack 8 bit unrolled"); +#endif + for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + dval[j] = ((data[i+j] - zref) * factor + 0.5); + } + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + *cgrib++ = (unsigned long) dval[j]; + } + z += __UNROLL_DEPTH_2; + } + for (j = 0; j < residual; j++) + { + dval[j] = ((data[ofs+j] - zref) * factor + 0.5); + } + for (j = 0; j < residual; j++) + { + *cgrib++ = (unsigned long) dval[j]; + } + z += residual; - if ( numBits == 8 ) - { - unsigned char *cgrib = (unsigned char *) (lGrib + z); #ifdef _GET_IBM_COUNTER - hpmStart(2, "pack 8 bit unrolled"); + hpmStop(2); #endif - for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - dval[j] = ((data[i+j] - zref) * factor + 0.5); - } - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - *cgrib = (unsigned long) dval[j]; - cgrib++; - z++; - } - } - for (j = 0; j < residual; j++) - { - dval[j] = ((data[ofs+j] - zref) * factor + 0.5); - } - for (j = 0; j < residual; j++) - { - *cgrib = (unsigned long) dval[j]; - cgrib++; - z++; - } + } + else if ( numBits == 16 ) + { + unsigned short *sgrib = (unsigned short *) (lGrib + z); #ifdef _GET_IBM_COUNTER - hpmStop(2); + hpmStart(3, "pack 16 bit unrolled"); #endif - } - else if ( numBits == 16 ) - { - unsigned short *sgrib = (unsigned short *) (lGrib + z); + for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + dval[j] = ((data[i+j] - zref) * factor + 0.5); + } + if ( IS_BIGENDIAN() ) + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + *sgrib++ = (unsigned long) dval[j]; + } + z += 2*__UNROLL_DEPTH_2; + } + else + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + ival = (unsigned long) dval[j]; + lGrib[z ] = ival >> 8; + lGrib[z+1] = ival; + z += 2; + } + } + } + for (j = 0; j < residual; j++) + { + dval[j] = ((data[ofs+j] - zref) * factor + 0.5); + } + if ( IS_BIGENDIAN() ) + { + for (j = 0; j < residual; j++) + { + *sgrib++ = (unsigned long) dval[j]; + } + z += 2*residual; + } + else + { + for (j = 0; j < residual; j++) + { + ival = (unsigned long) dval[j]; + lGrib[z ] = ival >> 8; + lGrib[z+1] = ival; + z += 2; + } + } #ifdef _GET_IBM_COUNTER - hpmStart(3, "pack 16 bit unrolled"); + hpmStop(3); #endif - for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - dval[j] = ((data[i+j] - zref) * factor + 0.5); - } - if ( IS_BIGENDIAN() ) - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - *sgrib = (unsigned long) dval[j]; - sgrib++; - z += 2; - } - } - else - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - ival = (unsigned long) dval[j]; - lGrib[z ] = ival >> 8; - lGrib[z+1] = ival; - z += 2; - } - } - } - for (j = 0; j < residual; j++) - { - dval[j] = ((data[ofs+j] - zref) * factor + 0.5); - } - if ( IS_BIGENDIAN() ) - { - for (j = 0; j < residual; j++) - { - *sgrib = (unsigned long) dval[j]; - sgrib++; - z += 2; - } - } - else - { - for (j = 0; j < residual; j++) - { - ival = (unsigned long) dval[j]; - lGrib[z ] = ival >> 8; - lGrib[z+1] = ival; - z += 2; - } - } + } + else if ( numBits == 24 ) + { #ifdef _GET_IBM_COUNTER - hpmStop(3); + hpmStart(4, "pack 24 bit unrolled"); #endif - } - else if ( numBits == 24 ) - { + for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + dval[j] = ((data[i+j] - zref) * factor + 0.5); + } + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + ival = (unsigned long) dval[j]; + lGrib[z ] = ival >> 16; + lGrib[z+1] = ival >> 8; + lGrib[z+2] = ival; + z += 3; + } + } + for (j = 0; j < residual; j++) + { + dval[j] = ((data[ofs+j] - zref) * factor + 0.5); + } + for (j = 0; j < residual; j++) + { + ival = (unsigned long) dval[j]; + lGrib[z ] = ival >> 16; + lGrib[z+1] = ival >> 8; + lGrib[z+2] = ival; + z += 3; + } #ifdef _GET_IBM_COUNTER - hpmStart(4, "pack 24 bit unrolled"); + hpmStop(4); #endif - for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - dval[j] = ((data[i+j] - zref) * factor + 0.5); - } - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - ival = (unsigned long) dval[j]; - lGrib[z ] = ival >> 16; - lGrib[z+1] = ival >> 8; - lGrib[z+2] = ival; - z += 3; - } - } - for (j = 0; j < residual; j++) - { - dval[j] = ((data[ofs+j] - zref) * factor + 0.5); - } - for (j = 0; j < residual; j++) - { - ival = (unsigned long) dval[j]; - lGrib[z ] = ival >> 16; - lGrib[z+1] = ival >> 8; - lGrib[z+2] = ival; - z += 3; - } + } + else if ( numBits == 32 ) + { #ifdef _GET_IBM_COUNTER - hpmStop(4); + hpmStart(5, "pack 32 bit unrolled"); #endif - } - else if ( numBits == 32 ) - { + unsigned int *igrib = (unsigned int *) (lGrib + z); + for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + dval[j] = ((data[i+j] - zref) * factor + 0.5); + } + if ( IS_BIGENDIAN() ) + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + *igrib = (unsigned long) dval[j]; + igrib++; + z += 4; + } + } + else + { + for (j = 0; j < __UNROLL_DEPTH_2; j++) + { + ival = (unsigned long) dval[j]; + lGrib[z ] = ival >> 24; + lGrib[z+1] = ival >> 16; + lGrib[z+2] = ival >> 8; + lGrib[z+3] = ival; + z += 4; + } + } + } + for (j = 0; j < residual; j++) + { + dval[j] = ((data[ofs+j] - zref) * factor + 0.5); + } + if ( IS_BIGENDIAN() ) + { + for (j = 0; j < residual; j++) + { + *igrib = (unsigned long) dval[j]; + igrib++; + z += 4; + } + } + else + { + for (j = 0; j < residual; j++) + { + ival = (unsigned long) dval[j]; + lGrib[z ] = ival >> 24; + lGrib[z+1] = ival >> 16; + lGrib[z+2] = ival >> 8; + lGrib[z+3] = ival; + z += 4; + } + } #ifdef _GET_IBM_COUNTER - hpmStart(5, "pack 32 bit unrolled"); + hpmStop(5); #endif - unsigned int *igrib = (unsigned int *) (lGrib + z); - for ( i = 0; i < datasize - residual; i += __UNROLL_DEPTH_2 ) - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - dval[j] = ((data[i+j] - zref) * factor + 0.5); - } - if ( IS_BIGENDIAN() ) - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - *igrib = (unsigned long) dval[j]; - igrib++; - z += 4; - } - } - else - { - for (j = 0; j < __UNROLL_DEPTH_2; j++) - { - ival = (unsigned long) dval[j]; - lGrib[z ] = ival >> 24; - lGrib[z+1] = ival >> 16; - lGrib[z+2] = ival >> 8; - lGrib[z+3] = ival; - z += 4; - } - } - } - for (j = 0; j < residual; j++) - { - dval[j] = ((data[ofs+j] - zref) * factor + 0.5); - } - if ( IS_BIGENDIAN() ) - { - for (j = 0; j < residual; j++) - { - *igrib = (unsigned long) dval[j]; - igrib++; - z += 4; - } - } - else - { - for (j = 0; j < residual; j++) - { - ival = (unsigned long) dval[j]; - lGrib[z ] = ival >> 24; - lGrib[z+1] = ival >> 16; - lGrib[z+2] = ival >> 8; - lGrib[z+3] = ival; - z += 4; - } - } -#ifdef _GET_IBM_COUNTER - hpmStop(5); + } + else if ( numBits > 0 && numBits <= 32 ) + { + encode_double_array_common(numBits, 0, datasize, lGrib, data, zref, factor, &z); + } + else if ( numBits == 0 ) + { + } + else + { + Error("Unimplemented packing factor %d!", numBits); + } + + *gz = z; +#undef __UNROLL_DEPTH_2 +} +//#undef _GET_X86_COUNTER +//#undef _GET_MACH_COUNTER +//#undef _GET_IBM_COUNTER +//#undef _ARCH_PWR6 + +#if defined _GET_IBM_COUNTER +#include <libhpc.h> +#elif defined _GET_X86_COUNTER +#include <x86intrin.h> +#elif defined _GET_MACH_COUNTER +#include <mach/mach_time.h> #endif + +#define __STDC_FORMAT_MACROS +#include <inttypes.h> + +/* +#if ((__GNUC__ >= 4) || (__ICC >= 1100) || defined (__clang__)) +#define _ENABLE_SIMD +#include <immintrin.h> +#undef __AVX +#ifdef __AVX__ +#define _ENABLE_AVX +#elif __SSE4_1__ +#define _ENABLE_SSE4_1 +#endif +#endif +*/ + +#undef _ENABLE_AVX +#undef _ENABLE_SSE4_1 + +#if defined _ENABLE_AVX + +static +void avx_decode_double_array_2byte(size_t datasize, const unsigned char * restrict igrib, + double * restrict fpdata, double fmin, double zscale) +{ + size_t i, j; + size_t nframes = datasize; + size_t residual; + size_t ofs; + + double dval; + + double *data = fpdata; + __m128i *sgrib; + + __m128i mask = _mm_set_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); + + __m256d ymm0 = _mm256_set1_pd(fmin); + __m256d ymm1 = _mm256_set1_pd(zscale); + + __m128i xmm0, xmm1, xmm2, xmm3; + __m256d ymm2, ymm3; + + i = -1; + while ( ((unsigned long) data) % 32 != 0 && datasize > 0) + { + i++; + dval = (((int)igrib[2*i] << 8) | (int)igrib[2*i+1]); + fpdata[i] = fmin + zscale * dval; + data++; + nframes--; + } + + if (i == -1) i = 0; + sgrib = (__m128i *) (igrib+i); + + while (nframes >= 16) + { + xmm0 = _mm_loadu_si128((__m128i *) sgrib); + xmm0 = _mm_shuffle_epi8(xmm0, mask); + xmm1 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(1, 0, 3, 2)); + xmm2 = _mm_cvtepu16_epi32(xmm0); + xmm3 = _mm_cvtepu16_epi32(xmm1); + + ymm2 = _mm256_cvtepi32_pd(xmm2); + ymm2 = _mm256_add_pd(_mm256_mul_pd(ymm2, ymm1), ymm0); + (void) _mm256_stream_pd(data, ymm2); + ymm3 = _mm256_cvtepi32_pd(xmm3); + ymm3 = _mm256_add_pd(_mm256_mul_pd(ymm3, ymm1), ymm0); + (void) _mm256_stream_pd(data+4, ymm3); + + xmm0 = _mm_loadu_si128((__m128i *) sgrib + 1); + xmm0 = _mm_shuffle_epi8(xmm0, mask); + xmm1 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(1, 0, 3, 2)); + xmm2 = _mm_cvtepu16_epi32(xmm0); + xmm3 = _mm_cvtepu16_epi32(xmm1); + + ymm2 = _mm256_cvtepi32_pd(xmm2); + ymm2 = _mm256_add_pd(_mm256_mul_pd(ymm2, ymm1), ymm0); + (void) _mm256_stream_pd(data+8, ymm2); + ymm3 = _mm256_cvtepi32_pd(xmm3); + ymm3 = _mm256_add_pd(_mm256_mul_pd(ymm3, ymm1), ymm0); + (void) _mm256_stream_pd(data+12, ymm3); + + data += 16; + sgrib += 2; + nframes -= 16; + } + + residual = nframes; + ofs = datasize - residual; + for ( j = 0; j < residual; j++ ) + { + dval = (((int)igrib[2*(ofs+j)] << 8) | (int)igrib[2*(ofs+j)+1]); + fpdata[ofs+j] = fmin + zscale * dval; + } + + return; +} + +#elif defined _ENABLE_SSE4_1 + +static +void sse41_decode_double_array_2byte(size_t datasize, const unsigned char * restrict igrib, + double * restrict fpdata, double fmin, double zscale) +{ + size_t i, j; + size_t nframes = datasize; + size_t residual; + size_t ofs; + + double dval; + + double *data = fpdata; + __m128i *sgrib; + + __m128i mask = _mm_set_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); + __m128d dmm8 = _mm_set1_pd(fmin); + __m128d dmm9 = _mm_set1_pd(zscale); + + __m128i xmm4, xmm5; + __m128i xmm6, xmm7; + + __m128d dmm0, dmm1, dmm2, dmm3; + __m128d dmm4, dmm5, dmm6, dmm7; + + i = -1; + while ( ((unsigned long) data) % 32 != 0 && datasize > 0) + { + i++; + dval = (((int)igrib[2*i] << 8) | (int)igrib[2*i+1]); + fpdata[i] = fmin + zscale * dval; + data++; + nframes--; + } + + if (i == -1) i = 0; + sgrib = (__m128i *) (igrib+i); + + while (nframes >= 16) + { + xmm5 = _mm_loadu_si128((__m128i *) sgrib); + xmm5 = _mm_shuffle_epi8(xmm5, mask); + xmm4 = _mm_srli_si128(xmm5, 8); + xmm6 = _mm_cvtepu16_epi32(xmm5); + dmm0 = _mm_cvtepi32_pd(xmm6); + dmm0 = _mm_add_pd(_mm_mul_pd(dmm0, dmm9), dmm8); + (void) _mm_stream_pd(data, dmm0); + xmm7 = _mm_srli_si128(xmm6, 8); + dmm1 = _mm_cvtepi32_pd(xmm7); + dmm1 = _mm_add_pd(_mm_mul_pd(dmm1, dmm9), dmm8); + (void) _mm_stream_pd(data+2, dmm1); + xmm6 = _mm_cvtepu16_epi32(xmm4); + dmm2 = _mm_cvtepi32_pd(xmm6); + dmm2 = _mm_add_pd(_mm_mul_pd(dmm2, dmm9), dmm8); + (void) _mm_stream_pd(data+4, dmm2); + xmm7 = _mm_srli_si128(xmm6, 8); + dmm3 = _mm_cvtepi32_pd(xmm7); + dmm3 = _mm_add_pd(_mm_mul_pd(dmm3, dmm9), dmm8); + (void) _mm_stream_pd(data+6, dmm3); + + xmm5 = _mm_loadu_si128((__m128i *) sgrib+1); + xmm5 = _mm_shuffle_epi8(xmm5, mask); + xmm4 = _mm_srli_si128(xmm5, 8); + xmm6 = _mm_cvtepu16_epi32(xmm5); + dmm4 = _mm_cvtepi32_pd(xmm6); + dmm4 = _mm_add_pd(_mm_mul_pd(dmm4, dmm9), dmm8); + (void) _mm_stream_pd(data+8, dmm4); + xmm7 = _mm_srli_si128(xmm6, 8); + dmm5 = _mm_cvtepi32_pd(xmm7); + dmm5 = _mm_add_pd(_mm_mul_pd(dmm5, dmm9), dmm8); + (void) _mm_stream_pd(data+10, dmm5); + xmm6 = _mm_cvtepu16_epi32(xmm4); + dmm6 = _mm_cvtepi32_pd(xmm6); + dmm6 = _mm_add_pd(_mm_mul_pd(dmm6, dmm9), dmm8); + (void) _mm_stream_pd(data+12, dmm6); + xmm7 = _mm_srli_si128(xmm6, 8); + dmm7 = _mm_cvtepi32_pd(xmm7); + dmm7 = _mm_add_pd(_mm_mul_pd(dmm7, dmm9), dmm8); + (void) _mm_stream_pd(data+14, dmm7); + + data += 16; + sgrib += 2; + nframes -= 16; + } + + residual = nframes; + ofs = datasize - residual; + for ( j = 0; j < residual; j++ ) + { + dval = (((int)igrib[2*(ofs+j)] << 8) | (int)igrib[2*(ofs+j)+1]); + fpdata[ofs+j] = fmin + zscale * dval; + } + + return; +} + +#endif + +static +void decode_double_array_common(const unsigned char * restrict igrib, long jlend, int NumBits, + double fmin, double zscale, double * restrict fpdata) +{ + /* code from wgrib routine BDS_unpack */ + const unsigned char *bits = igrib; + unsigned int jmask; + long i; + unsigned int tbits = 0; + int n_bits = NumBits; + int t_bits = 0; + + jmask = (1 << n_bits) - 1; + for ( i = 0; i < jlend; i++ ) + { + if (n_bits - t_bits > 8) + { + tbits = (tbits << 16) | (bits[0] << 8) | (bits[1]); + bits += 2; + t_bits += 16; + } + + while ( t_bits < n_bits ) + { + tbits = (tbits * 256) + *bits++; + t_bits += 8; + } + t_bits -= n_bits; + fpdata[i] = (tbits >> t_bits) & jmask; + } + /* at least this vectorizes :) */ + for ( i = 0; i < jlend; i++ ) + fpdata[i] = fmin + zscale*fpdata[i]; +} + +static unsigned int mask[] = {0,1,3,7,15,31,63,127,255}; +static double shift[9] = {1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0}; + +static +void decode_double_array_common2(const unsigned char * restrict igrib, long jlend, int NumBits, + double fmin, double zscale, double * restrict fpdata) +{ + /* code from wgrib routine BDS_unpack */ + const unsigned char *bits = igrib; + long i; + int n_bits = NumBits; + int c_bits, j_bits; + double jj; + + /* older unoptimized code, not often used */ + c_bits = 8; + for ( i = 0; i < jlend; i++ ) + { + jj = 0.0; + j_bits = n_bits; + while (c_bits <= j_bits) + { + if (c_bits == 8) + { + jj = jj * 256.0 + (double) (*bits++); + j_bits -= 8; + } + else + { + jj = (jj * shift[c_bits]) + (double) (*bits & mask[c_bits]); + bits++; + j_bits -= c_bits; + c_bits = 8; + } + } + + if (j_bits) + { + c_bits -= j_bits; + jj = (jj * shift[j_bits]) + (double) ((*bits >> c_bits) & mask[j_bits]); + } + + fpdata[i] = fmin + zscale*jj; + } +} + +static +void decode_double_array_byte(const unsigned char * restrict igrib, long jlend, int numBits, + double fmin, double zscale, double * restrict fpdata) +{ +#if defined _GET_X86_COUNTER || defined _GET_MACH_COUNTER + uint64_t start_decode, end_decode; +#endif + + long i; + double dval; +#if defined (VECTORCODE) + GRIBPACK *lgrib = NULL; + + if ( numBits%8 == 0 ) + { + long jlenc = jlend * numBits / 8; + if ( jlenc > 0 ) + { + lgrib = (GRIBPACK *) malloc(jlenc*sizeof(GRIBPACK)); + if ( lgrib == NULL ) SysError("No Memory!"); + + (void) UNPACK_GRIB(igrib, lgrib, jlenc, -1L); + } + } + + if ( numBits == 0 ) + { + for ( i = 0; i < jlend; i++ ) + fpdata[i] = fmin; + } + else if ( numBits == 8 ) + for ( i = 0; i < jlend; i++ ) + { + dval = (int)lgrib[i]; + fpdata[i] = fmin + zscale * dval; } - else if ( numBits > 0 && numBits <= 32 ) + else if ( numBits == 16 ) + for ( i = 0; i < jlend; i++ ) { - encode_double_array_common(numBits, 0, datasize, lGrib, - data, zref, factor, &z); + dval = (((int)lgrib[2*i ] << 8) + (int)lgrib[2*i+1]); + fpdata[i] = fmin + zscale * dval; } - else if ( numBits == 0 ) + else if ( numBits == 24 ) + for ( i = 0; i < jlend; i++ ) { + dval = (((int)lgrib[3*i ] << 16) + ((int)lgrib[3*i+1] << 8) + + (int)lgrib[3*i+2]); + fpdata[i] = fmin + zscale * dval; } - else + else if ( numBits == 32 ) + for ( i = 0; i < jlend; i++ ) { - Error("Unimplemented packing factor %d!", numBits); + dval = (((unsigned int)lgrib[4*i ] << 24) + ((unsigned int)lgrib[4*i+1] << 16) + + ((unsigned int)lgrib[4*i+2] << 8) + (unsigned int)lgrib[4*i+3]); + fpdata[i] = fmin + zscale * dval; } - } + else if ( numBits <= 25 ) + { + decode_double_array_common(igrib, jlend, numBits, fmin, zscale, fpdata); + } + else if ( numBits > 25 && numBits < 32 ) + { + decode_double_array_common2(igrib, jlend, numBits, fmin, zscale, fpdata); + } + else + { + Error("Unimplemented packing factor %d!", numBits); + } - *gz = z; -#undef __UNROLL_DEPTH_2 + if ( lgrib ) free(lgrib); + +#else + if ( numBits == 0 ) + { + for ( i = 0; i < jlend; i++ ) + fpdata[i] = fmin; + } + else if ( numBits == 8 ) + for ( i = 0; i < jlend; i++ ) + { + dval = (int)igrib[i]; + fpdata[i] = fmin + zscale * dval; + } + else if ( numBits == 16 ) + { +#ifdef _GET_IBM_COUNTER + hpmStart(6, "unpack 16 bit base"); +#elif defined _GET_X86_COUNTER + start_decode = _rdtsc(); +#elif defined _GET_MACH_COUNTER + start_decode = mach_absolute_time(); +#endif + +#if defined _ENABLE_AVX + printf("AVX selected ...\n"); + avx_decode_double_array_2byte((size_t) jlend, igrib, fpdata, fmin, zscale); +#elif defined _ENABLE_SSE4_1 + printf("SSE4 selected ...\n"); + sse41_decode_double_array_2byte((size_t) jlend, igrib, fpdata, fmin, zscale); +#else + for ( i = 0; i < jlend; i++ ) + { + dval = (((int)igrib[2*i ] << 8) | (int)igrib[2*i+1]); + fpdata[i] = fmin + zscale * dval; + } +#endif + +#if defined _GET_X86_COUNTER || defined _GET_MACH_COUNTER +#if defined _GET_X86_COUNTER + end_decode = _rdtsc(); +#elif defined _GET_MACH_COUNTER + end_decode = mach_absolute_time(); +#endif +#if defined _ENABLE_AVX + printf("AVX encoding cycles:: %" PRIu64 "\n", + end_decode-start_decode); +#elif defined _ENABLE_SSE4_1 + printf("SSE 4.1 encoding cycles:: %" PRIu64 "\n", + end_decode-start_decode); +#else + printf("loop encoding cycles:: %" PRIu64 "\n", + end_decode-start_decode); +#endif +#endif + +#ifdef _GET_IBM_COUNTER + hpmStop(6); +#endif + } + else if ( numBits == 24 ) + for ( i = 0; i < jlend; i++ ) + { + dval = (((int)igrib[3*i ] << 16) + ((int)igrib[3*i+1] << 8) + + (int)igrib[3*i+2]); + fpdata[i] = fmin + zscale * dval; + } + else if ( numBits == 32 ) + for ( i = 0; i < jlend; i++ ) + { + dval = (((unsigned int)igrib[4*i ] << 24) + ((unsigned int)igrib[4*i+1] << 16) + + ((unsigned int)igrib[4*i+2] << 8) + (unsigned int)igrib[4*i+3]); + fpdata[i] = fmin + zscale * dval; + } + else if ( numBits <= 25 ) + { + decode_double_array_common(igrib, jlend, numBits, fmin, zscale, fpdata); + } + else if ( numBits > 25 && numBits < 32 ) + { + decode_double_array_common2(igrib, jlend, numBits, fmin, zscale, fpdata); + } + else + { + Error("Unimplemented packing factor %d!", numBits); + } +#endif +} + +static +void decode_double_array_unrolled(const unsigned char * restrict igrib, long jlend, int numBits, + double fmin, double zscale, double * restrict fpdata) +{ + decode_double_array_byte(igrib, jlend, numBits, fmin, zscale, fpdata); } #define NINT(x) ((x) < 0 ? (int)((x)-.5) : (int)((x)+.5)) @@ -1625,12 +2231,12 @@ void confp3(double pval, int *kexp, int *kmant, int kbits, int kround) - replace 1.0 / pow(16.0, (double)(iexp - 70)) by rpow16m70tab[iexp] */ - double zval, rpowref; + double rpowref; double zref, zeps; int iexp, isign; int iround; - extern int CGRIBEX_Debug; - extern double _pow16tab[71]; + // extern int CGRIBEX_Debug; + extern const double const _pow16tab[71]; /* ----------------------------------------------------------------- */ /* Section 1 . Initialise */ @@ -1789,19 +2395,20 @@ void confp3(double pval, int *kexp, int *kmant, int kbits, int kround) /* ----------------------------------------------------------------- */ LABEL900: - + /* if ( CGRIBEX_Debug ) { + double zval; + Message("Conversion type parameter = %4d", kround); Message("Original number = %30.20f", pval); zval = decfp2(*kexp, *kmant); Message("Converted to %30.20f", zval); - Message("Sign = %3d, Exponent = %3d, Mantissa = %12d", - isign, iexp, *kmant); + Message("Sign = %3d, Exponent = %3d, Mantissa = %12d", isign, iexp, *kmant); } - + */ return; } /* confp3 */ @@ -1875,14 +2482,14 @@ double decfp2(int kexp, int kmant) double pval; int iexp, isign; - extern int CGRIBEX_Debug; - extern double _pow16tab[71]; + //extern int CGRIBEX_Debug; + extern const double const _pow16tab[71]; /* ----------------------------------------------------------------- */ /* Section 1 . Convert value of 0.0. Ignore sign bit. */ /* ----------------------------------------------------------------- */ - if ( CGRIBEX_Debug ) Message("KEXP = %d KMANT = %d", kexp, kmant); + //if ( CGRIBEX_Debug ) Message("KEXP = %d KMANT = %d", kexp, kmant); /* if ( (kexp == 128 || kexp == 0) && kmant == 0 ) */ @@ -1926,10 +2533,14 @@ double decfp2(int kexp, int kmant) LABEL900: - if ( CGRIBEX_Debug ) Message("Returned value = %f", pval); + //if ( CGRIBEX_Debug ) Message("Returned value = %f", pval); return (pval); } /* decfp2 */ +#include <stdio.h> +#include <stdint.h> +#include <string.h> +#include <stdarg.h> @@ -2006,8 +2617,9 @@ void gribDateTime(int *isec1, int *date, int *time) { static int lprint = TRUE; int ryear, rmonth, rday, rhour, rminute, second; - int time_period = 0; - int julday, secofday, addsec; + int julday, secofday; + int64_t addsec = 0; + int64_t time_period = 0; int century; extern int grib_calendar; @@ -2070,6 +2682,7 @@ void gribDateTime(int *isec1, int *date, int *time) gprintf(__func__, "Time unit %d unsupported", ISEC1_TimeUnit); lprint = FALSE; } + break; } julday_add_seconds(addsec, &julday, &secofday); @@ -2109,12 +2722,12 @@ gribExDP(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, { int yfunc = hoper; - if ( yfunc == 'D' || yfunc == 'J' || yfunc == 'R' ) - gribDecode(isec0, isec1, isec2, fsec2, isec3, + if ( yfunc == 'C' ) + gribEncode(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4, klenp, kgrib, kleng, kword, yfunc, kret); - else if ( yfunc == 'C' ) - gribEncode(isec0, isec1, isec2, fsec2, isec3, + else if ( yfunc == 'D' || yfunc == 'J' || yfunc == 'R' ) + gribDecode(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4, klenp, kgrib, kleng, kword, yfunc, kret); else if ( yfunc == 'V' ) @@ -2254,6 +2867,8 @@ void gribSetRefSP(float refval) void gribSetValueCheck(int vcheck) { } +#include <string.h> +#include <math.h> @@ -3741,6 +4356,7 @@ void gribPrintSec4Wave(int *isec4) fprintf(grprsm, "%20.10f\n", *ptemp); } } +#include <string.h> int BitsPerInt = (int) (sizeof(int) * 8); @@ -4332,7 +4948,7 @@ int encodeBDS(GRIBPACK *lGrib, long *gribLen, int decscale, int *isec2, int *ise /* Uwe Schulzweida, 11/04/2003 : Check that number of bits per value is not exceeded */ /* Uwe Schulzweida, 6/05/2003 : Copy result to fpval to prevent integer overflow */ - long z = *gribLen; + size_t z = *gribLen; long i, jloop; int numBits; int ival; @@ -4352,7 +4968,7 @@ int encodeBDS(GRIBPACK *lGrib, long *gribLen, int decscale, int *isec2, int *ise double jpepsln = 1.0e-12; /* -----> tolerance used to check equality */ /* of floating point numbers - needed */ /* on some platforms (eg vpp700, linux) */ - extern double _pow2tab[158]; + extern const double const _pow2tab[158]; extern int CGRIBEX_Const; /* 1: Don't pack constant fields on regular grids */ if ( isec2 ) @@ -4612,7 +5228,7 @@ void gribEncode(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, int bmsIncluded; size_t len; GRIBPACK *lGrib; - long datstart, datsize, bdsstart, bdsend; + long datstart, datsize, bdsstart; int status = 0; grsdef(); @@ -4684,7 +5300,6 @@ void gribEncode(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, return; } - bdsend = gribLen; encodeES(lGrib, &gribLen, bdsstart); if ( (size_t) gribLen > kleng*sizeof(int) ) @@ -4707,6 +5322,9 @@ void gribEncode(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, *kret = status; } +#include <string.h> + + @@ -4993,7 +5611,7 @@ int decodePDS(unsigned char *pds, int *isec0, int *isec1) static int decodeGDS(unsigned char *gds, int *isec0, int *isec2, double *fsec2, int *numGridVals, int dfunc) { - /* int imisng; */ + /* int imisng = 0; */ int ReducedGrid = FALSE, VertCoorTab = FALSE; int locnv = 0, locnl; int jlenl; @@ -5009,8 +5627,6 @@ int decodeGDS(unsigned char *gds, int *isec0, int *isec2, double *fsec2, int *n *numGridVals = 0; - /* imisng = 0; */ - memset(isec2, 0, 22*sizeof(int)); gdsLen = GDS_Len; @@ -5110,318 +5726,120 @@ int decodeGDS(unsigned char *gds, int *isec0, int *isec2, double *fsec2, int *n else if ( ISEC2_GridType == GRIB1_GTYPE_LATLON || ISEC2_GridType == GRIB1_GTYPE_LATLON_ROT || ISEC2_GridType == GRIB1_GTYPE_LATLON_STR || - ISEC2_GridType == GRIB1_GTYPE_LATLON_ROTSTR ) - { - /* - iret = decodeGDS_LL(gds, gdspos, isec0, isec2, imisng); - */ - } - else if ( ISEC2_GridType == GRIB1_GTYPE_LCC ) - { - ISEC2_NumLon = GDS_NumLon; - ISEC2_NumLat = GDS_NumLat; - *numGridVals = ISEC2_NumLon*ISEC2_NumLat; - ISEC2_FirstLat = GDS_FirstLat; - ISEC2_FirstLon = GDS_FirstLon; - ISEC2_ResFlag = GDS_ResFlag; - ISEC2_Lambert_Lov = GDS_Lambert_Lov; - ISEC2_Lambert_dx = GDS_Lambert_dx; - ISEC2_Lambert_dy = GDS_Lambert_dy; - ISEC2_Lambert_LatS1 = GDS_Lambert_LatS1; - ISEC2_Lambert_LatS2 = GDS_Lambert_LatS2; - ISEC2_Lambert_LatSP = GDS_Lambert_LatSP; - ISEC2_Lambert_LonSP = GDS_Lambert_LonSP; - ISEC2_Lambert_ProjFlag = GDS_Lambert_ProjFlag; - ISEC2_ScanFlag = GDS_ScanFlag; - } - else if ( ISEC2_GridType == GRIB1_GTYPE_SPECTRAL ) - { - ISEC2_PentaJ = GDS_PentaJ; /* Truncation */ - ISEC2_PentaK = GDS_PentaK; - ISEC2_PentaM = GDS_PentaM; - ISEC2_RepType = GDS_RepType; - ISEC2_RepMode = GDS_RepMode; - *numGridVals = (ISEC2_PentaJ+1)*(ISEC2_PentaJ+2); - isec2[ 6] = 0; - isec2[ 7] = 0; - isec2[ 8] = 0; - isec2[ 9] = 0; - isec2[10] = 0; - /* - iret = decodeGDS_SH(gds, gdspos, isec0, isec2, imisng); - */ - } - else if ( ISEC2_GridType == GRIB1_GTYPE_GME ) - { - ISEC2_GME_NI2 = GDS_GME_NI2; - ISEC2_GME_NI3 = GDS_GME_NI3; - ISEC2_GME_ND = GDS_GME_ND; - ISEC2_GME_NI = GDS_GME_NI; - ISEC2_GME_AFlag = GDS_GME_AFlag; - ISEC2_GME_LatPP = GDS_GME_LatPP; - ISEC2_GME_LonPP = GDS_GME_LonPP; - ISEC2_GME_LonMPL = GDS_GME_LonMPL; - ISEC2_GME_BFlag = GDS_GME_BFlag; - *numGridVals = (ISEC2_GME_NI+1)*(ISEC2_GME_NI+1)*10; - /* - iret = decodeGDS_TR(gds, gdspos, isec0, isec2, imisng); - */ - } - else - { - ISEC2_NumLon = GDS_NumLon; - ISEC2_NumLat = GDS_NumLat; - *numGridVals = ISEC2_NumLon*ISEC2_NumLat; - Message("Gridtype %d unsupported", ISEC2_GridType); - } - - /* vertical coordinate parameters for hybrid levels. */ - /* get number of vertical coordinate parameters, if any. */ - - ISEC2_NumVCP = 0; - - isec2[17] = 0; - isec2[18] = 0; - - if ( VertCoorTab == TRUE ) - { - if ( ISEC0_GRIB_Version == 0 ) - { - locnv = 32; - ISEC2_NumVCP = (gdsLen - 32) >> 2; - } - else - { - locnv = GDS_PVPL - 1; - ISEC2_NumVCP = GDS_NV; - } -#if defined (SX) - lGribLen = 4*ISEC2_NumVCP; - lgrib = (GRIBPACK *) malloc(lGribLen*sizeof(GRIBPACK)); - - igrib = &gds[locnv]; - if ( ISEC2_NumVCP > 0 ) (void) UNPACK_GRIB(igrib, lgrib, lGribLen, -1L); - for ( i = 0; i < ISEC2_NumVCP; i++ ) - { - iexp = (lgrib[4*i ]); - imant =((lgrib[4*i+1]) << 16) + - ((lgrib[4*i+2]) << 8) + - (lgrib[4*i+3]); - fsec2[10+i] = POW_2_M24 * imant * pow(16.0, (double)(iexp - 64)); - } - - free(lgrib); -#else - for ( i = 0; i < ISEC2_NumVCP; i++ ) - { - iexp = (gds[locnv+4*i ]); - imant =((gds[locnv+4*i+1]) << 16) + - ((gds[locnv+4*i+2]) << 8) + - (gds[locnv+4*i+3]); - fsec2[10+i] = decfp2(iexp,imant); - } -#endif - } - - return (gdsLen); -} - -static -void decode_double_array_common(unsigned char *igrib, long jlend, int NumBits, - double fmin, double zscale, double *fpdata) -{ - /* code from wgrib routine BDS_unpack */ - unsigned char *bits = igrib; - unsigned int jmask; - long i; - unsigned int tbits = 0; - int n_bits = NumBits; - int t_bits = 0; - - jmask = (1 << n_bits) - 1; - for ( i = 0; i < jlend; i++ ) - { - if (n_bits - t_bits > 8) - { - tbits = (tbits << 16) | (bits[0] << 8) | (bits[1]); - bits += 2; - t_bits += 16; - } - - while ( t_bits < n_bits ) - { - tbits = (tbits * 256) + *bits++; - t_bits += 8; - } - t_bits -= n_bits; - fpdata[i] = (tbits >> t_bits) & jmask; - } - /* at least this vectorizes :) */ - for ( i = 0; i < jlend; i++ ) - fpdata[i] = fmin + zscale*fpdata[i]; -} - -static unsigned int mask[] = {0,1,3,7,15,31,63,127,255}; -static double shift[9] = {1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0}; - -static -void decode_double_array_common2(unsigned char *igrib, long jlend, int NumBits, - double fmin, double zscale, double *fpdata) -{ - /* code from wgrib routine BDS_unpack */ - unsigned char *bits = igrib; - long i; - int n_bits = NumBits; - int c_bits, j_bits; - double jj; - - /* older unoptimized code, not often used */ - c_bits = 8; - for ( i = 0; i < jlend; i++ ) - { - jj = 0.0; - j_bits = n_bits; - while (c_bits <= j_bits) - { - if (c_bits == 8) - { - jj = jj * 256.0 + (double) (*bits++); - j_bits -= 8; - } - else - { - jj = (jj * shift[c_bits]) + (double) (*bits & mask[c_bits]); - bits++; - j_bits -= c_bits; - c_bits = 8; - } - } - - if (j_bits) - { - c_bits -= j_bits; - jj = (jj * shift[j_bits]) + (double) ((*bits >> c_bits) & mask[j_bits]); - } - - fpdata[i] = fmin + zscale*jj; - } -} - -static -void decode_double_array(unsigned char *igrib, long jlend, int numBits, - double fmin, double zscale, double *fpdata) -{ - long i; - double dval; -#if defined (VECTORCODE) - GRIBPACK *lgrib = NULL; - - if ( numBits == 8 || numBits == 16 || - numBits == 24 || numBits == 32 ) - { - long jlenc = jlend * numBits / 8; - if ( jlenc > 0 ) - { - lgrib = (GRIBPACK *) malloc(jlenc*sizeof(GRIBPACK)); - if ( lgrib == NULL ) SysError("No Memory!"); - - (void) UNPACK_GRIB(igrib, lgrib, jlenc, -1L); - } - } - - if ( numBits == 0 ) - { - for ( i = 0; i < jlend; i++ ) - fpdata[i] = fmin; - } - else if ( numBits == 8 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (int)lgrib[i]; - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits == 16 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (((int)lgrib[2*i ] << 8) + (int)lgrib[2*i+1]); - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits == 24 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (((int)lgrib[3*i ] << 16) + ((int)lgrib[3*i+1] << 8) + - (int)lgrib[3*i+2]); - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits == 32 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (((unsigned int)lgrib[4*i ] << 24) + ((unsigned int)lgrib[4*i+1] << 16) + - ((unsigned int)lgrib[4*i+2] << 8) + (unsigned int)lgrib[4*i+3]); - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits <= 25 ) - { - decode_double_array_common(igrib, jlend, numBits, fmin, zscale, fpdata); - } - else if ( numBits > 25 && numBits < 32 ) - { - decode_double_array_common2(igrib, jlend, numBits, fmin, zscale, fpdata); - } - else + ISEC2_GridType == GRIB1_GTYPE_LATLON_ROTSTR ) { - fprintf(stderr," Unimplemented packing factor %d!\n", numBits); - exit(EXIT_FAILURE); + /* + iret = decodeGDS_LL(gds, gdspos, isec0, isec2, imisng); + */ } - - if ( lgrib ) free(lgrib); - -#else - if ( numBits == 0 ) + else if ( ISEC2_GridType == GRIB1_GTYPE_LCC ) { - for ( i = 0; i < jlend; i++ ) - fpdata[i] = fmin; + ISEC2_NumLon = GDS_NumLon; + ISEC2_NumLat = GDS_NumLat; + *numGridVals = ISEC2_NumLon*ISEC2_NumLat; + ISEC2_FirstLat = GDS_FirstLat; + ISEC2_FirstLon = GDS_FirstLon; + ISEC2_ResFlag = GDS_ResFlag; + ISEC2_Lambert_Lov = GDS_Lambert_Lov; + ISEC2_Lambert_dx = GDS_Lambert_dx; + ISEC2_Lambert_dy = GDS_Lambert_dy; + ISEC2_Lambert_LatS1 = GDS_Lambert_LatS1; + ISEC2_Lambert_LatS2 = GDS_Lambert_LatS2; + ISEC2_Lambert_LatSP = GDS_Lambert_LatSP; + ISEC2_Lambert_LonSP = GDS_Lambert_LonSP; + ISEC2_Lambert_ProjFlag = GDS_Lambert_ProjFlag; + ISEC2_ScanFlag = GDS_ScanFlag; } - else if ( numBits == 8 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (int)igrib[i]; - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits == 16 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (((int)igrib[2*i ] << 8) | (int)igrib[2*i+1]); - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits == 24 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (((int)igrib[3*i ] << 16) + ((int)igrib[3*i+1] << 8) + - (int)igrib[3*i+2]); - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits == 32 ) - for ( i = 0; i < jlend; i++ ) - { - dval = (((unsigned int)igrib[4*i ] << 24) + ((unsigned int)igrib[4*i+1] << 16) + - ((unsigned int)igrib[4*i+2] << 8) + (unsigned int)igrib[4*i+3]); - fpdata[i] = fmin + zscale * dval; - } - else if ( numBits <= 25 ) + else if ( ISEC2_GridType == GRIB1_GTYPE_SPECTRAL ) { - decode_double_array_common(igrib, jlend, numBits, fmin, zscale, fpdata); + ISEC2_PentaJ = GDS_PentaJ; /* Truncation */ + ISEC2_PentaK = GDS_PentaK; + ISEC2_PentaM = GDS_PentaM; + ISEC2_RepType = GDS_RepType; + ISEC2_RepMode = GDS_RepMode; + *numGridVals = (ISEC2_PentaJ+1)*(ISEC2_PentaJ+2); + isec2[ 6] = 0; + isec2[ 7] = 0; + isec2[ 8] = 0; + isec2[ 9] = 0; + isec2[10] = 0; + /* + iret = decodeGDS_SH(gds, gdspos, isec0, isec2, imisng); + */ } - else if ( numBits > 25 && numBits < 32 ) + else if ( ISEC2_GridType == GRIB1_GTYPE_GME ) { - decode_double_array_common2(igrib, jlend, numBits, fmin, zscale, fpdata); + ISEC2_GME_NI2 = GDS_GME_NI2; + ISEC2_GME_NI3 = GDS_GME_NI3; + ISEC2_GME_ND = GDS_GME_ND; + ISEC2_GME_NI = GDS_GME_NI; + ISEC2_GME_AFlag = GDS_GME_AFlag; + ISEC2_GME_LatPP = GDS_GME_LatPP; + ISEC2_GME_LonPP = GDS_GME_LonPP; + ISEC2_GME_LonMPL = GDS_GME_LonMPL; + ISEC2_GME_BFlag = GDS_GME_BFlag; + *numGridVals = (ISEC2_GME_NI+1)*(ISEC2_GME_NI+1)*10; + /* + iret = decodeGDS_TR(gds, gdspos, isec0, isec2, imisng); + */ } else { - fprintf(stderr, "Unimplemented packing factor %d!\n", numBits); - exit(EXIT_FAILURE); + ISEC2_NumLon = GDS_NumLon; + ISEC2_NumLat = GDS_NumLat; + *numGridVals = ISEC2_NumLon*ISEC2_NumLat; + Message("Gridtype %d unsupported", ISEC2_GridType); } + + /* vertical coordinate parameters for hybrid levels. */ + /* get number of vertical coordinate parameters, if any. */ + + ISEC2_NumVCP = 0; + + isec2[17] = 0; + isec2[18] = 0; + + if ( VertCoorTab == TRUE ) + { + if ( ISEC0_GRIB_Version == 0 ) + { + locnv = 32; + ISEC2_NumVCP = (gdsLen - 32) >> 2; + } + else + { + locnv = GDS_PVPL - 1; + ISEC2_NumVCP = GDS_NV; + } +#if defined (SX) + lGribLen = 4*ISEC2_NumVCP; + lgrib = (GRIBPACK *) malloc(lGribLen*sizeof(GRIBPACK)); + + igrib = &gds[locnv]; + if ( ISEC2_NumVCP > 0 ) (void) UNPACK_GRIB(igrib, lgrib, lGribLen, -1L); + for ( i = 0; i < ISEC2_NumVCP; i++ ) + { + iexp = (lgrib[4*i ]); + imant =((lgrib[4*i+1]) << 16) + + ((lgrib[4*i+2]) << 8) + + (lgrib[4*i+3]); + fsec2[10+i] = POW_2_M24 * imant * pow(16.0, (double)(iexp - 64)); + } + + free(lgrib); +#else + for ( i = 0; i < ISEC2_NumVCP; i++ ) + { + iexp = (gds[locnv+4*i ]); + imant =((gds[locnv+4*i+1]) << 16) + + ((gds[locnv+4*i+2]) << 8) + + (gds[locnv+4*i+3]); + fsec2[10+i] = decfp2(iexp,imant); + } #endif + } + + return (gdsLen); } static @@ -5433,7 +5851,7 @@ int decodeBDS(int decscale, unsigned char *bds, int *isec2, int *isec4, int lcompress; int jup, kup, mup; int locnd; - int jlend; + long jlend; long i; int bds_flag, jscale, imiss; int bds_ubits; @@ -5656,11 +6074,11 @@ int decodeBDS(int decscale, unsigned char *bds, int *isec2, int *isec4, /* check length of output array. */ - if ( jlend+ioff > fsec4len ) + if ( ISEC4_NumValues > fsec4len ) { *iret = 710; gprintf(__func__, " Output array too small. Length = %d", fsec4len); - gprintf(__func__, " Number of values = %d", jlend+ioff); + gprintf(__func__, " Number of values = %d", ISEC4_NumValues); gprintf(__func__, " Return code = %d", *iret); return (0); } @@ -5670,7 +6088,11 @@ int decodeBDS(int decscale, unsigned char *bds, int *isec2, int *isec4, { igrib += locnd; - decode_double_array(igrib, jlend, ISEC4_NumBits, fmin, zscale, fpdata); +#if defined (_ARCH_PWR6) + decode_double_array_unrolled(igrib, jlend, ISEC4_NumBits, fmin, zscale, fpdata); +#else + decode_double_array_byte (igrib, jlend, ISEC4_NumBits, fmin, zscale, fpdata); +#endif } if ( lspherc && lcomplex ) @@ -5686,7 +6108,7 @@ int decodeBDS(int decscale, unsigned char *bds, int *isec2, int *isec4, if ( lspherc && !lcomplex ) { /* 20100705: Fix ZeroShiftError - Edi Kirk */ - if ( fsec4[1] != 0.0 ) + if ( IS_NOT_EQUAL(fsec4[1], 0.0) ) { double zserr = fsec4[1]; for ( i = 1; i < ISEC4_NumValues; i++ ) fsec4[i] -= zserr; @@ -5988,34 +6410,56 @@ void gribDecode(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, } } - if ( dfunc == 'R' && ISEC2_Reduced ) + if ( ISEC2_Reduced ) { int nlon, nlat; - int lsect3, lperio, lveggy; - ISEC2_Reduced = 0; - ISEC2_NumLon = ISEC2_NumLat*2; - nlon = ISEC2_NumLon; - nlat = ISEC2_NumLat; - ISEC4_NumValues = nlon*nlat; - - lsect3 = bitmapSize > 0; - lperio = 1; - lveggy = (ISEC1_CodeTable == 128) && (ISEC1_CenterID == 98) && - ((ISEC1_Parameter == 27) || (ISEC1_Parameter == 28) || - (ISEC1_Parameter == 29) || (ISEC1_Parameter == 30)); + int lsect3, lperio = 1, lveggy; + int ilat; + int nvalues = 0; + int dlon; - (void) qu2reg3(fsec4, ISEC2_RowLonPtr, nlat, nlon, FSEC3_MissVal, iret, - lsect3, lperio, lveggy); + nlat = ISEC2_NumLat; + nlon = ISEC2_RowLonPtr[0]; + for ( ilat = 0; ilat < nlat; ++ilat ) nvalues += ISEC2_RowLon(ilat); + for ( ilat = 1; ilat < nlat; ++ilat ) + if ( ISEC2_RowLon(ilat) > nlon ) nlon = ISEC2_RowLon(ilat); - if ( bitmapSize > 0 ) + dlon = ISEC2_LastLon-ISEC2_FirstLon; + if ( dlon < 0 ) dlon += 360000; + + if ( nvalues != ISEC4_NumValues ) { - long i; - int j = 0; - - for ( i = 0; i < ISEC4_NumValues; i++ ) - if ( IS_NOT_EQUAL(fsec4[i], FSEC3_MissVal) ) j++; + *iret = -801; + } - ISEC4_NumNonMissValues = j; + if ( dfunc == 'R' && *iret == -801 ) + gprintf(__func__, "Number of values (%d) and sum of lons per row (%d) differ, abort conversion to regular grid!", + ISEC4_NumValues, nvalues); + + if ( dfunc == 'R' && *iret != -801 ) + { + ISEC2_Reduced = 0; + ISEC2_NumLon = nlon; + ISEC4_NumValues = nlon*nlat; + + lsect3 = bitmapSize > 0; + lveggy = (ISEC1_CodeTable == 128) && (ISEC1_CenterID == 98) && + ((ISEC1_Parameter == 27) || (ISEC1_Parameter == 28) || + (ISEC1_Parameter == 29) || (ISEC1_Parameter == 30)); + + (void) qu2reg3(fsec4, ISEC2_RowLonPtr, nlat, nlon, FSEC3_MissVal, iret, + lsect3, lperio, lveggy); + + if ( bitmapSize > 0 ) + { + long i; + int j = 0; + + for ( i = 0; i < ISEC4_NumValues; i++ ) + if ( IS_NOT_EQUAL(fsec4[i], FSEC3_MissVal) ) j++; + + ISEC4_NumNonMissValues = j; + } } } @@ -6080,6 +6524,8 @@ void gribDecode(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, # include "config.h" #endif +#include <string.h> +#include <ctype.h> @@ -6548,6 +6994,8 @@ static int gribrec_len(int b1, int b2, int b3) return (gribsize); } +#include <stdio.h> +#include <math.h> /* calculate_pfactor: source code from grib_api-1.8.0 */ @@ -6616,7 +7064,7 @@ double calculate_pfactor(const double* spectralField, long fieldTruncation, long for( loop = ismin; loop <= ismax; loop++ ) { norms[n] = norms[n] > zeps ? norms[n] : zeps; - if( norms[n] == zeps ) weights[n] = 100.0 * zeps; + if( IS_EQUAL(norms[n], zeps) ) weights[n] = 100.0 * zeps; } /* @@ -7054,8 +7502,8 @@ C OMISNG - True if missing values are present in field. C C OPERIO - True if input field is periodic. C -C OVEGGY - True if 'nearest neighbour' processing must be used -C for interpolation +C OVEGGY - True if 'nearest neighbour' processing must be used +C for interpolation C C Output Parameters. C ------------------ @@ -7118,13 +7566,26 @@ C ----------------------------------------------------------------- for ( jl = 1; jl <= ki; ++jl ) pw[jl + pw_dim1] = p[jl]; - /* Arrange wrap-around value in work array */ - pw[ki + 1 + pw_dim1] = p[1]; + if ( operio ) + { + /* Arrange wrap-around value in work array */ + pw[ki + 1 + pw_dim1] = p[1]; - /* Set up constants to be used to figure out weighting for */ - /* values in interpolation. */ - zrdi = (double) ki; - zdo = 1.0 / (double) ko; + /* Set up constants to be used to figure out weighting for */ + /* values in interpolation. */ + zrdi = (double) ki; + zdo = 1.0 / (double) ko; + } + else + { + /* Repeat last value, to cope with "implicit truncation" below */ + pw[ki + 1 + pw_dim1] = p[ki]; + + /* Set up constants to be used to figure out weighting for */ + /* values in interpolation. */ + zrdi = (double) (ki-1); + zdo = 1.0 / (double) (ko-1); + } /* Loop through the output points */ for ( jl = 1; jl <= ko; ++jl ) @@ -7630,6 +8091,9 @@ L900: return 0; } /* qu2reg3 */ +#include <stdlib.h> +#include <string.h> +#include <ctype.h> FILE *grprsm = NULL; @@ -8296,6 +8760,7 @@ long unpackInt32(unsigned char *cp, unsigned INT32 *up, long bc, long tc) return (bc); } #endif +#include <stdio.h> void prtbin(int kin, int knbit, int *kout, int *kerr) { @@ -8480,6 +8945,7 @@ void ref2ibm(double *pref, int kbits) return; } /* ref2ibm */ +#include <string.h> int correct_bdslen(int bdslen, long recsize, long gribpos) @@ -8574,6 +9040,7 @@ int grib1Sections(unsigned char *gribbuffer, long bufsize, unsigned char **pdsp, { fprintf(stderr, "Missing end section >%2x %2x %2x %2x<\n", bufpointer[0], bufpointer[1], bufpointer[2], bufpointer[3]); + return (-2); } return (0); @@ -8758,6 +9225,7 @@ int grib2Sections(unsigned char *gribbuffer, long bufsize, unsigned char **idsp, { fprintf(stderr, "Missing end section >%2x %2x %2x %2x<\n", section[0], section[1], section[2], section[3]); + return (-2); } return (0); @@ -8907,7 +9375,7 @@ void grib1PrintALL(int nrec, long offset, long recpos, long recsize, unsigned ch bdslen = BDS_Len; bdslen = correct_bdslen(bdslen, recsize, bds-gribbuffer); - if ( (BDS_Flag >> 4)&1 && BDS_Z == 128 ) + if ( ((BDS_Flag >> 4)&1) && (BDS_Z == 128 || BDS_Z == 130) ) { int s1, s2; s1 = gribrec_len(bds[14], bds[15], bds[16]); @@ -8929,9 +9397,9 @@ void grib2PrintALL(int nrec, long offset, long recpos, long recsize, unsigned ch unsigned char *is = NULL, *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL; unsigned char *ids = NULL, *lus = NULL, *drs = NULL; long ids_len = 0, lus_len = 0, gds_len = 0, pds_len = 0, drs_len = 0, bms_len = 0, bds_len = 0; - int gridtype, paramnum, level1type/* , level2type */; - int level1/* , level1sf */; - /* int level2 , level2sf; */ + int gridtype, paramnum, level1type /*, level2type*/; + int level1 /*, level1sf*/; + /* int level2, level2sf; */ double cr = 1; if ( header ) @@ -9233,7 +9701,7 @@ void grib1PrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe else level = PDS_Level1; - if ( (BDS_Flag >> 4)&1 && BDS_Z == 128 ) + if ( ((BDS_Flag >> 4)&1) && BDS_Z == 128 ) { int s1, s2; s1 = ((int) ((bds[17]<<16)+(bds[18]<<8)+bds[19])); @@ -9302,7 +9770,7 @@ void gribCheck1(int nrec, long recpos, long recsize, unsigned char *gribbuffer) else level = PDS_Level1; - if ( (BDS_Flag >> 4)&1 && BDS_Z == 128 ) + if ( ((BDS_Flag >> 4)&1) && BDS_Z == 128 ) { int s1, s2; s1 = ((int) ((bds[17]<<16)+(bds[18]<<8)+bds[19])); @@ -9310,7 +9778,7 @@ void gribCheck1(int nrec, long recpos, long recsize, unsigned char *gribbuffer) cr = ((double)s1)/s2; } - if ( cr == 1 && BDS_NumBits == 24 ) + if ( IS_EQUAL(cr, 1) && BDS_NumBits == 24 ) { fprintf(stdout, "GRIB record %5d : code = %4d level = %7d\n", nrec, PDS_Parameter, level); } @@ -9323,10 +9791,10 @@ void repair1(unsigned char *gbuf, long gbufsize) long i; int nerr; unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL; - int recLen; + /* int recLen; */ unsigned char *source; size_t sourceLen; - int bds_len, bds_nbits, bds_flag, lspherc, lcomplex/* , lcompress */; + int bds_len, bds_nbits, bds_flag, lspherc, lcomplex /*, lcompress */; int bds_head = 11; int bds_ext = 0, bds_ubits; int datstart = 0; @@ -9338,8 +9806,7 @@ void repair1(unsigned char *gbuf, long gbufsize) fprintf(stdout, "grib1Sections error\n"); } - recLen = gribrec_len(gbuf[4], gbuf[5], gbuf[6]); - /* FIXME: value of llarge is never evaluated */ + /* recLen = gribrec_len(gbuf[4], gbuf[5], gbuf[6]); */ /* if ( recLen > JP23SET ) llarge = TRUE; */ bds_len = BDS_Len; @@ -9389,7 +9856,7 @@ void repair1(unsigned char *gbuf, long gbufsize) } -void gribRepair1(int nrec, long recpos, long recsize, unsigned char *gribbuffer) +void gribRepair1(int nrec, long recsize, unsigned char *gribbuffer) { int level, nerr; unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL; @@ -9409,7 +9876,7 @@ void gribRepair1(int nrec, long recpos, long recsize, unsigned char *gribbuffer) else level = PDS_Level1; - if ( (BDS_Flag >> 4)&1 && BDS_Z == 128 ) + if ( ((BDS_Flag >> 4)&1) && BDS_Z == 128 ) { int s1, s2; s1 = ((int) ((bds[17]<<16)+(bds[18]<<8)+bds[19])); @@ -9417,27 +9884,38 @@ void gribRepair1(int nrec, long recpos, long recsize, unsigned char *gribbuffer) cr = ((double)s1)/s2; } - if ( cr == 1 && BDS_NumBits == 24 ) + if ( IS_EQUAL(cr, 1) && BDS_NumBits == 24 ) { fprintf(stdout, "Repair GRIB record %5d : code = %4d level = %7d\n", nrec, PDS_Parameter, level); repair1(gribbuffer, recsize); } } +#include <stdio.h> +#include <string.h> #if defined (HAVE_CONFIG_H) # include "config.h" #endif -#if defined (HAVE_LIBSZ) +#if defined (HAVE_LIBSZ) || defined (HAVE_LIBAEC) #if defined(__cplusplus) extern "C" { #endif +#if defined (HAVE_LIBAEC) +# include <libaec.h> +#else # include <szlib.h> +#endif #if defined (__cplusplus) } #endif +#if defined (HAVE_LIBAEC) +# define AEC_FLAGS (AEC_DATA_MSB | AEC_DATA_PREPROCESS) +#else # define OPTIONS_MASK (SZ_RAW_OPTION_MASK | SZ_MSB_OPTION_MASK | SZ_NN_OPTION_MASK) +#endif + # define PIXELS_PER_BLOCK (8) # define PIXELS_PER_SCANLINE (PIXELS_PER_BLOCK*128) @@ -9445,13 +9923,26 @@ extern "C" { # define MIN_SIZE (256) #endif +#define Z_SZIP 128 +#define Z_AEC 130 + + +#define SetLen3(var, offset, value) ((var[offset+0] = 0xFF & (value >> 16)), \ + (var[offset+1] = 0xFF & (value >> 8)), \ + (var[offset+2] = 0xFF & (value ))) +#define SetLen4(var, offset, value) ((var[offset+0] = 0xFF & (value >> 24)), \ + (var[offset+1] = 0xFF & (value >> 16)), \ + (var[offset+2] = 0xFF & (value >> 8)), \ + (var[offset+3] = 0xFF & (value ))) + int gribGetZip(long recsize, unsigned char *gribbuffer, long *urecsize) { /* urecsize : uncompressed record size */ int compress = 0; int nerr; - int bds_len, bds_nbits, bds_flag, lcompress, lspherc, lcomplex; + /* int bds_len, bds_nbits, lspherc, lcomplex; */ + int bds_flag, lcompress; long gribsize = 0; unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL; int gribversion; @@ -9467,18 +9958,18 @@ int gribGetZip(long recsize, unsigned char *gribbuffer, long *urecsize) return (compress); } - bds_len = BDS_Len; - bds_nbits = BDS_NumBits; + /* bds_len = BDS_Len; */ + /* bds_nbits = BDS_NumBits; */ bds_flag = BDS_Flag; - lspherc = bds_flag >> 7; - lcomplex = (bds_flag >> 6)&1; + /* lspherc = bds_flag >> 7; */ + /* lcomplex = (bds_flag >> 6)&1; */ lcompress = (bds_flag >> 4)&1; *urecsize = 0; if ( lcompress ) { compress = BDS_Z; - if ( compress == 128 ) + if ( compress == Z_SZIP || compress == Z_AEC ) { gribsize = gribrec_len(bds[14], bds[15], bds[16]); } @@ -9496,7 +9987,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs int gribLen; int rec_len; int llarge = FALSE; -#if ! defined (HAVE_LIBSZ) +#if ! (defined (HAVE_LIBSZ) || defined (HAVE_LIBAEC)) static int libszwarn = 1; #endif unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL; @@ -9509,28 +10000,35 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs nerr = grib1Sections(dbuf, dbufsize, &pds, &gds, &bms, &bds); if ( nerr ) { - fprintf(stdout, "grib1Sections error\n"); + fprintf(stdout, "grib1Sections error!\n"); return (rec_len); } -#if defined (HAVE_LIBSZ) +#if defined (HAVE_LIBSZ) || defined (HAVE_LIBAEC) { long i; int bdsLen; int gribLenOld = 0; int status; - int datstart, datsize; + size_t datstart, datsize; +#if defined (HAVE_LIBAEC) + struct aec_stream strm; +#else SZ_com_t sz_param; /* szip parameter block */ +#endif unsigned char *dest, *source; size_t destLen, sourceLen; - int bds_len, bds_nbits, bds_flag, lspherc, lcomplex, lcompress, bds_ubits; + int bits_per_sample; + int bds_len, bds_nbits, bds_flag, lspherc, lcomplex,/* lcompress,*/ bds_ubits; int bds_head = 11; int bds_ext = 0; - int bds_zoffset = 12; + int bds_zoffset, bds_zstart; unsigned char *pbuf = NULL; - if ( llarge ) bds_zoffset = 14; + bds_zstart = 14; + bds_zoffset = 12; + if ( llarge ) bds_zoffset += 2; bds_len = BDS_Len; bds_len = correct_bdslen(bds_len, gribLen, bds-dbuf); @@ -9539,7 +10037,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs bds_ubits = bds_flag & 15; lspherc = bds_flag >> 7; lcomplex = (bds_flag >> 6)&1; - lcompress = (bds_flag >> 4)&1; + /* lcompress = (bds_flag >> 4)&1; */ if ( bds_nbits != 8 && bds_nbits != 16 && bds_nbits != 24 && bds_nbits != 32 ) { @@ -9551,16 +10049,26 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs } return (rec_len); } - - sz_param.options_mask = OPTIONS_MASK; +#if defined (HAVE_LIBSZ) if ( bds_nbits == 24 ) - sz_param.bits_per_pixel = 8; + bits_per_sample = 8; else - sz_param.bits_per_pixel = bds_nbits; - +#endif + bits_per_sample = bds_nbits; + +#if defined (HAVE_LIBAEC) + strm.bits_per_sample = bits_per_sample; + strm.block_size = PIXELS_PER_BLOCK; + strm.rsi = PIXELS_PER_SCANLINE / PIXELS_PER_BLOCK; + strm.flags = AEC_FLAGS; + if ( bds_nbits == 24 ) strm.flags |= AEC_DATA_3BYTE; +#else + sz_param.options_mask = OPTIONS_MASK; + sz_param.bits_per_pixel = bits_per_sample; sz_param.pixels_per_block = PIXELS_PER_BLOCK; sz_param.pixels_per_scanline = PIXELS_PER_SCANLINE; +#endif if ( lspherc ) { @@ -9591,6 +10099,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs source = bds + datstart; dest = sbuf; +#if defined (HAVE_LIBSZ) if ( bds_nbits == 24 ) { long nelem; @@ -9604,7 +10113,23 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs } source = pbuf; } +#endif + +#if defined (HAVE_LIBAEC) + strm.next_in = source; + strm.avail_in = sourceLen; + strm.next_out = dest; + strm.avail_out = destLen; + + status = aec_buffer_encode(&strm); + if ( status != AEC_OK ) + { + if ( status != AEC_DATA_ERROR ) + Warning("AEC ERROR: %d code %3d level %3d", status, PDS_Parameter, PDS_Level2); + } + destLen = strm.total_out; +#else status = SZ_BufftoBuffCompress(dest, &destLen, source, sourceLen, &sz_param); if ( status != SZ_OK ) { @@ -9619,12 +10144,12 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs else Warning("SZ ERROR: %d code %3d level %3d", status, PDS_Parameter, PDS_Level2); } +#endif if ( pbuf ) free(pbuf); /* fprintf(stderr, "sourceLen, destLen %d %d\n", sourceLen, destLen); */ - if ( destLen < MIN_COMPRESS*sourceLen ) { source = bds + datstart + bds_zoffset; @@ -9645,7 +10170,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs */ /* memcpy(bds + datstart + bds_zoffset, source, destLen); */ /* - fprintf(stderr, "z>>> %d %d %d %d <<<\n", (int) bds[0+datstart+bds_zoffset], + fprintf(stderr, "z>>> %d %d %d %d <<<\n", (int) bds[0+datstart+bds_zoffset], (int)bds[1+datstart+bds_zoffset], (int)bds[2+datstart+bds_zoffset], (int)bds[3+datstart+bds_zoffset]); */ if ( llarge ) @@ -9657,40 +10182,27 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs } gribLenOld = gribLenOld / (-120); gribLenOld = JP23SET - gribLenOld + 1; - bds[14] = 0xFF & (gribLenOld >> 16); - bds[15] = 0xFF & (gribLenOld >> 8); - bds[16] = 0xFF & (gribLenOld); - - bds[17] = 0xFF & (sourceLen >> 24); - bds[18] = 0xFF & (sourceLen >> 16); - bds[19] = 0xFF & (sourceLen >> 8); - bds[20] = 0xFF & (sourceLen); - - bds[21] = 0xFF & (destLen >> 24); - bds[22] = 0xFF & (destLen >> 16); - bds[23] = 0xFF & (destLen >> 8); - bds[24] = 0xFF & (destLen); + + SetLen3(bds, bds_zstart, gribLenOld); + SetLen4(bds, bds_zstart+3, sourceLen); + SetLen4(bds, bds_zstart+7, destLen); } else { - bds[14] = 0xFF & (gribLenOld >> 16); - bds[15] = 0xFF & (gribLenOld >> 8); - bds[16] = 0xFF & (gribLenOld); - - bds[17] = 0xFF & (sourceLen >> 16); - bds[18] = 0xFF & (sourceLen >> 8); - bds[19] = 0xFF & (sourceLen); - - bds[20] = 0xFF & (destLen >> 16); - bds[21] = 0xFF & (destLen >> 8); - bds[22] = 0xFF & (destLen); + SetLen3(bds, bds_zstart, gribLenOld); + SetLen3(bds, bds_zstart+3, sourceLen); + SetLen3(bds, bds_zstart+6, destLen); } bdsLen = datstart + bds_zoffset + destLen; bds[11] = 0; bds[12] = 0; - BDS_Z = 128; +#if defined (HAVE_LIBAEC) + BDS_Z = Z_AEC; +#else + BDS_Z = Z_SZIP; +#endif BDS_Flag += 16; if ( (bdsLen%2) == 1 ) @@ -9699,9 +10211,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs bds[bdsLen++] = 0; } - bds[0] = 0xFF & (bdsLen >> 16); - bds[1] = 0xFF & (bdsLen >> 8); - bds[2] = 0xFF & (bdsLen); + SetLen3(bds, 0, bdsLen); gribLen = (bds - dbuf) + bdsLen; @@ -9728,23 +10238,20 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs itemp = gribLen / (-120); itemp = JP23SET - itemp + 1; - dbuf[4] = 0xFF & (itemp >> 16); - dbuf[5] = 0xFF & (itemp >> 8); - dbuf[6] = 0xFF & (itemp); + SetLen3(dbuf, 4, itemp); bdslen = gribLen - bdslen; - bds[0] = 0xFF & (bdsLen >> 16); - bds[1] = 0xFF & (bdsLen >> 8); - bds[2] = 0xFF & (bdsLen); + SetLen3(bds, 0, bdslen); } else { - dbuf[4] = 0xFF & (gribLen >> 16); - dbuf[5] = 0xFF & (gribLen >> 8); - dbuf[6] = 0xFF & (gribLen); + SetLen3(dbuf, 4, gribLen); } } + else + { + } /* fprintf(stderr, "%3d %3d griblen in %6d out %6d CR %g slen %6d dlen %6d CR %g\n", PDS_Parameter, PDS_Level1, gribLenOld, gribLen, @@ -9756,12 +10263,15 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs #else if ( libszwarn ) { - Warning("Compression disabled, szlib not available!"); + Warning("Compression disabled, szlib or libaec not available!"); libszwarn = 0; } #endif - while ( gribLen & 7 ) dbuf[gribLen++] = 0; + if ( llarge ) + while ( gribLen%120 ) dbuf[gribLen++] = 0; + else + while ( gribLen & 7 ) dbuf[gribLen++] = 0; rec_len = gribLen; @@ -9771,18 +10281,18 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufsize) { -#if ! defined (HAVE_LIBSZ) +#if ! (defined (HAVE_LIBSZ) || defined (HAVE_LIBAEC)) static int libszwarn = 1; #endif int nerr; unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL; int bdsLen, recLen, gribLen = 0; - char *dest, *source; + unsigned char *dest, *source; size_t destLen, sourceLen; - int bds_len, bds_nbits, bds_flag, lspherc, lcomplex, lcompress; + int /* bds_len, */ bds_nbits, bds_flag, lspherc, lcomplex /*, lcompress*/; int bds_head = 11; int bds_ext = 0; - int bds_zoffset = 12; + int bds_zoffset, bds_zstart; int datstart = 0; int llarge = FALSE; @@ -9793,17 +10303,20 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu return (0); } - recLen = gribrec_len(bds[14], bds[15], bds[16]); + bds_zstart = 14; + + recLen = gribrec_len(bds[bds_zstart], bds[bds_zstart+1], bds[bds_zstart+2]); if ( recLen > JP23SET ) llarge = TRUE; - if ( llarge ) bds_zoffset = 14; + bds_zoffset = 12; + if ( llarge ) bds_zoffset += 2; - bds_len = BDS_Len; + /* bds_len = BDS_Len; */ bds_nbits = BDS_NumBits; bds_flag = BDS_Flag; lspherc = bds_flag >> 7; lcomplex = (bds_flag >> 6)&1; - lcompress = (bds_flag >> 4)&1; + /* lcompress = (bds_flag >> 4)&1; */ if ( lspherc ) { @@ -9822,7 +10335,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu datstart = bds_head + bds_ext; - source = (char *) bds + datstart + bds_zoffset; + source = bds + datstart + bds_zoffset; if ( llarge ) sourceLen = ((size_t) ((bds[21]<<24)+(bds[22]<<16)+(bds[23]<<8)+bds[24])); else @@ -9835,8 +10348,8 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu return (0); } - dest = (char *) bds + datstart; - if ( llarge ) + dest = bds + datstart; + if ( llarge ) destLen = ((size_t) ((bds[17]<<24)+(bds[18]<<16)+(bds[19]<<8)+bds[20])); else destLen = ((size_t) ((bds[17]<<16)+(bds[18]<<8)+bds[19])); @@ -9845,23 +10358,38 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu bdsLen = datstart + destLen; -#if defined (HAVE_LIBSZ) +#if defined (HAVE_LIBSZ) || defined (HAVE_LIBAEC) { int status; - size_t tmpLen; long i; + size_t tmpLen; int bds_ubits; + int bits_per_sample; +#if defined (HAVE_LIBAEC) + struct aec_stream strm; +#else SZ_com_t sz_param; /* szip parameter block */ +#endif - sz_param.options_mask = OPTIONS_MASK; - +#if defined (HAVE_LIBSZ) if ( bds_nbits == 24 ) - sz_param.bits_per_pixel = 8; + bits_per_sample = 8; else - sz_param.bits_per_pixel = bds_nbits; - +#endif + bits_per_sample = bds_nbits; + +#if defined (HAVE_LIBAEC) + strm.bits_per_sample = bits_per_sample; + strm.block_size = PIXELS_PER_BLOCK; + strm.rsi = PIXELS_PER_SCANLINE / PIXELS_PER_BLOCK; + strm.flags = AEC_FLAGS; + if ( bds_nbits == 24 ) strm.flags |= AEC_DATA_3BYTE; +#else + sz_param.options_mask = OPTIONS_MASK; + sz_param.bits_per_pixel = bits_per_sample; sz_param.pixels_per_block = PIXELS_PER_BLOCK; sz_param.pixels_per_scanline = PIXELS_PER_SCANLINE; +#endif if ( bds_ext ) for ( i = 0; i < bds_ext; ++i ) @@ -9874,6 +10402,18 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu */ tmpLen = destLen; +#if defined (HAVE_LIBAEC) + strm.next_in = source; + strm.avail_in = sourceLen; + strm.next_out = dest; + strm.avail_out = tmpLen; + + status = aec_buffer_decode(&strm); + if ( status != AEC_OK ) + Warning("AEC ERROR: %d code %3d level %3d", status, PDS_Parameter, PDS_Level2); + + tmpLen = strm.total_out; +#else status = SZ_BufftoBuffDecompress(dest, &tmpLen, source, sourceLen, &sz_param); if ( status != SZ_OK ) { @@ -9888,6 +10428,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu else Warning("SZ ERROR: %d code %3d level %3d", status, PDS_Parameter, PDS_Level2); } +#endif /* fprintf(stderr, "gribUnzip: sl = %ld dl = %ld tl = %ld\n", (long)sourceLen, (long)destLen,(long) tmpLen); @@ -9895,7 +10436,8 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu if ( tmpLen != destLen ) Warning("unzip size differ: code %3d level %3d ibuflen %ld ubuflen %ld", PDS_Parameter, PDS_Level2, (long) destLen, (long) tmpLen); - + +#if defined (HAVE_LIBSZ) if ( bds_nbits == 24 ) { long nelem; @@ -9911,7 +10453,8 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu memcpy(dest, pbuf, tmpLen); free(pbuf); } - +#endif + bds_ubits = BDS_Flag & 15; BDS_Flag -= bds_ubits; @@ -9921,9 +10464,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu bds[bdsLen++] = 0; } - bds[0] = 0xFF & (bdsLen >> 16); - bds[1] = 0xFF & (bdsLen >> 8); - bds[2] = 0xFF & (bdsLen); + SetLen3(bds, 0, bdsLen); gribLen = (bds - dbuf) + bdsLen; @@ -9952,26 +10493,23 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu itemp = gribLen / (-120); itemp = JP23SET - itemp + 1; - dbuf[4] = 0xFF & (itemp >> 16); - dbuf[5] = 0xFF & (itemp >> 8); - dbuf[6] = 0xFF & (itemp); - + SetLen3(dbuf, 4, itemp); + bdsLen = gribLen - bdsLen; - bds[0] = 0xFF & (bdsLen >> 16); - bds[1] = 0xFF & (bdsLen >> 8); - bds[2] = 0xFF & (bdsLen); + SetLen3(bds, 0, bdsLen); } else { - dbuf[4] = 0xFF & (recLen >> 16); - dbuf[5] = 0xFF & (recLen >> 8); - dbuf[6] = 0xFF & (recLen); + SetLen3(dbuf, 4, recLen); } /* fprintf(stderr, "recLen, gribLen, bdsLen %d %d %d\n", recLen, gribLen, bdsLen); */ - while ( gribLen & 7 ) dbuf[gribLen++] = 0; + if ( llarge ) + while ( gribLen%120 ) dbuf[gribLen++] = 0; + else + while ( gribLen & 7 ) dbuf[gribLen++] = 0; /* fprintf(stderr, "recLen, gribLen, bdsLen %d %d %d\n", recLen, gribLen, bdsLen); */ @@ -9979,14 +10517,14 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu #else if ( libszwarn ) { - Warning("Decompression disabled, szlib not available!"); + Warning("Decompression disabled, szlib or libaec not available!"); libszwarn = 0; } #endif return (gribLen); } -static const char grb_libvers[] = "1.5.3" " of ""Jun 14 2012"" ""13:22:45"; +static const char grb_libvers[] = "1.6.0" " of ""Mar 5 2013"" ""11:10:25"; const char * cgribexLibraryVersion(void) { diff --git a/src/config.h.in b/src/config.h.in index 33061d272..521e258b2 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -10,6 +10,9 @@ /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the `getline' function. */ +#undef HAVE_GETLINE + /* Define to 1 if you have the `getpagesize' function. */ #undef HAVE_GETPAGESIZE @@ -64,9 +67,6 @@ /* Define to 1 for JPEG compression for GRIB2 */ #undef HAVE_LIBOPENJPEG -/* Define to 1 if you have the <libpng14/png.h> header file. */ -#undef HAVE_LIBPNG14_PNG_H - /* Define to 1 if you have the `pthread' library (-lpthread). */ #undef HAVE_LIBPTHREAD @@ -109,6 +109,9 @@ /* netCDF library does support MPI parallel invocations */ #undef HAVE_PARALLEL_NC4 +/* Define to 1 if you have the <png.h> header file. */ +#undef HAVE_PNG_H + /* ScalES PPM C core library is available */ #undef HAVE_PPM_CORE @@ -201,11 +204,6 @@ /* Version number of package */ #undef VERSION -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS diff --git a/src/extralib.c b/src/extralib.c index 5f73bb602..613bbf2ba 100644 --- a/src/extralib.c +++ b/src/extralib.c @@ -32,7 +32,7 @@ static int extDefaultNumber = EXT_REAL; */ #undef LIBVERSION -#define LIBVERSION 1.3.0 +#define LIBVERSION 1.3.1 #define XSTRING(x) #x #define STRING(x) XSTRING(x) static const char ext_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__; @@ -96,6 +96,7 @@ void extLibInit() } default: Message("Invalid character in %s: %s", envName, envString); + break; } } } @@ -291,6 +292,7 @@ int extInqData(void *ext, int prec, void *data) default: { Error("unexpected data precision %d", rprec); + break; } } @@ -374,6 +376,7 @@ int extDefData(void *ext, int prec, const void *data) default: { Error("unexpected data precision %d", rprec); + break; } } @@ -449,6 +452,7 @@ int extRead(int fileID, void *ext) default: { Error("unexpected header precision %d", hprec); + break; } } @@ -557,6 +561,7 @@ int extWrite(int fileID, void *ext) default: { Error("unexpected header precision %d", rprec); + break; } } @@ -587,6 +592,7 @@ int extWrite(int fileID, void *ext) default: { Error("unexpected data precision %d", rprec); + break; } } diff --git a/src/file.c b/src/file.c index c46174bd9..38227299a 100644 --- a/src/file.c +++ b/src/file.c @@ -153,7 +153,7 @@ static void file_table_print(void); * A version string. */ #undef LIBVERSION -#define LIBVERSION 1.8.0 +#define LIBVERSION 1.8.1 #define XSTRING(x) #x #define STRING(x) XSTRING(x) const char file_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__; @@ -173,6 +173,7 @@ const char file_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__; 22/08/2010 1.7.0 refactor 11/11/2010 1.7.1 update for changed interface of error.h 02/02/2012 1.8.0 cleanup + 16/11/2012 1.8.1 added support for unbuffered write */ @@ -758,6 +759,11 @@ void file_initialize(void) value = file_getenv("FILE_BUFSIZE"); if ( value >= 0 ) FileBufferSizeEnv = value; + else + { + value = file_getenv("GRIB_API_IO_BUFFER_SIZE"); + if ( value >= 0 ) FileBufferSizeEnv = value; + } value = file_getenv("FILE_TYPE"); if ( value > 0 ) @@ -842,6 +848,8 @@ void file_set_buffer(bfile_t *fileptr) if ( buffersize < (size_t) fileptr->size && buffersize < minblocksize ) buffersize = minblocksize; } + + if ( buffersize == 0 ) buffersize = 1; } else { @@ -858,17 +866,18 @@ void file_set_buffer(bfile_t *fileptr) } } - if ( buffersize == 0 ) buffersize = 1; - if ( fileptr->bufferType == FILE_BUFTYPE_STD || fileptr->type == FILE_TYPE_FOPEN ) { - fileptr->buffer = (char *) malloc(buffersize); - if ( fileptr->buffer == NULL ) - SysError("Allocation of file buffer failed!"); + if ( buffersize > 0 ) + { + fileptr->buffer = (char *) malloc(buffersize); + if ( fileptr->buffer == NULL ) + SysError("Allocation of file buffer failed!"); + } } if ( fileptr->type == FILE_TYPE_FOPEN ) - if ( setvbuf(fileptr->fp, fileptr->buffer, _IOFBF, buffersize) ) + if ( setvbuf(fileptr->fp, fileptr->buffer, fileptr->buffer ? _IOFBF : _IONBF, buffersize) ) SysError("setvbuf failed!"); fileptr->bufferSize = buffersize; diff --git a/src/getline.c b/src/getline.c new file mode 100644 index 000000000..8205b5327 --- /dev/null +++ b/src/getline.c @@ -0,0 +1,89 @@ +/* + * getline.c --- replacement for GNU getline if not available in libc + * + * Copyright (C) 2011 Thomas Jahns <jahns@dkrz.de> + * + * Version: 0.0.1 + * Author: Thomas Jahns <jahns@dkrz.de> + * Maintainer: Thomas Jahns <jahns@dkrz.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <unistd.h> +#include <string.h> + +/* read until end of line or end of file */ +ssize_t +getline(char **linebuf, size_t *linebuf_size, FILE *fp) +{ + size_t len, old_len, buf_size; + char *buf; + ssize_t status = 0; + + if ( feof(fp) ) return -1; + + if (!linebuf_size || !linebuf) + { + errno = EINVAL; + return -1; + } + if (!*linebuf) + { + buf_size = 80; + buf = malloc(buf_size); + if (!buf) return -1; + } + else + { + buf_size = *linebuf_size; + buf = *linebuf; + } + if ((status = (fgets(buf, buf_size, fp) != NULL))) + { + len = strlen(buf); + if (buf[len-1] != '\n') + { + do { + void *temp = realloc(buf, buf_size * 2); + if (!temp) + { + status = -1; + break; + } + buf = temp; + buf_size *= 2; + old_len = len; + } while(fgets(buf + len, buf_size - len, fp) + && (len += strlen(buf + len)) > old_len + && buf[len-1] != '\n'); + } + status = len > SSIZE_MAX ? SSIZE_MAX : len; + } + if (linebuf_size) + *linebuf_size = buf_size; + *linebuf = buf; + return status; +} + diff --git a/src/gribapi.c b/src/gribapi.c index 6a2a79969..469267100 100644 --- a/src/gribapi.c +++ b/src/gribapi.c @@ -36,11 +36,11 @@ const char *gribapiLibraryVersion(void) } -void gribContainersNew(int streamID) +void gribContainersNew(stream_t * streamptr) { - stream_t *streamptr; + int editionNumber = 2; - streamptr = stream_to_pointer(streamID); + if ( streamptr->filetype == FILETYPE_GRB ) editionNumber = 1; #if defined (HAVE_LIBCGRIBEX) if ( streamptr->filetype == FILETYPE_GRB ) @@ -49,39 +49,70 @@ void gribContainersNew(int streamID) else #endif { - int i, editionNumber = 2; + int nvars = streamptr->nvars; + +#if defined (GRIBCONTAINER2D) + gribContainer_t **gribContainers; + gribContainers = (gribContainer_t **) malloc(nvars*sizeof(gribContainer_t *)); + + for ( int varID = 0; varID < nvars; ++varID ) + { + int nlevs = streamptr->vars[varID].nlevs; + gribContainers[varID] = (gribContainer_t *) malloc(nlevs*sizeof(gribContainer_t)); + + for ( int levelID = 0; levelID < nlevs; ++levelID ) + { + gribContainers[varID][levelID].gribHandle = gribHandleNew(editionNumber); + gribContainers[varID][levelID].init = FALSE; + } + } + + streamptr->gribContainers = (void **) gribContainers; +#else gribContainer_t *gribContainers; + gribContainers = (gribContainer_t *) malloc(nvars*sizeof(gribContainer_t)); - if ( streamptr->filetype == FILETYPE_GRB ) editionNumber = 1; + for ( int varID = 0; varID < nvars; ++varID ) + { + gribContainers[varID].gribHandle = gribHandleNew(editionNumber); + gribContainers[varID].init = FALSE; + } - gribContainers = (gribContainer_t *) malloc(streamptr->nvars*sizeof(gribContainer_t)); streamptr->gribContainers = (void *) gribContainers; - - for ( i = 0; i < streamptr->nvars; ++i ) - { - gribContainers[i].gribHandle = gribHandleNew(editionNumber); - gribContainers[i].init = FALSE; - } +#endif } } -void gribContainersDelete(int streamID) +void gribContainersDelete(stream_t * streamptr) { - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - if ( streamptr->gribContainers ) { - int i; + int nvars = streamptr->nvars; + +#if defined (GRIBCONTAINER2D) + gribContainer_t **gribContainers = (gribContainer_t **) streamptr->gribContainers; + + for ( int varID = 0; varID < nvars; ++varID ) + { + int nlevs = streamptr->vars[varID].nlevs; + for ( int levelID = 0; levelID < nlevs; ++levelID ) + { + gribHandleDelete(gribContainers[varID][levelID].gribHandle); + } + free(gribContainers[varID]); + } +#else gribContainer_t *gribContainers = (gribContainer_t *) streamptr->gribContainers; - for ( i = 0; i < streamptr->nvars; ++i ) + for ( int varID = 0; varID < nvars; ++varID ) { - gribHandleDelete(gribContainers[i].gribHandle); + gribHandleDelete(gribContainers[varID].gribHandle); } - free(streamptr->gribContainers); +#endif + + free(gribContainers); + streamptr->gribContainers = NULL; } } diff --git a/src/gribapi.h b/src/gribapi.h index 8d59aadf9..080e39d4b 100644 --- a/src/gribapi.h +++ b/src/gribapi.h @@ -5,6 +5,9 @@ /* GRIB2 Level Types */ #define GRIB2_LTYPE_SURFACE 1 +#define GRIB2_LTYPE_CLOUDBASE 2 +#define GRIB2_LTYPE_CLOUDTOP 3 +#define GRIB2_LTYPE_ISOTHERM0 4 #define GRIB2_LTYPE_TOA 8 #define GRIB2_LTYPE_SEA_BOTTOM 9 #define GRIB2_LTYPE_ATMOSPHERE 10 @@ -34,8 +37,8 @@ #define GRIB2_GTYPE_NUMBER 101 /* General Unstructured Grid */ const char *gribapiLibraryVersion(void); -void gribContainersNew(int streamID); -void gribContainersDelete(int streamID); +void gribContainersNew(stream_t * streamptr); +void gribContainersDelete(stream_t * streamptr); void *gribHandleNew(int editionNumber); void gribHandleDelete(void *gh); diff --git a/src/grid.c b/src/grid.c index a4602e86d..72ecfa18a 100644 --- a/src/grid.c +++ b/src/grid.c @@ -3,6 +3,11 @@ #endif #include <string.h> +#include <float.h> /* FLT_EPSILON */ + +#ifdef USE_MPI +#include <mpi.h> +#endif #ifdef USE_MPI #include <mpi.h> @@ -210,8 +215,6 @@ int gridSize(void) void gridGenXvals(int xsize, double xfirst, double xlast, double xinc, double *xvals) { - long i; - if ( (! (fabs(xinc) > 0)) && xsize > 1 ) { if ( xfirst >= xlast ) @@ -225,7 +228,7 @@ void gridGenXvals(int xsize, double xfirst, double xlast, double xinc, double *x } } - for ( i = 0; i < xsize; i++ ) + for ( int i = 0; i < xsize; ++i ) xvals[i] = xfirst + i*xinc; } @@ -2199,9 +2202,10 @@ void grid_check_cyclic(grid_t *gridptr) if ( xvals && xsize > 1 ) { xinc = xvals[1] - xvals[0]; - if ( IS_EQUAL(xinc, 0) ) - xinc = (xvals[xsize-1] - xvals[0])/(xsize-1); + if ( IS_EQUAL(xinc, 0) ) xinc = (xvals[xsize-1] - xvals[0])/(xsize-1); + x0 = 2*xvals[xsize-1]-xvals[xsize-2]-360; + if ( IS_NOT_EQUAL(xvals[0], xvals[xsize-1]) ) if ( fabs(x0 - xvals[0]) < 0.01*xinc ) gridptr->isCyclic = TRUE; } @@ -2229,6 +2233,7 @@ void grid_check_cyclic(grid_t *gridptr) if ( valn < 1 && val1 > 300 ) valn += 360; if ( val1 < -179 && valn > 120 ) val1 += 360; if ( valn < -179 && val1 > 120 ) valn += 360; + if ( fabs(valn-val1) > 180 ) val1 += 360; if ( valn > val1 ) x0 = valn - xinc; else x0 = valn + xinc; @@ -2260,6 +2265,7 @@ void grid_check_cyclic(grid_t *gridptr) if ( val2 < 1 && val1 > 300 ) val2 += 360; if ( val1 < -179 && val2 > 120 ) val1 += 360; if ( val2 < -179 && val1 > 120 ) val2 += 360; + if ( fabs(val2-val1) > 180 ) val1 += 360; if ( fabs(val1-val2) < 0.001 ) { @@ -2546,37 +2552,36 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) if ( g1->rowlon ) { for ( i = 0; i < g1->nrowlon; i++ ) - if ( g1->rowlon[i] != g2->rowlon[i] ) return differ; - } + if ( g1->rowlon[i] != g2->rowlon[i] ) return differ; + } else if ( g2->rowlon ) return differ; - if ( g1->xfirst != g2->xfirst ) return differ; - if ( g1->yfirst != g2->yfirst ) return differ; - if ( g1->xlast != g2->xlast ) return differ; - if ( g1->ylast != g2->ylast ) return differ; - if ( g1->xinc != g2->xinc ) return differ; - if ( g1->yinc != g2->yinc ) return differ; - if ( g1->lcc_originLon != g2->lcc_originLon ) return differ; - if ( g1->lcc_originLat != g2->lcc_originLat ) return differ; - if ( g1->lcc_lonParY != g2->lcc_lonParY ) return differ; - if ( g1->lcc_lat1 != g2->lcc_lat1 ) return differ; - if ( g1->lcc_lat2 != g2->lcc_lat2 ) return differ; - if ( g1->lcc_xinc != g2->lcc_xinc ) return differ; - if ( g1->lcc_yinc != g2->lcc_yinc ) return differ; - if ( g1->lcc2_lon_0 != g2->lcc2_lon_0 ) return differ; - if ( g1->lcc2_lat_0 != g2->lcc2_lat_0 ) return differ; - if ( g1->lcc2_lat_1 != g2->lcc2_lat_1 ) return differ; - if ( g1->lcc2_lat_2 != g2->lcc2_lat_2 ) return differ; - if ( g1->lcc2_a != g2->lcc2_a ) return differ; - if ( g1->laea_lon_0 != g2->laea_lon_0 ) return differ; - if ( g1->laea_lat_0 != g2->laea_lat_0 ) return differ; - if ( g1->laea_a != g2->laea_a ) return differ; - if ( g1->xpole != g2->xpole ) return differ; - if ( g1->ypole != g2->ypole ) return differ; - if ( g1->angle != g2->angle ) return differ; + if ( IS_NOT_EQUAL(g1->xfirst , g2->xfirst) ) return differ; + if ( IS_NOT_EQUAL(g1->yfirst , g2->yfirst) ) return differ; + if ( IS_NOT_EQUAL(g1->xlast , g2->xlast) ) return differ; + if ( IS_NOT_EQUAL(g1->ylast , g2->ylast) ) return differ; + if ( IS_NOT_EQUAL(g1->xinc , g2->xinc) ) return differ; + if ( IS_NOT_EQUAL(g1->yinc , g2->yinc) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_originLon , g2->lcc_originLon) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_originLat , g2->lcc_originLat) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_lonParY , g2->lcc_lonParY) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_lat1 , g2->lcc_lat1) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_lat2 , g2->lcc_lat2) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_xinc , g2->lcc_xinc) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc_yinc , g2->lcc_yinc) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc2_lon_0 , g2->lcc2_lon_0) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc2_lat_0 , g2->lcc2_lat_0) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc2_lat_1 , g2->lcc2_lat_1) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc2_lat_2 , g2->lcc2_lat_2) ) return differ; + if ( IS_NOT_EQUAL(g1->lcc2_a , g2->lcc2_a) ) return differ; + if ( IS_NOT_EQUAL(g1->laea_lon_0 , g2->laea_lon_0) ) return differ; + if ( IS_NOT_EQUAL(g1->laea_lat_0 , g2->laea_lat_0) ) return differ; + if ( IS_NOT_EQUAL(g1->laea_a , g2->laea_a) ) return differ; + if ( IS_NOT_EQUAL(g1->xpole , g2->xpole) ) return differ; + if ( IS_NOT_EQUAL(g1->ypole , g2->ypole) ) return differ; + if ( IS_NOT_EQUAL(g1->angle , g2->angle) ) return differ; - if ( g1->xvals ) { if ( g1->type == GRID_UNSTRUCTURED || g1->type == GRID_CURVILINEAR ) @@ -2588,11 +2593,11 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) if ( !g2->xvals ) return differ; for ( i = 0; i < size; i++ ) - if ( g1->xvals[i] != g2->xvals[i] ) return differ; - } + if ( IS_NOT_EQUAL(g1->xvals[i], g2->xvals[i]) ) return differ; + } else if ( g2->xvals ) return differ; - + if ( g1->yvals ) { if ( g1->type == GRID_UNSTRUCTURED || g1->type == GRID_CURVILINEAR ) @@ -2604,11 +2609,11 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) if ( !g2->yvals ) return differ; for ( i = 0; i < size; i++ ) - if ( g1->yvals[i] != g2->yvals[i] ) return differ; - } + if ( IS_NOT_EQUAL(g1->yvals[i], g2->yvals[i]) ) return differ; + } else if ( g2->yvals ) return differ; - + if ( g1->area ) { xassert ( g1->size ); @@ -2616,8 +2621,8 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) if ( !g2->area ) return differ; for ( i = 0; i < g1->size; i++ ) - if ( g1->area[i] != g2->area[i] ) return differ; - } + if ( IS_NOT_EQUAL(g1->area[i], g2->area[i]) ) return differ; + } else if ( g2->area ) return differ; @@ -2633,8 +2638,8 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) if ( !g2->xbounds ) return differ; for ( i = 0; i < size; i++ ) - if ( g1->xbounds[i] != g2->xbounds[i] ) return differ; - } + if ( IS_NOT_EQUAL(g1->xbounds[i], g2->xbounds[i]) ) return differ; + } else if ( g2->xbounds ) return differ; @@ -2650,34 +2655,25 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) if ( !g2->ybounds ) return differ; for ( i = 0; i < size; i++ ) - if ( g1->ybounds[i] != g2->ybounds[i] ) return differ; - } + if ( IS_NOT_EQUAL(g1->ybounds[i], g2->ybounds[i]) ) return differ; + } else if ( g2->ybounds ) return differ; - if ( memcmp ( &g1->xname ,&g2->xname ,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->yname ,&g2->yname ,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->xlongname,&g2->xlongname,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->ylongname,&g2->ylongname,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->xstdname ,&g2->xstdname ,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->ystdname ,&g2->ystdname ,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->xunits ,&g2->xunits ,CDI_MAX_NAME )) - return differ; - if ( memcmp ( &g1->yunits ,&g2->yunits ,CDI_MAX_NAME )) - return differ; + if ( memcmp ( &g1->xname ,&g2->xname ,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->yname ,&g2->yname ,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->xlongname,&g2->xlongname,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->ylongname,&g2->ylongname,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->xstdname ,&g2->xstdname ,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->ystdname ,&g2->ystdname ,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->xunits ,&g2->xunits ,CDI_MAX_NAME ) ) return differ; + if ( memcmp ( &g1->yunits ,&g2->yunits ,CDI_MAX_NAME ) ) return differ; if ( g1->reference ) { if ( !g2->reference ) return differ; size = strlen ( g1->reference ) + 1; - if ( memcmp ( g1->reference, g2->reference, size )) - return differ; + if ( memcmp ( g1->reference, g2->reference, size ) ) return differ; } else if ( g2->reference ) return differ; @@ -2686,8 +2682,7 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) { xassert ( g1->size ); if ( !g2->mask ) return differ; - if ( memcmp ( g1->mask, g2->mask, g1->size * sizeof ( unsigned char ))) - return differ; + if ( memcmp ( g1->mask, g2->mask, g1->size*sizeof(unsigned char)) ) return differ; } else if ( g2->mask ) return differ; @@ -2696,8 +2691,7 @@ int gridCompareP ( void * gridptr1, void * gridptr2 ) { xassert ( g1->size ); if ( !g2->mask_gme ) return differ; - if ( memcmp ( g1->mask_gme, g2->mask_gme, - g1->size * sizeof ( unsigned char ))) return differ; + if ( memcmp ( g1->mask_gme, g2->mask_gme, g1->size*sizeof(unsigned char)) ) return differ; } else if ( g2->mask_gme ) return differ; @@ -3438,7 +3432,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) int nbyte0, nbyte; int i; int nvertex, iv; - char uuid[17]; + char uuidOfHGrid[17]; int gridID = gridptr->self; const double *area = gridInqAreaPtr(gridID); const double *xvals = gridInqXvalsPtr(gridID); @@ -3505,7 +3499,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) if ( type == GRID_LAEA ) { - double a, lon_0, lat_0; + double a = 0, lon_0 = 0, lat_0 = 0; gridInqLaea(gridID, &a, &lon_0, &lat_0); fprintf(fp, "a = %g\n", a); fprintf(fp, "lon_0 = %g\n", lon_0); @@ -3514,7 +3508,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) if ( type == GRID_LCC2 ) { - double a, lon_0, lat_0, lat_1, lat_2; + double a = 0, lon_0 = 0, lat_0 = 0, lat_1 = 0, lat_2 = 0; gridInqLcc2(gridID, &a, &lon_0, &lat_0, &lat_1, &lat_2); fprintf(fp, "a = %g\n", a); fprintf(fp, "lon_0 = %g\n", lon_0); @@ -3534,8 +3528,8 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) { double xfirst = 0.0, xinc = 0.0; - if ( type == GRID_LONLAT || type == GRID_GAUSSIAN || - type == GRID_GENERIC || type == GRID_LCC2 || + if ( type == GRID_LONLAT || type == GRID_GAUSSIAN || + type == GRID_GENERIC || type == GRID_LCC2 || type == GRID_SINUSOIDAL || type == GRID_LAEA ) { xfirst = gridInqXval(gridID, 0); @@ -3667,8 +3661,8 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) } case GRID_LCC: { - double originLon, originLat, lonParY, lat1, lat2, xincm, yincm; - int projflag, scanflag; + double originLon = 0, originLat = 0, lonParY = 0, lat1 = 0, lat2 = 0, xincm = 0, yincm = 0; + int projflag = 0, scanflag = 0; gridInqLCC(gridID, &originLon, &originLat, &lonParY, &lat1, &lat2, &xincm, &yincm, &projflag, &scanflag); @@ -3707,14 +3701,16 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) } case GRID_REFERENCE: { - const unsigned char *d; + // const unsigned char *d; fprintf(fp, "number = %d\n", gridInqNumber(gridID)); fprintf(fp, "position = %d\n", gridInqPosition(gridID)); - gridInqUUID(gridID, uuid); - d = (unsigned char *) &uuid; + /* + gridInqUUID(gridID, uuidOfHGrid); + d = (unsigned char *) &uuidOfHGrid; fprintf(fp, "uuid = %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); + */ if ( gridInqReference(gridID, NULL) ) { char reference_link[8192]; @@ -3726,9 +3722,19 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp) default: { fprintf(stderr, "Unsupported grid type: %s\n", gridNamePtr(type)); + break; } } + gridInqUUID(gridID, uuidOfHGrid); + if ( uuidOfHGrid[0] != 0 ) + { + char uuidOfHGridStr[37]; + uuid2str(uuidOfHGrid, uuidOfHGridStr); + if ( uuidOfHGridStr[0] != 0 && strlen(uuidOfHGridStr) == 36 ) + fprintf(fp, "uuid = %s\n", uuidOfHGridStr); + } + if ( gridptr->mask ) { nbyte0 = fprintf(fp, "mask = "); diff --git a/src/grid.h b/src/grid.h index 83748a98f..f44a9844b 100644 --- a/src/grid.h +++ b/src/grid.h @@ -73,6 +73,8 @@ grid_t; void grid_init(grid_t *gridptr); void grid_free(grid_t *gridptr); +int gridSize(void); + const double *gridInqXvalsPtr(int gridID); const double *gridInqYvalsPtr(int gridID); @@ -83,7 +85,7 @@ const double *gridInqAreaPtr(int gridID); int gridCompare(int gridID, grid_t grid); int gridGenerate(grid_t grid); -void gridGetIndexList ( int, int * ); +void gridGetIndexList( int, int * ); #endif /* diff --git a/src/ieglib.c b/src/ieglib.c index 0a6021d86..596246825 100644 --- a/src/ieglib.c +++ b/src/ieglib.c @@ -29,7 +29,7 @@ static int iegDefaultDprec = 0; */ #undef LIBVERSION -#define LIBVERSION 1.3.0 +#define LIBVERSION 1.3.1 #define XSTRING(x) #x #define STRING(x) XSTRING(x) static const char ieg_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__; @@ -76,6 +76,7 @@ void iegLibInit() } default: Message("Invalid character in %s: %s", envName, envString); + break; } pos += 2; } @@ -275,6 +276,7 @@ int iegInqData(iegrec_t *iegp, int prec, void *data) default: { Error("unexpected data precision %d", dprec); + break; } } @@ -354,6 +356,7 @@ int iegDefData(iegrec_t *iegp, int prec, const void *data) default: { Error("unexpected data precision %d", dprec); + break; } } @@ -378,7 +381,7 @@ int iegRead(int fileID, iegrec_t *iegp) size_t datasize; size_t blocklen, blocklen2; size_t i; - char tmpbuf[800], *bufp = tmpbuf; + char tmpbuffer[800], *tmpbuf = tmpbuffer; int dprec = 0; void *buffer; int buffersize; @@ -414,41 +417,41 @@ int iegRead(int fileID, iegrec_t *iegp) iegp->dprec = dprec; - binReadInt32(fileID, byteswap, 37, (INT32 *) bufp); - for ( i = 0; i < 37; i++ ) iegp->ipdb[i] = (int) ((INT32 *) bufp)[i]; + binReadInt32(fileID, byteswap, 37, (INT32 *) tmpbuf); + for ( i = 0; i < 37; i++ ) iegp->ipdb[i] = (int) ((INT32 *) tmpbuf)[i]; - binReadInt32(fileID, byteswap, 18, (INT32 *) bufp); - for ( i = 0; i < 18; i++ ) iegp->igdb[i] = (int) ((INT32 *) bufp)[i]; + binReadInt32(fileID, byteswap, 18, (INT32 *) tmpbuf); + for ( i = 0; i < 18; i++ ) iegp->igdb[i] = (int) ((INT32 *) tmpbuf)[i]; if ( blocklen == 636 || blocklen == 1036 ) { - fileRead(fileID, bufp, 4); - if ( byteswap ) swap4byte(bufp, 1); - iegp->refval = (double) ((float *) bufp)[0]; + fileRead(fileID, tmpbuf, 4); + if ( byteswap ) swap4byte(tmpbuf, 1); + iegp->refval = (double) ((float *) tmpbuf)[0]; } else { - fileRead(fileID, bufp, 8); - if ( byteswap ) swap8byte(bufp, 1); - iegp->refval = (double) ((double *) bufp)[0]; + fileRead(fileID, tmpbuf, 8); + if ( byteswap ) swap8byte(tmpbuf, 1); + iegp->refval = (double) ((double *) tmpbuf)[0]; } - binReadInt32(fileID, byteswap, 3, (INT32 *) bufp); - for ( i = 0; i < 3; i++ ) iegp->igdb[18+i] = (int) ((INT32 *) bufp)[i]; + binReadInt32(fileID, byteswap, 3, (INT32 *) tmpbuf); + for ( i = 0; i < 3; i++ ) iegp->igdb[18+i] = (int) ((INT32 *) tmpbuf)[i]; if ( dprec == SINGLE_PRECISION ) { - fileRead(fileID, bufp, 400); - if ( byteswap ) swap4byte(bufp, 100); + fileRead(fileID, tmpbuf, 400); + if ( byteswap ) swap4byte(tmpbuf, 100); for ( i = 0; i < 100; i++ ) - iegp->vct[i] = (double) ((float *) bufp)[i]; + iegp->vct[i] = (double) ((float *) tmpbuf)[i]; } else { - fileRead(fileID, bufp, 800); - if ( byteswap ) swap8byte(bufp, 100); + fileRead(fileID, tmpbuf, 800); + if ( byteswap ) swap8byte(tmpbuf, 100); for ( i = 0; i < 100; i++ ) - iegp->vct[i] = (double) ((double *) bufp)[i]; + iegp->vct[i] = (double) ((double *) tmpbuf)[i]; } /* @@ -592,6 +595,7 @@ int iegWrite(int fileID, iegrec_t *iegp) default: { Error("unexpected data precision %d", dprec); + break; } } diff --git a/src/institution.c b/src/institution.c index 110b04d6b..67c2b9531 100644 --- a/src/institution.c +++ b/src/institution.c @@ -208,8 +208,7 @@ int institutInq(int center, int subcenter, const char *name, const char *longnam for ( i = 0; i < instCount; i++ ) { - instID = instResHs[i]; - ip2 = ( institute_t * ) reshGetVal ( instID, &instituteOps ); + ip2 = ( institute_t * ) reshGetVal ( instResHs[i], &instituteOps ); xassert ( ip2 ); if ( ip2->used && ! instituteCompareKernel ( ip1, ip2 )) @@ -245,11 +244,12 @@ int institutDef(int center, int subcenter, const char *name, const char *longnam int institutInqCenter(int instID) { - institute_t * instituteptr; + institute_t * instituteptr = NULL; instituteInit (); - instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); + if ( instID != UNDEFID ) + instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); return instituteptr ? instituteptr->center : UNDEFID; } @@ -257,11 +257,12 @@ int institutInqCenter(int instID) int institutInqSubcenter(int instID) { - institute_t * instituteptr; + institute_t * instituteptr = NULL; instituteInit (); - instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); + if ( instID != UNDEFID ) + instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); return instituteptr ? instituteptr->subcenter: UNDEFID; } @@ -269,11 +270,12 @@ int institutInqSubcenter(int instID) char *institutInqNamePtr(int instID) { - institute_t * instituteptr; + institute_t * instituteptr = NULL; instituteInit (); - instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); + if ( instID != UNDEFID ) + instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); return instituteptr ? instituteptr->name : NULL; } @@ -281,11 +283,12 @@ char *institutInqNamePtr(int instID) char *institutInqLongnamePtr(int instID) { - institute_t * instituteptr; + institute_t * instituteptr = NULL; instituteInit (); - instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); + if ( instID != UNDEFID ) + instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps ); return instituteptr ? instituteptr->longname : NULL; } diff --git a/src/make_cdilib b/src/make_cdilib index 1e2093e5c..33cb3e173 100755 --- a/src/make_cdilib +++ b/src/make_cdilib @@ -33,6 +33,10 @@ cat > ${PROG} << EOR # include "config.h" #endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 +#endif + #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -59,7 +63,7 @@ cat > ${PROG} << EOR # include <grib_api.h> #endif -#if defined (HAVE_MMAP) +#if defined (HAVE_MMAP) # include <sys/mman.h> /* mmap() is defined in this header */ #endif @@ -71,51 +75,6 @@ cat > ${PROG} << EOR # include <szlib.h> #endif - -//#undef _GET_X86_COUNTER -//#undef _GET_IBM_COUNTER -//#undef _ARCH_PWR6 - -#if defined(__GNUC__) && (__GNUC__ >= 4) -#elif defined(__ICC) && (__ICC >= 1100) -#else -#define DISABLE_SIMD -#endif - -#ifdef DISABLE_SIMD -#ifndef ENABLE_AVX -#undef __AVX__ -#endif -#ifndef ENABLE_SSE2 -#undef __SSE2__ -#endif -#endif - -#ifdef _GET_IBM_COUNTER -#include <libhpc.h> -#endif - -#ifdef __AVX__ -#include <float.h> -#include <stdint.h> -#include <inttypes.h> -#include <immintrin.h> -#ifdef _GET_X86_COUNTER -#include <x86intrin.h> -#endif -#else -#ifdef __SSE2__ -#include <float.h> -#include <stdint.h> -#include <inttypes.h> -#include <emmintrin.h> -#ifdef _GET_X86_COUNTER -#include <x86intrin.h> -#endif -#endif -#endif - - #if ! defined (HAVE_CONFIG_H) # define HAVE_LIBGRIB 1 # define HAVE_LIBCGRIBEX 1 @@ -130,7 +89,6 @@ c="dmemory.c \ dmemory.h \ error.c \ error.h \ - stream_int.h \ taxis.c \ timebase.c \ calendar.c \ @@ -175,6 +133,7 @@ c="dmemory.c \ resource_handle.c \ pio_util.c \ pio.c \ + pio_interface.c \ pio_dbuffer.c \ pio_mpinonb.c \ pio_posixasynch.c \ @@ -182,10 +141,11 @@ c="dmemory.c \ pio_posixnonb.c \ pio_list_set.c" -h="cdi_limits.h taxis.h dtypes.h file.h cgribex.h gribapi.h service.h extra.h \ +h="cdi_limits.h taxis.h dtypes.h file.h service.h extra.h \ ieg.h cdi.h timebase.h calendar.h basetime.h datetime.h \ + stream_int.h cgribex.h gribapi.h \ stream_cgribex.h stream_gribapi.h stream_grb.h stream_cdf.h \ - tablepar.h table.h gaussgrid.h grid.h varscan.h binary.h swap.h \ + tablepar.h table.h gaussgrid.h grid.h zaxis.h varscan.h binary.h swap.h \ service.h stream_srv.h stream_ext.h stream_ieg.h cdf_int.h \ cdf.h vlist.h vlist_var.h vlist_att.h model.h institution.h \ namespace.h resource_handle.h pio_util.h pio.h pio_impl.h" @@ -198,7 +158,7 @@ for hfile in $h ; do done for cfile in $c ; do - cat $srcdir/$cfile | grep -v '#include' | grep -v '# include' >> ${PROG} + cat $srcdir/$cfile | grep -v '#include "' | grep -v '# include "' >> ${PROG} done diff --git a/src/make_fint.c b/src/make_fint.c index 8e972ba98..27e7e7d6d 100644 --- a/src/make_fint.c +++ b/src/make_fint.c @@ -1,4 +1,5 @@ #define _XOPEN_SOURCE 700 +#define _GNU_SOURCE // needed for getline(3) on some systems it seems #include <ctype.h> #include <regex.h> #include <stdio.h> @@ -9,7 +10,7 @@ //#include "config.h" -#define VERSION "1.5.6.1" +#define VERSION "1.6.0" typedef struct { size_t naline; @@ -93,7 +94,7 @@ struct symbol { static struct symbol funArgSym[] = { { "", "", "void", "^"WS"*void"WS"*)", 0, 0 }, - { "CHARACTER*80", "STRING", "char *", + { "CHARACTER(80)", "STRING", "char *", "^"WS"*const"WS"+char"WS"+\\*"SYMRE WS"*\\(", 1, 0 }, { "INTEGER", "INT", "int", "^"WS"*(const"WS"+)?int("WS"+"SYMRE")?"WS"*[,\\)]", 3, 0 }, @@ -720,13 +721,13 @@ int main(int argc, char *argv[]) cp = strrchr(fname, '.'); if ( cp == NULL ) len = strlen(fname); else len = (size_t)(cp - fname); - + memcpy(fnameinc, fname, len); memcpy(fnameint, fname, len); strcpy(fnameinc+len, ".inc"); strcpy(fnameint+len, "Fortran.c"); - + fortran_interface(fname, fnameinc, fnameint); return (0); @@ -848,3 +849,4 @@ static int cfXtIdxlistConvert(FILE *outfp, const char *argName, * require-trailing-newline: t * End: */ + diff --git a/src/model.c b/src/model.c index 1460a5844..1ee09fdba 100644 --- a/src/model.c +++ b/src/model.c @@ -68,7 +68,7 @@ model_t *modelNewEntry ( void ) modelptr = (model_t *) xmalloc(sizeof(model_t)); modelDefaultValue ( modelptr ); modelptr->self = reshPut (( void * ) modelptr, &modelOps ); - modelptr->used = 1; + modelptr->used = 1; return (modelptr); } @@ -184,9 +184,9 @@ int modelInq(int instID, int modelgribID, char *name) if ( modelptr->name ) { len = strlen(modelptr->name); - if ( memcmp(modelptr->name, name, len) == 0 ) break; + if ( strncmp(modelptr->name, name, len) == 0 ) break; len = strlen(name); - if ( memcmp(modelptr->name, name, len) == 0 ) break; + if ( strncmp(modelptr->name, name, len) == 0 ) break; } } } @@ -198,7 +198,7 @@ int modelInq(int instID, int modelgribID, char *name) } } - if ( modelID == modelCount ) modelID = UNDEFID; + if ( i == modelCount ) modelID = UNDEFID; if ( modelResHs ) free ( modelResHs ); @@ -224,11 +224,12 @@ int modelDef(int instID, int modelgribID, const char *name) int modelInqInstitut(int modelID) { - model_t *modelptr; + model_t *modelptr = NULL; modelInit (); - modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps ); + if ( modelID != UNDEFID ) + modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps ); return modelptr ? modelptr->instID : UNDEFID; } @@ -236,11 +237,12 @@ int modelInqInstitut(int modelID) int modelInqGribID(int modelID) { - model_t *modelptr; + model_t *modelptr = NULL; modelInit (); - modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps ); + if ( modelID != UNDEFID ) + modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps ); return modelptr ? modelptr->modelgribID : UNDEFID; } @@ -248,11 +250,12 @@ int modelInqGribID(int modelID) char *modelInqNamePtr(int modelID) { - model_t *modelptr; + model_t *modelptr = NULL; modelInit (); - modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps ); + if ( modelID != UNDEFID ) + modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps ); return modelptr ? modelptr->name : NULL; } diff --git a/src/pio_dbuffer.c b/src/pio_dbuffer.c index 95b85f3f5..a329d70ac 100644 --- a/src/pio_dbuffer.c +++ b/src/pio_dbuffer.c @@ -1,9 +1,11 @@ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H # include "config.h" #endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 +#endif + #include <stdlib.h> #include <stdio.h> #include <stdbool.h> diff --git a/src/pio_util.c b/src/pio_util.c index bfb451479..564565cdc 100644 --- a/src/pio_util.c +++ b/src/pio_util.c @@ -11,14 +11,15 @@ #include "pio_util.h" #include "cdi.h" +static char commands[][13] = { "FINALIZE\0", "RESOURCES\0", "WINCREATE\0", "WRITETS\0"}; -void pcdiAssert ( bool assumption, const char * filename, - const char * functionname, int line ) +void pcdiAssert(bool assumption, + const char * filename, const char * functionname, int line ) { if ( !assumption ) { @@ -44,6 +45,32 @@ void pcdiAssert ( bool assumption, const char * filename, /****************************************************/ +void pcdiAbortC(const char * caller, const char * filename, + const char *functionname, int line, + const char * errorString, ... ) +{ + va_list ap; + va_start(ap, errorString); +#ifdef USE_MPI + { + int rank; + MPI_Comm_rank ( MPI_COMM_WORLD, &rank ); + fprintf(stderr, "ERROR, pe%d in %s, %s, line %d, called from" + " %s\nerrorString: \"", rank, functionname, filename, line, caller); + } + vfprintf(stderr, errorString, ap); + fputs("\"\n", stderr); + MPI_Abort ( MPI_COMM_WORLD, 1 ); +#else + fprintf(stderr, "ERROR, %s, %s, line %d, called from %s\nerrorString: \"", + functionname, filename, line, caller); + vfprintf(stderr, errorString, ap); + fputs("\"\n", stderr); +#endif + exit ( EXIT_FAILURE ); + va_end(ap); +} + void pcdiAbort(const char * filename, const char *functionname, int line, const char * errorString, ... ) { diff --git a/src/pio_util.h b/src/pio_util.h index 545ae7358..41cc12133 100644 --- a/src/pio_util.h +++ b/src/pio_util.h @@ -45,7 +45,7 @@ # define __attribute__(x) /*NOTHING*/ #endif -void pcdiAssert ( bool, const char *, const char *, int ); +void pcdiAssert( bool, const char *, const char *, int ); #define xassert(arg) do { \ if ((arg)) { \ } else { \ @@ -129,6 +129,10 @@ char * outTextComm ( MPI_Comm * ); } #endif +void pcdiAbortC(const char *, const char *, const char *, int, const char *, ... ) + __attribute__((noreturn)); +#define xabortC(caller, ...) pcdiAbortC(caller, __FILE__, __func__, __LINE__, __VA_ARGS__ ) + void pcdiAbort (const char *, const char *, int, const char *, ... ) __attribute__((noreturn)); #define xabort(...) pcdiAbort(__FILE__, __func__, __LINE__, __VA_ARGS__ ) diff --git a/src/resource_handle.c b/src/resource_handle.c index e8d145925..682fdae7b 100644 --- a/src/resource_handle.c +++ b/src/resource_handle.c @@ -2,6 +2,10 @@ # include "config.h" #endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 /* PTHREAD_MUTEX_RECURSIVE */ +#endif + #include <stdlib.h> #include <stdio.h> @@ -11,6 +15,7 @@ #include "cdi.h" #include "error.h" #include "file.h" + #ifdef USE_MPI #include "pio_comm.h" #include "pio_rpc.h" @@ -158,8 +163,12 @@ static void listInitialize ( void ) { #if defined (HAVE_LIBPTHREAD) + pthread_mutexattr_t ma; + pthread_mutexattr_init(&ma); + pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE); /* initialize global API mutex lock */ - pthread_mutex_init ( &listMutex, NULL); + pthread_mutex_init ( &listMutex, &ma); + pthread_mutexattr_destroy(&ma); #endif listNew (); @@ -183,7 +192,8 @@ void listInitialize ( void ) /**************************************************************/ -static void listSizeExtend() +static +void listSizeExtend() { int newListSize; int i, nsp; @@ -267,7 +277,7 @@ void reshRemove ( cdiResH resH, resOps * ops ) /**************************************************************/ -void *reshGetVal ( cdiResH resH, resOps * ops ) +void *reshGetValue(const char * caller, cdiResH resH, resOps * ops) { int nsp; namespaceTuple_t nspT; @@ -293,10 +303,13 @@ void *reshGetVal ( cdiResH resH, resOps * ops ) else { LIST_UNLOCK(); - xabort("invalid namespace %d or index %d", nspT.nsp, nspT.idx); + xabortC(caller, "Invalid namespace %d or index %d for resource handle %d!", + nspT.nsp, nspT.idx, (int)resH); } - xassert(listElem && listElem->ops == ops); + if ( !(listElem && listElem->ops == ops) ) + xabortC(caller, "Invalid resource handle %d, list element not found!", + (int)resH); return listElem->val; } @@ -667,6 +680,19 @@ void reshListPrint ( char * filename ) pioNamespaceSetActive ( temp ); } + +void cdiReset(void) +{ + LIST_LOCK(); + + listDestroy(); + + listNew (); + + listInitPointer (); + + LIST_UNLOCK(); +} /* * Local Variables: * c-file-style: "Java" diff --git a/src/resource_handle.h b/src/resource_handle.h index d11072ce4..d3529663e 100644 --- a/src/resource_handle.h +++ b/src/resource_handle.h @@ -47,7 +47,8 @@ void reshRemove ( cdiResH, resOps * ); int reshCountType ( resOps * ); -void * reshGetVal ( cdiResH, resOps * ); +void * reshGetValue(const char *, cdiResH, resOps * ); +#define reshGetVal(resH, ops) reshGetValue(__func__, resH, ops) void reshGetResHListOfType ( int, int *, resOps * ); diff --git a/src/servicelib.c b/src/servicelib.c index 8ea8581d2..f38ed9dc8 100644 --- a/src/servicelib.c +++ b/src/servicelib.c @@ -32,7 +32,7 @@ static int srvDefaultDprec = 0; */ #undef LIBVERSION -#define LIBVERSION 1.3.0 +#define LIBVERSION 1.3.1 #define XSTRING(x) #x #define STRING(x) XSTRING(x) static const char srv_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__; @@ -98,6 +98,7 @@ void srvLibInit() } default: Message("Invalid character in %s: %s", envName, envString); + break; } pos += 2; } @@ -296,6 +297,7 @@ int srvInqData(srvrec_t *srvp, int prec, void *data) default: { Error("unexpected data precision %d", dprec); + break; } } @@ -384,6 +386,7 @@ int srvDefData(srvrec_t *srvp, int prec, const void *data) default: { Error("unexpected data precision %d", dprec); + break; } } @@ -459,6 +462,7 @@ int srvRead(int fileID, srvrec_t *srvp) default: { Error("unexpected header precision %d", hprec); + break; } } @@ -559,6 +563,7 @@ int srvWrite(int fileID, srvrec_t *srvp) default: { Error("unexpected header precision %d", hprec); + break; } } @@ -588,6 +593,7 @@ int srvWrite(int fileID, srvrec_t *srvp) default: { Error("unexpected data precision %d", dprec); + break; } } diff --git a/src/stream.c b/src/stream.c index 6ec5d4c02..8625a774e 100644 --- a/src/stream.c +++ b/src/stream.c @@ -58,15 +58,15 @@ cdiPrintDefaults(void) void cdiDebug(int level) { - if ( level == 1 || level & 2 ) CDI_Debug = 1; + if ( level == 1 || (level & 2) ) CDI_Debug = 1; if ( CDI_Debug ) Message("debug level %d", level); - if ( level == 1 || level & 4 ) memDebug(1); + if ( level == 1 || (level & 4) ) memDebug(1); - if ( level == 1 || level & 8 ) fileDebug(1); + if ( level == 1 || (level & 8) ) fileDebug(1); - if ( level == 1 || level & 16 ) + if ( level == 1 || (level & 16) ) { #if defined (HAVE_LIBGRIB) gribSetDebug(1); @@ -97,7 +97,8 @@ void cdiDebug(int level) #define IsBigendian() ( u_byteorder.c[sizeof(long) - 1] ) -static int getByteorder(int byteswap) +static +int getByteorder(int byteswap) { static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1}; int byteorder = -1; @@ -117,7 +118,8 @@ static int getByteorder(int byteswap) } -static int getFiletype(const char *filename, int *byteorder) +static +int getFiletype(const char *filename, int *byteorder) { int filetype = CDI_EUFTYPE; int fileID; @@ -511,7 +513,7 @@ char *streamFilename(int streamID) return (streamptr->filename); } - +static int cdiInqTimeSize(int streamID) { int ntsteps; @@ -532,18 +534,13 @@ int cdiInqTimeSize(int streamID) return (ntsteps); } - -int cdiInqContents(int streamID) +static +int cdiInqContents(stream_t * streamptr) { int filetype; int vlistID; int taxisID; int status = 0; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); filetype = streamptr->filetype; @@ -553,28 +550,28 @@ int cdiInqContents(int streamID) case FILETYPE_GRB: case FILETYPE_GRB2: { - status = grbInqContents(streamID); + status = grbInqContents(streamptr); break; } #endif #if defined (HAVE_LIBSERVICE) case FILETYPE_SRV: { - status = srvInqContents(streamID); + status = srvInqContents(streamptr); break; } #endif #if defined (HAVE_LIBEXTRA) case FILETYPE_EXT: { - status = extInqContents(streamID); + status = extInqContents(streamptr); break; } #endif #if defined (HAVE_LIBIEG) case FILETYPE_IEG: { - status = iegInqContents(streamID); + status = iegInqContents(streamptr); break; } #endif @@ -584,7 +581,7 @@ int cdiInqContents(int streamID) case FILETYPE_NC4: case FILETYPE_NC4C: { - status = cdfInqContents(streamID); + status = cdfInqContents(streamptr); break; } #endif @@ -594,15 +591,22 @@ int cdiInqContents(int streamID) Message("%s support not compiled in!", strfiletype(filetype)); status = CDI_ELIBNAVAIL; + break; } } if ( status == 0 ) { - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; taxisID = vlistInqTaxis(vlistID); if ( taxisID != -1 ) - ptaxisCopy(taxisPtr(taxisID), &streamptr->tsteps[0].taxis); + { + taxis_t *taxisptr1 = &streamptr->tsteps[0].taxis; + taxis_t *taxisptr2 = taxisPtr(taxisID); + ptaxisCopy(taxisptr2, taxisptr1); + if ( taxisptr1->name ) taxisptr2->name = taxisptr1->name; + if ( taxisptr1->longname ) taxisptr2->longname = taxisptr1->longname; + } } return (status); @@ -771,7 +775,7 @@ int streamOpen(const char *filename, const char *filemode, int filetype) streamptr->vlistID = vlistID; /* cdiReadByteorder(streamID); */ - status = cdiInqContents(streamID); + status = cdiInqContents(streamptr); if ( status < 0 ) return (status); vlistptr = vlist_to_pointer(streamptr->vlistID); vlistptr->ntsteps = streamNtsteps(streamID); @@ -881,7 +885,7 @@ int streamOpenA(const char *filename, const char *filemode, int filetype) streamptr->vlistID = vlistCreate(); /* cdiReadByteorder(streamID); */ - status = cdiInqContents(streamID); + status = cdiInqContents(streamptr); if ( status < 0 ) return (status); vlistptr = vlist_to_pointer(streamptr->vlistID); vlistptr->ntsteps = cdiInqTimeSize(streamID); @@ -1208,7 +1212,7 @@ void streamClose(int streamID) case FILETYPE_GRB2: { gribClose(fileID); - gribContainersDelete(streamID); + gribContainersDelete(streamptr); break; } #endif @@ -1359,7 +1363,7 @@ void streamSync(int streamID) fileID = streamptr->fileID; filetype = streamptr->filetype; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; nvars = vlistNvars(vlistID); if ( fileID == CDI_UNDEFID ) @@ -1417,7 +1421,10 @@ int streamDefTimestep(int streamID, int tsID) int newtsID; int taxisID; int vlistID; + int time_is_varying; stream_t *streamptr; + taxis_t *taxisptr1; + taxis_t *taxisptr2; streamptr = stream_to_pointer(streamID); @@ -1426,23 +1433,39 @@ int streamDefTimestep(int streamID, int tsID) stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); - taxisID = vlistInqTaxis(vlistID); - if ( taxisID == CDI_UNDEFID ) + vlistID = streamptr->vlistID; + + time_is_varying = vlistHasTime(vlistID); + + if ( time_is_varying ) { - Warning("taxisID undefined for fileID = %d! Using absolute time axis.", streamID); - taxisID = taxisCreate(TAXIS_ABSOLUTE); - vlistDefTaxis(vlistID, taxisID); + taxisID = vlistInqTaxis(vlistID); + if ( taxisID == CDI_UNDEFID ) + { + Warning("taxisID undefined for fileID = %d! Using absolute time axis.", streamID); + taxisID = taxisCreate(TAXIS_ABSOLUTE); + vlistDefTaxis(vlistID, taxisID); + } } - newtsID = tstepsNewEntry(streamID); + newtsID = tstepsNewEntry(streamptr); if ( tsID != newtsID ) Error("Internal problem: tsID = %d newtsID = %d", tsID, newtsID); streamptr->curTsID = tsID; - ptaxisCopy(&streamptr->tsteps[tsID].taxis, taxisPtr(taxisID)); + if ( time_is_varying ) + { + taxisptr1 = taxisPtr(taxisID); + taxisptr2 = &streamptr->tsteps[tsID].taxis; + ptaxisCopy(taxisptr2, taxisptr1); + if ( tsID == 0 ) + { + if ( taxisptr1->name ) taxisptr2->name = taxisptr1->name; + if ( taxisptr1->longname ) taxisptr2->longname = taxisptr1->longname; + } + } streamptr->ntsteps = tsID + 1; @@ -1459,10 +1482,10 @@ int streamDefTimestep(int streamID, int tsID) || ((rank = commInqRankColl()) == (rankOpen = cdiPioSerialOpenFileMap(streamID)))) #endif - cdfDefTimestep(streamID, tsID); + cdfDefTimestep(streamptr, tsID); } - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); return (streamptr->ntsteps); } @@ -1496,7 +1519,7 @@ int streamInqTimestep(int streamID, int tsID) stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; if ( tsID < streamptr->rtsteps ) { @@ -1527,28 +1550,28 @@ int streamInqTimestep(int streamID, int tsID) case FILETYPE_GRB: case FILETYPE_GRB2: { - nrecs = grbInqTimestep(streamID, tsID); + nrecs = grbInqTimestep(streamptr, tsID); break; } #endif #if defined (HAVE_LIBSERVICE) case FILETYPE_SRV: { - nrecs = srvInqTimestep(streamID, tsID); + nrecs = srvInqTimestep(streamptr, tsID); break; } #endif #if defined (HAVE_LIBEXTRA) case FILETYPE_EXT: { - nrecs = extInqTimestep(streamID, tsID); + nrecs = extInqTimestep(streamptr, tsID); break; } #endif #if defined (HAVE_LIBIEG) case FILETYPE_IEG: { - nrecs = iegInqTimestep(streamID, tsID); + nrecs = iegInqTimestep(streamptr, tsID); break; } #endif @@ -1558,7 +1581,7 @@ int streamInqTimestep(int streamID, int tsID) case FILETYPE_NC4: case FILETYPE_NC4C: { - nrecs = cdfInqTimestep(streamID, tsID); + nrecs = cdfInqTimestep(streamptr, tsID); break; } #endif @@ -1619,28 +1642,28 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) case FILETYPE_GRB: case FILETYPE_GRB2: { - grbReadVarDP(streamID, varID, data, nmiss); + grbReadVarDP(streamptr, varID, data, nmiss); break; } #endif #if defined (HAVE_LIBSERVICE) case FILETYPE_SRV: { - srvReadVarDP(streamID, varID, data, nmiss); + srvReadVarDP(streamptr, varID, data, nmiss); break; } #endif #if defined (HAVE_LIBEXTRA) case FILETYPE_EXT: { - extReadVarDP(streamID, varID, data, nmiss); + extReadVarDP(streamptr, varID, data, nmiss); break; } #endif #if defined (HAVE_LIBIEG) case FILETYPE_IEG: { - iegReadVarDP(streamID, varID, data, nmiss); + iegReadVarDP(streamptr, varID, data, nmiss); break; } #endif @@ -1650,7 +1673,7 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss) case FILETYPE_NC4: case FILETYPE_NC4C: { - cdfReadVarDP(streamID, varID, data, nmiss); + cdfReadVarDP(streamptr, varID, data, nmiss); break; } #endif @@ -1701,7 +1724,7 @@ stream_write_var(int streamID, int varID, int memtype, const void *data, stream_check_ptr(__func__, streamptr); - streamDefineTaxis(streamID); + // streamDefineTaxis(streamID); filetype = streamptr->filetype; @@ -1711,8 +1734,7 @@ stream_write_var(int streamID, int varID, int memtype, const void *data, case FILETYPE_GRB: case FILETYPE_GRB2: { - if ( memtype == MEMTYPE_FLOAT ) Error("grbWriteVar not implemented for memtype float!"); - grbWriteVarDP(streamID, varID, data, nmiss); + grb_write_var(streamptr, varID, memtype, data, nmiss); break; } #endif @@ -1720,7 +1742,7 @@ stream_write_var(int streamID, int varID, int memtype, const void *data, case FILETYPE_SRV: { if ( memtype == MEMTYPE_FLOAT ) Error("srvWriteVar not implemented for memtype float!"); - srvWriteVarDP(streamID, varID, data); + srvWriteVarDP(streamptr, varID, data); break; } #endif @@ -1728,7 +1750,7 @@ stream_write_var(int streamID, int varID, int memtype, const void *data, case FILETYPE_EXT: { if ( memtype == MEMTYPE_FLOAT ) Error("extWriteVar not implemented for memtype float!"); - extWriteVarDP(streamID, varID, data); + extWriteVarDP(streamptr, varID, data); break; } #endif @@ -1736,7 +1758,7 @@ stream_write_var(int streamID, int varID, int memtype, const void *data, case FILETYPE_IEG: { if ( memtype == MEMTYPE_FLOAT ) Error("iegWriteVar not implemented for memtype float!"); - iegWriteVarDP(streamID, varID, data); + iegWriteVarDP(streamptr, varID, data); break; } #endif @@ -1746,8 +1768,8 @@ stream_write_var(int streamID, int varID, int memtype, const void *data, case FILETYPE_NC4: case FILETYPE_NC4C: { - if ( streamptr->accessmode == 0 ) cdfEndDef(streamID); - cdf_write_var(streamID, varID, memtype, data, nmiss); + if ( streamptr->accessmode == 0 ) cdfEndDef(streamptr); + cdf_write_var(streamptr, varID, memtype, data, nmiss); break; } #endif @@ -1785,9 +1807,6 @@ streamWriteVarPart(int streamID, int varID, int memtype, const void *data, int nmiss, Xt_idxlist partDesc) { #if defined USE_MPI - int filetype; - stream_t *streamptr; - if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID); check_parg(data); @@ -1876,28 +1895,28 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int case FILETYPE_GRB: case FILETYPE_GRB2: { - grbReadVarSliceDP(streamID, varID, levelID, data, nmiss); + grbReadVarSliceDP(streamptr, varID, levelID, data, nmiss); break; } #endif #if defined (HAVE_LIBSERVICE) case FILETYPE_SRV: { - srvReadVarSliceDP(streamID, varID, levelID, data, nmiss); + srvReadVarSliceDP(streamptr, varID, levelID, data, nmiss); break; } #endif #if defined (HAVE_LIBEXTRA) case FILETYPE_EXT: { - extReadVarSliceDP(streamID, varID, levelID, data, nmiss); + extReadVarSliceDP(streamptr, varID, levelID, data, nmiss); break; } #endif #if defined (HAVE_LIBIEG) case FILETYPE_IEG: { - iegReadVarSliceDP(streamID, varID, levelID, data, nmiss); + iegReadVarSliceDP(streamptr, varID, levelID, data, nmiss); break; } #endif @@ -1908,7 +1927,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int case FILETYPE_NC4C: { /* FIXME: status value ignored */ - int ierr = cdfReadVarSliceDP(streamID, varID, levelID, data, nmiss); + int ierr = cdfReadVarSliceDP(streamptr, varID, levelID, data, nmiss); break; } #endif @@ -1920,7 +1939,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int } } - +static void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, const void *data, int nmiss) { int filetype; @@ -1942,8 +1961,7 @@ void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, c case FILETYPE_GRB: case FILETYPE_GRB2: { - if ( memtype == MEMTYPE_FLOAT ) Error("grbWriteVarSlice not implemented for memtype float!"); - grbWriteVarSliceDP(streamID, varID, levelID, data, nmiss); + grb_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss); break; } #endif @@ -1951,7 +1969,7 @@ void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, c case FILETYPE_SRV: { if ( memtype == MEMTYPE_FLOAT ) Error("srvWriteVarSlice not implemented for memtype float!"); - srvWriteVarSliceDP(streamID, varID, levelID, data); + srvWriteVarSliceDP(streamptr, varID, levelID, data); break; } #endif @@ -1959,7 +1977,7 @@ void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, c case FILETYPE_EXT: { if ( memtype == MEMTYPE_FLOAT ) Error("extWriteVarSlice not implemented for memtype float!"); - extWriteVarSliceDP(streamID, varID, levelID, data); + extWriteVarSliceDP(streamptr, varID, levelID, data); break; } #endif @@ -1967,7 +1985,7 @@ void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, c case FILETYPE_IEG: { if ( memtype == MEMTYPE_FLOAT ) Error("iegWriteVarSlice not implemented for memtype float!"); - iegWriteVarSliceDP(streamID, varID, levelID, data); + iegWriteVarSliceDP(streamptr, varID, levelID, data); break; } #endif @@ -1978,8 +1996,8 @@ void stream_write_var_slice(int streamID, int varID, int levelID, int memtype, c case FILETYPE_NC4C: { int ierr = 0; - if ( streamptr->accessmode == 0 ) cdfEndDef(streamID); - ierr = cdf_write_var_slice(streamID, varID, levelID, memtype, data, nmiss); + if ( streamptr->accessmode == 0 ) cdfEndDef(streamptr); + ierr = cdf_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss); break; } #endif @@ -2058,7 +2076,7 @@ stream_write_var_chunk(int streamID, int varID, int memtype, stream_check_ptr(__func__, streamptr); - streamDefineTaxis(streamID); + // streamDefineTaxis(streamID); filetype = streamptr->filetype; @@ -2088,8 +2106,8 @@ stream_write_var_chunk(int streamID, int varID, int memtype, case FILETYPE_NC2: case FILETYPE_NC4: case FILETYPE_NC4C: - if ( streamptr->accessmode == 0 ) cdfEndDef(streamID); - cdf_write_var_chunk(streamID, varID, memtype, rect, data, nmiss); + if ( streamptr->accessmode == 0 ) cdfEndDef(streamptr); + cdf_write_var_chunk(streamptr, varID, memtype, rect, data, nmiss); break; #endif default: @@ -2126,7 +2144,7 @@ void streamWriteContents(int streamID, char *cname) stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; cnp = fopen(cname, "w"); @@ -2336,7 +2354,7 @@ void streamDefVlist(int streamID, int vlistID) { gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); - streamNewVar(streamID, gridID, zaxisID); + stream_new_var(streamptr, gridID, zaxisID); if ( streamptr->have_missval ) vlistDefVarMissval(streamptr->vlistID, varID, vlistInqVarMissval(vlistID, varID)); @@ -2356,12 +2374,12 @@ void streamDefVlist(int streamID, int vlistID) || ((rank = commInqRankColl()) == (rankOpen = cdiPioSerialOpenFileMap(streamID)))) #endif - cdfDefVars(streamID); + cdfDefVars(streamptr); } else if ( streamptr->filetype == FILETYPE_GRB || streamptr->filetype == FILETYPE_GRB2 ) { - gribContainersNew(streamID); + gribContainersNew(streamptr); } } } diff --git a/src/stream_cdf.c b/src/stream_cdf.c index b5efea328..daf64c91b 100644 --- a/src/stream_cdf.c +++ b/src/stream_cdf.c @@ -2,6 +2,7 @@ # include "config.h" #endif +//#define TEST_GROUPS 1 #include <stdio.h> #include <string.h> @@ -32,10 +33,9 @@ #define UNDEFID CDI_UNDEFID -void cdfDefGlobalAtts(int streamID); -void cdfDefLocalAtts(int streamID); +void cdfDefGlobalAtts(stream_t *streamptr); +void cdfDefLocalAtts(stream_t *streamptr); -#define MAXNAMELEN 256 #define X_AXIS 1 #define Y_AXIS 2 @@ -46,16 +46,18 @@ typedef struct { int ncvarid; int dimtype; size_t len; - char name[MAXNAMELEN]; + char name[CDI_MAX_NAME]; } ncdim_t; typedef struct { + int ncid; int ignore; int isvar; int islon; int islat; int islev; + int istime; int warn; int tsteptype; int param; @@ -86,6 +88,9 @@ typedef struct { int positive; int dimids[8]; int dimtype[8]; + int chunks[8]; + int chunked; + int chunktype; int natts; int *atts; int deflate; @@ -97,10 +102,11 @@ typedef struct { double addoffset; double scalefactor; double validrange[2]; - char name[MAXNAMELEN]; - char longname[MAXNAMELEN]; - char stdname[MAXNAMELEN]; - char units[MAXNAMELEN]; + char name[CDI_MAX_NAME]; + char longname[CDI_MAX_NAME]; + char stdname[CDI_MAX_NAME]; + char units[CDI_MAX_NAME]; + ensinfo_t *ensdata; /* Ensemble information */ } ncvar_t; @@ -427,7 +433,6 @@ int cdfDefDatatype(int datatype, int filetype) else xtype = NC_FLOAT; } - return (xtype); } @@ -445,6 +450,8 @@ void defineAttributes(int vlistID, int varID, int fileID, int ncvarID) { vlistInqAtt(vlistID, varID, iatt, attname, &atttype, &attlen); + if ( attlen == 0 ) continue; + if ( atttype == DATATYPE_TXT ) { char *atttxt; @@ -482,8 +489,7 @@ void defineAttributes(int vlistID, int varID, int fileID, int ncvarID) } #endif - -int cdfCopyRecord(int streamID2, int streamID1) +int cdfCopyRecord(stream_t *streamptr2, stream_t *streamptr1) { double *data; int datasize; @@ -493,14 +499,6 @@ int cdfCopyRecord(int streamID2, int streamID1) int ierr = 0; int memtype = MEMTYPE_DOUBLE; int vlistID1; - stream_t *streamptr1; - stream_t *streamptr2; - - streamptr1 = stream_to_pointer(streamID1); - streamptr2 = stream_to_pointer(streamID2); - - stream_check_ptr(__func__, streamptr1); - stream_check_ptr(__func__, streamptr2); vlistID1 = streamptr1->vlistID; @@ -518,8 +516,8 @@ int cdfCopyRecord(int streamID2, int streamID1) data = (double *) malloc(datasize*sizeof(double)); - streamReadRecord(streamID1, data, &nmiss); - stream_write_record(streamID2, memtype, data, nmiss); + cdfReadRecord(streamptr1, data, &nmiss); + cdf_write_record(streamptr2, memtype, data, nmiss); free(data); @@ -527,21 +525,15 @@ int cdfCopyRecord(int streamID2, int streamID1) } /* not used -int cdfInqRecord(int streamID, int *varID, int *levelID) +int cdfInqRecord(stream_t *streamptr, int *varID, int *levelID) { int tsID, recID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); recID = streamptr->tsteps[0].curRecID++; printf("cdfInqRecord recID %d %d\n", recID, streamptr->tsteps[0].curRecID); printf("cdfInqRecord tsID %d\n", streamptr->curTsID); - if ( streamptr->tsteps[0].curRecID >= - streamptr->tsteps[0].nrecs ) + if ( streamptr->tsteps[0].curRecID >= streamptr->tsteps[0].nrecs ) { streamptr->tsteps[0].curRecID = 0; } @@ -554,40 +546,31 @@ int cdfInqRecord(int streamID, int *varID, int *levelID) if ( CDI_Debug ) Message("recID = %d varID = %d levelID = %d", recID, *varID, *levelID); - + return (recID+1); } */ -int cdfDefRecord(int streamID) -{ - int ierr = 0; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - if ( CDI_Debug ) - Message("streamID = %d", streamID); - - stream_check_ptr(__func__, streamptr); +int cdfDefRecord(stream_t *streamptr) +{ + int ierr = 0; return (ierr); } #if defined (HAVE_LIBNETCDF) static -void cdfWriteGridTraj(int streamID, int gridID) +void cdfWriteGridTraj(stream_t *streamptr, int gridID) { int tsID, fileID; int lonID, latID, gridindex; size_t index; double xlon, xlat; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; gridindex = vlistGridIndex(vlistID, gridID); lonID = streamptr->xdimID[gridindex]; @@ -601,23 +584,18 @@ void cdfWriteGridTraj(int streamID, int gridID) cdf_put_var1_double(fileID, lonID, &index, &xlon); cdf_put_var1_double(fileID, latID, &index, &xlat); } -#endif -#if defined (HAVE_LIBNETCDF) static -void cdfReadGridTraj(int streamID, int gridID) +void cdfReadGridTraj(stream_t *streamptr, int gridID) { int tsID, fileID; int lonID, latID, gridindex; size_t index; double xlon, xlat; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; gridindex = vlistGridIndex(vlistID, gridID); lonID = streamptr->xdimID[gridindex]; @@ -691,12 +669,8 @@ void cdfDefVarSzip(int ncid, int ncvarid) #if defined (HAVE_LIBNETCDF) static -void cdfDefVarMissval(int streamID, int varID, int dtype, int lcheck) +void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck) { - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - if ( streamptr->vars[varID].defmiss == FALSE ) { int fileID; @@ -705,10 +679,11 @@ void cdfDefVarMissval(int streamID, int varID, int dtype, int lcheck) int vlistID; int xtype; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ncvarid = streamptr->vars[varID].ncvarid; missval = vlistInqVarMissval(vlistID, varID); + if ( lcheck && streamptr->ncmode == 2 ) cdf_redef(fileID); xtype = cdfDefDatatype(dtype, streamptr->filetype); @@ -725,35 +700,28 @@ void cdfDefVarMissval(int streamID, int varID, int dtype, int lcheck) } #endif -void cdf_write_record(int streamID, int memtype, const void *data, int nmiss) +void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nmiss) { #if defined (HAVE_LIBNETCDF) int varID; int levelID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); varID = streamptr->record->varID; levelID = streamptr->record->levelID; - if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); + if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID); - cdf_write_var_slice(streamID, varID, levelID, memtype, data, nmiss); + cdf_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss); #endif } -int cdfReadRecord(int streamID, double *data, int *nmiss) +int cdfReadRecord(stream_t *streamptr, double *data, int *nmiss) { int ierr = 0; int levelID, varID, tsID, recID, vrecID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - if ( CDI_Debug ) Message("streamID = %d", streamID); + if ( CDI_Debug ) Message("streamID = %d", streamptr->self); tsID = streamptr->curTsID; vrecID = streamptr->tsteps[tsID].curRecID; @@ -761,13 +729,13 @@ int cdfReadRecord(int streamID, double *data, int *nmiss) varID = streamptr->tsteps[tsID].records[recID].varID; levelID = streamptr->tsteps[tsID].records[recID].levelID; - cdfReadVarSliceDP(streamID, varID, levelID, data, nmiss); + cdfReadVarSliceDP(streamptr, varID, levelID, data, nmiss); return (ierr); } static -void cdfDefTimeValue(int streamID, int tsID) +void cdfDefTimeValue(stream_t *streamptr, int tsID) { #if defined (HAVE_LIBNETCDF) int fileID; @@ -775,14 +743,11 @@ void cdfDefTimeValue(int streamID, int tsID) int ncvarid; size_t index; taxis_t *taxis; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; if ( CDI_Debug ) - Message("streamID = %d, fileID = %d", streamID, fileID); + Message("streamID = %d, fileID = %d", streamptr->self, fileID); taxis = &streamptr->tsteps[tsID].taxis; @@ -821,7 +786,7 @@ printf("fileID = %d %d %d %f\n", fileID, time_varid, index, timevalue); } static -void cdfDefTime(int streamID) +void cdfDefTime(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) int fileID; @@ -831,34 +796,37 @@ void cdfDefTime(int streamID) int year, month, day, hour, minute, second; char unitstr[80]; char calstr[80]; - char tmpstr[256]; + char tmpstr[CDI_MAX_NAME]; + char default_name[] = "time"; + char *taxis_name = default_name; size_t len; taxis_t *taxis; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( streamptr->basetime.ncvarid != UNDEFID ) return; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; if ( streamptr->ncmode == 0 ) streamptr->ncmode = 1; if ( streamptr->ncmode == 2 ) cdf_redef(fileID); - cdf_def_dim(fileID, "time", NC_UNLIMITED, &streamptr->basetime.ncdimid); + taxis = &streamptr->tsteps[0].taxis; - dims[0] = streamptr->basetime.ncdimid; - cdf_def_var(fileID, "time", NC_DOUBLE, 1, dims, &time_varid); + if ( taxis->name && taxis->name[0] ) taxis_name = taxis->name; - streamptr->basetime.ncvarid = time_varid; + cdf_def_dim(fileID, taxis_name, NC_UNLIMITED, &streamptr->basetime.ncdimid); - taxis = &streamptr->tsteps[0].taxis; + dims[0] = streamptr->basetime.ncdimid; + cdf_def_var(fileID, taxis_name, NC_DOUBLE, 1, dims, &time_varid); + streamptr->basetime.ncvarid = time_varid; strcpy(tmpstr, "time"); cdf_put_att_text(fileID, time_varid, "standard_name", strlen(tmpstr), tmpstr); + if ( taxis->longname && taxis->longname[0] ) + cdf_put_att_text(fileID, time_varid, "long_name", strlen(taxis->longname), taxis->longname); + if ( taxis->has_bounds ) { /* fprintf(stderr, "time has bounds\n"); */ @@ -866,11 +834,13 @@ void cdfDefTime(int streamID) if ( nc_inq_dimid(fileID, "nb2", &dims[1]) != NC_NOERR ) cdf_def_dim(fileID, "nb2", 2, &dims[1]); - cdf_def_var(fileID, "time_bnds", NC_DOUBLE, 2, dims, &time_bndsid); + strcpy(tmpstr, taxis_name); + strcat(tmpstr, "_bnds"); + cdf_def_var(fileID, tmpstr, NC_DOUBLE, 2, dims, &time_bndsid); streamptr->basetime.ncvarboundsid = time_bndsid; - cdf_put_att_text(fileID, time_varid, "bounds", 9, "time_bnds"); + cdf_put_att_text(fileID, time_varid, "bounds", strlen(tmpstr), tmpstr); } unitstr[0] = 0; @@ -944,20 +914,20 @@ void cdfDefTime(int streamID) } -void cdfDefTimestep(int streamID, int tsID) +void cdfDefTimestep(stream_t *streamptr, int tsID) { int vlistID; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; - if ( vlistHasTime(vlistID) ) cdfDefTime(streamID); + if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr); - cdfDefTimeValue(streamID, tsID); + cdfDefTimeValue(streamptr, tsID); } #if defined (HAVE_LIBNETCDF) static -void cdfDefComplex(int streamID, int gridID) +void cdfDefComplex(stream_t *streamptr, int gridID) { char axisname[] = "nc2"; int index; @@ -967,12 +937,9 @@ void cdfDefComplex(int streamID, int gridID) int fileID; int dimlen; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1009,7 +976,7 @@ void cdfDefComplex(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefSP(int streamID, int gridID) +void cdfDefSP(stream_t *streamptr, int gridID) { /* char longname[] = "Spherical harmonic coefficient"; @@ -1022,12 +989,9 @@ void cdfDefSP(int streamID, int gridID) int fileID; int dimlen, dimlen0; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1073,7 +1037,7 @@ void cdfDefSP(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefFC(int streamID, int gridID) +void cdfDefFC(stream_t *streamptr, int gridID) { char axisname[5] = "nfcX"; int index, iz = 0; @@ -1083,12 +1047,9 @@ void cdfDefFC(int streamID, int gridID) int fileID; int dimlen, dimlen0; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1134,12 +1095,12 @@ void cdfDefFC(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefTrajLon(int streamID, int gridID) +void cdfDefTrajLon(stream_t *streamptr, int gridID) { - char units[256]; - char longname[256]; - char stdname[256]; - char axisname[256]; + char units[CDI_MAX_NAME]; + char longname[CDI_MAX_NAME]; + char stdname[CDI_MAX_NAME]; + char axisname[CDI_MAX_NAME]; int gridtype, gridindex; int dimID = UNDEFID; int fileID; @@ -1148,14 +1109,11 @@ void cdfDefTrajLon(int streamID, int gridID) int ncvarid; int vlistID; int xtype = NC_DOUBLE; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; gridtype = gridInqType(gridID); dimlen = gridInqXsize(gridID); @@ -1194,7 +1152,7 @@ void cdfDefTrajLon(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefTrajLat(int streamID, int gridID) +void cdfDefTrajLat(stream_t *streamptr, int gridID) { char units[] = "degrees_north"; char longname[] = "latitude"; @@ -1208,14 +1166,11 @@ void cdfDefTrajLat(int streamID, int gridID) int ncvarid; int vlistID; int xtype = NC_DOUBLE; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; gridtype = gridInqType(gridID); dimlen = gridInqYsize(gridID); @@ -1259,8 +1214,8 @@ int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID, int iz, index; int gridID0; int ncdimid; - char axisname0[256]; - char axisname2[256]; + char axisname0[CDI_MAX_NAME]; + char axisname2[CDI_MAX_NAME]; int checkname; int status; @@ -1268,7 +1223,7 @@ int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID, checkname = TRUE; iz = 0; - while ( checkname ) + while ( checkname ) { strcpy(axisname2, axisname); if ( iz ) sprintf(&axisname2[strlen(axisname2)], "_%d", iz+1); @@ -1318,12 +1273,12 @@ int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID, #if defined (HAVE_LIBNETCDF) static -void cdfDefXaxis(int streamID, int gridID) +void cdfDefXaxis(stream_t *streamptr, int gridID) { - char units[256]; - char longname[256]; - char stdname[256]; - char axisname[256]; + char units[CDI_MAX_NAME]; + char longname[CDI_MAX_NAME]; + char stdname[CDI_MAX_NAME]; + char axisname[CDI_MAX_NAME]; int index; /* int index2; */ int gridID0, gridtype0, gridindex; @@ -1337,14 +1292,11 @@ void cdfDefXaxis(int streamID, int gridID) int nvertex = 2, nvdimID = UNDEFID; int vlistID; int xtype = NC_DOUBLE; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1447,12 +1399,12 @@ void cdfDefXaxis(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefYaxis(int streamID, int gridID) +void cdfDefYaxis(stream_t *streamptr, int gridID) { - char units[256]; - char longname[256]; - char stdname[256]; - char axisname[256]; + char units[CDI_MAX_NAME]; + char longname[CDI_MAX_NAME]; + char stdname[CDI_MAX_NAME]; + char axisname[CDI_MAX_NAME]; int index; /* int index2; */ int gridID0, gridtype0, gridindex; @@ -1466,14 +1418,11 @@ void cdfDefYaxis(int streamID, int gridID) int nvertex = 2, nvdimID = UNDEFID; int vlistID; int xtype = NC_DOUBLE; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1576,16 +1525,30 @@ void cdfDefYaxis(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefCurvilinear(int streamID, int gridID) +void cdfGridCompress(int fileID, int ncvarid, int gridsize, int filetype, int comptype) { - char xunits[256]; - char xlongname[256]; - char xstdname[256]; - char yunits[256]; - char ylongname[256]; - char ystdname[256]; - char xaxisname[256]; - char yaxisname[256]; +#if defined (HAVE_NETCDF4) + if ( gridsize > 1 && comptype == COMPRESS_ZIP && (filetype == FILETYPE_NC4 || filetype == FILETYPE_NC4C) ) + { + nc_def_var_chunking(fileID, ncvarid, NC_CHUNKED, NULL); + cdfDefVarDeflate(fileID, ncvarid, 1); + } +#endif +} +#endif + +#if defined (HAVE_LIBNETCDF) +static +void cdfDefCurvilinear(stream_t *streamptr, int gridID) +{ + char xunits[CDI_MAX_NAME]; + char xlongname[CDI_MAX_NAME]; + char xstdname[CDI_MAX_NAME]; + char yunits[CDI_MAX_NAME]; + char ylongname[CDI_MAX_NAME]; + char ystdname[CDI_MAX_NAME]; + char xaxisname[CDI_MAX_NAME]; + char yaxisname[CDI_MAX_NAME]; char xdimname[4] = "x"; char ydimname[4] = "y"; int index; @@ -1602,14 +1565,11 @@ void cdfDefCurvilinear(int streamID, int gridID) int nvertex = 4, nvdimID = UNDEFID; int vlistID; int xtype = NC_DOUBLE; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1682,6 +1642,7 @@ void cdfDefCurvilinear(int streamID, int gridID) if ( gridInqXvalsPtr(gridID) ) { cdf_def_var(fileID, xaxisname, (nc_type) xtype, 2, dimIDs, &ncxvarid); + cdfGridCompress(fileID, ncxvarid, xdimlen*ydimlen, streamptr->filetype, streamptr->comptype); if ( (len = strlen(xstdname)) ) cdf_put_att_text(fileID, ncxvarid, "standard_name", len, xstdname); @@ -1702,6 +1663,8 @@ void cdfDefCurvilinear(int streamID, int gridID) dimIDs[1] = xdimID; dimIDs[2] = nvdimID; cdf_def_var(fileID, xaxisname, (nc_type) xtype, 3, dimIDs, &ncbxvarid); + cdfGridCompress(fileID, ncbxvarid, xdimlen*ydimlen, streamptr->filetype, streamptr->comptype); + cdf_put_att_text(fileID, ncxvarid, "bounds", strlen(xaxisname), xaxisname); } } @@ -1709,6 +1672,7 @@ void cdfDefCurvilinear(int streamID, int gridID) if ( gridInqYvalsPtr(gridID) ) { cdf_def_var(fileID, yaxisname, (nc_type) xtype, 2, dimIDs, &ncyvarid); + cdfGridCompress(fileID, ncyvarid, xdimlen*ydimlen, streamptr->filetype, streamptr->comptype); if ( (len = strlen(ystdname)) ) cdf_put_att_text(fileID, ncyvarid, "standard_name", len, ystdname); @@ -1729,6 +1693,8 @@ void cdfDefCurvilinear(int streamID, int gridID) dimIDs[1] = xdimID; dimIDs[2] = nvdimID; cdf_def_var(fileID, yaxisname, (nc_type) xtype, 3, dimIDs, &ncbyvarid); + cdfGridCompress(fileID, ncbyvarid, xdimlen*ydimlen, streamptr->filetype, streamptr->comptype); + cdf_put_att_text(fileID, ncyvarid, "bounds", strlen(yaxisname), yaxisname); } } @@ -1766,7 +1732,7 @@ void cdfDefCurvilinear(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefRgrid(int streamID, int gridID) +void cdfDefRgrid(stream_t *streamptr, int gridID) { char axisname[7] = "rgridX"; int index, iz = 0; @@ -1777,12 +1743,9 @@ void cdfDefRgrid(int streamID, int gridID) int dimlen, dimlen0; int vlistID; int lwarn = TRUE; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1836,9 +1799,8 @@ void cdfDefRgrid(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefGdim(int streamID, int gridID) +void cdfDefGdim(stream_t *streamptr, int gridID) { - char axisname[7] = "gsizeX"; int index, iz = 0; int gridID0, gridtype0, gridindex; int dimID = UNDEFID; @@ -1846,12 +1808,9 @@ void cdfDefGdim(int streamID, int gridID) int fileID; int dimlen, dimlen0; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1873,7 +1832,7 @@ void cdfDefGdim(int streamID, int gridID) break; } else - iz++; + iz++; } } } @@ -1894,18 +1853,25 @@ void cdfDefGdim(int streamID, int gridID) break; } else - iz++; + iz++; } } } if ( dimID == UNDEFID ) { + int status; + char axisname[CDI_MAX_NAME]; + strcpy(axisname, "gsize"); + + status = checkGridName('D', axisname, fileID, vlistID, gridID, ngrids, 'X'); + /* if ( iz == 0 ) axisname[5] = '\0'; else sprintf(&axisname[5], "%1d", iz+1); - + */ if ( streamptr->ncmode == 2 ) cdf_redef(fileID); + //printf("axisname, dimlen %s %d\n", axisname, dimlen); cdf_def_dim(fileID, axisname, dimlen, &dimID); cdf_enddef(fileID); @@ -1919,16 +1885,16 @@ void cdfDefGdim(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefUnstructured(int streamID, int gridID) +void cdfDefUnstructured(stream_t *streamptr, int gridID) { - char xunits[256]; - char xlongname[256]; - char xstdname[256]; - char yunits[256]; - char ylongname[256]; - char ystdname[256]; - char xaxisname[256]; - char yaxisname[256]; + char xunits[CDI_MAX_NAME]; + char xlongname[CDI_MAX_NAME]; + char xstdname[CDI_MAX_NAME]; + char yunits[CDI_MAX_NAME]; + char ylongname[CDI_MAX_NAME]; + char ystdname[CDI_MAX_NAME]; + char xaxisname[CDI_MAX_NAME]; + char yaxisname[CDI_MAX_NAME]; int index; int gridID0, gridtype0, gridindex; int dimID = UNDEFID; @@ -1941,14 +1907,11 @@ void cdfDefUnstructured(int streamID, int gridID) int nvertex, nvdimID = UNDEFID; int vlistID; int xtype = NC_DOUBLE; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ngrids = vlistNgrids(vlistID); @@ -1974,7 +1937,7 @@ void cdfDefUnstructured(int streamID, int gridID) { dimlen0 = gridInqSize(gridID0); if ( dimlen == dimlen0 ) - if ( gridInqNvertex(gridID0) == gridInqNvertex(gridID) && + if ( gridInqNvertex(gridID0) == gridInqNvertex(gridID) && IS_EQUAL(gridInqXval(gridID0, 0), gridInqXval(gridID, 0)) && IS_EQUAL(gridInqXval(gridID0, dimlen-1), gridInqXval(gridID, dimlen-1)) ) { @@ -1988,8 +1951,8 @@ void cdfDefUnstructured(int streamID, int gridID) if ( dimID == UNDEFID ) { int status; - char axisname[256]; - char vertname[256]; + char axisname[CDI_MAX_NAME]; + char vertname[CDI_MAX_NAME]; strcpy(axisname, "ncells"); strcpy(vertname, "nv"); @@ -2008,6 +1971,7 @@ void cdfDefUnstructured(int streamID, int gridID) if ( gridInqXvalsPtr(gridID) ) { cdf_def_var(fileID, xaxisname, (nc_type) xtype, 1, &dimID, &ncxvarid); + cdfGridCompress(fileID, ncxvarid, dimlen, streamptr->filetype, streamptr->comptype); if ( (len = strlen(xstdname)) ) cdf_put_att_text(fileID, ncxvarid, "standard_name", len, xstdname); @@ -2025,6 +1989,8 @@ void cdfDefUnstructured(int streamID, int gridID) dimIDs[1] = nvdimID; strcat(xaxisname, "_vertices"); cdf_def_var(fileID, xaxisname, (nc_type) xtype, 2, dimIDs, &ncbxvarid); + cdfGridCompress(fileID, ncbxvarid, dimlen, streamptr->filetype, streamptr->comptype); + cdf_put_att_text(fileID, ncxvarid, "bounds", strlen(xaxisname), xaxisname); } } @@ -2032,6 +1998,7 @@ void cdfDefUnstructured(int streamID, int gridID) if ( gridInqYvalsPtr(gridID) ) { cdf_def_var(fileID, yaxisname, (nc_type) xtype, 1, &dimID, &ncyvarid); + cdfGridCompress(fileID, ncyvarid, dimlen, streamptr->filetype, streamptr->comptype); if ( (len = strlen(ystdname)) ) cdf_put_att_text(fileID, ncyvarid, "standard_name", len, ystdname); @@ -2049,6 +2016,8 @@ void cdfDefUnstructured(int streamID, int gridID) dimIDs[1] = nvdimID; strcat(yaxisname, "_vertices"); cdf_def_var(fileID, yaxisname, (nc_type) xtype, 2, dimIDs, &ncbyvarid); + cdfGridCompress(fileID, ncbyvarid, dimlen, streamptr->filetype, streamptr->comptype); + cdf_put_att_text(fileID, ncyvarid, "bounds", strlen(yaxisname), yaxisname); } } @@ -2085,12 +2054,9 @@ void cdfDefUnstructured(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefVCT(int streamID, int zaxisID) +void cdfDefVCT(stream_t *streamptr, int zaxisID) { int type; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); type = zaxisInqType(zaxisID); if ( type == ZAXIS_HYBRID || type == ZAXIS_HYBRID_HALF ) @@ -2104,7 +2070,7 @@ void cdfDefVCT(int streamID, int zaxisID) int ncdimid, ncdimid2; int hyaiid, hybiid, hyamid, hybmid; double mval; - char tmpname[256]; + char tmpname[CDI_MAX_NAME]; if ( streamptr->vct.ilev > 0 ) { @@ -2119,7 +2085,7 @@ void cdfDefVCT(int streamID, int zaxisID) return; } - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; if ( streamptr->ncmode == 2 ) cdf_redef(fileID); @@ -2175,14 +2141,14 @@ void cdfDefVCT(int streamID, int zaxisID) #if defined (HAVE_LIBNETCDF) static -void cdfDefZaxis(int streamID, int zaxisID) +void cdfDefZaxis(stream_t *streamptr, int zaxisID) { - /* char zaxisname0[256]; */ - char axisname[256]; - char stdname[256]; - char longname[256]; - char units[256]; - char tmpname[256]; + /* char zaxisname0[CDI_MAX_NAME]; */ + char axisname[CDI_MAX_NAME]; + char stdname[CDI_MAX_NAME]; + char longname[CDI_MAX_NAME]; + char units[CDI_MAX_NAME]; + char tmpname[CDI_MAX_NAME]; int index; int zaxisID0; int dimID = UNDEFID; @@ -2199,14 +2165,11 @@ void cdfDefZaxis(int streamID, int zaxisID) int zaxisindex; int xtype = NC_DOUBLE; int positive; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( zaxisInqPrec(zaxisID) == DATATYPE_FLT32 ) xtype = NC_FLOAT; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; zaxisindex = vlistZaxisIndex(vlistID, zaxisID); @@ -2215,11 +2178,14 @@ void cdfDefZaxis(int streamID, int zaxisID) dimlen = zaxisInqSize(zaxisID); type = zaxisInqType(zaxisID); - if ( dimlen == 1 && type == ZAXIS_SURFACE ) return; - if ( dimlen == 1 && type == ZAXIS_TOA ) return; - if ( dimlen == 1 && type == ZAXIS_SEA_BOTTOM ) return; - if ( dimlen == 1 && type == ZAXIS_ATMOSPHERE ) return; - if ( dimlen == 1 && type == ZAXIS_MEANSEA ) return; + if ( dimlen == 1 && type == ZAXIS_SURFACE ) return; + if ( dimlen == 1 && type == ZAXIS_CLOUD_BASE ) return; + if ( dimlen == 1 && type == ZAXIS_CLOUD_TOP ) return; + if ( dimlen == 1 && type == ZAXIS_ISOTHERM_ZERO ) return; + if ( dimlen == 1 && type == ZAXIS_TOA ) return; + if ( dimlen == 1 && type == ZAXIS_SEA_BOTTOM ) return; + if ( dimlen == 1 && type == ZAXIS_ATMOSPHERE ) return; + if ( dimlen == 1 && type == ZAXIS_MEANSEA ) return; zaxisInqName(zaxisID, axisname); /* @@ -2235,8 +2201,8 @@ void cdfDefZaxis(int streamID, int zaxisID) */ if ( dimID == UNDEFID ) { - char axisname0[256]; - char axisname2[256]; + char axisname0[CDI_MAX_NAME]; + char axisname2[CDI_MAX_NAME]; int checkname = FALSE; int status; @@ -2336,7 +2302,7 @@ void cdfDefZaxis(int streamID, int zaxisID) cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID)); } - cdfDefVCT(streamID, zaxisID); + cdfDefVCT(streamptr, zaxisID); if ( dimID == UNDEFID ) { @@ -2433,7 +2399,7 @@ void cdfDefZaxis(int streamID, int zaxisID) #if defined (HAVE_LIBNETCDF) static -void cdfDefPole(int streamID, int gridID) +void cdfDefPole(stream_t *streamptr, int gridID) { int fileID; int ncvarid = UNDEFID; @@ -2442,7 +2408,7 @@ void cdfDefPole(int streamID, int gridID) char varname[] = "rotated_pole"; char mapname[] = "rotated_latitude_longitude"; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; ypole = gridInqYpole(gridID); xpole = gridInqXpole(gridID); @@ -2466,7 +2432,7 @@ void cdfDefPole(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefMapping(int streamID, int gridID) +void cdfDefMapping(stream_t *streamptr, int gridID) { int fileID; int ncvarid = UNDEFID; @@ -2477,7 +2443,7 @@ void cdfDefMapping(int streamID, int gridID) char varname[] = "sinusoidal"; char mapname[] = "sinusoidal"; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; cdf_redef(fileID); @@ -2498,7 +2464,7 @@ void cdfDefMapping(int streamID, int gridID) char varname[] = "laea"; char mapname[] = "lambert_azimuthal_equal_area"; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; cdf_redef(fileID); @@ -2522,7 +2488,7 @@ void cdfDefMapping(int streamID, int gridID) char varname[] = "Lambert_Conformal"; char mapname[] = "lambert_conformal_conic"; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; cdf_redef(fileID); @@ -2556,16 +2522,33 @@ void cdfDefMapping(int streamID, int gridID) #if defined (HAVE_LIBNETCDF) static -void cdfDefGrid(int streamID, int gridID) +void cdfDefGridUUID(stream_t *streamptr, int gridID) +{ + char uuidOfHGrid[17]; + + gridInqUUID(gridID, uuidOfHGrid); + if ( uuidOfHGrid[0] != 0 ) + { + char uuidOfHGridStr[37]; + uuid2str(uuidOfHGrid, uuidOfHGridStr); + if ( uuidOfHGridStr[0] != 0 && strlen(uuidOfHGridStr) == 36 ) + { + int fileID = streamptr->fileID; + if ( streamptr->ncmode == 2 ) cdf_redef(fileID); + cdf_put_att_text(fileID, NC_GLOBAL, "uuidOfHGrid", 36, uuidOfHGridStr); + if ( streamptr->ncmode == 2 ) cdf_enddef(fileID); + } + } +} + +static +void cdfDefGrid(stream_t *streamptr, int gridID) { int gridtype, size; int gridindex; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; gridindex = vlistGridIndex(vlistID, gridID); if ( streamptr->xdimID[gridindex] != UNDEFID ) return; @@ -2579,73 +2562,90 @@ void cdfDefGrid(int streamID, int gridID) gridtype == GRID_LONLAT || gridtype == GRID_GENERIC ) { - if ( gridtype == GRID_GENERIC && size == 1 && - gridInqXsize(gridID) == 0 && gridInqYsize(gridID) == 0 ) - { - /* no grid information */ - } - else if ( gridtype == GRID_GENERIC && (gridInqXsize(gridID) == 0 || gridInqYsize(gridID) == 0) ) + if ( gridtype == GRID_GENERIC ) { - cdfDefGdim(streamID, gridID); + if ( size == 1 && gridInqXsize(gridID) == 0 && gridInqYsize(gridID) == 0 ) + { + /* no grid information */ + } + else + { + int lx = 0, ly = 0; + if ( gridInqXsize(gridID) > 0 /*&& gridInqXvals(gridID, NULL) > 0*/ ) + { + cdfDefXaxis(streamptr, gridID); + lx = 1; + } + + if ( gridInqYsize(gridID) > 0 /*&& gridInqYvals(gridID, NULL) > 0*/ ) + { + cdfDefYaxis(streamptr, gridID); + ly = 1; + } + + if ( lx == 0 && ly == 0 ) cdfDefGdim(streamptr, gridID); + } } else { - if ( gridInqXsize(gridID) > 0 ) cdfDefXaxis(streamID, gridID); - if ( gridInqYsize(gridID) > 0 ) cdfDefYaxis(streamID, gridID); + if ( gridInqXsize(gridID) > 0 ) cdfDefXaxis(streamptr, gridID); + if ( gridInqYsize(gridID) > 0 ) cdfDefYaxis(streamptr, gridID); } - if ( gridIsRotated(gridID) ) cdfDefPole(streamID, gridID); + if ( gridIsRotated(gridID) ) cdfDefPole(streamptr, gridID); } else if ( gridtype == GRID_CURVILINEAR ) { - cdfDefCurvilinear(streamID, gridID); + cdfDefCurvilinear(streamptr, gridID); } else if ( gridtype == GRID_UNSTRUCTURED ) { - cdfDefUnstructured(streamID, gridID); + cdfDefUnstructured(streamptr, gridID); } else if ( gridtype == GRID_GAUSSIAN_REDUCED ) { - cdfDefRgrid(streamID, gridID); + cdfDefRgrid(streamptr, gridID); } else if ( gridtype == GRID_SPECTRAL ) { - cdfDefComplex(streamID, gridID); - cdfDefSP(streamID, gridID); + cdfDefComplex(streamptr, gridID); + cdfDefSP(streamptr, gridID); } else if ( gridtype == GRID_FOURIER ) { - cdfDefComplex(streamID, gridID); - cdfDefFC(streamID, gridID); + cdfDefComplex(streamptr, gridID); + cdfDefFC(streamptr, gridID); } else if ( gridtype == GRID_TRAJECTORY ) { - cdfDefTrajLon(streamID, gridID); - cdfDefTrajLat(streamID, gridID); + cdfDefTrajLon(streamptr, gridID); + cdfDefTrajLat(streamptr, gridID); } else if ( gridtype == GRID_SINUSOIDAL || gridtype == GRID_LAEA || gridtype == GRID_LCC2 ) { - cdfDefXaxis(streamID, gridID); - cdfDefYaxis(streamID, gridID); + cdfDefXaxis(streamptr, gridID); + cdfDefYaxis(streamptr, gridID); - cdfDefMapping(streamID, gridID); + cdfDefMapping(streamptr, gridID); } /* else if ( gridtype == GRID_LCC ) { - cdfDefLcc(streamID, gridID); + cdfDefLcc(streamptr, gridID); } */ else { Error("Unsupported grid type: %s", gridNamePtr(gridtype)); } + + cdfDefGridUUID(streamptr, gridID); } #endif #if defined (HAVE_LIBNETCDF) static -int cdfDefVar(int streamID, int varID) +int cdfDefVar(stream_t *streamptr, int varID) { int ncvarid = -1; int fileID; @@ -2653,13 +2653,14 @@ int cdfDefVar(int streamID, int varID) size_t xsize = 0, ysize = 0; int code, param, gridID, zaxisID; int pnum, pcat, pdis; - char varname[256]; + char varname[CDI_MAX_NAME]; const char *name = NULL; const char *longname = NULL; const char *stdname = NULL; const char *units = NULL; int dims[4]; int lchunk = FALSE; + int chunktype; size_t chunks[4] = {0,0,0,0}; int tableID; int ndims = 0; @@ -2674,21 +2675,18 @@ int cdfDefVar(int streamID, int varID) int ixyz; int iax = 0; char axis[5]; - stream_t *streamptr; int ensID, ensCount, forecast_type; int retval; - streamptr = stream_to_pointer(streamID); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; if ( CDI_Debug ) - Message("streamID = %d, fileID = %d, varID = %d", streamID, fileID, varID); + Message("streamID = %d, fileID = %d, varID = %d", streamptr->self, fileID, varID); if ( streamptr->vars[varID].ncvarid != UNDEFID ) return (streamptr->vars[varID].ncvarid); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); tsteptype = vlistInqVarTsteptype(vlistID, varID); @@ -2696,6 +2694,8 @@ int cdfDefVar(int streamID, int varID) param = vlistInqVarParam(vlistID, varID); cdiDecodeParam(param, &pnum, &pcat, &pdis); + chunktype = vlistInqVarChunkType(vlistID, varID); + ixyz = vlistInqVarXYZ(vlistID, varID); if ( ixyz == 0 ) ixyz = 321; // ZYX @@ -2756,7 +2756,10 @@ int cdfDefVar(int streamID, int varID) } else if ( dimorder[id] == 2 && yid != UNDEFID ) { - chunks[ndims] = ysize; + if ( chunktype == CHUNK_LINES ) + chunks[ndims] = 1; + else + chunks[ndims] = ysize; dims[ndims] = yid; ndims++; } @@ -2769,8 +2772,7 @@ int cdfDefVar(int streamID, int varID) } if ( CDI_Debug ) - fprintf(stderr, "chunks %d %d %d %d\n", - (int)chunks[0], (int)chunks[1], (int)chunks[2], (int)chunks[3]); + fprintf(stderr, "chunktype %d chunks %d %d %d %d\n", chunktype, (int)chunks[0], (int)chunks[1], (int)chunks[2], (int)chunks[3]); tableID = vlistInqVarTable(vlistID, varID); @@ -2793,7 +2795,7 @@ int cdfDefVar(int streamID, int varID) checkname = TRUE; iz = 0; - while ( checkname ) + while ( checkname ) { if ( iz ) sprintf(varname, "%s_%d", name, iz+1); @@ -2805,8 +2807,7 @@ int cdfDefVar(int streamID, int varID) if ( checkname ) iz++; - if ( iz > 99 ) - Error("Double entry of variable name '%s'!", name); + if ( iz >= CDI_MAX_NAME ) Error("Double entry of variable name '%s'!", name); } if ( strcmp(name, varname) != 0 ) @@ -2848,7 +2849,7 @@ int cdfDefVar(int streamID, int varID) if ( checkname ) iz++; - if ( iz > 99 ) break; + if ( iz >= CDI_MAX_NAME ) break; } name = varname; @@ -2866,8 +2867,12 @@ int cdfDefVar(int streamID, int varID) #if defined (HAVE_NETCDF4) if ( lchunk && (streamptr->filetype == FILETYPE_NC4 || streamptr->filetype == FILETYPE_NC4C) ) { - if ( (retval = nc_def_var_chunking(fileID, ncvarid, 0, chunks)) ) - Error("nc_def_var_chunking failed, status = %d", retval); + if ( chunktype == CHUNK_AUTO ) + retval = nc_def_var_chunking(fileID, ncvarid, NC_CHUNKED, NULL); + else + retval = nc_def_var_chunking(fileID, ncvarid, NC_CHUNKED, chunks); + + if ( retval ) Error("nc_def_var_chunking failed, status = %d", retval); } #endif @@ -2981,8 +2986,8 @@ int cdfDefVar(int streamID, int varID) } else if ( gridtype == GRID_UNSTRUCTURED || gridtype == GRID_CURVILINEAR ) { - char coordinates[256] = ""; - char cellarea[256] = "area: "; + char coordinates[CDI_MAX_NAME] = ""; + char cellarea[CDI_MAX_NAME] = "area: "; int ncxvarID, ncyvarID, ncavarID; int gridindex; size_t len; @@ -3057,12 +3062,15 @@ int cdfDefVar(int streamID, int varID) streamptr->vars[varID].ncvarid = ncvarid; if ( vlistInqVarMissvalUsed(vlistID, varID) ) - cdfDefVarMissval(streamID, varID, vlistInqVarDatatype(vlistID, varID), 0); + cdfDefVarMissval(streamptr, varID, vlistInqVarDatatype(vlistID, varID), 0); if ( zid == -1 ) { - if ( zaxisInqType(zaxisID) == ZAXIS_TOA || - zaxisInqType(zaxisID) == ZAXIS_SEA_BOTTOM || + if ( zaxisInqType(zaxisID) == ZAXIS_CLOUD_BASE || + zaxisInqType(zaxisID) == ZAXIS_CLOUD_TOP || + zaxisInqType(zaxisID) == ZAXIS_ISOTHERM_ZERO || + zaxisInqType(zaxisID) == ZAXIS_TOA || + zaxisInqType(zaxisID) == ZAXIS_SEA_BOTTOM || zaxisInqType(zaxisID) == ZAXIS_ATMOSPHERE ) { zaxisInqName(zaxisID, varname); @@ -3070,12 +3078,11 @@ int cdfDefVar(int streamID, int varID) } } - if( !vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) ) + if ( vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) ) { /* void cdf_put_att_int( int ncid, int varid, const char *name, nc_type xtype, size_t len, const int *ip ) */ - cdf_put_att_int(fileID, ncvarid, "realization", NC_INT, 1, &ensID); cdf_put_att_int(fileID, ncvarid, "ensemble_members", NC_INT, 1, &ensCount); cdf_put_att_int(fileID, ncvarid, "forecast_init_type", NC_INT, 1, &forecast_type); @@ -3118,7 +3125,7 @@ void scale_add(long size, double *data, double addoffset, double scalefactor) } #endif -void cdfReadVarDP(int streamID, int varID, double *data, int *nmiss) +void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss) { #if defined (HAVE_LIBNETCDF) int fileID; @@ -3139,15 +3146,11 @@ void cdfReadVarDP(int streamID, int varID, double *data, int *nmiss) double missval; int laddoffset, lscalefactor; double addoffset, scalefactor; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); + if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; @@ -3162,7 +3165,7 @@ void cdfReadVarDP(int streamID, int varID, double *data, int *nmiss) gridindex = vlistGridIndex(vlistID, gridID); if ( gridInqType(gridID) == GRID_TRAJECTORY ) { - cdfReadGridTraj(streamID, gridID); + cdfReadGridTraj(streamptr, gridID); } else { @@ -3431,7 +3434,7 @@ int cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtyp #endif #if defined (HAVE_LIBNETCDF) -void cdf_write_var(int streamID, int varID, int memtype, const void *data, int nmiss) +void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data, int nmiss) { int fileID; int gridID; @@ -3451,23 +3454,18 @@ void cdf_write_var(int streamID, int varID, int memtype, const void *data, int n int gridindex, zaxisindex; int dtype; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); + if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID); - if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ntsteps = streamptr->ntsteps; - if ( CDI_Debug ) - Message("ntsteps = %d", ntsteps); + if ( CDI_Debug ) Message("ntsteps = %d", ntsteps); - if ( vlistHasTime(vlistID) ) cdfDefTime(streamID); + if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr); - ncvarid = cdfDefVar(streamID, varID); + ncvarid = cdfDefVar(streamptr, varID); gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); @@ -3476,7 +3474,7 @@ void cdf_write_var(int streamID, int varID, int memtype, const void *data, int n gridindex = vlistGridIndex(vlistID, gridID); if ( gridInqType(gridID) == GRID_TRAJECTORY ) { - cdfWriteGridTraj(streamID, gridID); + cdfWriteGridTraj(streamptr, gridID); } else { @@ -3528,7 +3526,7 @@ void cdf_write_var(int streamID, int varID, int memtype, const void *data, int n dtype = vlistInqVarDatatype(vlistID, varID); - if ( nmiss > 0 ) cdfDefVarMissval(streamID, varID, dtype, 1); + if ( nmiss > 0 ) cdfDefVarMissval(streamptr, varID, dtype, 1); nvals = gridInqSize(gridID)*zaxisInqSize(zaxisID); @@ -3538,7 +3536,7 @@ void cdf_write_var(int streamID, int varID, int memtype, const void *data, int n #endif #if defined (HAVE_LIBNETCDF) -void cdf_write_var_chunk(int streamID, int varID, int memtype, +void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype, const int rect[][2], const void *data, int nmiss) { int fileID; @@ -3558,9 +3556,7 @@ void cdf_write_var_chunk(int streamID, int varID, int memtype, int gridindex, zaxisindex; int dtype; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); + int streamID = streamptr->self; if ( CDI_Debug ) Message("streamID = %d varID = %d", streamID, varID); @@ -3570,11 +3566,11 @@ void cdf_write_var_chunk(int streamID, int varID, int memtype, ntsteps = streamptr->ntsteps; if ( CDI_Debug ) - Message("ntsteps = %d", ntsteps); + Message("ntsteps = %d", ntsteps); - if ( vlistHasTime(vlistID) ) cdfDefTime(streamID); + if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr); - ncvarid = cdfDefVar(streamID, varID); + ncvarid = cdfDefVar(streamptr, varID); gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); @@ -3583,7 +3579,7 @@ void cdf_write_var_chunk(int streamID, int varID, int memtype, gridindex = vlistGridIndex(vlistID, gridID); if ( gridInqType(gridID) == GRID_TRAJECTORY ) { - cdfWriteGridTraj(streamID, gridID); + cdfWriteGridTraj(streamptr, gridID); } else { @@ -3642,7 +3638,7 @@ void cdf_write_var_chunk(int streamID, int varID, int memtype, dtype = vlistInqVarDatatype(vlistID, varID); - if ( nmiss > 0 ) cdfDefVarMissval(streamID, varID, dtype, 1); + if ( nmiss > 0 ) cdfDefVarMissval(streamptr, varID, dtype, 1); nvals = gridInqSize(gridID)*zaxisInqSize(zaxisID); @@ -3652,7 +3648,7 @@ void cdf_write_var_chunk(int streamID, int varID, int memtype, #endif -int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss) +int cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data, int *nmiss) { #if defined (HAVE_LIBNETCDF) int fileID; @@ -3680,19 +3676,15 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n double missval; int laddoffset, lscalefactor; double addoffset, scalefactor; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( CDI_Debug ) - Message("streamID = %d varID = %d levelID = %d", streamID, varID, levelID); + Message("streamID = %d varID = %d levelID = %d", streamptr->self, varID, levelID); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; - if ( CDI_Debug ) - Message("tsID = %d", tsID); + if ( CDI_Debug ) Message("tsID = %d", tsID); ncvarid = streamptr->vars[varID].ncvarid; @@ -3711,7 +3703,7 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n gridindex = vlistGridIndex(vlistID, gridID); if ( gridInqType(gridID) == GRID_TRAJECTORY ) { - cdfReadGridTraj(streamID, gridID); + cdfReadGridTraj(streamptr, gridID); } else if ( gridInqType(gridID) == GRID_UNSTRUCTURED ) { @@ -3726,7 +3718,7 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n zaxisindex = vlistZaxisIndex(vlistID, zaxisID); zid = streamptr->zaxisID[zaxisindex]; /* - printf("2 %d %d %d %s\n", streamID, zaxisindex, streamptr->zaxisID[zaxisindex], vlistInqVarNamePtr(vlistID, varID)); + printf("2 %p %d %d %s\n", streamptr, zaxisindex, streamptr->zaxisID[zaxisindex], vlistInqVarNamePtr(vlistID, varID)); */ dimorder[0] = ixyz/100; dimorder[1] = (ixyz-dimorder[0]*100)/10; @@ -3774,7 +3766,15 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n for (idim = 0; idim < ndims; idim++) Message("dim = %d start = %d count = %d", idim, start[idim], count[idim]); - cdf_get_vara_double(fileID, ncvarid, start, count, data); + if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_FLT32 ) + { + float *data_fp = (float *) data; + cdf_get_vara_float(fileID, ncvarid, start, count, data_fp); + for ( i = gridsize-1; i >=0; i-- ) + data[i] = (double) data_fp[i]; + } + else + cdf_get_vara_double(fileID, ncvarid, start, count, data); if ( swapxy ) { @@ -3852,7 +3852,7 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n } -int cdf_write_var_slice(int streamID, int varID, int levelID, int memtype, const void *data, int nmiss) +int cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, const void *data, int nmiss) { #if defined (HAVE_LIBNETCDF) int fileID; @@ -3874,23 +3874,19 @@ int cdf_write_var_slice(int streamID, int varID, int levelID, int memtype, const int swapxy = FALSE; int dtype; int vlistID; - stream_t *streamptr; extern int CDF_Debug; - streamptr = stream_to_pointer(streamID); + if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID); - if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; ntsteps = streamptr->ntsteps; if ( CDI_Debug ) Message("ntsteps = %d", ntsteps); - if ( vlistHasTime(vlistID) ) cdfDefTime(streamID); + if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr); - ncvarid = cdfDefVar(streamID, varID); + ncvarid = cdfDefVar(streamptr, varID); gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); @@ -3901,7 +3897,7 @@ int cdf_write_var_slice(int streamID, int varID, int levelID, int memtype, const gridindex = vlistGridIndex(vlistID, gridID); if ( gridInqType(gridID) == GRID_TRAJECTORY ) { - cdfWriteGridTraj(streamID, gridID); + cdfWriteGridTraj(streamptr, gridID); } else { @@ -3960,7 +3956,7 @@ int cdf_write_var_slice(int streamID, int varID, int levelID, int memtype, const dtype = vlistInqVarDatatype(vlistID, varID); - if ( nmiss > 0 ) cdfDefVarMissval(streamID, varID, dtype, 1); + if ( nmiss > 0 ) cdfDefVarMissval(streamptr, varID, dtype, 1); nvals = gridInqSize(gridID); @@ -3970,8 +3966,8 @@ int cdf_write_var_slice(int streamID, int varID, int levelID, int memtype, const return (0); } - -void cdfCreateRecords(int streamID, int tsID) +static +void cdfCreateRecords(stream_t *streamptr, int tsID) { #if defined (HAVE_LIBNETCDF) int varID, levelID, recID, vrecID, zaxisID; @@ -3979,11 +3975,8 @@ void cdfCreateRecords(int streamID, int tsID) record_t *records = NULL; int *recIDs = NULL; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; if ( tsID < 0 || (tsID >= streamptr->ntsteps && tsID > 0) ) return; @@ -4102,9 +4095,9 @@ int cdfTimeDimID(int fileID, int ndims, int nvars) { int dimid = 0; char dimname[80]; - char timeunits[256]; - char attname[256]; - char name[256]; + char timeunits[CDI_MAX_NAME]; + char attname[CDI_MAX_NAME]; + char name[CDI_MAX_NAME]; nc_type xtype; int nvdims, nvatts; int dimids[9]; @@ -4169,13 +4162,15 @@ void init_ncvars(long nvars, ncvar_t *ncvars) { long ncvarid; - for ( ncvarid = 0; ncvarid < nvars; ncvarid++ ) + for ( ncvarid = 0; ncvarid < nvars; ++ncvarid ) { + ncvars[ncvarid].ncid = UNDEFID; ncvars[ncvarid].ignore = FALSE; ncvars[ncvarid].isvar = UNDEFID; ncvars[ncvarid].islon = FALSE; ncvars[ncvarid].islat = FALSE; ncvars[ncvarid].islev = FALSE; + ncvars[ncvarid].istime = FALSE; ncvars[ncvarid].warn = FALSE; ncvars[ncvarid].tsteptype = TSTEP_CONSTANT; ncvars[ncvarid].param = UNDEFID; @@ -4208,6 +4203,8 @@ void init_ncvars(long nvars, ncvar_t *ncvars) ncvars[ncvarid].vdata = NULL; ncvars[ncvarid].truncation = 0; ncvars[ncvarid].positive = 0; + ncvars[ncvarid].chunked = 0; + ncvars[ncvarid].chunktype = UNDEFID; ncvars[ncvarid].defmiss = 0; ncvars[ncvarid].missval = 0; ncvars[ncvarid].addoffset = 0; @@ -4223,6 +4220,7 @@ void init_ncvars(long nvars, ncvar_t *ncvars) ncvars[ncvarid].lvalidrange = 0; ncvars[ncvarid].validrange[0] = VALIDMISS; ncvars[ncvarid].validrange[1] = VALIDMISS; + ncvars[ncvarid].ensdata = NULL; } } @@ -4415,19 +4413,22 @@ void cdfSetDim(ncvar_t *ncvars, int ncvarid, int dimid, int dimtype) } static -void printNCvars(ncvar_t *ncvars, int nvars) +void printNCvars(ncvar_t *ncvars, int nvars, const char *oname) { - char axis[6]; + char axis[7]; int ncvarid, i; int ndim; int iaxis[] = {'t', 'z', 'y', 'x'}; + fprintf(stderr, "%s:\n", oname); + for ( ncvarid = 0; ncvarid < nvars; ncvarid++ ) { ndim = 0; if ( ncvars[ncvarid].isvar ) { axis[ndim++] = 'v'; + axis[ndim++] = ':'; for ( i = 0; i < ncvars[ncvarid].ndims; i++ ) {/* if ( ncvars[ncvarid].tvarid != -1 ) axis[ndim++] = iaxis[0]; @@ -4436,25 +4437,27 @@ void printNCvars(ncvar_t *ncvars, int nvars) else if ( ncvars[ncvarid].xvarid != -1 ) axis[ndim++] = iaxis[3]; else */ - axis[ndim++] = '?'; + if ( ncvars[ncvarid].dimtype[i] == T_AXIS ) axis[ndim++] = iaxis[0]; + else if ( ncvars[ncvarid].dimtype[i] == Z_AXIS ) axis[ndim++] = iaxis[1]; + else if ( ncvars[ncvarid].dimtype[i] == Y_AXIS ) axis[ndim++] = iaxis[2]; + else if ( ncvars[ncvarid].dimtype[i] == X_AXIS ) axis[ndim++] = iaxis[3]; + else axis[ndim++] = '?'; } } else { axis[ndim++] = 'c'; - if ( ncvars[ncvarid].islev ) - axis[ndim++] = iaxis[1]; - else if ( ncvars[ncvarid].islat ) - axis[ndim++] = iaxis[2]; - else if ( ncvars[ncvarid].islon ) - axis[ndim++] = iaxis[3]; - else - axis[ndim++] = '?'; + axis[ndim++] = ':'; + if ( ncvars[ncvarid].istime ) axis[ndim++] = iaxis[0]; + else if ( ncvars[ncvarid].islev ) axis[ndim++] = iaxis[1]; + else if ( ncvars[ncvarid].islat ) axis[ndim++] = iaxis[2]; + else if ( ncvars[ncvarid].islon ) axis[ndim++] = iaxis[3]; + else axis[ndim++] = '?'; } axis[ndim++] = 0; - printf("%3d %3d %3d %-4s %s\n", ncvarid, ncvars[ncvarid].isvar, ndim-2, axis, ncvars[ncvarid].name); + fprintf(stderr, "%3d %3d %-6s %s\n", ncvarid, ndim-3, axis, ncvars[ncvarid].name); } } #endif @@ -4462,7 +4465,7 @@ void printNCvars(ncvar_t *ncvars, int nvars) typedef struct { int ncvarid; - char name[256]; + char name[CDI_MAX_NAME]; } varinfo_t; @@ -4478,17 +4481,18 @@ int cmpvarname(const void *s1, const void *s2) } static -void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdims, +void cdfScanVarAttributes(int nvars, ncvar_t *ncvars, ncdim_t *ncdims, int timedimid, int modelID, int format) { + int ncid; int ncvarid; int ncdimid; int nvdims, nvatts; int *dimidsp; nc_type xtype, atttype; size_t attlen; - char name[256]; - char attname[256]; + char name[CDI_MAX_NAME]; + char attname[CDI_MAX_NAME]; const int attstringlen = 8192; char attstring[8192]; int iatt; int i; @@ -4496,9 +4500,10 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim for ( ncvarid = 0; ncvarid < nvars; ncvarid++ ) { + ncid = ncvars[ncvarid].ncid; dimidsp = ncvars[ncvarid].dimids; - cdf_inq_var(fileID, ncvarid, name, &xtype, &nvdims, dimidsp, &nvatts); + cdf_inq_var(ncid, ncvarid, name, &xtype, &nvdims, dimidsp, &nvatts); strcpy(ncvars[ncvarid].name, name); for ( ncdimid = 0; ncdimid < nvdims; ncdimid++ ) @@ -4511,36 +4516,63 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim if ( format == NC_FORMAT_NETCDF4_CLASSIC || format == NC_FORMAT_NETCDF4 ) { int shuffle, deflate, deflate_level; - nc_inq_var_deflate(fileID, ncvarid, &shuffle, &deflate, &deflate_level); - if ( deflate > 0 ) - ncvars[ncvarid].deflate = 1; + size_t chunks[nvdims]; + int storage_in; + nc_inq_var_deflate(ncid, ncvarid, &shuffle, &deflate, &deflate_level); + if ( deflate > 0 ) ncvars[ncvarid].deflate = 1; + + if ( nc_inq_var_chunking(ncid, ncvarid, &storage_in, chunks) == NC_NOERR ) + { + if ( storage_in == NC_CHUNKED ) + { + ncvars[ncvarid].chunked = 1; + for ( int i = 0; i < nvdims; ++i ) ncvars[ncvarid].chunks[i] = chunks[i]; + /* + printf("storage %d %d %d\n", storage_in, NC_CONTIGUOUS, NC_CHUNKED); + for ( int i = 0; i < nvdims; ++i ) printf("chunk %d %d\n", i, chunks[i]); + */ + } + } } #endif if ( nvdims > 0 ) - if ( timedimid == dimidsp[0] ) - { - ncvars[ncvarid].tsteptype = TSTEP_INSTANT; - cdfSetDim(ncvars, ncvarid, 0, T_AXIS); - } + { + if ( timedimid == dimidsp[0] ) + { + ncvars[ncvarid].tsteptype = TSTEP_INSTANT; + cdfSetDim(ncvars, ncvarid, 0, T_AXIS); + } + else + { + for ( ncdimid = 1; ncdimid < nvdims; ncdimid++ ) + { + if ( timedimid == dimidsp[ncdimid] ) + { + Warning("Time must be the first dimension! Unsupported array structure, skipped variable %s!", ncvars[ncvarid].name); + ncvars[ncvarid].isvar = FALSE; + } + } + } + } for ( iatt = 0; iatt < nvatts; iatt++ ) { - cdf_inq_attname(fileID, ncvarid, iatt, attname); - cdf_inq_atttype(fileID, ncvarid, attname, &atttype); - cdf_inq_attlen(fileID, ncvarid, attname, &attlen); + cdf_inq_attname(ncid, ncvarid, iatt, attname); + cdf_inq_atttype(ncid, ncvarid, attname, &atttype); + cdf_inq_attlen(ncid, ncvarid, attname, &attlen); if ( strcmp(attname, "long_name") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, MAXNAMELEN, ncvars[ncvarid].longname); + cdfGetAttText(ncid, ncvarid, attname, CDI_MAX_NAME, ncvars[ncvarid].longname); } else if ( strcmp(attname, "standard_name") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, MAXNAMELEN, ncvars[ncvarid].stdname); + cdfGetAttText(ncid, ncvarid, attname, CDI_MAX_NAME, ncvars[ncvarid].stdname); } else if ( strcmp(attname, "units") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, MAXNAMELEN, ncvars[ncvarid].units); + cdfGetAttText(ncid, ncvarid, attname, CDI_MAX_NAME, ncvars[ncvarid].units); } else if ( strcmp(attname, "calendar") == 0 ) { @@ -4550,19 +4582,19 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim { char paramstr[32]; int pnum = 0, pcat = 255, pdis = 255; - cdfGetAttText(fileID, ncvarid, attname, sizeof(paramstr), paramstr); + cdfGetAttText(ncid, ncvarid, attname, sizeof(paramstr), paramstr); sscanf(paramstr, "%d.%d.%d", &pnum, &pcat, &pdis); ncvars[ncvarid].param = cdiEncodeParam(pnum, pcat, pdis); cdfSetVar(ncvars, ncvarid, TRUE); } else if ( strcmp(attname, "code") == 0 && atttype != NC_CHAR ) { - cdfGetAttInt(fileID, ncvarid, attname, 1, &ncvars[ncvarid].code); + cdfGetAttInt(ncid, ncvarid, attname, 1, &ncvars[ncvarid].code); cdfSetVar(ncvars, ncvarid, TRUE); } else if ( strcmp(attname, "table") == 0 && atttype != NC_CHAR ) { - cdfGetAttInt(fileID, ncvarid, attname, 1, &tablenum); + cdfGetAttInt(ncid, ncvarid, attname, 1, &tablenum); if ( tablenum > 0 ) { ncvars[ncvarid].tabnum = tablenum; @@ -4574,13 +4606,13 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "trunc_type") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); if ( memcmp(attstring, "Triangular", attlen) == 0 ) ncvars[ncvarid].gridtype = GRID_SPECTRAL; } else if ( strcmp(attname, "grid_type") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); strtolower(attstring); if ( strcmp(attstring, "gaussian reduced") == 0 ) @@ -4623,17 +4655,23 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "level_type") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); strtolower(attstring); if ( strcmp(attstring, "toa") == 0 ) ncvars[ncvarid].zaxistype = ZAXIS_TOA; + else if ( strcmp(attstring, "cloudbase") == 0 ) + ncvars[ncvarid].zaxistype = ZAXIS_CLOUD_BASE; + else if ( strcmp(attstring, "cloudtop") == 0 ) + ncvars[ncvarid].zaxistype = ZAXIS_CLOUD_TOP; + else if ( strcmp(attstring, "isotherm0") == 0 ) + ncvars[ncvarid].zaxistype = ZAXIS_ISOTHERM_ZERO; else if ( strcmp(attstring, "seabottom") == 0 ) ncvars[ncvarid].zaxistype = ZAXIS_SEA_BOTTOM; else if ( strcmp(attstring, "atmosphere") == 0 ) ncvars[ncvarid].zaxistype = ZAXIS_ATMOSPHERE; else - { + { static int warn = TRUE; if ( warn ) { @@ -4646,15 +4684,15 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "trunc_count") == 0 && atttype != NC_CHAR ) { - cdfGetAttInt(fileID, ncvarid, attname, 1, &ncvars[ncvarid].truncation); + cdfGetAttInt(ncid, ncvarid, attname, 1, &ncvars[ncvarid].truncation); } else if ( strcmp(attname, "truncation") == 0 && atttype != NC_CHAR ) { - cdfGetAttInt(fileID, ncvarid, attname, 1, &ncvars[ncvarid].truncation); + cdfGetAttInt(ncid, ncvarid, attname, 1, &ncvars[ncvarid].truncation); } else if ( strcmp(attname, "add_offset") == 0 && atttype != NC_CHAR ) { - cdfGetAttDouble(fileID, ncvarid, attname, 1, &ncvars[ncvarid].addoffset); + cdfGetAttDouble(ncid, ncvarid, attname, 1, &ncvars[ncvarid].addoffset); /* if ( atttype != NC_BYTE && atttype != NC_SHORT && atttype != NC_INT ) if ( ncvars[ncvarid].addoffset != 0 ) @@ -4664,7 +4702,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "scale_factor") == 0 && atttype != NC_CHAR ) { - cdfGetAttDouble(fileID, ncvarid, attname, 1, &ncvars[ncvarid].scalefactor); + cdfGetAttDouble(ncid, ncvarid, attname, 1, &ncvars[ncvarid].scalefactor); /* if ( atttype != NC_BYTE && atttype != NC_SHORT && atttype != NC_INT ) if ( ncvars[ncvarid].scalefactor != 1 ) @@ -4676,9 +4714,9 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim { int status, ncboundsid; - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); - status = nc_inq_varid(fileID, attstring, &ncboundsid); + status = nc_inq_varid(ncid, attstring, &ncboundsid); if ( status == NC_NOERR ) { @@ -4693,7 +4731,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim { char *pstring, *cell_measures = NULL, *cell_var = NULL; - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); pstring = attstring; while ( isspace((int) *pstring) ) pstring++; @@ -4713,7 +4751,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim int status; int nc_cell_id; - status = nc_inq_varid(fileID, cell_var, &nc_cell_id); + status = nc_inq_varid(ncid, cell_var, &nc_cell_id); if ( status == NC_NOERR ) { ncvars[ncvarid].cellarea = nc_cell_id; @@ -4734,7 +4772,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim { char *pstring, *xvarname = NULL, *yvarname = NULL; - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); pstring = attstring; while ( isspace((int) *pstring) ) pstring++; @@ -4746,8 +4784,8 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim while ( isgraph((int) *pstring) ) pstring++; *pstring++ = 0; - cdf_inq_varid(fileID, xvarname, &ncvars[ncvarid].xvarid); - cdf_inq_varid(fileID, yvarname, &ncvars[ncvarid].yvarid); + cdf_inq_varid(ncid, xvarname, &ncvars[ncvarid].xvarid); + cdf_inq_varid(ncid, yvarname, &ncvars[ncvarid].yvarid); cdfSetVar(ncvars, ncvars[ncvarid].xvarid, FALSE); cdfSetVar(ncvars, ncvars[ncvarid].yvarid, FALSE); @@ -4763,7 +4801,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim int dimvarid; extern int cdiIgnoreAttCoordinates; - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); pstring = attstring; for ( i = 0; i < 4; i++ ) @@ -4775,7 +4813,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim if ( *pstring == 0 ) lstop = TRUE; *pstring++ = 0; - status = nc_inq_varid(fileID, varname, &dimvarid); + status = nc_inq_varid(ncid, varname, &dimvarid); if ( status == NC_NOERR ) { cdfSetVar(ncvars, dimvarid, FALSE); @@ -4798,9 +4836,9 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim int status; int nc_gmap_id; - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); - status = nc_inq_varid(fileID, attstring, &nc_gmap_id); + status = nc_inq_varid(ncid, attstring, &nc_gmap_id); if ( status == NC_NOERR ) { ncvars[ncvarid].gmapid = nc_gmap_id; @@ -4813,7 +4851,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "positive") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); strtolower(attstring); if ( memcmp(attstring, "down", 4) == 0 ) ncvars[ncvarid].positive = -1; @@ -4829,7 +4867,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim else if ( (strcmp(attname, "_FillValue") == 0 || strcmp(attname, "missing_value") == 0) && atttype != NC_CHAR ) { - cdfGetAttDouble(fileID, ncvarid, attname, 1, &ncvars[ncvarid].missval); + cdfGetAttDouble(ncid, ncvarid, attname, 1, &ncvars[ncvarid].missval); ncvars[ncvarid].defmiss = TRUE; /* cdfSetVar(ncvars, ncvarid, TRUE); */ } @@ -4837,26 +4875,62 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim { if ( ncvars[ncvarid].lvalidrange == FALSE ) { - cdfGetAttDouble(fileID, ncvarid, attname, 2, ncvars[ncvarid].validrange); - ncvars[ncvarid].lvalidrange = TRUE; - if ( ((int)ncvars[ncvarid].validrange[0]) == 0 && ((int)ncvars[ncvarid].validrange[1]) == 255 ) - ncvars[ncvarid].lunsigned = TRUE; - /* cdfSetVar(ncvars, ncvarid, TRUE); */ + extern int cdiIgnoreValidRange; + int lignore = FALSE; + if ( (atttype == NC_FLOAT || atttype == NC_DOUBLE) && xtype != NC_FLOAT && xtype != NC_DOUBLE ) lignore = TRUE; + if ( cdiIgnoreValidRange == FALSE && lignore == FALSE ) + { + cdfGetAttDouble(ncid, ncvarid, attname, 2, ncvars[ncvarid].validrange); + ncvars[ncvarid].lvalidrange = TRUE; + if ( ((int)ncvars[ncvarid].validrange[0]) == 0 && ((int)ncvars[ncvarid].validrange[1]) == 255 ) + ncvars[ncvarid].lunsigned = TRUE; + /* cdfSetVar(ncvars, ncvarid, TRUE); */ + } + else if ( lignore ) + { + Warning("Inconsistent data type for attribute %s:valid_range, ignored!", name); + } } } else if ( strcmp(attname, "valid_min") == 0 && attlen == 1 ) { - cdfGetAttDouble(fileID, ncvarid, attname, 1, &(ncvars[ncvarid].validrange)[0]); - ncvars[ncvarid].lvalidrange = TRUE; + if ( ncvars[ncvarid].lvalidrange == FALSE ) + { + extern int cdiIgnoreValidRange; + int lignore = FALSE; + if ( (atttype == NC_FLOAT || atttype == NC_DOUBLE) && xtype != NC_FLOAT && xtype != NC_DOUBLE ) lignore = TRUE; + if ( cdiIgnoreValidRange == FALSE && lignore == FALSE ) + { + cdfGetAttDouble(ncid, ncvarid, attname, 1, &(ncvars[ncvarid].validrange)[0]); + ncvars[ncvarid].lvalidrange = TRUE; + } + else if ( lignore ) + { + Warning("Inconsistent data type for attribute %s:valid_min, ignored!", name); + } + } } else if ( strcmp(attname, "valid_max") == 0 && attlen == 1 ) { - cdfGetAttDouble(fileID, ncvarid, attname, 1, &(ncvars[ncvarid].validrange)[1]); - ncvars[ncvarid].lvalidrange = TRUE; + if ( ncvars[ncvarid].lvalidrange == FALSE ) + { + extern int cdiIgnoreValidRange; + int lignore = FALSE; + if ( (atttype == NC_FLOAT || atttype == NC_DOUBLE) && xtype != NC_FLOAT && xtype != NC_DOUBLE ) lignore = TRUE; + if ( cdiIgnoreValidRange == FALSE && lignore == FALSE ) + { + cdfGetAttDouble(ncid, ncvarid, attname, 1, &(ncvars[ncvarid].validrange)[1]); + ncvars[ncvarid].lvalidrange = TRUE; + } + else if ( lignore ) + { + Warning("Inconsistent data type for attribute %s:valid_max, ignored!", name); + } + } } else if ( strcmp(attname, "_Unsigned") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); strtolower(attstring); if ( memcmp(attstring, "true", 4) == 0 ) @@ -4872,7 +4946,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "cdi") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); strtolower(attstring); if ( memcmp(attstring, "ignore", 6) == 0 ) @@ -4883,7 +4957,7 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim } else if ( strcmp(attname, "axis") == 0 && atttype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); attlen = strlen(attstring); if ( (int) attlen > nvdims ) @@ -4908,12 +4982,12 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim { while ( attlen-- ) { - if ( tolower((int) attstring[attlen]) == 't' ) + if ( (int) attstring[attlen] == 't' ) { if ( attlen != 0 ) Warning("axis attribute 't' not on first position"); cdfSetDim(ncvars, ncvarid, attlen, T_AXIS); } - else if ( tolower((int) attstring[attlen]) == 'z' ) + else if ( (int) attstring[attlen] == 'z' ) { ncvars[ncvarid].zdim = dimidsp[attlen]; cdfSetDim(ncvars, ncvarid, attlen, Z_AXIS); @@ -4924,20 +4998,52 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim ncdims[ncvars[ncvarid].dimids[0]].dimtype = Z_AXIS; } } - else if ( tolower((int) attstring[attlen]) == 'y' ) + else if ( (int) attstring[attlen] == 'y' ) { ncvars[ncvarid].ydim = dimidsp[attlen]; cdfSetDim(ncvars, ncvarid, attlen, Y_AXIS); + + if ( ncvars[ncvarid].ndims == 1 ) + { + cdfSetVar(ncvars, ncvarid, FALSE); + ncdims[ncvars[ncvarid].dimids[0]].dimtype = Y_AXIS; + } } - else if ( tolower((int) attstring[attlen]) == 'x' ) + else if ( (int) attstring[attlen] == 'x' ) { ncvars[ncvarid].xdim = dimidsp[attlen]; cdfSetDim(ncvars, ncvarid, attlen, X_AXIS); + + if ( ncvars[ncvarid].ndims == 1 ) + { + cdfSetVar(ncvars, ncvarid, FALSE); + ncdims[ncvars[ncvarid].dimids[0]].dimtype = X_AXIS; + } } } } } } + else if ( ( strcmp(attname, "realization") == 0 ) || + ( strcmp(attname, "ensemble_members") == 0 ) || + ( strcmp(attname, "forecast_init_type") == 0 ) ) + { + int temp; + + if( ncvars[ncvarid].ensdata == NULL ) + ncvars[ncvarid].ensdata = (ensinfo_t *) malloc( sizeof( ensinfo_t ) ); + + cdfGetAttInt(ncid, ncvarid, attname, 1, &temp); + + if( strcmp(attname, "realization") == 0 ) + ncvars[ncvarid].ensdata->ens_index = temp; + else if( strcmp(attname, "ensemble_members") == 0 ) + ncvars[ncvarid].ensdata->ens_count = temp; + else if( strcmp(attname, "forecast_init_type") == 0 ) + ncvars[ncvarid].ensdata->forecast_init_type = temp; + + cdfSetVar(ncvars, ncvarid, TRUE); + } else { if ( ncvars[ncvarid].natts == 0 ) @@ -4948,21 +5054,21 @@ void cdfScanVarAttributes(int fileID, int nvars, ncvar_t *ncvars, ncdim_t *ncdim int attrint; double attrflt; nc_type attrtype; - cdf_inq_attlen(fileID, ncvarid, attname, &attlen); - cdf_inq_atttype(fileID, ncvarid, attname, &attrtype); + cdf_inq_attlen(ncid, ncvarid, attname, &attlen); + cdf_inq_atttype(ncid, ncvarid, attname, &attrtype); if ( attlen == 1 && (attrtype == NC_INT || attrtype == NC_SHORT) ) { - cdfGetAttInt(fileID, ncvarid, attname, 1, &attrint); + cdfGetAttInt(ncid, ncvarid, attname, 1, &attrint); printf("int: %s.%s = %d\n", ncvars[ncvarid].name, attname, attrint); } else if ( attlen == 1 && (attrtype == NC_FLOAT || attrtype == NC_DOUBLE) ) { - cdfGetAttDouble(fileID, ncvarid, attname, 1, &attrflt); + cdfGetAttDouble(ncid, ncvarid, attname, 1, &attrflt); printf("flt: %s.%s = %g\n", ncvars[ncvarid].name, attname, attrflt); } else if ( attrtype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); attstring[attlen] = 0; printf("txt: %s.%s = %s\n", ncvars[ncvarid].name, attname, attstring); } @@ -5009,33 +5115,31 @@ void setDimType(int nvars, ncvar_t *ncvars, ncdim_t *ncdims) if ( ncvars[ncvarid].dimtype[i] == X_AXIS ) lxdim = TRUE; else if ( ncvars[ncvarid].dimtype[i] == Y_AXIS ) lydim = TRUE; else if ( ncvars[ncvarid].dimtype[i] == Z_AXIS ) lzdim = TRUE; - /* else if ( ncvars[ncvarid].dimtype[i] == T_AXIS ) ltdim = TRUE; */ + /* else if ( ncvars[ncvarid].dimtype[i] == T_AXIS ) ltdim = TRUE; */ } - for ( i = ndims-1; i >= 0; i-- ) - { - if ( ncvars[ncvarid].dimtype[i] == -1 ) - { - /* - printf("undef dim: %d %d %d %d %d\n", i, lxdim, lydim, lzdim, ltdim); - */ - if ( lxdim == FALSE ) - { - cdfSetDim(ncvars, ncvarid, i, X_AXIS); - lxdim = TRUE; - } - else if ( lydim == FALSE && ncvars[ncvarid].gridtype != GRID_UNSTRUCTURED ) - { - cdfSetDim(ncvars, ncvarid, i, Y_AXIS); - lydim = TRUE; - } - else if ( lzdim == FALSE ) - { - cdfSetDim(ncvars, ncvarid, i, Z_AXIS); - lzdim = TRUE; - } - } - } + // if ( ndims > 1 ) + for ( i = ndims-1; i >= 0; i-- ) + { + if ( ncvars[ncvarid].dimtype[i] == -1 ) + { + if ( lxdim == FALSE ) + { + cdfSetDim(ncvars, ncvarid, i, X_AXIS); + lxdim = TRUE; + } + else if ( lydim == FALSE && ncvars[ncvarid].gridtype != GRID_UNSTRUCTURED ) + { + cdfSetDim(ncvars, ncvarid, i, Y_AXIS); + lydim = TRUE; + } + else if ( lzdim == FALSE ) + { + cdfSetDim(ncvars, ncvarid, i, Z_AXIS); + lzdim = TRUE; + } + } + } } } } @@ -5053,6 +5157,7 @@ void verify_coordinate_vars_1(int ndims, ncdim_t *ncdims, ncvar_t *ncvars, int t { if ( ncvars[ncvarid].dimids[0] == timedimid ) { + ncvars[ncvarid].istime = TRUE; ncdims[ncdimid].dimtype = T_AXIS; continue; } @@ -5125,6 +5230,7 @@ void verify_coordinate_vars_1(int ndims, ncdim_t *ncdims, ncvar_t *ncvars, int t if ( ncvars[ncvarid].zaxistype != UNDEFID ) { + ncvars[ncvarid].islev = TRUE; cdfSetVar(ncvars, ncvarid, FALSE); cdfSetDim(ncvars, ncvarid, 0, Z_AXIS); ncdims[ncdimid].dimtype = Z_AXIS; @@ -5212,7 +5318,7 @@ void copy_numeric_projatts(int gridID, int ncvarID, int ncfileID) { int iatt, nvatts; size_t attlen; - char attname[256]; + char attname[CDI_MAX_NAME]; nc_type xtype; cdf_inq_varnatts(ncfileID, ncvarID, &nvatts); @@ -5223,14 +5329,14 @@ void copy_numeric_projatts(int gridID, int ncvarID, int ncfileID) cdf_inq_atttype(ncfileID, ncvarID, attname, &xtype); cdf_inq_attlen(ncfileID, ncvarID, attname, &attlen); - printf("%s %d\n", attname, (int)attlen); + // printf("%s %d\n", attname, (int)attlen); } } /* define all input grids */ static -void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid) +void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid, char *uuidOfHGrid) { int ncvarid, ncvarid2; int ndims; @@ -5242,15 +5348,15 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd grid_t proj; int gridindex; size_t size = 0, xsize, ysize, np; - char name[256]; + char name[CDI_MAX_NAME]; int iatt; int ltwarn = TRUE; size_t attlen; - char attname[256]; + char attname[CDI_MAX_NAME]; const int attstringlen = 8192; char attstring[8192]; double datt; - for ( ncvarid = 0; ncvarid < nvars; ncvarid++ ) + for ( ncvarid = 0; ncvarid < nvars; ++ncvarid ) { if ( ncvars[ncvarid].isvar && ncvars[ncvarid].gridID == UNDEFID ) { @@ -5432,9 +5538,9 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd grid.xvals = (double *) malloc(size*sizeof(double)); if ( ltgrid ) - cdf_get_vara_double(fileID, xvarid, start, count, grid.xvals); + cdf_get_vara_double(ncvars[xvarid].ncid, xvarid, start, count, grid.xvals); else - cdf_get_var_double(fileID, xvarid, grid.xvals); + cdf_get_var_double(ncvars[xvarid].ncid, xvarid, grid.xvals); scale_add(size, grid.xvals, ncvars[xvarid].addoffset, ncvars[xvarid].scalefactor); @@ -5505,9 +5611,9 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd grid.yvals = (double *) malloc(size*sizeof(double)); if ( ltgrid ) - cdf_get_vara_double(fileID, yvarid, start, count, grid.yvals); + cdf_get_vara_double(ncvars[yvarid].ncid, yvarid, start, count, grid.yvals); else - cdf_get_var_double(fileID, yvarid, grid.yvals); + cdf_get_var_double(ncvars[yvarid].ncid, yvarid, grid.yvals); scale_add(size, grid.yvals, ncvars[yvarid].addoffset, ncvars[yvarid].scalefactor); @@ -5590,7 +5696,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd nvertex = ncdims[ncvars[ncvars[xvarid].bounds].dimids[nbdims-1]].len; grid.nvertex = (int) nvertex; grid.xbounds = (double *) malloc(nvertex*size*sizeof(double)); - cdf_get_var_double(fileID, ncvars[xvarid].bounds, grid.xbounds); + cdf_get_var_double(ncvars[xvarid].ncid, ncvars[xvarid].bounds, grid.xbounds); } } } @@ -5609,7 +5715,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd grid.nvertex, (int) nvertex); */ grid.ybounds = (double *) malloc(nvertex*size*sizeof(double)); - cdf_get_var_double(fileID, ncvars[yvarid].bounds, grid.ybounds); + cdf_get_var_double(ncvars[yvarid].ncid, ncvars[yvarid].bounds, grid.ybounds); } } } @@ -5617,7 +5723,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd if ( ncvars[ncvarid].cellarea != UNDEFID ) { grid.area = (double *) malloc(size*sizeof(double)); - cdf_get_var_double(fileID, ncvars[ncvarid].cellarea, grid.area); + cdf_get_var_double(ncvars[ncvarid].ncid, ncvars[ncvarid].cellarea, grid.area); } break; @@ -5663,16 +5769,16 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd if ( ncvars[ncvarid].gmapid >= 0 && ncvars[ncvarid].gridtype != GRID_CURVILINEAR ) { - cdf_inq_varnatts(fileID, ncvars[ncvarid].gmapid, &nvatts); + cdf_inq_varnatts(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, &nvatts); for ( iatt = 0; iatt < nvatts; iatt++ ) { - cdf_inq_attname(fileID, ncvars[ncvarid].gmapid, iatt, attname); - cdf_inq_attlen(fileID, ncvars[ncvarid].gmapid, attname, &attlen); + cdf_inq_attname(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, iatt, attname); + cdf_inq_attlen(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, &attlen); if ( strcmp(attname, "grid_mapping_name") == 0 ) { - cdfGetAttText(fileID, ncvars[ncvarid].gmapid, attname, attstringlen-1, attstring); + cdfGetAttText(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, attstringlen-1, attstring); strtolower(attstring); if ( strcmp(attstring, "rotated_latitude_longitude") == 0 ) @@ -5691,21 +5797,21 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd } else if ( strcmp(attname, "earth_radius") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &datt); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &datt); grid.laea_a = datt; grid.lcc2_a = datt; } else if ( strcmp(attname, "longitude_of_projection_origin") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &grid.laea_lon_0); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &grid.laea_lon_0); } else if ( strcmp(attname, "longitude_of_central_meridian") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &grid.lcc2_lon_0); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &grid.lcc2_lon_0); } else if ( strcmp(attname, "latitude_of_projection_origin") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &datt); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &datt); grid.laea_lat_0 = datt; grid.lcc2_lat_0 = datt; } @@ -5713,29 +5819,29 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd { if ( attlen == 1 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &datt); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &datt); grid.lcc2_lat_1 = datt; grid.lcc2_lat_2 = datt; } else { double datt2[2]; - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 2, datt2); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 2, datt2); grid.lcc2_lat_1 = datt2[0]; grid.lcc2_lat_2 = datt2[1]; } } else if ( strcmp(attname, "grid_north_pole_latitude") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &grid.ypole); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &grid.ypole); } else if ( strcmp(attname, "grid_north_pole_longitude") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &grid.xpole); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &grid.xpole); } else if ( strcmp(attname, "north_pole_grid_longitude") == 0 ) { - cdfGetAttDouble(fileID, ncvars[ncvarid].gmapid, attname, 1, &grid.angle); + cdfGetAttDouble(ncvars[ncvarid].ncid, ncvars[ncvarid].gmapid, attname, 1, &grid.angle); } } } @@ -5771,12 +5877,39 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd if ( proj.type == GRID_PROJECTION ) { ncvars[ncvarid].gridID = varDefGrid(vlistID, proj, 1); - copy_numeric_projatts(ncvars[ncvarid].gridID, ncvars[ncvarid].gmapid, fileID); + copy_numeric_projatts(ncvars[ncvarid].gridID, ncvars[ncvarid].gmapid, ncvars[ncvarid].ncid); } else #endif ncvars[ncvarid].gridID = varDefGrid(vlistID, grid, 1); + if ( uuidOfHGrid[0] != 0 && grid.type == GRID_UNSTRUCTURED ) + gridDefUUID(ncvars[ncvarid].gridID, uuidOfHGrid); + + if ( ncvars[ncvarid].chunked ) + { + ndims = ncvars[ncvarid].ndims; + + if ( grid.type == GRID_UNSTRUCTURED ) + { + if ( ncvars[ncvarid].chunks[ndims-1] == grid.size ) + ncvars[ncvarid].chunktype = CHUNK_GRID; + else + ncvars[ncvarid].chunktype = CHUNK_AUTO; + } + else + { + if ( grid.xsize > 1 && grid.ysize > 1 && ndims > 1 && + grid.xsize == ncvars[ncvarid].chunks[ndims-1] && + grid.ysize == ncvars[ncvarid].chunks[ndims-2] ) + ncvars[ncvarid].chunktype = CHUNK_GRID; + else if ( grid.xsize > 1 && grid.xsize == ncvars[ncvarid].chunks[ndims-1] ) + ncvars[ncvarid].chunktype = CHUNK_LINES; + else + ncvars[ncvarid].chunktype = CHUNK_AUTO; + } + } + gridindex = vlistGridIndex(vlistID, ncvars[ncvarid].gridID); streamptr->xdimID[gridindex] = xdimid; streamptr->ydimID[gridindex] = ydimid; @@ -5820,6 +5953,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd Message("Same gridID %d %d %s", ncvars[ncvarid].gridID, ncvarid2, ncvars[ncvarid2].name); ncvars[ncvarid2].gridID = ncvars[ncvarid].gridID; + ncvars[ncvarid2].chunktype = ncvars[ncvarid].chunktype; } } } @@ -5829,7 +5963,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd /* define all input zaxes */ static -void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, +void define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, size_t vctsize, double *vct) { int ncvarid, ncvarid2; @@ -5889,7 +6023,7 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd if ( pname[len-2] == '_' && isdigit((int) pname[len-1]) ) pname[len-2] = 0; */ - cdf_get_var_double(fileID, zvarid, zvar); + cdf_get_var_double(ncvars[zvarid].ncid, zvarid, zvar); if ( ncvars[zvarid].bounds != UNDEFID ) { @@ -5905,7 +6039,7 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd zbounds = (double *) malloc(2*nlevel*sizeof(double)); lbounds = (double *) malloc(nlevel*sizeof(double)); ubounds = (double *) malloc(nlevel*sizeof(double)); - cdf_get_var_double(fileID, ncvars[zvarid].bounds, zbounds); + cdf_get_var_double(ncvars[zvarid].ncid, ncvars[zvarid].bounds, zbounds); for ( i = 0; i < nlevel; ++i ) { lbounds[i] = zbounds[i*2]; @@ -5956,7 +6090,7 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd Message("zaxisID %d %d %s", ncvars[ncvarid].zaxisID, ncvarid, ncvars[ncvarid].name); for ( ncvarid2 = ncvarid+1; ncvarid2 < nvars; ncvarid2++ ) - if ( ncvars[ncvarid2].isvar == TRUE && ncvars[ncvarid2].zaxisID == UNDEFID ) + if ( ncvars[ncvarid2].isvar == TRUE && ncvars[ncvarid2].zaxisID == UNDEFID && ncvars[ncvarid2].zaxistype == UNDEFID ) { int zdimid2 = -1; ndims = ncvars[ncvarid2].ndims; @@ -5979,16 +6113,12 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd /* define all input data variables */ static -void define_all_vars(int fileID, int streamID, int vlistID, int instID, int modelID, int *varids, ncdim_t *ncdims, int nvars, ncvar_t *ncvars) +void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID, int *varids, int nvars, ncvar_t *ncvars) { + int ncid; int varID1, varID, ncvarid; int code; int tableID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( streamptr->sortname ) { @@ -6023,12 +6153,15 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode gridID = ncvars[ncvarid].gridID; zaxisID = ncvars[ncvarid].zaxisID; - varID = streamNewVar(streamID, gridID, zaxisID); + varID = stream_new_var(streamptr, gridID, zaxisID); varID = vlistDefVar(vlistID, gridID, zaxisID, ncvars[ncvarid].tsteptype); #if defined (HAVE_NETCDF4) if ( ncvars[ncvarid].deflate ) vlistDefVarCompType(vlistID, varID, COMPRESS_ZIP); + + if ( ncvars[ncvarid].chunked && ncvars[ncvarid].chunktype != UNDEFID ) + vlistDefVarChunkType(vlistID, varID, ncvars[ncvarid].chunktype); #endif streamptr->vars[varID1].level = NULL; @@ -6116,11 +6249,20 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode printf("dimids: %d %d\n", i, ncvars[ncvarid].dimids[i]); printf("xdimid, ydimid %d %d\n", xdimid, ydimid); */ + if ( ncvars[ncvarid].ensdata != NULL ) + { + vlistDefVarEnsemble( vlistID, varID, ncvars[ncvarid].ensdata->ens_index, + ncvars[ncvarid].ensdata->ens_count, + ncvars[ncvarid].ensdata->forecast_init_type ); + free(ncvars[ncvarid].ensdata); + ncvars[ncvarid].ensdata = NULL; + } } for ( varID = 0; varID < nvars; varID++ ) { ncvarid = varids[varID]; + ncid = ncvars[ncvarid].ncid; if ( ncvars[ncvarid].natts ) { @@ -6129,21 +6271,21 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode int iatt; nc_type attrtype; size_t attlen; - char attname[256]; + char attname[CDI_MAX_NAME]; const int attstringlen = 8192; char attstring[8192]; nvatts = ncvars[ncvarid].natts; for ( iatt = 0; iatt < nvatts; iatt++ ) { attnum = ncvars[ncvarid].atts[iatt]; - cdf_inq_attname(fileID, ncvarid, attnum, attname); - cdf_inq_attlen(fileID, ncvarid, attname, &attlen); - cdf_inq_atttype(fileID, ncvarid, attname, &attrtype); + cdf_inq_attname(ncid, ncvarid, attnum, attname); + cdf_inq_attlen(ncid, ncvarid, attname, &attlen); + cdf_inq_atttype(ncid, ncvarid, attname, &attrtype); if ( attrtype == NC_SHORT || attrtype == NC_INT ) { int *attint; attint = (int *) malloc(attlen*sizeof(int)); - cdfGetAttInt(fileID, ncvarid, attname, attlen, attint); + cdfGetAttInt(ncid, ncvarid, attname, attlen, attint); if ( attrtype == NC_SHORT ) vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT16, (int)attlen, attint); else @@ -6156,7 +6298,7 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode { double *attflt; attflt = (double *) malloc(attlen*sizeof(double)); - cdfGetAttDouble(fileID, ncvarid, attname, attlen, attflt); + cdfGetAttDouble(ncid, ncvarid, attname, attlen, attflt); if ( attrtype == NC_FLOAT ) vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT32, (int)attlen, attflt); else @@ -6167,8 +6309,7 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode } else if ( attrtype == NC_CHAR ) { - cdfGetAttText(fileID, ncvarid, attname, attstringlen-1, attstring); - attlen = 1 + strlen(attstring); + cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring); vlistDefAttTxt(vlistID, varID, attname, (int)attlen, attstring); if ( CDI_Debug ) printf("txt: %s.%s = %s\n", ncvars[ncvarid].name, attname, attstring); @@ -6248,91 +6389,26 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode tableID = cdiDefaultTableID; } } - if ( cdiDefaultModelID != UNDEFID ) - modelID = cdiDefaultModelID; - if ( cdiDefaultInstID != UNDEFID ) - instID = cdiDefaultInstID; + + if ( cdiDefaultModelID != UNDEFID ) modelID = cdiDefaultModelID; + if ( cdiDefaultInstID != UNDEFID ) instID = cdiDefaultInstID; } if ( instID != UNDEFID ) vlistDefVarInstitut(vlistID, varID, instID); if ( modelID != UNDEFID ) vlistDefVarModel(vlistID, varID, modelID); if ( tableID != UNDEFID ) vlistDefVarTable(vlistID, varID, tableID); } } -#endif -int cdfInqContents(int streamID) +static +void scan_global_attributtes(int fileID, int vlistID, stream_t *streamptr, int ngatts, + int *instID, int *modelID, int *ucla_les, char *uuidOfHGrid) { -#if defined (HAVE_LIBNETCDF) - int ndims, nvars, ngatts, unlimdimid; - int ncvarid; - int ncdimid; - int fileID; nc_type xtype; - size_t ntsteps; - int timedimid = -1; - int *varids; - int nvarids; size_t attlen; - char attname[256]; + char attname[CDI_MAX_NAME]; const int attstringlen = 8192; char attstring[8192]; - int iatt, timehasunits = FALSE; - int time_has_bounds = FALSE; - size_t len; - int nc_nvars; - int nvcth_id = UNDEFID, vcta_id = UNDEFID, vctb_id = UNDEFID; - size_t vctsize = 0; - double *vct = NULL; - int instID = UNDEFID; - int modelID = UNDEFID; - int taxisID; - int i; - int nbdims; - int calendar = UNDEFID; - ncdim_t *ncdims; - ncvar_t *ncvars; - int vlistID; - stream_t *streamptr; - int format = 0; - int ucla_les = FALSE; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); - - if ( CDI_Debug ) - Message("streamID = %d, fileID = %d", streamID, fileID); - -#if defined (HAVE_NETCDF4) - nc_inq_format(fileID, &format); -#endif - - cdf_inq(fileID, &ndims , &nvars, &ngatts, &unlimdimid); - - /* alloc ncdims */ - if ( ndims > 0 ) - ncdims = (ncdim_t *) malloc(ndims*sizeof(ncdim_t)); - else - { - Warning("ndims = %d", ndims); - return (CDI_EUFSTRUCT); - } - - /* alloc ncvars */ - if ( nvars > 0 ) - ncvars = (ncvar_t *) malloc(nvars*sizeof(ncvar_t)); - else - { - Warning("nvars = %d", nvars); - return (CDI_EUFSTRUCT); - } - - init_ncdims(ndims, ncdims); - init_ncvars(nvars, ncvars); + int iatt; - /* read global attributtes */ for ( iatt = 0; iatt < ngatts; iatt++ ) { cdf_inq_attname(fileID, NC_GLOBAL, iatt, attname); @@ -6351,18 +6427,20 @@ int cdfInqContents(int streamID) } else if ( strcmp(attname, "institution") == 0 ) { - instID = institutInq(0, 0, NULL, attstring); - if ( instID == UNDEFID ) - instID = institutDef(0, 0, NULL, attstring); + *instID = institutInq(0, 0, NULL, attstring); + if ( *instID == UNDEFID ) + *instID = institutDef(0, 0, NULL, attstring); } else if ( strcmp(attname, "source") == 0 ) { - modelID = modelInq(-1, 0, attstring); + *modelID = modelInq(-1, 0, attstring); + if ( *modelID == UNDEFID ) + *modelID = modelDef(-1, 0, attstring); } else if ( strcmp(attname, "Source") == 0 ) { if ( strncmp(attstring, "UCLA-LES", 8) == 0 ) - ucla_les = TRUE; + *ucla_les = TRUE; } /* else if ( strcmp(attname, "Conventions") == 0 ) @@ -6375,6 +6453,12 @@ int cdfInqContents(int streamID) else if ( strcmp(attname, "CDO") == 0 ) { } + else if ( strcmp(attname, "uuidOfHGrid") == 0 && attlen == 36 ) + { + attstring[36] = 0; + str2uuid(attstring, uuidOfHGrid); + // printf("uuid: %d %s\n", attlen, attstring); + } else { vlistDefAttTxt(vlistID, CDI_GLOBAL, attname, (int)attlen, attstring); @@ -6404,6 +6488,112 @@ int cdfInqContents(int streamID) free(attflt); } } +} +#endif + +int cdfInqContents(stream_t *streamptr) +{ +#if defined (HAVE_LIBNETCDF) + int ndims, nvars, ngatts, unlimdimid; + int ncvarid; + int ncdimid; + int fileID; + size_t ntsteps; + int timedimid = -1; + int *varids; + int nvarids; + const int attstringlen = 8192; char attstring[8192]; + int timehasunits = FALSE; + int time_has_bounds = FALSE; + size_t len; + int nvars_data; + int nvcth_id = UNDEFID, vcta_id = UNDEFID, vctb_id = UNDEFID; + size_t vctsize = 0; + double *vct = NULL; + int instID = UNDEFID; + int modelID = UNDEFID; + int taxisID; + int i; + int nbdims; + int calendar = UNDEFID; + ncdim_t *ncdims; + ncvar_t *ncvars = NULL; + int vlistID; + int format = 0; + int ucla_les = FALSE; + char uuidOfHGrid[17]; + + uuidOfHGrid[0] = 0; + + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; + + if ( CDI_Debug ) Message("streamID = %d, fileID = %d", streamptr->self, fileID); + +#if defined (HAVE_NETCDF4) + nc_inq_format(fileID, &format); +#endif + + cdf_inq(fileID, &ndims , &nvars, &ngatts, &unlimdimid); + + if ( CDI_Debug ) + Message("root: ndims %d, nvars %d, ngatts %d", ndims, nvars, ngatts); + + if ( ndims == 0 ) + { + Warning("ndims = %d", ndims); + return (CDI_EUFSTRUCT); + } + + /* alloc ncdims */ + ncdims = (ncdim_t *) malloc(ndims*sizeof(ncdim_t)); + init_ncdims(ndims, ncdims); + + if ( nvars > 0 ) + { + /* alloc ncvars */ + ncvars = (ncvar_t *) malloc(nvars*sizeof(ncvar_t)); + init_ncvars(nvars, ncvars); + + for ( ncvarid = 0; ncvarid < nvars; ++ncvarid ) + ncvars[ncvarid].ncid = fileID; + } + +#if defined (TEST_GROUPS) +#if defined (HAVE_NETCDF4) + if ( format == NC_FORMAT_NETCDF4 ) + { + int ncid; + int numgrps; + int ncids[NC_MAX_VARS]; + char name1[CDI_MAX_NAME]; + int gndims, gnvars, gngatts, gunlimdimid; + nc_inq_grps(fileID, &numgrps, ncids); + for ( int i = 0; i < numgrps; ++i ) + { + ncid = ncids[i]; + nc_inq_grpname (ncid, name1); + cdf_inq(ncid, &gndims , &gnvars, &gngatts, &gunlimdimid); + + if ( CDI_Debug ) + Message("%s: ndims %d, nvars %d, ngatts %d", name1, gndims, gnvars, gngatts); + + if ( gndims == 0 ) + { + } + } + } +#endif +#endif + + if ( nvars == 0 ) + { + Warning("nvars = %d", nvars); + return (CDI_EUFSTRUCT); + } + + /* scan global attributtes */ + scan_global_attributtes(fileID, vlistID, streamptr, ngatts, &instID, &modelID, &ucla_les, uuidOfHGrid); /* find time dim */ if ( unlimdimid >= 0 ) @@ -6418,9 +6608,7 @@ int cdfInqContents(int streamID) else ntsteps = 0; - streamptr->ntsteps = ntsteps; - - if ( CDI_Debug ) Message("Number of timesteps = %d", streamptr->ntsteps); + if ( CDI_Debug ) Message("Number of timesteps = %d", ntsteps); if ( CDI_Debug ) Message("Time dimid = %d", streamptr->basetime.ncdimid); /* read ncdims */ @@ -6432,12 +6620,13 @@ int cdfInqContents(int streamID) ncdims[ncdimid].dimtype = T_AXIS; } + if ( CDI_Debug ) printNCvars(ncvars, nvars, "cdfScanVarAttributes"); /* scan attributes of all variables */ - cdfScanVarAttributes(fileID, nvars, ncvars, ncdims, timedimid, modelID, format); + cdfScanVarAttributes(nvars, ncvars, ncdims, timedimid, modelID, format); - if ( CDI_Debug ) printNCvars(ncvars, nvars); + if ( CDI_Debug ) printNCvars(ncvars, nvars, "find coordinate vars"); /* find coordinate vars */ for ( ncdimid = 0; ncdimid < ndims; ncdimid++ ) @@ -6490,13 +6679,13 @@ int cdfInqContents(int streamID) { streamptr->basetime.ncvarid = ncvarid; ltimevar = TRUE; - if ( CDI_Debug ) + if ( CDI_Debug ) fprintf(stderr, "timevar %s\n", ncvars[ncvarid].name); } else { if ( CDI_Debug ) - fprintf(stderr, "skip timevar %s\n", ncvars[ncvarid].name); + fprintf(stderr, "skipped timevar %s\n", ncvars[ncvarid].name); } } @@ -6603,7 +6792,7 @@ int cdfInqContents(int streamID) /* verify coordinate vars - second scan (all other variables) */ verify_coordinate_vars_2(nvars, ncvars); - if ( CDI_Debug ) printNCvars(ncvars, nvars); + if ( CDI_Debug ) printNCvars(ncvars, nvars, "verify_coordinate_vars"); if ( ucla_les == TRUE ) { @@ -6693,11 +6882,11 @@ int cdfInqContents(int streamID) } } - if ( CDI_Debug ) printNCvars(ncvars, nvars); + if ( CDI_Debug ) printNCvars(ncvars, nvars, "define_all_grids"); /* define all grids */ - define_all_grids(streamptr, fileID, vlistID, ncdims, nvars, ncvars, timedimid); + define_all_grids(streamptr, vlistID, ncdims, nvars, ncvars, timedimid, uuidOfHGrid); /* read VCT */ @@ -6712,7 +6901,7 @@ int cdfInqContents(int streamID) /* define all zaxes */ - define_all_zaxes(streamptr, fileID, vlistID, ncdims, nvars, ncvars, vctsize, vct); + define_all_zaxes(streamptr, vlistID, ncdims, nvars, ncvars, vctsize, vct); if ( vct ) free(vct); @@ -6723,21 +6912,26 @@ int cdfInqContents(int streamID) for ( ncvarid = 0; ncvarid < nvars; ncvarid++ ) if ( ncvars[ncvarid].isvar == TRUE ) varids[nvarids++] = ncvarid; - nc_nvars = nvars; - nvars = nvarids; + nvars_data = nvarids; if ( CDI_Debug ) Message("time varid = %d", streamptr->basetime.ncvarid); - if ( CDI_Debug ) Message("ntsteps = %d", streamptr->ntsteps); - if ( CDI_Debug ) Message("nvars = %d", nvars); + if ( CDI_Debug ) Message("ntsteps = %d", ntsteps); + if ( CDI_Debug ) Message("nvars_data = %d", nvars_data); - if ( nvars == 0 ) return (CDI_EUFSTRUCT); + if ( nvars_data == 0 ) + { + streamptr->ntsteps = 0; + return (CDI_EUFSTRUCT); + } + + streamptr->ntsteps = ntsteps; /* define all data variables */ - define_all_vars(fileID, streamID, vlistID, instID, modelID, varids, ncdims, nvars, ncvars); + define_all_vars(streamptr, vlistID, instID, modelID, varids, nvars_data, ncvars); - cdiCreateTimesteps(streamID); + cdiCreateTimesteps(streamptr); /* time varID */ ncvarid = streamptr->basetime.ncvarid; @@ -6755,6 +6949,16 @@ int cdfInqContents(int streamID) if ( time_has_bounds ) streamptr->tsteps[0].taxis.has_bounds = TRUE; + if ( ncvarid != -1 ) + { + taxis_t *taxis; + taxis = &streamptr->tsteps[0].taxis; + + taxis->name = strdup(ncvars[ncvarid].name); + if ( ncvars[ncvarid].longname[0] ) + taxis->longname = strdup(ncvars[ncvarid].longname); + } + if ( ncvarid != -1 ) if ( ncvars[ncvarid].calendar == TRUE ) { @@ -6817,9 +7021,9 @@ int cdfInqContents(int streamID) streamptr->curTsID = 0; streamptr->rtsteps = 1; - (void) cdfInqTimestep(streamID, 0); + (void) cdfInqTimestep(streamptr, 0); - cdfCreateRecords(streamID, 0); + cdfCreateRecords(streamptr, 0); /* free ncdims */ free (ncdims); @@ -6833,7 +7037,7 @@ int cdfInqContents(int streamID) } -int cdfInqTimestep(int streamID, int tsID) +int cdfInqTimestep(stream_t * streamptr, int tsID) { long nrecs = 0; #if defined (HAVE_LIBNETCDF) @@ -6843,20 +7047,14 @@ int cdfInqTimestep(int streamID, int tsID) int fileID; size_t index; taxis_t *taxis; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - if ( CDI_Debug ) - Message("streamID = %d tsID = %d", streamID, tsID); - - stream_check_ptr(__func__, streamptr); + if ( CDI_Debug ) Message("streamID = %d tsID = %d", streamptr->self, tsID); if ( tsID < 0 ) Error("unexpected tsID = %d", tsID); if ( tsID < streamptr->ntsteps && streamptr->ntsteps > 0 ) { - cdfCreateRecords(streamID, tsID); + cdfCreateRecords(streamptr, tsID); taxis = &streamptr->tsteps[tsID].taxis; if ( tsID > 0 ) @@ -6867,7 +7065,7 @@ int cdfInqTimestep(int streamID, int tsID) nctimevarid = streamptr->basetime.ncvarid; if ( nctimevarid != UNDEFID ) { - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; index = tsID; if ( streamptr->basetime.lwrf ) @@ -6891,6 +7089,8 @@ int cdfInqTimestep(int streamID, int tsID) else { cdf_get_var1_double(fileID, nctimevarid, &index, &timevalue); + if ( timevalue >= NC_FILL_DOUBLE || timevalue < -NC_FILL_DOUBLE ) timevalue = 0; + cdiDecodeTimeval(timevalue, taxis, &taxis->vdate, &taxis->vtime); } @@ -6900,11 +7100,13 @@ int cdfInqTimestep(int streamID, int tsID) size_t start[2], count[2]; start[0] = tsID; count[0] = 1; start[1] = 0; count[1] = 1; cdf_get_vara_double(fileID, nctimeboundsid, start, count, &timevalue); + if ( timevalue >= NC_FILL_DOUBLE || timevalue < -NC_FILL_DOUBLE ) timevalue = 0; cdiDecodeTimeval(timevalue, taxis, &taxis->vdate_lb, &taxis->vtime_lb); start[0] = tsID; count[0] = 1; start[1] = 1; count[1] = 1; cdf_get_vara_double(fileID, nctimeboundsid, start, count, &timevalue); + if ( timevalue >= NC_FILL_DOUBLE || timevalue < -NC_FILL_DOUBLE ) timevalue = 0; cdiDecodeTimeval(timevalue, taxis, &taxis->vdate_ub, &taxis->vtime_ub); } @@ -6919,20 +7121,17 @@ int cdfInqTimestep(int streamID, int tsID) } -void cdfEndDef(int streamID) +void cdfEndDef(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) - int varID, ncvarid; + int varID; int nvars; int fileID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); + fileID = streamptr->fileID; - fileID = streamInqFileID(streamID); - - cdfDefGlobalAtts(streamID); - cdfDefLocalAtts(streamID); + cdfDefGlobalAtts(streamptr); + cdfDefLocalAtts(streamptr); if ( streamptr->accessmode == 0 ) { nvars = streamptr->nvars; @@ -6940,7 +7139,7 @@ void cdfEndDef(int streamID) if ( streamptr->ncmode == 2 ) cdf_redef(fileID); for ( varID = 0; varID < nvars; varID++ ) - ncvarid = cdfDefVar(streamID, varID); + cdfDefVar(streamptr, varID); if ( streamptr->ncmode == 2 ) cdf_enddef(fileID); @@ -6950,19 +7149,16 @@ void cdfEndDef(int streamID) } -void cdfDefInstitut(int streamID) +void cdfDefInstitut(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) int fileID, instID; char *longname; size_t len; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; instID = vlistInqInstitut(vlistID); if ( instID != UNDEFID ) @@ -6982,19 +7178,17 @@ void cdfDefInstitut(int streamID) #endif } -void cdfDefSource(int streamID) + +void cdfDefSource(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) int fileID, modelID; char *longname; size_t len; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; modelID = vlistInqModel(vlistID); if ( modelID != UNDEFID ) @@ -7015,22 +7209,19 @@ void cdfDefSource(int streamID) } -void cdfDefGlobalAtts(int streamID) +void cdfDefGlobalAtts(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) int fileID, vlistID; - stream_t *streamptr; int natts; - streamptr = stream_to_pointer(streamID); - if ( streamptr->globalatts ) return; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; - cdfDefSource(streamID); - cdfDefInstitut(streamID); + cdfDefSource(streamptr); + cdfDefInstitut(streamptr); vlistInqNatts(vlistID, CDI_GLOBAL, &natts); @@ -7045,7 +7236,7 @@ void cdfDefGlobalAtts(int streamID) } -void cdfDefLocalAtts(int streamID) +void cdfDefLocalAtts(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) int varID, instID, fileID; @@ -7053,12 +7244,9 @@ void cdfDefLocalAtts(int streamID) size_t len; int ncvarid; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; if ( streamptr->localatts ) return; if ( vlistInqInstitut(vlistID) != UNDEFID ) return; @@ -7086,27 +7274,23 @@ void cdfDefLocalAtts(int streamID) #endif } -void cdfDefHistory(int streamID, int size, char *history) + +void cdfDefHistory(stream_t *streamptr, int size, char *history) { #if defined (HAVE_LIBNETCDF) int ncid; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); ncid = streamptr->fileID; cdf_put_att_text(ncid, NC_GLOBAL, "history", (size_t) size, history); #endif } -int cdfInqHistorySize(int streamID) + +int cdfInqHistorySize(stream_t *streamptr) { size_t size = 0; #if defined (HAVE_LIBNETCDF) int ncid; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); ncid = streamptr->fileID; if ( streamptr->historyID != UNDEFID ) @@ -7117,13 +7301,10 @@ int cdfInqHistorySize(int streamID) } -void cdfInqHistoryString(int streamID, char *history) +void cdfInqHistoryString(stream_t *streamptr, char *history) { #if defined (HAVE_LIBNETCDF) int ncid; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); ncid = streamptr->fileID; if ( streamptr->historyID != UNDEFID ) @@ -7133,42 +7314,39 @@ void cdfInqHistoryString(int streamID, char *history) } -void cdfDefVars(int streamID) +void cdfDefVars(stream_t *streamptr) { #if defined (HAVE_LIBNETCDF) int index, gridID, zaxisID, vlistID; int ngrids, nzaxis; /* int nvars, ncvarid; */ - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; if ( vlistID == UNDEFID ) - Error("Internal problem! vlist undefined for streamID %d", streamID); + Error("Internal problem! vlist undefined for streamptr %p", streamptr); /* nvars = vlistNvars(vlistID); */ ngrids = vlistNgrids(vlistID); nzaxis = vlistNzaxis(vlistID); /* - if ( vlistHasTime(vlistID) ) cdfDefTime(streamID); + if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr); */ for ( index = 0; index < ngrids; index++ ) { gridID = vlistGrid(vlistID, index); - cdfDefGrid(streamID, gridID); + cdfDefGrid(streamptr, gridID); } for ( index = 0; index < nzaxis; index++ ) { zaxisID = vlistZaxis(vlistID, index); - if ( streamptr->zaxisID[index] == UNDEFID ) cdfDefZaxis(streamID, zaxisID); + if ( streamptr->zaxisID[index] == UNDEFID ) cdfDefZaxis(streamptr, zaxisID); } /* define time first!!! for (varID = 0; varID < nvars; varID++ ) { - ncvarid = cdfDefVar(streamID, varID); + ncvarid = cdfDefVar(streamptr, varID); } */ #endif diff --git a/src/stream_cdf.h b/src/stream_cdf.h index 16fc0207e..166aecd05 100644 --- a/src/stream_cdf.h +++ b/src/stream_cdf.h @@ -1,29 +1,29 @@ #ifndef _STREAM_CDF_H #define _STREAM_CDF_H -void cdfDefVars(int streamID); -void cdfDefTimestep(int streamID, int tsID); -int cdfInqTimestep(int streamID, int tsID); -int cdfInqContents(int streamID); -void cdfDefHistory(int streamID, int size, char *history); -int cdfInqHistorySize(int streamID); -void cdfInqHistoryString(int streamID, char *history); +void cdfDefVars(stream_t *streamptr); +void cdfDefTimestep(stream_t *streamptr, int tsID); +int cdfInqTimestep(stream_t *streamptr, int tsID); +int cdfInqContents(stream_t *streamptr); +void cdfDefHistory(stream_t *streamptr, int size, char *history); +int cdfInqHistorySize(stream_t *streamptr); +void cdfInqHistoryString(stream_t *streamptr, char *history); -void cdfEndDef(int streamID); -int cdfDefRecord(int streamID); +void cdfEndDef(stream_t * streamptr); +int cdfDefRecord(stream_t * streamptr); -int cdfCopyRecord(int streamIDdest, int streamIDsrc); +int cdfCopyRecord(stream_t *streamptr2, stream_t *streamptr1); -int cdfReadRecord(int streamID, double *data, int *nmiss); -void cdf_write_record(int streamID, int memtype, const void *data, int nmiss); +int cdfReadRecord(stream_t *streamptr, double *data, int *nmiss); +void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nmiss); -void cdfReadVarDP(int streamID, int varID, double *data, int *nmiss); -void cdf_write_var(int streamID, int varID, int memtype, const void *data, int nmiss); +void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss); +void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data, int nmiss); -int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss); -int cdf_write_var_slice(int streamID, int varID, int levelID, int memtype, const void *data, int nmiss); +int cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data, int *nmiss); +int cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, const void *data, int nmiss); -void cdf_write_var_chunk(int streamID, int varID, int memtype, +void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype, const int rect[][2], const void *data, int nmiss); #endif diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c index f8f1f8924..fdabb1da4 100644 --- a/src/stream_cgribex.c +++ b/src/stream_cgribex.c @@ -3,7 +3,7 @@ #endif #include <stdio.h> -#include <float.h> /* FLT_EPSILON */ +// #include <float.h> /* FLT_EPSILON */ #include "dmemory.h" #include "cdi.h" @@ -52,9 +52,7 @@ int cgribexGetGridType(int *isec2) return (gridtype); } -#endif -#if defined (HAVE_LIBCGRIBEX) static int cgribexGetIsRotated(int *isec2) { @@ -67,9 +65,7 @@ int cgribexGetIsRotated(int *isec2) return (isRotated); } -#endif -#if defined (HAVE_LIBCGRIBEX) static int cgribexGetZaxisHasBounds(int grb_ltype) { @@ -88,9 +84,7 @@ int cgribexGetZaxisHasBounds(int grb_ltype) return (lbounds); } -#endif -#if defined (HAVE_LIBCGRIBEX) static int cgribexGetTimeUnit(int *isec1) { @@ -112,13 +106,12 @@ int cgribexGetTimeUnit(int *isec1) Message("GRIB time unit %d unsupported!", ISEC1_TimeUnit); lprint = FALSE; } + break; } return (timeunit); } -#endif -#if defined (HAVE_LIBCGRIBEX) static int cgribexTimeIsFC(int *isec1) { @@ -129,13 +122,11 @@ int cgribexTimeIsFC(int *isec1) return (isFC); } -#endif -#if defined (HAVE_LIBCGRIBEX) static int cgribexGetTsteptype(int timerange) { - int tsteptype = 0; + int tsteptype = TSTEP_INSTANT; static int lprint = TRUE; switch ( timerange ) @@ -153,25 +144,27 @@ int cgribexGetTsteptype(int timerange) Message("GRIB time range %d unsupported!", timerange); lprint = FALSE; } + break; } return (tsteptype); } -#endif -#if defined (HAVE_LIBCGRIBEX) static -void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) +void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, int iret) { int gridtype; gridtype = cgribexGetGridType(isec2); - if ( streamptr->unreduced && gridtype == GRID_GAUSSIAN_REDUCED ) + if ( streamptr->unreduced && gridtype == GRID_GAUSSIAN_REDUCED && iret != -801 ) { + int ilat, nlon = 0; + for ( ilat = 0; ilat < ISEC2_NumLat; ++ilat ) + if ( ISEC2_RowLon(ilat) > nlon ) nlon = ISEC2_RowLon(ilat); gridtype = GRID_GAUSSIAN; - ISEC2_NumLon = 2*ISEC2_NumLat; - ISEC4_NumValues = ISEC2_NumLon*ISEC2_NumLat; + ISEC2_NumLon = nlon; + ISEC4_NumValues = nlon*ISEC2_NumLat; } memset(grid, 0, sizeof(grid_t)); @@ -194,16 +187,23 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) { if ( grid->xsize > 1 ) { - if ( ISEC2_ResFlag && ISEC2_LonIncr > 0 ) - if ( ISEC2_LonIncr*(grid->xsize-1) > 360000 ) ISEC2_LonIncr = 0; + int recompinc = TRUE; if ( ISEC2_ResFlag && ISEC2_LonIncr > 0 ) - grid->xinc = ISEC2_LonIncr * 0.001; - else - grid->xinc = (ISEC2_LastLon - ISEC2_FirstLon) * 0.001 / (grid->xsize - 1); + { + if ( ISEC2_LastLon < ISEC2_FirstLon && ISEC2_LastLon < 0 ) ISEC2_LastLon += 360000; + if ( abs(ISEC2_LastLon - (ISEC2_FirstLon+ISEC2_LonIncr*(grid->xsize-1))) <= 2 ) + { + recompinc = FALSE; + grid->xinc = ISEC2_LonIncr * 0.001; + } + } + + /* recompute xinc if necessary */ + if ( recompinc ) grid->xinc = (ISEC2_LastLon - ISEC2_FirstLon) * 0.001 / (grid->xsize-1); /* correct xinc if necessary */ - if ( ISEC2_FirstLon == 0 && ISEC2_LastLon > 354000 ) + if ( ISEC2_FirstLon == 0 && ISEC2_LastLon > 354000 && ISEC2_LastLon < 360000 ) { double xinc = 360. / grid->xsize; @@ -223,13 +223,19 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) { if ( grid->ysize > 1 ) { - if ( ISEC2_ResFlag && ISEC2_LatIncr > 0 ) - if ( ISEC2_LatIncr*(grid->ysize-1) > 180000 ) ISEC2_LatIncr = 0; + int recompinc = TRUE; if ( ISEC2_ResFlag && ISEC2_LatIncr > 0 ) - grid->yinc = ISEC2_LatIncr * 0.001; - else - grid->yinc = (ISEC2_LastLat - ISEC2_FirstLat) * 0.001 / (grid->ysize - 1); + { + if ( abs(ISEC2_LastLat - (ISEC2_FirstLat+ISEC2_LatIncr*(grid->ysize-1))) <= 2 ) + { + recompinc = FALSE; + grid->yinc = ISEC2_LatIncr * 0.001; + } + } + + /* recompute yinc if necessary */ + if ( recompinc ) grid->yinc = (ISEC2_LastLat - ISEC2_FirstLat) * 0.001 / (grid->ysize - 1); } grid->yfirst = ISEC2_FirstLat * 0.001; grid->ylast = ISEC2_LastLat * 0.001; @@ -347,12 +353,10 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) grid->yvals = NULL; grid->type = gridtype; } -#endif -#if defined (HAVE_LIBCGRIBEX) static -void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *fsec2, double *fsec3, - int *isec4, long recsize, off_t position, int datatype, int comptype, int lmv) +void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, double *fsec2, double *fsec3, + int *isec4, long recsize, off_t position, int datatype, int comptype, int lmv, int iret) { int zaxistype; int gridID = CDI_UNDEFID, varID; @@ -365,13 +369,10 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f record_t *record; grid_t grid; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; tsID = streamptr->curTsID; - recID = recordNewEntry(streamID, tsID); + recID = recordNewEntry(streamptr, tsID); record = &streamptr->tsteps[tsID].records[recID]; tsteptype = cgribexGetTsteptype(ISEC1_TimeRange); @@ -389,7 +390,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f (*record).ilevel2 = level2; (*record).ltype = ISEC1_LevelType; - cgribexGetGrid(streamptr, isec2, isec4, &grid); + cgribexGetGrid(streamptr, isec2, isec4, &grid, iret); gridID = varDefGrid(vlistID, grid, 0); @@ -408,7 +409,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f if ( datatype > 32 ) datatype = DATATYPE_PACK32; if ( datatype < 0 ) datatype = DATATYPE_PACK; - varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, + varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, 0, datatype, &varID, &levelID, tsteptype, numavg, ISEC1_LevelType, NULL, NULL, NULL); (*record).varID = varID; @@ -416,6 +417,14 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f varDefCompType(varID, comptype); + if ( ISEC1_LocalFLag ) + { + if ( ISEC1_CenterID == 78 && isec1[36] == 253 ) // DWD local extension + varDefEnsembleInfo(varID, isec1[54], isec1[53], isec1[52]); + else if ( ISEC1_CenterID == 252 && isec1[36] == 1 ) // MPIM local extension + varDefEnsembleInfo(varID, isec1[38], isec1[39], isec1[37]); + } + if ( lmv ) varDefMissval(varID, FSEC3_MissVal); if ( varInqInst(varID) == CDI_UNDEFID ) @@ -456,9 +465,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f Message("varID = %d param = %d zaxistype = %d gridID = %d levelID = %d", varID, param, zaxistype, gridID, levelID); } -#endif -#if defined (HAVE_LIBCGRIBEX) static void MCH_get_undef(int *isec1, double *undef_pds, double *undef_eps) { @@ -483,18 +490,18 @@ void MCH_get_undef(int *isec1, double *undef_pds, double *undef_eps) } } } -#endif -#if defined (HAVE_LIBCGRIBEX) static void cgribexDecodeHeader(int *isec0, int *isec1, int *isec2, double *fsec2, int *isec3, double *fsec3, int *isec4, double *fsec4, - int *gribbuffer, int recsize, int *lmv) + int *gribbuffer, int recsize, int *lmv, int *iret) { - int iret = 0, ipunp = 0, iword = 0; + int ipunp = 0, iword = 0; + + memset(isec1, 0, 256*sizeof(int)); gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4, - ipunp, (int *) gribbuffer, recsize, &iword, 'J', &iret); + ipunp, (int *) gribbuffer, recsize, &iword, 'J', iret); *lmv = 0; @@ -507,14 +514,43 @@ void cgribexDecodeHeader(int *isec0, int *isec1, int *isec2, double *fsec2, *lmv = 1; } } + +static +compvar_t cgribexVarSet(int param, int level1, int level2, int leveltype) +{ + compvar_t compVar; + + compVar.param = param; + compVar.level1 = level1; + compVar.level2 = level2; + compVar.ltype = leveltype; + + return (compVar); +} + +static +int cgribexVarCompare(compvar_t compVar, record_t record) +{ + int rstatus; + compvar_t compVar0; + + compVar0.param = record.param; + compVar0.level1 = record.ilevel; + compVar0.level2 = record.ilevel2; + compVar0.ltype = record.ltype; + + rstatus = memcmp(&compVar0, &compVar, sizeof(compvar_t)); + + return (rstatus); +} #endif -int cgribexScanTimestep1(int streamID) +int cgribexScanTimestep1(stream_t * streamptr) { #if defined (HAVE_LIBCGRIBEX) int *isec0, *isec1, *isec2, *isec3, *isec4; double fsec2[512], fsec3[2], *fsec4 = NULL; - int lmv = 0; + int lmv = 0, iret = 0; off_t recpos = 0; unsigned char *gribbuffer = NULL; long buffersize = 0; @@ -527,6 +563,7 @@ int cgribexScanTimestep1(int streamID) int varID; size_t readsize; int nrecords, nrecs, recID; + int nrecs_scanned; int datatype; long recsize = 0; int warn_time = TRUE; @@ -537,15 +574,10 @@ int cgribexScanTimestep1(int streamID) int vlistID; int comptype; long unzipsize; - compvar_t compVar, compVar0; - stream_t *streamptr; + compvar_t compVar; extern int cdiSkipRecords; int nskip = cdiSkipRecords; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - streamptr->curTsID = 0; isec0 = streamptr->record->sec0; @@ -554,13 +586,13 @@ int cgribexScanTimestep1(int streamID) isec3 = streamptr->record->sec3; isec4 = streamptr->record->sec4; - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); taxis = &streamptr->tsteps[tsID].taxis; if ( tsID != 0 ) Error("Internal problem! tstepsNewEntry returns %d", tsID); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; while ( nskip-- > 0 ) { @@ -572,6 +604,7 @@ int cgribexScanTimestep1(int streamID) fileSetPos(fileID, recsize, SEEK_CUR); } + nrecs_scanned = 0; nrecs = 0; while ( TRUE ) { @@ -608,8 +641,9 @@ int cgribexScanTimestep1(int streamID) } } + nrecs_scanned++; cgribexDecodeHeader(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4, - (int *) gribbuffer, recsize, &lmv); + (int *) gribbuffer, recsize, &lmv, &iret); param = cdiEncodeParam(ISEC1_Parameter, ISEC1_CodeTable, 255); if ( ISEC1_LevelType == 100 ) ISEC1_Level1 *= 100; @@ -637,18 +671,12 @@ int cgribexScanTimestep1(int streamID) { datetime.date = vdate; datetime.time = vtime; - compVar.param = param; - compVar.level1 = level1; - compVar.level2 = level2; - compVar.ltype = ISEC1_LevelType; + + compVar = cgribexVarSet(param, level1, level2, ISEC1_LevelType); + for ( recID = 0; recID < nrecs; recID++ ) { - compVar0.param = streamptr->tsteps[0].records[recID].param; - compVar0.level1 = streamptr->tsteps[0].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[0].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[0].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar_t)) == 0 ) break; + if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID]) == 0 ) break; } if ( cdiInventoryMode == 1 ) @@ -671,7 +699,7 @@ int cgribexScanTimestep1(int streamID) { char paramstr[32]; cdiParamToString(param, paramstr, sizeof(paramstr)); - Warning("Param=%s level=%d already exist, skipped!", paramstr, level1); + Warning("Param=%s level=%d (record %d) already exist, skipped!", paramstr, level1, nrecs_scanned); continue; } } @@ -696,15 +724,15 @@ int cgribexScanTimestep1(int streamID) if ( CDI_Debug ) Message("%4d %8d %4d %8d %8d %6d", nrecs, (int)recpos, param, level1, vdate, vtime); - cgribexAddRecord(streamID, param, isec1, isec2, fsec2, fsec3, - isec4, recsize, recpos, datatype, comptype, lmv); + cgribexAddRecord(streamptr, param, isec1, isec2, fsec2, fsec3, + isec4, recsize, recpos, datatype, comptype, lmv, iret); } streamptr->rtsteps = 1; if ( nrecs == 0 ) return (CDI_EUFSTRUCT); - cdiGenVars(streamID); + cdi_generate_vars(streamptr); if ( fcast ) { @@ -724,7 +752,7 @@ int cgribexScanTimestep1(int streamID) taxis->vdate = datetime0.date; taxis->vtime = datetime0.time; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; vlistDefTaxis(vlistID, taxisID); nrecords = streamptr->tsteps[0].nallrecs; @@ -745,7 +773,7 @@ int cgribexScanTimestep1(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -772,13 +800,13 @@ int cgribexScanTimestep1(int streamID) } -int cgribexScanTimestep2(int streamID) +int cgribexScanTimestep2(stream_t * streamptr) { int rstatus = 0; #if defined (HAVE_LIBCGRIBEX) int *isec0, *isec1, *isec2, *isec3, *isec4; double fsec2[512], fsec3[2], *fsec4 = NULL; - int lmv = 0; + int lmv = 0, iret = 0; off_t recpos = 0; unsigned char *gribbuffer = NULL; long buffersize = 0; @@ -797,12 +825,7 @@ int cgribexScanTimestep2(int streamID) taxis_t *taxis; int vlistID; long unzipsize; - compvar_t compVar, compVar0; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); + compvar_t compVar; streamptr->curTsID = 1; @@ -812,8 +835,8 @@ int cgribexScanTimestep2(int streamID) isec3 = streamptr->record->sec3; isec4 = streamptr->record->sec4; - fileID = streamInqFileID(streamID); - vlistID = streamInqVlist(streamID); + fileID = streamptr->fileID; + vlistID = streamptr->vlistID; taxisID = vlistInqTaxis(vlistID); gribbuffer = (unsigned char *) streamptr->record->buffer; @@ -827,10 +850,10 @@ int cgribexScanTimestep2(int streamID) fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecords = streamptr->tsteps[tsID].nallrecs; - streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); + if ( nrecords ) streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); streamptr->tsteps[1].nrecs = 0; for ( recID = 0; recID < nrecords; recID++ ) streamptr->tsteps[1].recIDs[recID] = -1; @@ -875,7 +898,7 @@ int cgribexScanTimestep2(int streamID) } cgribexDecodeHeader(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4, - (int *) gribbuffer, recsize, &lmv); + (int *) gribbuffer, recsize, &lmv, &iret); param = cdiEncodeParam(ISEC1_Parameter, ISEC1_CodeTable, 255); if ( ISEC1_LevelType == 100 ) ISEC1_Level1 *= 100; @@ -926,18 +949,12 @@ int cgribexScanTimestep2(int streamID) datetime.date = vdate; datetime.time = vtime; - compVar.param = param; - compVar.level1 = level1; - compVar.level2 = level2; - compVar.ltype = ISEC1_LevelType; + + compVar = cgribexVarSet(param, level1, level2, ISEC1_LevelType); + for ( recID = 0; recID < nrecords; recID++ ) { - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar_t)) == 0 ) break; + if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break; } if ( recID == nrecords ) @@ -984,12 +1001,7 @@ int cgribexScanTimestep2(int streamID) streamptr->tsteps[tsID].records[recID].size = recsize; - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar_t)) != 0 ) + if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 ) { Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d", tsID, recID, @@ -1033,7 +1045,7 @@ int cgribexScanTimestep2(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1049,13 +1061,13 @@ int cgribexScanTimestep2(int streamID) } -int cgribexScanTimestep(int streamID) +int cgribexScanTimestep(stream_t * streamptr) { int rstatus = 0; #if defined (HAVE_LIBCGRIBEX) int *isec0, *isec1, *isec2, *isec3, *isec4; double fsec2[512], fsec3[2], *fsec4 = NULL; - int lmv = 0; + int lmv = 0, iret = 0; long recsize = 0; off_t recpos = 0; unsigned char *gribbuffer; @@ -1073,18 +1085,13 @@ int cgribexScanTimestep(int streamID) int vlistID; int rindex, nrecs = 0; long unzipsize; - compvar_t compVar, compVar0; - stream_t *streamptr; + compvar_t compVar; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; if ( CDI_Debug ) { - Message("streamID = %d", streamID); + Message("streamID = %d", streamptr->self); Message("cts = %d", streamptr->curTsID); Message("rts = %d", streamptr->rtsteps); Message("nts = %d", streamptr->ntsteps); @@ -1104,7 +1111,7 @@ int cgribexScanTimestep(int streamID) gribbuffer = (unsigned char *) streamptr->record->buffer; buffersize = streamptr->record->buffersize; - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecs = streamptr->tsteps[1].nrecs; @@ -1113,7 +1120,7 @@ int cgribexScanTimestep(int streamID) for ( recID = 0; recID < nrecs; recID++ ) streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID]; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); @@ -1157,7 +1164,7 @@ int cgribexScanTimestep(int streamID) } cgribexDecodeHeader(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4, - (int *) gribbuffer, recsize, &lmv); + (int *) gribbuffer, recsize, &lmv, &iret); param = cdiEncodeParam(ISEC1_Parameter, ISEC1_CodeTable, 255); if ( ISEC1_LevelType == 100 ) ISEC1_Level1 *= 100; @@ -1209,19 +1216,13 @@ int cgribexScanTimestep(int streamID) datetime.date = vdate; datetime.time = vtime; - compVar.param = param; - compVar.level1 = level1; - compVar.level2 = level2; - compVar.ltype = ISEC1_LevelType; + + compVar = cgribexVarSet(param, level1, level2, ISEC1_LevelType); + for ( vrecID = 0; vrecID < nrecs; vrecID++ ) { recID = streamptr->tsteps[1].recIDs[vrecID]; - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar_t)) == 0 ) break; + if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break; } if ( vrecID == nrecs ) @@ -1265,12 +1266,7 @@ int cgribexScanTimestep(int streamID) if ( CDI_Debug ) Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime); - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar_t)) != 0 ) + if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 ) { Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d", tsID, recID, @@ -1307,7 +1303,7 @@ int cgribexScanTimestep(int streamID) if ( streamptr->ntsteps != streamptr->rtsteps ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1422,7 +1418,6 @@ int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri return (status); } - #if defined (HAVE_LIBCGRIBEX) static void cgribexDefInstitut(int *isec1, int vlistID, int varID) @@ -1489,11 +1484,11 @@ int cgribexDefTimerange(int tsteptype, int factor, int calendar, cdiDecodeDate(rdate, &year, &month, &day); cdiDecodeTime(rtime, &hour, &minute, &second); - encode_juldaysec(calendar, year, month, day, hour, minute, &julday1, &secofday1); + encode_juldaysec(calendar, year, month, day, hour, minute, second, &julday1, &secofday1); cdiDecodeDate(vdate, &year, &month, &day); cdiDecodeTime(vtime, &hour, &minute, &second); - encode_juldaysec(calendar, year, month, day, hour, minute, &julday2, &secofday2); + encode_juldaysec(calendar, year, month, day, hour, minute, second, &julday2, &secofday2); (void) julday_sub(julday1, secofday1, julday2, secofday2, &days, &secs); @@ -1651,7 +1646,7 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) memset(isec2, 0, 16*sizeof(int)); ISEC1_Sec2Or3Flag = 128; - + gridtype = gridInqType(gridID); ISEC1_GridDefinition = 255; @@ -1773,8 +1768,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ISEC2_LastLon = NINT(xlast*1000); ISEC2_LonIncr = NINT(xinc*1000); } - if ( fabs(xinc*1000 - ISEC2_LonIncr) > FLT_EPSILON ) - ISEC2_LonIncr = 0; + + // if ( fabs(xinc*1000 - ISEC2_LonIncr) > FLT_EPSILON ) ISEC2_LonIncr = 0; if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) { @@ -1785,8 +1780,7 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) else { ISEC2_LatIncr = NINT(yinc*1000); - if ( fabs(yinc*1000 - ISEC2_LatIncr) > FLT_EPSILON ) - ISEC2_LatIncr = 0; + // if ( fabs(yinc*1000 - ISEC2_LatIncr) > FLT_EPSILON ) ISEC2_LatIncr = 0; if ( ISEC2_LatIncr < 0 ) ISEC2_LatIncr = -ISEC2_LatIncr; } @@ -1887,6 +1881,7 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) { Warning("The CGRIBEX library can not store fields on the used grid!"); Error("Unsupported grid type: %s", gridNamePtr(gridtype)); + break; } } } @@ -1923,6 +1918,27 @@ void cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int lev ISEC1_Level2 = 0; break; } + case ZAXIS_CLOUD_BASE: + { + ISEC1_LevelType = GRIB1_LTYPE_CLOUDBASE; + ISEC1_Level1 = 0; + ISEC1_Level2 = 0; + break; + } + case ZAXIS_CLOUD_TOP: + { + ISEC1_LevelType = GRIB1_LTYPE_CLOUDTOP; + ISEC1_Level1 = 0; + ISEC1_Level2 = 0; + break; + } + case ZAXIS_ISOTHERM_ZERO: + { + ISEC1_LevelType = GRIB1_LTYPE_ISOTHERM0; + ISEC1_Level1 = 0; + ISEC1_Level2 = 0; + break; + } case ZAXIS_TOA: { ISEC1_LevelType = GRIB1_LTYPE_TOA; @@ -2165,9 +2181,6 @@ void cgribexDefaultSec4(int *isec4) static void cgribexDefEnsembleVar(int *isec1, int vlistID, int varID) { - - /* int *ensID, int *ensCount, int *forecast_type; */ - int ensID, ensCount, forecast_type; /* For Ensemble info */ @@ -2178,29 +2191,24 @@ void cgribexDefEnsembleVar(int *isec1, int vlistID, int varID) //Put2Byte(isec1[38]); /* individual ensemble member */ //Put2Byte(isec1[39]); /* number of forecasts in ensemble */ - if( !vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) ) + if ( vlistInqVarEnsemble(vlistID, varID, &ensID, &ensCount, &forecast_type) ) { - ISEC1_LocalFLag = 1; - isec1[36] = 1; - - isec1[37] = forecast_type; - isec1[38] = ensID; - isec1[39] = ensCount; - -#ifdef DBG - if( DBG ) - { - fprintf( stderr, "cgribexDefEnsembleVar :\n EnsID %d\n Enscount %d\n Forecast init type %d\n", ensID, - ensCount, forecast_type ); - } -#endif + if ( ISEC1_CenterID == 252 ) + { + ISEC1_LocalFLag = 1; + isec1[36] = 1; + + isec1[37] = forecast_type; + isec1[38] = ensID; + isec1[39] = ensCount; + } } } #endif size_t cgribexEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID, - int vdate, int vtime, int tsteptype, int numavg, + int vdate, int vtime, int tsteptype, int numavg, long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize) { size_t nbytes = 0; @@ -2212,7 +2220,7 @@ size_t cgribexEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI int datatype; int param; - memset(isec1, 0, 32*sizeof(int)); + memset(isec1, 0, 256*sizeof(int)); fsec2[0] = 0; fsec2[1] = 0; gribsize = gribbuffersize / sizeof(int); diff --git a/src/stream_cgribex.h b/src/stream_cgribex.h index de320c1ac..8a8ae79e4 100644 --- a/src/stream_cgribex.h +++ b/src/stream_cgribex.h @@ -1,9 +1,9 @@ #ifndef _STREAM_CGRIBEX_H #define _STREAM_CGRIBEX_H -int cgribexScanTimestep1(int streamID); -int cgribexScanTimestep2(int streamID); -int cgribexScanTimestep(int streamID); +int cgribexScanTimestep1(stream_t * streamptr); +int cgribexScanTimestep2(stream_t * streamptr); +int cgribexScanTimestep(stream_t * streamptr); int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize, int unreduced, int *nmiss, int *zip, double missval); diff --git a/src/stream_ext.c b/src/stream_ext.c index 5aaed13d2..d6c3cbe92 100644 --- a/src/stream_ext.c +++ b/src/stream_ext.c @@ -29,7 +29,7 @@ typedef struct { int param; int level; -} extcompvar_t; +} extcompvar_t; static int extInqDatatype(int prec, int number) @@ -70,7 +70,7 @@ void extDefDatatype(int datatype, int *prec, int *number) } /* not used -int extInqRecord(int streamID, int *varID, int *levelID) +int extInqRecord(stream_t *streamptr, int *varID, int *levelID) { int status; int fileID; @@ -79,14 +79,9 @@ int extInqRecord(int streamID, int *varID, int *levelID) int header[4]; int vlistID; extrec_t *extp; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; extp = streamptr->record->extp; *varID = -1; @@ -107,12 +102,12 @@ int extInqRecord(int streamID, int *varID, int *levelID) zaxisID = vlistInqVarZaxis(vlistID, *varID); *levelID = zaxisInqLevelID(zaxisID, (double) ilevel); - + return (1); } */ -int extReadRecord(int streamID, double *data, int *nmiss) +int extReadRecord(stream_t *streamptr, double *data, int *nmiss) { int vlistID, fileID; int status; @@ -123,14 +118,9 @@ int extReadRecord(int streamID, double *data, int *nmiss) int i, size; double missval; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; vrecID = streamptr->tsteps[tsID].curRecID; recID = streamptr->tsteps[tsID].recIDs[vrecID]; @@ -176,7 +166,7 @@ int extReadRecord(int streamID, double *data, int *nmiss) } -int extCopyRecord(int streamID2, int streamID1) +int extCopyRecord(stream_t *streamptr2, stream_t *streamptr1) { int fileID1, fileID2; int tsID, recID, vrecID; @@ -184,17 +174,9 @@ int extCopyRecord(int streamID2, int streamID1) off_t recpos; int status = 0; char *buffer; - stream_t *streamptr1; - stream_t *streamptr2; - streamptr1 = stream_to_pointer(streamID1); - streamptr2 = stream_to_pointer(streamID2); - - stream_check_ptr(__func__, streamptr1); - stream_check_ptr(__func__, streamptr2); - - fileID1 = streamInqFileID(streamID1); - fileID2 = streamInqFileID(streamID2); + fileID1 = streamptr1->fileID; + fileID2 = streamptr2->fileID; tsID = streamptr1->curTsID; vrecID = streamptr1->tsteps[tsID].curRecID; @@ -216,18 +198,13 @@ int extCopyRecord(int streamID2, int streamID1) } -int extDefRecord(int streamID) +int extDefRecord(stream_t *streamptr) { int gridID; int header[4]; int status = 0; int pdis, pcat, pnum; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); gridID = streamptr->record->gridID; extp = streamptr->record->extp; @@ -246,18 +223,13 @@ int extDefRecord(int streamID) } -int extWriteRecord(int streamID, const double *data) +int extWriteRecord(stream_t *streamptr, const double *data) { int fileID; int status = 0; extrec_t *extp; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; extp = streamptr->record->extp; extDefDataDP(extp, data); @@ -268,7 +240,7 @@ int extWriteRecord(int streamID, const double *data) } static -void extAddRecord(int streamID, int param, int level, int xysize, +void extAddRecord(stream_t *streamptr, int param, int level, int xysize, long recsize, off_t position, int prec, int number) { int leveltype; @@ -278,13 +250,10 @@ void extAddRecord(int streamID, int param, int level, int xysize, record_t *record; grid_t grid; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; tsID = streamptr->curTsID; - recID = recordNewEntry(streamID, tsID); + recID = recordNewEntry(streamptr, tsID); record = &streamptr->tsteps[tsID].records[recID]; (*record).size = recsize; @@ -306,7 +275,7 @@ void extAddRecord(int streamID, int param, int level, int xysize, */ leveltype = ZAXIS_GENERIC; - varAddRecord(recID, param, gridID, leveltype, 0, level, 0, + varAddRecord(recID, param, gridID, leveltype, 0, level, 0, 0, extInqDatatype(prec, number), &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL); (*record).varID = varID; @@ -321,15 +290,12 @@ void extAddRecord(int streamID, int param, int level, int xysize, } -void extCmpRecord(int streamID, int tsID, int recID, off_t position, int param, +void extCmpRecord(stream_t *streamptr, int tsID, int recID, off_t position, int param, int level, int xysize) { int varID = 0; int levelID = 0; record_t *record; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); record = &streamptr->tsteps[tsID].records[recID]; @@ -351,8 +317,8 @@ void extCmpRecord(int streamID, int tsID, int recID, off_t position, int param, } static -void extScanTimestep1(int streamID) -{ +void extScanTimestep1(stream_t *streamptr) +{ int header[4]; int status; int fileID; @@ -370,22 +336,17 @@ void extScanTimestep1(int streamID) int vlistID; extcompvar_t compVar, compVar0; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); streamptr->curTsID = 0; extp = streamptr->record->extp; - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); taxis = &streamptr->tsteps[tsID].taxis; if ( tsID != 0 ) Error("Internal problem! tstepsNewEntry returns %d", tsID); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; nrecs = 0; while ( TRUE ) @@ -437,22 +398,22 @@ void extScanTimestep1(int streamID) if ( CDI_Debug ) Message("%4d%8d%4d%8d%8d%6d", nrecs, (int)recpos, rcode, rlevel, vdate, vtime); - extAddRecord(streamID, param, rlevel, rxysize, recsize, recpos, extp->prec, extp->number); + extAddRecord(streamptr, param, rlevel, rxysize, recsize, recpos, extp->prec, extp->number); } streamptr->rtsteps = 1; - cdiGenVars(streamID); + cdi_generate_vars(streamptr); taxisID = taxisCreate(TAXIS_ABSOLUTE); taxis->type = TAXIS_ABSOLUTE; taxis->vdate = datetime0.date; taxis->vtime = datetime0.time; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; vlistDefTaxis(vlistID, taxisID); - cdiCheckContents(streamID); + vlist_check_contents(vlistID); nrecords = streamptr->tsteps[0].nallrecs; if ( nrecords < streamptr->tsteps[0].recordSize ) @@ -469,7 +430,7 @@ void extScanTimestep1(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -491,12 +452,12 @@ void extScanTimestep1(int streamID) } static -int extScanTimestep2(int streamID) -{ +int extScanTimestep2(stream_t *streamptr) +{ int header[4]; int status; int fileID; - /* int rxysize = 0; */ + // int rxysize = 0; int param = 0; int rcode = 0, rlevel = 0, vdate = 0, vtime = 0; int tsID; @@ -509,16 +470,11 @@ int extScanTimestep2(int streamID) int vlistID; extcompvar_t compVar, compVar0; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); streamptr->curTsID = 1; - fileID = streamInqFileID(streamID); - vlistID = streamInqVlist(streamID); + fileID = streamptr->fileID; + vlistID = streamptr->vlistID; extp = streamptr->record->extp; tsID = streamptr->rtsteps; @@ -529,7 +485,7 @@ int extScanTimestep2(int streamID) fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecords = streamptr->tsteps[0].nallrecs; streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); @@ -540,9 +496,9 @@ int extScanTimestep2(int streamID) for ( recID = 0; recID < nrecords; recID++ ) { varID = streamptr->tsteps[0].records[recID].varID; - streamptr->tsteps[tsID].records[recID].position = + streamptr->tsteps[tsID].records[recID].position = streamptr->tsteps[0].records[recID].position; - streamptr->tsteps[tsID].records[recID].size = + streamptr->tsteps[tsID].records[recID].size = streamptr->tsteps[0].records[recID].size; } @@ -563,7 +519,7 @@ int extScanTimestep2(int streamID) vtime = 0; rcode = header[1]; rlevel = header[2]; - /* rxysize = header[3]; */ + // rxysize = header[3]; param = cdiEncodeParam(rcode, 255, 255); @@ -643,7 +599,7 @@ int extScanTimestep2(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -655,23 +611,18 @@ int extScanTimestep2(int streamID) } -int extInqContents(int streamID) +int extInqContents(stream_t *streamptr) { int fileID; int status = 0; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; streamptr->curTsID = 0; - extScanTimestep1(streamID); - - if ( streamptr->ntsteps == -1 ) status = extScanTimestep2(streamID); + extScanTimestep1(streamptr); + + if ( streamptr->ntsteps == -1 ) status = extScanTimestep2(streamptr); fileSetPos(fileID, 0, SEEK_SET); @@ -679,13 +630,13 @@ int extInqContents(int streamID) } static -int extScanTimestep(int streamID) +int extScanTimestep(stream_t *streamptr) { int header[4]; int status; int fileID; int tsID; - /* int rxysize = 0; */ + // int rxysize = 0; int param = 0; int rcode = 0, rlevel = 0, vdate = 0, vtime = 0; long recsize = 0; @@ -695,15 +646,10 @@ int extScanTimestep(int streamID) int rindex, nrecs = 0; extcompvar_t compVar, compVar0; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( CDI_Debug ) { - Message("streamID = %d", streamID); + Message("streamID = %d", streamptr->self); Message("cts = %d", streamptr->curTsID); Message("rts = %d", streamptr->rtsteps); Message("nts = %d", streamptr->ntsteps); @@ -718,7 +664,7 @@ int extScanTimestep(int streamID) if ( streamptr->tsteps[tsID].recordSize == 0 ) { - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecs = streamptr->tsteps[1].nrecs; @@ -727,7 +673,7 @@ int extScanTimestep(int streamID) for ( recID = 0; recID < nrecs; recID++ ) streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID]; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); @@ -748,7 +694,7 @@ int extScanTimestep(int streamID) vtime = 0; rcode = header[1]; rlevel = header[2]; - /* rxysize = header[3]; */ + // rxysize = header[3]; param = cdiEncodeParam(rcode, 255, 255); @@ -763,7 +709,7 @@ int extScanTimestep(int streamID) taxis->vtime = vtime; } /* - extCmpRecord(streamID, tsID, nrecs, recpos, param, rlevel, rxysize); + extCmpRecord(streamptr, tsID, nrecs, recpos, param, rlevel, rxysize); */ compVar.param = param; compVar.level = rlevel; @@ -790,7 +736,7 @@ int extScanTimestep(int streamID) if ( streamptr->ntsteps != streamptr->rtsteps ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -812,24 +758,19 @@ int extScanTimestep(int streamID) } -int extInqTimestep(int streamID, int tsID) +int extInqTimestep(stream_t *streamptr, int tsID) { int ntsteps, nrecs; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( tsID == 0 && streamptr->rtsteps == 0 ) Error("Call to cdiInqContents missing!"); if ( CDI_Debug ) Message("tsID = %d rtsteps = %d", tsID, streamptr->rtsteps); - + ntsteps = UNDEFID; while ( ( tsID + 1 ) > streamptr->rtsteps && ntsteps == UNDEFID ) - ntsteps = extScanTimestep(streamID); + ntsteps = extScanTimestep(streamptr); if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID ) { @@ -845,7 +786,7 @@ int extInqTimestep(int streamID, int tsID) } -void extReadVarDP(int streamID, int varID, double *data, int *nmiss) +void extReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss) { int vlistID, fileID; int levID, nlevs, gridID, gridsize; @@ -854,16 +795,12 @@ void extReadVarDP(int streamID, int varID, double *data, int *nmiss) int tsid; int recID; int i; - int status; double missval; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); extp = streamptr->record->extp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; nlevs = streamptr->vars[varID].nlevs; missval = vlistInqVarMissval(vlistID, varID); gridID = vlistInqVarGrid(vlistID, varID); @@ -880,8 +817,7 @@ void extReadVarDP(int streamID, int varID, double *data, int *nmiss) recID = streamptr->vars[varID].level[levID]; recpos = streamptr->tsteps[tsid].records[recID].position; fileSetPos(fileID, recpos, SEEK_SET); - /* FIXME: result of operation is ignored */ - status = extRead(fileID, extp); + extRead(fileID, extp); extInqHeader(extp, header); extInqDataDP(extp, &data[levID*gridsize]); } @@ -909,7 +845,7 @@ void extReadVarDP(int streamID, int varID, double *data, int *nmiss) } -void extReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nmiss) +void extReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data, int *nmiss) { int vlistID, fileID; int nlevs, gridID, gridsize; @@ -918,16 +854,12 @@ void extReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm int tsid; int recID; int i; - int status; double missval; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); extp = streamptr->record->extp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; nlevs = streamptr->vars[varID].nlevs; missval = vlistInqVarMissval(vlistID, varID); gridID = vlistInqVarGrid(vlistID, varID); @@ -943,8 +875,7 @@ void extReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm recID = streamptr->vars[varID].level[levID]; recpos = streamptr->tsteps[tsid].records[recID].position; fileSetPos(fileID, recpos, SEEK_SET); - /* FIXME: result of operation is ignored */ - status = extRead(fileID, extp); + extRead(fileID, extp); extInqHeader(extp, header); extInqDataDP(extp, data); @@ -972,7 +903,7 @@ void extReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm } -void extWriteVarDP(int streamID, int varID, const double *data) +void extWriteVarDP(stream_t *streamptr, int varID, const double *data) { int fileID; int levID, nlevs, gridID, gridsize; @@ -983,16 +914,12 @@ void extWriteVarDP(int streamID, int varID, const double *data) int vlistID; int pdis, pcat, pnum; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); + if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID); extp = streamptr->record->extp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; gridID = vlistInqVarGrid(vlistID, varID); gridsize = gridInqSize(gridID); @@ -1022,7 +949,7 @@ void extWriteVarDP(int streamID, int varID, const double *data) } -void extWriteVarSliceDP(int streamID, int varID, int levID, const double *data) +void extWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double *data) { int fileID; int gridID; @@ -1033,13 +960,10 @@ void extWriteVarSliceDP(int streamID, int varID, int levID, const double *data) int vlistID; int pdis, pcat, pnum; extrec_t *extp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); extp = streamptr->record->extp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); diff --git a/src/stream_ext.h b/src/stream_ext.h index 90daf791e..4fe4918fa 100644 --- a/src/stream_ext.h +++ b/src/stream_ext.h @@ -5,20 +5,20 @@ # include "extra.h" #endif -int extInqContents(int streamID); -int extInqTimestep(int streamID, int tsID); +int extInqContents(stream_t *streamptr); +int extInqTimestep(stream_t *streamptr, int tsID); -int extInqRecord(int streamID, int *varID, int *levelID); -int extDefRecord(int streamID); -int extCopyRecord(int streamIDdest, int streamIDsrc); -int extReadRecord(int streamID, double *data, int *nmiss); -int extWriteRecord(int streamID, const double *data); +int extInqRecord(stream_t *streamptr, int *varID, int *levelID); +int extDefRecord(stream_t *streamptr); +int extCopyRecord(stream_t *streamptr2, stream_t *streamptr1); +int extReadRecord(stream_t *streamptr, double *data, int *nmiss); +int extWriteRecord(stream_t *streamptr, const double *data); -void extReadVarDP (int streamID, int varID, double *data, int *nmiss); -void extWriteVarDP(int streamID, int varID, const double *data); +void extReadVarDP (stream_t *streamptr, int varID, double *data, int *nmiss); +void extWriteVarDP(stream_t *streamptr, int varID, const double *data); -void extReadVarSliceDP (int streamID, int varID, int levelID, double *data, int *nmiss); -void extWriteVarSliceDP(int streamID, int varID, int levelID, const double *data); +void extReadVarSliceDP (stream_t *streamptr, int varID, int levelID, double *data, int *nmiss); +void extWriteVarSliceDP(stream_t *streamptr, int varID, int levelID, const double *data); #endif /* _STREAM_EXT_H */ /* diff --git a/src/stream_grb.c b/src/stream_grb.c index b403ebd3e..0323a490d 100644 --- a/src/stream_grb.c +++ b/src/stream_grb.c @@ -14,12 +14,10 @@ #include "cgribex.h" /* gribZip gribGetZip gribGinfo */ #include "gribapi.h" -/* begin deike */ #ifdef USE_MPI #include "pio.h" #include "pio_comm.h" #endif -/* end deike */ int grib1ltypeToZaxisType(int grib_ltype) @@ -28,23 +26,26 @@ int grib1ltypeToZaxisType(int grib_ltype) switch ( grib_ltype ) { - case GRIB1_LTYPE_SURFACE: { zaxistype = ZAXIS_SURFACE; break; } - case GRIB1_LTYPE_TOA: { zaxistype = ZAXIS_TOA; break; } - case GRIB1_LTYPE_SEA_BOTTOM: { zaxistype = ZAXIS_SEA_BOTTOM; break; } - case GRIB1_LTYPE_ATMOSPHERE: { zaxistype = ZAXIS_ATMOSPHERE; break; } - case GRIB1_LTYPE_MEANSEA: { zaxistype = ZAXIS_MEANSEA; break; } + case GRIB1_LTYPE_SURFACE: { zaxistype = ZAXIS_SURFACE; break; } + case GRIB1_LTYPE_CLOUDBASE: { zaxistype = ZAXIS_CLOUD_BASE; break; } + case GRIB1_LTYPE_CLOUDTOP: { zaxistype = ZAXIS_CLOUD_TOP; break; } + case GRIB1_LTYPE_ISOTHERM0: { zaxistype = ZAXIS_ISOTHERM_ZERO; break; } + case GRIB1_LTYPE_TOA: { zaxistype = ZAXIS_TOA; break; } + case GRIB1_LTYPE_SEA_BOTTOM: { zaxistype = ZAXIS_SEA_BOTTOM; break; } + case GRIB1_LTYPE_ATMOSPHERE: { zaxistype = ZAXIS_ATMOSPHERE; break; } + case GRIB1_LTYPE_MEANSEA: { zaxistype = ZAXIS_MEANSEA; break; } case GRIB1_LTYPE_99: - case GRIB1_LTYPE_ISOBARIC: { zaxistype = ZAXIS_PRESSURE; break; } - case GRIB1_LTYPE_HEIGHT: { zaxistype = ZAXIS_HEIGHT; break; } - case GRIB1_LTYPE_ALTITUDE: { zaxistype = ZAXIS_ALTITUDE; break; } + case GRIB1_LTYPE_ISOBARIC: { zaxistype = ZAXIS_PRESSURE; break; } + case GRIB1_LTYPE_HEIGHT: { zaxistype = ZAXIS_HEIGHT; break; } + case GRIB1_LTYPE_ALTITUDE: { zaxistype = ZAXIS_ALTITUDE; break; } case GRIB1_LTYPE_SIGMA: - case GRIB1_LTYPE_SIGMA_LAYER: { zaxistype = ZAXIS_SIGMA; break; } + case GRIB1_LTYPE_SIGMA_LAYER: { zaxistype = ZAXIS_SIGMA; break; } case GRIB1_LTYPE_HYBRID: - case GRIB1_LTYPE_HYBRID_LAYER: { zaxistype = ZAXIS_HYBRID; break; } + case GRIB1_LTYPE_HYBRID_LAYER: { zaxistype = ZAXIS_HYBRID; break; } case GRIB1_LTYPE_LANDDEPTH: - case GRIB1_LTYPE_LANDDEPTH_LAYER: { zaxistype = ZAXIS_DEPTH_BELOW_LAND; break; } - case GRIB1_LTYPE_ISENTROPIC: { zaxistype = ZAXIS_ISENTROPIC; break; } - case GRIB1_LTYPE_SEADEPTH: { zaxistype = ZAXIS_DEPTH_BELOW_SEA; break; } + case GRIB1_LTYPE_LANDDEPTH_LAYER: { zaxistype = ZAXIS_DEPTH_BELOW_LAND; break; } + case GRIB1_LTYPE_ISENTROPIC: { zaxistype = ZAXIS_ISENTROPIC; break; } + case GRIB1_LTYPE_SEADEPTH: { zaxistype = ZAXIS_DEPTH_BELOW_SEA; break; } } return (zaxistype); @@ -58,6 +59,9 @@ int grib2ltypeToZaxisType(int grib_ltype) switch ( grib_ltype ) { case GRIB2_LTYPE_SURFACE: { zaxistype = ZAXIS_SURFACE; break; } + case GRIB2_LTYPE_CLOUDBASE: { zaxistype = ZAXIS_CLOUD_BASE; break; } + case GRIB2_LTYPE_CLOUDTOP: { zaxistype = ZAXIS_CLOUD_TOP; break; } + case GRIB2_LTYPE_ISOTHERM0: { zaxistype = ZAXIS_ISOTHERM_ZERO; break; } case GRIB2_LTYPE_TOA: { zaxistype = ZAXIS_TOA; break; } case GRIB2_LTYPE_SEA_BOTTOM: { zaxistype = ZAXIS_SEA_BOTTOM; break; } case GRIB2_LTYPE_ATMOSPHERE: { zaxistype = ZAXIS_ATMOSPHERE; break; } @@ -100,24 +104,19 @@ int grbBitsPerValue(int datatype) /* -int grbInqRecord(int streamID, int *varID, int *levelID) +int grbInqRecord(stream_t * streamptr, int *varID, int *levelID) { int status; - status = cgribexInqRecord(streamID, varID, levelID); + status = cgribexInqRecord(streamptr, varID, levelID); return (status); } */ -int grbDefRecord(int streamID) +int grbDefRecord(stream_t * streamptr) { int status = 0; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); return (status); } @@ -134,12 +133,12 @@ int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *dat else #endif status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip, missval); - + return (status); } -int grbReadRecord(int streamID, double *data, int *nmiss) +int grbReadRecord(stream_t * streamptr, double *data, int *nmiss) { int status = 0; unsigned char *gribbuffer; @@ -152,18 +151,13 @@ int grbReadRecord(int streamID, double *data, int *nmiss) int zip; int filetype; double missval; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); filetype = streamptr->filetype; gribbuffer = (unsigned char *) streamptr->record->buffer; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; vrecID = streamptr->tsteps[tsID].curRecID; recID = streamptr->tsteps[tsID].recIDs[vrecID]; @@ -190,95 +184,84 @@ int grbReadRecord(int streamID, double *data, int *nmiss) } static -int grbScanTimestep1(int streamID) +int grbScanTimestep1(stream_t * streamptr) { int status; int filetype; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); filetype = streamptr->filetype; #if defined (HAVE_LIBCGRIBEX) if ( filetype == FILETYPE_GRB ) { - status = cgribexScanTimestep1(streamID); + status = cgribexScanTimestep1(streamptr); } else #endif { - status = gribapiScanTimestep1(streamID); + status = gribapiScanTimestep1(streamptr); } return (status); } static -int grbScanTimestep2(int streamID) +int grbScanTimestep2(stream_t * streamptr) { int status; int filetype; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); filetype = streamptr->filetype; #if defined (HAVE_LIBCGRIBEX) if ( filetype == FILETYPE_GRB ) { - status = cgribexScanTimestep2(streamID); + status = cgribexScanTimestep2(streamptr); } else #endif { - status = gribapiScanTimestep2(streamID); + status = gribapiScanTimestep2(streamptr); } return (status); } static -int grbScanTimestep(int streamID) +int grbScanTimestep(stream_t * streamptr) { int status; int filetype; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); filetype = streamptr->filetype; #if defined (HAVE_LIBCGRIBEX) if ( filetype == FILETYPE_GRB ) { - status = cgribexScanTimestep(streamID); + status = cgribexScanTimestep(streamptr); } else #endif { - status = gribapiScanTimestep(streamID); + status = gribapiScanTimestep(streamptr); } return (status); } -int grbInqContents(int streamID) +int grbInqContents(stream_t * streamptr) { int fileID; int status = 0; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; streamptr->curTsID = 0; - status = grbScanTimestep1(streamID); - - if ( status == 0 && streamptr->ntsteps == -1 ) status = grbScanTimestep2(streamID); + status = grbScanTimestep1(streamptr); + + if ( status == 0 && streamptr->ntsteps == -1 ) status = grbScanTimestep2(streamptr); fileSetPos(fileID, 0, SEEK_SET); @@ -286,25 +269,20 @@ int grbInqContents(int streamID) } -int grbInqTimestep(int streamID, int tsID) +int grbInqTimestep(stream_t * streamptr, int tsID) { int ntsteps, nrecs; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( tsID == 0 && streamptr->rtsteps == 0 ) Error("Call to cdiInqContents missing!"); if ( CDI_Debug ) Message("tsid = %d rtsteps = %d", tsID, streamptr->rtsteps); - + ntsteps = CDI_UNDEFID; while ( (tsID + 1) > streamptr->rtsteps && ntsteps == CDI_UNDEFID ) { - ntsteps = grbScanTimestep(streamID); + ntsteps = grbScanTimestep(streamptr); if ( ntsteps == CDI_EUFSTRUCT ) { streamptr->ntsteps = streamptr->rtsteps; @@ -326,7 +304,7 @@ int grbInqTimestep(int streamID, int tsID) } -void grbReadVarDP(int streamID, int varID, double *data, int *nmiss) +void grbReadVarDP(stream_t * streamptr, int varID, double *data, int *nmiss) { int fileID; int levelID, nlevs, gridID, gridsize; @@ -339,18 +317,13 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss) int zip; int filetype; double missval; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); filetype = streamptr->filetype; gribbuffer = (unsigned char *) streamptr->record->buffer; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; nlevs = streamptr->vars[varID].nlevs; @@ -375,7 +348,7 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss) missval = vlistInqVarMissval(vlistID, varID); - grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize, + grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize, streamptr->unreduced, &imiss, &zip, missval); *nmiss += imiss; @@ -387,7 +360,7 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss) } -void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss) +void grbReadVarSliceDP(stream_t * streamptr, int varID, int levelID, double *data, int *nmiss) { int fileID; int gridID, gridsize; @@ -399,17 +372,12 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int * int zip; int filetype; double missval; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); filetype = streamptr->filetype; gribbuffer = (unsigned char *) streamptr->record->buffer; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; gridID = vlistInqVarGrid(vlistID, varID); gridsize = gridInqSize(gridID); tsID = streamptr->curTsID; @@ -417,7 +385,7 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int * if ( CDI_Debug ) Message("gridID = %d gridsize = %d", gridID, gridsize); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; currentfilepos = fileGetPos(fileID); @@ -444,7 +412,7 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int * static size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID, int zaxisID, - int date, int time, int tsteptype, int numavg, + int date, int time, int tsteptype, int numavg, long datasize, const double *data, int nmiss, unsigned char **gribbuffer, int ljpeg, void *gribContainer) { @@ -458,14 +426,14 @@ size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID, *gribbuffer = (unsigned char *) malloc(gribbuffersize); nbytes = cgribexEncode(varID, levelID, vlistID, gridID, zaxisID, - date, time, tsteptype, numavg, + date, time, tsteptype, numavg, datasize, data, nmiss, *gribbuffer, gribbuffersize); } else #endif { nbytes = gribapiEncode(varID, levelID, vlistID, gridID, zaxisID, - date, time, tsteptype, numavg, + date, time, tsteptype, numavg, datasize, data, nmiss, gribbuffer, &gribbuffersize, ljpeg, gribContainer); } @@ -485,7 +453,7 @@ size_t grbSzip(int filetype, unsigned char *gribbuffer, size_t gribbuffersize) buffer = (unsigned char *) malloc(buffersize); /* memcpy(buffer, gribbuffer, gribbuffersize); */ - + if ( filetype == FILETYPE_GRB ) { nbytes = gribZip(gribbuffer, (long) gribbuffersize, buffer, (long) buffersize); @@ -496,14 +464,14 @@ size_t grbSzip(int filetype, unsigned char *gribbuffer, size_t gribbuffersize) lszip_warn = 0; nbytes = gribbuffersize; } - + free(buffer); return (nbytes); } -int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data, int nmiss) +int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, const void *data, int nmiss) { size_t nwrite; int fileID; @@ -518,19 +486,15 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data, int numavg = 0; size_t nbytes; int filetype; - stream_t *streamptr; int ljpeg = 0; int ljpeg_warn = 1; void *gc = NULL; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); + if ( memtype == MEMTYPE_FLOAT ) Error("cdf_write_var_slice not implemented for memtype float!"); filetype = streamptr->filetype; - - fileID = streamInqFileID(streamID); - vlistID = streamInqVlist(streamID); + fileID = streamptr->fileID; + vlistID = streamptr->vlistID; gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); tsteptype = vlistInqVarTsteptype(vlistID, varID); @@ -556,8 +520,13 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data, else #endif { +#if defined (GRIBCONTAINER2D) + gribContainer_t **gribContainers = (gribContainer_t **) streamptr->gribContainers; + gc = (void *) &gribContainers[varID][levelID]; +#else gribContainer_t *gribContainers = (gribContainer_t *) streamptr->gribContainers; gc = (void *) &gribContainers[varID]; +#endif } if ( streamptr->comptype == COMPRESS_JPEG ) @@ -596,12 +565,12 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data, } -void grbWriteVarDP(int streamID, int varID, const double *data, int nmiss) +void grb_write_var(stream_t *streamptr, int varID, int memtype, const void *data, int nmiss) { int vlistID, gridID, zaxisID, levelID, nlevs; int gridsize; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; gridID = vlistInqVarGrid(vlistID, varID); gridsize = gridInqSize(gridID); zaxisID = vlistInqVarZaxis(vlistID, varID); @@ -609,12 +578,15 @@ void grbWriteVarDP(int streamID, int varID, const double *data, int nmiss) for ( levelID = 0; levelID < nlevs; levelID++ ) { - grbWriteVarSliceDP(streamID, varID, levelID, data+levelID*gridsize, nmiss); + if ( memtype == MEMTYPE_FLOAT ) + grb_write_var_slice(streamptr, varID, levelID, memtype, ((float*)data)+levelID*gridsize, nmiss); + else + grb_write_var_slice(streamptr, varID, levelID, memtype, ((double*)data)+levelID*gridsize, nmiss); } } -int grbCopyRecord(int streamID2, int streamID1) +int grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1) { int fileID1, fileID2; int tsID, recID, vrecID; @@ -627,19 +599,11 @@ int grbCopyRecord(int streamID2, int streamID1) size_t nbytes; long unzipsize; int izip; - stream_t *streamptr1; - stream_t *streamptr2; - - streamptr1 = stream_to_pointer(streamID1); - streamptr2 = stream_to_pointer(streamID2); - - stream_check_ptr(__func__, streamptr1); - stream_check_ptr(__func__, streamptr2); filetype = streamptr1->filetype; - fileID1 = streamInqFileID(streamID1); - fileID2 = streamInqFileID(streamID2); + fileID1 = streamptr1->fileID; + fileID2 = streamptr2->fileID; tsID = streamptr1->curTsID; vrecID = streamptr1->tsteps[tsID].curRecID; @@ -658,7 +622,7 @@ int grbCopyRecord(int streamID2, int streamID1) nbytes = recsize; izip = gribGetZip(recsize, gribbuffer, &unzipsize); - + if ( izip == 0 ) if ( streamptr2->comptype == COMPRESS_SZIP ) nbytes = grbSzip(filetype, gribbuffer, nbytes); @@ -674,20 +638,15 @@ int grbCopyRecord(int streamID2, int streamID1) } -int grbWriteRecord(int streamID, const double *data, int nmiss) +int grb_write_record(stream_t * streamptr, int memtype, const void *data, int nmiss) { int status = 0; int varID, levelID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); varID = streamptr->record->varID; levelID = streamptr->record->levelID; - status = grbWriteVarSliceDP(streamID, varID, levelID, data, nmiss); + status = grb_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss); return (status); } diff --git a/src/stream_grb.h b/src/stream_grb.h index 1d7e3fb36..1430b6853 100644 --- a/src/stream_grb.h +++ b/src/stream_grb.h @@ -3,20 +3,20 @@ int grbBitsPerValue(int datatype); -int grbInqContents(int streamID); -int grbInqTimestep(int streamID, int tsID); +int grbInqContents(stream_t * streamptr); +int grbInqTimestep(stream_t * streamptr, int tsID); -int grbInqRecord(int streamID, int *varID, int *levelID); -int grbDefRecord(int streamID); -int grbWriteRecord(int streamID, const double *data, int nmiss); -int grbReadRecord(int streamID, double *data, int *nmiss); -int grbCopyRecord(int streamIDdest, int streamIDsrc); +int grbInqRecord(stream_t * streamptr, int *varID, int *levelID); +int grbDefRecord(stream_t * streamptr); +int grb_write_record(stream_t * streamptr, int memtype, const void *data, int nmiss); +int grbReadRecord(stream_t * streamptr, double *data, int *nmiss); +int grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1); -void grbReadVarDP(int streamID, int varID, double *data, int *nmiss); -void grbWriteVarDP(int streamID, int varID, const double *data, int nmiss); +void grbReadVarDP(stream_t * streamptr, int varID, double *data, int *nmiss); +void grb_write_var(stream_t * streamptr, int varID, int memtype, const void *data, int nmiss); -void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss); -int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data, int nmiss); +void grbReadVarSliceDP(stream_t * streamptr, int varID, int levelID, double *data, int *nmiss); +int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, const void *data, int nmiss); int grib1ltypeToZaxisType(int grib_ltype); int grib2ltypeToZaxisType(int grib_ltype); diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c index d817e7c77..2cf4ef00b 100644 --- a/src/stream_gribapi.c +++ b/src/stream_gribapi.c @@ -21,6 +21,7 @@ # include "grib_api.h" #endif +#define NINT(x) ((x) < 0 ? (int)((x)-.5) : (int)((x)+.5)) extern int cdiInventoryMode; @@ -29,7 +30,8 @@ typedef struct { int level1; int level2; int ltype; -} compvar2_t; + char name[32]; +} compvar2_t; #if defined (HAVE_LIBGRIB_API) @@ -37,12 +39,14 @@ static int gribapiGetGridType(grib_handle *gh) { int gridtype = GRID_GENERIC; - int gribgridtype; + int gribgridtype = -1; long lpar; { - GRIB_CHECK(grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar), 0); - gribgridtype = (int) lpar; + int status; + status = grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar); + + if ( status == 0 ) gribgridtype = (int) lpar; switch (gribgridtype) { @@ -66,28 +70,24 @@ int gribapiGetGridType(grib_handle *gh) return (gridtype); } -#endif -#if defined (HAVE_LIBGRIB_API) static int gribapiGetIsRotated(grib_handle *gh) { int isRotated = 0; - int gribgridtype; + int gribgridtype = -1; long lpar; + int status; - { - GRIB_CHECK(grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar), 0); - gribgridtype = (int) lpar; + status = grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar); - if ( gribgridtype == GRIB2_GTYPE_LATLON_ROT ) isRotated = 1; - } + if ( status == 0 ) gribgridtype = (int) lpar; + + if ( gribgridtype == GRIB2_GTYPE_LATLON_ROT ) isRotated = 1; return (isRotated); } -#endif -#if defined (HAVE_LIBGRIB_API) static int gribapiGetZaxisType(long editionNumber, int grib_ltype) { @@ -104,20 +104,11 @@ int gribapiGetZaxisType(long editionNumber, int grib_ltype) return (zaxistype); } -#endif -#if defined (HAVE_LIBGRIB_API) static -int gribapiGetTimeUnits(grib_handle *gh) +int getTimeunits(long unitsOfTime) { int timeunits = -1; - long unitsOfTime; - long lpar; - size_t len = 8; - char stepunits[8]; - static int lprint = TRUE; - - GRIB_CHECK(grib_get_long(gh, "indicatorOfUnitOfTimeRange", &unitsOfTime), 0); switch (unitsOfTime) { @@ -131,6 +122,45 @@ int gribapiGetTimeUnits(grib_handle *gh) default: timeunits = TUNIT_HOUR; break; } + return (timeunits); +} + +static +double timeunit_factor(int tu1, int tu2) +{ + double factor = 1; + + if ( tu2 == TUNIT_HOUR ) + { + switch (tu1) + { + case TUNIT_SECOND: factor = 3600; break; + case TUNIT_MINUTE: factor = 60; break; + case TUNIT_HOUR: factor = 1; break; + case TUNIT_3HOURS: factor = 1./3; break; + case TUNIT_6HOURS: factor = 1./6; break; + case TUNIT_12HOURS: factor = 1./12; break; + case TUNIT_DAY: factor = 1./24; break; + } + } + + return (factor); +} + +static +int gribapiGetTimeUnits(grib_handle *gh) +{ + int timeunits = -1; + long unitsOfTime = -1; + int status; + // size_t len = 8; + //char stepunits[8]; + //static int lprint = TRUE; + + status = grib_get_long(gh, "indicatorOfUnitOfTimeRange", &unitsOfTime); + + timeunits = getTimeunits(unitsOfTime); + /* GRIB_CHECK(grib_get_string(gh, "stepUnits", stepunits, &len), 0); @@ -154,9 +184,30 @@ int gribapiGetTimeUnits(grib_handle *gh) return (timeunits); } -#endif -#if defined (HAVE_LIBGRIB_API) +static +int gribapiGetEndStep(grib_handle *gh, int startStep, int timeunits) +{ + int endStep = startStep; + int timeunits2; + int status; + long unitsOfTime; + long lpar; + + // status = grib_get_long(gh, "stepUnits", &unitsOfTime); + + // timeunits2 = getTimeunits(unitsOfTime); + timeunits2 = gribapiGetTimeUnits(gh); + + status = grib_get_long(gh, "endStep", &lpar); + + if ( status == 0 ) + endStep = (int) ((lpar * timeunit_factor(timeunits, timeunits2)) + 0.5); + // printf("%d %d %d %d %d %g\n", startStep, endStep, lpar, timeunits, timeunits2, timeunit_factor(timeunits, timeunits2)); + + return (endStep); +} + static int gribapiTimeIsFC(grib_handle *gh) { @@ -176,14 +227,11 @@ int gribapiTimeIsFC(grib_handle *gh) return (isFC); } -#endif -#if defined (HAVE_LIBGRIB_API) static int gribapiGetTsteptype(grib_handle *gh) { int tsteptype = TSTEP_INSTANT; - long lpar; static int lprint = TRUE; if ( gribapiTimeIsFC(gh) ) @@ -191,7 +239,7 @@ int gribapiGetTsteptype(grib_handle *gh) int status; size_t len = 256; char stepType[256]; - + status = grib_get_string(gh, "stepType", stepType, &len); if ( status == 0 && len > 1 && len < 256 ) { @@ -217,16 +265,33 @@ int gribapiGetTsteptype(grib_handle *gh) return (tsteptype); } -#endif -#if defined (HAVE_LIBGRIB_API) +static +void gribapiGetDataDateTime(grib_handle *gh, int *datadate, int *datatime) +{ + long lpar; + + GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0); + *datadate = (int) lpar; + GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); + *datatime = (int) lpar*100; +} + +static +void gribapiSetDataDateTime(grib_handle *gh, int datadate, int datatime) +{ + GRIB_CHECK(grib_set_long(gh, "dataDate", datadate), 0); + GRIB_CHECK(grib_set_long(gh, "dataTime", datatime/100), 0); +} + static int gribapiGetValidityDateTime(grib_handle *gh, int *vdate, int *vtime) { int rdate, rtime; - int timeUnits, startStep, endStep; + int timeUnits, startStep = 0, endStep; int tstepRange = 0; int range; + int status; long lpar; long sigofrtime = 3; long editionNumber; @@ -240,22 +305,16 @@ int gribapiGetValidityDateTime(grib_handle *gh, int *vdate, int *vtime) if ( sigofrtime == 3 ) { - GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0); - *vdate = (int) lpar; - GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); - *vtime = (int) lpar*100; + gribapiGetDataDateTime(gh, vdate, vtime); } else { - GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0); - rdate = (int) lpar; - GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); - rtime = (int) lpar*100; - GRIB_CHECK(grib_get_long(gh, "forecastTime", &lpar), 0); - startStep = (int) lpar; - GRIB_CHECK(grib_get_long(gh, "endStep", &lpar), 0); - endStep = (int) lpar; + gribapiGetDataDateTime(gh, &rdate, &rtime); + + status = grib_get_long(gh, "forecastTime", &lpar); + if ( status == 0 ) startStep = (int) lpar; timeUnits = gribapiGetTimeUnits(gh); + endStep = gribapiGetEndStep(gh, startStep, timeUnits); range = endStep - startStep; @@ -293,14 +352,13 @@ int gribapiGetValidityDateTime(grib_handle *gh, int *vdate, int *vtime) Warning("Time unit %d unsupported", timeUnits); lprint = FALSE; } + break; } julday_add_seconds(addsec, &julday, &secofday); decode_caldaysec(grib_calendar, julday, secofday, &ryear, &rmonth, &rday, &rhour, &rminute, &rsecond); - /* - printf("new %d/%d/%d %d:%d\n", ryear, rmonth, rday, rhour, rminute); - */ + *vdate = cdiEncodeDate(ryear, rmonth, rday); *vtime = cdiEncodeTime(rhour, rminute, rsecond); } @@ -308,9 +366,7 @@ int gribapiGetValidityDateTime(grib_handle *gh, int *vdate, int *vtime) return (tstepRange); } -#endif -#if defined (HAVE_LIBGRIB_API) static void gribapiGetGrid(grib_handle *gh, grid_t *grid) { @@ -355,8 +411,7 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) } if ( numberOfPoints != nlon*nlat ) - Error("numberOfPoints (%d) and gridSize (%d) differ!", - (int)numberOfPoints, nlon*nlat); + Error("numberOfPoints (%d) and gridSize (%d) differ!", (int)numberOfPoints, nlon*nlat); grid->size = numberOfPoints; grid->xsize = nlon; @@ -533,27 +588,26 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) case GRID_REFERENCE: { char uuid[17]; - char reference_link[8192]; - size_t len = sizeof(reference_link); - reference_link[0] = 0; + char reference_link[8192]; + size_t len = sizeof(reference_link); + reference_link[0] = 0; - grid->size = numberOfPoints; - if ( grib_get_long(gh, "numberOfGridUsed", &lpar) == 0 ) - { - grid->number = lpar; - if ( grib_get_long(gh, "numberOfGridInReference", &lpar) == 0 ) grid->position = lpar; - if ( grib_get_string(gh, "gridDescriptionFile", reference_link, &len) == 0 ) - { - if ( strncmp(reference_link, "file://", 7) == 0 ) - grid->reference = strdupx(reference_link); - } + grid->size = numberOfPoints; + if ( grib_get_long(gh, "numberOfGridUsed", &lpar) == 0 ) + { + grid->number = lpar; + if ( grib_get_long(gh, "numberOfGridInReference", &lpar) == 0 ) grid->position = lpar; + if ( grib_get_string(gh, "gridDescriptionFile", reference_link, &len) == 0 ) + { + if ( strncmp(reference_link, "file://", 7) == 0 ) + grid->reference = strdupx(reference_link); + } len = (size_t) 16; - if ( grib_get_string(gh, "uuidOfHGrid", uuid, &len) == 0) + if ( grib_get_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) == 0) { strncpy(grid->uuid, uuid, 16); } - } - + } break; } case GRID_GENERIC: @@ -601,9 +655,7 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) grid->yvals = NULL; grid->type = gridtype; } -#endif -#if defined (HAVE_LIBGRIB_API) static void grib1GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, int *level2) { @@ -650,7 +702,7 @@ void grib1GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i } static -void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, int *level2) +void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, int *level2, int *level_sf) { int status; int leveltype2 = -1; @@ -662,6 +714,7 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i *lbounds = 0; *level1 = 0; *level2 = 0; + *level_sf = 0; status = grib_get_long(gh, "typeOfFirstFixedSurface", &lpar); if ( status == 0 ) @@ -679,9 +732,11 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i { GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0); GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0); - if ( factor == 0 ) dlevel *= 100; // m to cm - else if ( factor == 1 ) dlevel *= 10; // dm to cm - else if ( factor == 3 ) dlevel *= 0.1; // mm to cm + if ( factor == 0 ) dlevel *= 1000; // m to mm + else if ( factor == 1 ) dlevel *= 100; // dm to mm + else if ( factor == 2 ) dlevel *= 10; // cm to mm + else if ( factor == 3 ) dlevel *= 1; // mm to mm + *level_sf = 77; } else { @@ -700,16 +755,19 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i { GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0); GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0); - if ( factor == 0 ) dlevel *= 100; // m to cm - else if ( factor == 1 ) dlevel *= 10; // dm to cm - else if ( factor == 3 ) dlevel *= 0.1; // mm to cm + if ( factor == 0 ) dlevel *= 1000; // m to mm + else if ( factor == 1 ) dlevel *= 100; // dm to mm + else if ( factor == 2 ) dlevel *= 10; // cm to mm + else if ( factor == 3 ) dlevel *= 1; // mm to mm *level1 = (int) dlevel; GRIB_CHECK(grib_get_long(gh, "scaleFactorOfSecondFixedSurface", &factor), 0); GRIB_CHECK(grib_get_double(gh, "scaledValueOfSecondFixedSurface", &dlevel), 0); - if ( factor == 0 ) dlevel *= 100; // m to cm - else if ( factor == 1 ) dlevel *= 10; // dm to cm - else if ( factor == 3 ) dlevel *= 0.1; // mm to cm + if ( factor == 0 ) dlevel *= 1000; // m to mm + else if ( factor == 1 ) dlevel *= 100; // dm to mm + else if ( factor == 2 ) dlevel *= 10; // cm to mm + else if ( factor == 3 ) dlevel *= 1; // mm to mm *level2 = (int) dlevel; + *level_sf = 77; } else { @@ -723,33 +781,39 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i } static -void gribapiAddRecord(int streamID, int param, grib_handle *gh, - long recsize, off_t position, int datatype, int comptype) +void gribapiGetString(grib_handle *gh, const char *key, char *string, size_t length) +{ + string[0] = 0; + + GRIB_CHECK(grib_get_string(gh, key, string, &length), 0); + if ( length == 8 && memcmp(string, "unknown", length) == 0 ) string[0] = 0; + else if ( length == 2 && memcmp(string, "~", length) == 0 ) string[0] = 0; +} + +static +void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, + long recsize, off_t position, int datatype, int comptype, size_t len, const char *varname, + int leveltype, int lbounds, int level1, int level2, int level_sf) { long editionNumber; int zaxistype; int gridID = CDI_UNDEFID, varID; int levelID = 0; int tsID, recID; - int level1 = 0, level2 = 0; int numavg; int tsteptype; - int lbounds = 0; record_t *record; grid_t grid; int vlistID; - stream_t *streamptr; - int leveltype; long lpar; int status; - char name[256], longname[256], units[256]; + char longname[256], units[256]; size_t vlen; + long ens_index = 0, ens_count = 0, ens_forecast_type = 0; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; tsID = streamptr->curTsID; - recID = recordNewEntry(streamID, tsID); + recID = recordNewEntry(streamptr, tsID); record = &streamptr->tsteps[tsID].records[recID]; tsteptype = gribapiGetTsteptype(gh); @@ -758,11 +822,6 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh, GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); - if ( editionNumber <= 1 ) - grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); - else - grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); - // fprintf(stderr, "param %d %d %d %d\n", param, level1, level2, leveltype); (*record).size = recsize; @@ -771,6 +830,7 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh, (*record).ilevel = level1; (*record).ilevel2 = level2; (*record).ltype = leveltype; + memcpy((*record).varname, varname, len); gribapiGetGrid(gh, &grid); @@ -803,19 +863,21 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh, { size_t len; char uuid[17]; + double dtmp; long nlev, nvgrid; GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0); - if ( lpar != 3 ) + if ( lpar != 6 ) { fprintf(stderr, "Warning ...\n"); } - GRIB_CHECK(grib_get_long(gh, "nlev", &nlev), 0); - GRIB_CHECK(grib_get_long(gh, "numberOfVGridUsed", &nvgrid), 0); - + GRIB_CHECK(grib_get_double(gh, "nlev", &dtmp), 0); + nlev = (int) NINT(dtmp); + GRIB_CHECK(grib_get_double(gh, "numberOfVGridUsed", &dtmp), 0); + nvgrid = NINT(dtmp); len = (size_t) 16; uuid[16] = 0; - GRIB_CHECK(grib_get_string(gh, "uuidOfVGrid", uuid, &len), 0); + GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len), 0); varDefZAxisReference((int) nlev, (int) nvgrid, uuid); break; } @@ -824,35 +886,44 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh, // if ( datatype > 32 ) datatype = DATATYPE_PACK32; if ( datatype < 0 ) datatype = DATATYPE_PACK; - name[0] = 0; longname[0] = 0; units[0] = 0; - vlen = 256; - GRIB_CHECK(grib_get_string(gh, "shortName", name, &vlen), 0); - if ( vlen == 8 && memcmp(name, "unknown", vlen) == 0 ) name[0] = 0; - else if ( vlen == 2 && memcmp(name, "~", vlen) == 0 ) name[0] = 0; - - if ( name[0] != 0 ) + if ( varname[0] != 0 ) { vlen = 256; - GRIB_CHECK(grib_get_string(gh, "name", longname, &vlen), 0); - if ( vlen == 8 && memcmp(longname, "unknown", vlen) == 0 ) longname[0] = 0; + gribapiGetString(gh, "name", longname, vlen); vlen = 256; - GRIB_CHECK(grib_get_string(gh, "units", units, &vlen), 0); - if ( vlen == 8 && memcmp(units, "unknown", vlen) == 0 ) units[0] = 0; + gribapiGetString(gh, "units", units, vlen); } - // fprintf(stderr, "param %d name %s %s %s\n", param, name, longname, units); + // fprintf(stderr, "param %d name %s %s %s\n", param, name, longname, units); - varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, + varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, level_sf, datatype, &varID, &levelID, tsteptype, numavg, leveltype, - name, longname, units); + varname, longname, units); (*record).varID = varID; (*record).levelID = levelID; varDefCompType(varID, comptype); + /* + Get the ensemble Info from the grib-2 Tables and update the intermediate datastructure. + Further update to the "vlist" is handled in the same way as for GRIB-1 by "cdi_generate_vars" + */ + { + int status; + status = grib_get_long(gh, "typeOfEnsembleForecast", &ens_forecast_type ); + if ( status == 0 ) + { + GRIB_CHECK(grib_get_long(gh, "numberOfForecastsInEnsemble", &ens_count ), 0); + GRIB_CHECK(grib_get_long(gh, "perturbationNumber", &ens_index ), 0); + } + } + if ( ens_index > 0 ) + varDefEnsembleInfo(varID, (int)ens_index, (int)ens_count, (int)ens_forecast_type); + + if ( varInqInst(varID) == CDI_UNDEFID ) { long center, subcenter; @@ -905,15 +976,72 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh, Message("varID = %d param = %d zaxistype = %d gridID = %d levelID = %d", varID, param, zaxistype, gridID, levelID); } + +static +int gribapiGetParam(grib_handle *gh) +{ + int pdis = 0, pcat = 0, pnum = 0; + int param = 0; + int status; + long lpar; + + GRIB_CHECK(grib_get_long(gh, "discipline", &lpar), 0); + pdis = (int) lpar; + + status = grib_get_long(gh, "parameterCategory", &lpar); + if ( status == 0 ) pcat = (int) lpar; + + status = grib_get_long(gh, "parameterNumber", &lpar); + if ( status == 0 ) pnum = (int) lpar; + + param = cdiEncodeParam(pnum, pcat, pdis); + + return (param); +} + +static +compvar2_t gribapiVarSet(int param, int level1, int level2, int leveltype, char *name) +{ + compvar2_t compVar; + size_t maxlen = sizeof(compVar.name); + size_t len = strlen(name); + if ( len > maxlen ) len = maxlen; + + compVar.param = param; + compVar.level1 = level1; + compVar.level2 = level2; + compVar.ltype = leveltype; + memset(compVar.name, 0, maxlen); + memcpy(compVar.name, name, len); + + return (compVar); +} + +static +int gribapiVarCompare(compvar2_t compVar, record_t record) +{ + int rstatus; + compvar2_t compVar0; + size_t maxlen = sizeof(compVar.name); + + compVar0.param = record.param; + compVar0.level1 = record.ilevel; + compVar0.level2 = record.ilevel2; + compVar0.ltype = record.ltype; + memcpy(compVar0.name, record.varname, maxlen); + + rstatus = memcmp(&compVar0, &compVar, sizeof(compvar2_t)); + + return (rstatus); +} #endif -int gribapiScanTimestep1(int streamID) +int gribapiScanTimestep1(stream_t * streamptr) { #if defined (HAVE_LIBGRIB_API) off_t recpos = 0; unsigned char *gribbuffer = NULL; long buffersize = 0; - int iret = 0, ipunp = 0, iword = 0; int rstatus; int status; int fileID; @@ -926,41 +1054,41 @@ int gribapiScanTimestep1(int streamID) int varID; size_t readsize; int nrecords, nrecs, recID; + int nrecs_scanned; int datatype; long recsize = 0; int warn_time = TRUE; - int warn_numavg = TRUE; + // int warn_numavg = TRUE; int taxisID = -1; int rdate = 0, rtime = 0, tunit = 0, fcast = 0; taxis_t *taxis; int vlistID; int comptype; long unzipsize; - compvar2_t compVar, compVar0; - stream_t *streamptr; + compvar2_t compVar; grib_handle *gh = NULL; int leveltype; - int pdis = 0, pcat = 0, pnum = 0; long editionNumber; long lpar; + size_t len; int bitsPerValue; int lieee = FALSE; int lbounds; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); + int level_sf; + char paramstr[32]; + char varname[256]; streamptr->curTsID = 0; - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); taxis = &streamptr->tsteps[tsID].taxis; if ( tsID != 0 ) Error("Internal problem! tstepsNewEntry returns %d", tsID); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; + nrecs_scanned = 0; nrecs = 0; while ( TRUE ) { @@ -998,8 +1126,9 @@ int gribapiScanTimestep1(int streamID) } } + nrecs_scanned++; gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize); - GRIB_CHECK(grib_set_double(gh, "missingValue", GRIBAPI_MISSVAL), 0); + GRIB_CHECK(grib_set_double(gh, "missingValue", cdiDefaultMissval), 0); GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); @@ -1013,6 +1142,7 @@ int gribapiScanTimestep1(int streamID) param = cdiEncodeParam(rcode, rtabnum, 255); grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); + level_sf = 0; } else { @@ -1027,19 +1157,18 @@ int gribapiScanTimestep1(int streamID) else if ( strncmp(typeOfPacking, "grid_ieee", len) == 0 ) lieee = TRUE; } - GRIB_CHECK(grib_get_long(gh, "discipline", &lpar), 0); - pdis = (int) lpar; + param = gribapiGetParam(gh); - GRIB_CHECK(grib_get_long(gh, "parameterCategory", &lpar), 0); - pcat = (int) lpar; + grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2, &level_sf); + } - GRIB_CHECK(grib_get_long(gh, "parameterNumber", &lpar), 0); - pnum = (int) lpar; + cdiParamToString(param, paramstr, sizeof(paramstr)); - param = cdiEncodeParam(pnum, pcat, pdis); - - grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); - } + varname[0] = 0; + gribapiGetString(gh, "shortName", varname, sizeof(varname)); + len = strlen(varname); + if ( len > 32 ) len = 32; + //printf("param = %s name = %s l1 = %d l2 = %d\n", paramstr, varname, level1, level2); gribapiGetValidityDateTime(gh, &vdate, &vtime); /* @@ -1067,10 +1196,9 @@ int gribapiScanTimestep1(int streamID) { datetime0.date = vdate; datetime0.time = vtime; - GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0); - rdate = (int) lpar; - GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); - rtime = (int) lpar*100; + + gribapiGetDataDateTime(gh, &rdate, &rtime); + fcast = gribapiTimeIsFC(gh); if ( fcast ) tunit = gribapiGetTimeUnits(gh); } @@ -1079,23 +1207,10 @@ int gribapiScanTimestep1(int streamID) datetime.date = vdate; datetime.time = vtime; - compVar.param = param; - compVar.level1 = level1; - compVar.level2 = level2; - compVar.ltype = leveltype; + compVar = gribapiVarSet(param, level1, level2, leveltype, varname); for ( recID = 0; recID < nrecs; recID++ ) - { - compVar0.param = streamptr->tsteps[0].records[recID].param; - compVar0.level1 = streamptr->tsteps[0].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[0].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[0].records[recID].ltype; - /* - printf("var0: %d %d %d %d %d\n", recID, compVar0.param, compVar0.level1, compVar0.level2, compVar0.ltype); - printf("var1: %d %d %d %d %d\n", recID, compVar.param, compVar.level1, compVar.level2, compVar.ltype); - */ - if ( memcmp(&compVar0, &compVar, sizeof(compvar2_t)) == 0 ) break; - } + if ( gribapiVarCompare(compVar, streamptr->tsteps[0].records[recID]) == 0 ) break; if ( cdiInventoryMode == 1 ) { @@ -1103,8 +1218,6 @@ int gribapiScanTimestep1(int streamID) if ( warn_time ) if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); Warning("Inconsistent verification time (param=%s level=%d)", paramstr, level1); warn_time = FALSE; } @@ -1115,9 +1228,7 @@ int gribapiScanTimestep1(int streamID) if ( recID < nrecs ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); - Warning("Param=%s level=%d already exist, skipped!", paramstr, level1); + Warning("Param=%s level=%d (record %d) already exist, skipped!", paramstr, level1, nrecs_scanned); continue; } } @@ -1142,7 +1253,8 @@ int gribapiScanTimestep1(int streamID) if ( CDI_Debug ) Message("%4d %8d %4d %8d %8d %6d", nrecs, (int)recpos, param, level1, vdate, vtime); - gribapiAddRecord(streamID, param, gh, recsize, recpos, datatype, comptype); + gribapiAddRecord(streamptr, param, gh, recsize, recpos, datatype, comptype, len, varname, + leveltype, lbounds, level1, level2, level_sf); grib_handle_delete(gh); gh = NULL; @@ -1154,7 +1266,7 @@ int gribapiScanTimestep1(int streamID) if ( nrecs == 0 ) return (CDI_EUFSTRUCT); - cdiGenVars(streamID); + cdi_generate_vars(streamptr); if ( fcast ) { @@ -1173,7 +1285,7 @@ int gribapiScanTimestep1(int streamID) taxis->vdate = datetime0.date; taxis->vtime = datetime0.time; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; vlistDefTaxis(vlistID, taxisID); nrecords = streamptr->tsteps[0].nallrecs; @@ -1194,7 +1306,7 @@ int gribapiScanTimestep1(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1221,48 +1333,44 @@ int gribapiScanTimestep1(int streamID) } -int gribapiScanTimestep2(int streamID) +int gribapiScanTimestep2(stream_t * streamptr) { int rstatus = 0; #if defined (HAVE_LIBGRIB_API) - int status; off_t recpos = 0; unsigned char *gribbuffer = NULL; long buffersize = 0; - int iret = 0, ipunp = 0, iword = 0; int fileID; int rtabnum = 0; int rcode = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0; DateTime datetime, datetime0; int tsID; - int varID, gridID; + int varID; + // int gridID; size_t readsize; int nrecords, nrecs, recID, rindex; long recsize = 0; - int warn_numavg = TRUE; + // int warn_numavg = TRUE; int tsteptype; int taxisID = -1; taxis_t *taxis; int vlistID; long unzipsize; - compvar2_t compVar, compVar0; - stream_t *streamptr; + compvar2_t compVar; grib_handle *gh = NULL; int leveltype; - int pdis = 0, pcat = 0, pnum = 0; int param = 0; long editionNumber; long lpar; int lbounds; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); + int level_sf; + char paramstr[32]; + char varname[256]; streamptr->curTsID = 1; - fileID = streamInqFileID(streamID); - vlistID = streamInqVlist(streamID); + fileID = streamptr->fileID; + vlistID = streamptr->vlistID; taxisID = vlistInqTaxis(vlistID); gribbuffer = (unsigned char *) streamptr->record->buffer; @@ -1276,7 +1384,7 @@ int gribapiScanTimestep2(int streamID) fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecords = streamptr->tsteps[tsID].nallrecs; streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); @@ -1324,7 +1432,7 @@ int gribapiScanTimestep2(int streamID) } gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize); - GRIB_CHECK(grib_set_double(gh, "missingValue", GRIBAPI_MISSVAL), 0); + GRIB_CHECK(grib_set_double(gh, "missingValue", cdiDefaultMissval), 0); GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); @@ -1338,22 +1446,19 @@ int gribapiScanTimestep2(int streamID) param = cdiEncodeParam(rcode, rtabnum, 255); grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); + level_sf = 0; } else { - GRIB_CHECK(grib_get_long(gh, "discipline", &lpar), 0); - pdis = (int) lpar; + param = gribapiGetParam(gh); - GRIB_CHECK(grib_get_long(gh, "parameterCategory", &lpar), 0); - pcat = (int) lpar; - - GRIB_CHECK(grib_get_long(gh, "parameterNumber", &lpar), 0); - pnum = (int) lpar; + grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2, &level_sf); + } - param = cdiEncodeParam(pnum, pcat, pdis); + cdiParamToString(param, paramstr, sizeof(paramstr)); - grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); - } + varname[0] = 0; + gribapiGetString(gh, "shortName", varname, sizeof(varname)); gribapiGetValidityDateTime(gh, &vdate, &vtime); @@ -1362,10 +1467,9 @@ int gribapiScanTimestep2(int streamID) if ( taxisInqType(taxisID) == TAXIS_RELATIVE ) { taxis->type = TAXIS_RELATIVE; - GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0); - taxis->rdate = (int) lpar; - GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); - taxis->rtime = (int) lpar*100; + + gribapiGetDataDateTime(gh, &(taxis->rdate), &(taxis->rtime)); + taxis->unit = gribapiGetTimeUnits(gh); } else @@ -1396,70 +1500,39 @@ int gribapiScanTimestep2(int streamID) */ datetime.date = vdate; datetime.time = vtime; - compVar.param = param; - compVar.level1 = level1; - compVar.level2 = level2; - compVar.ltype = leveltype; - for ( recID = 0; recID < nrecords; recID++ ) - { - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - if ( memcmp(&compVar0, &compVar, sizeof(compvar2_t)) == 0 ) break; - } + compVar = gribapiVarSet(param, level1, level2, leveltype, varname); + + for ( recID = 0; recID < nrecords; recID++ ) + if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break; if ( recID == nrecords ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); - Warning("Param=%s level=%d not defined at timestep 1!", paramstr, level1); + Warning("Param=%s (%s) l1=%d l2=%d not defined at timestep 1!", paramstr, varname, level1, level2); return (CDI_EUFSTRUCT); } - if ( cdiInventoryMode == 1 ) - { - if ( streamptr->tsteps[tsID].records[recID].used ) - { - break; - } - else - { - streamptr->tsteps[tsID].records[recID].used = TRUE; - streamptr->tsteps[tsID].recIDs[rindex] = recID; - } - } - else - { - if ( streamptr->tsteps[tsID].records[recID].used ) + if ( streamptr->tsteps[tsID].records[recID].used ) + { + if ( cdiInventoryMode == 1 ) break; + else { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); - if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break; Warning("Param=%s level=%d already exist, skipped!", paramstr, level1); continue; } - else - { - streamptr->tsteps[tsID].records[recID].used = TRUE; - streamptr->tsteps[tsID].recIDs[rindex] = recID; - } } + streamptr->tsteps[tsID].records[recID].used = TRUE; + streamptr->tsteps[tsID].recIDs[rindex] = recID; + if ( CDI_Debug ) Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime); streamptr->tsteps[tsID].records[recID].size = recsize; - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar2_t)) != 0 ) + if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 ) { Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d", tsID, recID, @@ -1470,8 +1543,8 @@ int gribapiScanTimestep2(int streamID) streamptr->tsteps[1].records[recID].position = recpos; varID = streamptr->tsteps[tsID].records[recID].varID; - gridID = vlistInqVarGrid(vlistID, varID); /* + gridID = vlistInqVarGrid(vlistID, varID); if ( gridInqSize(gridID) == 1 && gridInqType(gridID) == GRID_LONLAT ) { if ( IS_NOT_EQUAL(gridInqXval(gridID, 0),ISEC2_FirstLon*0.001) || @@ -1484,10 +1557,10 @@ int gribapiScanTimestep2(int streamID) grib_handle_delete(gh); gh = NULL; - + rindex++; } - + if ( gh ) grib_handle_delete(gh); nrecs = 0; @@ -1509,7 +1582,7 @@ int gribapiScanTimestep2(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1525,48 +1598,43 @@ int gribapiScanTimestep2(int streamID) } -int gribapiScanTimestep(int streamID) +int gribapiScanTimestep(stream_t * streamptr) { int rstatus = 0; #if defined (HAVE_LIBGRIB_API) - int status = 0; long recsize = 0; off_t recpos = 0; unsigned char *gribbuffer; long buffersize = 0; - int iret = 0, ipunp = 0, iword = 0; int fileID; int rtabnum = 0; int rcode = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0; DateTime datetime, datetime0; int tsID; int vrecID, recID; - int warn_numavg = TRUE; + //int warn_numavg = TRUE; size_t readsize; int taxisID = -1; taxis_t *taxis; int vlistID; int rindex, nrecs = 0; long unzipsize; - compvar2_t compVar, compVar0; - stream_t *streamptr; + compvar2_t compVar; grib_handle *gh = NULL; int leveltype; - int pdis = 0, pcat = 0, pnum = 0; int param = 0; long editionNumber; long lpar; int lbounds; + int level_sf; + char paramstr[32]; + char varname[256]; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; if ( CDI_Debug ) { - Message("streamID = %d", streamID); + Message("streamID = %d", streamptr->self); Message("cts = %d", streamptr->curTsID); Message("rts = %d", streamptr->rtsteps); Message("nts = %d", streamptr->ntsteps); @@ -1580,7 +1648,7 @@ int gribapiScanTimestep(int streamID) gribbuffer = (unsigned char *) streamptr->record->buffer; buffersize = streamptr->record->buffersize; - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecs = streamptr->tsteps[1].nrecs; @@ -1589,7 +1657,7 @@ int gribapiScanTimestep(int streamID) for ( recID = 0; recID < nrecs; recID++ ) streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID]; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); @@ -1634,7 +1702,7 @@ int gribapiScanTimestep(int streamID) } gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize); - GRIB_CHECK(grib_set_double(gh, "missingValue", GRIBAPI_MISSVAL), 0); + GRIB_CHECK(grib_set_double(gh, "missingValue", cdiDefaultMissval), 0); GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); @@ -1648,22 +1716,19 @@ int gribapiScanTimestep(int streamID) param = cdiEncodeParam(rcode, rtabnum, 255); grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); + level_sf = 0; } else { - GRIB_CHECK(grib_get_long(gh, "discipline", &lpar), 0); - pdis = (int) lpar; - - GRIB_CHECK(grib_get_long(gh, "parameterCategory", &lpar), 0); - pcat = (int) lpar; + param = gribapiGetParam(gh); - GRIB_CHECK(grib_get_long(gh, "parameterNumber", &lpar), 0); - pnum = (int) lpar; + grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2, &level_sf); + } - param = cdiEncodeParam(pnum, pcat, pdis); + cdiParamToString(param, paramstr, sizeof(paramstr)); - grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); - } + varname[0] = 0; + gribapiGetString(gh, "shortName", varname, sizeof(varname)); gribapiGetValidityDateTime(gh, &vdate, &vtime); @@ -1675,10 +1740,9 @@ int gribapiScanTimestep(int streamID) if ( taxisInqType(taxisID) == TAXIS_RELATIVE ) { taxis->type = TAXIS_RELATIVE; - GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0); - taxis->rdate = (int) lpar; - GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); - taxis->rtime = (int) lpar*100; + + gribapiGetDataDateTime(gh, &(taxis->rdate), &(taxis->rtime)); + taxis->unit = gribapiGetTimeUnits(gh); } else @@ -1707,25 +1771,17 @@ int gribapiScanTimestep(int streamID) */ datetime.date = vdate; datetime.time = vtime; - compVar.param = param; - compVar.level1 = level1; - compVar.level2 = level2; - compVar.ltype = leveltype; + + compVar = gribapiVarSet(param, level1, level2, leveltype, varname); + for ( vrecID = 0; vrecID < nrecs; vrecID++ ) { recID = streamptr->tsteps[1].recIDs[vrecID]; - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar2_t)) == 0 ) break; + if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break; } if ( vrecID == nrecs ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); Warning("Param=%s level=%d not available at timestep %d!", paramstr, level1, tsID+1); if ( cdiInventoryMode == 1 ) @@ -1734,18 +1790,10 @@ int gribapiScanTimestep(int streamID) continue; } - if ( cdiInventoryMode == 1 ) - { - streamptr->tsteps[tsID].records[recID].used = TRUE; - streamptr->tsteps[tsID].recIDs[rindex] = recID; - } - else + if ( cdiInventoryMode != 1 ) { if ( streamptr->tsteps[tsID].records[recID].used ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); - if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break; if ( CDI_Debug ) @@ -1753,22 +1801,15 @@ int gribapiScanTimestep(int streamID) continue; } - else - { - streamptr->tsteps[tsID].records[recID].used = TRUE; - streamptr->tsteps[tsID].recIDs[rindex] = recID; - } } + streamptr->tsteps[tsID].records[recID].used = TRUE; + streamptr->tsteps[tsID].recIDs[rindex] = recID; + if ( CDI_Debug ) Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime); - compVar0.param = streamptr->tsteps[tsID].records[recID].param; - compVar0.level1 = streamptr->tsteps[tsID].records[recID].ilevel; - compVar0.level2 = streamptr->tsteps[tsID].records[recID].ilevel2; - compVar0.ltype = streamptr->tsteps[tsID].records[recID].ltype; - - if ( memcmp(&compVar0, &compVar, sizeof(compvar2_t)) != 0 ) + if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 ) { Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d", tsID, recID, @@ -1799,7 +1840,6 @@ int gribapiScanTimestep(int streamID) if ( vrecID < nrecs ) { - char paramstr[32]; cdiParamToString(streamptr->tsteps[tsID].records[recID].param, paramstr, sizeof(paramstr)); Warning("Param %d level %d not found at timestep %d!", paramstr, streamptr->tsteps[tsID].records[recID].ilevel, tsID+1); @@ -1810,7 +1850,7 @@ int gribapiScanTimestep(int streamID) if ( streamptr->ntsteps != streamptr->rtsteps ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1927,9 +1967,7 @@ void gribapiDefInstitut(grib_handle *gh, int vlistID, int varID) GRIB_CHECK(grib_set_long(gh, "subCentre", subcenter), 0); } } -#endif -#if defined (HAVE_LIBGRIB_API) static void gribapiDefModel(grib_handle *gh, int vlistID, int varID) { @@ -1943,14 +1981,11 @@ void gribapiDefModel(grib_handle *gh, int vlistID, int varID) if ( modelID != CDI_UNDEFID ) GRIB_CHECK(grib_set_long(gh, "generatingProcessIdentifier", modelInqGribID(modelID)), 0); } -#endif -#if defined (HAVE_LIBGRIB_API) static -void gribapiDefParam(grib_handle *gh, int param, const char *name) +void gribapiDefParam(int editionNumber, grib_handle *gh, int param, const char *name) { int pdis, pcat, pnum; - long editionNumber; cdiDecodeParam(param, &pnum, &pcat, &pdis); @@ -1967,8 +2002,6 @@ void gribapiDefParam(grib_handle *gh, int param, const char *name) { if ( pnum < 0 ) pnum = -pnum; - GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); - if ( editionNumber <= 1 ) { if ( pdis != 255 ) @@ -1991,11 +2024,9 @@ void gribapiDefParam(grib_handle *gh, int param, const char *name) // printf("param: %d.%d.%d %s\n", pnum, pcat, pdis, name); } -#endif -#if defined (HAVE_LIBGRIB_API) static -int gribapiDefStepUnits(grib_handle *gh, int timeunit) +int gribapiDefStepUnits(grib_handle *gh, int timeunit, int gcinit) { int factor = 1; long unitsOfTime; @@ -2014,53 +2045,78 @@ int gribapiDefStepUnits(grib_handle *gh, int timeunit) default: factor = 3600; unitsOfTime = 1; strcpy(stepunits, "h"); break; } - len = strlen(stepunits) + 1; - GRIB_CHECK(grib_set_long(gh, "indicatorOfUnitOfTimeRange", unitsOfTime), 0); - GRIB_CHECK(grib_set_string(gh, "stepUnits", stepunits, &len), 0); + if ( !gcinit ) + { + len = strlen(stepunits) + 1; + GRIB_CHECK(grib_set_long(gh, "indicatorOfUnitOfTimeRange", unitsOfTime), 0); + GRIB_CHECK(grib_set_string(gh, "stepUnits", stepunits, &len), 0); + } return (factor); } static -int gribapiDefDateTime(grib_handle *gh, int timeunit, int date, int time) +int gribapiDefSteptype(int editionNumber, grib_handle *gh, int tsteptype, int gcinit) { - long editionNumber; + long proDefTempNum = 0; + size_t len = 64; + char stepType[64]; - GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); + switch ( tsteptype ) + { + case TSTEP_AVG: strcpy(stepType, "avg"); proDefTempNum = 8; break; + case TSTEP_ACCUM: strcpy(stepType, "accum"); proDefTempNum = 8; break; + case TSTEP_MAX: strcpy(stepType, "max"); proDefTempNum = 8; break; + case TSTEP_MIN: strcpy(stepType, "min"); proDefTempNum = 8; break; + case TSTEP_DIFF: strcpy(stepType, "diff"); proDefTempNum = 8; break; + case TSTEP_RMS: strcpy(stepType, "rms"); proDefTempNum = 8; break; + case TSTEP_SD: strcpy(stepType, "sd"); proDefTempNum = 8; break; + case TSTEP_COV: strcpy(stepType, "cov"); proDefTempNum = 8; break; + case TSTEP_RATIO: strcpy(stepType, "ratio"); proDefTempNum = 8; break; + case TSTEP_INSTANT: strcpy(stepType, "instant"); proDefTempNum = 0; break; + default: strcpy(stepType, "instant"); proDefTempNum = 0; break; + } + + if ( !gcinit ) + { + if ( editionNumber > 1 ) GRIB_CHECK(grib_set_long(gh, "productDefinitionTemplateNumber", proDefTempNum), 0); + len = strlen(stepType); + GRIB_CHECK(grib_set_string(gh, "stepType", stepType, &len), 0); + } + return ((int)proDefTempNum); +} + +static +void gribapiDefDateTimeAbs(int editionNumber, grib_handle *gh, int date, int time, int tsteptype, int gcinit) +{ if ( editionNumber > 1 ) GRIB_CHECK(grib_set_long(gh, "significanceOfReferenceTime", 0), 0); - GRIB_CHECK(grib_set_long(gh, "stepRange", 0), 0); + if ( editionNumber > 1 ) GRIB_CHECK(grib_set_long(gh, "stepRange", 0), 0); if ( date == 0 ) date = 10101; - GRIB_CHECK(grib_set_long(gh, "dataDate", date), 0); - GRIB_CHECK(grib_set_long(gh, "dataTime", time/100), 0); + gribapiSetDataDateTime(gh, date, time); - return (gribapiDefStepUnits(gh, timeunit)); + (void ) gribapiDefSteptype(editionNumber, gh, tsteptype, gcinit); } static -int gribapiDefTsteptype(grib_handle *gh, int tsteptype, int timeunit, int factor, int calendar, - int rdate, int rtime, int vdate, int vtime) +int gribapiDefDateTimeRel(int editionNumber, grib_handle *gh, int rdate, int rtime, int vdate, int vtime, + int tsteptype, int factor, int calendar, int gcinit) { int status = -1; int year, month, day, hour, minute, second; int julday1, secofday1, julday2, secofday2, days, secs; long startStep = 0, endStep; long proDefTempNum = 0; - size_t len = 256; - char stepType[256]; - long editionNumber; - - GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); cdiDecodeDate(rdate, &year, &month, &day); cdiDecodeTime(rtime, &hour, &minute, &second); - encode_juldaysec(calendar, year, month, day, hour, minute, &julday1, &secofday1); + encode_juldaysec(calendar, year, month, day, hour, minute, second, &julday1, &secofday1); cdiDecodeDate(vdate, &year, &month, &day); cdiDecodeTime(vtime, &hour, &minute, &second); - encode_juldaysec(calendar, year, month, day, hour, minute, &julday2, &secofday2); - + encode_juldaysec(calendar, year, month, day, hour, minute, second, &julday2, &secofday2); + (void) julday_sub(julday1, secofday1, julday2, secofday2, &days, &secs); if ( !(int) fmod(days*86400.0 + secs, factor) ) @@ -2068,28 +2124,14 @@ int gribapiDefTsteptype(grib_handle *gh, int tsteptype, int timeunit, int factor endStep = (int) ((days*86400.0 + secs)/factor); if ( editionNumber > 1 ) GRIB_CHECK(grib_set_long(gh, "significanceOfReferenceTime", 1), 0); - gribapiDefStepUnits(gh, timeunit); + if ( editionNumber > 1 ) GRIB_CHECK(grib_set_long(gh, "stepRange", 0), 0); - // printf(">>>>> tsteptype %d startStep %d endStep %d\n", tsteptype, startStep, endStep); + if ( rdate == 0 ) rdate = 10101; + gribapiSetDataDateTime(gh, rdate, rtime); - switch ( tsteptype ) - { - case TSTEP_INSTANT: strcpy(stepType, "instant"); proDefTempNum = 0; break; - case TSTEP_AVG: strcpy(stepType, "avg"); proDefTempNum = 8; break; - case TSTEP_ACCUM: strcpy(stepType, "accum"); proDefTempNum = 8; break; - case TSTEP_MAX: strcpy(stepType, "max"); proDefTempNum = 8; break; - case TSTEP_MIN: strcpy(stepType, "min"); proDefTempNum = 8; break; - case TSTEP_DIFF: strcpy(stepType, "diff"); proDefTempNum = 8; break; - case TSTEP_RMS: strcpy(stepType, "rms"); proDefTempNum = 8; break; - case TSTEP_SD: strcpy(stepType, "sd"); proDefTempNum = 8; break; - case TSTEP_COV: strcpy(stepType, "cov"); proDefTempNum = 8; break; - case TSTEP_RATIO: strcpy(stepType, "ratio"); proDefTempNum = 8; break; - default: strcpy(stepType, "instant"); proDefTempNum = 0; break; - } + // printf(">>>>> tsteptype %d startStep %ld endStep %ld\n", tsteptype, startStep, endStep); - if ( editionNumber > 1 ) GRIB_CHECK(grib_set_long(gh, "productDefinitionTemplateNumber", proDefTempNum), 0); - len = strlen(stepType); - GRIB_CHECK(grib_set_string(gh, "stepType", stepType, &len), 0); + proDefTempNum = gribapiDefSteptype(editionNumber, gh, tsteptype, gcinit); if ( proDefTempNum == 0 ) startStep = endStep; @@ -2101,52 +2143,44 @@ int gribapiDefTsteptype(grib_handle *gh, int tsteptype, int timeunit, int factor return (status); } -#endif -#if defined (HAVE_LIBGRIB_API) static -void gribapiDefTime(grib_handle *gh , int vdate, int vtime, int tsteptype, int numavg, int taxisID) +void gribapiDefTime(int editionNumber, grib_handle *gh , int vdate, int vtime, int tsteptype, int numavg, int taxisID, int gcinit) { int taxistype = -1; int timeunit; + int factor; if ( taxisID != -1 ) taxistype = taxisInqType(taxisID); timeunit = taxisInqTunit(taxisID); + factor = gribapiDefStepUnits(gh, timeunit, gcinit); + if ( taxistype == TAXIS_RELATIVE ) { - int factor = 1; - int rdate, rtime; - int calendar; int status; + int calendar = taxisInqCalendar(taxisID); + int rdate = taxisInqRdate(taxisID); + int rtime = taxisInqRtime(taxisID); - calendar = taxisInqCalendar(taxisID); - rdate = taxisInqRdate(taxisID); - rtime = taxisInqRtime(taxisID); - - factor = gribapiDefDateTime(gh, timeunit, rdate, rtime); - - status = gribapiDefTsteptype(gh, tsteptype, timeunit, factor, calendar, - rdate, rtime, vdate, vtime); + status = gribapiDefDateTimeRel(editionNumber, gh, rdate, rtime, vdate, vtime, + tsteptype, factor, calendar, gcinit); if ( status != 0 ) taxistype = TAXIS_ABSOLUTE; } if ( taxistype == TAXIS_ABSOLUTE ) { - (void) gribapiDefDateTime(gh, timeunit, vdate, vtime); + gribapiDefDateTimeAbs(editionNumber, gh, vdate, vtime, tsteptype, gcinit); } } -#endif -#if defined (HAVE_LIBGRIB_API) static -void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datatype) +void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int ljpeg, int lieee, int datatype, int nmiss, int gcinit) { int gridtype; int status; - long editionNumber; char uuid[17]; static short lwarn = TRUE; size_t len; @@ -2154,7 +2188,6 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datat gridtype = gridInqType(gridID); - GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); if ( editionNumber <= 1 ) if ( gridtype == GRID_GME || gridtype == GRID_REFERENCE ) gridtype = -1; @@ -2197,6 +2230,30 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datat gridtype = GRID_LONLAT; } + + if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ) + { + if ( editionNumber != 2 || lieee ) { ljpeg = 0; } + + if ( ljpeg ) + { + if ( nmiss > 0 ) ljpeg = 0; + + if ( ljpeg ) + { + mesg = "grid_jpeg"; len = strlen(mesg); + GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0); + } + else + { + mesg = "grid_simple"; len = strlen(mesg); + GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0); + } + } + } + + if ( gcinit ) return; + switch (gridtype) { case GRID_LONLAT: @@ -2340,6 +2397,8 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datat /* South -> North */ //if ( ISEC2_LastLat > ISEC2_FirstLat ) ISEC2_ScanFlag += 64; + if ( editionNumber != 2 ) { lieee = 0; ljpeg = 0; } + if ( lieee ) { mesg = "grid_ieee"; len = strlen(mesg); @@ -2350,10 +2409,20 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datat else GRIB_CHECK(grib_set_long(gh, "precision", 1), 0); } - else if ( ljpeg && editionNumber == 2 ) + else if ( ljpeg ) { - mesg = "grid_jpeg"; len = strlen(mesg); - GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0); + if ( nmiss > 0 ) ljpeg = 0; + + if ( ljpeg ) + { + mesg = "grid_jpeg"; len = strlen(mesg); + GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0); + } + else + { + mesg = "grid_simple"; len = strlen(mesg); + GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0); + } } else { @@ -2465,7 +2534,7 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datat GRIB_CHECK(grib_set_long(gh, "numberOfGridUsed", gridInqNumber(gridID)), 0); GRIB_CHECK(grib_set_long(gh, "numberOfGridInReference", gridInqPosition(gridID)), 0); len = 16; - GRIB_CHECK(grib_set_string(gh, "uuidOfHGrid", gridInqUUID(gridID, uuid), &len), 0); + GRIB_CHECK(grib_set_bytes(gh, "uuidOfHGrid", (unsigned char *) gridInqUUID(gridID, uuid), &len), 0); } break; @@ -2473,25 +2542,33 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg, int lieee, int datat default: { Error("Unsupported grid type: %s", gridNamePtr(gridtype)); + break; } } } -#endif -#if defined (HAVE_LIBGRIB_API) static -void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) +void getLevelFactor(double level, long *factor, double *scale) +{ + double dum; + + if ( level >= 1 && (int)(1000*modf(level, &dum)) == 0 ) { *factor = 0; *scale = 1; } + else if ( level >= 0.1 && (int)(1000*modf(level*10, &dum)) == 0 ) { *factor = 1; *scale = 10; } + else if ( level >= 0.01 && (int)(1000*modf(level*100, &dum)) == 0 ) { *factor = 2; *scale = 100; } + else if ( level >= 0.001 && (int)(1000*modf(level*1000, &dum)) == 0 ) { *factor = 3; *scale = 1000; } + else { *factor = 2; *scale = 10; } +} + +static +void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, int levelID, int gcinit) { double level; int zaxistype, ltype; static int warning = 1; - long editionNumber; int reference; char uuid[17]; size_t len; - GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); - zaxistype = zaxisInqType(zaxisID); ltype = zaxisInqLtype(zaxisID); level = zaxisInqLevel(zaxisID, levelID); @@ -2499,8 +2576,7 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) if ( zaxistype == ZAXIS_GENERIC && ltype == 0 ) { Message("Changed zaxis type from %s to %s", - zaxisNamePtr(zaxistype), - zaxisNamePtr(ZAXIS_PRESSURE)); + zaxisNamePtr(zaxistype), zaxisNamePtr(ZAXIS_PRESSURE)); zaxistype = ZAXIS_PRESSURE; zaxisChangeType(zaxisID, zaxistype); zaxisDefUnits(zaxisID, "Pa"); @@ -2511,42 +2587,106 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) case ZAXIS_SURFACE: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SURFACE), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SURFACE), 0); - GRIB_CHECK(grib_set_long(gh, "level", level), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SURFACE), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SURFACE), 0); + } + + GRIB_CHECK(grib_set_long(gh, "level", level), 0); + break; } + case ZAXIS_CLOUD_BASE: + { + if ( editionNumber <= 1 ) + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_CLOUDBASE), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_CLOUDBASE), 0); + } + + break; + } + case ZAXIS_CLOUD_TOP: + { + if ( editionNumber <= 1 ) + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_CLOUDTOP), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_CLOUDTOP), 0); + } + + break; + } + case ZAXIS_ISOTHERM_ZERO: + { + if ( editionNumber <= 1 ) + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ISOTHERM0), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ISOTHERM0), 0); + } + + break; + } case ZAXIS_TOA: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_TOA), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_TOA), 0); - break; + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_TOA), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_TOA), 0); + } + + break; } case ZAXIS_SEA_BOTTOM: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SEA_BOTTOM), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SEA_BOTTOM), 0); - break; + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SEA_BOTTOM), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SEA_BOTTOM), 0); + } + + break; } case ZAXIS_ATMOSPHERE: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ATMOSPHERE), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ATMOSPHERE), 0); - break; + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ATMOSPHERE), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ATMOSPHERE), 0); + } + + break; } case ZAXIS_MEANSEA: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_MEANSEA), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_MEANSEA), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_MEANSEA), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_MEANSEA), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2555,18 +2695,18 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) case ZAXIS_HYBRID: case ZAXIS_HYBRID_HALF: { - int vctsize; - if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) ) { long level1, level2; if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID_LAYER), 0); - else { - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID), 0); - GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_HYBRID), 0); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID_LAYER), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID), 0); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_HYBRID), 0); } level1 = zaxisInqLbound(zaxisID, levelID); @@ -2578,23 +2718,30 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) else { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID), 0); + } GRIB_CHECK(grib_set_long(gh, "level", level), 0); } - vctsize = zaxisInqVctSize(zaxisID); - if ( vctsize == 0 && warning ) - { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); - Warning("VCT missing ( param = %s, zaxisID = %d )", paramstr, zaxisID); - warning = 0; - } - GRIB_CHECK(grib_set_long(gh, "PVPresent", 1), 0); - GRIB_CHECK(grib_set_double_array(gh, "pv", zaxisInqVctPtr(zaxisID), vctsize), 0); + if ( !gcinit ) + { + int vctsize = zaxisInqVctSize(zaxisID); + if ( vctsize == 0 && warning ) + { + char paramstr[32]; + cdiParamToString(param, paramstr, sizeof(paramstr)); + Warning("VCT missing ( param = %s, zaxisID = %d )", paramstr, zaxisID); + warning = 0; + } + GRIB_CHECK(grib_set_long(gh, "PVPresent", 1), 0); + GRIB_CHECK(grib_set_double_array(gh, "pv", zaxisInqVctPtr(zaxisID), vctsize), 0); + } break; } @@ -2611,18 +2758,27 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) if ( level < 32768 && (level < 100 || modf(level/100, &dum) > 0) ) { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_99), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB1_LTYPE_99), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_99), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB1_LTYPE_99), 0); + } + GRIB_CHECK(grib_set_double(gh, "level", level), 0); } else { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ISOBARIC), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ISOBARIC), 0); - //GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ISOBARIC), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ISOBARIC), 0); + } + //GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level), 0); GRIB_CHECK(grib_set_double(gh, "level", level/100), 0); } @@ -2630,10 +2786,14 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) } case ZAXIS_HEIGHT: { - if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HEIGHT), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_HEIGHT), 0); + if ( editionNumber <= 1 ) + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HEIGHT), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_HEIGHT), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2641,10 +2801,14 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) } case ZAXIS_ALTITUDE: { - if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ALTITUDE), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ALTITUDE), 0); + if ( editionNumber <= 1 ) + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ALTITUDE), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ALTITUDE), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2653,9 +2817,13 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) case ZAXIS_SIGMA: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SIGMA), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SIGMA), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SIGMA), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SIGMA), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2675,35 +2843,43 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) else if ( memcmp(units, "dm", 2) == 0 ) factor = 10; else factor = 100; // meter - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_LANDDEPTH), 0); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_LANDDEPTH), 0); GRIB_CHECK(grib_set_double(gh, "level", level*factor), 0); } else { long factor; - if ( memcmp(units, "mm", 2) == 0 ) factor = 3; - else if ( memcmp(units, "cm", 2) == 0 ) factor = 2; - else if ( memcmp(units, "dm", 2) == 0 ) factor = 1; - else factor = 0; // meter + double scale; + double scalefactor; + + if ( memcmp(units, "mm", 2) == 0 ) scalefactor = 0.001; + else if ( memcmp(units, "cm", 2) == 0 ) scalefactor = 0.01; + else if ( memcmp(units, "dm", 2) == 0 ) scalefactor = 0.1; + else scalefactor = 1; // meter if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) ) { double level1, level2; - level1 = zaxisInqLbound(zaxisID, levelID); - level2 = zaxisInqUbound(zaxisID, levelID); + level1 = scalefactor*zaxisInqLbound(zaxisID, levelID); + level2 = scalefactor*zaxisInqUbound(zaxisID, levelID); - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); + getLevelFactor(level1, &factor, &scale); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0); - GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level1), 0); - GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); + GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level1*scale), 0); + + getLevelFactor(level, &factor, &scale); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); GRIB_CHECK(grib_set_long(gh, "scaleFactorOfSecondFixedSurface", factor), 0); - GRIB_CHECK(grib_set_double(gh, "scaledValueOfSecondFixedSurface", level2), 0); + GRIB_CHECK(grib_set_double(gh, "scaledValueOfSecondFixedSurface", level2*scale), 0); } else - { - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); + { + level *= scalefactor; + getLevelFactor(level, &factor, &scale); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0); - GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level), 0); + GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level*scale), 0); } } @@ -2712,9 +2888,13 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) case ZAXIS_DEPTH_BELOW_SEA: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SEADEPTH), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SEADEPTH), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_SEADEPTH), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_SEADEPTH), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2723,9 +2903,13 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) case ZAXIS_ISENTROPIC: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ISENTROPIC), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ISENTROPIC), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_ISENTROPIC), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_ISENTROPIC), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2738,23 +2922,27 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) else { reference = zaxisInqReference(zaxisID); - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_REFERENCE), 0); - GRIB_CHECK(grib_set_double(gh, "level", level), 0); - - GRIB_CHECK(grib_set_long(gh, "NV", 3), 0); - GRIB_CHECK(grib_set_long(gh, "nlev", (long) zaxisInqSize(zaxisID)), 0); - GRIB_CHECK(grib_set_long(gh, "numberOfVGridUsed", reference), 0); + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_REFERENCE), 0); + GRIB_CHECK(grib_set_long(gh, "NV", 6), 0); + GRIB_CHECK(grib_set_double(gh, "nlev", (double) zaxisInqSize(zaxisID)), 0); + GRIB_CHECK(grib_set_double(gh, "numberOfVGridUsed", (double) reference), 0); len = 16; - GRIB_CHECK(grib_set_string(gh, "uuidOfVGrid", zaxisInqUUID(zaxisID, uuid), &len), 0); + GRIB_CHECK(grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) zaxisInqUUID(zaxisID, uuid), &len), 0); + GRIB_CHECK(grib_set_double(gh, "level", level), 0); } + break; } case ZAXIS_GENERIC: { if ( editionNumber <= 1 ) - GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", ltype), 0); - else - GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", ltype), 0); + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", ltype), 0); + } + else + { + if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", ltype), 0); + } GRIB_CHECK(grib_set_double(gh, "level", level), 0); @@ -2769,7 +2957,6 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) } #endif - void *gribHandleNew(int editionNumber) { void *gh = NULL; @@ -2810,7 +2997,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI int lieee = FALSE; int ensID, ensCount, forecast_type; /* Ensemble Data */ long bitsPerValue; - long editionNumber; + long editionNumber = 2; char name[256]; grib_handle *gh = NULL; gribContainer_t *gc = (gribContainer_t *) gribContainer; @@ -2821,7 +3008,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI vlistInqVarName(vlistID, varID, name); #if defined(GRIBAPIENCODETEST) - gh = (grib_handle *) gribHandleNew(); + gh = (grib_handle *) gribHandleNew(editionNumber); #else gh = gc->gribHandle; #endif @@ -2831,16 +3018,16 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI if ( ! gc->init ) gribapiDefInstitut(gh, vlistID, varID); if ( ! gc->init ) gribapiDefModel(gh, vlistID, varID); - if ( ! gc->init ) gribapiDefParam(gh, param, name); + if ( ! gc->init ) gribapiDefParam(editionNumber, gh, param, name); /* - if( !vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) ) + if( vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) ) { GRIB_CHECK(grib_set_long(gh, "typeOfEnsembleForecast", forecast_type ), 0); GRIB_CHECK(grib_set_long(gh, "numberOfForecastsInEnsemble", ensCount ), 0); GRIB_CHECK(grib_set_long(gh, "perturbationNumber", ensID ), 0); } */ - gribapiDefTime(gh, vdate, vtime, tsteptype, numavg, vlistInqTaxis(vlistID)); + gribapiDefTime(editionNumber, gh, vdate, vtime, tsteptype, numavg, vlistInqTaxis(vlistID), gc->init); if ( editionNumber == 2 && (datatype == DATATYPE_FLT32 || datatype == DATATYPE_FLT64) ) lieee = TRUE; @@ -2851,9 +3038,30 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI GRIB_CHECK(grib_set_long(gh, "bitsPerValue", bitsPerValue), 0); } - if ( ! gc->init ) gribapiDefGrid(gh, gridID, ljpeg, lieee, datatype); + gribapiDefGrid(editionNumber, gh, gridID, ljpeg, lieee, datatype, nmiss, gc->init); + + gribapiDefLevel(editionNumber, gh, param, zaxisID, levelID, gc->init); + + /* ---------------------------------- */ + /* Local change: 2013-01-28, FP (DWD) */ + /* ---------------------------------- */ + + vlist_t *vlistptr; + vlistptr = vlist_to_pointer(vlistID); + if (!gc->init) { + int i; + for (i=0; i<vlistptr->vars[varID].opt_grib_dbl_nentries; i++) + { + GRIB_CHECK(grib_set_double(gh, vlistptr->vars[varID].opt_grib_dbl_keyword[i], + vlistptr->vars[varID].opt_grib_dbl_val[i]), 0); + } + for (i=0; i<vlistptr->vars[varID].opt_grib_int_nentries; i++) + { + GRIB_CHECK(grib_set_long(gh, vlistptr->vars[varID].opt_grib_int_keyword[i], + vlistptr->vars[varID].opt_grib_int_val[i]), 0); + } + } - gribapiDefLevel(gh, param, zaxisID, levelID); if ( nmiss > 0 ) { @@ -2885,6 +3093,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI return (nbytes); } + /* * Local Variables: * c-file-style: "Java" diff --git a/src/stream_gribapi.h b/src/stream_gribapi.h index b068f3eed..380d0d631 100644 --- a/src/stream_gribapi.h +++ b/src/stream_gribapi.h @@ -1,9 +1,9 @@ #ifndef _STREAM_GRIBAPI_H #define _STREAM_GRIBAPI_H -int gribapiScanTimestep1(int streamID); -int gribapiScanTimestep2(int streamID); -int gribapiScanTimestep(int streamID); +int gribapiScanTimestep1(stream_t * streamptr); +int gribapiScanTimestep2(stream_t * streamptr); +int gribapiScanTimestep(stream_t * streamptr); int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize, int unreduced, int *nmiss, int *zip, double missval); diff --git a/src/stream_history.c b/src/stream_history.c index 41e469372..558482c6c 100644 --- a/src/stream_history.c +++ b/src/stream_history.c @@ -27,7 +27,7 @@ void streamDefHistory(int streamID, int length, const char *history) if ( len ) { histstring = strdupx(history); - cdfDefHistory(streamID, length, histstring); + cdfDefHistory(streamptr, length, histstring); free(histstring); } } @@ -47,7 +47,7 @@ int streamInqHistorySize(int streamID) streamptr->filetype == FILETYPE_NC4 || streamptr->filetype == FILETYPE_NC4C ) { - size = cdfInqHistorySize(streamID); + size = cdfInqHistorySize(streamptr); } return (size); @@ -65,7 +65,7 @@ void streamInqHistoryString(int streamID, char *history) streamptr->filetype == FILETYPE_NC4 || streamptr->filetype == FILETYPE_NC4C ) { - cdfInqHistoryString(streamID, history); + cdfInqHistoryString(streamptr, history); } } /* diff --git a/src/stream_ieg.c b/src/stream_ieg.c index 40481fe11..1c48d2738 100644 --- a/src/stream_ieg.c +++ b/src/stream_ieg.c @@ -31,7 +31,7 @@ typedef struct { int param; int level; -} IEGCOMPVAR; +} IEGCOMPVAR; int iegInqDatatype(int prec) @@ -62,7 +62,7 @@ int iegDefDatatype(int datatype) } /* not used -int iegInqRecord(int streamID, int *varID, int *levelID) +int iegInqRecord(stream_t *streamptr, int *varID, int *levelID) { int status; int fileID; @@ -70,14 +70,9 @@ int iegInqRecord(int streamID, int *varID, int *levelID) int zaxisID = -1; int vlistID; iegrec_t *iegp; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; iegp = streamptr->record->iegp; *varID = -1; @@ -99,12 +94,12 @@ int iegInqRecord(int streamID, int *varID, int *levelID) zaxisID = vlistInqVarZaxis(vlistID, *varID); *levelID = zaxisInqLevelID(zaxisID, (double) ilevel); - + return (1); } */ -int iegReadRecord(int streamID, double *data, int *nmiss) +int iegReadRecord(stream_t *streamptr, double *data, int *nmiss) { int vlistID, fileID; int status; @@ -114,14 +109,9 @@ int iegReadRecord(int streamID, double *data, int *nmiss) int i, size; double missval; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; vrecID = streamptr->tsteps[tsID].curRecID; recID = streamptr->tsteps[tsID].recIDs[vrecID]; @@ -536,7 +526,7 @@ void iegDefLevel(int *pdb, int *gdb, double *vct, int zaxisID, int levelID) } -int iegCopyRecord(int streamID2, int streamID1) +int iegCopyRecord(stream_t *streamptr2, stream_t *streamptr1) { int fileID1, fileID2; int tsID, recID, vrecID; @@ -544,17 +534,9 @@ int iegCopyRecord(int streamID2, int streamID1) off_t recpos; int status = 0; char *buffer; - stream_t *streamptr1; - stream_t *streamptr2; - streamptr1 = stream_to_pointer(streamID1); - streamptr2 = stream_to_pointer(streamID2); - - stream_check_ptr(__func__, streamptr1); - stream_check_ptr(__func__, streamptr2); - - fileID1 = streamInqFileID(streamID1); - fileID2 = streamInqFileID(streamID2); + fileID1 = streamptr1->fileID; + fileID2 = streamptr2->fileID; tsID = streamptr1->curTsID; vrecID = streamptr1->tsteps[tsID].curRecID; @@ -576,7 +558,7 @@ int iegCopyRecord(int streamID2, int streamID1) } -int iegDefRecord(int streamID) +int iegDefRecord(stream_t *streamptr) { int status = 0; int vlistID; @@ -588,13 +570,8 @@ int iegDefRecord(int streamID) int varID, levelID, tsID, zaxisID; int byteorder; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; iegp = streamptr->record->iegp; byteorder = streamptr->byteorder; @@ -604,7 +581,7 @@ int iegDefRecord(int streamID) gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); - + iegInitMem(iegp); for ( i = 0; i < 37; i++ ) iegp->ipdb[i] = -1; @@ -629,23 +606,18 @@ int iegDefRecord(int streamID) } -int iegWriteRecord(int streamID, const double *data) +int iegWriteRecord(stream_t *streamptr, const double *data) { int fileID; int status = 0; int i, gridsize, gridID; double refval; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - stream_check_ptr(__func__, streamptr); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; iegp = streamptr->record->iegp; gridID = streamptr->record->gridID; - + gridsize = gridInqSize(gridID); refval = data[0]; @@ -662,7 +634,7 @@ int iegWriteRecord(int streamID, const double *data) } static -void iegAddRecord(int streamID, int param, int *pdb, int *gdb, double *vct, +void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vct, long recsize, off_t position, int prec) { int leveltype; @@ -676,13 +648,10 @@ void iegAddRecord(int streamID, int param, int *pdb, int *gdb, double *vct, record_t *record; grid_t grid; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; tsID = streamptr->curTsID; - recID = recordNewEntry(streamID, tsID); + recID = recordNewEntry(streamptr, tsID); record = &streamptr->tsteps[tsID].records[recID]; if ( IEG_P_LevelType(pdb) == IEG_LTYPE_HYBRID_LAYER ) @@ -783,7 +752,7 @@ void iegAddRecord(int streamID, int param, int *pdb, int *gdb, double *vct, gridID = varDefGrid(vlistID, grid, 0); leveltype = iegGetZaxisType(IEG_P_LevelType(pdb)); - + if ( leveltype == ZAXIS_HYBRID ) { int i; @@ -800,7 +769,7 @@ void iegAddRecord(int streamID, int param, int *pdb, int *gdb, double *vct, datatype = iegInqDatatype(prec); - varAddRecord(recID, param, gridID, leveltype, lbounds, level1, level2, + varAddRecord(recID, param, gridID, leveltype, lbounds, level1, level2, 0, datatype, &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL); (*record).varID = varID; @@ -816,15 +785,12 @@ void iegAddRecord(int streamID, int param, int *pdb, int *gdb, double *vct, #if 0 static -void iegCmpRecord(int streamID, int tsID, int recID, off_t position, int param, +void iegCmpRecord(stream_t *streamptr, int tsID, int recID, off_t position, int param, int level, int xsize, int ysize) { int varID = 0; int levelID = 0; record_t *record; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); record = &streamptr->tsteps[tsID].records[recID]; @@ -865,8 +831,8 @@ void iegDateTime(int *pdb, int *date, int *time) } static -void iegScanTimestep1(int streamID) -{ +void iegScanTimestep1(stream_t *streamptr) +{ int prec = 0; int status; int fileID; @@ -884,22 +850,17 @@ void iegScanTimestep1(int streamID) int vlistID; IEGCOMPVAR compVar, compVar0; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); streamptr->curTsID = 0; iegp = streamptr->record->iegp; - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); taxis = &streamptr->tsteps[tsID].taxis; if ( tsID != 0 ) Error("Internal problem! tstepsNewEntry returns %d", tsID); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; nrecs = 0; while ( TRUE ) @@ -955,22 +916,22 @@ void iegScanTimestep1(int streamID) if ( CDI_Debug ) Message("%4d%8d%4d%8d%8d%6d", nrecs, (int)recpos, param, rlevel, vdate, vtime); - iegAddRecord(streamID, param, iegp->ipdb, iegp->igdb, iegp->vct, recsize, recpos, prec); + iegAddRecord(streamptr, param, iegp->ipdb, iegp->igdb, iegp->vct, recsize, recpos, prec); } streamptr->rtsteps = 1; - cdiGenVars(streamID); + cdi_generate_vars(streamptr); taxisID = taxisCreate(TAXIS_ABSOLUTE); taxis->type = TAXIS_ABSOLUTE; taxis->vdate = datetime0.date; taxis->vtime = datetime0.time; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; vlistDefTaxis(vlistID, taxisID); - cdiCheckContents(streamID); + vlist_check_contents(vlistID); nrecords = streamptr->tsteps[0].nallrecs; if ( nrecords < streamptr->tsteps[0].recordSize ) @@ -987,7 +948,7 @@ void iegScanTimestep1(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1009,8 +970,8 @@ void iegScanTimestep1(int streamID) } static -int iegScanTimestep2(int streamID) -{ +int iegScanTimestep2(stream_t *streamptr) +{ int status; int fileID; int tabnum; @@ -1026,16 +987,11 @@ int iegScanTimestep2(int streamID) int vlistID; IEGCOMPVAR compVar, compVar0; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); streamptr->curTsID = 1; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; iegp = streamptr->record->iegp; tsID = streamptr->rtsteps; @@ -1046,7 +1002,7 @@ int iegScanTimestep2(int streamID) fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecords = streamptr->tsteps[0].nallrecs; streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); @@ -1057,9 +1013,9 @@ int iegScanTimestep2(int streamID) for ( recID = 0; recID < nrecords; recID++ ) { varID = streamptr->tsteps[0].records[recID].varID; - streamptr->tsteps[tsID].records[recID].position = + streamptr->tsteps[tsID].records[recID].position = streamptr->tsteps[0].records[recID].position; - streamptr->tsteps[tsID].records[recID].size = + streamptr->tsteps[tsID].records[recID].size = streamptr->tsteps[0].records[recID].size; } @@ -1165,7 +1121,7 @@ int iegScanTimestep2(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1177,23 +1133,18 @@ int iegScanTimestep2(int streamID) } -int iegInqContents(int streamID) +int iegInqContents(stream_t *streamptr) { int fileID; int status = 0; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; streamptr->curTsID = 0; - iegScanTimestep1(streamID); - - if ( streamptr->ntsteps == -1 ) status = iegScanTimestep2(streamID); + iegScanTimestep1(streamptr); + + if ( streamptr->ntsteps == -1 ) status = iegScanTimestep2(streamptr); fileSetPos(fileID, 0, SEEK_SET); @@ -1201,7 +1152,7 @@ int iegInqContents(int streamID) } static -int iegScanTimestep(int streamID) +int iegScanTimestep(stream_t *streamptr) { int status; int fileID; @@ -1216,15 +1167,10 @@ int iegScanTimestep(int streamID) int rindex, nrecs = 0; IEGCOMPVAR compVar, compVar0; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( CDI_Debug ) { - Message("streamID = %d", streamID); + Message("streamID = %d", streamptr->self); Message("cts = %d", streamptr->curTsID); Message("rts = %d", streamptr->rtsteps); Message("nts = %d", streamptr->ntsteps); @@ -1239,7 +1185,7 @@ int iegScanTimestep(int streamID) if ( streamptr->tsteps[tsID].recordSize == 0 ) { - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecs = streamptr->tsteps[1].nrecs; @@ -1248,7 +1194,7 @@ int iegScanTimestep(int streamID) for ( recID = 0; recID < nrecs; recID++ ) streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID]; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); @@ -1312,7 +1258,7 @@ int iegScanTimestep(int streamID) if ( streamptr->ntsteps != streamptr->rtsteps ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -1334,24 +1280,19 @@ int iegScanTimestep(int streamID) } -int iegInqTimestep(int streamID, int tsID) +int iegInqTimestep(stream_t *streamptr, int tsID) { int ntsteps, nrecs; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( tsID == 0 && streamptr->rtsteps == 0 ) Error("Call to cdiInqContents missing!"); if ( CDI_Debug ) Message("tsID = %d rtsteps = %d", tsID, streamptr->rtsteps); - + ntsteps = UNDEFID; while ( ( tsID + 1 ) > streamptr->rtsteps && ntsteps == UNDEFID ) - ntsteps = iegScanTimestep(streamID); + ntsteps = iegScanTimestep(streamptr); if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID ) { @@ -1367,7 +1308,7 @@ int iegInqTimestep(int streamID, int tsID) } -void iegReadVarDP(int streamID, int varID, double *data, int *nmiss) +void iegReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss) { int vlistID, fileID; int levID, nlevs, gridID, gridsize; @@ -1377,13 +1318,10 @@ void iegReadVarDP(int streamID, int varID, double *data, int *nmiss) int i; double missval; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); iegp = streamptr->record->iegp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; nlevs = streamptr->vars[varID].nlevs; missval = vlistInqVarMissval(vlistID, varID); gridID = vlistInqVarGrid(vlistID, varID); @@ -1415,7 +1353,7 @@ void iegReadVarDP(int streamID, int varID, double *data, int *nmiss) } -void iegReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nmiss) +void iegReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data, int *nmiss) { int vlistID, fileID; int nlevs, gridID, gridsize; @@ -1425,13 +1363,10 @@ void iegReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm int i; double missval; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); iegp = streamptr->record->iegp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; nlevs = streamptr->vars[varID].nlevs; missval = vlistInqVarMissval(vlistID, varID); gridID = vlistInqVarGrid(vlistID, varID); @@ -1462,7 +1397,7 @@ void iegReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm } -void iegWriteVarDP(int streamID, int varID, const double *data) +void iegWriteVarDP(stream_t *streamptr, int varID, const double *data) { int fileID; int levID, nlevs, gridID, gridsize; @@ -1475,20 +1410,17 @@ void iegWriteVarDP(int streamID, int varID, const double *data) int param, pdis, pcat, pnum; double refval; iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); + Message("streamID = %d varID = %d", streamptr->self, varID); iegp = streamptr->record->iegp; iegInitMem(iegp); for ( i = 0; i < 37; i++ ) iegp->ipdb[i] = -1; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; gridID = vlistInqVarGrid(vlistID, varID); gridsize = gridInqSize(gridID); @@ -1528,7 +1460,7 @@ void iegWriteVarDP(int streamID, int varID, const double *data) } -void iegWriteVarSliceDP(int streamID, int varID, int levID, const double *data) +void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double *data) { int fileID; int gridID; @@ -1539,13 +1471,10 @@ void iegWriteVarSliceDP(int streamID, int varID, int levID, const double *data) int vlistID; /* int param, date, time, datasize; */ iegrec_t *iegp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); iegp = streamptr->record->iegp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; /* tsID = streamptr->curTsID; */ gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); diff --git a/src/stream_ieg.h b/src/stream_ieg.h index 7b5c76f7e..860cedbb1 100644 --- a/src/stream_ieg.h +++ b/src/stream_ieg.h @@ -5,20 +5,20 @@ # include "ieg.h" #endif -int iegInqContents(int streamID); -int iegInqTimestep(int streamID, int tsID); +int iegInqContents(stream_t *streamptr); +int iegInqTimestep(stream_t *streamptr, int tsID); -int iegInqRecord(int streamID, int *varID, int *levelID); -int iegDefRecord(int streamID); -int iegCopyRecord(int streamIDdest, int streamIDsrc); -int iegReadRecord(int streamID, double *data, int *nmiss); -int iegWriteRecord(int streamID, const double *data); +int iegInqRecord(stream_t *streamptr, int *varID, int *levelID); +int iegDefRecord(stream_t *streamptr); +int iegCopyRecord(stream_t *streamptr2, stream_t *streamptr1); +int iegReadRecord(stream_t *streamptr, double *data, int *nmiss); +int iegWriteRecord(stream_t *streamptr, const double *data); -void iegReadVarDP (int streamID, int varID, double *data, int *nmiss); -void iegWriteVarDP(int streamID, int varID, const double *data); +void iegReadVarDP (stream_t *streamptr, int varID, double *data, int *nmiss); +void iegWriteVarDP(stream_t *streamptr, int varID, const double *data); -void iegReadVarSliceDP (int streamID, int varID, int levelID, double *data, int *nmiss); -void iegWriteVarSliceDP(int streamID, int varID, int levelID, const double *data); +void iegReadVarSliceDP (stream_t *streamptr, int varID, int levelID, double *data, int *nmiss); +void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levelID, const double *data); #endif /* _STREAM_IEG_H */ /* diff --git a/src/stream_int.c b/src/stream_int.c index fe2e82890..632c6b401 100644 --- a/src/stream_int.c +++ b/src/stream_int.c @@ -29,9 +29,11 @@ int cdiDefaultModelID = CDI_UNDEFID; int cdiDefaultTableID = CDI_UNDEFID; int cdiNcMissingValue = CDI_UNDEFID; int cdiNcChunksizehint = CDI_UNDEFID; +int cdiChunkType = CHUNK_GRID; int cdiSplitLtype105 = CDI_UNDEFID; int cdiIgnoreAttCoordinates = FALSE; +int cdiIgnoreValidRange = FALSE; int cdiSkipRecords = 0; int cdiInventoryMode = 1; @@ -47,6 +49,7 @@ char *Filetypes[] = { "netCDF", "netCDF2", "netCDF4", + "netCDF4c", "SERVICE", "EXTRA", "IEG", @@ -111,6 +114,7 @@ long cdiGetenvInt(char *envName) fact = 0; Message("Invalid number string in %s: %s", envName, envString); Warning("%s must comprise only digits [0-9].",envName); + break; } break; } @@ -124,6 +128,42 @@ long cdiGetenvInt(char *envName) return (envValue); } +static +void cdiSetChunk(const char *chunkAlgo) +{ + //char *pch; + //size_t len = strlen(chunkAlgo); + int algo = -1; + + if ( strcmp("auto", chunkAlgo) == 0 ) algo = CHUNK_AUTO; + else if ( strcmp("grid", chunkAlgo) == 0 ) algo = CHUNK_GRID; + else if ( strcmp("lines", chunkAlgo) == 0 ) algo = CHUNK_LINES; + /* + else if ( (pch = strstr(chunkAlgo,"x")) != 0 ) + { + int ix, iy; + ix = atoi(chunkAlgo); + iy = atoi(pch+1); + if ( ix > 0 && iy > 0 ) + { + cdiChunkX = ix; + cdiChunkY = iy; + algo = CHUNK_USER; + } + else + Warning("Invalid environment variable CDI_CHUNK_ALGO: %s", chunkAlgo); + } + */ + else + Warning("Invalid environment variable CDI_CHUNK_ALGO: %s", chunkAlgo); + + if ( algo != -1 ) + { + cdiChunkType = algo; + if ( CDI_Debug ) Message("set ChunkAlgo to %s", chunkAlgo); + } +} + void cdiInitialize(void) { @@ -140,9 +180,6 @@ void cdiInitialize(void) gribSetConst(1); // 1: Don't pack constant fields on regular grids #endif - value = cdiGetenvInt("CD_REGULARGRID"); - if ( value >= 0 ) cdiDataUnreduced = (int) value; - value = cdiGetenvInt("CDI_REGULARGRID"); if ( value >= 0 ) cdiDataUnreduced = (int) value; @@ -152,15 +189,9 @@ void cdiInitialize(void) value = cdiGetenvInt("CDI_HAVE_MISSVAL"); if ( value >= 0 ) cdiHaveMissval = (int) value; - value = cdiGetenvInt("CD_LEVELTYPE"); - if ( value >= 0 ) cdiDefaultLeveltype = (int) value; - value = cdiGetenvInt("CDI_LEVELTYPE"); if ( value >= 0 ) cdiDefaultLeveltype = (int) value; - envString = getenv("CD_MISSVAL"); - if ( envString ) cdiDefaultMissval = atof(envString); - envString = getenv("CDI_MISSVAL"); if ( envString ) cdiDefaultMissval = atof(envString); @@ -170,12 +201,18 @@ void cdiInitialize(void) envString = getenv("NC_CHUNKSIZEHINT"); if ( envString ) cdiNcChunksizehint = atoi(envString); + envString = getenv("CDI_CHUNK_ALGO"); + if ( envString ) cdiSetChunk(envString); + envString = getenv("SPLIT_LTYPE_105"); if ( envString ) cdiSplitLtype105 = atoi(envString); envString = getenv("IGNORE_ATT_COORDINATES"); if ( envString ) cdiIgnoreAttCoordinates = atoi(envString); + envString = getenv("IGNORE_VALID_RANGE"); + if ( envString ) cdiIgnoreValidRange = atoi(envString); + envString = getenv("CDI_SKIP_RECORDS"); if ( envString ) { @@ -237,7 +274,7 @@ char *strfiletype(int filetype) if ( filetype > 0 && filetype < size ) name = Filetypes[filetype]; else - name = Filetypes[0]; + name = Filetypes[0]; return (name); } @@ -248,7 +285,6 @@ stream_t *stream_to_pointer(int idx) return ( stream_t *) reshGetVal ( idx, &streamOps ); } - static void streamDefaultValue ( stream_t * streamptr ) { @@ -393,17 +429,10 @@ double cdiInqMissval(void) } -void cdiCheckContents(int streamID) +void vlist_check_contents(int vlistID) { int index, nzaxis, zaxisID; - int vlistID; - stream_t *streamptr; - streamptr = ( stream_t *) reshGetVal ( streamID, &streamOps ); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); nzaxis = vlistNzaxis(vlistID); for ( index = 0; index < nzaxis; index++ ) @@ -424,7 +453,8 @@ int streamInqFileID(int streamID) return (streamptr->fileID); } - +/* not used anymore */ +/* void streamDefineTaxis(int streamID) { stream_t *streamptr; @@ -436,7 +466,7 @@ void streamDefineTaxis(int streamID) int varID, nvars; int vlistID; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; nvars = vlistNvars(vlistID); for ( varID = 0; varID < nvars; varID++ ) @@ -459,7 +489,7 @@ void streamDefineTaxis(int streamID) Error("time axis undefined"); } } - +*/ void streamDefDimgroupID(int streamID, int dimgroupID) { @@ -588,14 +618,14 @@ void streamPrintP ( void * streamptr, FILE * fp ) fprintf ( fp, "nrecs = %d\n", sp->nrecs ); fprintf ( fp, "nvars = %d\n", sp->nvars ); fprintf ( fp, "varlocked = %d\n", sp->varlocked ); - fprintf ( fp, "//SVARINFO *vars;\n" ); + fprintf ( fp, "//svarinfo_t *vars;\n" ); fprintf ( fp, "varsAllocated = %d\n", sp->varsAllocated ); fprintf ( fp, "varinit = %d\n", sp->varinit ); fprintf ( fp, "curTsID = %d\n", sp->curTsID ); fprintf ( fp, "rtsteps = %d\n", sp->rtsteps ); fprintf ( fp, "//long ntsteps;\n" ); fprintf ( fp, "numTimestep = %d\n", sp->numTimestep ); - fprintf ( fp, "// TSTEPS *tsteps;\n" ); + fprintf ( fp, "// tsteps_t *tsteps;\n" ); fprintf ( fp, "tstepsTableSize= %d\n", sp->tstepsTableSize ); fprintf ( fp, "tstepsNextID = %d\n", sp->tstepsNextID ); fprintf ( fp, "//BaseTime basetime;\n" ); @@ -619,7 +649,7 @@ void streamPrintP ( void * streamptr, FILE * fp ) fprintf ( fp, "curfile = %d\n", sp->curfile ); fprintf ( fp, "nfiles = %d\n", sp->nfiles ); fprintf ( fp, "// char **fnames;\n" ); - fprintf ( fp, "// void *gribContainers;\n" ); + fprintf ( fp, "// void **gribContainers;\n" ); fprintf ( fp, "vlistIDorig = %d\n", sp->vlistIDorig ); } diff --git a/src/stream_int.h b/src/stream_int.h index e562e5298..3e35ee754 100644 --- a/src/stream_int.h +++ b/src/stream_int.h @@ -104,7 +104,6 @@ char *strdup(const char *s); #define MEMTYPE_DOUBLE 1 #define MEMTYPE_FLOAT 2 - typedef struct { void *buffer; @@ -134,7 +133,7 @@ typedef struct srvrec_t *srvp; #endif #if defined (HAVE_LIBEXTRA) - extrec_t *extp; + extrec_t *extp; #endif #if defined (HAVE_LIBIEG) iegrec_t *iegp; @@ -155,6 +154,7 @@ typedef struct short used; short varID; short levelID; + char varname[32]; /* needed for grib decoding with GRIB_API */ } record_t; @@ -172,7 +172,7 @@ typedef struct { off_t position; /* timestep file position */ taxis_t taxis; } -TSTEPS; +tsteps_t; typedef struct { @@ -186,9 +186,8 @@ typedef struct { int gridID; int zaxisID; int tsteptype; /* TSTEP_* */ - int nlevel; } -SVARINFO; +svarinfo_t; typedef struct { @@ -201,56 +200,66 @@ VCT; typedef struct { - int self; - int accesstype; /* TYPE_REC or TYPE_VAR */ - int accessmode; - int filetype; - int byteorder; - int fileID; - int dimgroupID; - int filemode; - off_t numvals; - char *filename; - Record *record; - int nrecs; /* number of records */ - int nvars; /* number of variables */ - int varlocked; /* variables locked */ - SVARINFO *vars; - int varsAllocated; - int varinit; - int curTsID; /* current timestep ID */ - int rtsteps; /* number of tsteps accessed */ - long ntsteps; /* number of tsteps : only set if all records accessed */ - int numTimestep; /* number of tsteps : only set if all records accessed */ - TSTEPS *tsteps; - int tstepsTableSize; - int tstepsNextID; - BaseTime basetime; - int ncmode; - int vlistID; - int xdimID[MAX_GRIDS_PS]; - int ydimID[MAX_GRIDS_PS]; - int zaxisID[MAX_ZAXES_PS]; - int ncxvarID[MAX_GRIDS_PS]; - int ncyvarID[MAX_GRIDS_PS]; - int ncavarID[MAX_GRIDS_PS]; - int historyID; - int globalatts; - int localatts; - VCT vct; - int unreduced; - int sortname; - int have_missval; - int comptype; // compression type - int complevel; // compression level - int curfile; - int nfiles; - char **fnames; - void *gribContainers; - int vlistIDorig; + int self; + int accesstype; /* TYPE_REC or TYPE_VAR */ + int accessmode; + int filetype; + int byteorder; + int fileID; + int dimgroupID; + int filemode; + off_t numvals; + char *filename; + Record *record; + int nrecs; /* number of records */ + int nvars; /* number of variables */ + int varlocked; /* variables locked */ + svarinfo_t *vars; + int varsAllocated; + int varinit; + int curTsID; /* current timestep ID */ + int rtsteps; /* number of tsteps accessed */ + long ntsteps; /* number of tsteps : only set if all records accessed */ + int numTimestep; /* number of tsteps : only set if all records accessed */ + tsteps_t *tsteps; + int tstepsTableSize; + int tstepsNextID; + BaseTime basetime; + int ncmode; + int vlistID; + int xdimID[MAX_GRIDS_PS]; + int ydimID[MAX_GRIDS_PS]; + int zaxisID[MAX_ZAXES_PS]; + int ncxvarID[MAX_GRIDS_PS]; + int ncyvarID[MAX_GRIDS_PS]; + int ncavarID[MAX_GRIDS_PS]; + int historyID; + int globalatts; + int localatts; + VCT vct; + int unreduced; + int sortname; + int have_missval; + int comptype; // compression type + int complevel; // compression level + int curfile; + int nfiles; + char **fnames; +#if defined (GRIBCONTAINER2D) + void **gribContainers; +#else + void *gribContainers; +#endif + int vlistIDorig; #if USE_MPI int ownerRank; // MPI rank of owner process #endif + + /* ---------------------------------- */ + /* Local change: 2013-02-18, FP (DWD) */ + /* ---------------------------------- */ + + void *gh; // grib handle } stream_t; @@ -263,6 +272,7 @@ extern int cdiDefaultTableID; extern int cdiDefaultLeveltype; extern int cdiNcMissingValue; extern int cdiNcChunksizehint; +extern int cdiChunkType; extern int cdiSplitLtype105; extern char *cdiPartabPath; @@ -285,21 +295,21 @@ void streamDefineTaxis(int streamID); int streamsNewEntry(int filetype); void streamsInitEntry(int streamID); -int streamNewVar(int streamID, int gridID, int zaxisID); +int stream_new_var(stream_t *streamptr, int gridID, int zaxisID); -int tstepsNewEntry(int streamID); +int tstepsNewEntry(stream_t *streamptr); char *strfiletype(int filetype); -void cdiGenVars(int streamID); +void cdi_generate_vars(stream_t *streamptr); -void cdiCheckContents(int streamID); +void vlist_check_contents(int vlistID); -void cdiCreateRecords(int streamID, int tsID); +void cdi_create_records(stream_t *streamptr, int tsID); -int recordNewEntry(int streamID, int tsID); +int recordNewEntry(stream_t *streamptr, int tsID); -void cdiCreateTimesteps(int streamID); +void cdiCreateTimesteps(stream_t *streamptr); void recordInitEntry(record_t *record); @@ -323,6 +333,9 @@ void cdiInitialize(void); void stream_write_record(int streamID, int memtype, const void *data, int nmiss); +void uuid2str(const char *uuid, char *uuidstr); +void str2uuid(const char *uuidstr, char *uuid); + #endif /* _STREAM_INT_H */ /* diff --git a/src/stream_record.c b/src/stream_record.c index 8c790d1c5..d6f0299cd 100644 --- a/src/stream_record.c +++ b/src/stream_record.c @@ -26,17 +26,15 @@ void recordInitEntry(record_t *record) (*record).used = FALSE; (*record).varID = CDI_UNDEFID; (*record).levelID = CDI_UNDEFID; + memset((*record).varname, 0, sizeof((*record).varname)); } -int recordNewEntry(int streamID, int tsID) +int recordNewEntry(stream_t *streamptr, int tsID) { int recordID = 0; int recordSize; record_t *records; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); recordSize = streamptr->tsteps[tsID].recordSize; records = streamptr->tsteps[tsID].records; @@ -97,13 +95,9 @@ int recordNewEntry(int streamID, int tsID) return (recordID); } - -void cdiInitRecord(int streamID) +static +void cdiInitRecord(stream_t *streamptr) { - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - streamptr->record = (Record *) malloc(sizeof(Record)); streamptr->record->used = 0; @@ -140,7 +134,7 @@ void streamInqRecord(int streamID, int *varID, int *levelID) cdiDefAccesstype(streamID, TYPE_REC); - if ( ! streamptr->record ) cdiInitRecord(streamID); + if ( ! streamptr->record ) cdiInitRecord(streamptr); tsID = streamptr->curTsID; rindex = streamptr->tsteps[tsID].curRecID + 1; @@ -178,7 +172,7 @@ void streamInqRecord(int streamID, int *varID, int *levelID) } case FILETYPE_SRV: { - rec = srvInqRecord(streamID, varID, levelID); + rec = srvInqRecord(streamptr, varID, levelID); break; } #if defined (HAVE_LIBNETCDF) @@ -222,9 +216,9 @@ void streamDefRecord(int streamID, int varID, int levelID) streamDefTimestep(streamID, tsID); } - if ( ! streamptr->record ) cdiInitRecord(streamID); + if ( ! streamptr->record ) cdiInitRecord(streamptr); - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); param = vlistInqVarParam(vlistID, varID); @@ -249,7 +243,7 @@ void streamDefRecord(int streamID, int varID, int levelID) case FILETYPE_GRB2: { /* FIXME: return value not inspected */ - status = grbDefRecord(streamID); + status = grbDefRecord(streamptr); break; } #endif @@ -257,7 +251,7 @@ void streamDefRecord(int streamID, int varID, int levelID) case FILETYPE_SRV: { /* FIXME: return value not inspected */ - status = srvDefRecord(streamID); + status = srvDefRecord(streamptr); break; } #endif @@ -265,7 +259,7 @@ void streamDefRecord(int streamID, int varID, int levelID) case FILETYPE_EXT: { /* FIXME: return value not inspected */ - status = extDefRecord(streamID); + status = extDefRecord(streamptr); break; } #endif @@ -273,7 +267,7 @@ void streamDefRecord(int streamID, int varID, int levelID) case FILETYPE_IEG: { /* FIXME: return value not inspected */ - status = iegDefRecord(streamID); + status = iegDefRecord(streamptr); break; } #endif @@ -283,8 +277,8 @@ void streamDefRecord(int streamID, int varID, int levelID) case FILETYPE_NC4: case FILETYPE_NC4C: { - if ( streamptr->accessmode == 0 ) cdfEndDef(streamID); - status = cdfDefRecord(streamID); + if ( streamptr->accessmode == 0 ) cdfEndDef(streamptr); + status = cdfDefRecord(streamptr); break; } #endif @@ -321,7 +315,7 @@ void streamReadRecord(int streamID, double *data, int *nmiss) case FILETYPE_GRB2: { /* FIXME: return value not inspected */ - status = grbReadRecord(streamID, data, nmiss); + status = grbReadRecord(streamptr, data, nmiss); break; } #endif @@ -329,7 +323,7 @@ void streamReadRecord(int streamID, double *data, int *nmiss) case FILETYPE_SRV: { /* FIXME: return value not inspected */ - status = srvReadRecord(streamID, data, nmiss); + status = srvReadRecord(streamptr, data, nmiss); break; } #endif @@ -337,7 +331,7 @@ void streamReadRecord(int streamID, double *data, int *nmiss) case FILETYPE_EXT: { /* FIXME: return value not inspected */ - status = extReadRecord(streamID, data, nmiss); + status = extReadRecord(streamptr, data, nmiss); break; } #endif @@ -345,7 +339,7 @@ void streamReadRecord(int streamID, double *data, int *nmiss) case FILETYPE_IEG: { /* FIXME: return value not inspected */ - status = iegReadRecord(streamID, data, nmiss); + status = iegReadRecord(streamptr, data, nmiss); break; } #endif @@ -356,7 +350,7 @@ void streamReadRecord(int streamID, double *data, int *nmiss) case FILETYPE_NC4C: { /* FIXME: return value not inspected */ - status = cdfReadRecord(streamID, data, nmiss); + status = cdfReadRecord(streamptr, data, nmiss); break; } #endif @@ -389,8 +383,7 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss) case FILETYPE_GRB: case FILETYPE_GRB2: { - if ( memtype == MEMTYPE_FLOAT ) Error("grbWriteRecord not implemented for memtype float!"); - status = grbWriteRecord(streamID, data, nmiss); + status = grb_write_record(streamptr, memtype, data, nmiss); break; } #endif @@ -398,7 +391,7 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss) case FILETYPE_SRV: { if ( memtype == MEMTYPE_FLOAT ) Error("srvWriteRecord not implemented for memtype float!"); - status = srvWriteRecord(streamID, data); + status = srvWriteRecord(streamptr, data); break; } #endif @@ -406,7 +399,7 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss) case FILETYPE_EXT: { if ( memtype == MEMTYPE_FLOAT ) Error("extWriteRecord not implemented for memtype float!"); - status = extWriteRecord(streamID, data); + status = extWriteRecord(streamptr, data); break; } #endif @@ -414,7 +407,7 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss) case FILETYPE_IEG: { if ( memtype == MEMTYPE_FLOAT ) Error("iegWriteRecord not implemented for memtype float!"); - status = iegWriteRecord(streamID, data); + status = iegWriteRecord(streamptr, data); break; } #endif @@ -424,7 +417,7 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss) case FILETYPE_NC4: case FILETYPE_NC4C: { - cdf_write_record(streamID, memtype, data, nmiss); + cdf_write_record(streamptr, memtype, data, nmiss); break; } #endif @@ -464,7 +457,9 @@ void streamCopyRecord(int streamID2, int streamID1) filetype1 = streamptr1->filetype; filetype2 = streamptr2->filetype; - if ( filetype1 == filetype2 ) filetype = filetype2; + if ( filetype1 == filetype2 ) filetype = filetype2; + else + Error("Streams have different file types (%s -> %s)!", strfiletype(filetype1), strfiletype(filetype2)); switch (filetype) { @@ -473,7 +468,7 @@ void streamCopyRecord(int streamID2, int streamID1) case FILETYPE_GRB2: { /* FIXME: return value not inspected */ - status = grbCopyRecord(streamID2, streamID1); + status = grbCopyRecord(streamptr2, streamptr1); break; } #endif @@ -481,7 +476,7 @@ void streamCopyRecord(int streamID2, int streamID1) case FILETYPE_SRV: { /* FIXME: return value not inspected */ - status = srvCopyRecord(streamID2, streamID1); + status = srvCopyRecord(streamptr2, streamptr1); break; } #endif @@ -489,7 +484,7 @@ void streamCopyRecord(int streamID2, int streamID1) case FILETYPE_EXT: { /* FIXME: return value not inspected */ - status = extCopyRecord(streamID2, streamID1); + status = extCopyRecord(streamptr2, streamptr1); break; } #endif @@ -497,35 +492,40 @@ void streamCopyRecord(int streamID2, int streamID1) case FILETYPE_IEG: { /* FIXME: return value not inspected */ - status = iegCopyRecord(streamID2, streamID1); + status = iegCopyRecord(streamptr2, streamptr1); break; } #endif - default: +#if defined (HAVE_LIBNETCDF) + case FILETYPE_NC: + case FILETYPE_NC2: + case FILETYPE_NC4: + case FILETYPE_NC4C: { /* FIXME: return value not inspected */ - status = cdfCopyRecord(streamID2, streamID1); + status = cdfCopyRecord(streamptr2, streamptr1); + break; + } +#endif + default: + { + Error("%s support not compiled in!", strfiletype(filetype)); break; } } } -void cdiCreateRecords(int streamID, int tsID) +void cdi_create_records(stream_t *streamptr, int tsID) { int nrecords, maxrecords; int nvars, varID, recID; record_t *records; int vlistID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( streamptr->tsteps[tsID].records ) return; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; if ( tsID == 0 ) { diff --git a/src/stream_srv.c b/src/stream_srv.c index 8a5e33cea..be8cfa30c 100644 --- a/src/stream_srv.c +++ b/src/stream_srv.c @@ -29,7 +29,7 @@ typedef struct { int param; int level; -} SRVCOMPVAR; +} SRVCOMPVAR; int srvInqDatatype(int prec) @@ -60,7 +60,7 @@ int srvDefDatatype(int datatype) } /* not used -int srvInqRecord(int streamID, int *varID, int *levelID) +int srvInqRecord(stream_t *streamptr, int *varID, int *levelID) { int status; int fileID; @@ -69,14 +69,9 @@ int srvInqRecord(int streamID, int *varID, int *levelID) int header[8]; int vlistID; srvrec_t *srvp; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; srvp = streamptr->record->srvp; *varID = -1; @@ -97,12 +92,12 @@ int srvInqRecord(int streamID, int *varID, int *levelID) zaxisID = vlistInqVarZaxis(vlistID, *varID); *levelID = zaxisInqLevelID(zaxisID, (double) ilevel); - + return (1); } */ -int srvReadRecord(int streamID, double *data, int *nmiss) +int srvReadRecord(stream_t *streamptr, double *data, int *nmiss) { int vlistID, fileID; int status; @@ -113,14 +108,9 @@ int srvReadRecord(int streamID, double *data, int *nmiss) int i, size; double missval; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; vrecID = streamptr->tsteps[tsID].curRecID; recID = streamptr->tsteps[tsID].recIDs[vrecID]; @@ -154,7 +144,7 @@ int srvReadRecord(int streamID, double *data, int *nmiss) } -int srvCopyRecord(int streamID2, int streamID1) +int srvCopyRecord(stream_t *streamptr2, stream_t *streamptr1) { int fileID1, fileID2; int tsID, recID, vrecID; @@ -162,17 +152,9 @@ int srvCopyRecord(int streamID2, int streamID1) off_t recpos; int status = 0; char *buffer; - stream_t *streamptr1; - stream_t *streamptr2; - streamptr1 = stream_to_pointer(streamID1); - streamptr2 = stream_to_pointer(streamID2); - - stream_check_ptr(__func__, streamptr1); - stream_check_ptr(__func__, streamptr2); - - fileID1 = streamInqFileID(streamID1); - fileID2 = streamInqFileID(streamID2); + fileID1 = streamptr1->fileID; + fileID2 = streamptr2->fileID; tsID = streamptr1->curTsID; vrecID = streamptr1->tsteps[tsID].curRecID; @@ -194,7 +176,7 @@ int srvCopyRecord(int streamID2, int streamID1) } -int srvDefRecord(int streamID) +int srvDefRecord(stream_t *streamptr) { int gridID; int header[8]; @@ -203,11 +185,6 @@ int srvDefRecord(int streamID) int datatype; int pdis, pcat, pnum; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); gridID = streamptr->record->gridID; srvp = streamptr->record->srvp; @@ -244,18 +221,13 @@ int srvDefRecord(int streamID) } -int srvWriteRecord(int streamID, const double *data) +int srvWriteRecord(stream_t *streamptr, const double *data) { int fileID; int status = 0; srvrec_t *srvp; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; srvp = streamptr->record->srvp; srvDefDataDP(srvp, data); @@ -265,9 +237,9 @@ int srvWriteRecord(int streamID, const double *data) return (status); } - -void srvAddRecord(int streamID, int param, int level, int xsize, int ysize, - long recsize, off_t position, int prec) +static +void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ysize, + long recsize, off_t position, int prec) { int leveltype; int gridID = UNDEFID; @@ -277,13 +249,10 @@ void srvAddRecord(int streamID, int param, int level, int xsize, int ysize, record_t *record; grid_t grid; int vlistID; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; tsID = streamptr->curTsID; - recID = recordNewEntry(streamID, tsID); + recID = recordNewEntry(streamptr, tsID); record = &streamptr->tsteps[tsID].records[recID]; (*record).size = recsize; @@ -292,7 +261,7 @@ void srvAddRecord(int streamID, int param, int level, int xsize, int ysize, (*record).ilevel = level; memset(&grid, 0, sizeof(grid_t)); - grid.type = GRID_GENERIC; + grid.type = GRID_GENERIC; grid.size = xsize*ysize; grid.xsize = xsize; grid.ysize = ysize; @@ -307,7 +276,7 @@ void srvAddRecord(int streamID, int param, int level, int xsize, int ysize, datatype = srvInqDatatype(prec); - varAddRecord(recID, param, gridID, leveltype, 0, level, 0, + varAddRecord(recID, param, gridID, leveltype, 0, level, 0, 0, datatype, &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL); (*record).varID = varID; @@ -322,15 +291,12 @@ void srvAddRecord(int streamID, int param, int level, int xsize, int ysize, } -void srvCmpRecord(int streamID, int tsID, int recID, off_t position, int param, +void srvCmpRecord(stream_t *streamptr, int tsID, int recID, off_t position, int param, int level, int xsize, int ysize) { int varID = 0; int levelID = 0; record_t *record; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); record = &streamptr->tsteps[tsID].records[recID]; @@ -352,8 +318,8 @@ void srvCmpRecord(int streamID, int tsID, int recID, off_t position, int param, } static -void srvScanTimestep1(int streamID) -{ +void srvScanTimestep1(stream_t *streamptr) +{ int header[8]; int prec = 0; int status; @@ -372,22 +338,17 @@ void srvScanTimestep1(int streamID) int vlistID; SRVCOMPVAR compVar, compVar0; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); streamptr->curTsID = 0; srvp = streamptr->record->srvp; - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); taxis = &streamptr->tsteps[tsID].taxis; if ( tsID != 0 ) Error("Internal problem! tstepsNewEntry returns %d", tsID); - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; nrecs = 0; while ( TRUE ) @@ -441,22 +402,22 @@ void srvScanTimestep1(int streamID) if ( CDI_Debug ) Message("%4d%8d%4d%8d%8d%6d", nrecs, (int)recpos, rcode, rlevel, vdate, vtime); - srvAddRecord(streamID, param, rlevel, rxsize, rysize, recsize, recpos, prec); + srv_add_record(streamptr, param, rlevel, rxsize, rysize, recsize, recpos, prec); } streamptr->rtsteps = 1; - cdiGenVars(streamID); + cdi_generate_vars(streamptr); taxisID = taxisCreate(TAXIS_ABSOLUTE); taxis->type = TAXIS_ABSOLUTE; taxis->vdate = datetime0.date; taxis->vtime = datetime0.time; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; vlistDefTaxis(vlistID, taxisID); - cdiCheckContents(streamID); + vlist_check_contents(vlistID); nrecords = streamptr->tsteps[0].nallrecs; if ( nrecords < streamptr->tsteps[0].recordSize ) @@ -473,7 +434,7 @@ void srvScanTimestep1(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -495,8 +456,8 @@ void srvScanTimestep1(int streamID) } static -int srvScanTimestep2(int streamID) -{ +int srvScanTimestep2(stream_t *streamptr) +{ int header[8]; int status; int fileID; @@ -512,16 +473,11 @@ int srvScanTimestep2(int streamID) int vlistID; SRVCOMPVAR compVar, compVar0; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); streamptr->curTsID = 1; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; srvp = streamptr->record->srvp; tsID = streamptr->rtsteps; @@ -532,7 +488,7 @@ int srvScanTimestep2(int streamID) fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecords = streamptr->tsteps[0].nallrecs; streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); @@ -543,9 +499,9 @@ int srvScanTimestep2(int streamID) for ( recID = 0; recID < nrecords; recID++ ) { varID = streamptr->tsteps[0].records[recID].varID; - streamptr->tsteps[tsID].records[recID].position = + streamptr->tsteps[tsID].records[recID].position = streamptr->tsteps[0].records[recID].position; - streamptr->tsteps[tsID].records[recID].size = + streamptr->tsteps[tsID].records[recID].size = streamptr->tsteps[0].records[recID].size; } @@ -645,7 +601,7 @@ int srvScanTimestep2(int streamID) if ( streamptr->ntsteps == -1 ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -657,23 +613,18 @@ int srvScanTimestep2(int streamID) } -int srvInqContents(int streamID) +int srvInqContents(stream_t *streamptr) { int fileID; int status = 0; - stream_t *streamptr; - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); - - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; streamptr->curTsID = 0; - srvScanTimestep1(streamID); - - if ( streamptr->ntsteps == -1 ) status = srvScanTimestep2(streamID); + srvScanTimestep1(streamptr); + + if ( streamptr->ntsteps == -1 ) status = srvScanTimestep2(streamptr); fileSetPos(fileID, 0, SEEK_SET); @@ -681,7 +632,7 @@ int srvInqContents(int streamID) } static -int srvScanTimestep(int streamID) +int srvScanTimestep(stream_t *streamptr) { int header[8]; int status; @@ -697,15 +648,10 @@ int srvScanTimestep(int streamID) int rindex, nrecs = 0; SRVCOMPVAR compVar, compVar0; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( CDI_Debug ) { - Message("streamID = %d", streamID); + Message("streamID = %d", streamptr->self); Message("cts = %d", streamptr->curTsID); Message("rts = %d", streamptr->rtsteps); Message("nts = %d", streamptr->ntsteps); @@ -720,7 +666,7 @@ int srvScanTimestep(int streamID) if ( streamptr->tsteps[tsID].recordSize == 0 ) { - cdiCreateRecords(streamID, tsID); + cdi_create_records(streamptr, tsID); nrecs = streamptr->tsteps[1].nrecs; @@ -729,7 +675,7 @@ int srvScanTimestep(int streamID) for ( recID = 0; recID < nrecs; recID++ ) streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID]; - fileID = streamInqFileID(streamID); + fileID = streamptr->fileID; fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET); @@ -750,8 +696,8 @@ int srvScanTimestep(int streamID) rlevel = header[1]; vdate = header[2]; vtime = header[3]; - /* rxsize = header[4]; - * rysize = header[5]; */ + /* rxsize = header[4]; */ + /* rysize = header[5]; */ param = cdiEncodeParam(rcode, 255, 255); @@ -766,7 +712,7 @@ int srvScanTimestep(int streamID) taxis->vtime = vtime; } /* - srvCmpRecord(streamID, tsID, nrecs, recpos, param, rlevel, rxsize, rysize); + srvCmpRecord(streamptr, tsID, nrecs, recpos, param, rlevel, rxsize, rysize); */ compVar.param = param; compVar.level = rlevel; @@ -793,7 +739,7 @@ int srvScanTimestep(int streamID) if ( streamptr->ntsteps != streamptr->rtsteps ) { - tsID = tstepsNewEntry(streamID); + tsID = tstepsNewEntry(streamptr); if ( tsID != streamptr->rtsteps ) Error("Internal error. tsID = %d", tsID); @@ -815,24 +761,19 @@ int srvScanTimestep(int streamID) } -int srvInqTimestep(int streamID, int tsID) +int srvInqTimestep(stream_t *streamptr, int tsID) { int ntsteps, nrecs; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - - stream_check_ptr(__func__, streamptr); if ( tsID == 0 && streamptr->rtsteps == 0 ) Error("Call to cdiInqContents missing!"); if ( CDI_Debug ) Message("tsID = %d rtsteps = %d", tsID, streamptr->rtsteps); - + ntsteps = UNDEFID; while ( ( tsID + 1 ) > streamptr->rtsteps && ntsteps == UNDEFID ) - ntsteps = srvScanTimestep(streamID); + ntsteps = srvScanTimestep(streamptr); if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID ) { @@ -848,7 +789,7 @@ int srvInqTimestep(int streamID, int tsID) } -void srvReadVarDP(int streamID, int varID, double *data, int *nmiss) +void srvReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss) { int vlistID, fileID; int levID, nlevs, gridID, gridsize; @@ -859,13 +800,10 @@ void srvReadVarDP(int streamID, int varID, double *data, int *nmiss) int i; double missval; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); srvp = streamptr->record->srvp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; nlevs = streamptr->vars[varID].nlevs; missval = vlistInqVarMissval(vlistID, varID); gridID = vlistInqVarGrid(vlistID, varID); @@ -899,7 +837,7 @@ void srvReadVarDP(int streamID, int varID, double *data, int *nmiss) } -void srvReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nmiss) +void srvReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data, int *nmiss) { int vlistID, fileID; int nlevs, gridID, gridsize; @@ -910,13 +848,10 @@ void srvReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm int i; double missval; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); srvp = streamptr->record->srvp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; nlevs = streamptr->vars[varID].nlevs; missval = vlistInqVarMissval(vlistID, varID); gridID = vlistInqVarGrid(vlistID, varID); @@ -949,7 +884,7 @@ void srvReadVarSliceDP(int streamID, int varID, int levID, double *data, int *nm } -void srvWriteVarDP(int streamID, int varID, const double *data) +void srvWriteVarDP(stream_t *streamptr, int varID, const double *data) { int fileID; int levID, nlevs, gridID, gridsize; @@ -962,16 +897,13 @@ void srvWriteVarDP(int streamID, int varID, const double *data) int vlistID; int pdis, pcat, pnum; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( CDI_Debug ) - Message("streamID = %d varID = %d", streamID, varID); + Message("streamID = %d varID = %d", streamptr->self, varID); srvp = streamptr->record->srvp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; gridID = vlistInqVarGrid(vlistID, varID); gridsize = gridInqSize(gridID); @@ -1019,7 +951,7 @@ void srvWriteVarDP(int streamID, int varID, const double *data) } -void srvWriteVarSliceDP(int streamID, int varID, int levID, const double *data) +void srvWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double *data) { int fileID; int gridID; @@ -1032,13 +964,10 @@ void srvWriteVarSliceDP(int streamID, int varID, int levID, const double *data) int vlistID; int pdis, pcat, pnum; srvrec_t *srvp; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); srvp = streamptr->record->srvp; - vlistID = streamInqVlist(streamID); - fileID = streamInqFileID(streamID); + vlistID = streamptr->vlistID; + fileID = streamptr->fileID; tsID = streamptr->curTsID; gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); diff --git a/src/stream_srv.h b/src/stream_srv.h index cd4526202..5989808a1 100644 --- a/src/stream_srv.h +++ b/src/stream_srv.h @@ -5,20 +5,20 @@ # include "service.h" #endif -int srvInqContents(int streamID); -int srvInqTimestep(int streamID, int tsID); +int srvInqContents(stream_t *streamptr); +int srvInqTimestep(stream_t *streamptr, int tsID); -int srvInqRecord(int streamID, int *varID, int *levelID); -int srvDefRecord(int streamID); -int srvCopyRecord(int streamIDdest, int streamIDsrc); -int srvReadRecord(int streamID, double *data, int *nmiss); -int srvWriteRecord(int streamID, const double *data); +int srvInqRecord(stream_t *streamptr, int *varID, int *levelID); +int srvDefRecord(stream_t *streamptr); +int srvCopyRecord(stream_t *streamptr2, stream_t *streamptr1); +int srvReadRecord(stream_t *streamptr, double *data, int *nmiss); +int srvWriteRecord(stream_t *streamptr, const double *data); -void srvReadVarDP (int streamID, int varID, double *data, int *nmiss); -void srvWriteVarDP(int streamID, int varID, const double *data); +void srvReadVarDP (stream_t *streamptr, int varID, double *data, int *nmiss); +void srvWriteVarDP(stream_t *streamptr, int varID, const double *data); -void srvReadVarSliceDP (int streamID, int varID, int levelID, double *data, int *nmiss); -void srvWriteVarSliceDP(int streamID, int varID, int levelID, const double *data); +void srvReadVarSliceDP (stream_t *streamptr, int varID, int levelID, double *data, int *nmiss); +void srvWriteVarSliceDP(stream_t *streamptr, int varID, int levelID, const double *data); #endif /* _STREAM_SRV_H */ /* diff --git a/src/stream_var.c b/src/stream_var.c index 660d0f845..a069e5edf 100644 --- a/src/stream_var.c +++ b/src/stream_var.c @@ -12,12 +12,8 @@ static -void streamvarInitEntry(int streamID, int varID) +void streamvar_init_entry(stream_t *streamptr, int varID) { - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - streamptr->vars[varID].ncvarid = CDI_UNDEFID; streamptr->vars[varID].defmiss = 0; streamptr->vars[varID].nlevs = 0; @@ -32,14 +28,11 @@ void streamvarInitEntry(int streamID, int varID) } static -int streamvarNewEntry(int streamID) +int streamvar_new_entry(stream_t *streamptr) { int varID = 0; int streamvarSize; - SVARINFO *streamvar; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); + svarinfo_t *streamvar; streamvarSize = streamptr->varsAllocated; streamvar = streamptr->vars; @@ -52,11 +45,11 @@ int streamvarNewEntry(int streamID) int i; streamvarSize = 2; - streamvar = (SVARINFO *) malloc(streamvarSize*sizeof(SVARINFO)); + streamvar = (svarinfo_t *) malloc(streamvarSize*sizeof(svarinfo_t)); if ( streamvar == NULL ) { Message("streamvarSize = %d", streamvarSize); - SysError("Allocation of SVARINFO failed"); + SysError("Allocation of svarinfo_t failed"); } for ( i = 0; i < streamvarSize; i++ ) @@ -78,11 +71,11 @@ int streamvarNewEntry(int streamID) int i; streamvarSize = 2*streamvarSize; - streamvar = (SVARINFO *) realloc(streamvar, streamvarSize*sizeof(SVARINFO)); + streamvar = (svarinfo_t *) realloc(streamvar, streamvarSize*sizeof(svarinfo_t)); if ( streamvar == NULL ) { Message("streamvarSize = %d", streamvarSize); - SysError("Reallocation of SVARINFO failed"); + SysError("Reallocation of svarinfo_t failed"); } varID = streamvarSize/2; @@ -93,7 +86,7 @@ int streamvarNewEntry(int streamID) streamptr->varsAllocated = streamvarSize; streamptr->vars = streamvar; - streamvarInitEntry(streamID, varID); + streamvar_init_entry(streamptr, varID); streamptr->vars[varID].isUsed = TRUE; @@ -101,21 +94,18 @@ int streamvarNewEntry(int streamID) } -int streamNewVar(int streamID, int gridID, int zaxisID) +int stream_new_var(stream_t *streamptr, int gridID, int zaxisID) { int varID; int *level; int *lindex; int nlevs; int levID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( CDI_Debug ) Message("gridID = %d zaxisID = %d", gridID, zaxisID); - varID = streamvarNewEntry(streamID); + varID = streamvar_new_entry(streamptr); streamptr->nvars++; diff --git a/src/table.h b/src/table.h index d933cbc3f..0d189d4df 100644 --- a/src/table.h +++ b/src/table.h @@ -282,181 +282,181 @@ static PAR echam5[] = { }; static PAR echam6[] = { - { 4, "precip", "total precipitation", "kg/m^2s" }, - { 34, "low_cld", "low cloud", NULL }, - { 35, "mid_cld", "mid cloud", NULL }, - { 36, "hih_cld", "high cloud", NULL }, - { 68, "fage", "aging factor of snow on ice", NULL }, - { 69, "snifrac", "fraction of ice covered with snow", NULL }, - { 70, "barefrac", "bare ice fraction", NULL }, - { 71, "alsom", "albedo of melt ponds", NULL }, - { 72, "alsobs", "albedo of bare ice and snow", NULL }, - { 73, "sicepdw", "melt pond depth on sea-ice", "m" }, - { 74, "sicepdi", "ice thickness on melt pond", "m" }, - { 75, "tsicepdi", "ice temperature on frozen melt pond", "K" }, - { 76, "sicepres", "residual heat flux", "W/m**2" }, - { 77, "ameltdepth", "total melt pond depth", "m" }, - { 78, "ameltfrac", "fractional area of melt ponds on sea-ice", NULL }, - { 79, "albedo_vis_dir", "surface albedo visible range direct", NULL }, - { 80, "albedo_nir_dir", "surface albedo NIR range direct", NULL }, - { 81, "albedo_vis_dif", "surface albedo visible range diffuse", NULL }, - { 82, "albedo_nir_dif", "surface albedo NIR range diffuse", NULL }, - { 83, "ocu", "ocean eastw. velocity (coupled mode)", "m/s" }, - { 84, "ocv", "ocean northw. velocity (coupled mode)", "m/s" }, - { 85, "tradl", "thermal radiation 200mb", "W/m**2" }, - { 86, "sradl", "solar radiation 200mb", "W/m**2" }, - { 87, "trafl", "thermal radiation 200mb (clear sky)", "W/m**2" }, - { 88, "srafl", "solar radiation 200mb (clear sky)", "W/m**2" }, - { 89, "amlcorac", "mixed layer flux correction", "W/m**2" }, - { 90, "amlheatac", "mixed layer heat content", "J/m**2" }, - { 91, "trfliac", "LW flux over ice", "W/m^2" }, - { 92, "trflwac", "LW flux over water", "W/m^2" }, - { 93, "trfllac", "LW flux over land", "W/m^2" }, - { 94, "sofliac", "SW flux over ice", "W/m^2" }, - { 95, "soflwac", "SW flux over water", "W/m^2" }, - { 96, "sofllac", "SW flux over land", "W/m^2" }, - { 97, "friac", "ice cover (fraction of grid box)", NULL }, - { 102, "tsi", "surface temperature of ice", "K" }, - { 103, "tsw", "surface temperature of water", "K" }, - { 104, "ustri", "zonal wind stress over ice", "Pa" }, - { 105, "vstri", "meridional wind stress over ice", "Pa" }, - { 106, "ustrw", "zonal wind stress over water", "Pa" }, - { 107, "vstrw", "meridional wind stress over water", "Pa" }, - { 108, "ustrl", "zonal wind stress over land", "Pa" }, - { 109, "vstrl", "meridional wind stress over land", "Pa" }, - { 110, "ahfliac", "latent heat flux over ice", "W/m^2" }, - { 111, "ahflwac", "latent heat flux over water", "W/m^2" }, - { 112, "ahfllac", "latent heat flux over land", "W/m^2" }, - { 113, "evapiac", "evaporation over ice", "kg/m^2s" }, - { 114, "evapwac", "evaporation over water", "kg/m^2s" }, - { 115, "evaplac", "evaporation over land", "kg/m^2s" }, - { 116, "az0i", "roughness length over ice", "m" }, - { 117, "az0w", "roughness length over water", "m" }, - { 118, "az0l", "roughness length over land", "m" }, - { 119, "ahfsiac", "sensible heat flux over ice", "W/m^2" }, - { 120, "ahfswac", "sensible heat flux over water", "W/m^2" }, - { 121, "ahfslac", "sensible heat flux over land", "W/m^2" }, - { 122, "alsoi", "albedo of ice", NULL }, - { 123, "alsow", "albedo of water", NULL }, - { 124, "alsol", "albedo of land", NULL }, - { 125, "ahfice", "conductive heat flux", "W/m^2" }, - { 126, "qres", "residual heat flux for melting sea ice", "W/m^2" }, - { 127, "alake", "lake fraction of grid box", "fraction" }, - { 128, "rintop", "low level inversion", NULL }, - { 129, "geosp", "surface geopotential (orography)", "m^2/s^2" }, - { 130, "t", "temperature", "K" }, - { 131, "u", "u-velocity", "m/s" }, - { 132, "v", "v-velocity", "m/s" }, - { 133, "q", "specific humidity", "kg/kg" }, - { 134, "aps", "surface pressure", "Pa" }, - { 135, "omega", "vertical velocity", "Pa/s" }, - { 136, "acdnc", "cloud droplet number concentration", "1/m^3" }, - { 137, "apmeb", "vert. integr. tendencies of water", "kg/m^2s" }, - { 138, "svo", "vorticity", "1/s" }, - { 139, "tslm1", "surface temperature of land", "K" }, - { 140, "ws", "soil wetness", "m" }, - { 141, "sn", "snow depth", "m" }, - { 142, "aprl", "large scale precipitation", "kg/m^2s" }, - { 143, "aprc", "convective precipitation", "kg/m^2s" }, - { 144, "aprs", "snow fall", "kg/m^2s" }, - { 145, "vdis", "boundary layer dissipation", "W/m^2" }, - { 146, "ahfs", "sensible heat flux", "W/m^2" }, - { 147, "ahfl", "latent heat flux", "W/m^2" }, - { 148, "stream", "streamfunction", "m^2/s" }, - { 149, "velopot", "velocity potential", "m^2/s" }, - { 150, "xivi", "vertically integrated cloud ice", "kg/m^2" }, - { 151, "slp", "mean sea level pressure", "Pa" }, - { 152, "stp(20)", "log surface pressure", NULL }, - { 153, "xl", "cloud water", "kg/kg" }, - { 154, "xi", "cloud ice", "kg/kg" }, - { 155, "sd", "divergence", "1/s" }, - { 156, "geopoth", "geopotential height", "m" }, - { 157, "rhumidity", "relative humidity", "fraction" }, - { 158, "var158", "tendency of surface pressure", "Pa/s" }, - { 159, "wind10w", "10m windspeed over water", "m/s" }, - { 160, "runoff", "surface runoff and drainage", "kg/m^2s" }, - { 161, "drain", "drainage", "kg/m^2s" }, - { 162, "aclc", "cloud cover", NULL }, - { 163, "aclcv", "total cloud cover", NULL }, - { 164, "aclcov", "total cloud cover (mean)", NULL }, - { 165, "u10", "10m u-velocity", "m/s" }, - { 166, "v10", "10m v-velocity", "m/s" }, - { 167, "temp2", "2m temperature", "K" }, - { 168, "dew2", "2m dew point temperature", "K" }, - { 169, "tsurf", "surface temperature", "K" }, - { 170, "xvar", "variance of total water amount qv+qi+ql", "kg/kg" }, - { 171, "wind10", "10m windspeed", "m/s" }, - { 172, "slm", "land sea mask (1. = land, 0. = sea/lakes)", NULL }, - { 173, "az0", "roughness length", "m" }, - { 174, "alb", "surface background albedo", NULL }, - { 175, "albedo", "surface albedo", NULL }, - { 176, "srads", "net surface solar radiation", "W/m^2" }, - { 177, "trads", "net surface thermal radiation", "W/m^2" }, - { 178, "srad0", "net top solar radiation", "W/m^2" }, - { 179, "trad0", "top thermal radiation (OLR)", "W/m^2" }, - { 180, "ustr", "u-stress", "Pa" }, - { 181, "vstr", "v-stress", "Pa" }, - { 182, "evap", "evaporation", "kg/m^2s" }, - { 183, "xskew", "skewness of total water amount qv+qi+ql", NULL }, - { 184, "srad0d", "top incoming solar radiation", "W/m^2" }, - { 185, "srafs", "net surf. solar radiation (clear sky)", "W/m^2" }, - { 186, "trafs", "net surf. thermal radiation (clear sky)", "W/m^2" }, - { 187, "sraf0", "net top solar radiation (clear sky)", "W/m^2" }, - { 188, "traf0", "net top thermal radiation (clear sky)", "W/m^2" }, - { 189, "sclfs", "surface solar cloud forcing", "W/m^2" }, - { 190, "tclfs", "surface thermal cloud forcing", "W/m^2" }, - { 191, "sclf0", "SW top cloud forcing (178-187)", "W/m^2" }, - { 192, "tclf0", "LW top cloud forcing (179-188)", "W/m^2" }, - { 193, "wl", "skin reservoir content", "m" }, - { 194, "slf", "sea land fraction", NULL }, - { 195, "ustrgw", "u-gravity wave stress", "Pa" }, - { 196, "vstrgw", "v-gravity wave stress", "Pa" }, - { 197, "vdisgw", "gravity wave dissipation", "W/m^2" }, - { 198, "vgrat", "vegetation ratio", NULL }, - { 199, "orostd", "orographic standard deviation", "m" }, - { 200, "vlt", "leaf area index", NULL }, - { 201, "t2max", "maximum 2m-temperature", "K" }, - { 202, "t2min", "minimum 2m-temperature", "K" }, - { 203, "srad0u", "top solar radiation upward", "W/m^2" }, - { 204, "sradsu", "surface solar radiation upward", "W/m^2" }, - { 205, "tradsu", "surface thermal radiation upward", "W/m^2" }, - { 206, "grndflux", "surface ground heat flux", NULL }, - { 207, "tsoil", "deep soil temperatures (5 layers)", "K" }, - { 208, "ahfcon", "conductive heat flux through ice", "W/m^2" }, - { 209, "ahfres", "melting of ice", "W/m^2" }, - { 210, "seaice", "ice cover (fraction of 1-SLM)", NULL }, - { 211, "siced", "ice depth", "m" }, - { 212, "forest", "forest fraction", NULL }, - { 213, "gld", "glacier depth", "m" }, - { 214, "sni", "water equivalent of snow on ice", "m" }, - { 215, "rogl", "glacier runoff", "kg/m^2s" }, - { 216, "wimax", "maximum 10m-wind speed", "m/s" }, - { 217, "topmax", "maximum height of convective cloud tops", "Pa" }, - { 218, "snmel", "snow melt", "kg/m^2s" }, - { 219, "runtoc", "surface runoff into ocean", "kg/m^2s" }, - { 220, "runlnd", "surface runoff not running into ocean", "kg/m^2s" }, - { 221, "apmegl", "P-E over land ice", "kg/m^2s" }, - { 222, "snacl", "snow accumulation over land", "kg/m^2s" }, - { 223, "aclcac", "cloud cover", NULL }, - { 224, "tke", "turbulent kinetic energy", "m^2/s^2" }, - { 225, "tkem1", "turbulent kinetic energy (t-1)", "m^2/s^2" }, - { 226, "fao", "FAO data set (soil data flags)", "0...5" }, - { 227, "rgcgn", "heat capacity of soil", NULL }, - { 228, "sodif", "diffusivity of soil and land ice", "m^2/s" }, - { 229, "wsmx", "field capacity of soil", "m" }, - { 230, "qvi", "vertically integrated water vapor", "kg/m^2" }, - { 231, "xlvi", "vertically integrated cloud water", "kg/m^2" }, - { 232, "glac", "fraction of land covered by glaciers", NULL }, - { 233, "snc", "snow depth at the canopy", "m" }, - { 234, "rtype", "type of convection", "0...3" }, - { 235, "abso4", "antropogenic sulfur burden", "kg/m**2" }, - { 236, "ao3", "ipcc ozone", "kg/m**2" }, - { 237, "tropo", "WMO defined tropopause height", "Pa" }, - { 259, "windspeed", "windspeed (sqrt(u^2+v^2))", "m/s" }, - { 260, "precip", "total precipitation (142+143)", "kg/m^2s" }, - { 261, "net_top", "total top radiation (178+179)", "W/m^2" }, - { 262, "net_bot", "total surface radiation (176+177)", "W/m^2" }, - { 272, "mastfru", "mass stream function", "kg/s" }, + { 4, "precip", "total precipitation", "kg m-2 s-1" }, + { 34, "low_cld", "low cloud", NULL }, + { 35, "mid_cld", "mid cloud", NULL }, + { 36, "hih_cld", "high cloud", NULL }, + { 68, "fage", "aging factor of snow on ice", NULL }, + { 69, "snifrac", "fraction of ice covered with snow", NULL }, + { 70, "barefrac", "bare ice fraction", NULL }, + { 71, "alsom", "albedo of melt ponds", NULL }, + { 72, "alsobs", "albedo of bare ice and snow", NULL }, + { 73, "sicepdw", "melt pond depth on sea-ice", "m" }, + { 74, "sicepdi", "ice thickness on melt pond", "m" }, + { 75, "tsicepdi", "ice temperature on frozen melt pond", "K" }, + { 76, "sicepres", "residual heat flux", "W m-2" }, + { 77, "ameltdepth", "total melt pond depth", "m" }, + { 78, "ameltfrac", "fractional area of melt ponds on sea-ice", NULL }, + { 79, "albedo_vis_dir", "surface albedo visible range direct", NULL }, + { 80, "albedo_nir_dir", "surface albedo NIR range direct", NULL }, + { 81, "albedo_vis_dif", "surface albedo visible range diffuse", NULL }, + { 82, "albedo_nir_dif", "surface albedo NIR range diffuse", NULL }, + { 83, "ocu", "ocean eastw. velocity (coupled mode)", "m/s" }, + { 84, "ocv", "ocean northw. velocity (coupled mode)", "m/s" }, + { 85, "tradl", "thermal radiation 200mb", "W m-2" }, + { 86, "sradl", "solar radiation 200mb", "W m-2" }, + { 87, "trafl", "thermal radiation 200mb (clear sky)", "W m-2" }, + { 88, "srafl", "solar radiation 200mb (clear sky)", "W m-2" }, + { 89, "amlcorac", "mixed layer flux correction", "W m-2" }, + { 90, "amlheatac", "mixed layer heat content", "J m-2" }, + { 91, "trfliac", "LW flux over ice", "W m-2" }, + { 92, "trflwac", "LW flux over water", "W m-2" }, + { 93, "trfllac", "LW flux over land", "W m-2" }, + { 94, "sofliac", "SW flux over ice", "W m-2" }, + { 95, "soflwac", "SW flux over water", "W m-2" }, + { 96, "sofllac", "SW flux over land", "W m-2" }, + { 97, "friac", "ice cover (fraction of grid box)", NULL }, + { 102, "tsi", "surface temperature of ice", "K" }, + { 103, "tsw", "surface temperature of water", "K" }, + { 104, "ustri", "zonal wind stress over ice", "Pa" }, + { 105, "vstri", "meridional wind stress over ice", "Pa" }, + { 106, "ustrw", "zonal wind stress over water", "Pa" }, + { 107, "vstrw", "meridional wind stress over water", "Pa" }, + { 108, "ustrl", "zonal wind stress over land", "Pa" }, + { 109, "vstrl", "meridional wind stress over land", "Pa" }, + { 110, "ahfliac", "latent heat flux over ice", "W m-2" }, + { 111, "ahflwac", "latent heat flux over water", "W m-2" }, + { 112, "ahfllac", "latent heat flux over land", "W m-2" }, + { 113, "evapiac", "evaporation over ice", "kg m-2 s-1" }, + { 114, "evapwac", "evaporation over water", "kg m-2 s-1" }, + { 115, "evaplac", "evaporation over land", "kg m-2 s-1" }, + { 116, "az0i", "roughness length over ice", "m" }, + { 117, "az0w", "roughness length over water", "m" }, + { 118, "az0l", "roughness length over land", "m" }, + { 119, "ahfsiac", "sensible heat flux over ice", "W m-2" }, + { 120, "ahfswac", "sensible heat flux over water", "W m-2" }, + { 121, "ahfslac", "sensible heat flux over land", "W m-2" }, + { 122, "alsoi", "albedo of ice", NULL }, + { 123, "alsow", "albedo of water", NULL }, + { 124, "alsol", "albedo of land", NULL }, + { 125, "ahfice", "conductive heat flux", "W m-2" }, + { 126, "qres", "residual heat flux for melting sea ice", "W m-2" }, + { 127, "alake", "lake fraction of grid box", "fraction" }, + { 128, "rintop", "low level inversion", NULL }, + { 129, "geosp", "surface geopotential (orography)", "m^2/s^2" }, + { 130, "t", "temperature", "K" }, + { 131, "u", "u-velocity", "m/s" }, + { 132, "v", "v-velocity", "m/s" }, + { 133, "q", "specific humidity", "kg/kg" }, + { 134, "aps", "surface pressure", "Pa" }, + { 135, "omega", "vertical velocity", "Pa/s" }, + { 136, "acdnc", "cloud droplet number concentration", "1 m-3" }, + { 137, "apmeb", "vert. integr. tendencies of water", "kg m-2 s-1" }, + { 138, "svo", "vorticity", "1/s" }, + { 139, "tslm1", "surface temperature of land", "K" }, + { 140, "ws", "soil wetness", "m" }, + { 141, "sn", "snow depth", "m" }, + { 142, "aprl", "large scale precipitation", "kg m-2 s-1" }, + { 143, "aprc", "convective precipitation", "kg m-2 s-1" }, + { 144, "aprs", "snow fall", "kg m-2 s-1" }, + { 145, "vdis", "boundary layer dissipation", "W m-2" }, + { 146, "ahfs", "sensible heat flux", "W m-2" }, + { 147, "ahfl", "latent heat flux", "W m-2" }, + { 148, "stream", "streamfunction", "m^2/s" }, + { 149, "velopot", "velocity potential", "m^2/s" }, + { 150, "xivi", "vertically integrated cloud ice", "kg m-2" }, + { 151, "slp", "mean sea level pressure", "Pa" }, + { 152, "lsp", "log surface pressure", NULL }, + { 153, "xl", "cloud water", "kg/kg" }, + { 154, "xi", "cloud ice", "kg/kg" }, + { 155, "sd", "divergence", "1/s" }, + { 156, "geopoth", "geopotential height", "m" }, + { 157, "rhumidity", "relative humidity", "fraction" }, + { 158, "var158", "tendency of surface pressure", "Pa/s" }, + { 159, "wind10w", "10m windspeed over water", "m/s" }, + { 160, "runoff", "surface runoff and drainage", "kg m-2 s-1" }, + { 161, "drain", "drainage", "kg m-2 s-1" }, + { 162, "aclc", "cloud cover", NULL }, + { 163, "aclcv", "total cloud cover", NULL }, + { 164, "aclcov", "total cloud cover (mean)", NULL }, + { 165, "u10", "10m u-velocity", "m/s" }, + { 166, "v10", "10m v-velocity", "m/s" }, + { 167, "temp2", "2m temperature", "K" }, + { 168, "dew2", "2m dew point temperature", "K" }, + { 169, "tsurf", "surface temperature", "K" }, + { 170, "xvar", "variance of total water amount qv+qi+ql", "kg/kg" }, + { 171, "wind10", "10m windspeed", "m/s" }, + { 172, "slm", "land sea mask (1. = land, 0. = sea/lakes)", NULL }, + { 173, "az0", "roughness length", "m" }, + { 174, "alb", "surface background albedo", NULL }, + { 175, "albedo", "surface albedo", NULL }, + { 176, "srads", "net surface solar radiation", "W m-2" }, + { 177, "trads", "net surface thermal radiation", "W m-2" }, + { 178, "srad0", "net top solar radiation", "W m-2" }, + { 179, "trad0", "top thermal radiation (OLR)", "W m-2" }, + { 180, "ustr", "u-stress", "Pa" }, + { 181, "vstr", "v-stress", "Pa" }, + { 182, "evap", "evaporation", "kg m-2 s-1" }, + { 183, "xskew", "skewness of total water amount qv+qi+ql", NULL }, + { 184, "srad0d", "top incoming solar radiation", "W m-2" }, + { 185, "srafs", "net surf. solar radiation (clear sky)", "W m-2" }, + { 186, "trafs", "net surf. thermal radiation (clear sky)", "W m-2" }, + { 187, "sraf0", "net top solar radiation (clear sky)", "W m-2" }, + { 188, "traf0", "net top thermal radiation (clear sky)", "W m-2" }, + { 189, "sclfs", "surface solar cloud forcing", "W m-2" }, + { 190, "tclfs", "surface thermal cloud forcing", "W m-2" }, + { 191, "sclf0", "SW top cloud forcing (178-187)", "W m-2" }, + { 192, "tclf0", "LW top cloud forcing (179-188)", "W m-2" }, + { 193, "wl", "skin reservoir content", "m" }, + { 194, "slf", "sea land fraction", NULL }, + { 195, "ustrgw", "u-gravity wave stress", "Pa" }, + { 196, "vstrgw", "v-gravity wave stress", "Pa" }, + { 197, "vdisgw", "gravity wave dissipation", "W m-2" }, + { 198, "vgrat", "vegetation ratio", NULL }, + { 199, "orostd", "orographic standard deviation", "m" }, + { 200, "vlt", "leaf area index", NULL }, + { 201, "t2max", "maximum 2m-temperature", "K" }, + { 202, "t2min", "minimum 2m-temperature", "K" }, + { 203, "srad0u", "top solar radiation upward", "W m-2" }, + { 204, "sradsu", "surface solar radiation upward", "W m-2" }, + { 205, "tradsu", "surface thermal radiation upward", "W m-2" }, + { 206, "grndflux", "surface ground heat flux", NULL }, + { 207, "tsoil", "deep soil temperatures (5 layers)", "K" }, + { 208, "ahfcon", "conductive heat flux through ice", "W m-2" }, + { 209, "ahfres", "melting of ice", "W m-2" }, + { 210, "seaice", "ice cover (fraction of 1-SLM)", NULL }, + { 211, "siced", "ice depth", "m" }, + { 212, "forest", "forest fraction", NULL }, + { 213, "gld", "glacier depth", "m" }, + { 214, "sni", "water equivalent of snow on ice", "m" }, + { 215, "rogl", "glacier runoff", "kg m-2 s-1" }, + { 216, "wimax", "maximum 10m-wind speed", "m/s" }, + { 217, "topmax", "maximum height of convective cloud tops", "Pa" }, + { 218, "snmel", "snow melt", "kg m-2 s-1" }, + { 219, "runtoc", "surface runoff into ocean", "kg m-2 s-1" }, + { 220, "runlnd", "surface runoff not running into ocean", "kg m-2 s-1" }, + { 221, "apmegl", "P-E over land ice", "kg m-2 s-1" }, + { 222, "snacl", "snow accumulation over land", "kg m-2 s-1" }, + { 223, "aclcac", "cloud cover", NULL }, + { 224, "tke", "turbulent kinetic energy", "m^2/s^2" }, + { 225, "tkem1", "turbulent kinetic energy (t-1)", "m^2/s^2" }, + { 226, "fao", "FAO data set (soil data flags)", "0...5" }, + { 227, "rgcgn", "heat capacity of soil", NULL }, + { 228, "sodif", "diffusivity of soil and land ice", "m^2/s" }, + { 229, "wsmx", "field capacity of soil", "m" }, + { 230, "qvi", "vertically integrated water vapor", "kg m-2" }, + { 231, "xlvi", "vertically integrated cloud water", "kg m-2" }, + { 232, "glac", "fraction of land covered by glaciers", NULL }, + { 233, "snc", "snow depth at the canopy", "m" }, + { 234, "rtype", "type of convection", "0...3" }, + { 235, "abso4", "antropogenic sulfur burden", "kg m-2" }, + { 236, "ao3", "ipcc ozone", "kg m-2" }, + { 237, "tropo", "WMO defined tropopause height", "Pa" }, + { 259, "windspeed", "windspeed (sqrt(u^2+v^2))", "m/s" }, + { 260, "precip", "total precipitation (142+143)", "kg m-2 s-1" }, + { 261, "net_top", "total top radiation (178+179)", "W m-2" }, + { 262, "net_bot", "total surface radiation (176+177)", "W m-2" }, + { 272, "mastfru", "mass stream function", "kg/s" }, }; static PAR mpiom1[] = { @@ -1424,12 +1424,3 @@ tableDefault(void) } #endif /* _TABLE_H */ -/* - * Local Variables: - * c-file-style: "Java" - * c-basic-offset: 2 - * indent-tabs-mode: nil - * show-trailing-whitespace: t - * require-trailing-newline: t - * End: - */ diff --git a/src/taxis.c b/src/taxis.c index a8e69ceed..d21d7dff2 100644 --- a/src/taxis.c +++ b/src/taxis.c @@ -107,21 +107,23 @@ void taxis_defaults(void) static void taxisDefaultValue ( taxis_t *taxisptr ) { - taxisptr->self = CDI_UNDEFID; - taxisptr->used = FALSE; - taxisptr->type = DefaultTimeType; - taxisptr->vdate = 0; - taxisptr->vtime = 0; - taxisptr->rdate = CDI_UNDEFID; - taxisptr->rtime = 0; - taxisptr->calendar = cdiDefaultCalendar; - taxisptr->unit = DefaultTimeUnit; - taxisptr->numavg = 0; - taxisptr->has_bounds = FALSE; - taxisptr->vdate_lb = 0; - taxisptr->vtime_lb = 0; - taxisptr->vdate_ub = 0; - taxisptr->vtime_ub = 0; + taxisptr->self = CDI_UNDEFID; + taxisptr->used = FALSE; + taxisptr->type = DefaultTimeType; + taxisptr->vdate = 0; + taxisptr->vtime = 0; + taxisptr->rdate = CDI_UNDEFID; + taxisptr->rtime = 0; + taxisptr->calendar = cdiDefaultCalendar; + taxisptr->unit = DefaultTimeUnit; + taxisptr->numavg = 0; + taxisptr->has_bounds = FALSE; + taxisptr->vdate_lb = 0; + taxisptr->vtime_lb = 0; + taxisptr->vdate_ub = 0; + taxisptr->vtime_ub = 0; + taxisptr->name = NULL; + taxisptr->longname = NULL; } static @@ -253,6 +255,9 @@ void taxisDestroy(int taxisID) taxisptr = ( taxis_t * ) reshGetVal ( taxisID, &taxisOps ); + if ( taxisptr->name ) free(taxisptr->name); + if ( taxisptr->longname ) free(taxisptr->longname); + taxisDestroyKernel ( taxisptr ); } @@ -280,6 +285,8 @@ int taxisDuplicate(int taxisID1) Message("taxisID2: %d", taxisID2); ptaxisCopy(taxisptr2, taxisptr1); + if ( taxisptr1->name ) taxisptr2->name = strdup(taxisptr1->name); + if ( taxisptr1->longname ) taxisptr2->longname = strdup(taxisptr1->longname); // taxisptr2->has_bounds = FALSE; @@ -536,7 +543,6 @@ void taxisCopyTimestep(int taxisID2, int taxisID1) taxis_t *taxisptr1; taxis_t *taxisptr2; - taxisptr1 = ( taxis_t * ) reshGetVal ( taxisID1, &taxisOps ); taxisptr2 = ( taxis_t * ) reshGetVal ( taxisID2, &taxisOps ); @@ -1009,8 +1015,6 @@ double vtime2timeval(int vdate, int vtime, taxis_t *taxis) { int nmonth, dpm; - dpm = days_per_month(calendar, year, month); - value = (year-ryear)*12 - rmonth + month; nmonth = (int) value; @@ -1019,6 +1023,8 @@ double vtime2timeval(int vdate, int vtime, taxis_t *taxis) while ( month > 12 ) { month -= 12; year++; } while ( month < 1 ) { month += 12; year--; } + dpm = days_per_month(calendar, year, month); + encode_caldaysec(calendar, year, month, day, hour, minute, second, &julday2, &secofday2); julday_sub(julday1, secofday1, julday2, secofday2, &days, &secs); @@ -1056,7 +1062,7 @@ void conv_timeval(double timevalue, int *rvdate, int *rvtime) daysec = (int) (-(timevalue - vdate)*86400 + 0.01); else daysec = (int) ( (timevalue - vdate)*86400 + 0.01); - + hour = daysec / 3600; minute = (daysec - hour*3600)/60; second = daysec - hour*3600 - minute*60; @@ -1315,7 +1321,6 @@ int taxisGetPackSize ( void * voidP, MPI_Comm comm ) return packBufferSize; } - void taxisUnpack ( char * unpackBuffer, int unpackBufferSize, int * unpackBufferPos, int nspTarget, MPI_Comm comm ) { @@ -1337,48 +1342,48 @@ void taxisUnpack ( char * unpackBuffer, int unpackBufferSize, xassert ( namespaceAdaptKey ( intBuffer[0], nspTarget ) == taxisP->self ); - taxisP->used = intBuffer[1]; - taxisP->type = intBuffer[2]; - taxisP->vdate = intBuffer[3]; - taxisP->vtime = intBuffer[4]; - taxisP->rdate = intBuffer[5]; - taxisP->rtime = intBuffer[6]; - taxisP->calendar = intBuffer[7]; - taxisP->unit = intBuffer[8]; - taxisP->numavg = intBuffer[9]; + taxisP->used = intBuffer[1]; + taxisP->type = intBuffer[2]; + taxisP->vdate = intBuffer[3]; + taxisP->vtime = intBuffer[4]; + taxisP->rdate = intBuffer[5]; + taxisP->rtime = intBuffer[6]; + taxisP->calendar = intBuffer[7]; + taxisP->unit = intBuffer[8]; + taxisP->numavg = intBuffer[9]; taxisP->has_bounds = intBuffer[10]; - taxisP->vdate_lb = intBuffer[11]; - taxisP->vtime_lb = intBuffer[12]; - taxisP->vdate_ub = intBuffer[13]; + taxisP->vdate_lb = intBuffer[11]; + taxisP->vtime_lb = intBuffer[12]; + taxisP->vdate_ub = intBuffer[13]; taxisP->vtime_ub = intBuffer[14]; } static -void taxisPack ( void * voidP, void * packBuffer, int packBufferSize, +void taxisPack ( void * voidP, void * packBuffer, int packBufferSize, int * packBufferPos, MPI_Comm comm ) { taxis_t * taxisP = ( taxis_t * ) voidP; int intBuffer[taxisNint]; double d; - intBuffer[0] = taxisP->self; - intBuffer[1] = taxisP->used; - intBuffer[2] = taxisP->type; - intBuffer[3] = taxisP->vdate; - intBuffer[4] = taxisP->vtime; - intBuffer[5] = taxisP->rdate; - intBuffer[6] = taxisP->rtime; - intBuffer[7] = taxisP->calendar; - intBuffer[8] = taxisP->unit; - intBuffer[9] = taxisP->numavg; + intBuffer[0] = taxisP->self; + intBuffer[1] = taxisP->used; + intBuffer[2] = taxisP->type; + intBuffer[3] = taxisP->vdate; + intBuffer[4] = taxisP->vtime; + intBuffer[5] = taxisP->rdate; + intBuffer[6] = taxisP->rtime; + intBuffer[7] = taxisP->calendar; + intBuffer[8] = taxisP->unit; + intBuffer[9] = taxisP->numavg; intBuffer[10] = taxisP->has_bounds; - intBuffer[11] = taxisP->vdate_lb; - intBuffer[12] = taxisP->vtime_lb; - intBuffer[13] = taxisP->vdate_ub; - intBuffer[14] = taxisP->vtime_ub; - - xmpi ( MPI_Pack ( intBuffer, taxisNint, MPI_INT, + intBuffer[11] = taxisP->vdate_lb; + intBuffer[12] = taxisP->vtime_lb; + intBuffer[13] = taxisP->vdate_ub; + intBuffer[14] = taxisP->vtime_ub; + + xmpi ( MPI_Pack ( intBuffer, taxisNint, MPI_INT, packBuffer, packBufferSize, packBufferPos, comm )); d = xchecksum ( DATATYPE_INT, taxisNint, intBuffer ); xmpi ( MPI_Pack ( &d, 1, MPI_DOUBLE, diff --git a/src/taxis.h b/src/taxis.h index c78e51def..a57e09041 100644 --- a/src/taxis.h +++ b/src/taxis.h @@ -20,6 +20,8 @@ typedef struct { int vtime_lb; /* lower bounds of vtime */ int vdate_ub; /* upper bounds of vdate */ int vtime_ub; /* upper bounds of vtime */ + char *name; + char *longname; } taxis_t; diff --git a/src/timebase.c b/src/timebase.c index 3c9a86d46..01e3549d7 100644 --- a/src/timebase.c +++ b/src/timebase.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdint.h> #include <math.h> /* for floor() */ #include "cdi.h" @@ -136,9 +137,9 @@ int sec_to_time(int secofday) } static -void adjust_seconds(int *julday, int *secofday) +void adjust_seconds(int *julday, int64_t *secofday) { - int secperday = 86400; + int64_t secperday = 86400; while ( *secofday >= secperday ) { @@ -154,52 +155,66 @@ void adjust_seconds(int *julday, int *secofday) } -void julday_add_seconds(int seconds, int *julday, int *secofday) +void julday_add_seconds(int64_t seconds, int *julday, int *secofday) { - *secofday += seconds; + int64_t sec_of_day = *secofday; - adjust_seconds(julday, secofday); + sec_of_day += seconds; + + adjust_seconds(julday, &sec_of_day); + + *secofday = (int) sec_of_day; } /* add days and secs to julday/secofday */ void julday_add(int days, int secs, int *julday, int *secofday) { - *julday += days; - *secofday += secs; + int64_t sec_of_day = *secofday; + + sec_of_day += secs; + *julday += days; - adjust_seconds(julday, secofday); + adjust_seconds(julday, &sec_of_day); + + *secofday = (int) sec_of_day; } /* subtract julday1/secofday1 from julday2/secofday2 and returns the result in seconds */ double julday_sub(int julday1, int secofday1, int julday2, int secofday2, int *days, int *secs) { - int seconds; + int64_t sec_of_day; + int64_t seconds; *days = julday2 - julday1; *secs = secofday2 - secofday1; - adjust_seconds(days, secs); + sec_of_day = *secs; + + adjust_seconds(days, &sec_of_day); + + *secs = (int) sec_of_day; - seconds = *days*86400. + *secs; + seconds = *days*86400. + sec_of_day; return (seconds); } -void encode_juldaysec(int calendar, int year, int month, int day, int hour, int minute, int *julday, int *secofday) +void encode_juldaysec(int calendar, int year, int month, int day, int hour, int minute, int second, int *julday, int *secofday) { *julday = encode_julday(calendar, year, month, day); - *secofday = (hour*60 + minute)*60; + *secofday = (hour*60 + minute)*60 + second; } -void decode_juldaysec(int calendar, int julday, int secofday, int *year, int *month, int *day, int *hour, int *minute) +void decode_juldaysec(int calendar, int julday, int secofday, int *year, int *month, int *day, int *hour, int *minute, int *second) { decode_julday(calendar, julday, year, month, day); *hour = secofday/3600; *minute = secofday/60 - *hour*60; + *second = secofday - *hour*3600 - *minute*60; } @@ -213,6 +228,7 @@ int main(void) int i, j = 0; int year, mon, day, hour, minute, second; int julday, secofday; + int calendar = CALENDAR_STANDARD; /* 1 - Check valid range of years */ @@ -302,36 +318,28 @@ int main(void) { int i; int julday, secofday; - int year, month, day, hour, minute; + int year, month, day, hour, minute, second; int value = 30; int factor = 86400; + int calendar = CALENDAR_STANDARD; - year=1979; month=1; day=15; hour=12; minute=30; + year=1979; month=1; day=15; hour=12; minute=30, second=17; - printf("%d/%02d/%02d %02d:%02d\n", year, month, day, hour, minute); + printf("%d/%02d/%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second); - encode_juldaysec(calendar, year, month, day, hour, minute, &julday, &secofday); + encode_juldaysec(calendar, year, month, day, hour, minute, second, &julday, &secofday); - decode_juldaysec(calendar, julday, secofday, &year, &month, &day, &hour, &minute); - printf("%d/%02d/%02d %02d:%02d %d %d\n", year, month, day, hour, minute, julday, secofday); + decode_juldaysec(calendar, julday, secofday, &year, &month, &day, &hour, &minute, &second); + printf("%d/%02d/%02d %02d:%02d:%02d %d %d\n", year, month, day, hour, minute, second, julday, secofday); for ( i = 0; i < 420; i++ ) { - decode_juldaysec(calendar, julday, secofday, &year, &month, &day, &hour, &minute); - printf("%2d %d/%02d/%02d %02d:%02d\n", i, year, month, day, hour, minute); + decode_juldaysec(calendar, julday, secofday, &year, &month, &day, &hour, &minute, &second); + printf("%2d %d/%02d/%02d %02d:%02d:%02d\n", i, year, month, day, hour, minute, second); julday_add_seconds(value*factor, &julday, &secofday); } return (0); } #endif -/* - * Local Variables: - * c-file-style: "Java" - * c-basic-offset: 2 - * indent-tabs-mode: nil - * show-trailing-whitespace: t - * require-trailing-newline: t - * End: - */ diff --git a/src/timebase.h b/src/timebase.h index 483a9787d..d298f1719 100644 --- a/src/timebase.h +++ b/src/timebase.h @@ -13,20 +13,11 @@ int julday_to_date(int calendar, int julday); int time_to_sec(int time); int sec_to_time(int secofday); -void julday_add_seconds(int seconds, int *julday, int *secofday); +void julday_add_seconds(int64_t seconds, int *julday, int *secofday); void julday_add(int days, int secs, int *julday, int *secofday); double julday_sub(int julday1, int secofday1, int julday2, int secofday2, int *days, int *secs); -void encode_juldaysec(int calendar, int year, int month, int day, int hour, int minute, int *julday, int *secofday); -void decode_juldaysec(int calendar, int julday, int secofday, int *year, int *month, int *day, int *hour, int *minute); +void encode_juldaysec(int calendar, int year, int month, int day, int hour, int minute, int second, int *julday, int *secofday); +void decode_juldaysec(int calendar, int julday, int secofday, int *year, int *month, int *day, int *hour, int *minute, int *second); #endif /* _TIMEBASE_H */ -/* - * Local Variables: - * c-file-style: "Java" - * c-basic-offset: 2 - * indent-tabs-mode: nil - * show-trailing-whitespace: t - * require-trailing-newline: t - * End: - */ diff --git a/src/tsteps.c b/src/tsteps.c index d1b1cf418..1cc139ae5 100644 --- a/src/tsteps.c +++ b/src/tsteps.c @@ -8,12 +8,9 @@ #include "stream_int.h" -static void tstepsInitEntry(int streamID, int tsID) +static +void tstepsInitEntry(stream_t *streamptr, int tsID) { - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); - streamptr->tsteps[tsID].curRecID = CDI_UNDEFID; streamptr->tsteps[tsID].position = 0; streamptr->tsteps[tsID].records = NULL; @@ -26,14 +23,12 @@ static void tstepsInitEntry(int streamID, int tsID) ptaxisInit(&streamptr->tsteps[tsID].taxis); } -int tstepsNewEntry(int streamID) + +int tstepsNewEntry(stream_t *streamptr) { int tsID = 0; int tstepsTableSize; - TSTEPS *tstepsTable; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); + tsteps_t *tstepsTable; tsID = streamptr->tstepsNextID++; tstepsTableSize = streamptr->tstepsTableSize; @@ -46,31 +41,29 @@ int tstepsNewEntry(int streamID) { if ( tstepsTableSize == 0 ) tstepsTableSize = 1; tstepsTableSize = 2*tstepsTableSize; - tstepsTable = (TSTEPS *) realloc(tstepsTable, tstepsTableSize*sizeof(TSTEPS)); + tstepsTable = (tsteps_t *) realloc(tstepsTable, tstepsTableSize*sizeof(tsteps_t)); if ( tstepsTable == NULL ) { Message("tstepsTableSize = %d", tstepsTableSize); - SysError("Reallocation of TSTEPS failed"); + SysError("Reallocation of tsteps_t failed"); } } streamptr->tstepsTableSize = tstepsTableSize; streamptr->tsteps = tstepsTable; - tstepsInitEntry(streamID, tsID); + tstepsInitEntry(streamptr, tsID); streamptr->tsteps[tsID].taxis.used = TRUE; return (tsID); } -void cdiCreateTimesteps(int streamID) + +void cdiCreateTimesteps(stream_t *streamptr) { int ntsteps; int tsID; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); if ( streamptr->ntsteps < 0 || streamptr->tstepsTableSize > 0 ) return; @@ -78,16 +71,16 @@ void cdiCreateTimesteps(int streamID) if ( streamptr->ntsteps == 0 ) ntsteps = 1; /* <<<<<-------- */ else ntsteps = streamptr->ntsteps; - streamptr->tsteps = (TSTEPS *) malloc(ntsteps*sizeof(TSTEPS)); + streamptr->tsteps = (tsteps_t *) malloc(ntsteps*sizeof(tsteps_t)); if ( streamptr->tsteps == NULL ) - SysError("Allocation of TSTEPS failed"); + SysError("Allocation of tsteps_t failed"); streamptr->tstepsTableSize = ntsteps; streamptr->tstepsNextID = ntsteps; for ( tsID = 0; tsID < ntsteps; tsID++ ) { - tstepsInitEntry(streamID, tsID); + tstepsInitEntry(streamptr, tsID); streamptr->tsteps[tsID].taxis.used = TRUE; } } diff --git a/src/util.c b/src/util.c index 4d18c5a05..6a0f540b3 100644 --- a/src/util.c +++ b/src/util.c @@ -20,27 +20,27 @@ void cdiPrintDatatypes(void) /* IsBigendian returns 1 for big endian byte order */ static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1}; - fprintf (stderr, "+-------------+-------+\n"); - fprintf (stderr, "| types | bytes |\n"); - fprintf (stderr, "+-------------+-------+\n"); + fprintf (stderr, "+-------------+-------+\n"); + fprintf (stderr, "| types | bytes |\n"); + fprintf (stderr, "+-------------+-------+\n"); fprintf (stderr, "| void * | %3d |\n", (int) sizeof(void *)); - fprintf (stderr, "+-------------+-------+\n"); + fprintf (stderr, "+-------------+-------+\n"); fprintf (stderr, "| char | %3d |\n", (int) sizeof(char)); - fprintf (stderr, "+-------------+-------+\n"); + fprintf (stderr, "+-------------+-------+\n"); fprintf (stderr, "| short | %3d |\n", (int) sizeof(short)); fprintf (stderr, "| int | %3d |\n", (int) sizeof(int)); fprintf (stderr, "| long | %3d |\n", (int) sizeof(long)); fprintf (stderr, "| long long | %3d |\n", (int) sizeof(long long)); fprintf (stderr, "| size_t | %3d |\n", (int) sizeof(size_t)); fprintf (stderr, "| off_t | %3d |\n", (int) sizeof(off_t)); - fprintf (stderr, "+-------------+-------+\n"); + fprintf (stderr, "+-------------+-------+\n"); fprintf (stderr, "| float | %3d |\n", (int) sizeof(float)); fprintf (stderr, "| double | %3d |\n", (int) sizeof(double)); fprintf (stderr, "| long double | %3d |\n", (int) sizeof(long double)); - fprintf (stderr, "+-------------+-------+\n\n"); + fprintf (stderr, "+-------------+-------+\n\n"); #define XSTRING(x) #x #define STRING(x) XSTRING(x) - fprintf (stderr, "+-------------+-----------+\n"); + fprintf (stderr, "+-------------+-----------+\n"); fprintf (stderr, "| INT32 | %-9s |\n", STRING(INT32)); fprintf (stderr, "| INT64 | %-9s |\n", STRING(INT64)); fprintf (stderr, "| FLT32 | %-9s |\n", STRING(FLT32)); @@ -52,6 +52,51 @@ void cdiPrintDatatypes(void) else fprintf (stderr, "\n byte ordering is LITTLEENDIAN\n\n"); } + + +void uuid2str(const char *uuid, char *uuidstr) +{ + int iret; + unsigned int ui[16]; + + if ( uuid == NULL ) return; + if ( uuidstr == NULL ) return; + + uuidstr[0] = 0; + + for ( int i = 0; i < 16; ++i ) ui[i] = (unsigned char) uuid[i]; + + iret = sprintf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + ui[0], ui[1], ui[2], ui[3], ui[4], ui[5], ui[6], ui[7], + ui[8], ui[9], ui[10], ui[11], ui[12], ui[13], ui[14], ui[15]); + + if ( iret != 36 ) uuidstr[0] = 0; +} + + +void str2uuid(const char *uuidstr, char *uuid) +{ + int iret; + unsigned int ui[16]; + + if ( uuid == NULL ) return; + if ( uuidstr == NULL ) return; + + uuid[0] = 0; + + if ( strlen(uuidstr) != 36 ) return; + + iret = sscanf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + &ui[0], &ui[1], &ui[2], &ui[3], &ui[4], &ui[5], &ui[6], &ui[7], + &ui[8], &ui[9], &ui[10], &ui[11], &ui[12], &ui[13], &ui[14], &ui[15]); + + if ( iret != 16 ) return; + + for ( int i = 0; i < 16; ++i ) uuid[i] = ui[i]; + + uuid[16] = 0; +} + /* * Local Variables: * c-file-style: "Java" diff --git a/src/varscan.c b/src/varscan.c index 950f6844e..f4a3a3f8d 100644 --- a/src/varscan.c +++ b/src/varscan.c @@ -11,6 +11,7 @@ #include "varscan.h" #include "vlist.h" #include "grid.h" +#include "zaxis.h" extern void zaxisGetIndexList ( int, int * ); @@ -46,6 +47,7 @@ typedef struct int zaxistype; int ltype; /* GRIB level type */ int lbounds; + int level_sf; int zaxisID; int nlevels; int levelTableSize; @@ -60,6 +62,7 @@ typedef struct char *name; char *longname; char *units; + ensinfo_t *ensdata; } vartable_t; @@ -81,6 +84,8 @@ void paramInitEntry(int varID, int param) vartable[varID].gridID = UNDEFID; vartable[varID].zaxistype = 0; vartable[varID].ltype = 0; + vartable[varID].lbounds = 0; + vartable[varID].level_sf = 0; vartable[varID].levelTable = NULL; vartable[varID].levelTableSize = 0; vartable[varID].nlevels = 0; @@ -94,11 +99,11 @@ void paramInitEntry(int varID, int param) vartable[varID].name = NULL; vartable[varID].longname = NULL; vartable[varID].units = NULL; + vartable[varID].ensdata = NULL; } - static -int varGetEntry(int param, int zaxistype, int ltype) +int varGetEntry(int param, int zaxistype, int ltype, const char *name) { int varID; @@ -107,13 +112,22 @@ int varGetEntry(int param, int zaxistype, int ltype) if ( vartable[varID].param == param && vartable[varID].zaxistype == zaxistype && vartable[varID].ltype == ltype ) - return (varID); + { + if ( name && name[0] && vartable[varID].name && vartable[varID].name[0] ) + { + if ( strcmp(name, vartable[varID].name) == 0 ) return (varID); + } + else + { + return (varID); + } + } } return (UNDEFID); } - +static void varFree(void) { int varID; @@ -126,6 +140,7 @@ void varFree(void) if ( vartable[varID].name ) free(vartable[varID].name); if ( vartable[varID].longname ) free(vartable[varID].longname); if ( vartable[varID].units ) free(vartable[varID].units); + if ( vartable[varID].ensdata ) free(vartable[varID].ensdata); } if ( vartable ) @@ -142,6 +157,7 @@ void varFree(void) Vctsize = 0; } +static int levelNewEntry(int varID, int level1, int level2) { int levelID = 0; @@ -198,9 +214,9 @@ int levelNewEntry(int varID, int level1, int level2) levelTable[i].recID = UNDEFID; } - levelTable[levelID].level1 = level1; - levelTable[levelID].level2 = level2; - levelTable[levelID].lindex = levelID; + levelTable[levelID].level1 = level1; + levelTable[levelID].level2 = level2; + levelTable[levelID].lindex = levelID; vartable[varID].nlevels = levelID+1; vartable[varID].levelTableSize = levelTableSize; @@ -211,7 +227,8 @@ int levelNewEntry(int varID, int level1, int level2) #define UNDEF_PARAM -4711 -int paramNewEntry (int param) +static +int paramNewEntry(int param) { int varID = 0; @@ -269,7 +286,7 @@ int paramNewEntry (int param) void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds, - int level1, int level2, int prec, + int level1, int level2, int level_sf, int prec, int *pvarID, int *plevelID, int tsteptype, int numavg, int ltype, const char *name, const char *longname, const char *units) { @@ -277,7 +294,7 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds, int levelID = -1; if ( ! (cdiSplitLtype105 == 1 && zaxistype == ZAXIS_HEIGHT) ) - varID = varGetEntry(param, zaxistype, ltype); + varID = varGetEntry(param, zaxistype, ltype, name); if ( varID == UNDEFID ) { @@ -287,6 +304,7 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds, vartable[varID].zaxistype = zaxistype; vartable[varID].ltype = ltype; vartable[varID].lbounds = lbounds; + vartable[varID].level_sf = level_sf; if ( tsteptype != UNDEFID ) vartable[varID].tsteptype = tsteptype; if ( numavg ) vartable[varID].timave = 1; @@ -296,17 +314,16 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds, } else { + char paramstr[32]; + cdiParamToString(param, paramstr, sizeof(paramstr)); + if ( vartable[varID].gridID != gridID ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); Message("param = %s gridID = %d", paramstr, gridID); Error("horizontal grid must not change for same param!"); } if ( vartable[varID].zaxistype != zaxistype ) { - char paramstr[32]; - cdiParamToString(param, paramstr, sizeof(paramstr)); Message("param = %s zaxistype = %d", paramstr, zaxistype); Error("zaxistype must not change for same param!"); } @@ -323,8 +340,8 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds, *pvarID = varID; *plevelID = levelID; } - - +/* +static int dblcmp(const void *s1, const void *s2) { int cmp = 0; @@ -334,8 +351,8 @@ int dblcmp(const void *s1, const void *s2) return (cmp); } - - +*/ +static int cmpLevelTable(const void *s1, const void *s2) { int cmp = 0; @@ -388,7 +405,7 @@ int cmpltype(const void *s1, const void *s2) } -void cdiGenVars(int streamID) +void cdi_generate_vars(stream_t *streamptr) { int varID, gridID, zaxisID, levelID; int instID, modelID, tableID; @@ -398,17 +415,15 @@ void cdiGenVars(int streamID) int timave, timaccu; int lbounds; int comptype; - char name[256], longname[256], units[256]; + char name[CDI_MAX_NAME], longname[CDI_MAX_NAME], units[CDI_MAX_NAME]; double *dlevels = NULL; double *dlevels1 = NULL; double *dlevels2 = NULL; int vlistID; int *varids, index, varid; - stream_t *streamptr; - - streamptr = stream_to_pointer(streamID); + double level_sf = 1; - vlistID = streamInqVlist(streamID); + vlistID = streamptr->vlistID; varids = (int *) malloc(nvars*sizeof(int)); for ( varID = 0; varID < nvars; varID++ ) varids[varID] = varID; @@ -460,6 +475,9 @@ void cdiGenVars(int streamID) timaccu = vartable[varid].timaccu; comptype = vartable[varid].comptype; + level_sf = 1; + if ( vartable[varid].level_sf == 77 ) level_sf = 0.001; + zaxisID = UNDEFID; if ( ltype == 0 && zaxistype == ZAXIS_GENERIC && nlevels == 1 && @@ -470,11 +488,11 @@ void cdiGenVars(int streamID) if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF ) for ( levelID = 0; levelID < nlevels; levelID++ ) - dlevels[levelID] = (vartable[varid].levelTable[levelID].level1 + - vartable[varid].levelTable[levelID].level2)/2; + dlevels[levelID] = (level_sf*vartable[varid].levelTable[levelID].level1 + + level_sf*vartable[varid].levelTable[levelID].level2)/2; else for ( levelID = 0; levelID < nlevels; levelID++ ) - dlevels[levelID] = vartable[varid].levelTable[levelID].level1; + dlevels[levelID] = level_sf*vartable[varid].levelTable[levelID].level1; if ( nlevels > 1 ) { @@ -500,16 +518,15 @@ void cdiGenVars(int streamID) /* qsort(dlevels, nlevels, sizeof(double), dblcmp); */ - qsort(vartable[varid].levelTable, nlevels, - sizeof(leveltable_t), cmpLevelTable); + qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTable); if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF ) for ( levelID = 0; levelID < nlevels; levelID++ ) - dlevels[levelID] = (vartable[varid].levelTable[levelID].level1 + - vartable[varid].levelTable[levelID].level2)/2.; + dlevels[levelID] = (level_sf*vartable[varid].levelTable[levelID].level1 + + level_sf*vartable[varid].levelTable[levelID].level2)/2.; else for ( levelID = 0; levelID < nlevels; levelID++ ) - dlevels[levelID] = vartable[varid].levelTable[levelID].level1; + dlevels[levelID] = level_sf*vartable[varid].levelTable[levelID].level1; } } } @@ -518,20 +535,24 @@ void cdiGenVars(int streamID) { dlevels1 = (double *) malloc(nlevels*sizeof(double)); for ( levelID = 0; levelID < nlevels; levelID++ ) - dlevels1[levelID] = vartable[varid].levelTable[levelID].level1; + dlevels1[levelID] = level_sf*vartable[varid].levelTable[levelID].level1; dlevels2 = (double *) malloc(nlevels*sizeof(double)); for ( levelID = 0; levelID < nlevels; levelID++ ) - dlevels2[levelID] = vartable[varid].levelTable[levelID].level2; + dlevels2[levelID] = level_sf*vartable[varid].levelTable[levelID].level2; } - zaxisID = varDefZaxis(vlistID, zaxistype, nlevels, dlevels, lbounds, dlevels1, dlevels2, - Vctsize, Vct, NULL, NULL, NULL, 0, 0, ltype); + if ( vartable[varid].level_sf == 77 ) + zaxisID = varDefZaxis(vlistID, zaxistype, nlevels, dlevels, lbounds, dlevels1, dlevels2, + Vctsize, Vct, NULL, NULL, "m", 0, 0, ltype); + else + zaxisID = varDefZaxis(vlistID, zaxistype, nlevels, dlevels, lbounds, dlevels1, dlevels2, + Vctsize, Vct, NULL, NULL, NULL, 0, 0, ltype); if ( lbounds ) free(dlevels1); if ( lbounds ) free(dlevels2); free(dlevels); - varID = streamNewVar(streamID, gridID, zaxisID); + varID = stream_new_var(streamptr, gridID, zaxisID); varID = vlistDefVar(vlistID, gridID, zaxisID, tsteptype); vlistDefVarParam(vlistID, varID, param); @@ -546,6 +567,10 @@ void cdiGenVars(int streamID) if ( vartable[varid].longname ) vlistDefVarLongname(vlistID, varID, vartable[varid].longname); if ( vartable[varid].units ) vlistDefVarUnits(vlistID, varID, vartable[varid].units); + if ( vartable[varid].ensdata ) vlistDefVarEnsemble(vlistID, varID, vartable[varid].ensdata->ens_index, + vartable[varid].ensdata->ens_count, + vartable[varid].ensdata->forecast_init_type); + if ( cdiDefaultTableID != UNDEFID ) { int pdis, pcat, pnum; @@ -597,8 +622,7 @@ void cdiGenVars(int streamID) */ for ( levelID = 0; levelID < nlevels; levelID++ ) { - streamptr->vars[varID].level[levelID] = - vartable[varid].levelTable[levelID].recID; + streamptr->vars[varID].level[levelID] = vartable[varid].levelTable[levelID].recID; for ( lindex = 0; lindex < nlevels; lindex++ ) if ( levelID == vartable[varid].levelTable[lindex].lindex ) break; @@ -625,6 +649,7 @@ void varDefVCT(size_t vctsize, double *vctptr) } } + void varDefZAxisReference(int nlev, int nvgrid, char *uuid) { numberOfVerticalLevels = nlev; @@ -632,6 +657,7 @@ void varDefZAxisReference(int nlev, int nvgrid, char *uuid) strncpy(uuidVGrid, uuid, 16); } + int varDefGrid(int vlistID, grid_t grid, int mode) { /* @@ -670,7 +696,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode) ngrids = gridSize(); if ( ngrids > 0 ) { - gridIndexList = malloc ( ngrids * sizeof ( int )); + gridIndexList = malloc(ngrids*sizeof(int)); gridGetIndexList ( ngrids, gridIndexList ); for ( i = 0; i < ngrids; i++ ) { @@ -721,8 +747,8 @@ int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, double *l if ( nlevels == zaxisInqSize(zaxisID) && zlbounds == lbounds ) { const double *dlevels; - char zlongname[256]; - char zunits[256]; + char zlongname[CDI_MAX_NAME]; + char zunits[CDI_MAX_NAME]; dlevels = zaxisInqLevelsPtr(zaxisID); for ( levelID = 0; levelID < nlevels; levelID++ ) @@ -767,7 +793,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo int index; int zaxisglobdefined = 0; vlist_t *vlistptr; - int * zaxisIndexList, i; + int i; vlistptr = vlist_to_pointer(vlistID); @@ -791,7 +817,8 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo nzaxis = zaxisSize(); if ( nzaxis > 0 ) { - zaxisIndexList = malloc ( nzaxis * sizeof ( int )); + int *zaxisIndexList; + zaxisIndexList = (int *) malloc ( nzaxis * sizeof ( int )); zaxisGetIndexList ( nzaxis, zaxisIndexList ); for ( i = 0; i < nzaxis; i++ ) { @@ -907,6 +934,18 @@ void varDefTable(int varID, int tableID) { vartable[varID].tableID = tableID; } + + +void varDefEnsembleInfo(int varID, int ens_idx, int ens_count, int forecast_type) +{ + if ( vartable[varID].ensdata == NULL ) + vartable[varID].ensdata = (ensinfo_t *) malloc( sizeof( ensinfo_t ) ); + + vartable[varID].ensdata->ens_index = ens_idx; + vartable[varID].ensdata->ens_count = ens_count; + vartable[varID].ensdata->forecast_init_type = forecast_type; +} + /* * Local Variables: * c-file-style: "Java" diff --git a/src/varscan.h b/src/varscan.h index 1be1f90c0..f24f162cd 100644 --- a/src/varscan.h +++ b/src/varscan.h @@ -7,7 +7,7 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds, - int level1, int level2, int prec, + int level1, int level2, int level_sf, int prec, int *pvarID, int *plevelID, int tsteptype, int numavg, int ltype, const char *name, const char *longname, const char *units); @@ -27,6 +27,7 @@ void varDefModel(int varID, int modelID); int varInqModel(int varID); void varDefTable(int varID, int tableID); int varInqTable(int varID); +void varDefEnsembleInfo(int varID, int ens_idx, int ens_count, int forecast_type); int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, double *levels, char *longname, char *units, int ltype); diff --git a/src/vlist.c b/src/vlist.c index bb58c0546..6adb0beac 100644 --- a/src/vlist.c +++ b/src/vlist.c @@ -6,6 +6,7 @@ #include "cdi.h" #include "stream_int.h" #include "vlist.h" +#include "zaxis.h" #include "varscan.h" #include "namespace.h" #include "pio_util.h" @@ -14,6 +15,8 @@ #include "vlist_att.h" #include "pio_rpc.h" +extern void zaxisGetIndexList ( int, int * ); + static int VLIST_Debug = 0; static void vlist_initialize(void); @@ -31,7 +34,7 @@ static pthread_once_t _vlist_init_thread = PTHREAD_ONCE_INIT; static int vlistIsInitialized = 0; # define VLIST_INIT() \ - if ( _vlist_init == FALSE ) vlist_initialize() + if ( !vlistIsInitialized ) vlist_initialize() #endif @@ -130,6 +133,9 @@ void vlist_initialize(void) env = getenv("VLIST_DEBUG"); if ( env ) VLIST_Debug = atoi(env); +#ifndef HAVE_LIBPTHREAD + vlistIsInitialized = TRUE; +#endif } static @@ -180,6 +186,8 @@ int vlistCreate(void) int vlistID = 0; vlist_t *vlistptr; + cdiInitialize(); + VLIST_INIT(); vlistptr = vlist_new_entry(); @@ -210,6 +218,17 @@ vlist_delete(vlist_t *vlistptr) if ( vlistptr->vars[varID].ensdata ) free(vlistptr->vars[varID].ensdata); if ( vlistptr->vars[varID].deco ) free(vlistptr->vars[varID].deco); + + int i; + for (i=0; i<vlistptr->vars[varID].opt_grib_int_nentries; i++) { + if ( vlistptr->vars[varID].opt_grib_int_keyword[i] ) + free(vlistptr->vars[varID].opt_grib_int_keyword[i]); + } + for (i=0; i<vlistptr->vars[varID].opt_grib_dbl_nentries; i++) { + if ( vlistptr->vars[varID].opt_grib_dbl_keyword[i] ) + free(vlistptr->vars[varID].opt_grib_dbl_keyword[i]); + } + vlistDelAtts(vlistID, varID); } @@ -289,12 +308,6 @@ void vlistCopy(int vlistID2, int vlistID1) if ( vlistptr1->vars[varID].units ) vlistptr2->vars[varID].units = strdupx(vlistptr1->vars[varID].units); - nlevs = vlistptr1->vars[varID].nlevs; - vlistptr2->vars[varID].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t)); - memcpy(vlistptr2->vars[varID].levinfo, - vlistptr1->vars[varID].levinfo, nlevs*sizeof(levinfo_t)); - - if ( vlistptr2->vars[varID].ensdata ) free(vlistptr2->vars[varID].ensdata); if ( vlistptr1->vars[varID].ensdata ) { vlistptr2->vars[varID].ensdata = (ensinfo_t *) malloc(sizeof(ensinfo_t)); @@ -309,8 +322,33 @@ void vlistCopy(int vlistID2, int vlistID1) decoSize * sizeof (deco_t)); } + /* ---------------------------------- */ + /* Local change: 2013-01-28, FP (DWD) */ + /* ---------------------------------- */ + + int i; + vlistptr2->vars[varID].opt_grib_int_nentries = vlistptr1->vars[varID].opt_grib_int_nentries; + for (i=0; i<vlistptr1->vars[varID].opt_grib_int_nentries; i++) { + if ( vlistptr1->vars[varID].opt_grib_int_keyword[i] ) { + vlistptr2->vars[varID].opt_grib_int_keyword[i] = strdupx(vlistptr1->vars[varID].opt_grib_int_keyword[i]); + vlistptr2->vars[varID].opt_grib_int_val[i] = vlistptr1->vars[varID].opt_grib_int_val[i]; + } + } + vlistptr2->vars[varID].opt_grib_dbl_nentries = vlistptr1->vars[varID].opt_grib_dbl_nentries; + for (i=0; i<vlistptr1->vars[varID].opt_grib_dbl_nentries; i++) { + if ( vlistptr1->vars[varID].opt_grib_dbl_keyword[i] ) { + vlistptr2->vars[varID].opt_grib_dbl_keyword[i] = strdupx(vlistptr1->vars[varID].opt_grib_dbl_keyword[i]); + vlistptr2->vars[varID].opt_grib_dbl_val[i] = vlistptr1->vars[varID].opt_grib_dbl_val[i]; + } + } + vlistptr2->vars[varID].atts.nelems = 0; vlistCopyVarAtts(vlistID1, varID, vlistID2, varID); + + nlevs = vlistptr1->vars[varID].nlevs; + vlistptr2->vars[varID].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t)); + memcpy(vlistptr2->vars[varID].levinfo, + vlistptr1->vars[varID].levinfo, nlevs*sizeof(levinfo_t)); } } } @@ -368,15 +406,16 @@ void vlistClearFlag(int vlistID) } } - -int vlistInqZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbounds, double *levels2, - int vctsize, const double *vct) +static +int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, double *levels, + double *lbounds, double *ubounds, int vctsize, const double *vct) { int zaxisdefined; int nzaxis; int zaxisID = CDI_UNDEFID; int index; int zaxisglobdefined = 0; + int has_bounds = FALSE; vlist_t *vlistptr; vlistptr = vlist_to_pointer(vlistID); @@ -386,11 +425,13 @@ int vlistInqZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int l zaxisdefined = 0; nzaxis = vlistptr->nzaxis; - for ( index = 0; index < nzaxis; index++ ) + if ( lbounds && ubounds ) has_bounds = TRUE; + + for ( index = 0; index < nzaxis; ++index ) { zaxisID = vlistptr->zaxisIDs[index]; - if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, NULL, NULL, 0) == 0 ) + if ( zaxisCompare(zaxisID, zaxistype, nlevels, has_bounds, levels, NULL, NULL, 0) == 0 ) { zaxisdefined = 1; break; @@ -400,12 +441,22 @@ int vlistInqZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int l if ( ! zaxisdefined ) { nzaxis = zaxisSize(); - for ( zaxisID = 0; zaxisID < nzaxis; zaxisID++ ) - if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, NULL, NULL, 0) == 0 ) - { - zaxisglobdefined = 1; - break; - } + if ( nzaxis > 0 ) + { + int *zaxisIndexList; + zaxisIndexList = (int *) malloc ( nzaxis * sizeof ( int )); + zaxisGetIndexList ( nzaxis, zaxisIndexList ); + for ( index = 0; index < nzaxis; ++index ) + { + zaxisID = zaxisIndexList[index]; + if ( zaxisCompare(zaxisID, zaxistype, nlevels, has_bounds, levels, NULL, NULL, 0) == 0 ) + { + zaxisglobdefined = 1; + break; + } + } + if ( zaxisIndexList ) free ( zaxisIndexList ); + } } if ( ! zaxisdefined ) @@ -414,10 +465,10 @@ int vlistInqZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int l { zaxisID = zaxisCreate(zaxistype, nlevels); zaxisDefLevels(zaxisID, levels); - if ( lbounds ) + if ( has_bounds ) { - zaxisDefLbounds(zaxisID, levels); - zaxisDefUbounds(zaxisID, levels2); + zaxisDefLbounds(zaxisID, lbounds); + zaxisDefUbounds(zaxisID, ubounds); } if ( zaxistype == ZAXIS_HYBRID ) @@ -513,6 +564,36 @@ void vlistCopyFlag(int vlistID2, int vlistID1) if ( vlistptr1->vars[varID].units ) vlistptr2->vars[varID2].units = strdupx(vlistptr1->vars[varID].units); + if ( vlistptr1->vars[varID].ensdata ) + { + vlistptr2->vars[varID2].ensdata = (ensinfo_t *) malloc(sizeof(ensinfo_t)); + memcpy(vlistptr2->vars[varID2].ensdata, + vlistptr1->vars[varID].ensdata, sizeof(ensinfo_t)); + } + + /* ---------------------------------- */ + /* Local change: 2013-01-28, FP (DWD) */ + /* ---------------------------------- */ + + int i; + vlistptr2->vars[varID2].opt_grib_int_nentries = vlistptr1->vars[varID].opt_grib_int_nentries; + for (i=0; i<vlistptr1->vars[varID].opt_grib_int_nentries; i++) { + if ( vlistptr1->vars[varID].opt_grib_int_keyword[i] ) { + vlistptr2->vars[varID2].opt_grib_int_keyword[i] = strdupx(vlistptr1->vars[varID].opt_grib_int_keyword[i]); + vlistptr2->vars[varID2].opt_grib_int_val[i] = vlistptr1->vars[varID].opt_grib_int_val[i]; + } + } + vlistptr2->vars[varID2].opt_grib_dbl_nentries = vlistptr1->vars[varID].opt_grib_dbl_nentries; + for (i=0; i<vlistptr1->vars[varID].opt_grib_dbl_nentries; i++) { + if ( vlistptr1->vars[varID].opt_grib_dbl_keyword[i] ) { + vlistptr2->vars[varID2].opt_grib_dbl_keyword[i] = strdupx(vlistptr1->vars[varID].opt_grib_dbl_keyword[i]); + vlistptr2->vars[varID2].opt_grib_dbl_val[i] = vlistptr1->vars[varID].opt_grib_dbl_val[i]; + } + } + + vlistptr2->vars[varID2].atts.nelems = 0; + vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2); + nlevs = vlistptr1->vars[varID].nlevs; nlevs2 = 0; for ( levID = 0; levID < nlevs; levID++ ) @@ -520,23 +601,20 @@ void vlistCopyFlag(int vlistID2, int vlistID1) vlistptr2->vars[varID2].levinfo = (levinfo_t *) malloc(nlevs2*sizeof(levinfo_t)); - vlistptr2->vars[varID2].atts.nelems = 0; - vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2); - if ( nlevs != nlevs2 ) { int zaxisType; int zaxisID2; int nvct = 0; - int lbounds; double *levels; - double *levels2; + double *lbounds = NULL, *ubounds = NULL; const double *vct = NULL; + char ctemp[CDI_MAX_NAME]; zaxisID = vlistptr1->vars[varID].zaxisID; levels = (double *) malloc(nlevs2*sizeof(double)); levID2 = 0; - for ( levID = 0; levID < nlevs; levID++ ) + for ( levID = 0; levID < nlevs; ++levID ) if ( vlistptr1->vars[varID].levinfo[levID].flag ) { vlistptr1->vars[varID].levinfo[levID].flevelID = levID2; @@ -551,20 +629,43 @@ void vlistCopyFlag(int vlistID2, int vlistID1) nvct = zaxisInqVctSize(zaxisID); vct = zaxisInqVctPtr(zaxisID); } - lbounds = 0; /* <------------ have to defined */ - levels2 = NULL; /* <------------ have to defined */ - zaxisID2 = vlistInqZaxis(vlistID2, zaxisType, nlevs2, levels, lbounds, levels2, nvct, vct); + + if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) ) + { + double *lbounds1, *ubounds1; + lbounds1 = (double *) malloc(nlevs*sizeof(double)); + ubounds1 = (double *) malloc(nlevs*sizeof(double)); + + zaxisInqLbounds(zaxisID, lbounds1); + zaxisInqUbounds(zaxisID, ubounds1); + + lbounds = (double *) malloc(nlevs2*sizeof(double)); + ubounds = (double *) malloc(nlevs2*sizeof(double)); + + levID2 = 0; + for ( levID = 0; levID < nlevs; ++levID ) + if ( vlistptr1->vars[varID].levinfo[levID].flag ) + { + lbounds[levID2] = lbounds1[levID]; + ubounds[levID2] = ubounds1[levID]; + levID2++; + } + + free(lbounds1); + free(ubounds1); + } + + zaxisID2 = vlist_generate_zaxis(vlistID2, zaxisType, nlevs2, levels, lbounds, ubounds, nvct, vct); free(levels); + if ( lbounds ) free(lbounds); + if ( ubounds ) free(ubounds); - { - char ctemp[256]; - zaxisInqName(zaxisID, ctemp); - zaxisDefName(zaxisID2, ctemp); - zaxisInqLongname(zaxisID, ctemp); - zaxisDefLongname(zaxisID2, ctemp); - zaxisInqUnits(zaxisID, ctemp); - zaxisDefUnits(zaxisID2, ctemp); - } + zaxisInqName(zaxisID, ctemp); + zaxisDefName(zaxisID2, ctemp); + zaxisInqLongname(zaxisID, ctemp); + zaxisDefLongname(zaxisID2, ctemp); + zaxisInqUnits(zaxisID, ctemp); + zaxisDefUnits(zaxisID2, ctemp); zaxisID = zaxisID2; vlistptr2->vars[varID2].zaxisID = zaxisID2; @@ -663,7 +764,7 @@ void vlistCat(int vlistID2, int vlistID1) { int pnum, pcat, pdis; cdiDecodeParam(vlistptr1->vars[varID].param, &pnum, &pcat, &pdis); - pnum=-(varID2+1); + pnum = -(varID2+1); vlistptr2->vars[varID2].param = cdiEncodeParam(pnum, pcat, pdis); } @@ -689,6 +790,26 @@ void vlistCat(int vlistID2, int vlistID1) memcpy(vlistptr2->vars[varID2].ensdata, vlistptr1->vars[varID].ensdata, sizeof(ensinfo_t)); } + /* ---------------------------------- */ + /* Local change: 2013-01-28, FP (DWD) */ + /* ---------------------------------- */ + + int i; + vlistptr2->vars[varID2].opt_grib_int_nentries = vlistptr1->vars[varID].opt_grib_int_nentries; + for (i=0; i<vlistptr1->vars[varID].opt_grib_int_nentries; i++) { + if ( vlistptr1->vars[varID].opt_grib_int_keyword[i] ) { + vlistptr2->vars[varID2].opt_grib_int_keyword[i] = strdupx(vlistptr1->vars[varID].opt_grib_int_keyword[i]); + vlistptr2->vars[varID2].opt_grib_int_val[i] = vlistptr1->vars[varID].opt_grib_int_val[i]; + } + } + vlistptr2->vars[varID2].opt_grib_dbl_nentries = vlistptr1->vars[varID].opt_grib_dbl_nentries; + for (i=0; i<vlistptr1->vars[varID].opt_grib_dbl_nentries; i++) { + if ( vlistptr1->vars[varID].opt_grib_dbl_keyword[i] ) { + vlistptr2->vars[varID2].opt_grib_dbl_keyword[i] = strdupx(vlistptr1->vars[varID].opt_grib_dbl_keyword[i]); + vlistptr2->vars[varID2].opt_grib_dbl_val[i] = vlistptr1->vars[varID].opt_grib_dbl_val[i]; + } + } + vlistptr2->vars[varID2].atts.nelems = 0; vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2); @@ -1101,7 +1222,7 @@ vlistPrintKernel(vlist_t *vlistptr, FILE * fp ) decoSize = vlistptr->vars[varID].decoSize; size = vlistptr->vars[varID].nlevs * gridInqSize ( vlistptr->vars[varID].gridID ); - + for ( i = 0; i < decoSize; i++ ) { rank = vlistptr->vars[varID].deco[i].rank; @@ -1110,7 +1231,7 @@ vlistPrintKernel(vlist_t *vlistptr, FILE * fp ) fprintf ( fp, "%3d %8d %6d %6d %6d %8d %6d\n", varID, size, iorank, decoSize, rank, offset, chunk ); } - } + } } } diff --git a/src/vlist.h b/src/vlist.h index fc2db402b..a49f3940c 100644 --- a/src/vlist.h +++ b/src/vlist.h @@ -68,6 +68,13 @@ typedef struct } ensinfo_t; +/* ---------------------------------- */ +/* Local change: 2013-01-28, FP (DWD) */ +/* ---------------------------------- */ + +/* Length of optional keyword/value pair list */ +#define MAX_OPT_GRIB_ENTRIES 50 + typedef struct { @@ -86,6 +93,7 @@ typedef struct int tableID; int timave; int timaccu; + int chunktype; int xyz; int missvalused; /* TRUE if missval is defined */ int lvalidrange; @@ -106,6 +114,18 @@ typedef struct int decoSize; deco_t *deco; + /* ---------------------------------- */ + /* Local change: 2013-01-28, FP (DWD) */ + /* ---------------------------------- */ + + /* (Optional) list of keyword/double value pairs */ + int opt_grib_dbl_nentries; + char* opt_grib_dbl_keyword[MAX_OPT_GRIB_ENTRIES]; + double opt_grib_dbl_val[MAX_OPT_GRIB_ENTRIES]; + /* (Optional) list of keyword/integer value pairs */ + int opt_grib_int_nentries; + char* opt_grib_int_keyword[MAX_OPT_GRIB_ENTRIES]; + int opt_grib_int_val[MAX_OPT_GRIB_ENTRIES]; } var_t; diff --git a/src/vlist_var.c b/src/vlist_var.c index 1e361b15d..ec938fd4a 100644 --- a/src/vlist_var.c +++ b/src/vlist_var.c @@ -35,6 +35,7 @@ void vlistvarInitEntry(int vlistID, int varID) vlistptr->vars[varID].tsteptype = TSTEP_INSTANT; vlistptr->vars[varID].timave = 0; vlistptr->vars[varID].timaccu = 0; + vlistptr->vars[varID].chunktype = cdiChunkType; vlistptr->vars[varID].xyz = 0; vlistptr->vars[varID].gridID = CDI_UNDEFID; vlistptr->vars[varID].zaxisID = CDI_UNDEFID; @@ -59,9 +60,23 @@ void vlistvarInitEntry(int vlistID, int varID) vlistptr->vars[varID].validrange[0] = VALIDMISS; vlistptr->vars[varID].validrange[1] = VALIDMISS; vlistptr->vars[varID].ensdata = NULL; - vlistptr->vars[varID].iorank = CDI_UNDEFID; - vlistptr->vars[varID].decoSize = 0; - vlistptr->vars[varID].deco = NULL; + vlistptr->vars[varID].iorank = CDI_UNDEFID; + vlistptr->vars[varID].decoSize = 0; + vlistptr->vars[varID].deco = NULL; + + /* ---------------------------------- */ + /* Local change: 2013-01-28, FP (DWD) */ + /* ---------------------------------- */ + + vlistptr->vars[varID].opt_grib_dbl_nentries = 0; + vlistptr->vars[varID].opt_grib_int_nentries = 0; + int i; + for (i=0; i<MAX_OPT_GRIB_ENTRIES; i++) { + vlistptr->vars[varID].opt_grib_dbl_val[i] = 0.0; + vlistptr->vars[varID].opt_grib_int_val[i] = 0; + vlistptr->vars[varID].opt_grib_int_keyword[i] = NULL; + vlistptr->vars[varID].opt_grib_dbl_keyword[i] = NULL; + } // for } static @@ -656,7 +671,7 @@ void vlistInqVarStdname(int vlistID, int varID, char *stdname) if ( vlistptr->vars[varID].stdname == NULL ) { stdname[0] = '\0'; - } + } else strcpy(stdname, vlistptr->vars[varID].stdname); @@ -671,7 +686,7 @@ void vlistInqVarStdname(int vlistID, int varID, char *stdname) @Parameter @Item vlistID Variable list ID, from a previous call to @fref{vlistCreate}. @Item varID Variable identifier. - @Item units Units of the variable. The caller must allocate space for the + @Item units Units of the variable. The caller must allocate space for the returned string. The maximum possible length, in characters, of the string is given by the predefined constant @func{CDI_MAX_NAME}. @@ -1683,6 +1698,30 @@ int vlistInqVarCompLevel(int vlistID, int varID) } +void vlistDefVarChunkType(int vlistID, int varID, int chunktype) +{ + vlist_t *vlistptr; + + vlistptr = vlist_to_pointer(vlistID); + + vlistCheckVarID(__func__, vlistID, varID); + + vlistptr->vars[varID].chunktype = chunktype; +} + + +int vlistInqVarChunkType(int vlistID, int varID) +{ + vlist_t *vlistptr; + + vlistptr = vlist_to_pointer(vlistID); + + vlistCheckVarID(__func__, vlistID, varID); + + return (vlistptr->vars[varID].chunktype); +} + + void vlistDefVarXYZ(int vlistID, int varID, int xyz) { vlist_t *vlistptr; @@ -1741,63 +1780,137 @@ void vlistDefVarEnsemble(int vlistID, int varID, int ensID, int ensCount, int fo vlistCheckVarID(__func__, vlistID, varID); if ( vlistptr->vars[varID].ensdata == NULL ) - vlistptr->vars[varID].ensdata = (ensinfo_t *) malloc( sizeof( ensinfo_t ) ); + vlistptr->vars[varID].ensdata = (ensinfo_t *) malloc( sizeof( ensinfo_t ) ); vlistptr->vars[varID].ensdata->ens_index = ensID; vlistptr->vars[varID].ensdata->ens_count = ensCount; vlistptr->vars[varID].ensdata->forecast_init_type = forecast_type; - - /* - int ens_index; - int ens_count; - int forecast_init_type; - */ - -#ifdef DBG - if( DBG ) - { - fprintf( stderr, "vlistDefVarEnsemble Inputs: \n EnsID %d\n Enscount %d\n Forecast init type %d\n", ensID, - ensCount, forecast_type ); - - fprintf( stderr, "vlistDefVarEnsemble outputs: \n EnsID %d\n Enscount %d\n Forecast init type %d\n",vlistptr->vars[varID].ensdata->ens_index, - vlistptr->vars[varID].ensdata->ens_count, vlistptr->vars[varID].ensdata->forecast_init_type ); - } -#endif } int vlistInqVarEnsemble( int vlistID, int varID, int *ensID, int *ensCount, int *forecast_type ) { vlist_t *vlistptr; + int status = 0; vlistptr = vlist_to_pointer(vlistID); vlistCheckVarID(__func__, vlistID, varID); - if( vlistptr->vars[varID].ensdata ) + if ( vlistptr->vars[varID].ensdata ) { *ensID = vlistptr->vars[varID].ensdata->ens_index; *ensCount = vlistptr->vars[varID].ensdata->ens_count; *forecast_type = vlistptr->vars[varID].ensdata->forecast_init_type; + + status = 1; } + + return (status); +} + +/* ---------------------------------- */ +/* Local change: 2013-01-28, FP (DWD) */ +/* ---------------------------------- */ + +/* vlistDefVarIntKey: Set an arbitrary keyword/integer value pair for GRIB API */ +void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value) +{ + vlist_t *vlistptr; + vlistptr = vlist_to_pointer(vlistID); + + int idx = vlistptr->vars[varID].opt_grib_int_nentries; + vlistptr->vars[varID].opt_grib_int_nentries++; + if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/integer value pairs!"); + vlistptr->vars[varID].opt_grib_int_val[idx] = value; + if ( name ) + vlistptr->vars[varID].opt_grib_int_keyword[idx] = strdupx(name); else - return 1; + Error("Internal error!"); +} -#ifdef DBG - if( DBG ) - { - fprintf( stderr, "vlistInqVarEnsemble outputs: \n EnsID %d\n Enscount %d\n Forecast init type %d\n", *ensID, - *ensCount, *forecast_type ); +/* vlistDefVarDblKey: Set an arbitrary keyword/double value pair for GRIB API */ +void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value) +{ + vlist_t *vlistptr; + vlistptr = vlist_to_pointer(vlistID); - /* - fprintf( stderr, " EnsID %d\n Enscount %d\n Forecast init type %d\n",vlistptr->vars[varID].ensdata->ens_index, - vlistptr->vars[varID].ensdata->ens_count, vlistptr->vars[varID].ensdata->forecast_init_type ); - */ + int idx = vlistptr->vars[varID].opt_grib_dbl_nentries; + vlistptr->vars[varID].opt_grib_dbl_nentries++; + if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/double value pairs!"); + vlistptr->vars[varID].opt_grib_dbl_val[idx] = value; + if ( name ) + vlistptr->vars[varID].opt_grib_dbl_keyword[idx] = strdupx(name); + else + Error("Internal error!"); +} - } +#if defined (HAVE_LIBGRIB_API) +# include "file.h" +# include "grib_api.h" #endif - return 0; +/* vlistInqVarRawBegin: Open GRIB record to retrieve raw meta-data in subsequent calls */ +void vlistInqVarRawBegin(int streamID, int varID) +{ +#if defined (HAVE_LIBGRIB_API) + stream_t *streamptr; + int recID, tsID, fileID; + long recpos, recsize; + + streamptr = stream_to_pointer(streamID); + stream_check_ptr(__func__, streamptr); + + fileID = streamInqFileID(streamID); + tsID = streamptr->curTsID; + + // determine record ID for varID in current time step + for (recID=0; (recID<streamptr->tsteps[0].nrecs) && (varID != streamptr->tsteps[tsID].records[recID].varID); recID++); + recpos = streamptr->tsteps[tsID].records[recID].position; + recsize = streamptr->tsteps[tsID].records[recID].size; + + fileSetPos(fileID, recpos, SEEK_SET); + fileRead(fileID, streamptr->record->buffer, (size_t) recsize); + + streamptr->gh = (void *) grib_handle_new_from_message(NULL, (void *) streamptr->record->buffer, recsize); +#endif +} + + +/* vlistInqVarDblKey: raw access to GRIB meta-data */ +double vlistInqVarDblKey(int streamID, const char* name) +{ + double value = 0; +#if defined (HAVE_LIBGRIB_API) + stream_t *streamptr = stream_to_pointer(streamID); + stream_check_ptr(__func__, streamptr); + GRIB_CHECK(grib_get_double((grib_handle*) streamptr->gh, name, &value), 0); +#endif + return value; +} + + +/* vlistInqVarIntKey: raw access to GRIB meta-data */ +int vlistInqVarIntKey(int streamID, const char* name) +{ + long int value = 0; +#if defined (HAVE_LIBGRIB_API) + stream_t *streamptr = stream_to_pointer(streamID); + stream_check_ptr(__func__, streamptr); + GRIB_CHECK(grib_get_long((grib_handle*) streamptr->gh, name, &value), 0); +#endif + return (int) value; +} + + +/* vlistInqVarRawEnd: Free previously opened GRIB record */ +void vlistInqVarRawEnd(int streamID) +{ +#if defined (HAVE_LIBGRIB_API) + stream_t *streamptr = stream_to_pointer(streamID); + stream_check_ptr(__func__, streamptr); + grib_handle_delete((grib_handle*) streamptr->gh); +#endif } @@ -1833,24 +1946,25 @@ void vlistDefVarDeco ( int vlistID, int varID, int decoSize, deco_t * deco ) int vlistInqVarDecoChunk ( int vlistID, int varID, int rankModel ) { + vlist_t *vlistptr; int iret = CDI_UNDEFID; + vlistptr = vlist_to_pointer(vlistID); + vlistCheckVarID(__func__, vlistID, varID); #ifdef USE_MPI { deco_t * deco; int i, decoSize = 0; - vlist_t *vlistptr = vlist_to_pointer(vlistID); - xassert ( vlistptr->vars[varID].deco != NULL && - vlistptr->vars[varID].decoSize != CDI_UNDEFID ); - + vlistptr->vars[varID].decoSize != CDI_UNDEFID ); + deco = vlistptr->vars[varID].deco; decoSize = vlistptr->vars[varID].decoSize; if ( decoSize && deco ) for ( i = 0; i < decoSize; i++ ) - if ( deco[i].rank == rankModel ) + if ( deco[i].rank == rankModel ) { iret = deco[i].chunk; break; @@ -1864,7 +1978,6 @@ int vlistInqVarDecoChunk ( int vlistID, int varID, int rankModel ) return iret; } - int vlistInqVarDecoOff ( int vlistID, int varID, int rankModel ) { int iret = CDI_UNDEFID; diff --git a/src/vlist_var.h b/src/vlist_var.h index adab671b7..c152e0d8e 100644 --- a/src/vlist_var.h +++ b/src/vlist_var.h @@ -9,7 +9,9 @@ #include <mpi.h> #endif +#ifndef _VLIST_H #include "vlist.h" +#endif int vlistInqVarDecoChunk ( int, int, int ); int vlistInqVarDecoOff ( int, int, int ); diff --git a/src/zaxis.c b/src/zaxis.c index e5e7b4244..cc9ac8647 100644 --- a/src/zaxis.c +++ b/src/zaxis.c @@ -44,7 +44,10 @@ ZaxistypeEntry[] = { { /* 13 */ 0, "toa", "top_of_atmosphere", "", ""}, { /* 14 */ 0, "seabottom", "sea_bottom", "", ""}, { /* 15 */ 0, "atmosphere", "atmosphere", "", ""}, - { /* 16 */ 0, "height", "generalized height","height", "m"}, + { /* 16 */ 0, "cloudbase", "cloud_base", "", ""}, + { /* 17 */ 0, "cloudtop", "cloud_top", "", ""}, + { /* 18 */ 0, "isotherm0", "isotherm_zero", "", ""}, + { /* 19 */ 0, "height", "generalized height","height", "m"}, }; static int CDI_MaxZaxistype = sizeof(ZaxistypeEntry) / sizeof(ZaxistypeEntry[0]); @@ -131,7 +134,7 @@ zaxis_t *zaxisNewEntry(void) } static -void zaxisInit (void) +void zaxisInit(void) { static int zaxisInitialized = 0; char *env; @@ -178,6 +181,9 @@ int zaxisSize(void) @Item zaxistype The type of the Z-axis, one of the set of predefined CDI Z-axis types. The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE}, @func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT}, + @func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA}, + @func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE}, + @func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}. @Item size Number of levels. @@ -246,7 +252,7 @@ int zaxisCreate(int zaxistype, int size) } -void zaxisDestroyKernel ( zaxis_t * zaxisptr ) +void zaxisDestroyKernel( zaxis_t * zaxisptr ) { int id; @@ -987,6 +993,9 @@ The function @func{zaxisInqType} returns the type of a Z-axis. one of the set of predefined CDI Z-axis types. The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE}, @func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT}, +@func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA}, +@func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE}, +@func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}. @EndFunction @@ -1476,7 +1485,7 @@ int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 ) if ( !z2->vals ) return differ; for ( i = 0; i < z1->size; i++ ) - if ( z1->vals[i] != z2->vals[i] ) return differ; + if ( IS_NOT_EQUAL(z1->vals[i], z2->vals[i]) ) return differ; } else if ( z2->vals ) return differ; @@ -1488,7 +1497,7 @@ int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 ) if ( !z2->lbounds ) return differ; for ( i = 0; i < z1->size; i++ ) - if ( z1->lbounds[i] != z2->lbounds[i] ) return differ; + if ( IS_NOT_EQUAL(z1->lbounds[i], z2->lbounds[i]) ) return differ; } else if ( z2->lbounds ) return differ; @@ -1500,7 +1509,7 @@ int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 ) if ( !z2->ubounds ) return differ; for ( i = 0; i < z1->size; i++ ) - if ( z1->ubounds[i] != z2->ubounds[i] ) return differ; + if ( IS_NOT_EQUAL(z1->ubounds[i], z2->ubounds[i]) ) return differ; } else if ( z2->ubounds ) return differ; @@ -1512,7 +1521,7 @@ int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 ) if ( !z2->weights ) return differ; for ( i = 0; i < z1->size; i++ ) - if ( z1->weights[i] != z2->weights[i] ) return differ; + if ( IS_NOT_EQUAL(z1->weights[i], z2->weights[i]) ) return differ; } else if ( z2->weights ) return differ; @@ -1524,7 +1533,7 @@ int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 ) if ( !z2->vct ) return differ; for ( i = 0; i < z1->vctsize; i++ ) - if ( z1->vct[i] != z2->vct[i] ) return differ; + if ( IS_NOT_EQUAL(z1->vct[i], z2->vct[i]) ) return differ; } else if ( z2->vct ) return differ; diff --git a/src/zaxis.h b/src/zaxis.h new file mode 100644 index 000000000..366c7b153 --- /dev/null +++ b/src/zaxis.h @@ -0,0 +1,6 @@ +#ifndef _ZAXIS_H +#define _ZAXIS_H + +int zaxisSize(void); + +#endif diff --git a/tables/echam6 b/tables/echam6 index facb09608..ea752d81d 100644 --- a/tables/echam6 +++ b/tables/echam6 @@ -18,182 +18,181 @@ # title = long name (description) # units = variable units # -#----+-------------+------------------------------------------+----------+ -# id | name | title | units | -#----+-------------+------------------------------------------+----------+ - 4 | precip | total precipitation | kg/m^2s | - 34 | low_cld | low cloud | | - 35 | mid_cld | mid cloud | | - 36 | hih_cld | high cloud | | - 68 | fage | aging factor of snow on ice | | - 69 | snifrac | fraction of ice covered with snow | | - 70 | barefrac | bare ice fraction | | - 71 | alsom | albedo of melt ponds | | - 72 | alsobs | albedo of bare ice and snow | | - 73 | sicepdw | melt pond depth on sea-ice | m | - 74 | sicepdi | ice thickness on melt pond | m | - 75 | tsicepdi | ice temperature on frozen melt pond | K | - 76 | sicepres | residual heat flux | W/m**2 | - 77 | ameltdepth | total melt pond depth | m | - 78 | ameltfrac | fractional area of melt ponds on sea-ice | | - 79 | albedo_vis_dir | surface albedo visible range direct | | - 80 | albedo_nir_dir | surface albedo NIR range direct | | - 81 | albedo_vis_dif | surface albedo visible range diffuse | | - 82 | albedo_nir_dif | surface albedo NIR range diffuse | | - 83 | ocu |ocean eastw. velocity (coupled mode) | m/s | - 84 | ocv |ocean northw. velocity (coupled mode) | m/s | - 85 | tradl |thermal radiation 200mb | W/m**2 | - 86 | sradl |solar radiation 200mb | W/m**2 | - 87 | trafl |thermal radiation 200mb (clear sky) | W/m**2 | - 88 | srafl |solar radiation 200mb (clear sky) | W/m**2 | - 89 | amlcorac |mixed layer flux correction | W/m**2 | - 90 | amlheatac |mixed layer heat content | J/m**2 | - 91 | trfliac | LW flux over ice | W/m^2 | - 92 | trflwac | LW flux over water | W/m^2 | - 93 | trfllac | LW flux over land | W/m^2 | - 94 | sofliac | SW flux over ice | W/m^2 | - 95 | soflwac | SW flux over water | W/m^2 | - 96 | sofllac | SW flux over land | W/m^2 | - 97 | friac | ice cover (fraction of grid box) | | - 102 | tsi | surface temperature of ice | K | - 103 | tsw | surface temperature of water | K | - 104 | ustri | zonal wind stress over ice | Pa | - 105 | vstri | meridional wind stress over ice | Pa | - 106 | ustrw | zonal wind stress over water | Pa | - 107 | vstrw | meridional wind stress over water | Pa | - 108 | ustrl | zonal wind stress over land | Pa | - 109 | vstrl | meridional wind stress over land | Pa | - 110 | ahfliac | latent heat flux over ice | W/m^2 | - 111 | ahflwac | latent heat flux over water | W/m^2 | - 112 | ahfllac | latent heat flux over land | W/m^2 | - 113 | evapiac | evaporation over ice | kg/m^2s | - 114 | evapwac | evaporation over water | kg/m^2s | - 115 | evaplac | evaporation over land | kg/m^2s | - 116 | az0i | roughness length over ice | m | - 117 | az0w | roughness length over water | m | - 118 | az0l | roughness length over land | m | - 119 | ahfsiac | sensible heat flux over ice | W/m^2 | - 120 | ahfswac | sensible heat flux over water | W/m^2 | - 121 | ahfslac | sensible heat flux over land | W/m^2 | - 122 | alsoi | albedo of ice | | - 123 | alsow | albedo of water | | - 124 | alsol | albedo of land | | - 125 | ahfice | conductive heat flux | W/m^2 | - 126 | qres | residual heat flux for melting sea ice | W/m^2 | - 127 | alake | lake fraction of grid box | fraction | - 128 | rintop | low level inversion - 129 | geosp | surface geopotential (orography) | m^2/s^2 | - 130 | t | temperature | K | - 131 | u | u-velocity | m/s | - 132 | v | v-velocity | m/s | - 133 | q | specific humidity | kg/kg | - 134 | aps | surface pressure | Pa | - 135 | omega | vertical velocity | Pa/s | - 136 | acdnc | cloud droplet number concentration | 1/m^3 | - 137 | apmeb | vert. integr. tendencies of water | kg/m^2s | - 138 | svo | vorticity | 1/s | - 139 | tslm1 | surface temperature of land | K | - 140 | ws | soil wetness | m | - 141 | sn | snow depth | m | - 142 | aprl | large scale precipitation | kg/m^2s | - 143 | aprc | convective precipitation | kg/m^2s | - 144 | aprs | snow fall | kg/m^2s | - 145 | vdis | boundary layer dissipation | W/m^2 | - 146 | ahfs | sensible heat flux | W/m^2 | - 147 | ahfl | latent heat flux | W/m^2 | - 148 | stream | streamfunction | m^2/s | - 149 | velopot | velocity potential | m^2/s | - 150 | xivi | vertically integrated cloud ice | kg/m^2 | - 151 | slp | mean sea level pressure | Pa | - 152 | stp(20) | log surface pressure | | - 153 | xl | cloud water | kg/kg | - 154 | xi | cloud ice | kg/kg | - 155 | sd | divergence | 1/s | - 156 | geopoth | geopotential height | m | - 157 | rhumidity | relative humidity | fraction | - 158 | | tendency of surface pressure | Pa/s | - 159 | wind10w | 10m windspeed over water | m/s | - 160 | runoff | surface runoff and drainage | kg/m^2s | - 161 | drain | drainage | kg/m^2s | - 162 | aclc | cloud cover | | - 163 | aclcv | total cloud cover | | - 164 | aclcov | total cloud cover (mean) | | - 165 | u10 | 10m u-velocity | m/s | - 166 | v10 | 10m v-velocity | m/s | - 167 | temp2 | 2m temperature | K | - 168 | dew2 | 2m dew point temperature | K | - 169 | tsurf | surface temperature | K | - 170 | xvar | variance of total water amount qv+qi+ql | kg/kg | - 171 | wind10 | 10m windspeed | m/s | - 172 | slm | land sea mask (1. = land, 0. = sea/lakes)| | - 173 | az0 | roughness length | m | - 174 | alb | surface background albedo | | - 175 | albedo | surface albedo | | - 176 | srads | net surface solar radiation | W/m^2 | - 177 | trads | net surface thermal radiation | W/m^2 | - 178 | srad0 | net top solar radiation | W/m^2 | - 179 | trad0 | top thermal radiation (OLR) | W/m^2 | - 180 | ustr | u-stress | Pa | - 181 | vstr | v-stress | Pa | - 182 | evap | evaporation | kg/m^2s | - 183 | xskew | skewness of total water amount qv+qi+ql | | - 184 | srad0d | top incoming solar radiation | W/m^2 | - 185 | srafs | net surf. solar radiation (clear sky) | W/m^2 | - 186 | trafs | net surf. thermal radiation (clear sky) | W/m^2 | - 187 | sraf0 | net top solar radiation (clear sky) | W/m^2 | - 188 | traf0 | net top thermal radiation (clear sky) | W/m^2 | - 189 | sclfs | surface solar cloud forcing | W/m^2 | - 190 | tclfs | surface thermal cloud forcing | W/m^2 | - 191 | sclf0 | SW top cloud forcing (178-187) | W/m^2 | - 192 | tclf0 | LW top cloud forcing (179-188) | W/m^2 | - 193 | wl | skin reservoir content | m | +#----+-------------+------------------------------------------+------------ +# id | name | title | units +#----+-------------+------------------------------------------+------------ + 4 | precip | total precipitation | kg m-2 s-1 + 34 | low_cld | low cloud | + 35 | mid_cld | mid cloud | + 36 | hih_cld | high cloud | + 68 | fage | aging factor of snow on ice | + 69 | snifrac | fraction of ice covered with snow | + 70 | barefrac | bare ice fraction | + 71 | alsom | albedo of melt ponds | + 72 | alsobs | albedo of bare ice and snow | + 73 | sicepdw | melt pond depth on sea-ice | m + 74 | sicepdi | ice thickness on melt pond | m + 75 | tsicepdi | ice temperature on frozen melt pond | K + 76 | sicepres | residual heat flux | W m-2 + 77 | ameltdepth | total melt pond depth | m + 78 | ameltfrac | fractional area of melt ponds on sea-ice | + 79 | albedo_vis_dir | surface albedo visible range direct | + 80 | albedo_nir_dir | surface albedo NIR range direct | + 81 | albedo_vis_dif | surface albedo visible range diffuse | + 82 | albedo_nir_dif | surface albedo NIR range diffuse | + 83 | ocu |ocean eastw. velocity (coupled mode) | m/s + 84 | ocv |ocean northw. velocity (coupled mode) | m/s + 85 | tradl |thermal radiation 200mb | W m-2 + 86 | sradl |solar radiation 200mb | W m-2 + 87 | trafl |thermal radiation 200mb (clear sky) | W m-2 + 88 | srafl |solar radiation 200mb (clear sky) | W m-2 + 89 | amlcorac |mixed layer flux correction | W m-2 + 90 | amlheatac |mixed layer heat content | J m-2 + 91 | trfliac | LW flux over ice | W m-2 + 92 | trflwac | LW flux over water | W m-2 + 93 | trfllac | LW flux over land | W m-2 + 94 | sofliac | SW flux over ice | W m-2 + 95 | soflwac | SW flux over water | W m-2 + 96 | sofllac | SW flux over land | W m-2 + 97 | friac | ice cover (fraction of grid box) | + 102 | tsi | surface temperature of ice | K + 103 | tsw | surface temperature of water | K + 104 | ustri | zonal wind stress over ice | Pa + 105 | vstri | meridional wind stress over ice | Pa + 106 | ustrw | zonal wind stress over water | Pa + 107 | vstrw | meridional wind stress over water | Pa + 108 | ustrl | zonal wind stress over land | Pa + 109 | vstrl | meridional wind stress over land | Pa + 110 | ahfliac | latent heat flux over ice | W m-2 + 111 | ahflwac | latent heat flux over water | W m-2 + 112 | ahfllac | latent heat flux over land | W m-2 + 113 | evapiac | evaporation over ice | kg m-2 s-1 + 114 | evapwac | evaporation over water | kg m-2 s-1 + 115 | evaplac | evaporation over land | kg m-2 s-1 + 116 | az0i | roughness length over ice | m + 117 | az0w | roughness length over water | m + 118 | az0l | roughness length over land | m + 119 | ahfsiac | sensible heat flux over ice | W m-2 + 120 | ahfswac | sensible heat flux over water | W m-2 + 121 | ahfslac | sensible heat flux over land | W m-2 + 122 | alsoi | albedo of ice | + 123 | alsow | albedo of water | + 124 | alsol | albedo of land | + 125 | ahfice | conductive heat flux | W m-2 + 126 | qres | residual heat flux for melting sea ice | W m-2 + 127 | alake | lake fraction of grid box | fraction + 128 | rintop | low level inversion | + 129 | geosp | surface geopotential (orography) | m^2/s^2 + 130 | t | temperature | K + 131 | u | u-velocity | m/s + 132 | v | v-velocity | m/s + 133 | q | specific humidity | kg/kg + 134 | aps | surface pressure | Pa + 135 | omega | vertical velocity | Pa/s + 136 | acdnc | cloud droplet number concentration | 1 m-3 + 137 | apmeb | vert. integr. tendencies of water | kg m-2 s-1 + 138 | svo | vorticity | 1/s + 139 | tslm1 | surface temperature of land | K + 140 | ws | soil wetness | m + 141 | sn | snow depth | m + 142 | aprl | large scale precipitation | kg m-2 s-1 + 143 | aprc | convective precipitation | kg m-2 s-1 + 144 | aprs | snow fall | kg m-2 s-1 + 145 | vdis | boundary layer dissipation | W m-2 + 146 | ahfs | sensible heat flux | W m-2 + 147 | ahfl | latent heat flux | W m-2 + 148 | stream | streamfunction | m^2/s + 149 | velopot | velocity potential | m^2/s + 150 | xivi | vertically integrated cloud ice | kg m-2 + 151 | slp | mean sea level pressure | Pa + 152 | lsp | log surface pressure | + 153 | xl | cloud water | kg/kg + 154 | xi | cloud ice | kg/kg + 155 | sd | divergence | 1/s + 156 | geopoth | geopotential height | m + 157 | rhumidity | relative humidity | fraction + 158 | | tendency of surface pressure | Pa/s + 159 | wind10w | 10m windspeed over water | m/s + 160 | runoff | surface runoff and drainage | kg m-2 s-1 + 161 | drain | drainage | kg m-2 s-1 + 162 | aclc | cloud cover | + 163 | aclcv | total cloud cover | + 164 | aclcov | total cloud cover (mean) | + 165 | u10 | 10m u-velocity | m/s + 166 | v10 | 10m v-velocity | m/s + 167 | temp2 | 2m temperature | K + 168 | dew2 | 2m dew point temperature | K + 169 | tsurf | surface temperature | K + 170 | xvar | variance of total water amount qv+qi+ql | kg/kg + 171 | wind10 | 10m windspeed | m/s + 172 | slm | land sea mask (1. = land, 0. = sea/lakes)| + 173 | az0 | roughness length | m + 174 | alb | surface background albedo | + 175 | albedo | surface albedo | + 176 | srads | net surface solar radiation | W m-2 + 177 | trads | net surface thermal radiation | W m-2 + 178 | srad0 | net top solar radiation | W m-2 + 179 | trad0 | top thermal radiation (OLR) | W m-2 + 180 | ustr | u-stress | Pa + 181 | vstr | v-stress | Pa + 182 | evap | evaporation | kg m-2 s-1 + 183 | xskew | skewness of total water amount qv+qi+ql | + 184 | srad0d | top incoming solar radiation | W m-2 + 185 | srafs | net surf. solar radiation (clear sky) | W m-2 + 186 | trafs | net surf. thermal radiation (clear sky) | W m-2 + 187 | sraf0 | net top solar radiation (clear sky) | W m-2 + 188 | traf0 | net top thermal radiation (clear sky) | W m-2 + 189 | sclfs | surface solar cloud forcing | W m-2 + 190 | tclfs | surface thermal cloud forcing | W m-2 + 191 | sclf0 | SW top cloud forcing (178-187) | W m-2 + 192 | tclf0 | LW top cloud forcing (179-188) | W m-2 + 193 | wl | skin reservoir content | m 194 | slf | sea land fraction - 195 | ustrgw | u-gravity wave stress | Pa | - 196 | vstrgw | v-gravity wave stress | Pa | - 197 | vdisgw | gravity wave dissipation | W/m^2 | - 198 | vgrat | vegetation ratio | | - 199 | orostd | orographic standard deviation | m | - 200 | vlt | leaf area index | | - 201 | t2max | maximum 2m-temperature | K | - 202 | t2min | minimum 2m-temperature | K | - 203 | srad0u | top solar radiation upward | W/m^2 | - 204 | sradsu | surface solar radiation upward | W/m^2 | - 205 | tradsu | surface thermal radiation upward | W/m^2 | - 206 | grndflux | surface ground heat flux | | - 207 | tsoil | deep soil temperatures (5 layers) | K | - 208 | ahfcon | conductive heat flux through ice | W/m^2 | - 209 | ahfres | melting of ice | W/m^2 | - 210 | seaice | ice cover (fraction of 1-SLM) | | - 211 | siced | ice depth | m | - 212 | forest | forest fraction | | - 213 | gld | glacier depth | m | - 214 | sni | water equivalent of snow on ice | m | - 215 | rogl | glacier runoff | kg/m^2s | - 216 | wimax | maximum 10m-wind speed | m/s | - 217 | topmax | maximum height of convective cloud tops | Pa | - 218 | snmel | snow melt | kg/m^2s | - 219 | runtoc | surface runoff into ocean | kg/m^2s | - 220 | runlnd | surface runoff not running into ocean | kg/m^2s | - 221 | apmegl | P-E over land ice | kg/m^2s | - 222 | snacl | snow accumulation over land | kg/m^2s | - 223 | aclcac | cloud cover | | - 224 | tke | turbulent kinetic energy | m^2/s^2 | - 225 | tkem1 | turbulent kinetic energy (t-1) | m^2/s^2 | - 226 | fao | FAO data set (soil data flags) | 0...5 | - 227 | rgcgn | heat capacity of soil | | - 228 | sodif | diffusivity of soil and land ice | m^2/s | - 229 | wsmx | field capacity of soil | m | - 230 | qvi | vertically integrated water vapor | kg/m^2 | - 231 | xlvi | vertically integrated cloud water | kg/m^2 | - 232 | glac | fraction of land covered by glaciers | | - 233 | snc | snow depth at the canopy | m | - 234 | rtype | type of convection | 0...3 | - 235 | abso4 | antropogenic sulfur burden | kg/m**2 | - 236 | ao3 | ipcc ozone | kg/m**2 | - 237 | tropo | WMO defined tropopause height | Pa | - 259 | windspeed | windspeed (sqrt(u^2+v^2)) | m/s | - 260 | precip | total precipitation (142+143) | kg/m^2s | - 261 | net_top | total top radiation (178+179) | W/m^2 | - 262 | net_bot | total surface radiation (176+177) | W/m^2 | - 272 | mastfru | mass stream function | kg/s | - + 195 | ustrgw | u-gravity wave stress | Pa + 196 | vstrgw | v-gravity wave stress | Pa + 197 | vdisgw | gravity wave dissipation | W m-2 + 198 | vgrat | vegetation ratio | + 199 | orostd | orographic standard deviation | m + 200 | vlt | leaf area index | + 201 | t2max | maximum 2m-temperature | K + 202 | t2min | minimum 2m-temperature | K + 203 | srad0u | top solar radiation upward | W m-2 + 204 | sradsu | surface solar radiation upward | W m-2 + 205 | tradsu | surface thermal radiation upward | W m-2 + 206 | grndflux | surface ground heat flux | + 207 | tsoil | deep soil temperatures (5 layers) | K + 208 | ahfcon | conductive heat flux through ice | W m-2 + 209 | ahfres | melting of ice | W m-2 + 210 | seaice | ice cover (fraction of 1-SLM) | + 211 | siced | ice depth | m + 212 | forest | forest fraction | + 213 | gld | glacier depth | m + 214 | sni | water equivalent of snow on ice | m + 215 | rogl | glacier runoff | kg m-2 s-1 + 216 | wimax | maximum 10m-wind speed | m/s + 217 | topmax | maximum height of convective cloud tops | Pa + 218 | snmel | snow melt | kg m-2 s-1 + 219 | runtoc | surface runoff into ocean | kg m-2 s-1 + 220 | runlnd | surface runoff not running into ocean | kg m-2 s-1 + 221 | apmegl | P-E over land ice | kg m-2 s-1 + 222 | snacl | snow accumulation over land | kg m-2 s-1 + 223 | aclcac | cloud cover | + 224 | tke | turbulent kinetic energy | m^2/s^2 + 225 | tkem1 | turbulent kinetic energy (t-1) | m^2/s^2 + 226 | fao | FAO data set (soil data flags) | 0...5 + 227 | rgcgn | heat capacity of soil | + 228 | sodif | diffusivity of soil and land ice | m^2/s + 229 | wsmx | field capacity of soil | m + 230 | qvi | vertically integrated water vapor | kg m-2 + 231 | xlvi | vertically integrated cloud water | kg m-2 + 232 | glac | fraction of land covered by glaciers | + 233 | snc | snow depth at the canopy | m + 234 | rtype | type of convection | 0...3 + 235 | abso4 | antropogenic sulfur burden | kg m-2 + 236 | ao3 | ipcc ozone | kg m-2 + 237 | tropo | WMO defined tropopause height | Pa + 259 | windspeed | windspeed (sqrt(u^2+v^2)) | m/s + 260 | precip | total precipitation (142+143) | kg m-2 s-1 + 261 | net_top | total top radiation (178+179) | W m-2 + 262 | net_bot | total surface radiation (176+177) | W m-2 + 272 | mastfru | mass stream function | kg/s diff --git a/tables/echam6cmip5 b/tables/echam6cmip5 new file mode 100644 index 000000000..871b0a5a1 --- /dev/null +++ b/tables/echam6cmip5 @@ -0,0 +1,170 @@ +¶meter name=low_cld / +¶meter name=mid_cld / +¶meter name=hih_cld / +¶meter name=fage / +¶meter name=snifrac / +¶meter name=barefrac / +¶meter name=alsom / +¶meter name=alsobs / +¶meter name=sicepdw / +¶meter name=sicepdi / +¶meter name=tsicepdi / +¶meter name=sicepres / +¶meter name=ameltdepth / +¶meter name=ameltfrac / +¶meter name=albedo_vis_dir / +¶meter name=albedo_nir_dir / +¶meter name=albedo_vis_dif / +¶meter name=albedo_nir_dif / +¶meter name=ocu / +¶meter name=ocv / +¶meter name=tradl standard_name=net_upward_longwave_flux_in_air factor=-1 / +¶meter name=sradl standard_name=net_downward_shortwave_flux_in_air / +¶meter name=trafl standard_name=net_upward_longwave_flux_in_air_assuming_clear_sky factor=-1 / +¶meter name=srafl standard_name=net_downward_shortwave_flux_in_air_assuming_clear_sky / +¶meter name=amlcorac / +¶meter name=amlheatac / +¶meter name=trfliac / +¶meter name=trflwac / +¶meter name=trfllac / +¶meter name=sofliac / +¶meter name=soflwac / +¶meter name=sofllac / +¶meter name=friac / +¶meter name=tsi / +¶meter name=tsw standard_name=surface_temperature_where_open_sea / +¶meter name=ustri / +¶meter name=vstri / +¶meter name=ustrw / +¶meter name=vstrw / +¶meter name=ustrl / +¶meter name=vstrl / +¶meter name=ahfliac / +¶meter name=ahflwac / +¶meter name=ahfllac / +¶meter name=evapiac / +¶meter name=evapwac / +¶meter name=evaplac / +¶meter name=az0i / +¶meter name=az0w / +¶meter name=az0l / +¶meter name=ahfsiac / +¶meter name=ahfswac / +¶meter name=ahfslac / +¶meter name=alsoi / +¶meter name=alsow / +¶meter name=alsol standard_name=soil_albedo / +¶meter name=ahfice / +¶meter name=qres / +¶meter name=alake / +¶meter name=rintop / +¶meter name=geosp standard_name=surface_geopotential / +¶meter name=t out_name=ta standard_name=air_temperature / +¶meter name=u out_name=ua standard_name=eastward_wind / +¶meter name=v out_name=va standard_name=northward_wind / +¶meter name=q out_name=hus standard_name=specific_humidity / +¶meter name=aps out_name=ps standard_name=surface_air_pressure / +¶meter name=omega out_name=wap standard_name=lagrangian_tendency_of_air_pressure / +¶meter name=acdnc / +¶meter name=apmeb / +¶meter name=svo / +¶meter name=tslm1 out_name=tslsi standard_name=surface_temperature / +¶meter name=ws standard_name=soil_moisture_content / +¶meter name=sn standard_name=surface_snow_amount / +¶meter name=aprl standard_name=large_scale_rainfall_flux / +¶meter name=aprc out_name=prc standard_name=convective_precipitation_flux / +¶meter name=aprs out_name=prsn standard_name=snowfall_flux / +¶meter name=vdis / +¶meter name=ahfs out_name=hfss standard_name=surface_upward_sensible_heat_flux factor=-1 / +¶meter name=ahfl out_name=hfls standard_name=surface_upward_latent_heat_flux factor=-1 / +¶meter name=stream standard_name=atmosphere_horizontal_streamfunction / +¶meter name=velopot / +¶meter name=xivi out_name=clivi standard_name=atmosphere_cloud_ice_content / +¶meter name=slp out_name=psl standard_name=air_pressure_at_sea_level / +¶meter name=lsp / +¶meter name=xl / +¶meter name=xi / +¶meter name=sd standard_name=divergence_of_wind / +¶meter name=geopoth out_name=zg standard_name=geopotential_height / +¶meter name=rhumidity out_name=rhs standard_name=relative_humidity / +¶meter name=wind10w / +¶meter name=runoff standard_name=runoff_flux / +¶meter name=drain / +¶meter name=aclc / +¶meter name=aclcv / +¶meter name=aclcov standard_name=cloud_area_fraction / +¶meter name=u10 standard_name=eastward_wind / +¶meter name=v10 standard_name=northward_wind / +¶meter name=temp2 standard_name=air_temperature / +¶meter name=dew2 standard_name=dew_point_temperature / +¶meter name=tsurf out_name=ts standard_name=surface_temperature / +¶meter name=xvar / +¶meter name=wind10 standard_name=wind_speed / +¶meter name=slm / +¶meter name=az0 standard_name=surface_roughness_length / +¶meter name=alb / +¶meter name=albedo standard_name=surface_albedo / +¶meter name=srads standard_name=surface_net_downward_shortwave_flux / +¶meter name=trads standard_name=surface_net_downward_longwave_flux / +¶meter name=srad0 out_name=rsut standard_name=toa_outgoing_shortwave_flux factor=-1 / +¶meter name=trad0 out_name=rlut standard_name=toa_outgoing_longwave_flux factor=-1 / +¶meter name=ustr out_name=tauu standard_name=surface_downward_eastward_stress / +¶meter name=vstr out_name=tauv standard_name=surface_downward_northward_stress / +¶meter name=evap / +¶meter name=xskew / +¶meter name=srad0d out_name=rsdt standard_name=toa_incoming_shortwave_flux / +¶meter name=srafs / +¶meter name=trafs / +¶meter name=sraf0 out_name=rsutcs standard_name=toa_outgoing_shortwave_flux_assuming_clear_sky factor=-1 / +¶meter name=traf0 out_name=rlutcs standard_name=toa_outgoing_longwave_flux_assuming_clear_sky factor=-1 / +¶meter name=sclfs / +¶meter name=tclfs / +¶meter name=sclf0 / +¶meter name=tclf0 / +¶meter name=wl / +¶meter name=slf / +¶meter name=ustrgw standard_name=atmosphere_eastward_stress_due_to_gravity_wave_drag / +¶meter name=vstrgw standard_name=atmosphere_northward_stress_due_to_gravity_wave_drag / +¶meter name=vdisgw / +¶meter name=vgrat standard_name=vegetation_area_fraction / +¶meter name=orostd / +¶meter name=vlt standard_name=leaf_area_index / +¶meter name=t2max standard_name=air_temperature / +¶meter name=t2min standard_name=air_temperature / +¶meter name=srad0u standard_name=toa_outgoing_shortwave_flux factor=-1 / +¶meter name=sradsu out_name=rsus standard_name=surface_upwelling_shortwave_flux_in_air factor=-1 / +¶meter name=tradsu out_name=rlus standard_name=surface_upwelling_longwave_flux_in_air factor=-1 / +¶meter name=grndflux / +¶meter name=tsoil standard_name=soil_temperature / +¶meter name=ahfcon / +¶meter name=ahfres / +¶meter name=seaice / +¶meter name=siced / +¶meter name=forest / +¶meter name=gld / +¶meter name=sni / +¶meter name=rogl / +¶meter name=wimax / +¶meter name=topmax / +¶meter name=snmel standard_name=surface_snow_melt_flux / +¶meter name=runtoc / +¶meter name=runlnd / +¶meter name=apmegl / +¶meter name=snacl / +¶meter name=aclcac out_name=cl standard_name=cloud_area_fraction_in_atmosphere_layer / +¶meter name=tke / +¶meter name=tkem1 / +¶meter name=fao standard_name=soil_type / +¶meter name=rgcgn / +¶meter name=sodif / +¶meter name=wsmx standard_name=soil_moisture_content_at_field_capacity / +¶meter name=qvi out_name=prw standard_name=atmosphere_water_vapor_content / +¶meter name=xlvi out_name=clwvi standard_name=atmosphere_cloud_condensed_water_content / +¶meter name=glac standard_name=land_ice_area_fraction / +¶meter name=snc / +¶meter name=rtype / +¶meter name=abso4 / +¶meter name=ao3 / +¶meter name=tropo / +¶meter name=windspeed out_name=sfcWind standard_name=wind_speed / +¶meter name=precip out_name=pr standard_name=precipitation_flux / diff --git a/tests/Makefile.am b/tests/Makefile.am index 45f88c36d..c71fb38b0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,4 +21,4 @@ INCLUDES = -I$(top_srcdir)/src # EXTRA_DIST = $(TESTS) # -CLEANFILES = `ls *~ *.grb *.nc *.srv *.ext` +CLEANFILES = `ls *~ *.grb *.nc *.srv *.ext example_*.cksum` diff --git a/tests/Makefile.in b/tests/Makefile.in index 566536c18..f2cba72f1 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -338,7 +338,7 @@ INCLUDES = -I$(top_srcdir)/src # EXTRA_DIST = $(TESTS) # -CLEANFILES = `ls *~ *.grb *.nc *.srv *.ext` +CLEANFILES = `ls *~ *.grb *.nc *.srv *.ext example_*.cksum` all: all-am .SUFFIXES: diff --git a/write_tornado.job b/write_tornado.job deleted file mode 100755 index 3442e5262..000000000 --- a/write_tornado.job +++ /dev/null @@ -1,35 +0,0 @@ - #! /bin/bash -# -#----------------------------------------------------------------------------- -#$ -S /bin/bash -#$ -N write -#$ -o write.$JOB_ID.o -#$ -j y -#$ -pe orte8 16 -#$ -q cluster -#$ -cwd -#----------------------------------------------------------------------------- -# - -IOMODE=3 -NPROCSIO=8 -NPROCSMODEL=8 -(( SIZEGLOB = NPROCSIO + NPROCSMODEL )) - -EXPUSER=m300050 -EXPGROUP=mh0033 -EXPDIR=/scratch/work/$EXPGROUP/$EXPUSER/cdi-exp -WORKDIR=/scratch/work/$EXPGROUP/$EXPUSER/cdi-build/cdi-parallel - -# the directory for the experiment will be created, if not already there -if [ ! -d $EXPDIR ]; then - mkdir -p $EXPDIR -fi - -cd $EXPDIR - -MPIBIN=/sw/sles10-x64/mpi/openmpi-1.4.3-static-nag52/bin - -$MPIBIN/mpiexec -n $SIZEGLOB $WORKDIR/pioExamples/collectDataNStreams $IOMODE $NPROCSIO - -exit -- GitLab