J
jld8996
Hi All,
I just started learning Perl with Sams Teach Yourself Perl in 24
hours. I have been able to accomplish part of what I wanted to do but
need a little more help. I have 2 files, the first is a list of
element numbers and the 2nd is a large text file (a .f06 file from
NASTRAN for those who are familiar). I started writing a script shown
below to open both files. What I need to do is step through the first
file element by element and look up each element in the 2nd file.
Once found I want to write the line where it is found and the next
line to an output file. Then find the next element of file 1 and so
on. Any help or guidance would be great. Thanks, Jeremy
Here is my script so far:
-----------------------
#!/usr/bin/perl
print "Enter the name of the element control file: \n";
$control=<STDIN>;
open(INPUT,$control) || die "$!";
@input=<INPUT>;
close(INPUT);
print "Enter the name of the .f06 file: \n";
$f06=<STDIN>;
open(STRESS,$f06) || die "$!";
@stresses=<STRESS>;
close(STRESS);
print "Enter the name of the output file: \n";
$output=<STDIN>;
open(OUTPUT,">$output") || die "$!";
-------------------------------------------
so I've only done the easy stuff. I read all of the .f06 file into
the array "stresses". I'm not sure if this was necessary. The actual
file is over 300,000 lines long so this might be slowing me down.
Here's is a sample of file 1, the element file:
-------------------------------------------
119471
119472
119473
119474
--------------------------------------------
And here is a piece of file 2, the .f06 file:
--------------------------------------------
1 MSC.NASTRAN JOB CREATED ON 19-SEP-03 AT 15:32:39
W145
0
S T R E S S E S I N Q U A D R I L A T E R
A
ELEMENT FIBER STRESSES IN ELEMENT COORD SYSTEM
ID. DISTANCE NORMAL-X NORMAL-Y SHEAR-XY
0 119461 -6.250000E-02 -2.809423E+02 -2.226965E+03
7.288095E+02
6.250000E-02 -2.154822E+02 -2.395907E+03
5.431436E+02
0 119462 -6.250000E-02 9.256976E+02 -2.722196E+03
1.075280E+03
6.250000E-02 9.582150E+02 -3.030506E+03
1.060233E+03
0 119463 -6.250000E-02 -5.176458E+01 1.040512E+03
-9.355118E+01
6.250000E-02 -2.901073E+01 1.011089E+03
-2.422135E+01
0 119464 -6.250000E-02 -1.102965E+02 1.167524E+03
5.211899E+01
6.250000E-02 -1.033523E+02 1.100544E+03
1.217817E+02
0 119465 -6.250000E-02 8.531695E+02 3.763257E+02
8.413060E+02
6.250000E-02 7.949519E+02 8.895544E+01
8.487442E+02
0 119466 -6.250000E-02 2.496463E+02 1.557864E+03
7.741991E+02
6.250000E-02 1.736531E+02 1.307298E+03
8.175496E+02
0 119467 -6.250000E-02 -1.153684E+02 1.296065E+03
3.091736E+02
6.250000E-02 -1.198170E+02 1.147716E+03
3.649098E+02
0 119468 -6.250000E-02 1.097371E+03 3.642865E+03
1.958549E+03
6.250000E-02 1.037483E+03 3.431623E+03
1.997865E+03
0 119469 -6.250000E-02 -5.984709E+01 1.383306E+03
1.489364E+02
6.250000E-02 -5.029673E+01 1.210617E+03
1.580537E+02
0 119470 -6.250000E-02 1.908398E+02 1.890122E+03
3.743426E+02
6.250000E-02 1.284111E+02 1.673722E+03
3.498486E+02
0 119471 -1.900000E-01 5.097551E+02 1.409135E+02
-2.752976E+01
1.900000E-01 -1.391517E+03 -3.814824E+02
-3.767153E+02
0 119472 -1.900000E-01 -7.821536E+01 1.430543E+03
-4.919512E+02
1.900000E-01 3.173092E+02 1.755130E+03
-6.183864E+02
0 119473 -1.900000E-01 -4.190353E+02 -9.498234E+02
-3.387274E+02
1.900000E-01 1.031396E+02 2.249585E+02
-2.015406E+02
0 119474 -1.900000E-01 -6.918803E+01 -1.046147E+03
-7.935986E+02
1.900000E-01 7.496266E+02 8.220536E+02
-1.732447E+02
0 119475 -1.900000E-01 -9.534775E+02 -2.848530E+03
-1.332869E+02
1.900000E-01 1.081157E+03 3.724546E+03
4.091841E+02
0 119476 -1.900000E-01 2.104021E+01 -2.328312E+03
-4.683439E+02
1.900000E-01 -3.702834E+01 -3.805241E+02
-1.132028E+02
I just started learning Perl with Sams Teach Yourself Perl in 24
hours. I have been able to accomplish part of what I wanted to do but
need a little more help. I have 2 files, the first is a list of
element numbers and the 2nd is a large text file (a .f06 file from
NASTRAN for those who are familiar). I started writing a script shown
below to open both files. What I need to do is step through the first
file element by element and look up each element in the 2nd file.
Once found I want to write the line where it is found and the next
line to an output file. Then find the next element of file 1 and so
on. Any help or guidance would be great. Thanks, Jeremy
Here is my script so far:
-----------------------
#!/usr/bin/perl
print "Enter the name of the element control file: \n";
$control=<STDIN>;
open(INPUT,$control) || die "$!";
@input=<INPUT>;
close(INPUT);
print "Enter the name of the .f06 file: \n";
$f06=<STDIN>;
open(STRESS,$f06) || die "$!";
@stresses=<STRESS>;
close(STRESS);
print "Enter the name of the output file: \n";
$output=<STDIN>;
open(OUTPUT,">$output") || die "$!";
-------------------------------------------
so I've only done the easy stuff. I read all of the .f06 file into
the array "stresses". I'm not sure if this was necessary. The actual
file is over 300,000 lines long so this might be slowing me down.
Here's is a sample of file 1, the element file:
-------------------------------------------
119471
119472
119473
119474
--------------------------------------------
And here is a piece of file 2, the .f06 file:
--------------------------------------------
1 MSC.NASTRAN JOB CREATED ON 19-SEP-03 AT 15:32:39
W145
0
S T R E S S E S I N Q U A D R I L A T E R
A
ELEMENT FIBER STRESSES IN ELEMENT COORD SYSTEM
ID. DISTANCE NORMAL-X NORMAL-Y SHEAR-XY
0 119461 -6.250000E-02 -2.809423E+02 -2.226965E+03
7.288095E+02
6.250000E-02 -2.154822E+02 -2.395907E+03
5.431436E+02
0 119462 -6.250000E-02 9.256976E+02 -2.722196E+03
1.075280E+03
6.250000E-02 9.582150E+02 -3.030506E+03
1.060233E+03
0 119463 -6.250000E-02 -5.176458E+01 1.040512E+03
-9.355118E+01
6.250000E-02 -2.901073E+01 1.011089E+03
-2.422135E+01
0 119464 -6.250000E-02 -1.102965E+02 1.167524E+03
5.211899E+01
6.250000E-02 -1.033523E+02 1.100544E+03
1.217817E+02
0 119465 -6.250000E-02 8.531695E+02 3.763257E+02
8.413060E+02
6.250000E-02 7.949519E+02 8.895544E+01
8.487442E+02
0 119466 -6.250000E-02 2.496463E+02 1.557864E+03
7.741991E+02
6.250000E-02 1.736531E+02 1.307298E+03
8.175496E+02
0 119467 -6.250000E-02 -1.153684E+02 1.296065E+03
3.091736E+02
6.250000E-02 -1.198170E+02 1.147716E+03
3.649098E+02
0 119468 -6.250000E-02 1.097371E+03 3.642865E+03
1.958549E+03
6.250000E-02 1.037483E+03 3.431623E+03
1.997865E+03
0 119469 -6.250000E-02 -5.984709E+01 1.383306E+03
1.489364E+02
6.250000E-02 -5.029673E+01 1.210617E+03
1.580537E+02
0 119470 -6.250000E-02 1.908398E+02 1.890122E+03
3.743426E+02
6.250000E-02 1.284111E+02 1.673722E+03
3.498486E+02
0 119471 -1.900000E-01 5.097551E+02 1.409135E+02
-2.752976E+01
1.900000E-01 -1.391517E+03 -3.814824E+02
-3.767153E+02
0 119472 -1.900000E-01 -7.821536E+01 1.430543E+03
-4.919512E+02
1.900000E-01 3.173092E+02 1.755130E+03
-6.183864E+02
0 119473 -1.900000E-01 -4.190353E+02 -9.498234E+02
-3.387274E+02
1.900000E-01 1.031396E+02 2.249585E+02
-2.015406E+02
0 119474 -1.900000E-01 -6.918803E+01 -1.046147E+03
-7.935986E+02
1.900000E-01 7.496266E+02 8.220536E+02
-1.732447E+02
0 119475 -1.900000E-01 -9.534775E+02 -2.848530E+03
-1.332869E+02
1.900000E-01 1.081157E+03 3.724546E+03
4.091841E+02
0 119476 -1.900000E-01 2.104021E+01 -2.328312E+03
-4.683439E+02
1.900000E-01 -3.702834E+01 -3.805241E+02
-1.132028E+02