vic/extensions/rout_rvic/src/rout_alloc.c
void
rout_alloc(void)
{
    extern int mpi_rank;
    if (mpi_rank == VIC_MPI_ROOT) {
        extern domain_struct    global_domain;
        extern rout_struct      rout;
        int                     ivar;
        size_t                  d1count[1];
        size_t                  d1start[1];
        extern filenames_struct filenames;
        int                     status;

        // open parameter file
        status = nc_open(filenames.rout_params.nc_filename, NC_NOWRITE,
                         &(filenames.rout_params.nc_id));
        check_nc_status(status, "Error opening %s",
                        filenames.rout_params.nc_filename);

        d1count[0] = 0;
        d1start[0] = 1;

        // Get some values and dimensions
        get_nc_field_int(&(filenames.rout_params),
                         "full_time_length",
                         d1start,
                         d1count,
                         &ivar);
        rout.rout_param.full_time_length = (int) ivar;

        rout.rout_param.n_timesteps = get_nc_dimension(&(filenames.rout_params),
                                                       "timesteps");
        rout.rout_param.n_outlets = get_nc_dimension(&(filenames.rout_params),
                                                     "outlets");
        rout.rout_param.n_sources = get_nc_dimension(&(filenames.rout_params),
                                                     "sources");

        // Allocate memory in rout param_struct
        rout.rout_param.source2outlet_ind = malloc(
            rout.rout_param.n_sources *
            sizeof(*rout.rout_param.source2outlet_ind));
        check_alloc_status(rout.rout_param.source2outlet_ind,
                           "Memory allocation error.");

        rout.rout_param.source_time_offset = malloc(
            rout.rout_param.n_sources *
            sizeof(*rout.rout_param.source_time_offset));
        check_alloc_status(rout.rout_param.source_time_offset,
                           "Memory allocation error.");

        rout.rout_param.source_x_ind = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_x_ind));
        check_alloc_status(rout.rout_param.source_x_ind,
                           "Memory allocation error.");

        rout.rout_param.source_y_ind = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_y_ind));
        check_alloc_status(rout.rout_param.source_y_ind,
                           "Memory allocation error.");

        rout.rout_param.source_lat = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_lat));
        check_alloc_status(rout.rout_param.source_lat,
                           "Memory allocation error.");

        rout.rout_param.source_lon = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_lon));
        check_alloc_status(rout.rout_param.source_lon,
                           "Memory allocation error.");

        rout.rout_param.source_VIC_index = malloc(
            rout.rout_param.n_sources *
            sizeof(*rout.rout_param.source_VIC_index));
        check_alloc_status(rout.rout_param.source_VIC_index,
                           "Memory allocation error.");

        rout.rout_param.outlet_lat = malloc(
            rout.rout_param.n_outlets * sizeof(*rout.rout_param.outlet_lat));
        check_alloc_status(rout.rout_param.outlet_lat,
                           "Memory allocation error.");

        rout.rout_param.outlet_lon = malloc(
            rout.rout_param.n_outlets * sizeof(*rout.rout_param.outlet_lon));
        check_alloc_status(rout.rout_param.outlet_lon,
                           "Memory allocation error.");

        rout.rout_param.outlet_VIC_index = malloc(
            rout.rout_param.n_outlets *
            sizeof(rout.rout_param.outlet_VIC_index));
        check_alloc_status(rout.rout_param.outlet_VIC_index,
                           "Memory allocation error.");

        rout.rout_param.unit_hydrograph = malloc(
            rout.rout_param.n_sources * rout.rout_param.n_timesteps *
            sizeof(*rout.rout_param.unit_hydrograph));
        check_alloc_status(rout.rout_param.unit_hydrograph,
                           "Memory allocation error.");

        rout.rout_param.aggrunin =
            malloc(
                global_domain.ncells_total * sizeof(*rout.rout_param.aggrunin));
        check_alloc_status(rout.rout_param.aggrunin,
                           "Memory allocation error.");

        rout.discharge =
            malloc(global_domain.ncells_total * sizeof(*rout.discharge));
        check_alloc_status(rout.discharge, "Memory allocation error.");

        // Allocate memory for the ring
        rout.ring = malloc(
            rout.rout_param.full_time_length * rout.rout_param.n_outlets *
            sizeof(*rout.ring));
        check_alloc_status(rout.ring, "Memory allocation error.");
    }
}
/******************************************************************************
 * @brief    Allocate memory for Routing structures.
 *****************************************************************************/
@brief    Allocate memory for Routing structures.
@brief Allocate memory for Routing structures .
void
rout_alloc(void)
{
    extern int mpi_rank;
    if (mpi_rank == VIC_MPI_ROOT) {
        extern domain_struct    global_domain;
        extern rout_struct      rout;
        int                     ivar;
        size_t                  d1count[1];
        size_t                  d1start[1];
        extern filenames_struct filenames;
        int                     status;
        status = nc_open(filenames.rout_params.nc_filename, NC_NOWRITE,
                         &(filenames.rout_params.nc_id));
        check_nc_status(status, "Error opening %s",
                        filenames.rout_params.nc_filename);
        d1count[0] = 0;
        d1start[0] = 1;
        get_nc_field_int(&(filenames.rout_params),
                         "full_time_length",
                         d1start,
                         d1count,
                         &ivar);
        rout.rout_param.full_time_length = (int) ivar;
        rout.rout_param.n_timesteps = get_nc_dimension(&(filenames.rout_params),
                                                       "timesteps");
        rout.rout_param.n_outlets = get_nc_dimension(&(filenames.rout_params),
                                                     "outlets");
        rout.rout_param.n_sources = get_nc_dimension(&(filenames.rout_params),
                                                     "sources");
        rout.rout_param.source2outlet_ind = malloc(
            rout.rout_param.n_sources *
            sizeof(*rout.rout_param.source2outlet_ind));
        check_alloc_status(rout.rout_param.source2outlet_ind,
                           "Memory allocation error.");
        rout.rout_param.source_time_offset = malloc(
            rout.rout_param.n_sources *
            sizeof(*rout.rout_param.source_time_offset));
        check_alloc_status(rout.rout_param.source_time_offset,
                           "Memory allocation error.");
        rout.rout_param.source_x_ind = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_x_ind));
        check_alloc_status(rout.rout_param.source_x_ind,
                           "Memory allocation error.");
        rout.rout_param.source_y_ind = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_y_ind));
        check_alloc_status(rout.rout_param.source_y_ind,
                           "Memory allocation error.");
        rout.rout_param.source_lat = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_lat));
        check_alloc_status(rout.rout_param.source_lat,
                           "Memory allocation error.");
        rout.rout_param.source_lon = malloc(
            rout.rout_param.n_sources * sizeof(*rout.rout_param.source_lon));
        check_alloc_status(rout.rout_param.source_lon,
                           "Memory allocation error.");
        rout.rout_param.source_VIC_index = malloc(
            rout.rout_param.n_sources *
            sizeof(*rout.rout_param.source_VIC_index));
        check_alloc_status(rout.rout_param.source_VIC_index,
                           "Memory allocation error.");
        rout.rout_param.outlet_lat = malloc(
            rout.rout_param.n_outlets * sizeof(*rout.rout_param.outlet_lat));
        check_alloc_status(rout.rout_param.outlet_lat,
                           "Memory allocation error.");
        rout.rout_param.outlet_lon = malloc(
            rout.rout_param.n_outlets * sizeof(*rout.rout_param.outlet_lon));
        check_alloc_status(rout.rout_param.outlet_lon,
                           "Memory allocation error.");
        rout.rout_param.outlet_VIC_index = malloc(
            rout.rout_param.n_outlets *
            sizeof(rout.rout_param.outlet_VIC_index));
        check_alloc_status(rout.rout_param.outlet_VIC_index,
                           "Memory allocation error.");
        rout.rout_param.unit_hydrograph = malloc(
            rout.rout_param.n_sources * rout.rout_param.n_timesteps *
            sizeof(*rout.rout_param.unit_hydrograph));
        check_alloc_status(rout.rout_param.unit_hydrograph,
                           "Memory allocation error.");
        rout.rout_param.aggrunin =
            malloc(
                global_domain.ncells_total * sizeof(*rout.rout_param.aggrunin));
        check_alloc_status(rout.rout_param.aggrunin,
                           "Memory allocation error.");
        rout.discharge =
            malloc(global_domain.ncells_total * sizeof(*rout.discharge));
        check_alloc_status(rout.discharge, "Memory allocation error.");
        rout.ring = malloc(
            rout.rout_param.full_time_length * rout.rout_param.n_outlets *
            sizeof(*rout.ring));
        check_alloc_status(rout.ring, "Memory allocation error.");
    }
}
void rout_alloc ( void ) { extern int mpi_rank ; if ( mpi_rank == VIC_MPI_ROOT ) { extern domain_struct global_domain ; extern rout_struct rout ; int ivar ; size_t d1count [ 1 ] ; size_t d1start [ 1 ] ; extern filenames_struct filenames ; int status ; status = nc_open ( filenames . rout_params . nc_filename , NC_NOWRITE , & ( filenames . rout_params . nc_id ) ) ; check_nc_status ( status , " " , filenames . rout_params . nc_filename ) ; d1count [ 0 ] = 0 ; d1start [ 0 ] = 1 ; get_nc_field_int ( & ( filenames . rout_params ) , " " , d1start , d1count , & ivar ) ; rout . rout_param . full_time_length = ( int ) ivar ; rout . rout_param . n_timesteps = get_nc_dimension ( & ( filenames . rout_params ) , " " ) ; rout . rout_param . n_outlets = get_nc_dimension ( & ( filenames . rout_params ) , " " ) ; rout . rout_param . n_sources = get_nc_dimension ( & ( filenames . rout_params ) , " " ) ; rout . rout_param . source2outlet_ind = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source2outlet_ind ) ) ; check_alloc_status ( rout . rout_param . source2outlet_ind , " " ) ; rout . rout_param . source_time_offset = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source_time_offset ) ) ; check_alloc_status ( rout . rout_param . source_time_offset , " " ) ; rout . rout_param . source_x_ind = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source_x_ind ) ) ; check_alloc_status ( rout . rout_param . source_x_ind , " " ) ; rout . rout_param . source_y_ind = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source_y_ind ) ) ; check_alloc_status ( rout . rout_param . source_y_ind , " " ) ; rout . rout_param . source_lat = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source_lat ) ) ; check_alloc_status ( rout . rout_param . source_lat , " " ) ; rout . rout_param . source_lon = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source_lon ) ) ; check_alloc_status ( rout . rout_param . source_lon , " " ) ; rout . rout_param . source_VIC_index = malloc ( rout . rout_param . n_sources * sizeof ( * rout . rout_param . source_VIC_index ) ) ; check_alloc_status ( rout . rout_param . source_VIC_index , " " ) ; rout . rout_param . outlet_lat = malloc ( rout . rout_param . n_outlets * sizeof ( * rout . rout_param . outlet_lat ) ) ; check_alloc_status ( rout . rout_param . outlet_lat , " " ) ; rout . rout_param . outlet_lon = malloc ( rout . rout_param . n_outlets * sizeof ( * rout . rout_param . outlet_lon ) ) ; check_alloc_status ( rout . rout_param . outlet_lon , " " ) ; rout . rout_param . outlet_VIC_index = malloc ( rout . rout_param . n_outlets * sizeof ( rout . rout_param . outlet_VIC_index ) ) ; check_alloc_status ( rout . rout_param . outlet_VIC_index , " " ) ; rout . rout_param . unit_hydrograph = malloc ( rout . rout_param . n_sources * rout . rout_param . n_timesteps * sizeof ( * rout . rout_param . unit_hydrograph ) ) ; check_alloc_status ( rout . rout_param . unit_hydrograph , " " ) ; rout . rout_param . aggrunin = malloc ( global_domain . ncells_total * sizeof ( * rout . rout_param . aggrunin ) ) ; check_alloc_status ( rout . rout_param . aggrunin , " " ) ; rout . discharge = malloc ( global_domain . ncells_total * sizeof ( * rout . discharge ) ) ; check_alloc_status ( rout . discharge , " " ) ; rout . ring = malloc ( rout . rout_param . full_time_length * rout . rout_param . n_outlets * sizeof ( * rout . ring ) ) ; check_alloc_status ( rout . ring , " " ) ; } }
@brief    Allocate memory for Routing structures.
@brief Allocate memory for Routing structures .
// open parameter file // Get some values and dimensions // Allocate memory in rout param_struct // Allocate memory for the ring