From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078712011764.tru64-unix-managers.marc@archive.invalid> From: Arno Hahma Date: Fri, 19 Jun 1998 11:24:52 +0000 To: tru64-unix-managers Subject: SUMMARY: Converting endianness on Alpha X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078712011764 Thank you for a huge number of informative responses: Lucio Chiappetti Peter Stern lombardi emanuele Andrew L. Weston David Nicholson Burch Seymour Serge MUNHOVEN Luke Liu Roddy McColl Oisin McGuinness Brian C Hill etc. The problem appeared to be much more complicated than I first thought. First of all, the data to be converted affects how the conversion should be done. If the data type is integral (like int, char, unsigned char, long, etc.), you may be able to use dd with conv=swab. If it is not integral, such as double, float, complex etc. then there are more difficulties and the exact structure of the data to be converted should be known. Possibilities how to do the actual conversion (to convert a binary datafile to Alpha-format): 1. dd conv=swab. This works for short integer type at least (16-bit), might work for others, too. For non-integral data, it does not work. 2. Sex is the answer ;-). /usr/include/sex.h contains macros for doing the conversion by words or by half words. Sex works for integral data only. 3. Fortran program. In DEC fortran, there are conversion specifiers, when reading unformatted binary data. Specify CONV='conversion type' for the OPEN -statement, where the file is used, e.g. OPEN(1,FILE='filename',CONV='conversion',ACCESS='access type') big_endian is one of the conversion types. You can also provide switches to the compiler, say: man f77 and search for "endian". This approach works for non-integral data as well, provided you can read the file with the fortran program. There might be problems with record lengths or data over- or underruns. Whatever, a fortran program is a bit clumsy, if the data is not of equal length in every run. 4. C-language utilities uread and uswap; not included in DU, but available from the Net. These can do a conversion on a variety of formats, even if they are mixed in the file. However, in the case of IEEE big endian double I couldn't get anything sensible out of these. That was probably due to mixed data in the files, i.e. I tried converting data, that is not really valid floating point values. 5. The best one last: There is a nice function provided in the DEC Math library. Say: man cvt_ftof. It can convert a variety of floating point formats and you can choose freely, from which one to which one. This is the way I took, I wrote a short C-program, that reads the big endian data and outputs little-endian using cvt_ftof. It also doesn't care, whether the data is valid or not, so you can run the entire file through cvt_ftof and then extract the valid part out of it afterwards. Just make sure the data is aligned correctly or everything will break. Of course, anything else but the correct floating point data in the file will be trashed from applying cvt_ftof on it. ArNO 2