Table of Contents
bswap - swap bytes in a file
swaps the bytes in a file. This can be useful if the file was copied between
different endian machines (e.g. Sparc-Solaris and pc-linux), and consists of
a homogeneous datatype. (most NEMO files, e.g. those made via filestruct(5NEMO)
are notable example where you cannot use this technique, though NEMO’s binary
files swap on-the-fly if they detect them to be originating from another
This program also has a few keyword to aid benchmarking
file I/O and different sized word swapping speed. The reported speed will
be in Mswaps (mega word swaps per second).
The following parameters
are recognized in any order if the keyword is also given:
careful with pipes, they don’t seem to work on an input file yet.
following example will byte-swap a binary file with only 4-byte data (INTEGER*4,
REAL*4) created using fortran unformatted I/O from the following statement:
- Input file
to read and swap bytes of. No default.
- Output filename for which all
the bytes have been swapped. If no filename given, data will not be written,
and CPU usage will be reported. Default: no output.
- Itemlength in bytes
during swapping . Common are 2, 4 and 8, for which the code is optimized.
Any other (even) number can be handled too though. [Default: 2].
- One swap call? Only useful to set false under benchmark circumstances. [Default:
- Offset (in bytes) before which no swapping is done. [Default:
- If used, the input file will be assumed of this type of endian.
Options are thus ’big’ (e.g. sparc, powerpc) or ’little’ (e.g. i385) endian. Depending
on what kind of machine you are, this could result in a no-operation. By
default this option is not used and swapping is always applied.
- Test swapping data as 8-byte doubles via memcpy. len=8 is required for this
to work. Default:f
- Number of times to repeat swapping
all the words, only good for more accurate benchmarking. Default: 0
REAL x(MAXP), y(MAXP), z(MAXP)
one can see the blocks, and optionally data:
$ unfio junk.dat
$ unfio junk.dat block=1
If this file was created on a machine of which the endianism is reversed
from the machine where it is being read, the unfio would have returned
nothing, it would need to be swapped with len=4:
$ bswap junk.dat junks.dat 4
This above example is a bit contrived, since unfio(1NEMO)
also has a swap=
keyword to read files from the opposite endianism machine.
27-Feb-94 V1.1b Documented PJT
23-feb-97 V1.3 allow offset before swapping starts PJT
15-dec-98 V1.4 add streaming mode to I/O PJT
6-jun-01 more verbosities, plus an example PJT
30-sep-03 V1.5 added memcpy=, repeat= PJT
20-sep-05 V1.6 added endian= PJT
Table of Contents