Search code examples
stringif-statementgnuplot

Gnuplot and if contition not working with string variables


I have a file with 7 columns like:


KOKEE               TIGOCONC              1.21143392716200008E-002   9999.0000000000000       1.21143404344029992E-002  1.21143392665158823E-002  1.21143392665158823E-002  
KOKEE               WESTFORD             -1.97799503925290016E-003   9999.0000000000000      -1.97799445968519991E-003 -1.97799503786376526E-003 -1.97799503786376526E-003  
SESHAN25            WETTZELL              1.39989741037330005E-002   9999.0000000000000       1.39989741037330005E-002  1.39989740975521026E-002  1.39989740975521026E-002  
WESTFORD            WETTZELL             -1.74290229035720004E-003   9999.0000000000000      -1.74290124344059997E-003 -1.74290228675636817E-003 -1.74290228675636817E-003  
KOKEE               SESHAN25             -3.83187032666899982E-003   9999.0000000000000      -3.83186908442739987E-003 -3.83187032349491209E-003 -3.83187032349491209E-003  
```

I want to plot the rest of two columns in case $1 eq KOKEE. (I have no isse when the variable is a number)
So, my command is:

plot [][-0.002:0.0025] 'outall.txt' u ($1 eq "KOKEE" ?($3-$7)*299792458:1/0) title "by source" w p pt 7 ps 1

and the system says:
internal error : STRING operator applied to undefined or non-STRING variable

         1

As far as I could see in other post, this should be fine

Solution

  • $1 is interpreted as floating point number. If you want to compare column 1 as string you have to take strcol(1), check help stringcolumn.

    Your plotting command would be:

    plot [][-0.002:0.0025] $Data u (strcol(1) eq "KOKEE" ? ...