---
title: 定义一个新维度
description: "nc_def_dim(int ncid, const char* name, size_t len, int *idp)"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/userg_hyperio_0047.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/userg_hyperio_0047.html
indexId: 5deb1bc73557dbb7f1de14c823eea5b860ac99f16c6de10f5fb4f0d44135112464
---
# 定义一个新维度

#### 函数定义

nc_def_dim(int ncid, const char* name, size_t len, int *idp)


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| ncid | 文件ID | 非负整数 | 输入 |
| \*name | 文件名称 | 非空，长度小于256字节 | 输入 |
| len | 维度长度 | 非负整数 | 输入 |
| \*idp | 返回维度ID的指针 | 非空 | 输出 |


#### 返回值

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


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| NC\_EBADID | 无效ncid |
| NC\_EMAXNAME | 名称过长 |
| NC\_EINVAL | 无效参数 |
| NC\_EDIMSIZE | 无效维度大小 |
| NC\_ENOMEM | 内存不足 |
