---
title: 查询变量信息
description: "- 查询有关变量信息。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0055.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0055.html
indexId: 568a1e7e8b52d435488106785b31329c927e5bfa05477542b76554dae171cad658
---
# 查询变量信息

#### 函数定义

- 查询有关变量信息。
  nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)

- 查询变量的维度数量。
  nc_inq_varndims(int ncid, int varid, int *ndimsp)

- 查询变量的维度ID。
  nc_inq_vardimid(int ncid, int varid, int *dimidsp)

- 根据名称查询变量ID。
  nc_inq_varid(int ncid, const char *name, int *varidp)


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| ncid | 文件ID | 非负整数 | 输入 |
| varid | variable ID | 非负整数 | 输入 |
| const \*name | variable名称 | 非空，长度小于256字节 | 输入 |
| \*name | 返回variable名称的指针 | 非空 | 输出 |
| \*xtypep | 返回variable数据类型的指针 | 非空 | 输出 |
| \*ndimsp | 返回variable dim数量的指针 | 非空 | 输出 |
| \*dimidsp | 返回variable dimid数组的指针 | 非空 | 输出 |
| \*nattsp | 返回variable attribute数量的指针 | 非空 | 输出 |
| \*varidp | 返回variable id的指针 | 非空 | 输出 |


#### 返回值

- 成功：返回NC_NOERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| NC\_EBADID | 无效ncid |
| NC\_ENOTVAR | 无效varid |


#### 注意

*name、*xtypep、*ndimsp、*dimidsp、*nattsp、*varidp参数在不需要获取数据时可以为空指针，需要获取数据时必须非空。
