Matlab to Tecplot

Creating Tecplot binary data files

Moderators: davetaflin, salter, steve, jprenaud, straton, Chris Idso

chrisb
Newbie
Posts: 3
Joined: Thu Oct 29, 2009 3:37 pm
Location: Melbourne, Australia
Contact:

Matlab to Tecplot

Postby chrisb » Thu Oct 29, 2009 3:44 pm

Hello,
I have written a MATLAB function to directly write to the Tecplot data format. I am having trouble with the Parent zone variable. The data itself is a standalone set on an ordered two dimensional grid. Therefore from my understanding there is no parent zone (single zone in the file) consequently ParentZone = 0;

Assigning zero to the parent zone variable causes the following error:
Parent zone assignment for zone 1 may not be self referencing.

Any help would be appreciated.

User avatar
Scott Rumage
Tecplot Employee
Posts: 45
Joined: Mon Nov 20, 2006 2:28 pm
Location: Seattle
Contact:

Re: Matlab to Tecplot

Postby Scott Rumage » Tue Nov 03, 2009 3:55 pm

Hi Chris,

A parent zone value of 0 does indicate that the zone has no parent. It appears from the error message, that the parent zone for zone 1 is actually being set to 1. If Fortran is being used, is there a chance a 1-based value is being used instead of a 0-based value?

Scott

chrisb
Newbie
Posts: 3
Joined: Thu Oct 29, 2009 3:37 pm
Location: Melbourne, Australia
Contact:

Re: Matlab to Tecplot

Postby chrisb » Tue Dec 15, 2009 2:19 pm

Hi Scott,
Sorry about the delayed reply I have only just had time to finish the routine. I managed to get the function up and running, by assigning a "-1" value. I am assuming when you meant "1-based value" you where referring to the array indices. However, you can see from the code below that a scalar "-1" value is assigned.

It turned out (as it usually does) that most of the problem isolating this issue was related to another missing variable.

Chris

Code: Select all

%% mat_to_plt
% This function takes two dimensional ordered data and creates a tecplot
% file mesh.

% X,Y are x-y coordinates as output from the meshgrid function such that
% surf(X,Y,contour) will produce a plot using matlab functions

%%
function [] = mat_to_plt(X,Y,contour,file_name,title)
% open file
fid_out = fopen(file_name,'w');
% Comments following match as closely as possible those in tecplot binary
% data format
% HEADER SECTION
% i. magic number
magic_number = '#!TDV112';
char_hold = char(magic_number);
l_max = max(size(char_hold));
for ii =1:1:l_max
    fwrite(fid_out,char_hold(ii),'char');
end

% ii. Integer value of 1.
dummy_int32 = 1;
fwrite(fid_out,dummy_int32,'int32');
% iii. Title and variable names.
% filetype
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% write title and terminate with a null char
char_hold = int32(title);
l_max = max(size(char_hold));
for ii =1:1:l_max
    fwrite(fid_out,char_hold(ii),'int32');
end
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% Number of variables
% at this stage fixed
% lets hope this is what we need to do
dummy_int32 = 3;
fwrite(fid_out,dummy_int32,'int32');
%variable names just give 3 names
x_name = 'x';
y_name = 'y';
contour_name = 'value';

char_hold = int32(x_name);
l_max = max(size(char_hold));
for ii =1:1:l_max
    fwrite(fid_out,char_hold(ii),'int32');
end
dummy_int32 =0;
fwrite(fid_out,dummy_int32,'int32');

char_hold = int32(y_name);
l_max = max(size(char_hold));
for ii =1:1:l_max
    fwrite(fid_out,char_hold(ii),'int32');
end
dummy_int32 =0;
fwrite(fid_out,dummy_int32,'int32');

char_hold = int32(contour_name);
l_max = max(size(char_hold));
for ii =1:1:l_max
    fwrite(fid_out,char_hold(ii),'int32');
end
dummy_int32 =0;
fwrite(fid_out,dummy_int32,'int32');

% iv. Zones
% write zone marker float32 = 299.0
dummy_float32 = single(299.0);
fwrite(fid_out,dummy_float32,'float32');

% write zone name 'data zone' and nul
zone_name = 'Data zone';
char_hold = int32(zone_name);
l_max = max(size(char_hold));
for x =1:1:l_max
    fwrite(fid_out,char_hold(x),'int32');
end
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% parent zone = 0 (no parent zone) int32
dummy_int32 = -1;
fwrite(fid_out,dummy_int32,'int32');

% strand ID suggested as zero from old calls
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% solution time
dummy_float64 = pi;
fwrite(fid_out,dummy_float64,'float64');

% not used set to -1 (int32)
dummy_int32 = -1;
fwrite(fid_out,dummy_int32,'int32');

% zone type (ordered = 0)
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% var location (0 = all data at nodal points)
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% are raw local 1-to-1 face neighbors supplied (must be false for ordered)
% flase = 0 (int32)
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% No. of miscellaneous user defined face neighbor connections
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% ordered zone var 3 int32s for num points i -j -k
[Imax,Jmax] =size(X);
Kmax = 1;

fwrite(fid_out,Imax,'int32');
fwrite(fid_out,Jmax,'int32');
fwrite(fid_out,Kmax,'int32');

% No auxilary data pairs
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% v. Geometries ???
% looks like we can get away without it

% EOH MARKER
dummy_float32 = single(357.0);
fwrite(fid_out,dummy_float32,'float32')

% II. DATA SECTION
% i for both ordered and fe
% zone marker = 299.0
dummy_float32 = single(299.0);
fwrite(fid_out,dummy_float32,'float32')
% specify data format for plt file 64 bit floats for each var int32 = 2 per
% var
dummy_int32 = 2;

fwrite(fid_out,dummy_int32,'int32');
fwrite(fid_out,dummy_int32,'int32');
fwrite(fid_out,dummy_int32,'int32');

% no passive variables
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% no variable sharing
dummy_int32 = 0;
fwrite(fid_out,dummy_int32,'int32');

% zone number to share connectivity with
dummy_int32 = -1;
fwrite(fid_out,dummy_int32,'int32');

% data



% write data in the right order
% reshape matrices
X = reshape(X,1,(Imax*Jmax));
Y = reshape(Y,1,(Imax*Jmax));
contour = reshape(contour,1,(Imax*Jmax));

% get data minima and maxima after reshape to call min max once per set
min_X = min(X);
max_X = max(X);
min_Y = min(Y);
max_Y = max(Y);
min_C = min(contour);
max_C = max(contour);

% write min/max
fwrite(fid_out,min_X,'float64');
fwrite(fid_out,max_X,'float64');
fwrite(fid_out,min_Y,'float64');
fwrite(fid_out,max_Y,'float64');
fwrite(fid_out,min_C,'float64');
fwrite(fid_out,max_C,'float64');
% write data
fwrite(fid_out,X,'float64');
fwrite(fid_out,Y,'float64');
fwrite(fid_out,contour,'float64');

% ii. specific to ordered
    % null as misc user def connections = 0

% iii. specific to fe therefore not generated

% end of file

fclose(fid_out)

return


Return to “TecIO Library”

Who is online

Users browsing this forum: No registered users and 2 guests