! +-======-+ ! Copyright (c) 2003-2007 United States Government as represented by ! the Admistrator of the National Aeronautics and Space Administration. ! All Rights Reserved. ! ! THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE, ! REPRODUCTION, DISTRIBUTION, MODIFICATION AND REDISTRIBUTION OF CERTAIN ! COMPUTER SOFTWARE ORIGINALLY RELEASED BY THE UNITED STATES GOVERNMENT AS ! REPRESENTED BY THE GOVERNMENT AGENCY LISTED BELOW ("GOVERNMENT AGENCY"). ! THE UNITED STATES GOVERNMENT, AS REPRESENTED BY GOVERNMENT AGENCY, IS AN ! INTENDED THIRD-PARTY BENEFICIARY OF ALL SUBSEQUENT DISTRIBUTIONS OR ! REDISTRIBUTIONS OF THE SUBJECT SOFTWARE. ANYONE WHO USES, REPRODUCES, ! DISTRIBUTES, MODIFIES OR REDISTRIBUTES THE SUBJECT SOFTWARE, AS DEFINED ! HEREIN, OR ANY PART THEREOF, IS, BY THAT ACTION, ACCEPTING IN FULL THE ! RESPONSIBILITIES AND OBLIGATIONS CONTAINED IN THIS AGREEMENT. ! ! Government Agency: National Aeronautics and Space Administration ! Government Agency Original Software Designation: GSC-15354-1 ! Government Agency Original Software Title: GEOS-5 GCM Modeling Software ! User Registration Requested. Please Visit http://opensource.gsfc.nasa.gov ! Government Agency Point of Contact for Original Software: ! Dale Hithon, SRA Assistant, (301) 286-2691 ! ! +-======-+ program endian_convert implicit none real, pointer :: var(:) integer :: i, bpos, epos, status integer :: rsize character(128) :: str, f_in, f_out integer*4 :: ftell external :: ftell integer*4 :: iargc external :: iargc ! Begin if (iargc() /= 2) then call getarg(0,str) write(*,*) "Usage:",trim(str)," " call exit(2) end if call getarg(1,f_in) call getarg(2,f_out) open(unit=10, file=trim(f_in), form='unformatted', convert="big_endian") open(unit=20, file=trim(f_out), form='unformatted', convert="native") print *,'Converting File: ',trim(f_in) bpos=0 do read(10, end=100, err=200) ! skip to next record epos = ftell(10) ! ending position of file pointer backspace(10) rsize = (epos-bpos)/4-2 ! record size (in 4 byte words; ! 2 is the number of fortran control words) bpos=epos allocate(var(rsize), stat=status) if (status /= 0) then print *, 'Error: allocation ', rsize, ' failed!' call exit(11) end if read (10) var write(20) var deallocate(var) end do 100 continue close(10) close(20) stop 200 print *,'Error reading file ',trim(f_in) call exit(11) end