C**** swap.f ; to compile: f77 swap.f (or: f90 swap.f) C**** C**** Converts big_endian to little_endian byte arrangement C**** for the 3 basic gistemp input files C**** parameter (monmx=12*(2200-1700)) integer info(8) real tin(monmx) character*4 infoc(8),tinc(monmx) equivalence (infoc(1),info(1)),(tin(1),tinc(1)) character*80 title write(*,*) 'rename (link) your file to DAT' write(*,*) 'the converted file will be DAT_REV' c**** Try assuming rec.lengths are measured in 4-byte words open(8,file='DAT',form='unformatted',access='direct',recl=1) read(8,rec=1,err=10) len go to 20 c**** if the section above leads to a crash, delete it c**** looks like, rec.lengths are measured in bytes 10 close (8) open(8,file='DAT',form='unformatted',access='direct',recl=4) read(8,rec=1) len 20 if(len.eq.112) stop 'data already big_endian' c**** just to make sure: read(8,rec=30) len1 if(len.ne.len1) then ! let's hope we did not yet try recl=4 close (8) open(8,file='DAT',form='unformatted',access='direct',recl=4) end if C**** C**** Read, convert, and save the header record C**** !! read(8) info,title !! but do it word by word do n=2,9 read(8,rec=n) info(n-1) end do call swap_bytes_4 (infoc,8) do n=10,29 read(8,rec=n) title(1+4*(n-10):4+4*(n-10)) end do nr=30+2 open(9,file='DAT_REV',form='unformatted',access='sequential') write(9) info,title Mnow=info(1) ! length of first data record (months) C**** C**** Loop over subboxes - read, convert, save C**** do n=1,8000 C**** Read in time series TIN/TINO of monthly means: land/Ocean data call sread (8,tin(1),tinc(1),Mnow,next,nr) Mnow=next ! Mnow/next: length of current/next time series end do stop end SUBROUTINE SREAD (NDISK,A,ac,LEN, LNEXT,nr) real A(LEN),dstn character*4 ac(len),dstnc,nsc(6) integer ns(6) equivalence (dstn,dstnc),(ns,nsc) !! READ(NDISK) LNEXT, NS, DSTN, A read(ndisk,rec=nr) lnext do n=1,6 read(ndisk,rec=nr+n) ns(n) end do read(ndisk,rec=nr+7) dstn nr=nr+8 do n=1,len read(ndisk,rec=nr) a(n) nr=nr+1 end do nr=nr+2 ! skip over record end and beg. markers call swap_bytes_4 (lnext,1) call swap_bytes_4 (nsc,6) call swap_bytes_4 (dstnc,1) call swap_bytes_4 (ac,len) write(9) LNEXT, NS, DSTN, A return end subroutine swap_bytes_4( c, ndim ) integer n,ndim character*1 c(4,ndim),temp C**** Reverses bytes in array c (integer or real*4) with ndim elements do n=1,ndim temp = c(1,n) c(1,n) = c(4,n) c(4,n) = temp temp = c(2,n) c(2,n) = c(3,n) c(3,n) = temp end do return end