macos - Fortran 在目录中找不到输入文件
问题描述
我用fortran(f90,使用gfortran)编写了一个程序,它从一个.txt文件(列出o整数)接收输入。
PROGRAM prog_example
implicit none
INTEGER i,j
CHARACTER file1*20
CHARACTER*8, DIMENSION(10,3000) :: data
302 FORMAT (a20)
WRITE(*,*)'Type the name of the input file:'
CALL SYSTEM("pwd") !show the directory
READ(*,302) file1
OPEN(20,file=file1,status='old')
END
当我运行代码并键入文件夹中的文件名 (in.txt) 时,它返回一个错误,指出它找不到该文件。这段代码在我的旧 Windows 计算机上运行得很好,但在我的 Mac 上却不行。可能是什么问题呢?
所有文件都在 Usr/documents/prog_example 中,其中包含:
Sypome5.cbp Sypome5.depend Sypome5.exe Sypome5.layout
a.out bin in.txt main main.f95 obj
我收到以下错误消息:
At line 101 of file main.f95 (unit = 20) Fortran runtime error: Cannot open file 'in.txt': No such file or directory
Error termination. Backtrace:
#0 0x104620b17
#1 0x10462178f
#2 0x104622113
#3 0x1046e6f23
#4 0x1046e7157
#5 0x10456155b
#6 0x104562337
#7 0x10456314b
添加打印目录的命令后,我了解到它在我的根目录 (Users/pedro) 中运行,但它应该在 Users/pedro/documents/prog_example 中运行。如果我将输入文件粘贴到根目录中,它就可以正常工作,但是将这些文件放在那里会很麻烦。
解决方案
推荐阅读
- html - 尽管 Bootstrap col 说 col-md-4,为什么它会占据整个宽度?
- python - 如何从对象列表中导入类对象?
- python - 为什么我的下拉菜单在某些页面上不起作用
- google-sheets - 基于第一个单元格的相邻单元格的总和
- c - 使用cmake编译带有c文件的asm文件
- azure - 错误的请求。提供的工作流操作输入无效。在创建 blob 存储时
- javascript - Angular ngx-datatable 将 ID 添加到行
- rust - Rust bitwise into u8
- time-series - 如何根据时间序列数据中的 t-1 值计算列值?
- sql-server - 使用 ASP.NET 和 AngularJs 将二进制数据格式的图像和多个文件上传到 SQL Server