Concatenting Strings Help
Concatenting Strings Help
(OP)
I need to build a string based on some input data. The data is coming from user input from a motif application so I don't know the length of any piece of data.
Here is my code:
character*50 str0,s0
character*50 str1,s1
character*50 str2,s2
character*50 str3,s3
character*10 str4,s4
character*10 str5,s5
character*70 elemID
integer*4 lenchr
c *** note: s0 thru s5 are variable from motif applic.***
str0 = s0(1:lentrim(s0))
str1 = s1(1:lentrim(s1))
.
.
.
str6 = s6(1:lentrim(s6))
elemID = str0 // ',' // str1 // ',' // str2 // ',' //
& str3 // ',' // str4 // ',' // str5
open(1,"filename", status="UNKNOWN")
write(1,'(a,2x,i4)') elemID, lenchr
c *** end of code ***
When I print out the values, I get the correct values for all the separate variables, ie...
str0 = base
str1 = A
str2 = B
str3 = C
str4 = D
str5 = E
When I print out 'eleID' and 'lenchr', I expect this:
'base,A,B,C,D,E 14'
... but what i get is:
'base 4'
I am assuming this has something to do with the string declarations, but I'm not sure. I know that when all the strings are added up, they will be less than 70 characters, but I don't know the length of any of the particular fields.
Any help would be greatly appreciated.
Regards,
mjs84
Here is my code:
character*50 str0,s0
character*50 str1,s1
character*50 str2,s2
character*50 str3,s3
character*10 str4,s4
character*10 str5,s5
character*70 elemID
integer*4 lenchr
c *** note: s0 thru s5 are variable from motif applic.***
str0 = s0(1:lentrim(s0))
str1 = s1(1:lentrim(s1))
.
.
.
str6 = s6(1:lentrim(s6))
elemID = str0 // ',' // str1 // ',' // str2 // ',' //
& str3 // ',' // str4 // ',' // str5
open(1,"filename", status="UNKNOWN")
write(1,'(a,2x,i4)') elemID, lenchr
c *** end of code ***
When I print out the values, I get the correct values for all the separate variables, ie...
str0 = base
str1 = A
str2 = B
str3 = C
str4 = D
str5 = E
When I print out 'eleID' and 'lenchr', I expect this:
'base,A,B,C,D,E 14'
... but what i get is:
'base 4'
I am assuming this has something to do with the string declarations, but I'm not sure. I know that when all the strings are added up, they will be less than 70 characters, but I don't know the length of any of the particular fields.
Any help would be greatly appreciated.
Regards,
mjs84
RE: Concatenting Strings Help
elemID=len_trim(s0)//','//len_trim(s1)//','//....etc.
That will eliminate all those trailing blanks, as well as save the auxilliary storage variables, which, as you coded them, wind up being exact copies (trim the blanks, then pad with blanks again to fill the variable to its defined length).
RE: Concatenting Strings Help
elemID=trim(s0)//','//trim(s1)//','//....etc.
What an embarassment! But I hope I have redeemed myself. HTH.
RE: Concatenting Strings Help
Thanks for your help.
mjs84