Programma matlab: BDF_P_changer.m
%---%
% MAIN PROG: %
%---%
%Crea il .bdf della griglia modificata partendo dal .bdf originale e dal
%report creato direttamente da Patran, in cui si deve esplicitare di
%plottare le posizioni originali e gli spostamenti dei nodi.
% Construct a questdlg with options
choice = questdlg('Nel BDF è già stato caricato il campo di pressioni?', ...
'Switching Menu', ...
'Si, è solo da modificare.','No, va inserito.','No, va inserito.');
% Handle response switch choice
case 'Si, è solo da modificare.' disp([choice ' coming right up.']) dessert = 1;
%Legge il report e crea la matrice della griglia deformata.
%---%
%--- Prog_Mat1 ---%
%---%
fid = fopen('P_map.nas');
tmp=[];
tline1 = fgetl(fid); %crea una stringa uguale alla i-esima riga del testo
tline2= regexprep(tline1,'PLOAD4',''); %sostituisce lo spazio a PLOAD4 while ischar(tline1);
%disp(tline2);
if tline1~=-1;
tline2= regexprep(tline1,'PLOAD4',''); %sostituisce lo spazio a PLOAD4 tline3= regexprep(tline2,',',' '); %sostituisce lo spazio alla virgola nline=str2num(tline3); %trasforma la stringa in numeri
tmp=vertcat(tmp,nline); %concatena le stringhe verticalmente end;
tline1 = fgetl(fid);
end;
C1=tmp(:,1);
C2=tmp(:,2);%+tmp(:,5);
C3=tmp(:,3);%+tmp(:,6);
%C4=tmp(:,4)+tmp(:,7);
C=[C1,C2,C3];
fclose(fid);
msg1='--- passo 1 di 4 COMPLETO ---';
msg2='---';
msg=strvcat(msg2,msg1,msg2);
msg
pause(3);
%---%
%--- Prog_Mat2 ---%
%---%
file=fopen('Mappa_P.txt','w');
bdf2=[];
i0= length(C1);
for i=1:i0;
c1_str = num2str(C1(i));
l1=length(c1_str );
a1 = 15-l1;
if l1>15
c1_str = c1_str(1:15);
%else
% for j=1:a1
% c1_str = [c1_str,' '];
% end end
c2_str = num2str(C2(i));
l2=length(c2_str );
a2 = 8-l2;
if l2>8
c2_str = c2_str(1:8);
%else
% for j=1:a2
% c2_str = [c2_str,' '];
% end end
c3_str = num2str(C3(i),'%7.7f');
l3=length(c3_str );
a3 = 8-l3;
if l3>8
c3_str = c3_str(1:8);
%else
% for j=1:a3
% c3_str = [c3_str,' '];
% end end
s_i = ['PLOAD4,' c1_str,',', c2_str ,',', c3_str,',,,'];
num2str(C4(i))];
l_si= length(s_i);
fprintf(file,'%s\r\n',s_i);
bdf2=strvcat(bdf2,s_i);
end;
msg1='--- passo 2 di 4 COMPLETO ---';
msg2='---';
msg=strvcat(msg2,msg1,msg2);
msg
fclose(file);
pause(3);
%---%
%--- Prog_Mat3 ---%
%---%
fid1 = fopen('Str_Sym.bdf');
fid1_array=[];
%temp=[];
n=0;
del_line=[];
%array=['GRID'];
Tline1 = fgetl(fid1); %crea una stringa uguale alla i-esima riga del testo
while ischar(Tline1);
%disp(Tline1);
if regexpi( Tline1,'PLOAD4'); %Riconosce la sringa2 all'interno della stringa1
del_line=vertcat(del_line,n); %crea un vettore con il numero delle righe da cembiare
%findstr(kdbvj,isdvbi)
end;
Tline1 = fgetl(fid1); %cambia l'i-esima riga di testo n=n+1; %conta le righe
fid1_array=strvcat(fid1_array,Tline1); %concatena le stringhe verticalmente
end;
dl_star=max(del_line)+1;
if regexpi(fid1_array(dl_star),'*');
del_line=vertcat(del_line,dl_star); %crea un vettore cin il numero delle righe da cembiare
end;
msg1='--- passo 3 di 4 COMPLETO ---';
msg2='---';
msg=strvcat(msg2,msg1,msg2);
msg
fclose(fid1);
pause(3);
%crea il nuovo .bdf corretto
%---%
%--- Prog_Mat4 ---%
%---%
stop_line=del_line(1);
start_line=del_line(length(del_line))+1;
fine=length(fid1_array(:,1));
bdf1=fid1_array(1:stop_line,:);
bdf3=fid1_array(start_line:fine,:);
bdf=strvcat(bdf1,bdf2,bdf3);
fid2 = fopen('BDF_P_Mapped.bdf','w');
k0= length(bdf);
for k=1:k0;
bdf_line=bdf(k,:);
fprintf(fid2,'%s\r\n',bdf_line);
end
%prova=['lsajfbqc'];
%fprintf(fid2,prova);
fclose(fid2);
msg1='--- passo 4 di 4 COMPLETO ---';
msg2='---';
msg3='--- Grazie per aver scelto ---';
msg4='---- GuiZzo Software ---';
msg5='---';
msg6=' ';
msg=strvcat(msg2,msg1,msg2,msg6,msg6,msg2,msg3,msg4,msg5);
msg
%img=imread('PaulKlee.jpg');
%image(img );
case 'No, va inserito.'
disp([choice ' coming right up.']) dessert = 2;
%---%
% MAIN PROG: %
%---%
%Legge il report e crea la matrice della griglia deformata.
%---%
%--- Prog_Mat1 ---%
%---%
fid = fopen('P_map.nas');
tmp=[];
tline1 = fgetl(fid); %crea una stringa uguale alla i-esima riga del testo
tline2= regexprep(tline1,'PLOAD4',''); %sostituisce lo spazio a PLOAD4 while ischar(tline1);
%disp(tline2);
if tline1~=-1;
tline2= regexprep(tline1,'PLOAD4',''); %sostituisce lo spazio a PLOAD4 tline3= regexprep(tline2,',',' '); %sostituisce lo spazio alla virgola nline=str2num(tline3); %trasforma la stringa in numeri
tmp=vertcat(tmp,nline); %concatena le stringhe verticalmente end;
tline1 = fgetl(fid);
end;
C1=tmp(:,1);
C2=tmp(:,2);%+tmp(:,5);
C3=tmp(:,3);%+tmp(:,6);
%C4=tmp(:,4)+tmp(:,7);
C=[C1,C2,C3];
fclose(fid);
msg1='--- passo 1 di 4 COMPLETO ---';
msg2='---';
msg=strvcat(msg2,msg1,msg2);
msg
pause(3);
%---%
%--- Prog_Mat2 ---%
%---%
file=fopen('Mappa_P.txt','w');
bdf2=[];
i0= length(C1);
for i=1:i0;
c1_str = num2str(C1(i));
l1=length(c1_str );
a1 = 15-l1;
if l1>15
c1_str = c1_str(1:15);
end
c2_str = num2str(C2(i));
l2=length(c2_str );
a2 = 8-l2;
if l2>8
c2_str = c2_str(1:8);
end
c3_str = num2str(C3(i),'%7.7f');
l3=length(c3_str );
a3 = 8-l3;
if l3>8
c3_str = c3_str(1:8);
end
s_i = ['PLOAD4,' c1_str,',', c2_str ,',', c3_str,',,,'];
% s_i = ['GRID ' num2str(C1(i)), ' ' num2str(C2(i)) , ' ' num2str(C3(i)), ' ' num2str(C4(i))];
l_si= length(s_i);
fprintf(file,'%s\r\n',s_i);
bdf2=strvcat(bdf2,s_i);
end;
line_1=['$ Pressure Loads of Load Set : pload4.105.2D '];
bdf2=strvcat(line_1,bdf2);
msg1='--- passo 2 di 4 COMPLETO ---';
msg2='---';
msg=strvcat(msg2,msg1,msg2);
msg
fclose(file);
pause(3);
%---%
%--- Prog_Mat3 ---%
%---%
fid1 = fopen('Str_Sym.bdf');
fid1_array=[];
n=0;
del_line=[];
line1 = fgetl(fid1); %crea una stringa uguale alla i-esima riga del testo
while ischar(Tline1);
%disp(Tline1);
if regexpi( Tline1,'ENDDATA'); %Riconosce la sringa2 all'interno della stringa1
del_line=n; %crea un vettore con il numero delle righe da cembiare
%findstr(kdbvj,isdvbi)
end;
%temp=strvcat(temp,Tline1);
Tline1 = fgetl(fid1); %cambia l'i-esima riga di testo n=n+1; %conta le righe
fid1_array=strvcat(fid1_array,Tline1); %concatena le stringhe verticalmente
end;
msg1='--- passo 3 di 4 COMPLETO ---';
msg2='---';
msg=strvcat(msg2,msg1,msg2);
msg
fclose(fid1);
pause(3);
%crea il nuovo .bdf corretto
%---%
%--- Prog_Mat4 ---%
%---%
stop_line=del_line-2;
start_line=del_line-1;
fine=length(fid1_array(:,1));
bdf1=fid1_array(1:stop_line,:);
bdf3=fid1_array(start_line:fine,:);
bdf=strvcat(bdf1,bdf2,bdf3);
fid2 = fopen('BDF_P_Mapped.bdf','w');
k0= length(bdf);
for k=1:k0;
bdf_line=bdf(k,:);
fprintf(fid2,'%s\r\n',bdf_line);
end
fclose(fid2);
msg1='--- passo 4 di 4 COMPLETO ---';
msg2='---';
msg3='--- Grazie per aver scelto ---';
msg4='---- GuiZzo Software ---';
msg5='---';
msg6=' ';
msg=strvcat(msg2,msg1,msg2,msg6,msg6,msg2,msg3,msg4,msg5);
msg
%img=imread('PaulKlee.jpg');
%image(img );
end;