for l=1:length(x)
x[l] = bswap(x[l])
y[l] = bswap(y[l])
z[l] = bswap(z[l])
end
Am Sonntag, 15. März 2015 11:17:53 UTC+1 schrieb Christian Dengler:
>
> Hello again,
>
> No that did not do the trick, but i managed to compare the julia output to
> a working .vtk file, using a binary reader. The problem with the julia
> output, is that it is written LittleEndian, while paraview needs BigEndian.
> Also the structure must be write(fid, hcat(x[:]', y[:]', z[:]') ), but
> written with BigEndians, which i haven't figured out how to do yet. I tried
> the hton() function, as well as NetworkByteOrder from the docs, but i
> guess i'm applying it wrong. I tried
>
> write(fid, hcat(x[:]', y[:]', z[:]') , NetworkByteOrder) -> NetworkByteOrder
> not defined
> write(fid, hcat(x[:]', y[:]', z[:]') , "NetworkByteOrder") -> writes the
> string to the file, instead of changing endianness
> write(fid, hton(hcat(x[:]', y[:]', z[:]'))) -> ERROR: `bswap` has no
> method matching bswap(::Array{Float64,2})
>
> Any suggestions how to write big endian?
>
>
> Am Samstag, 14. März 2015 20:05:50 UTC+1 schrieb Tobias Knopp:
>>
>> not familiar with the vtk format but are you sure the the x,y,z
>> coordinates lay not directly after each other?
>> Could try:
>>
>> write(fid, vcat(x[:]', y[:]', z[:]') )
>>
>> Am Samstag, 14. März 2015 18:54:59 UTC+1 schrieb Christian Dengler:
>>>
>>> Ty for your answers. I'm not familiar with vtk export on python, and i'm
>>> confident that finding my mistake will be easier than trying to understand
>>> what you did there with pycall.
>>> As for the nrrd code, it seems to be doing exactly what i did. I found
>>> one mistake i did previously though, telling paraview to load float instead
>>> of double values. Now with the function below, paraview loads the files
>>> withoud error message, yet doesnt display anything reasonable, seems that
>>> there is another mistake somewhere, i still assume it to be the "write"
>>> function, where i'm not sure if it does what i want it to.
>>> I'll keep you up to date, should i find my mistake
>>>
>>> function exportVTK(DataMat, NameMat ,filename, dh, Nxyz)
>>>
>>> nx = dh[1]*(Nxyz[1]-1);
>>> ny = dh[2]*(Nxyz[2]-1);
>>> nz = dh[3]*(Nxyz[3]-1);
>>>
>>> x, y, z = ndgrid(0:dh[1]:nx, 0:dh[2]:ny, 0:dh[3]:nz );
>>>
>>> nr_of_elements = length(x);
>>> fid = open(filename, "w");
>>>
>>> #ASCII file header
>>> println(fid, "# vtk DataFile Version 3.0");
>>> println(fid, "VTK from Julia");
>>> println(fid, "BINARY\n");
>>> println(fid, "DATASET STRUCTURED_GRID");
>>> println(fid, "DIMENSIONS $(size(x,1)) $(size(x,2)) $(size(x,3)) ");
>>> println(fid, "POINTS $(nr_of_elements) double");
>>> write(fid, [x[:] y[:] z[:]] )
>>>
>>> #append data
>>> print(fid, "\nPOINT_DATA $(nr_of_elements) \n");
>>>
>>> for i = 1:length(DataMat)
>>>
>>> if size(DataMat[i], 2) == 3
>>> #append a vector
>>> println(fid, "\nVECTORS $(NameMat[i]) double");
>>> elseif size(DataMat[i], 2) == 1
>>> #append a scalar
>>> println(fid, "\nSCALARS $(NameMat[i]) double");
>>> println(fid, "LOOKUP_TABLE default");
>>> else
>>> error("DataMat $i is not a vector or scalar, or not shaped the
>>> way it should be")
>>> end
>>>
>>> write(fid, DataMat[i]);
>>>
>>> end
>>>
>>> close(fid);
>>>
>>> end
>>>
>>>
>>>
>>>
>>>
>>> Am Samstag, 14. März 2015 17:49:50 UTC+1 schrieb Kristoffer Carlsson:
>>>>
>>>> One method that I have used to export VTK from Julia is simply using
>>>> the VTK-library from python and calling it with PyCall.
>>>>
>>>> Something like this:
>>>> https://gist.github.com/KristofferC/9a989a2c0518bb70009c
>>>>
>>>>
>>>>
>>>> On Saturday, March 14, 2015 at 1:41:04 PM UTC+1, Christian Dengler
>>>> wrote:
>>>>>
>>>>> Hello,
>>>>>
>>>>> I'm trying to save my data as .vtk files, and ran into a problem with
>>>>> the "print" and "write" function.
>>>>>
>>>>> Resumee of what would solve my problems:
>>>>> - Using print(filestream, data), but omitting the square brackets, and
>>>>> - using print(filestream, vector), and actually writes the vector, one
>>>>> element per line
>>>>>
>>>>> Does anyone know how this is done?
>>>>>
>>>>> Another way of creating .vtk files using binary data, using the write
>>>>> function, didn't lead to any success, but i cant really say whats wrong,
>>>>> because the files are unreadable. Could it be, that write also somehow
>>>>> includes brackets?
>>>>>
>>>>>
>>>>> For those who want to see my problem in code, i attached a script,
>>>>> creating and saving a simple veocity field as .vtk (ASCII) file.
>>>>> After manually deleting the brackets, atleast the velocity can be
>>>>> imported into paraview.
>>>>> In order to create the binary .vtk file (thats not working at all), i
>>>>> used to replace "ASCII" by "BINARY", and "print" in line 22 and 41 by
>>>>> "write".
>>>>>
>>>>> Greetings,
>>>>> Christian
>>>>>
>>>>