---
title: 文件操作
description: "- 创建文件。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0044.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0044.html
indexId: c5253850fe65e7019f999da1849d680e0c2ab7ea4de927ea7972de22edfa8ac758
---
# 文件操作

#### 函数定义

- 创建文件。
  NC_create(const char *name, int mode, size_t initialsz, int basepe,

  size_t *chunksizehintp, int useparallel, void *parameters, int *ncidp)

- 创建文件进行并行IO。
  nc_create_par(const char *name, int mode, MPI_Comm comm, MPI_Info info, int* ncidp)

- 打开现有文件。
  NC_open(const char *name, int mode, int basepe, size_t *chunksizehintp,

  int useparallel, void *parameters, int *ncidp)

- 打开现有文件进行并行IO。
  nc_open_par(const char *name, int mode, MPI_Comm comm, MPI_Info info, int* ncidp)

- 关闭打开的文件。
  nc_close(int ncid)

- 进入定义模式。
  nc_redef(int ncid)

- 退出定义模式。
  nc_enddef(int ncid)


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| ncid | 文件ID | 非负整数 | 输入 |
| \*ncidp | 返回文件ID的指针 | 非空 | 输出 |
| \*name | 文件名称 | 非空，长度小于256字节 | 输入 |
| comm | MPI通信器句柄 | 非空 | 输入 |
| info | MPIinfo对象句柄 | 非空 | 输入 |
| \*chunksizehintp | 分块大小指针 | 非空 | 输入 |
| useparallel | 是否开启并行IO | 整数 | 输入 |
| \*parameters | 存储MPI信息的结构体指针 | 非空 | 输入 |
| mode | 创建/打开模式 | 整数 | 输入 |
| initialsz | 初始化大小 | 非负整数 | 输入 |
| basepe | 基本处理元素 | 整数 | 输入 |


#### 返回值

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


#### 错误码

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