Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

legal use of transfer?

andrew_s
Beginner
632 Views
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
0 Kudos
4 Replies
Steven_L_Intel1
Employee
632 Views
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.
0 Kudos
andrew_s
Beginner
632 Views
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
0 Kudos
Steven_L_Intel1
Employee
632 Views
I will report this as a bug - thanks. From my experiments, it ignores the 1_ in this context.
0 Kudos
Steven_L_Intel1
Employee
632 Views
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.
0 Kudos
Reply