无法使用 c++ 中的 nc_open() 函数打开 netcdf 文件(.nc)

发布于 2025-01-12 21:46:48 字数 203 浏览 1 评论 0原文

nc_open(input_file.c_str(), NC_NOWRITE , &ncid)

这里的 input_file 是文件路径。仅当 netcdf 文件放置在可执行文件所在的 bin 文件夹中时,该文件才会打开。 当 netcdf 文件 (.nc) 未放置在 bin 文件夹中时,netcdf 文件不会打开。 为什么会发生这种情况?

nc_open(input_file.c_str(), NC_NOWRITE , &ncid)

Here the input_file is the file path. The file is opening only when the netcdf file is placed in the bin folder where the executable is present.
When the netcdf file(.nc) is not placed in the bin folder then the netcdf file does not open.
why is this happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多孤肩上扛 2025-01-19 21:46:48

/bin 文件夹代表二进制文件,您编译的程序通常位于该文件夹中。如果您传入“file.txt”作为文件名,程序将在程序本身所在的文件夹中查找文件“file.txt”。

C:\
  |- proj\
         |- bin\
               |- program.exe [open("test.txt")]--\
               |- file.txt     <------------------/

如果您想访问某个位置的文件,您应该在 input_file 中传入绝对路径(例如 C:\test.txt

C:\
  |- proj\
  |      |- bin\
  |            |- program.exe [open("C:\\test.txt")]
  |- file.txt     <--------------------|

The /bin folder stand for binary and your complied program is usually located in this folder. If you passes in "file.txt" as the file name, the program will find the file "file.txt" in the folder where the program itself locates.

C:\
  |- proj\
         |- bin\
               |- program.exe [open("test.txt")]--\
               |- file.txt     <------------------/

If you want to access the file at a location, you should pass in the absolute path (eg. C:\test.txt) in the input_file

C:\
  |- proj\
  |      |- bin\
  |            |- program.exe [open("C:\\test.txt")]
  |- file.txt     <--------------------|
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文