Matlab data to .k file
Show older comments
clear;
filename='plate.k';
global preprocessor_type passive0 passive1 curved_extrusion extrusion_type
preprocessor_type=1
fid = fopen(filename, 'rt');
load nodetable.mat
if(fid == -1) disp('Error: Model file does not exist.')
x=[]; error=1; eltsize=0;
return;
end % if file does not exist or is empty, exit
n=1;
%temp_nodetable=zeros(400000,4);
tline = fgetl(fid);
str1=['k'];
%filename = ['/input.k'];
%filename = ['k',num2str,'/input.k'];
fid = fopen(filename, 'rt');
tline = fgetl(fid);
% str1=['iter_',num2str(ITER)];mkdir(str1);
filename_out = ['k','/input.k'];
filename_in = ['k','/input.k'];
fid_in = fopen(filename_in, 'rt');
fid_out = fopen(filename_out, 'wt');
%tline = fgetl(fid_in);
while( feof(fid_in) == 0 && ( ~strcmp(tline,'*END') || ~strcmp(tline(1:4),'*END')))
findstring1='*NODE';
flag1 = strcmp(strtrim(tline),findstring1);
if flag1 > 0
fprintf(fid_out,[tline '\n']);
tline = fgetl(fid_in);
for j=1:(n-1);
fprintf(fid_out,'%8g%16g%16g%16g%8g%8g',nodetable(j,:));fprintf(fid_out,'\n');
end
while(~isempty(tline) && ~strcmp(tline(1),'*'))
tline = fgetl(fid_in);
end
else
fprintf(fid_out,[tline '\n']);tline = fgetl(fid_in);
end
end
fprintf(fid_out,'\n');
fclose('all');
cd ..
I have this code to insert my data in nodetable in a .k file format to read in LS-Dyna. Please let me know where i am going wrong. Thanks.
2 Comments
Walter Roberson
on 24 Apr 2012
What problem are you encountering? Is there an error message?
Sven
on 9 Jul 2012
"Please let me know where i am going wrong"
Yep, I think the problem you're having is that you're not describing the problem you're having.
Dyna decks are tricky to work with but here are a couple of suggestions:
- Test your deck-writer with a small file (~20 nodes)... I bet the 10 seconds saved by not having to scroll to the *NODE card each time you make a change will outweigh the 5 minutes it will take to make a test file.
- I see some of your previous questions about lining up coordinates over 16 characters. Remember that with dyna you can also just separate lists (node x,y,z, element node #s) with a comma (,). It doesn't look as pretty to read for a human, but it's easier to code and can even save file size if you're working with massive meshes.
Answers (0)
Categories
Find more on Software Development in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!