0

From my computationa tool I am getting two plots one in xmgrace and other in some dat file format. The top few lines in xmgrace format (say it is a file grace.agr) is having tick lable and their positions which I want to use in my gnuplot script. My grace.dat lookes like (total ticklabels may be more here I am mentioning only few)

 @ page size 595, 842
 @ view 0.120000, 0.150000, 0.900000, 1.280000
 @ default linewidth 2.0
 @ xaxis  label char size 1.5
 @ xaxis  ticklabel char size 1.25
 @ yaxis  label char size 1.5
 @ yaxis  ticklabel char size 1.25
 @ xaxis  tick major grid on
 @ xaxis  tick spec type both
 @ xaxis  tick spec           8
@ xaxis  tick major   0, 0.00000
 @ xaxis  ticklabel            0 ,"\xG"
@ xaxis  tick major   1, 0.67643
 @ xaxis  ticklabel            1 ,"M           "
@ xaxis  tick major   2, 1.06696
 @ xaxis  ticklabel            2 ,"K           "
@ xaxis  tick major   3, 1.84803
 @ xaxis  ticklabel            3 ,"\xG"
@ xaxis  tick major   4, 1.98549
 @ xaxis  ticklabel            4 ,"A           "
@ xaxis  tick major   5, 2.66192
 @ xaxis  ticklabel            5 ,"L           "
@ xaxis  tick major   6, 3.05245
 @ xaxis  ticklabel            6 ,"H           "
@ xaxis  tick major   7, 3.83352
 @ xaxis  ticklabel            7 ,"A           "
@ with g0

With the help of grep, awk and some other tricks as mentioned in code section I managed to append below data in a file (say the file name is SETTICKS.dat)

cat SETTICKS.dat gives me this:
set xtics ( "\xG" 0.00000, "M" 0.67643, "K" 1.06696, "\xG" 1.84803, "A" 1.98549, "L" 2.66192, "H" 3.05245, "A" 3.83352, )

grep 'bandindex:   1' -B10000 grace.agr | grep xaxis | grep 'type both' -A 1000 | grep 'xaxis  tick spec           ' -A1000 | grep '0, 0.00000' -A1000 | awk '{print $5}' | grep -v '^[0-9]' | awk '{p
rint substr($1,2); }'| awk -F\|  '{ print substr($1,1,4)}' > xlable-1.txt
# "
grep 'bandindex:   1' -B10000 grace.agr | grep xaxis | grep 'type both' -A 1000 | grep 'xaxis  tick spec           ' -A1000 | grep '0, 0.00000' -A1000 | awk '{print $5}' | grep -v '^[0-9]' | awk '{p
rint substr($1,2); }'| awk -F\|  '{ print substr($1,1,1)}' >  xlable-2.txt

#"X"
paste  xlable-* | awk '$1 =$1$2 {print}' | awk '{print$1}' > xlable-3.txt

#Tick_position
grep 'bandindex:   1' -B10000 grace.agr | grep xaxis | grep 'type both' -A 1000 | grep 'xaxis  tick spec           ' -A1000 | grep '0, 0.00000' -A1000 | awk '{print $6}' | awk '!/"/' | awk 'NF > 0'  
> xlable-4.txt

#comma
grep 'bandindex:   1' -B10000 grace.agr | grep xaxis | grep 'type both' -A 1000 | grep 'xaxis  tick spec           ' -A1000 | grep '0, 0.00000' -A1000 | awk '{print $5}' | grep -v '^[0-9]' | awk -F\
|  '{ print substr($1,1,1)}' > xlable-5.txt

paste xlable-4.txt xlable-5.txt | awk '$1 =$1$2 {print}' | awk '{print$1}' > xlable-6.txt
#cat xlable-6.txt

paste xlable-3.txt xlable-6.txt | awk '{print $1, $2}' | awk 'BEGIN { ORS = " " } { print }' >  xlable-7.txt

echo  "set xtics (" > x-tick-1.txt
echo  ")" > x-tick-2.txt


paste x-tick-1.txt xlable-7.txt x-tick-2.txt > SETTICKS.dat

I want to use ticks and their positions from above mentioned grace.agr file at two places in the gnuscript as below

(1)
set xtics ("\xG" 0.00000, "M" 0.67643, "K" 1.06696, "\xG" 1.84803 ,"A" 1.98549, "L" 2.66192, "H" 3.05245 ,"A" 3.83352,)  and then 

(2) 

set arrow from 0.00000,Y11 to 0.00000,Y12 nohead
set arrow from 0.67643,Y11 to 0.67643,Y12 nohead
set arrow from 1.06696,Y11 to 1.06696,Y12 nohead
set arrow from 1.84803,Y11 to 1.84803,Y12 nohead
set arrow from 1.98549,Y11 to 1.98549,Y12 nohead
set arrow from 2.66192,Y11 to 2.66192,Y12 nohead
set arrow from 3.05245,Y11 to 3.05245,Y12 nohead
set arrow from 3.83352,Y11 to 3.83352,Y12 nohead

where Y11 and Y12 are -10 and 10 respectively.

astha
  • 593
  • 5
  • 15

1 Answers1

1

I propose you a solution just using awk.

For the first part:

awk 'BEGIN {mystring="";FS=", *"}/tick major +[0-9]+/{myfield1=$2;getline;gsub(" ","");mystring=mystring$2" "myfield1", ";}END{print "set xtics ("mystring") and then ";}' grace.dat

you'll get this output:

set xtics ("\xG" 0.00000, "M" 0.67643, "K" 1.06696, "\xG" 1.84803, "A" 1.98549, "L" 2.66192, "H" 3.05245, "A" 3.83352, ) and then

For second part:

awk 'BEGIN {FS=", *"}/tick major +[0-9]+/{myfield1=$2;getline;gsub(" ","");print "set arrow from "myfield1",Y11 to "myfield1",Y12 nohead"}' grace.dat

you'll get this output:

set arrow from 0.00000,Y11 to 0.00000,Y12 nohead
set arrow from 0.67643,Y11 to 0.67643,Y12 nohead
set arrow from 1.06696,Y11 to 1.06696,Y12 nohead
set arrow from 1.84803,Y11 to 1.84803,Y12 nohead
set arrow from 1.98549,Y11 to 1.98549,Y12 nohead
set arrow from 2.66192,Y11 to 2.66192,Y12 nohead
set arrow from 3.05245,Y11 to 3.05245,Y12 nohead
set arrow from 3.83352,Y11 to 3.83352,Y12 nohead
Rogelio Prieto
  • 359
  • 3
  • 10
  • Dear Rogelio, I could you your reply for first query by removing set xtics from the script to out and keeping it at the start and it worked. But I am not able to use your second reply. Please see my next reply – astha Sep 12 '19 at 15:31
  • 1
    Could you please modify your second reply in such a way that it works like a loop which contains "arrow from 0.00000,Y11 to 0.00000,Y12 nohead" in variable (say it is VARIABLE) form and then set VARIABLE will print the same output what your script gives. – astha Sep 12 '19 at 16:14
  • In this answer Y11 is set to -10 and Y12 is set to 10: `awk 'BEGIN {FS=", *";mycoord1=-10;mycoord2=10}/tick major +[0-9]+/{myfield1=$2;getline;gsub(" ","");print "set arrow from "myfield1","mycoord1" to "myfield1","mycoord2" nohead"}' grace.dat` – Rogelio Prieto Sep 12 '19 at 16:31
  • Thanks Prof. Rogelio but still I am not able to use it in gnuscript. on terminal it is working fine. My asim from this is to draw arrow in a graph. – astha Sep 12 '19 at 17:21
  • You should accept this answer because the topic is inside awk tag!. You need to post using gnuplot tag. Similar question are here: – Rogelio Prieto Sep 12 '19 at 20:23
  • You should accept this answer because the topic is inside awk tag!. You need to post using gnuplot tag. Similar question are here: https://stackoverflow.com/questions/53519962/how-to-run-a-shell-command-in-gnuplot-and-place-the-output-in-new-file In 3.7: http://www.gnuplot.info/faq/faq.html – Rogelio Prieto Sep 12 '19 at 20:34