Fortran Coder

simply Fortran批量读取文件

查看数: 11179 | 评论数: 9 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2017-12-26 21:50

正文摘要:

在使用simply Fortran批量读取文件中遇到问题,求各位大神指点!原来用CVF里面常用的批量读取命令: res=SYSTEMQQ(CMD),用simply Fortran报错:can't convert REAL(4)to LOGICAL(4) at 1,上网查了一下SYSTEMQQ ...

回复

辞觉 发表于 2017-12-29 17:29:05
kyra 发表于 2017-12-29 08:13
eof 函数不是标准语法,类似的 systemqq 也不是标准语法。
但凡是标准的,所有编译器都支持,所以你必须 ...

我明白了,感谢大神的指点!
辞觉 发表于 2017-12-29 17:28:37
pasuka 发表于 2017-12-29 10:17
传送门
https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gfortran/IS_005fIOSTAT_005fEND.html#IS_005fIOSTAT_ ...

感谢感谢!还要多多学习~
pasuka 发表于 2017-12-29 10:17:42
辞觉 发表于 2017-12-28 19:48
谢谢大神的回复,问题已经解决了,还想请教一下读文件的时候判断文件到末尾用的eof函数,在simply fortra ...

传送门
https://gcc.gnu.org/onlinedocs/g ... _005fIOSTAT_005fEND
9.154 IS_IOSTAT_END — Test for end-of-file value
Description:
IS_IOSTAT_END tests whether an variable has the value of the I/O status “end of file”. The function is equivalent to comparing the variable with the IOSTAT_END parameter of the intrinsic module ISO_FORTRAN_ENV.

Standard:
Fortran 2003 and later

Class:
Elemental function

Syntax:
RESULT = IS_IOSTAT_END(I)

Arguments:
I        Shall be of the type INTEGER.
Return value:
Returns a LOGICAL of the default kind, which .TRUE. if I has the value which indicates an end of file condition for IOSTAT= specifiers, and is .FALSE. otherwise.

Example:
PROGRAM iostat
  IMPLICIT NONE
  INTEGER :: stat, i
  OPEN(88, FILE='test.dat')
  READ(88, *, IOSTAT=stat) i
  IF(IS_IOSTAT_END(stat)) STOP 'END OF FILE'
END PROGRAM
kyra 发表于 2017-12-29 08:13:24
辞觉 发表于 2017-12-28 19:48
谢谢大神的回复,问题已经解决了,还想请教一下读文件的时候判断文件到末尾用的eof函数,在simply fortra ...

eof 函数不是标准语法,类似的 systemqq 也不是标准语法。
但凡是标准的,所有编译器都支持,所以你必须明白,什么用法是标准的,什么是扩展的。
能用标准的,就尽量不要用扩展的,否则更换编译器会有困难。

这也是国家提倡说普通话的原因。

eof 可以用 ioStat = k ,然后判断 k 是否等于 0 实现。
http://linenumber.w.fcode.cn/ 这里是个范例。

作为一款编译器,不需要教程。你只要保证代码足够规范、严谨就可以了
pasuka 发表于 2017-12-28 22:17:58
gfortran的在线帮助文档写得很清楚了呀!
https://gcc.gnu.org/onlinedocs/g ... 05fCOMMAND_005fLINE
9.100 EXECUTE_COMMAND_LINE — Execute a shell command
Description:
EXECUTE_COMMAND_LINE runs a shell command, synchronously or asynchronously.

The COMMAND argument is passed to the shell and executed, using the C library’s system call. (The shell is sh on Unix systems, and cmd.exe on Windows.) If WAIT is present and has the value false, the execution of the command is asynchronous if the system supports it; otherwise, the command is executed synchronously.

The three last arguments allow the user to get status information. After synchronous execution, EXITSTAT contains the integer exit code of the command, as returned by system. CMDSTAT is set to zero if the command line was executed (whatever its exit status was). CMDMSG is assigned an error message if an error has occurred.

Note that the system function need not be thread-safe. It is the responsibility of the user to ensure that system is not called concurrently.

Standard:
Fortran 2008 and later

Class:
Subroutine

Syntax:
CALL EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG ])

Arguments:
COMMAND        Shall be a default CHARACTER scalar.
WAIT        (Optional) Shall be a default LOGICAL scalar.
EXITSTAT        (Optional) Shall be an INTEGER of the default kind.
CMDSTAT        (Optional) Shall be an INTEGER of the default kind.
CMDMSG        (Optional) Shall be an CHARACTER scalar of the default kind.
Example:
program test_exec
  integer :: i

  call execute_command_line ("external_prog.exe", exitstat=i)
  print *, "Exit status of external_prog.exe was ", i

  call execute_command_line ("reindex_files.exe", wait=.false.)
  print *, "Now reindexing files in the background"

end program test_exec
Note:
Because this intrinsic is implemented in terms of the system function call, its behavior with respect to signaling is processor dependent. In particular, on POSIX-compliant systems, the SIGINT and SIGQUIT signals will be ignored, and the SIGCHLD will be blocked. As such, if the parent process is terminated, the child process might not be terminated alongside.

See also:
SYSTEM
辞觉 发表于 2017-12-28 19:50:44
li913 发表于 2017-12-27 15:26
call EXECUTE_COMMAND_LINE  ()
标准用法。

感谢感谢!还想求教一下作为刚刚接触fortran不久的小白,怎么解决从CVF转换到SF的这些问题呢?也很想自己解决,有没有什么参考的教程呢?
辞觉 发表于 2017-12-28 19:48:35

谢谢大神的回复,问题已经解决了,还想请教一下读文件的时候判断文件到末尾用的eof函数,在simply fortran中也不能用,请问应该怎么改呢?有没有simply fortran的教程啊?这些问题也想自己解决,但是网上很难搜到解决方法
li913 发表于 2017-12-27 15:26:42
call EXECUTE_COMMAND_LINE  ()
标准用法。
kyra 发表于 2017-12-27 09:35:24
call system(cmd)

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-11-23 15:41

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表