Commit aad1f826 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

grbWriteVar: bug fix

parent 0a0b7d9e
......@@ -73,6 +73,7 @@ examples/Makefile.am -text
examples/Makefile.in -text
examples/cdi_copy.c -text
examples/cdi_copy_f.f -text
examples/cdi_copy_file.c -text
examples/cdi_read.c -text
examples/cdi_read_example.f90 -text
examples/cdi_read_f.f -text
......
2009-10-28 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* grbWriteVar: bug fix
* Version 1.4.0.2 released
2009-10-23 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* stream_cdf:cdfDefXaxis: bug fix for multi generic grids [report: Uwe Mikolajewicz]
......
#include <stdio.h>
#include <stdlib.h>
#include "cdi.h"
/* gcc -g -O2 -o cdi_copy_file cdi_copy_file.c -I../src ../src/libcdi.a -lm */
#define MAX_LEVEL 200
int main(int argc, char *argv[])
{
int linfo = 0;
int vlistID1, vlistID2, varID, streamID1, streamID2, tsID;
int nmiss, nvars, status, gridsize;
double *vardata = NULL;
const char *ifile, *ofile;
if ( argc == 1 )
{
fprintf(stderr, "usage: %s ifile ofile\n", argv[0]);
return (-1);
}
ifile = argv[1];
ofile = argv[2];
/* Open the input dataset */
streamID1 = streamOpenRead(ifile);
if ( streamID1 < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID1));
return(1);
}
/* Get the variable list of the dataset */
vlistID1 = streamInqVlist(streamID1);
nvars = vlistNvars(vlistID1);
gridsize = vlistGridsizeMax(vlistID1);
vardata = (double *) malloc(gridsize*MAX_LEVEL*sizeof(double));
/* Open the output dataset (GRIB fromat) */
streamID2 = streamOpenWrite(ofile, FILETYPE_GRB);
if ( streamID2 < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID2));
return(1);
}
vlistID2 = vlistDuplicate(vlistID1);
streamDefVlist(streamID2, vlistID2);
/* Loop over all time steps */
tsID = 0;
while ( (status = streamInqTimestep(streamID1, tsID)) )
{
/* Define the output time step */
streamDefTimestep(streamID2, tsID);
for ( varID = 0; varID < nvars; ++varID )
{
/* Read variable */
streamReadVar(streamID1, varID, vardata, &nmiss);
if ( linfo )
{
int i, k, nlevel;
nlevel = zaxisInqSize(vlistInqVarZaxis(vlistID1, varID));
gridsize = gridInqSize(vlistInqVarGrid(vlistID1, varID));
for ( k = 0; k < nlevel; ++k )
{
double fmin = 1.e30, fmax = -1.e30, fmean = 0;
for ( i = 0; i < gridsize; ++i )
{
if ( vardata[k*gridsize+i] < fmin ) fmin = vardata[k*gridsize+i];
if ( vardata[k*gridsize+i] > fmax ) fmax = vardata[k*gridsize+i];
fmean += vardata[k*gridsize+i];
}
printf("%3d %3d %3d %9g %9g %9g\n",
tsID, varID, k, fmin, fmean/gridsize, fmax);
}
}
/* Write variable */
streamWriteVar(streamID2, varID, vardata, nmiss);
}
tsID++;
}
/* Close the streams */
streamClose(streamID1);
streamClose(streamID2);
free(vardata);
return 0;
}
! This file was automatically created, don't edit!
!
! Fortran interface for CDI library version 1.3.2
! Fortran interface for CDI library version 1.4.1
!
! Author:
! -------
! Uwe Schulzweida, MPI-MET, Hamburg, September 2009
! Uwe Schulzweida, MPI-MET, Hamburg, October 2009
!
INTEGER CDI_UNDEFID
......
......@@ -479,15 +479,18 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
void grbWriteVarDP(int streamID, int varID, const double *data, int nmiss)
{
int vlistID, zaxisID, levelID, nlevs;
int vlistID, gridID, zaxisID, levelID, nlevs;
int gridsize;
vlistID = streamInqVlist(streamID);
zaxisID = vlistInqVarZaxis(vlistID, varID);
nlevs = zaxisInqSize(zaxisID);
vlistID = streamInqVlist(streamID);
gridID = vlistInqVarGrid(vlistID, varID);
gridsize = gridInqSize(gridID);
zaxisID = vlistInqVarZaxis(vlistID, varID);
nlevs = zaxisInqSize(zaxisID);
for ( levelID = 0; levelID < nlevs; levelID++ )
{
grbWriteVarSliceDP(streamID, varID, levelID, data, nmiss);
grbWriteVarSliceDP(streamID, varID, levelID, data+levelID*gridsize, nmiss);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment