PLUTO
pload.m
Go to the documentation of this file.
1 (* ****************************************************************
2  pload.m
3  Provide basic capabilities to read PLUTO binary files
4 
5  Last Modified: Jan 23, 2013
6  Author: A. Mignone (mignone@ph.unito.it)
7  **************************************************************** *)
8 
9 readFloatMatrix[fileName_,nx_,ny_,nv_,type_] := Module[{file, obj},
10  file = OpenRead[fileName, BinaryFormat -> True];
11  If [type == 4, obj = BinaryReadList[file, "Real32", nx*ny*nv]];
12  If [type == 8, obj = BinaryReadList[file, "Real64", nx*ny*nv]];
13  Close[file];
14  Partition[Partition[obj, nx],ny]
15  ]
16 
17 (* *******************************************************
18  Read Grid information from grid.out
19  ******************************************************* *)
20 
21 file = OpenRead["grid.out"];
22 For[i=1, i < 10, i++,
23  {str=Read[file,String],
24  If[UnsameQ[StringTake[str,1],"#"], Break[]]
25  }];
26 
27 nx = Read[file,Number];
28 xgrid = Partition[ReadList[file,Number,nx*3],3];
29 
30 ny = Read[file,Number];
31 ygrid = Partition[ReadList[file,Number,ny*3],3];
32 
33 Close[file]
34 
35 (* *******************************************************
36  Read .out file and get various information
37  ******************************************************* *)
38 
39 nout = Input["Enter output number"]
40 type = Input["Enter precision type (4 = real/8 = double)"]
41 
42 If [type == 4, {file = OpenRead["flt.out"], suf = ".flt"} ]
43 If [type == 8, {file = OpenRead["dbl.out"], suf = ".dbl"} ]
44 
45 For[i=0, i <= nout, i++, {str=Read[file,String]}];
46 Close[file]
47 
48 strlist = StringSplit[str]
49 t = strlist[[2]]
50 dt = strlist[[3]]
51 mode = strlist[[5]]
52 
53 n = Length[strlist]
54 nvar = n-6
55 Print["Sim. time: "<>ToString[t]]
56 Print["Grid size: "<>ToString[nx]<>" x "<>ToString[ny]]
57 Print["File mode: "<>mode]
58 Print["Variables: "<>ToString[nvar]]
59 For[i=7, i <= n, i++,
60  {name = strlist[[i]];
61  Print[ToString[i-6]<>" -> "<>strlist[[i]]];
62  }
63 ];
64 
65 varnames = strlist[[7;;n]]
66 
67 (* *******************************************************
68  Set file name(s) and read data
69  ******************************************************* *)
70 
71 If [mode === "single_file",
72  If [nout < 10, fname = "data.000"<>ToString[nout]<>suf,
73  If [nout < 100, fname = "data.00"<>ToString[nout]<>suf,
74  If [nout < 1000, fname = "data.0"<>ToString[nout]<>suf,
75  If [nout < 1000, fname = "data."<>ToString[nout]<>suf];
76  ];
77  ];
78  ];
79  data = readFloatMatrix[fname,nx,ny,nvar,type];
80 ];
81 
82 
83 If [mode === "multiple_files",
84  data = {};
85  For[n=1, n <= nvar, n++,
86  {If [nout < 10, fname = ".000"<>ToString[nout]<>suf,
87  If [nout < 100, fname = ".00"<>ToString[nout]<>suf,
88  If [nout < 1000, fname = ".0"<>ToString[nout]<>suf,
89  If [nout < 1000, fname = "."<>ToString[nout]<>suf];
90  ];
91  ];
92  ];
93  fname = varnames[[n]]<>fname;
94  Print[fname];
95  data = Join[data,readFloatMatrix[fname,nx,ny,1,type]];
96  };
97  ];
98 ]
99 
100 
101 (* ** Pload binary data ** *)
102 (*
103 xmin = 0.5*(xgrid[[ 1,2]] + xgrid[[ 1,3]])
104 xmax = 0.5*(xgrid[[nx,2]] + xgrid[[nx,3]])
105 
106 ymin = 0.5*(ygrid[[ 1,2]] + ygrid[[ 1,3]])
107 ymax = 0.5*(ygrid[[ny,2]] + ygrid[[ny,3]])
108 *)
109 xmin = xgrid[[1,2]]
110 xmax = xgrid[[nx,3]]
111 
112 ymin = ygrid[[1,2]]
113 ymax = ygrid[[ny,3]]
114 
115 nv = Input["Enter variable to plot"]
116 
117 ArrayPlot[data[[nv]], ColorFunction -> "Rainbow",
118  DataReversed -> True,
119  DataRange -> {{xmin,xmax},{ymin,ymax}},
120  Frame -> True, FrameTicks -> Automatic]
121 
122 (* the following should plot a vertical cut along y at i = 40 of rho
123 ListPlot[data[[1, 1 ;; ny, 40]]]
124 *)
125 
126 
127 (* the following should plot a horizontal cut along x at j = 20 of vx
128 ListPlot[data[[2,20]]]
129 *)
130 
static double a
Definition: init.c:135
static int n
Definition: analysis.c:3
def read(fname)
Definition: file.py:29
Definition: structs.h:78
def Print
Print a message on the screen.
Definition: menu.py:60
int j
Definition: analysis.c:2
(*****************************************************************)(*xmin=0.5 *(xgrid[[1, 2]]+xgrid[[1, 3]]) xmax=0.5 *(xgrid[[nx, 2]]+xgrid[[nx, 3]]) ymin=0.5 *(ygrid[[1, 2]]+ygrid[[1, 3]]) ymax=0.5 *(ygrid[[ny, 2]]+ygrid[[ny, 3]])*) pload(mignone @ph.unito.it) *****************************************************************) readFloatMatrix[fileName_, nx_, ny_, nv_, type_]:=Module[{file, obj}, file=OpenRead[fileName, BinaryFormat-> True];If[type==4, obj=BinaryReadList[file,"Real32", nx *ny *nv]];If[type==8, obj=BinaryReadList[file,"Real64", nx *ny *nv]];Close[file];Partition[Partition[obj, nx], ny]](******************************************************** Read Grid information from grid.out ********************************************************) file=OpenRead["grid.out"];For[i=1, i< 10, i++, {str=Read[file, String], If[UnsameQ[StringTake[str, 1],"#"], Break[]] }]; nx =Read[file, Number];xgrid=Partition[ReadList[file, Number, nx *3], 3];ny =Read[file, Number];ygrid=Partition[ReadList[file, Number, ny *3], 3];Close[file](******************************************************** Read.out file and get various information ********************************************************) nout=Input["Enter output number"]type=Input["Enter precision type (4 = real/8 = double)"]If[type==4,{file=OpenRead["flt.out"], suf=".flt"}]If[type==8,{file=OpenRead["dbl.out"], suf=".dbl"}]For[i=0, i<=nout, i++,{str=Read[file, String]}];Close[file]strlist=StringSplit[str]t =strlist[[2]]dt =strlist[[3]]mode =strlist[[5]]n =Length[strlist]nvar=n-6Print["Sim. time: "<>ToString[t]]Print["Grid size: "<>ToString[nx]<>" x "<>ToString[ny]]Print["File mode: "<>mode]Print["Variables: "<>ToString[nvar]]For[i=7, i<=n, i++, {name=strlist[[i]]; Print[ToString[i-6]<>" -> "<>strlist[[i]]]; }];varnames=strlist[[7;;n]](******************************************************** Set file name(s) and read data ********************************************************) If[mode==="single_file", If[nout< 10, fname="data.000"<>ToString[nout]<>suf, If[nout< 100, fname="data.00"<>ToString[nout]<>suf, If[nout< 1000, fname="data.0"<>ToString[nout]<>suf, If[nout< 1000, fname="data."<>ToString[nout]<>suf]; ]; ];];data=readFloatMatrix[fname, nx, ny, nvar, type];];If[mode==="multiple_files", data={};For[n=1, n<=nvar, n++, {If[nout< 10, fname=".000"<>ToString[nout]<>suf, If[nout< 100, fname=".00"<>ToString[nout]<>suf, If[nout< 1000, fname=".0"<>ToString[nout]<>suf, If[nout< 1000, fname="."<>ToString[nout]<>suf]; ]; ]; ]; fname=varnames[[n]]<>fname; Print[fname]; data=Join[data, readFloatMatrix[fname, nx, ny, 1, type]]; };];](***Pload binary data ***
Definition: pload.m:6
#define s
int i
Definition: analysis.c:2
Definition: file.py:1