f06 file stack overflow

3

Click here to load reader

Upload: imran-sajid-shahid

Post on 16-Sep-2015

238 views

Category:

Documents


1 download

DESCRIPTION

aszl

TRANSCRIPT

  • 5/4/2015 fastestwaytoreadanf06file(Nastran)withmatlabStackOverflow

    http://stackoverflow.com/questions/17948192/fastestwaytoreadanf06filenastranwithmatlab 1/3

    signup login tour help stackoverflowcareers

    Takethe2minutetour StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.It's100%free,noregistrationrequired.

    fastestwaytoreadanf06file(Nastran)withmatlab

    IhavetoreadseveralfileofresultsfromNastranwithMATLAB.Ineedtoimporttheinformationaboutthedisplacementvector,whichislocatedinthemiddleofthefile,(butIknowthelinewherethesectionaboutdisplacementsstartsandends.).

    Thosefilesareformattedasfollows:

    Theyaredividedin"pages"withafixednumberofrowperpage

    Eachpagehasaheader,whichIdonotneedtoimportDatacolumnshavefixedwidth(Belowanexampleof"apage"ofthefile)

    Ihavewrittenafunctioninmatlab,butitisextremelyslow,andthisprocessisthebottleneckofmycode.(ThosefilesareverybigandIneedtoprocessalotofthem):I'msearchingthefastestwaytoreadthem.

    Haveyousomeideas?

    ThankyouEdit:Ihaveaddedmycode

    function[TIME,T1,T2,T3,R1,R2,R3]=importdisp(D,L,cst,cst2,filename)%Dfirstrowofthesection%Llastrow+1ofthesectionpage=floor((LD)/cst);q=zeros((page)*cst2,1);TIME=q;T1=q;T2=q;T3=q;R1=q;R2=q;R3=q;

    fori=0:page1startRow=D+i*cst;endRow=startRow+cst1;qq=(1+i*cst2:(i+1)*cst2);[TIME(qq),~,T1(qq),T2(qq),T3(qq),R1(qq),R2(qq),R3(qq)]=importfile2(filename,startRow,endRow);endi=page;startRow=D+i*57;endRow=L1;[aTIME,~,aT1,aT2,aT3,aR1,aR2,aR3]=importfile2(filename,startRow,endRow);TIME=[TIME;aTIME];T1=[T1;aT1];T2=[T2;aT2];T3=[T3;aT3];

    function[TIME,TYPE,T1,T2,T3,R1,R2,R3]=importfile2(filename,startRow,endRow)

    %%Readcolumnsofdataasstrings:%Formoreinformation,seetheTEXTSCANdocumentation.formatSpec='%12f%*s%13f%13f%13f%13f%13f%13f';

    %%Openthetextfile.fileID=fopen(filename,'r');dataArray=textscan(fileID,formatSpec,endRowstartRow6,'HeaderLines',startRow+6,'ReturnOnError',false);

    fclose(fileID);

    TIME=cell2mat(dataArray(1));TYPE=[];%T1=cell2mat(dataArray(2));T2=cell2mat(dataArray(3));T3=cell2mat(dataArray(4));R1=cell2mat(dataArray(5));R2=cell2mat(dataArray(6));R3=cell2mat(dataArray(7));R1=[R1;aR1];R2=[R2;aR2];R3=[R3;aR3];

  • 5/4/2015 fastestwaytoreadanf06file(Nastran)withmatlabStackOverflow

    http://stackoverflow.com/questions/17948192/fastestwaytoreadanf06filenastranwithmatlab 2/3

    1MSC.NASTRANJOBCREATEDON23JUL13AT11:37:55JULY30,2013MSC.NASTRAN11/25/11PAGE375TIME_DIPENDENT0SUBCASE1POINTID=51DISPLACEMENTVECTOR

    TIMETYPET1T2T3R1R2R31.010000E+00G3.575517E050.02.498832E050.01.368603E060.01.010200E+00G3.615527E050.05.931119E050.02.523460E080.01.010400E+00G3.643431E050.01.400531E040.01.428176E060.01.010600E+00G3.690420E050.02.124308E040.01.886763E060.01.010800E+00G3.727554E050.02.720885E040.01.029395E060.01.011000E+00G3.753303E050.03.154415E040.05.155680E070.01.011200E+00G3.799178E050.03.399170E040.01.612602E060.01.011400E+00G3.847007E050.03.440528E040.01.544716E060.01.011600E+00G3.878193E050.03.275930E040.03.747878E070.01.011800E+00G3.927647E050.02.914786E040.01.095575E060.01.012000E+00G3.994424E050.02.378519E040.01.759643E060.01.012200E+00G4.034076E050.01.699633E040.01.095494E060.01.012400E+00G4.074808E050.09.188905E050.03.884768E070.01.012600E+00G4.135053E050.08.304626E060.01.629274E060.01.012800E+00G4.170949E050.07.576412E050.01.752396E060.01.013000E+00G4.199858E050.01.552350E040.06.461957E070.01.013200E+00G4.248216E050.02.252832E040.08.903658E070.01.013400E+00G4.278283E050.02.817524E040.01.804066E060.01.013600E+00G4.301732E050.03.213745E040.01.573536E060.01.013800E+00G4.358916E050.03.417496E040.03.442360E070.01.014000E+00G4.405503E050.03.414665E040.01.139860E060.01.014200E+00G4.437157E050.03.203563E040.01.834472E060.01.014400E+00G4.499020E050.02.795874E040.01.277272E060.01.014600E+00G4.558231E050.02.215368E040.02.333646E080.01.014800E+00G4.597261E050.01.495850E040.01.129674E060.01.015000E+00G4.643634E050.06.810582E050.01.298742E060.01.015200E+00G4.685981E050.01.765095E050.04.973296E070.01.015400E+00G4.722315E050.01.022117E040.05.859554E070.01.015600E+00G4.764707E050.01.804387E040.01.191458E060.01.015800E+00G4.799638E050.02.476246E040.09.108963E070.01.016000E+00G4.831509E050.02.995918E040.01.032815E070.01.016200E+00G4.872533E050.03.330215E040.01.085160E060.01.016400E+00G4.917991E050.03.459135E040.01.281773E060.01.016600E+00G4.956298E050.03.376274E040.05.597767E070.01.016800E+00G4.989865E050.03.085430E040.05.647819E070.01.017000E+00G5.048857E050.02.602277E040.01.257802E060.01.017200E+00G5.116086E050.01.957408E040.01.047838E060.01.017400E+00G5.149745E050.01.192598E040.01.662111E070.01.017600E+00G5.192366E050.03.549325E050.0

  • 5/4/2015 fastestwaytoreadanf06file(Nastran)withmatlabStackOverflow

    http://stackoverflow.com/questions/17948192/fastestwaytoreadanf06filenastranwithmatlab 3/3

    7.763596E070.01.017800E+00G5.251750E050.05.053262E050.01.131500E060.01.018000E+00G5.280536E050.01.334662E040.06.140833E070.01.018200E+00G5.301622E050.02.081115E040.03.166196E070.01.018400E+00G5.345660E050.02.701173E040.08.439085E070.01.018600E+00G5.390675E050.03.158737E040.05.923507E070.01.018800E+00G5.422348E050.03.423101E040.01.950982E070.01.019000E+00G5.467689E050.03.474040E040.09.392950E070.01.019200E+00G5.521453E050.03.307139E040.01.020770E060.01.019400E+00G5.565249E050.02.932987E040.02.693299E070.01.019600E+00G5.617935E050.02.372591E040.08.091097E070.01.019800E+00G5.678378E050.01.657268E040.01.504755E060.0

    matlab

    editedJul30'13at14:33 askedJul30'13at13:19thunder1123351 1 3 13

    Haveyoutried ?mathworks.co.uk/matlabcentral/fileexchange/ am304 Jul30'13at13:27

    1

    Pleasequantify .Andeverythingelse.AndshowusyourcodewithoutseeingyourcodeallIcansuggestisthatyouhavechosentheslowestpossiblewayofreadingafile.

    extremelyslow

    HighPerformanceMark Jul30'13at14:02

    Ihaveaddedmycode.Ittakes2025stoimport5000timestep. thunder1123 Jul30'13at14:53

    1Answer

    Nastranf06filesareformattedtoprovideadequatereadibilityforusers.Forprogrammingpurposesattheotherhand,thereisabetteroptioninmyopinion.Itisthepunchfile(.pch).Itcontainsalltheresultsinafixedlengthtexttableformat.Youdonothavetodealwithpagebreaks,emptylinesorrepeatitiveidentifiersateachpagelikeyoudoinanf06file.Thegoodthingisthatonceyouhaveachievedacodethatreadssomedatasuccessfully,youcanjustusealmostthesamepatterninordertoreadotherkindofdatabecausetheonlythingthatchangesthetitleandtherownumber.Youhavetoexaminealittletogetintoitanyway...

    ThepunchfilemustberequestedbytheBDFfile.Forexampleifyourrequestis:

    DISPLACEMENT(PRINT)=ALL

    thenyouadda"PUNCH"

    DISPLACEMENT(PUNCH,PRINT)=ALL

    anditwillgeneratethepchfileaswellasthef06file.

    answeredJul24'14at20:42gsahin1