Commit a53191d7 authored by Deike Kleberg's avatar Deike Kleberg
Browse files

Bug fixed in varscan.c, catch empty arrays.

parent d999798b
#include <stdio.h>
#include "cdi.h"
extern void reshArrayPrint ( char * filename );
int nlon = 12; // Number of longitudes
int nlat = 6; // Number of latitudes
int nlev = 5; // Number of levels
......@@ -15,7 +17,7 @@ int main(void)
// Open the dataset
streamID = streamOpenRead("example.nc");
streamID = streamOpenRead("example.grb");
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
......@@ -47,6 +49,8 @@ int main(void)
streamReadVar(streamID, varID2, var2, &nmiss);
}
reshArrayPrint ( "reshArrayRead" );
// Close the input stream
streamClose(streamID);
......
......@@ -658,19 +658,22 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
if ( ! griddefined )
{
ngrids = gridSize();
gridIndexArray = malloc ( ngrids * sizeof ( int ));
gridGetIndexArray ( ngrids, gridIndexArray );
for ( i = 0; i < ngrids; i++ )
{
gridID = gridIndexArray[i];
if ( gridCompare(gridID, grid) == 0 )
{
gridglobdefined = TRUE;
break;
}
}
if ( gridIndexArray ) free ( gridIndexArray );
if ( ngrids > 0 )
{
gridIndexArray = malloc ( ngrids * sizeof ( int ));
gridGetIndexArray ( ngrids, gridIndexArray );
for ( i = 0; i < ngrids; i++ )
{
gridID = gridIndexArray[i];
if ( gridCompare(gridID, grid) == 0 )
{
gridglobdefined = TRUE;
break;
}
}
if ( gridIndexArray ) free ( gridIndexArray );
}
ngrids = vlistptr->ngrids;
if ( mode == 1 )
for ( index = 0; index < ngrids; index++ )
......@@ -776,18 +779,21 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
if ( ! zaxisdefined )
{
nzaxis = zaxisSize();
zaxisIndexArray = malloc ( nzaxis * sizeof ( int ));
zaxisGetIndexArray ( nzaxis, zaxisIndexArray );
for ( i = 0; i < nzaxis; i++ )
{
zaxisID = zaxisIndexArray[i];
if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, longname, units, ltype) == 0 )
{
zaxisglobdefined = 1;
break;
}
}
if ( zaxisIndexArray ) free ( zaxisIndexArray );
if ( nzaxis > 0 )
{
zaxisIndexArray = malloc ( nzaxis * sizeof ( int ));
zaxisGetIndexArray ( nzaxis, zaxisIndexArray );
for ( i = 0; i < nzaxis; i++ )
{
zaxisID = zaxisIndexArray[i];
if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, longname, units, ltype) == 0 )
{
zaxisglobdefined = 1;
break;
}
}
if ( zaxisIndexArray ) free ( zaxisIndexArray );
}
nzaxis = vlistptr->nzaxis;
if ( mode == 1 )
......
Supports Markdown
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