Richard Rublev
Richard Rublev

Reputation: 8162

FORTRAN unformatted output

I have already posted here,but now I have changed my code

program v10

implicit none

real :: xmin,xmax,ymin,ymax,zmin,zmax,size
integer :: nx,ny,nz,i,j,nodestotal,irec
real,dimension(15025)    :: v
integer,dimension(15025) :: v1

open(unit=34, file='for.header', status='old')
read(34,115) xmin,xmax,ymin,ymax,zmin,zmax,size,nx,ny,nz
115   format(7f10.3,3i10)

open(unit=35, file='vel.txt', status='unknown')
read(35,*)v
v1=nint(v)

inquire (iolength = irec) v1(1)
open (36, file="lia2", form="unformatted", access="direct", recl=2*irec)
do i=1,15025
    write(36, rec=i) v1(i)
end do

end

I have compiled with gfortran on Ubuntu 16.04. When I dump the binary output I got

0000000        5000           0        5000           0
*
0011300        5000           0        5350           0
0011320        5350           0        5350           0
*
0022620        5700           0        5700           0
*
0034120        5700           0        5727           0
0034140        5727           0        5727           0
*
0045440        5755           0        5755           0
*
0056740        5755           0        5783           0
0056760        5783           0        5783           0
*
0070260        5811           0        5811           0
*
0101560        5811           0        5838           0
0101600        5838           0        5838           0
*
0113100        5866           0        5866           0
*
0124400        5866           0        5894           0
0124420        5894           0        5894           0
*
0135720        5922           0        5922           0
*
0147220        5922           0        5950           0
0147240        5950           0        5950           0
*
0160540        5977           0        5977           0
*
0172040        5977           0        6005           0
0172060        6005           0        6005           0
*
0203360        6033           0        6033           0
*
0214660        6033           0        6061           0
0214700        6061           0        6061           0
*
0226200        6088           0        6088           0
*
0237500        6088           0        6116           0
0237520        6116           0        6116           0
*
0251020        6144           0        6144           0
*
0262320        6144           0        6172           0
0262340        6172           0        6172           0
*
0273640        6200           0        6200           0
*
0352600        6200           0
0352610

vel.txt is pasted http://pastebin.com/D1dM8e91

Why do I have these zeros inserted?

Upvotes: 1

Views: 90

Answers (1)

It is because

recl=2*irec

I can't see any reason whatsoever for the 2*, it should be just irec.

Explanation:

inquire (iolength = irec) v1(1)

asks how large is a record with one element of v1, recl=2*irec sets file records to be two times of that. Your records can hold two numbers and you write always only one number

write(36, rec=i) v1(i)

Upvotes: 2

Related Questions