Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Remove trailing spaces

kai_larsen
Beginner
1,533 Views

Hi!

I need to tell my fortran program which directory to find all the files it will work with. To accomplish this, I use a text parameter through CALL GETARG().

I then

filename = workingdirectory // 'filename.dat'

OPEN(50,FILE=filename,FORM='FORMATTED')

Unfortunately, this leads to the following content in filename:

c:directory1 est svd2b.dat

I need a way to remove all the spaces. Any advice is greatly appreciated!

Thanks!

-- Kai

0 Kudos
6 Replies
lklawrie
Beginner
1,533 Views

Use TRIM(workingdirectory)//trim(filename)

Linda

0 Kudos
kai_larsen
Beginner
1,533 Views

Thanks! That helps a lot. Unfortunately, that seems to remove spaces from anywhere in the string (since I'm dealing with directory names, it removes some crucial spaces). Is there any way to remove only trailing spaces?

-- Kai :-)

0 Kudos
davidspurr
Beginner
1,533 Views
If so, something else is wrong.

TRIM( ) only removes trailing blanks. Standard Fortran since "forever".

It is best you read the manual, or type "trim fortran" into Google .

David
0 Kudos
kai_larsen
Beginner
1,533 Views

Thanks David!

You are right, of course, and I did actually google the problem before asking. I just realized that TRIM was not my problem.

As I mentioned above, I use GETARG() to get the directory name as a command line parameter. Unfortunately, it turns out that when the directory name contains spaces, these are treated as different parameters. Arg(h)...

I guess my question is whether there is a way to cap a string so that GETARG understands that it is one string rather than two (or 3,4,5,6)? I've tried Google with no luck, and my guesses of "c:dir 1" and 'c:dir 1' don't work.

Kai :-)

0 Kudos
anthonyrichards
New Contributor III
1,533 Views

Use double quotes ( application.exe "here is the argument")and it will work fine.

Just to prove it, here is a simple Fortran console .EXE which I copied to the root directory c: and then ran from the Start..Run...command line as

c:getargument "here is an argument"

which gave the console output shown in the screenshot.

0 Kudos
Steven_L_Intel1
Employee
1,533 Views
This is the standard behavior for Windows (and Linux and UNIX) - spaces are considered separators in command line arguments. As Anthony says, enclosing the string in quotes preserves the spaces.

If you don't want to do this, you can add a space between each argument you retrieve with GETARG.
0 Kudos
Reply