- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do anyone know how to convert an integer*4 to a byte or character*32 ?
Thanks
M.Santos
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
character(10) string
integer num
num = 123
write (string, '(I0)') num
print *, string
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In fact, I have a variable (integer*4) thatrepresents a tagname.
I need this tagname as a character*32 or a Byte in order to access a dll, called from C++.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could use a UNION of the integer*4 and a character*4 then copy the character part of the union to a character*32. Note, you may have to check for BigEndian/LittleEndian issues and the copy operation will insert spaces into the remainder of the character*32 as opposed to NULL bytes.
FORTRAN also has a TRANSFER Intrinsic function
Un-tested sample
integer(4) :: I4
character(len=4) :: C4
character(len=32) :: C32
character :: C1
character :: C1x4(4)
...
C4 = TRANSFER(I4, C4)
C1x4 = TRANSFER(I4,C1,4)
Or something like that.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Exact. I mean "byte array" when I say byte.
In my database I have saved a string (FC1200PV, for example)as an integer*4 variable. NowI need a "byte array" (or character*32) that represents this integer*4, that is, FC1200PV.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
character(32) tagname
integer key
key = 1200
write (tagname,'("FC",I4.4,"PV")') key
The I4.4 assumes that you always want four digits with leading zeroes. If you want no leading zeroes, then use I0 instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I read a binary file in C. This variable Name is defined in C as
char Name[32]
This variable is passed from C to Fortran in a structure.
In Fortran, I define this variable as integer*4 Name[32]
I do that because in C and Fortran, char and character are different.
So, I need the string that represents this integer variable in Fortran (character or byte array).
Sorry for the misunderstanding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve and Jim,
It works well with the TRANSFER function.
Thank you very much.
M.Santos
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page