Arisinhell
December 14th, 2013, 01:07 PM
[SOLVED]
(see post #6)
Hello!
Im trying to convert some datafiles from this format (lammps velocity files):
ITEM: TIMESTEP
1
ITEM: NUMBER OF ATOMS
924
ITEM: BOX BOUNDS pp pp pp
0 67.4728
0 62.565
0 45.105
ITEM: ATOMS type vx vy vz
3.96234 2.15174 -3.08438
4.81728 -4.71916 2.30628
4.57479 2.70962 -0.816817
...
ITEM: TIMESTEP
2
ITEM: NUMBER OF ATOMS
924
ITEM: BOX BOUNDS pp pp pp
0 67.4728
0 62.565
0 45.105
ITEM: ATOMS type vx vy vz
2.61854 3.17183 -2.45742
-0.322279 1.69319 2.70096
2.94569 -3.51979 0.784884
.. ect
to this format:
"frame" "time" (eg 1 0)
3.96234 2.15174 -3.08438
4.81728 -4.71916 2.30628
4.57479 2.70962 -0.816817
...
"frame" "time" (eg 2 1)
2.61854 3.17183 -2.45742
-0.322279 1.69319 2.70096
2.94569 -3.51979 0.784884
.. ect
Ive already made a bash script to do this:
#!/bin/bash
sed -e '/TIMESTEP/,+7d' velmps.dat > out (deletes the first 8 lines from the text that needs to be deleted (total lines 9))
Atoms=924
timestep=.0032
framestep=4
for i in {1..2049}
do
Tline=`echo "scale=5; ($i+($i-1)*$Atoms)" | bc -l`;
Tframe=`echo "scale=5; ($i*$framestep)" | bc -l`;
Ttimestep=`echo "scale=5; ($i-1)*$timestep" | bc -l`;
sed -e ''$Tline's/.*/'$Tframe' '$Ttimestep'/' out > out.tmp
mv out.tmp out
done
mv out myrun.vel
but it is really unsophisticated and way to slow (takes from 40-90 mins!)
Can you please show me an alternative based on sed or awk?
something like:
sed/awk
(i from 1 to number)
{
replace the "function[i]" line with the text "(function1[i] function2[i]"
}
Thanks a lot in advance!
(see post #6)
Hello!
Im trying to convert some datafiles from this format (lammps velocity files):
ITEM: TIMESTEP
1
ITEM: NUMBER OF ATOMS
924
ITEM: BOX BOUNDS pp pp pp
0 67.4728
0 62.565
0 45.105
ITEM: ATOMS type vx vy vz
3.96234 2.15174 -3.08438
4.81728 -4.71916 2.30628
4.57479 2.70962 -0.816817
...
ITEM: TIMESTEP
2
ITEM: NUMBER OF ATOMS
924
ITEM: BOX BOUNDS pp pp pp
0 67.4728
0 62.565
0 45.105
ITEM: ATOMS type vx vy vz
2.61854 3.17183 -2.45742
-0.322279 1.69319 2.70096
2.94569 -3.51979 0.784884
.. ect
to this format:
"frame" "time" (eg 1 0)
3.96234 2.15174 -3.08438
4.81728 -4.71916 2.30628
4.57479 2.70962 -0.816817
...
"frame" "time" (eg 2 1)
2.61854 3.17183 -2.45742
-0.322279 1.69319 2.70096
2.94569 -3.51979 0.784884
.. ect
Ive already made a bash script to do this:
#!/bin/bash
sed -e '/TIMESTEP/,+7d' velmps.dat > out (deletes the first 8 lines from the text that needs to be deleted (total lines 9))
Atoms=924
timestep=.0032
framestep=4
for i in {1..2049}
do
Tline=`echo "scale=5; ($i+($i-1)*$Atoms)" | bc -l`;
Tframe=`echo "scale=5; ($i*$framestep)" | bc -l`;
Ttimestep=`echo "scale=5; ($i-1)*$timestep" | bc -l`;
sed -e ''$Tline's/.*/'$Tframe' '$Ttimestep'/' out > out.tmp
mv out.tmp out
done
mv out myrun.vel
but it is really unsophisticated and way to slow (takes from 40-90 mins!)
Can you please show me an alternative based on sed or awk?
something like:
sed/awk
(i from 1 to number)
{
replace the "function[i]" line with the text "(function1[i] function2[i]"
}
Thanks a lot in advance!