Assigning a number string to a character variable 
Author Message
 Assigning a number string to a character variable

Hi

 I apologize if this is a very simple question and I am missing something
obvious.

 I want to append a positive integer to a character string in a consistent
manner. Lets say that my number is n. Then the number of characters
occupied by the n, represented as a string is :

 m=int(log10(real(n)))+1

 Now, if I try to use an internal read to "convert" n to a string :

 read(cn,*) n

 I end up with a set of leading blanks. How does one get rid of them (unless
I am much mistaken, trim() gets rid only of trailing blanks) ?

 I cannot have a variable length format specifier above in the read, of the
form a<m> as that is not standard fortran.

 My required final result is string.n (with len_trim(string)+1+m characters,
no needless blanks anywhere). How do you suggest I achieve this ?

Thanks.



Mon, 17 Sep 2007 14:16:51 GMT  
 Assigning a number string to a character variable

Quote:

> Hi

>  I apologize if this is a very simple question and I am missing something
> obvious.

>  I want to append a positive integer to a character string in a consistent
> manner. Lets say that my number is n. Then the number of characters
> occupied by the n, represented as a string is :

>  m=int(log10(real(n)))+1

>  Now, if I try to use an internal read to "convert" n to a string :

>  read(cn,*) n

>  I end up with a set of leading blanks. How does one get rid of them (unless
> I am much mistaken, trim() gets rid only of trailing blanks) ?

>  I cannot have a variable length format specifier above in the read, of the
> form a<m> as that is not standard fortran.

>  My required final result is string.n (with len_trim(string)+1+m characters,
> no needless blanks anywhere). How do you suggest I achieve this ?

> Thanks.

If you are using a Fortran 95 compiler, then you can use the I0 format -
that will write only as many positions as are strictly needed. If you
are
stuck to Fortran 90, then ADJUSTL(cn) will do the trick

Regards,

Arjen



Mon, 17 Sep 2007 14:26:36 GMT  
 Assigning a number string to a character variable

Quote:
>  My required final result is string.n (with len_trim(string)+1+m
characters,
> no needless blanks anywhere). How do you suggest I achieve this ?

trim(string)//'.'//write_number(n)

The write_number function and its required specification
function, write_number_len can be found in

http://home.comcast.net/~kmbtib/conv2b.f90

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end



Mon, 17 Sep 2007 15:47:26 GMT  
 Assigning a number string to a character variable
Quote:

> Hi

>  I apologize if this is a very simple question and I am missing something
> obvious.

>  I want to append a positive integer to a character string in a consistent
> manner. Lets say that my number is n. Then the number of characters
> occupied by the n, represented as a string is :

>  m=int(log10(real(n)))+1

>  Now, if I try to use an internal read to "convert" n to a string :

I suppose you mean
  WRITE(cn,*) N   !  :-)

Quote:
>  read(cn,*) n
>  I end up with a set of leading blanks. How does one get rid of them (unless
> I am much mistaken, trim() gets rid only of trailing blanks) ?
>  I cannot have a variable length format specifier above in the read, of the
> form a<m> as that is not standard fortran.

But, what you might do, is use a fixed number of digits with:

  WRITE(CN, "(I4.4)") n   !  Leading zeros.
or
  WRITE(CN, "(I0)")  n  !  minimum width  

Quote:
>  My required final result is string.n (with len_trim(string)+1+m characters,
> no needless blanks anywhere). How do you suggest I achieve this ?

 [JvO]


Mon, 17 Sep 2007 23:16:15 GMT  
 Assigning a number string to a character variable

Quote:



>> Hi

>>  I apologize if this is a very simple question and I am missing something
>> obvious.

>>  I want to append a positive integer to a character string in a
>>  consistent
>> manner. Lets say that my number is n. Then the number of characters
>> occupied by the n, represented as a string is :

>>  m=int(log10(real(n)))+1

>>  Now, if I try to use an internal read to "convert" n to a string :

> I suppose you mean
>   WRITE(cn,*) N   !  :-)

Yes :)

Fatigue, late night and programming clearly do not mix :)

Thanks for your response.



Tue, 18 Sep 2007 01:19:25 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. assigning new numbers to same variables?

2. Assigning a random number as a variable

3. Assigning a string variable to a memo field in CW5

4. How to assign null string to a variable?

5. assigning to class variable works in string, not in block

6. Assigning numeric variables to strings

7. BUG: Scientific Number to String/String to Number

8. Converting a number in a String character to an Integer

9. How to count number of characters in string?

10. number to string .... string to number

11. converting character strings to real numbers

12. Parsing a character string into numbers?

 

 
Powered by phpBB® Forum Software