[Nek5000-users] Reading binary data
nek5000-users at lists.mcs.anl.gov
nek5000-users at lists.mcs.anl.gov
Thu May 6 07:18:03 CDT 2010
Hi Fred,
header: 132 bytes
endian test tag: 4 bytes
element mapping: nel* 4 bytes
data: nfields*nxyz*nel* wdsizo (where wdsizo is 4 or 8 bytes)
metadata (min/max values): nfields*2*nel * 4 bytes
Stefan
On May 6, 2010, at 10:14 AM, nek5000-users at lists.mcs.anl.gov wrote:
> Dear Neks,
>
> I have written a small Matlab function to read in the binary result files. Mostly I understood the structure including the header and the structure of the data. After reading in the data (in my case I only wrote x,y,z,u,v,w,p) there was still some information in the result file. See
> % ???
> for i=1:252
> rest(i)=fread(fid,1,'float');
> end
> in the function. Can you explain me what is this?? I added the Matlab function.
>
> Best , Fred
> function [x,y,z,u,v,w,p,nel1,nmax,time,step] = nek_readbin(file)
> % Function nek_readbin
> %
> % Open *0.f0** binary NEK5000 result file
> % Call: [x,y,z,u,v,w,p,ne,nmax,time,step]=nek_readbin('file')
> %
> % Author: Frederik Folke
> % Date: 06/05/2010
>
> %------------------------------------------------------------------------%
> %clear all
>
> % Read header of ouput-file
> [a,n,nx,ny,nz,nel1,nel2,time,step]=...
> textread(file,'%5c %d %d %d %d %d %d %f %d' ,1);
> %source code from prepost.f
> % write(hdr,1) wdsizo,nxo,nyo,nzo,nelo,nelgt,time,istep,fid0,nfileoo
> % $ , (rdcode1(i),i=1,10) ! 74+20=94
> %1 format('#std',1x,i1,1x,i2,1x,i2,1x,i2,1x,i10,1x,i10,1x,e20.13,
> % $ 1x,i9,1x,i6,1x,i6,1x,10a)
> clear a;
>
> %------------------------------------------------------------------------%
> % Open result file and skip header
> fid=fopen(file)
> for i=1:52
> bin(i)=fread(fid,1,'int');
> end
>
> nmax=(nx*ny*nz);
>
> % Initialize x,y,z,u,v,w,p
> x2=zeros(nmax*nel1,1);
> y2=zeros(nmax*nel1,1);
> z2=zeros(nmax*nel1,1);
> u2=zeros(nmax*nel1,1);
> v2=zeros(nmax*nel1,1);
> w2=zeros(nmax*nel1,1);
> p2=zeros(nmax*nel1,1);
>
> % Read data (here: x,y,z,u,v,w,p)
> k=0;
> l=0;
> m=0;
> for i=1:nel1 %maybe nel2??
> for j=1:nmax
> k=k+1;
> x2(k)=fread(fid,1,'float');
> end
> for j=1:nmax
> l=l+1;
> y2(l)=fread(fid,1,'float');
> end
> for j=1:nmax
> m=m+1;
> z2(m)=fread(fid,1,'float');
> end
> end
>
>
> k=0;
> l=0;
> m=0;
> n=0;
> for i=1:nel1 %maybe nel2??
> for j=1:nmax
> k=k+1;
> u2(k)=fread(fid,1,'float');
> end
> for j=1:nmax
> l=l+1;
> v2(l)=fread(fid,1,'float');
> end
> for j=1:nmax
> m=m+1;
> w2(m)=fread(fid,1,'float');
> end
> end
>
> k=0;
> for i=1:nel1 %maybe nel2??
> for j=1:nmax
> k=k+1;
> p2(k)=fread(fid,1,'float');
> end
> end
>
> % ???
> for i=1:252
> rest(i)=fread(fid,1,'float');
> end
>
> fclose('all');
>
> end_______________________________________________
> Nek5000-users mailing list
> Nek5000-users at lists.mcs.anl.gov
> https://lists.mcs.anl.gov/mailman/listinfo/nek5000-users
More information about the Nek5000-users
mailing list