|
| 1 | +/****************************************************************************** |
| 2 | + * @section DESCRIPTION |
| 3 | + * |
| 4 | + * Get netCDF variable type. |
| 5 | + * |
| 6 | + * @section LICENSE |
| 7 | + * |
| 8 | + * The Variable Infiltration Capacity (VIC) macroscale hydrological model |
| 9 | + * Copyright (C) 2016 The Computational Hydrology Group, Department of Civil |
| 10 | + * and Environmental Engineering, University of Washington. |
| 11 | + * |
| 12 | + * The VIC model is free software; you can redistribute it and/or |
| 13 | + * modify it under the terms of the GNU General Public License |
| 14 | + * as published by the Free Software Foundation; either version 2 |
| 15 | + * of the License, or (at your option) any later version. |
| 16 | + * |
| 17 | + * This program is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License along with |
| 23 | + * this program; if not, write to the Free Software Foundation, Inc., |
| 24 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 25 | + *****************************************************************************/ |
| 26 | + |
| 27 | +#include <vic_driver_shared_image.h> |
| 28 | + |
| 29 | +/****************************************************************************** |
| 30 | + * @brief Get netCDF variable type. |
| 31 | + *****************************************************************************/ |
| 32 | +int |
| 33 | +get_nc_var_type(char *nc_name, |
| 34 | + char *var_name) |
| 35 | +{ |
| 36 | + int nc_id; |
| 37 | + int var_id; |
| 38 | + int status; |
| 39 | + int xtypep; |
| 40 | + |
| 41 | + // open the netcdf file |
| 42 | + status = nc_open(nc_name, NC_NOWRITE, &nc_id); |
| 43 | + check_nc_status(status, "Error opening %s", nc_name); |
| 44 | + |
| 45 | + // get variable id |
| 46 | + status = nc_inq_varid(nc_id, var_name, &var_id); |
| 47 | + check_nc_status(status, "Error getting variable id %s in %s", var_name, |
| 48 | + nc_name); |
| 49 | + |
| 50 | + // get type ID |
| 51 | + status = nc_inq_var(nc_id, var_id, NULL, &xtypep, NULL, NULL, NULL); |
| 52 | + check_nc_status(status, "Error getting variable type %s in %s", var_name, |
| 53 | + nc_name); |
| 54 | + |
| 55 | + // close the netcdf file |
| 56 | + status = nc_close(nc_id); |
| 57 | + check_nc_status(status, "Error closing %s", nc_name); |
| 58 | + |
| 59 | + return(xtypep); |
| 60 | +} |
0 commit comments