Re: 回?: 回?: 回?: system c ommand in gnuplot
Andrew Rasmussen <[email protected]>
| Newsgroups | gmane.comp.graphics.gnuplot.user |
|---|---|
| Message-ID | <CANrsd3y3JJ6ykZwT5yzONW-K_Hy2Lx5dJQDMJ6M5UwTYoaaAWg@mail.gmail.com> |
Without testing (I might have time later), there are two things that look like they need to be fixed: 1. in order for "./myscript.sh" not to have the 'Permission denied' error, it needs to be executable. You can do this on the command line with> chmod +x myscript.sh 2. When a bash script takes command line arguments, they have the names $1, $2, etc. So, you might have to change $k to $1. Andy On Wed, Dec 30, 2020 at 2:29 AM [email protected] < [email protected]> wrote: > Thanks for your answer. > > But there are some other problems. > > When I do > > >system("bash -c ./myscript.sh ".sprintf("%.1f", k)) > > An error appears : nan: ./myscript.sh: : Permission denied > > > > I modified the command as system("/bin/bash combine.sh ".sprintf("%.1f", > k)) > > The script is executed. However, not only passing the variable k, the > whole script is executed. > > > > What I want is that executing the > > plot for [k= 1: 20: 1] "< bash ./myscript.sh" u 1:2 > > the index of loop k can be paased into the script as a variable (the red > parameter as follow). > > > > The code in the script is > > paste <(cat Q_byE_i*.txt) <(cat Q_byM_i*.txt)|awk -v vtime=$k ' > {if($1==vtime*1.0) { e[$3] += $4; m[$3] += $9}} END { for ( i in e) { print > i , e[i], m[i], vtime}}' > > > > For your convenience to test, I send you some data files。 > > > > **************************************************** > 秦志豪 > 京都大学大学院 エネルギー科学研究科 > エネルギー基礎科学専攻 プラズマ・核融合基礎学分野 > 岸本研究室 > E-mail : [email protected] > **************************************************** > > > > *发件人: *Andrew Rasmussen <[email protected]> > *发送时间: *2020年12月30日 5:32 > *收件人: *[email protected] > *抄送: *[email protected] > *主题: *Re: 回?: 回?: [Gnuplot-info] system command in gnuplot > > > > You can definitely pass arguments to a bash script. In the script, you use > the arguments as variables $1, $2, etc. (Reference example: > https://www.golinuxcloud.com/beginners-guide-to-use-script-arguments-in-bash-with-examples/ > ). > > > > It will take some fiddling to construct the command in gnuplot, but if the > variables are var1 and var2 for example, you can do it like this: > > > > > system("bash -c ./myscript.sh ".var1." ".var2) > > > > The '.' concatenates the string variables. If var1 or var2 is a number > like 16.0 instead of a string "16.0", you might have to do something like > the below with sprintf to get it to turn into a string correctly: > > > > > system("bash -c ./myscript.sh ".var1." ".sprintf("%.1f", var2)) > > > > Andy > > > > On Tue, Dec 29, 2020 at 12:48 AM [email protected] < > [email protected]> wrote: > > Dear Andy > > As your advice, we can reduce syntax / escape errors by put the paste / > awk script in a separate file ("myscript.sh"). > > Then call it from inside gnuplot as plot "< bash ./myscript.sh" > > But if the data file name (Q_byE_i*.txt) is a string variable and “16.0” of > “if($1==16.0” in awk part is also a variable, > > How can I pass these variables from gnuplot into myscript.sh. > > > > Because I'm not very familiar with linux, my questions might be very basic > or stupid. > > please forgive me. > > **************************************************** > 秦志豪 > 京都大学大学院 エネルギー科学研究科 > エネルギー基礎科学専攻 プラズマ・核融合基礎学分野 > 岸本研究室 > E-mail : [email protected] > **************************************************** > > > > *发件人: *Andrew Rasmussen <[email protected]> > *发送时间: *2020年12月29日 1:13 > *收件人: *[email protected] > *抄送: *[email protected] > *主题: *Re: 回?: [Gnuplot-info] system command in gnuplot > > > > Yes, you should be able to make a similar modification, something like: > > > > plot "< bash -c 'paste <(cat Q_byE_i*.txt) <(cat Q_byM_i*.txt)|awk > \'{if($1==16.0) { e[$3] += $4 }}END { for ( i in e) { print i , e[i]}}\''" > > > > I can't test it out, so you might have to escape some additional > characters (* etc.). > > > > When you are using a command that is this complicated, a way to simplify > things and reduce syntax / escape errors is to put the paste / awk script > in a separate file ("myscript.sh") and call that script from inside gnuplot: > > > > plot "< bash ./myscript.sh" > > > > Andy > > > > On Mon, Dec 28, 2020 at 9:31 AM [email protected] < > [email protected]> wrote: > > Dear Andy > > > > Thank you very much. > > It worked. But I have another question. > > In fact, I tried to merge some data files, then plot a graph. > > The code is > > plot "< paste <(cat Q_byE_i*.txt) <(cat Q_byM_i*.txt)|awk '{if($1==16.0) > { e[$3] += $4 }}END { for ( i in e) { print i , e[i]}}'" u 1:2 > > > > The latter part of code about ‘awk’, I think there is no problem. Could I > modify the code as the system("bash -c 'paste <(ls Q*) <(ls F*)'")? > > > > Qin > > > > **************************************************** > 秦志豪 > 京都大学大学院 エネルギー科学研究科 > エネルギー基礎科学専攻 プラズマ・核融合基礎学分野 > 岸本研究室 > E-mail : [email protected] > **************************************************** > > > > *发件人: *Andrew Rasmussen <[email protected]> > *发送时间: *2020年12月28日 23:57 > *收件人: *[email protected] > *抄送: *[email protected] > *主题: *Re: [Gnuplot-info] system command in gnuplot > > > > Hello, > > > > Your error comes from the fact that gnuplot is running the system command > using the sh shell instead of bash (or whatever your usual shell is). You > can get the command to be interpreted by bash like this: > > > > system("bash -c 'paste <(ls Q*) <(ls F*)'") > > > > Andy > > > > On Mon, Dec 28, 2020 at 4:11 AM [email protected] < > [email protected]> wrote: > > Hello > > Now I am using gnuplot (Version 5.2 patchlevel 6) on a Linux system. > The information of operating system as follow > Linux version 4.4.162-94.72-default (geeko@buildhost) (gcc version 4.8.5 > (SUSE Linux) ) > LSB Version: n/a > Distributor ID: SUSE > Description: SUSE Linux Enterprise Server 12 SP3 > Release: 12.3 > Codename: n/a > > My question: > I am trying to launch a system command in gnuplot like > Terminal type is now 'qt' > gnuplot> system(" paste <(ls Q*) <(ls F*)") > > show me the error message as > sh: -c: line 0: syntax error near unexpected token `(' > sh: -c: line 0: ` paste <(ls Q*) <(ls F*)' > > But if I exit the gnuplot and run the command, it can work. > qin@csc1:~/qin /txt> paste <(ls Q*) <(ls F*) > > any help would be much appreciated > have a nice day > > **************************************************** > 秦志豪 > 京都大学大学院 エネルギー科学研究科 > エネルギー基礎科学専攻 プラズマ・核融合基礎学分野 > 岸本研究室 > E-mail : [email protected] > **************************************************** > > > _______________________________________________ > gnuplot-info mailing list > [email protected] > Membership management via: > https://lists.sourceforge.net/lists/listinfo/gnuplot-info > > > > > > > _______________________________________________ gnuplot-info mailing list [email protected] Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info