0

I was trying to do parametric studies in ABAQUS. I created an *.inp file (master) using GUI in abaqus, then wrote a matlab code to create a new *.inp file using the master. Master *.inp file can be found here and will be required to run the code. In the new *.inp file everything was same as the master except a few specific lines which I am changing for parametric studies, code is given below. I am getting the files nicely but the problem is ABAQUS can't read the file and gives error messages. By visual inspection I don't find any faults. I guess matlab is writing the *.inp file in some other format which ABAQUS can't interpret.

clc;
%Number of lines to be copied
total_lines=4538; %total number of lines
lines_b4_RP1=4406; % lines before reference point 1

%creating new files
for A=0
    for R=[20 30 40 50 100 200 300 400 500]
        fileroot = sprintf('P_SHS_120X120X1_NLA_I15_A%dR%d.inp', A,R);
        main_inp=fopen('P_SHS_120X120X1_NLA_I15_A0R10.inp','r'); %inputting the main inp file to be copied
        wfile=fopen(fileroot,'w+'); %wfile= writing the new file
        for i=1:total_lines
            data=fgets(main_inp);
                if  i<lines_b4_RP1
                    fprintf(wfile,'%s\n', data);
                elseif i==lines_b4_RP1
                    formatline1=('%s\n');
                    txtline='*Node';
                    fprintf(wfile, formatline1 ,txtline);
                elseif i==(lines_b4_RP1+1)
                    formatline2=('%d%s%d%s%d%s%d\r\n');
                    comma=',';
                    refpt1=1;
                    xcoord1=R*cosd(A);
                    ycoord1=R*sind(A);
                    zcoord1=-20;
                    fprintf(wfile, formatline2, refpt1,comma,xcoord1,comma,ycoord1,comma,zcoord1);
                elseif i==(lines_b4_RP1+2) 
                    fprintf(wfile, formatline1 ,txtline);
                elseif i==(lines_b4_RP1+3)
                    refpt2=2;    
                    xcoord2=R*cosd(A);
                    ycoord2=R*sind(A);
                    zcoord2=420;
                    fprintf(wfile, formatline2 ,refpt2,comma,xcoord2,comma,ycoord2,comma,zcoord2);
                elseif i>(lines_b4_RP1+3)
                    fprintf(wfile,'%s\n', data);
                else break;
                end
        end        
        fclose(main_inp);
        fclose(wfile);
    end
end

Thanks in advance.

N.B. A sample *.dat file containing the error message is given here.

Anwar Saadat
  • 1
  • 1
  • 3

1 Answers1

0

You are using fgets to get each line of the input file. From the matlab help:

fgets: Read line from file, keeping newline characters

You then print each line using

fprintf(wfile,'%s\n', data);

This creates two newlines at the end of each data line in the file. A second problem in your file is that you use \r\n in your format specifier. In matlab (unlike C) this will give you two newlines. e.g.

>> fprintf('Hello\rWorld\nFoo\r\nBar\n')
Hello
World
Foo

Bar
>> 

I would suggest in future to test this approach with a much simpler format that you can use. Also there is a

*preprint

option that allows you to echo the contents of the input file back into the dat file. This creates big dat files, but it is useful for debugging.

will
  • 377
  • 1
  • 10
  • Dear Will, Thanks for all your suggestions. I got another idea of the mistake that I am reading and printing all the lines using '%s' but file itself is a combination of string, decimal and float. – Anwar Saadat May 19 '15 at 05:05
  • fgets has read each line as a string, so i don't see %s as a problem? Also if this answered your question, please vote it up. I think you should test your matlab code with a simpler abaqus input file. – will May 19 '15 at 12:51