IFrIT understands the following file formats.
- Regular mesh file: uniformly spaced 3-dimensional mesh of
data values.
- Plain ASCII file. This file should have an extension
"txt" (as in "myfile.txt", lower-case or upper-case does not
matter) and should contain in its first
line three integer numbers: the sizes of the mesh in X, Y, and Z
directions. These dimensions do not have to be the same. Each line
after the first one should contain one to three floating point
numbers as values for the physical variables at each cell of the
mesh. The first dimension changes the fastest.
For example, the following file:
12 33 55
1.0456 4.56768 2.45e-30
0.9866 5.45890 3.07e-20
...
(12*33*55+1 lines altogether)
defines a 12 by 33 by 55 data mesh with all three physical
variables defined. If only one or two floating point numbers are supplied
in lines 2 to the last, the rest of physical variable remains
undefined. The following FORTRAN code will create such a file from
three arrays var1(n1,n2,n3), var2(n1,n2,n3), and
var3(n1,n2,n3):
open(unit=1, file='mydata.txt')
write(1,*) n1, n2, n3
do k=1,n3
do j=1,n2
do i=1,n1
write(1,*)
var1(i,j,k), var2(i,j,k), var3(i,j,k)
enddo
enddo
enddo
close(1)
An equivalent C code:
F = fopen("mydata.txt","w");
fprintf(F,"%d %d %d\n",n1,n2,n3);
for(k=0; k<n3; k++) {
for(j=0; j<n2, j++) {
for(i=0; i<n1; i++) {
fprintf(F,"%g %g %g\n", var1[i][j][k], var2[i][j][k], var3[i][j][k]);
}
}
}
fclose(F);
An equivalent IDL code:
openw, 1, 'mydata.txt'
printf, 1, n1, n2, n3
for k=0,n3-1 do $
for j=0,n2-1 do $
for i=0,n1-1 do $
printf, 1, var1[i,j,k], var2[i,j,k], var3[i,j,k]
close, 1
- Binary file. This file should have an extension "bin"
(as in "myfile.bin") and should be a FORTRAN unformatted binary file.
The following FORTRAN code will create such a file from
three arrays var1(n1,n2,n3), var2(n1,n2,n3), and
var3(n1,n2,n3):
open(unit=1, file='mydata.bin', form='unformatted')
write(1) n1, n2, n3
write(1) (((var1(i,j,k),i=1,n1),j=1,n2),k=1,n3)
write(1) (((var2(i,j,k),i=1,n1),j=1,n2),k=1,n3)
write(1) (((var3(i,j,k),i=1,n1),j=1,n2),k=1,n3)
close(1)
An equivalent C code (n1, n2, n3, and
ntemp must be declared as long on a 16-bit
machine and as int on a 32-bit or a 64-bit machine):
F = fopen("mydata.bin","w");
ntemp = 12;
fwrite(&ntemp,4,1,F);
fwrite(&n3,4,1,F);
fwrite(&n2,4,1,F);
fwrite(&n1,4,1,F);
fwrite(&ntemp,4,1,F);
ntemp = 4*n1*n2*n3;
fwrite(&ntemp,4,1,F); fwrite(var1,4,n1*n2*n3,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(var2,4,n1*n2*n3,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(var3,4,n1*n2*n3,F); fwrite(&ntemp,4,1,F);
fclose(F);
(notice that the first and the last dimensions of the arrays are
swapped - FORTRAN and C keep arrays in different order).
An equivalent IDL code:
openw, 1, 'mydata.bin', /F77_UNFORMATTED
writeu, 1, [n1,n2,n3]
writeu, 1, var1
writeu, 1, var2
writeu, 1, var3
close, 1
Statement(s) shown in red statement may be omitted if the second
and/or third
variable are not loaded.
- Particle file: three positions and optional three attributes for
a set of particles.
- Plain ASCII file. This file should have an extension
"txt" (as in "myfile.txt", lower-case or upper-case does not
matter) and should contain in its first
line one integer number: the total number of particles in the
file. The second line should contain 6 numbers that determine how
the particle positions relate to the bounding box. The first three
numbers are X, Y, and Z coordinates of the lower-left-front corner
of the bounding box in the units in which particle coordinates are
given. The last three numbers are X, Y, and Z coordinates of the
upper-right-back corner. For example, if you ran a simulation with
a cubic box of 5 meters in size, and your particle positions are
given in meters, and the left-lower-front corner of your box has
coordinates of (0,0,0) meters, then the second line should be:
Each line after the second one should contain three
floating point numbers as values for the three coordinates for each
particle and, optionally, up to three more numbers as values of
attributes. The attributes can be used to distinguish particles in a
set. For example, the following file:
120
0.0 0.0 0.0 5.0 5.0 5.0
1.0456 4.56768 3.05678 2.45e-30 1.11e+10 0.555
0.9866 5.45890 -2.0568 3.07e-20 2.44e+11 -0.34
...
(120+2 lines altogether)
defines a set of 120 particles with the single attribute field
defined. Notice that the second particle is located outside the
bounding box - there is nothing wrong with that. The following
FORTRAN code will create such a file from six arrays
x(n), y(n), z(n), attr1(n),
attr2(n), attr3(n),
where particles are located in a cubic box with the side of 5.0:
open(unit=1, file='mydata.txt')
write(1,*) n
write(1,*) 0.0, 0.0, 0.0, 5.0, 5.0, 5.0
do i=1,n
write(1,*) x(i), y(i), z(i), attr1(i), attr2(i), attr3(i)
enddo
close(1)
An equivalent C code:
F = fopen("mydata.txt","w");
fprintf(F,"%d\n",n);
fprintf(F,"%g %g %g %g %g %g\n",0.0,0.0,0.0,5.0,5.0,5.0);
for(i=0; i<n; i++) {
fprintf(F,"%g %g %g %g %g %g\n", x[i], y[i], z[i], attr1[i], attr2[i], attr3[i]);
}
fclose(F);
An equivalent IDL code:
openw, 1, 'mydata.txt'
printf, 1, n
printf, 1, 0.0, 0.0, 0.0, 5.0, 5.0, 5.0
for i=0,n-1 do $
printf, 1, x[i], y[i], z[i], attr1[i], attr2[i], attr3[i]
close, 1
- Binary file. This file should have an extension "bin"
(as in "myfile.bin") and should be a FORTRAN unformatted binary file.
The following FORTRAN code will create such a file from
six arrays
x(n), y(n), z(n), attr1(n),
attr2(n), attr3(n),
where particles are located in a cubic box with the side of
BoxLength:
open(unit=1, file='mydata.bin', form='unformatted')
write(1) n
write(1) 0.0, 0.0, 0.0, BoxLength, BoxLength, BoxLength
write(1) (x(i),i=1,n)
write(1) (y(i),i=1,n)
write(1) (z(i),i=1,n)
write(1) (attr1(i),i=1,n)
write(1) (attr2(i),i=1,n)
write(1) (attr3(i),i=1,n)
close(1)
An equivalent C code (n and
ntemp must be declared as long on a 16-bit
machine and as int on a 32-bit or a 64-bit machine,
temp as
float):
F = fopen("mydata.bin","w");
ntemp = 4;
fwrite(&ntemp,4,1,F);
fwrite(&n,4,1,F);
fwrite(&ntemp,4,1,F);
ntemp = 24;
temp = 0.0;
fwrite(&ntemp,4,1,F);
fwrite(&temp,4,1,F);
fwrite(&temp,4,1,F);
fwrite(&temp,4,1,F);
fwrite(&BoxLength,4,1,F);
fwrite(&BoxLength,4,1,F);
fwrite(&BoxLength,4,1,F);
fwrite(&ntemp,4,1,F);
ntemp = 4*n;
fwrite(&ntemp,4,1,F); fwrite(x,4,n,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(y,4,n,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(z,4,n,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(attr1,4,n,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(attr2,4,n,F); fwrite(&ntemp,4,1,F);
fwrite(&ntemp,4,1,F); fwrite(attr3,4,n,F); fwrite(&ntemp,4,1,F);
fclose(F);
An equivalent IDL code:
openw, 1, 'mydata.bin', /F77_UNFORMATTED
writeu, 1, n
writeu, 1, 0.0, 0.0, 0.0, float(BoxLength), float(BoxLength),
float(BoxLength)
writeu, 1, x
writeu, 1, y
writeu, 1, z
writeu, 1, attr1
writeu, 1, attr2
writeu, 1, attr3
close, 1
Statements shown in red statement may be omitted if the attributes
are not needed.
Note #1: Reading binary file is much faster than reading an ASCII
file.
Note #2: For the data file to be read correctly, the endiness of the
data (big endian vs little endian) should be set via Options menu.
Note #3: All three physical variables from a mesh file must
be positive - they are always stretched logarithmically when visualized.
Particles attributes, however, can be both positive or negative, and can be
interactively stretched linearly or logarithmically (there is a button to
switch between the two modes).
|