/**************************************************************************** * * allocdata * * Allocates necessary space for the passed structures to hold one scanline * of data. * * ARGUMENTS: * Name Type Description * ---- ---- ----------- * *data struct std_data Pointer to std_data structure to hold data * pixels short Pixels per scanline for these data * fields short Fields per pixel for these data * * RETURNS: * 0 if successful * -1 if suspect arguments passed * -2 if unable to allocate space * *****************************************************************************/ #include #include #include "common_structures" int allocdata ( struct std_data *data, short pixels, short fields ) { int error_flag = 0 ; int i ; /** Check for valid arguments **/ if ( ( pixels < 0 ) || ( pixels > 100000 ) || ( fields < 0 ) || ( fields > 100000 ) ) { error_flag = -1 ; goto bailout ; } /** Allocate space for time, lat and lon fields **/ data->itime = ( long * ) malloc ( pixels * sizeof ( long ) ) ; data->lat = ( float * ) malloc ( pixels * sizeof ( float ) ) ; data->lng = ( float * ) malloc ( pixels * sizeof ( float ) ) ; if ( data->itime == NULL || data->lat == NULL || data->lng == NULL ) { error_flag = -2 ; goto bailout ; } /** Allocate pointers to data fields **/ data->fielddata = ( float ** ) malloc ( fields * sizeof ( float * ) ) ; if ( data->fielddata == NULL ) { error_flag = -2 ; goto bailout ; } for ( i = 0 ; i < fields ; i++ ) { data->fielddata[i] = ( float * ) malloc ( pixels * sizeof ( float ) ) ; if ( data->fielddata[i] == NULL ) { error_flag = -2 ; goto bailout ; } } bailout : return ( error_flag ) ; }