If those files were written by another compiler, then there is no real standard for unformatted binary files and the form of the record length part of each line changes for lines of length less or greater than 256 characters.
Try using this program on the .dat files:
winapp
! convert an unformatted binary file to the FTN95 format
integer*1 input(65536),work(65536*2),ibyte_long(4)
INTEGER*2 handle_in,handle_out, error_code,itest_ffh
integer*4 i,iwork_pointer,iwork_end,irec_len, ilong, nline,imove, ilen_extra, itransfer_4bytes, nbytes_read
equivalence (ibyte_long,ilong)
iwork_pointer = 1
iwork_end = 0
itest_ffh = -1 !-1 as a single byte is ffh the code for a long record
irec_len = 0
call openr@('otherftnformattedlong.dat',handle_in,error_code)
call openw@('ftn95formattedlong_new.dat',handle_out,error_code)
nline = 0
do
call READF@(input, handle_in, 65536L, nbytes_read, error_code)
if(nbytes_read .eq. 0)goto 9999
nline = nline + 1
print *,nline,nbytes_read,error_code
!move previously handled work to the start of the work buffer
imove = 0
do i=iwork_pointer,iwork_end
imove = imove + 1
work(imove) = work(i)
enddo
iwork_pointer = 1
iwork_end = imove
!move the input line to the work
do i=1,nbytes_read
imove = imove + 1
work(imove) = input(i)
enddo
iwork_end = imove
!
! now process the next chunk from iwork_pointer to iwork_end
do while (iwork_pointer .lt. iwork_end)
!get the 4 byte record length
irec_len = itransfer_4bytes(work(iwork_pointer))
iwork_pointer = iwork_pointer + 4
ilen_extra = 4
print *,'irec_len',irec_len,ilen_extra
!process record to output data here
!if the record length is less than 255 long, then output a single byte
! record length
if(irec_len .lt. 255)then
ilong = irec_len
call WRITEF@(ibyte_long,handle_out, 1L, error_code)
call WRITEF@(work(iwork_pointer),handle_out, irec_len, error_code)
call WRITEF@(ibyte_long,handle_out, 1L, error_code)
else
! prefix with record length as ffh + a 4 byte integer
call WRITEF@(itest_ffh,handle_out, 1L, error_code)
call WRITEF@(irec_len,handle_out, 4L, error_code)
!output the data
call WRITEF@(work(iwork_pointer),handle_out, irec_len, error_code)
! postfix with record length as a 4 byte integer + ffH
call WRITEF@(irec_len,handle_out, 4L, error_code)
call WRITEF@(itest_ffh,handle_out, 1L, error_code)
endif
! now advance to the next record start
iwork_pointer = iwork_pointer + irec_len + ilen_extra
print*,'next iwork_pointer',iwork_pointer
enddo
enddo
9999 continue
call CLOSEF@(handle_in, error_code)
call CLOSEF@(handle_out, error_code)
print *,nline
end
integer*4 function itransfer_4bytes(idata1)
integer*1 idata1(4),jdata1(4)
integer*4 jdata4,i
equivalence (jdata1,jdata4)
do i=1,4
jdata1(i) = idata1(i)
print '(z2.2)',jdata1(i)
enddo
itransfer_4bytes = jdata4
print '(z8.8)',jdata4
end