---
title: 查询变量和属性信息
description: "- 查询变量信息。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/userg_hyperio_0070.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/userg_hyperio_0070.html
indexId: cb9090626b5acc3f7a5b4c57a48d9b7f09eaad6a08aeaa894b350d37f3b90b0364
---
# 查询变量和属性信息

#### 函数定义

- 查询变量信息。
  int ncmpi_inq_varid(int fileId, const char* name, int* idPoint);

  int ncmpi_inq_var(int fileId, int variableId, char* name, int* ncDataType, int* dimNumber, int* dimsArray, int* nattsp);

  int ncmpi_inq_varndims(int fileId, int variableId, int* dimNumber);

- 查询属性信息。
  int ncmpi_inq_att(int fileId, int varId, const char* name, int* xtypep, MPI_Offset* lenp);

  int ncmpi_inq_attname(int fileId, int varId, int attNum, char* name);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| fileId | 文件ID | 非负整数 | 输入 |
| \*idPoint | 返回variable ID的指针 | 非空 | 输出 |
| variableId/varId | variable ID | 非负整数 | 输入 |
| const \*name | variable名称/attribute名称 | 非空，长度小于256字节 | 输入 |
| \*name | variable名称/attribute名称 | 非空 | 输出 |
| \*ncDataType | 返回variable数据类型的指针 | 非空 | 输出 |
| \*dimNumber | 返回维度数量的指针 | 非空 | 输出 |
| \*dimsArray | 返回维度ID数组的指针 | 非空 | 输出 |
| \*nattsp | 返回属性数量的指针 | 非空 | 输出 |
| \*xtypep | 返回att类型的指针 | 非空 | 输出 |
| \*lenp | 返回att数量的指针 | 非空 | 输出 |
| attNum | att ID | 非负整数 | 输入 |


#### 返回值

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


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| NC\_EBADID | 无效ncid |
| NC\_ENBADDIM | 无效dimid |
| NC\_ENOMEM | 空指针或无效内存 |
| NC\_EBADNAME | 无效名称 |


#### 注意

*idPoint、*name、*ncDataType、*dimNumber、*dimsArray、*nattsp、*xtypep、*lenp参数在不需要获取数据时可以为空指针，在需要获取数据时必须非空。
