
# --- configuration ---
datafilec = "../ANASEN_analysis/PW_study_Sudarsan/cathode1_2.dat"
datafilea = "../ANASEN_analysis/PW_study_Sudarsan/anode1_2.dat"
datafileqr = "../ANASEN_analysis/PW_study_Sudarsan/qqq_rings_geometry.dat"
datafileqw = "../ANASEN_analysis/PW_study_Sudarsan/qqq_wedges_geometry.dat"

set datafile separator ","

N = 24   #number of cids

# --- allocate arrays ---
array ca1x[N]
array an1x[N]
array ca1y[N]
array an1y[N]
array ca1z[N]
array an1z[N]
array ca2x[N]
array an2x[N]
array ca2y[N]
array an2y[N]
array ca2z[N]
array an2z[N]
array qqqW_Phi[64] 
array qqqR_Rho[16]

# --- initialize (optional but safe) ---
do for [i=1:N] {
    ca1x[i] = ca1y[i] = ca1z[i] = NaN;
    ca2x[i] = ca2y[i] = ca2z[i] = NaN;
    an1x[i] = an1y[i] = an1z[i] = NaN;
    an2x[i] = an2y[i] = an2z[i] = NaN;
}

do for [j=1:16] {
    do for [i=1:4] {
        qqqW_Phi[i*4+j] = NaN
    }
    qqqR_Rho[j] = NaN
}


# --- load table into arrays ---
stats datafilec using \
    (ca1x[int($1)+1] = $2, \
     ca1y[int($1)+1] = $3, \
     ca1z[int($1)+1] = $4, \
     ca2x[int($1)+1] = $5, \
     ca2y[int($1)+1] = $6, \
     ca2z[int($1)+1] = $7, 0) \
    nooutput

stats datafilea using \
    (an1x[int($1)+1] = $2, \
     an1y[int($1)+1] = $3, \
     an1z[int($1)+1] = $4, \
     an2x[int($1)+1] = $5, \
     an2y[int($1)+1] = $6, \
     an2z[int($1)+1] = $7, 0) \
    nooutput

set datafile separator "\t"
stats datafileqr using \
    (qqqR_Rho[int($1)+1] = $2, 0) \
    nooutput

stats datafileqw using \
    (qqqW_Phi[(int($1))*4+int($2)+1] = $3, 0) \
    nooutput

#do for [i=1:N] {
#    print sprintf("Data[%d] = %g", i, an1x[i])
#    print sprintf("Data[%d] = %g", i, ca1x[i])
#}

set datafile separator whitespace
#plot '< cat /tmp/coords | grep q' u (ca1x[int($2)+1]):(ca1y[int($2)+1]):(ca1x[int($2)+1]):(ca1y[int($2)+1]) w vector

#pause mouse key
