Hi,
First, Fortran does not have an unsigned type. Thus, in general,
you can't do this in Fortran, at least in any straightforward
way. The good news is that any unsigned that overflows an int
will come out as a negative number when read into a signed int,
so you can at least know whether you have this problem; if you
do, you can probably handle it with difficulty by understanding
the bit pattern.
Also, I suppose that your F90 compiler could have a signed int
KIND large enough to hold the positive values of the unsigned
ints that form the file.
Second, the Fortran standard does not provide for reading a
"raw" binary file, though most compilers provide extensions
for this. Fortran unformatted IO is usually expected to
read/write some format peculiar to the compiler and/or the OS.
Bottom line: never say never, but here's a case where I think
the right answer really is, "Do it in C."
-P.
On Mon, 10 Apr 2000, AGP wrote:
> I have been programming in F90 and F95 on a win98 machine
> and I have been given the task of extracting data from
> a binary file into ASCII. I consider myself a good programmer
> but this is a bit above my head. The binary file is described
> as "data as a binary integer array (PC byte-ordered) with
> 10800 columns (e-w) by 6000 or 4800 rows (n-s)....the data
> are also unsigned integers".
> How would I use FORTRAN to extract the binary into an ASCII text file.
> Any guidance is appreciated.
> tia
> AGP
>
>
>
--
** Whether the playing field is level depends on the coordinate system. ***
********* Peter S. Shenkin; Schrodinger, Inc.; (201)433-2014 x111 *********
*********** [log in to unmask]; http://www.schrodinger.com ***********
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|