View previous topic :: View next topic |
Author |
Message |
m.burkhardt
Joined: 02 Sep 2008 Posts: 26
|
Posted: Fri Jun 10, 2011 12:48 pm Post subject: How to use transfer |
|
|
Hello I hope this is my last question!
Is there anyone who can explane the use of transfer in the following case:
Code: |
OBJECT("System.String") :: STR
CHARACTER*6 :: CHR
!
STR = "ABCDEF"
CHR = transfer(STR, CHR)
!
PRINT *,CHR
|
The output string are hieroglyphics. So I think, I never get the string 'ABCDF' but the Memory address of the variable (pointer).
I try the following with no changes:
Code: |
OBJECT("System.String") :: STR
CHARACTER*6 :: CHR
INTEGER*2 LENGTH
!
LENGTH = 6
STR = "ABCDEF"
CHR = transfer(STR, CHR, LENGTH)
!
PRINT *,CHR
|
The outoput is the same as on the top!
What do I wrong? Or how can I get access of the value (string) and not of the address (pointer)?
Greetings from Germany
Michael |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat Jun 11, 2011 7:38 am Post subject: |
|
|
Transfer just copies "bits" from one variable to another. The target and source variables need to be the same size and it needs to make sense to copy the bits. Think of it as a run-time form of EQUIVALENCE.
As the bit patterns for the string "ABCDEF" are probably different for the two variable types OBJECT("System.String") and CHARACTER*6 then transfer is not much use in this case. You will just get garbage.
However something like OBJECT("System.Int32") and INTEGER*4 are likely to have the same bit pattern representation.
Transfer isn't very portable. I use it to implement generic function interfaces in Fortran 95 (where transfer is made to "coerce" a variable into an integer array for passing, and later this is transfered back to the variable type). This is quite portable but it breaks some optimizing compilers. Once we get fully working Fortran 2003 compilers there are better ways to do this. |
|
Back to top |
|
|
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Mon Jun 13, 2011 11:29 am Post subject: |
|
|
.NET strings are unicode, though I don't know if this is the only problem here. |
|
Back to top |
|
|
m.burkhardt
Joined: 02 Sep 2008 Posts: 26
|
Posted: Wed Jun 15, 2011 6:15 pm Post subject: |
|
|
Thanks allot!
It Works!!!
Greetings from Germany
Michael |
|
Back to top |
|
|
|