Challenge

Project 1 - Parsing NASA thermodynamic data

clc,clear all,close all,

file=fopen('THERMO.dat','r')
V=fgetl(file)
data=fgetl(file)


temp_values=strsplit(data,' ');

%Global temperature
global_low_temp=str2num(temp_values{2})
global_mid_temp=str2num(temp_values{3})
global_high_temp=str2num(temp_values{4})

fgetl(file)
fgetl(file)
fgetl(file)
for Z=1:inf

    Header=fgetl(file);
    if strcmp(Header,'END')
        disp('File Reading was successfull')
        break

    end
    % species oxygen



    T=strsplit(Header,' ')
    species=T{1};
    % oxygen local temperature
    local_low_temp1=str2num(T{end-3});
    local_mid_temp2=str2num(T{end-1});
    local_high_temp3=str2num(T{end-2});

    second_line=fgetl(file);
    co=strfind(second_line,'E');
    E1=second_line(1:co(1)+3);
    E2=second_line(co(1)+4:co(2)+3);
    E3=second_line(co(2)+4:co(3)+3);
    E4=second_line(co(3)+4:co(4)+3);
    E5=second_line(co(4)+4:co(5)+3);

    %oxygen coefficients
    coff_1=str2num(E1)
    coff_2=str2num(E2)
    coff_3=str2num(E3)
    coff_4=str2num(E4)
    coff_5=str2num(E5)

    third_line=fgetl(file);
    co_1=strfind(third_line,'E');

    E_1_1=third_line(1:co_1(1)+3);
    E_1_2=third_line(co_1(1)+4:co_1(2)+3);
    E_1_3=third_line(co_1(2)+4:co_1(3)+3);
    E_1_4=third_line(co_1(3)+4:co_1(4)+3);
    E_1_5=third_line(co_1(4)+4:co_1(5)+3);

    coff_6=str2num(E_1_1);
    coff_7=str2num(E_1_2);
    coff_8=str2num(E_1_3)
    coff_9=str2num(E_1_4)
    coff_10=str2num(E_1_5)

    fourth_line=fgetl(file)
    o=strfind(fourth_line,'E')
    f1=fourth_line(1:o(1)+3)
    f2=fourth_line(o(1)+4:o(2)+3)
    f3=fourth_line(o(2)+4:o(3)+3)
    f4=fourth_line(o(3)+4:o(4)+3)

    coff_11=str2num(f1)
    coff_12=str2num(f2)
    coff_13=str2num(f3)
    coff_14=str2num(f4)
    R=8.134;

    low_temp=linspace(local_low_temp1,local_high_temp3,100)

    for i=1:length(low_temp)
        if low_temp(i)>local_mid_temp2
            cp(i)=(coff_1+coff_2.*low_temp(i)+coff_3.*low_temp(i).^2+coff_4.*low_temp(i).^3+coff_5.*low_temp(i).^4).*R;
            H(i)=(coff_1+(coff_2.*low_temp(i))./2+(coff_3.*low_temp(i).^2)./3+(coff_4.*low_temp(i).^3)./4+(coff_5.*low_temp(i).^4)./5+(coff_6)./low_temp(i)).*R.*low_temp(i);
            S(i)=(coff_1.*log(low_temp(i))+(coff_2.*low_temp(i))+(coff_3.*low_temp(i).^2)./2+(coff_4.*low_temp(i).^3)./3+(coff_5.*low_temp(i).^4)./4+coff_7).*R;
        else
           cp(i)=(coff_8+coff_9.*low_temp(i)+coff_10.*low_temp(i).^2+coff_11.*low_temp(i).^3+coff_12.*low_temp(i).^4).*R;
            H(i)=(coff_8+(coff_9.*low_temp(i))./2+(coff_10.*low_temp(i).^2)./3+(coff_11.*low_temp(i).^3)./4+(coff_12.*low_temp(i).^4)./5+(coff_13)./low_temp(i)).*R.*low_temp(i);
            S(i)=(coff_8.*log(low_temp(i))+(coff_9.*low_temp(i))+(coff_10.*low_temp(i).^2)./2+(coff_11.*low_temp(i).^3)./3+(coff_12.*low_temp(i).^4)./4+coff_14).*R;

        end
    end
    figure(1)
    plot(cp,low_temp,'linewidth',4,'color','g')
    xlabel('specific heat')
    ylabel('Temperature')
    figure(2)
    plot(H,low_temp,'linewidth',4,'color','r')
    xlabel('Enthalpy')
    ylabel('Temperature')
    figure(3)
    plot(S,low_temp,'linewidth',4,'color','c')
    xlabel('Entropy')
    ylabel('Temperature')
    mkdir('figures')
    cd('figures')
    mkdir(species)
    cd(species)
    filename=[species,' specific_heat.jpeg ']
    saveas(figure(1),filename)
    filename=[species,' Enthalpy.jpeg ']
    saveas(figure(2),filename)
    filename=[species,' Entropy.jpeg ']
    saveas(figure(3),filename)
    cd ..
    cd ..

 
end

 file_p(species)
function file_p(species)
Elements=['O','H','C','A','S','N'];
Mass=[8,1,12,39.9,32,14];
weight=0;
for i=1:length(species);
    for j=1:length(Elements);
        if species(i)==Elements(j);
            weight=weight+Mass(j);
            pos=j;
        end

    end
    V= str2num(species(i));
    if V
        weight=weight+(Mass(pos)*(V-1));
    end
end
weight
end

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.