This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: u9i4tDogT25lIHF1ZXN0aW9u


>  Excuse for my poor expression, my question in detail:

Indeed, as often:  The more detail, the better ;-)

>  I have to run a fortran program under linux OS, but this
>  program works originally on the workstation like SGI or
>  HP etc, so I have to transplant it to my Pentium-II@266MHZ
>  PC, but this program requires some data files as input,
>  these data files are also from workstation, I have
>  examined one of them using Norton diskedit under DOS, I
>  found e.g. a decimal integer like 4 has been expressed
>  in hex 00 00 00 04 in the datafile, but on PC datafile
>  it is always expressed in hex 04 00 00 00, so I wonder
>  if this is a big difference between workstation datafile
>  and PC's , there is a fortran compiler called PGF77
>  running under linux could deal with this difference just
>  using an option -byteswapio on the command line, but I
>  can't get this kind fortran compiler due to some reasons,
>  then could I solve this problem using egcs_g77 fortran
>  compiler ...

Yep, all of these are correct observations, up to and including  
that g77 doesn't have a flag to do this for you.  From your example  
I get the impression that it is a sequential, unformatted file.   
Now, if you are sure the file consists only of 32-bit REALs, you  
could try the following program to convert it to the other  
endianness (works both ways):

      PROGRAM CONVRT
      INTEGER N1, N2
      OPEN(1,FORM='UNFORMATTED',ACCESS='DIRECT',RECL=4)
      OPEN(2,FORM='UNFORMATTED',ACCESS='DIRECT',RECL=4)
      I = 1
  10  READ(1,REC=I,ERR=20) N1
      N2 = N1 / 2**24 + MOD(N1 / 2**16, 2**8) * 2**8 +
     +   MOD(N1 / 2**8, 2**8) * 2**16 + MOD(N1, 2**8) * 2**24
      WRITE(2,REC=I) N2
      I = I + 1
      GOTO 10
  20  CLOSE(1)
      CLOSE(2)
      END

compile this with g77, and type:

% ln -s infile fort.1
% ln -s outfile fort.2
% ./a.out
% rm fort.[12]

where infile is the file you want to convert and outfile the file  
you want to produce.

Hope this helps,
Toon.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]