0

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')

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.

1
  • If I were really nit-picking, I would say you did not write a program in F90, but in a proprietary extension language to it. Commented Mar 12, 2013 at 18:44

1 Answer 1

2

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

or

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
Sign up to request clarification or add additional context in comments.

2 Comments

I implemented the following: 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 But after compiling I enter './createfxi AP2412' in the command prompt and it gives me the 'No date provided' output. Not sure what is going on
Also, see your compiler manual for exact definition of your getarg, it can behave slightly differently than mine, it is nonstandard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.