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

ifort String Concatenation problem in Fortran 90

Ahmad_Falahatpisheh
2,465 Views
Hi All,

I have read forums on string concatenation in fortran 90 such as http://software.intel.com/en-us/forums/showthread.php?t=51416&o=a&s=lr&wapkw=%28atom%29 but I couldn't find the solution to my problem. A portion of my code which concatenates the file name and its path is as follows:

character*255 :: ifilename, ipath, ifull

ifilename='test.dat'
ipath='c:\\data\'
ifull=ipath//ifilename
open (unit = 1 , file = ifull , form='formatted', status = "old", iostat = status)


But ifull does not have the full path of the file and contains only the value of ipath and therefore OPEN statement cannot find the file. I build my code by ifort command in windows. I appreciate any help.

0 Kudos
1 Solution
Arjen_Markus
Honored Contributor II
2,465 Views
The thing you overlook is that in Fortran a string is padded with blanks. So:
ipath = 'c:\data' is actually ipath = 'c:\data... blanks until position 255 ...'

So: ifull = ipath // ifilename puts 255 characters into ifull, followed by another 255 characters.
But then the result has to be truncated to 255 characters again, thus the concatenation has no effect.

Use:

ifull = trim(ipath) // ifilename

instead - trim() removes the trailing blanks.

Regards,

Arjen

View solution in original post

0 Kudos
3 Replies
Arjen_Markus
Honored Contributor II
2,466 Views
The thing you overlook is that in Fortran a string is padded with blanks. So:
ipath = 'c:\data' is actually ipath = 'c:\data... blanks until position 255 ...'

So: ifull = ipath // ifilename puts 255 characters into ifull, followed by another 255 characters.
But then the result has to be truncated to 255 characters again, thus the concatenation has no effect.

Use:

ifull = trim(ipath) // ifilename

instead - trim() removes the trailing blanks.

Regards,

Arjen
0 Kudos
Les_Neilson
Valued Contributor II
2,465 Views
You need to trim the trailing spaces from ipath before concatenating it with the file name.

ifull = ipath(:len_trim(ipath))//ifilename

Les

0 Kudos
Mohammadjafar_S_
Beginner
2,465 Views
This comment has been moved to its own thread
0 Kudos
Reply