P.S.
Sam's "plotgroup" x-function shines nicely in most cases with reasonable number of
plot groups. If there are thousands like your case, you can still try my method.
Also, if you want to make vector plots to indicate the direction, you can modify my script like below.
Hope this suggestion helps people someway who visit this post.
//////////////////////////////////////////////////
nc=wks.nCols;
nr=wks.maxRows;
wks1$=%H;
window -t wks;
wks2$=%H;
worksheet -a 4;
//Set Long Names
range ri=[wks1$]1!col(1); range ro=[wks2$]1!col(1); ro[L]$=ri[L]$;
range ro=[wks2$]1!col(2); ro[L]$="X1";
range ro=[wks2$]1!col(3); ro[L]$="Y1";
range ro=[wks2$]1!col(4); ro[L]$="X2";
range ro=[wks2$]1!col(5); ro[L]$="Y2";
range ri=[wks1$]1!col(4); range ro=[wks2$]1!col(6); ro[L]$=ri[L]$;
wks.col1.type=2; //Set 1st col as Disregard
wks.col2.type=4; //Set 2nd col as X
wks.col4.type=4; //Set 4th col as X
curr=-1;
for(ii=1; ii<nr; ii++) {
range r1=[wks1$]1!col(1);
curr=r1[ii];
if(r1[ii+1]!=curr) {
for(kk=1; kk<=nc+2; kk++) {
range ro=[wks2$]1!wcol(kk);
ro[ii]=1/0; //insert missing value
}
}
else { //copy cells
range ri=[wks1$]1!col(1); range ro=[wks2$]1!col(1); ro[ii]=ri[ii];
range ri=[wks1$]1!col(2); range ro=[wks2$]1!col(2); ro[ii]=ri[ii];
range ri=[wks1$]1!col(3); range ro=[wks2$]1!col(3); ro[ii]=ri[ii];
range ri=[wks1$]1!col(2); range ro=[wks2$]1!col(4); ro[ii]=ri[ii+1];
range ri=[wks1$]1!col(3); range ro=[wks2$]1!col(5); ro[ii]=ri[ii+1];
range ri=[wks1$]1!col(4); range ro=[wks2$]1!col(6); ro[ii]=ri[ii];
}
}
//////////////////////////////////////////////////