---
title: 属性信息写入
description: "- 写入属性。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/userg_hyperio_0057.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/userg_hyperio_0057.html
indexId: 15de92692f6ed1a2dc161561df5717cee59873d0ecbc4290683a6c1c3510901164
---
# 属性信息写入

#### 函数定义

- 写入属性。
  nc_put_att(int ncid, int varid, const char* name, int xtype, size_t len, const void* op)

- 写入int类型属性。
  nc_put_att_int(int ncid, int varid, const char* name, nc_type xtype, size_t len, const int *op)

- 写入float类型属性。
  nc_put_att_float(int ncid, int varid, const char* name, nc_type xtype, size_t len, const float *op)

- 写入double类型属性。
  nc_put_att_double(int ncid, int varid, const char* name, nc_type xtype, size_t len, const double *op)

- 写入文本类型属性。
  nc_put_att_text(int ncid, int varid, const char* name, size_t len, const char *op)


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| ncid | 文件ID | 非负整数 | 输入 |
| varid | variable ID | 非负整数 | 输入 |
| xtype | attribute类型 | 非负整数 | 输入 |
| name | attribute名称 | 非空 | 输入 |
| len | attribute名称长度 | 非负整数 | 输入 |
| op | 数据指针 | 非空 | 输入 |


#### 返回值

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


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| NC\_EBADID | 无效ncid |
| NC\_ENOTVAR | 无效variableid |
| NC\_EINVAL | 无效参数 |
| NC\_ENOMEM | 内存不足 |


#### 注意

- 用户需要保证指针内存大小正确性，中间件无法检查指针大小。
- 目前仅支持上述类型att的写入，需要保证类型与函数对应。
- nc_type是int类型的别名。
