Hi Katie, here is the code that extracts failure indices (Please note I am only a beginner perl programmer):
use strict; use warnings; my @FileArray = ("c:/ultimate1_it2.f06"); open(QUAD4FIINFILE, ">QUAD4FI.txt") or die "Unable to open QUAD4FI.txt + file\n"; open(QUAD4CEINFILE, ">QUAD4CE.txt") or die "Unable to open QUAD4CE.txt + file\n"; open(FAIL_FLAG_QUAD4, ">FAIL_FLAG_QUAD4.txt") or die "Unable to open F +AIL_FLAG_QUAD4.txt file\n"; &Initial_Sort(); close QUAD4FIINFILE; close QUAD4CEINFILE; close FAIL_FLAG_QUAD4; sub Initial_Sort { #------------------------------------------------------ my $in = 0; my $loadname; my $loadname1; my $loadname2; my @subcaseno = (); my $last = ""; my $var; # The following variables are for extraction of failure indices fo +r layered composite elements my $QUAD4CE_Element_ID = 0; my $QUAD4CE_Failure_Theory = ""; my $QUAD4CE_Flag_for_elem_id_line = 0; my $QUAD4CE_Flag_for_long_line = 0; my $QUAD4CE_Ply_Id = 0; my $QUAD4CE_Failure_Index_1 = ""; my $QUAD4CE_Failure_Index_2 = ""; my $QUAD4CE_Element_Id_Line = ""; # ------------------------------- my $Size_Of_FileArray = @FileArray; #-------------------------------- my @QUAD4CE_load_array = (); my $QUAD4CE_load_array_counter = 0; #-------------------------------- for (my $i =0; $i<= $#FileArray; $i++) { open(FILE, $FileArray[$i]) or die "Unable to open input file\n +"; while (<FILE>) { #This is the main while loop that goes throug +h f06 Files. $in = $_; if (($in =~ /^1/) && ($in =~ /MSC/) && ($in =~ /NASTRAN/) + && ($in =~ /PAGE/)) { $loadname = <FILE>; if($loadname ne /^\s+$/){ chomp ($loadname); $loadname1 = $loadname; } next; } if ( ($in =~ m/^0\s+(.+?)\s+SUBCASE/) || ($in =~ m/^0\s+(. ++?)\s+SUBCOM/) || ($in =~ m/^0\s+(.+?)\s+SYM/) || ($in =~ m/^0\s+(.+? +)\s+SYMCOM/) || ($in =~ m/^0\s+(.+?)\s+REPCASE/) ) { if ($1 eq " "){ $loadname2 = $loadname1; }else{$loadname2 = $1;} @subcaseno = split(' ', $in); $var = @subcaseno; next; } if( ($in =~ /F A I L U R E I N D I C E S F O R L A Y + E R E D C O M P O S I T E E L E M E N T S/) && ($in =~ /( Q U A +D 4 )/) ) { do { $in = (<FILE>); chomp($in); if ( ($in =~ /\d\.\d\d/) || ($in =~ /0\.0/) || ($ +in =~ /\.0/) || ($in =~ /\d+/) ) { my @array = split(" ", $in); my $size = @array; if($size == 5){ $QUAD4CE_Element_ID = $array[0]; $QUAD4CE_Failure_Theory = $array[1]; $QUAD4CE_Ply_Id = $array[2]; $QUAD4CE_Failure_Index_1 = $array[3]; $QUAD4CE_Failure_Index_2 = $array[4]; $QUAD4CE_Flag_for_elem_id_line = 1; }elsif($size == 3){ $QUAD4CE_Ply_Id = $array[0]; $QUAD4CE_Failure_Index_1 = $array[1]; $QUAD4CE_Failure_Index_2 = $array[2]; $QUAD4CE_Flag_for_long_line = 1; }elsif( ( ($size == 1) && ($QUAD4CE_Flag_for_e +lem_id_line == 1) ) || ( ($size == 2) && ($QUAD4CE_Flag_for_elem_id_l +ine == 1) ) ){ print QUAD4CEINFILE ("$QUAD4CE_Element_ID $ +QUAD4CE_Failure_Theory $QUAD4CE_Ply_Id $QUAD4CE_Failure_Index_1 + $QUAD4CE_Failure_Index_2 $array[0] $subcaseno[$var-1] $l +oadname2\n"); $QUAD4CE_Element_Id_Line = $QUAD4CE_Element_ID +; $QUAD4CE_Flag_for_elem_id_line = 0; }elsif( (($size == 1) && ($QUAD4CE_Flag_for_lo +ng_line == 1)) || (($size == 2) && ($QUAD4CE_Flag_for_long_line == 1) +) ){ print QUAD4CEINFILE ("$QUAD4CE_Element_ID $ +QUAD4CE_Failure_Theory $QUAD4CE_Ply_Id $QUAD4CE_Failure_Index_1 + $QUAD4CE_Failure_Index_2 $array[0]\n"); $QUAD4CE_Flag_for_long_line = 0; print QUAD4FIINFILE ("$QUAD4CE_Element_Id_Line + $array[0] $subcaseno[$var-1] $loadname2\n"); if( ($size == 2) && ( (defined $array[1] && $a +rray[1] =~ m/\*{3}/) ) ) { print FAIL_FLAG_QUAD4 ("$QUAD4CE_Element_I +D $QUAD4CE_Ply_Id $QUAD4CE_Failure_Index_1 $QUAD4CE_Failure_ +Index_2 $array[0] $array[1] $subcaseno[$var-1] $loadname2 +\n"); } } } }until (($in =~ /^1/) && ($in =~ /MSC/) && ($in =~ / +NASTRAN/) && ($in =~ /PAGE/)); if($subcaseno[$var-1] =~ /^\d+$/){ $QUAD4CE_load_array[$QUAD4CE_load_array_counter] = + $subcaseno[$var-1]; $QUAD4CE_load_array_counter++; } } # End of if } # End Of while - end of main while loop that goes through ea +ch f06 file close FILE; } # End of for (my $i =0; $i<= $#FileArray; $i++) { }

In reply to Re: Re: Fast reading and processing from a text file - Perl vs. FORTRAN by ozgurp
in thread Fast reading and processing from a text file - Perl vs. FORTRAN by ozgurp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.