- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am creating a large amount of data in memory which i then write as a binary file. The data is in different formats (reals and integers of different types) and is non-sequential across types. Writing every individual element to disk in turn can be quite slow. What I am doing, therefore, is to create a large character array and use the transfer function to copy the bytes of, for example, a REAL*8 to 8 elements of a character array. I can then use a single write.
e.g. dataset(:)(tempInt4:tempInt4+7) = TRANSFER(stataFile%saveCurr%valReal8,(/1_'00000000'/))
where dataset is CHARACTER(N1) :: dataset(N2) and valReal8 is an N2 dimensional array of type REAL*8. I do this similarly for other types where mold has a different number of zeros depending upon the number of bytes required.
This works as I want it to work. But should it? Someone told me that if this works, it must be a bug. Any thoughts?
Thanks,
Andrew
I am creating a large amount of data in memory which i then write as a binary file. The data is in different formats (reals and integers of different types) and is non-sequential across types. Writing every individual element to disk in turn can be quite slow. What I am doing, therefore, is to create a large character array and use the transfer function to copy the bytes of, for example, a REAL*8 to 8 elements of a character array. I can then use a single write.
e.g. dataset(:)(tempInt4:tempInt4+7) = TRANSFER(stataFile%saveCurr%valReal8,(/1_'00000000'/))
where dataset is CHARACTER(N1) :: dataset(N2) and valReal8 is an N2 dimensional array of type REAL*8. I do this similarly for other types where mold has a different number of zeros depending upon the number of bytes required.
This works as I want it to work. But should it? Someone told me that if this works, it must be a bug. Any thoughts?
Thanks,
Andrew
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you really mean to write 1_'00000000'? That's not legal syntax. If it was '00000000', that would be ok. Other than that, I don't see a problem with what you're doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Thanks for your reply. It compiles and works properly using both 1_'00000000' (as I did originally) and just with '00000000' (as I have changed it to now). It would be useful if it generated a compile time error to stop people like me using bad syntax (which may/may not work with other compilers).
Andrew
Thanks for your reply. It compiles and works properly using both 1_'00000000' (as I did originally) and just with '00000000' (as I have changed it to now). It would be useful if it generated a compile time error to stop people like me using bad syntax (which may/may not work with other compilers).
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will report this as a bug - thanks. From my experiments, it ignores the 1_ in this context.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sigh - I had forgotten that for character constants, the KIND specifier comes first. So the 1_'00000000' is correct - not a bug.
However, on closer evaluation, the TRANSFER doesn't do what you want it to do, from what I can see. The discussion in comp.lang.fortran is helpful here.
However, on closer evaluation, the TRANSFER doesn't do what you want it to do, from what I can see. The discussion in comp.lang.fortran is helpful here.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page