实现getarg子例程调用 [英] Implementing getarg subroutine call

查看:55
本文介绍了实现getarg子例程调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用F90编写了一个程序,该程序从文本文件中读取一些输入数组,然后通过函数将它们组合到单个输出文件中.使用MMDDYY.tuvr收集数据的日期命名为输入文件之一,然后将输出文件命名为MMDDYY.fxi.我希望能够在运行程序时在命令行中输入数据的MMDDYY,而不必每次手动更改代码并进行编译,这就是为什么我尝试使用getarg的原因,但是我似乎无法使它正常工作.我尝试使用的代码在下面列出(仅显示get arg和open命令,而不是整个程序,因为这是我遇到的问题):

I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I cannot seem to make it work properly. The code im attempting to use is listed below (just shows the get arg and the open commands and not the entire program since this is where I'm having trouble):

CHARACTER(len=20) :: arg, tuvrname, fxiname
CALL getarg(1, arg)
IF(LEN_TRIM(arg) == 0) THEN
    print*,'No date provided'
    STOP
ELSE
    tuvrname = TRIM(arg)'.tuvr'
    fxiname = TRIM(arg).'fxi'
ENDIF

OPEN(1, file = tuvrname, status='old', action='read')
....
OPEN(4, file = fxiname, status='replace', action='write')

我还尝试仅使用两个单独的getarg命令并在命令行中输入MMDDDYY.tuvr MMDDYY.fxi,程序运行了,但是由于输出为空,它似乎找不到我的TUVR文件.

I also tried just using two separate getarg commands and entering MMDDDYY.tuvr MMDDYY.fxi in the command line and the program ran, but it could not seem to find my TUVR file as the output was empty.

推荐答案

我对使用 getarg 并没有真正的经验.我使用的是Fortran 2003中的 get_command_argument .我认为您只是忘记了使用//来连接字符串.

I am not really experienced in using getarg. I use get_command_argument from Fortran 2003. I think you just forgot to use // to concatenate the strings.

CHARACTER(len=20) :: arg, tuvrname, fxiname
CALL getarg(1, arg)
IF(LEN_TRIM(arg) == 0) THEN
    print*,'No date provided'
    STOP
ELSE
    tuvrname = TRIM(arg)//'.tuvr'
    fxiname = TRIM(arg)//'.fxi'
ENDIF

print *, tuvrname, fxiname

end

CHARACTER(len=20) :: arg, tuvrname, fxiname
if (command_argument_count()<1) then
  stop "Provide the file name."
end if
CALL get_command_argument(1, value=arg)

tuvrname = TRIM(arg)//'.tuvr'
fxiname = TRIM(arg)//'.fxi'

print *, tuvrname, fxiname

end

这篇关于实现getarg子例程调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆