Help with AWK script please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with AWK script please
# 1  
Old 01-31-2012
Help with AWK script please

Hello All,

I am working on a code with my adviser,but have run into some problems. I was wondering: Can anyone see what I am doing wrong and/or point me in the right direction. I have an experiment where objects are presented in a circular display, and rotate clockwise or counter depending on the trial. The output produced by the awk file below is erroneous. I appreciate any help on this issue.

Sample file:

RIAL_LABEL TRIAL_START_TIME TRIAL_FIXATION_TOTAL TARGET_LOCATION CURRENT_FIX_INDEX CURRENT_FIX_X CURRENT_FIX_Y CURRENT_FIX_START CURRENT_FIX_END rotation targettype distractortype targetFixated targetName distractorName

Trial: 1 442393 6 (289, 161) 1 496.10 379.20 7 427 0 1 1 1 ironboard_n.jpg ironboard_n.jpg

Trial: 1 442393 6 (289, 161) 2 509.00 373.10 572 848 0 1 1 1 ironboard_n.jpg ironboard_n.jpg

Trial: 1 442393 6 (289, 161) 3 225.60 377.40 898 1029 0 1 1 1 ironboard_n.jpg ironboard_n.jpg

Trial: 1 442393 6 (289, 161) 4 370.30 237.00 1083 1355 0 1 1 1 ironboard_n.jpg ironboard_n.jpg

Trial: 1 442393 6 (289, 161) 5 274.60 185.30 1393 1777 0 1 1 1 ironboard_n.jpg ironboard_n.jpg

Trial: 1 442393 6 (289, 161) 6 274.10 167.10 1797 1986 0 1 1 1 ironboard_n.jpg ironboard_n.jpg

Trial: 2 671034 5 (631, 673) 1 507.20 387.30 7 1158 -1 0 2 1 mailbox_c.jpg mailbox_n.jpg

Trial: 2 671034 5 (631, 673) 2 496.90 684.30 1214 1422 -1 0 2 1 mailbox_c.jpg mailbox_n.jpg

Trial: 2 671034 5 (631, 673) 3 392.40 659.60 1459 1589 -1 0 2 1 mailbox_c.jpg mailbox_n.jpg

Trial: 2 671034 5 (631, 673) 4 616.50 660.40 1637 1908 -1 0 2 1 mailbox_c.jpg mailbox_n.jpg

Trial: 2 671034 5 (631, 673) 5 618.40 646.80 1917 2212 -1 0 2 1 mailbox_c.jpg mailbox_n.jpg

Trial: 3 687547 3 (289, 605) 1 514.30 385.50 7 1119 0 1 2 1 gummachine_n.jpg gummachine_n.jpg

Trial: 3 687547 3 (289, 605) 2 282.30 592.50 1177 1508 0 1 2 1 gummachine_n.jpg gummachine_n.jpg

Trial: 3 687547 3 (289, 605) 3 302.90 604.60 1530 1766 0 1 2 1 gummachine_n.jpg gummachine_n.jpg

Trial: 4 693219 2 (289, 605) 1 513.80 385.40 7 1147 0 0 1 1 chimes_c.jpg chimes_c.jpg

Trial: 4 693219 2 (289, 605) 2 297.40 580.50 1204 1784 0 0 1 1 chimes_c.jpg chimes_c.jpg

Trial: 5 697132 2 (289, 605) 1 516.00 392.10 7 1084 0 0 1 1 ancor_c.jpg ancor_c.jpg

Trial: 5 697132 2 (289, 605) 2 304.20 582.80 1141 1725 0 0 1 1 ancor_c.jpg ancor_c.jpg

Trial: 6 701652 6 (631, 93) 1 515.00 386.40 7 1116 1 1 1 1 construction_n.jpg officechair_n.jpg

Trial: 6 701652 6 (631, 93) 2 517.60 75.40 1186 1371 1 1 1 1 construction_n.jpg officechair_n.jpg

Trial: 6 701652 6 (631, 93) 3 501.60 84.50 1384 1521 1 1 1 1 construction_n.jpg officechair_n.jpg

Trial: 6 701652 6 (631, 93) 4 626.80 78.50 1562 1893 1 1 1 1 construction_n.jpg officechair_n.jpg

Trial: 6 701652 6 (631, 93) 5 449.70 89.20 1926 2051 1 1 1 1 construction_n.jpg officechair_n.jpg

Trial: 6 701652 6 (631, 93) 6 670.90 91.60 2098 2144 1 1 1 1 construction_n.jpg officechair_n.jpg

Trial: 7 706907 2 (197, 383) 1 514.30 387.90 7 1149 0 0 2 1 mailbox_c.jpg mailbox_c.jpg

Trial: 7 706907 2 (197, 383) 2 202.40 358.20 1200 1777 0 0 2 1 mailbox_c.jpg mailbox_c.jpg

Trial: 8 711330 2 (289, 605) 1 514.10 392.50 7 1240 0 0 1 1 banklamp_c.jpg banklamp_c.jpg

Trial: 8 711330 2 (289, 605) 2 292.30 575.80 1288 1876 0 0 1 1 banklamp_c.jpg banklamp_c.jpg

Trial: 9 715869 2 (733, 605) 1 516.90 389.70 7 1062 0 0 2 1 50gallondrum_c.jpg 50gallondrum_c.jpg

Trial: 9 715869 2 (733, 605) 2 730.60 615.50 1119 1709 0 0 2 1 50gallondrum_c.jpg 50gallondrum_c.jpg

Trial: 10 719220 4 (197, 383) 1 515.10 389.00 7 1184 0 1 0 1 razor_n.jpg razor_n.jpg

Trial: 10 719220 4 (197, 383) 2 230.00 370.20 1237 1394 0 1 0 1 razor_n.jpg razor_n.jpg

Trial: 10 719220 4 (197, 383) 3 190.80 357.40 1428 1588 0 1 0 1 razor_n.jpg razor_n.jpg

Trial: 10 719220 4 (197, 383) 4 213.80 354.30 1609 1828 0 1 0 1 razor_n.jpg razor_n.jpg

Trial: 11 723475 3 (511, 69) 1 518.80 388.20 7 1122 0 0 1 1 house_c.jpg house_c.jpg

Trial: 11 723475 3 (511, 69) 2 507.50 75.90 1207 1624 0 0 1 1 house_c.jpg house_c.jpg

Trial: 11 723475 3 (511, 69) 3 534.90 70.50 1647 1794 0 0 1 1 house_c.jpg house_c.jpg

Trial: 12 727420 5 (801, 503) 1 513.80 388.40 7 1146 -1 0 2 1 banana_c.jpg banana_n.jpg

Code:
BEGIN{FS="\t"; RS="\n"; d=50;
    xx[0]= 511;yy[0]= 69;	
    xx[1]= 631;yy[1]= 93;
    xx[2]= 733;yy[2]= 161;
    xx[3]= 801;yy[3]= 263;
    xx[4]= 825;yy[4]= 383;
    xx[5]= 801;yy[5]= 503;
    xx[6]= 733;yy[6]= 605;
    xx[7]= 631;yy[7]= 673;
    xx[8]= 511;yy[8]= 697;
    xx[9]= 391;yy[9]= 673;
    xx[10]=289;yy[10]= 605;
    xx[11]=221;yy[11]= 503;
    xx[12]=197;yy[12]= 383;
    xx[13]=221;yy[13]= 263;
    xx[14]=289;yy[14]= 161;
    xx[15]=391;yy[15]= 93;
}
{
   
    xxxx=xxxx+1;
    if(xxxx>5){
#   if(subj!=$1){ print "END\n" >>subj;}
    }
    subj=$1;

    if	($4 == "(511, 69)"){pos=0;}	
    if	($4 == "(631, 93)"){pos=1;}
    if	($4 == "(733, 161)"){pos=2;}
    if	($4 == "(801, 263)"){pos=3;}
    if	($4 == "(825, 383)"){pos=4;}
    if	($4 == "(801, 503)"){pos=5;}
    if	($4 == "(733, 605)"){pos=6;}
    if	($4 == "(631, 673)"){pos=7;}
    if	($4 == "(511, 697)"){pos=8;}
    if	($4 == "(391, 673)"){pos=9;}
    if	($4 == "(289, 605)"){pos=10;}
    if	($4 == "(221, 503)"){pos=11;}
    if	($4 == "(197, 383)"){pos=12;}
    if	($4 == "(221, 263)"){pos=13;}
    if	($4 == "(289, 161)"){pos=14;}
    if	($4 == "(391, 93)"){pos=15;}

##	Generate point sets (The remainder works well when adding but not subtracting.)
##	Positions start at 0 and increase as you move counter clockwise around the circle.
##	So, on counter-clockwise rotation trials, the distractor will be 2 positions lower than
##	the final target position.  The following is a reference:
##
##     No Rotatio   Counter-Clockwise Rotation	Clockwise Rotation
##        0		15-0-1    1-2-3            15-14-13   1-0-15
##   14       2       13-14-15      3-4-5    13-12-11            3-2-1
## 12           4                     
##   10       6       11-12-13      5-6-7    11-10-9             5-4-3
##        8             9-10-11    7-8-9             9-8-7    7-6-5    
##

    
    tx=xx[pos];
    ty=yy[pos];
    
    
    if($10==(-1)){
	if(pos<15){
	    cx=xx[pos+1];
	    cy=yy[pos+1];
	    dx=xx[pos+2];
	    dy=yy[pos+2];
	}
	if(pos==15){
	    cx=xx[0];
	    cy=yy[0];
	    dx=xx[1];
	    dy=yy[1];
	}
    }
    if($10==1){
	if(pos>1){
	    cx=xx[pos-1];
	    cy=yy[pos-1];
	    dx=xx[pos-2];
	    dy=yy[pos-2];
	}
	if(pos==1){
	    cx=xx[0];
	    cy=yy[0];
	    dx=xx[15];
	    dy=yy[15];
	}
    }
    if($10==0){
	tx=cx=dx=xx[pos];
	ty=cy=dy=yy[pos];
    }

    if ($5==1){tn=tn+1; flag=0; time[0]=time[1]=0; accuracy="";}


    if (flag==0){
	if(sqrt(($6-cx)^2+($7-cy)^2) <= d){time[0]=$8;flag=1;fix0=$5}
    }
    if($10!=0){
	if (($5-1)==fix0 && flag==1 && sqrt(($6-tx)^2+($7-ty)^2) <= d){time[1]=$8-begin;flag=2;accuracy="c";correctcount=correctcount+1;}
#	if (($5-1)==fix0 && flag==1 && sqrt(($6-tx)^2+($7-ty)^2) <= d){time[1]=$8;flag=2;accuracy="c";correctcount=correctcount+1;}
#	if (($5-1)==fix0 && flag==1 && flag==1 && sqrt(($6-dx)^2+($7-dy)^2) <= d){time[1]=$8;flag=2;accuracy="e";errorcount=errorcount+1;}
	if (($5-1)==fix0 && flag==1 && flag==1 && sqrt(($6-dx)^2+($7-dy)^2) <= d){time[1]=$8-begin;flag=2;accuracy="e";errorcount=errorcount+1;}

    }


    begin=$10;
	
#### This means to print a easy to read description of time[0] and time[1] with trial labels, latency, and 
#### rotation. It is indicating something is wrong with the script: I have negative latencies sometimes.
    if (flag==2 && $10!=0) {
#	print $1 "\t" pos "\n"\
#	    "Crit   \t\t\t\t" cx "\t" cy "\t" time[0] "\n"\
#	    "Target \t\t\t" $12 "\t" tx "\t" ty "\n"\
#	    "Distra \t\t\t" $13 "\t" dx "\t" dy "\n"\
#	    "Actual \t\t\t\t" $6 "\t" $7 "\t" time[1] "\n"\
#	    "Error/correct: " accuracy "\n" \
#	    "Latency: " time[1]-time[0] "\t" "Rotation: " $10 "\t" "Flag: " flag "\t" "Trial Number: " tn "\n" \
#	    "-----------------------";
	flag=3;
	print accuracy time[1] "\n" $10+1 $11 $12 $13 pos; 
#       print accuracy time[1]-time[0] "\n" $11+1 $12 $13 $14 pos >> $1;              

    }
}
END{}

---------- Post updated at 06:23 PM ---------- Previous update was at 06:20 PM ----------

Trials look something like this:
No Rotatio Counter-Clockwise Rotation Clockwise Rotation
## 0 15-0-1 1-2-3 15-14-13 1-0-15
## 14 2 13-14-15 3-4-5 13-12-11 3-2-1
## 12 4
## 10 6 11-12-13 5-6-7 11-10-9 5-4-3
## 8 9-10-11 7-8-9 9-8-7 7-6-5
# 2  
Old 02-01-2012
To debug your (messy) code, put the print statements throughout the script. You'd see immediately, that variable "pos" is always empty.
You try to set the 'pos' var here:
Code:
  if	($4 == "(511, 69)"){pos=0;}

But the fourth field is not this, it is an integer before:
Code:
 Trial: 7 706907 2 (197, 383) 1 514.30 387.90 7 1149 0 0 2 1 mailbox_c.jpg mailbox_c.jpg

Furthermore, the pair (197, 383) has a space inbetween, so it's actually two fields. But wait, the FS is set to tab character, so you actually have only one filed ($1) in each line, since there are no tabs there. You could take out the FS="\t" line, and test for $5 $6:
Code:
  if	($5 $6 == "(511, 69)"){pos=0;}

but honestly, that code has so many errors, i suggest you rewrite it. Try to use 'case' statements, they are much more easier to read and less prone than nested if statements.
And I would take out the space from the paired values (511, 69) change to (511,69) so that the input is properly delimited, at least.
Good luck.

Last edited by mirni; 02-01-2012 at 12:15 AM..
# 3  
Old 02-10-2012
This code works on the above file:
Code:
  
BEGIN{FS="\t"; RS="\n"; d=50;
    xx[0]= 511;yy[0]= 69;     
    xx[1]= 631;yy[1]= 93;
    xx[2]= 733;yy[2]= 161;
    xx[3]= 801;yy[3]= 263;
    xx[4]= 825;yy[4]= 383;
    xx[5]= 801;yy[5]= 503;
    xx[6]= 733;yy[6]= 605;
    xx[7]= 631;yy[7]= 673;
    xx[8]= 511;yy[8]= 697;
    xx[9]= 391;yy[9]= 673;
    xx[10]=289;yy[10]= 605;
    xx[11]=221;yy[11]= 503;
    xx[12]=197;yy[12]= 383;
    xx[13]=221;yy[13]= 263;
    xx[14]=289;yy[14]= 161;
    xx[15]=391;yy[15]= 93;
}
{

    xxxx=xxxx+1;
    if(xxxx>5){
#   if(subj!=$1){ print "END\n" >>subj;}
    }
    subj=$1;

    if      ($5 == "(511, 69)"){pos=0;}   
    if      ($5 == "(631, 93)"){pos=1;}
    if      ($5 == "(733, 161)"){pos=2;}
    if      ($5 == "(801, 263)"){pos=3;}
    if      ($5 == "(825, 383)"){pos=4;}
    if      ($5 == "(801, 503)"){pos=5;}
    if      ($5 == "(733, 605)"){pos=6;}
    if      ($5 == "(631, 673)"){pos=7;}
    if      ($5 == "(511, 697)"){pos=8;}
    if      ($5 == "(391, 673)"){pos=9;}
    if      ($5 == "(289, 605)"){pos=10;}
    if      ($5 == "(221, 503)"){pos=11;}
    if      ($5 == "(197, 383)"){pos=12;}
    if      ($5 == "(221, 263)"){pos=13;}
    if      ($5 == "(289, 161)"){pos=14;}
    if      ($5 == "(391, 93)"){pos=15;}

##    Generate point sets (The remainder works well when adding but not subtracting.)
##    Positions start at 0 and increase as you move counter clockwise around the circle.
##    So, on counter-clockwise rotation trials, the distractor will be 2 positions lower than
##    the final target position.  The following is a reference:
##
##     No Rotatio   Counter-Clockwise Rotation  Clockwise Rotation
##        0       15-0-1    1-2-3            15-14-13   1-0-15
##   14       2       13-14-15      3-4-5    13-12-11            3-2-1
## 12           4                     
##   10       6       11-12-13      5-6-7    11-10-9             5-4-3
##        8             9-10-11    7-8-9             9-8-7    7-6-5    
##


    tx=xx[pos];
    ty=yy[pos];


    if($11==(-1)){
      if(pos<15){
          cx=xx[pos+1];
          cy=yy[pos+1];
          dx=xx[pos+2];
          dy=yy[pos+2];
      }
      if(pos==15){
          cx=xx[0];
          cy=yy[0];
          dx=xx[1];
          dy=yy[1];
      }
    }
    if($11==1){
      if(pos>1){
          cx=xx[pos-1];
          cy=yy[pos-1];
          dx=xx[pos-2];
          dy=yy[pos-2];
      }
      if(pos==1){
          cx=xx[0];
          cy=yy[0];
          dx=xx[15];
          dy=yy[15];
      }
    }
    if($11==0){
      tx=cx=dx=xx[pos];
      ty=cy=dy=yy[pos];
    }

    if ($6==1){tn=tn+1; flag=0; time[0]=time[1]=0; accuracy="";}


    if (flag==0){
      if(sqrt(($7-cx)^2+($8-cy)^2) <= d){time[0]=$9;flag=1;fix0=$6}
    }
    if($11!=0){
      if (($6-1)==fix0 && flag==1 && sqrt(($7-tx)^2+($8-ty)^2) <= d){time[1]=$9-begin;flag=2;accuracy="c";correctcount=correctcount+1;}
#     if (($6-1)==fix0 && flag==1 && sqrt(($7-tx)^2+($8-ty)^2) <= d){time[1]=$9;flag=2;accuracy="c";correctcount=correctcount+1;}
#     if (($6-1)==fix0 && flag==1 && flag==1 && sqrt(($7-dx)^2+($8-dy)^2) <= d){time[1]=$9;flag=2;accuracy="e";errorcount=errorcount+1;}
      if (($6-1)==fix0 && flag==1 && flag==1 && sqrt(($7-dx)^2+($8-dy)^2) <= d){time[1]=$9-begin;flag=2;accuracy="e";errorcount=errorcount+1;}

    }


    begin=$10;

#### This means to print a easy to read description of time[0] and time[1] with trial labels, latency, and 
#### rotation. It is indicating something is wrong with the script: I have negative latencies sometimes.
    if (flag==2 && $11!=0) {
#     print $1 "\t" pos "\n"\
#         "Crit   \t\t\t\t" cx "\t" cy "\t" time[0] "\n"\
#         "Target \t\t\t" $12 "\t" tx "\t" ty "\n"\
#         "Distra \t\t\t" $13 "\t" dx "\t" dy "\n"\
#         "Actual \t\t\t\t" $6 "\t" $7 "\t" time[1] "\n"\
#         "Error/correct: " accuracy "\n" \
#         "Latency: " time[1]-time[0] "\t" "Rotation: " $10 "\t" "Flag: " flag "\t" "Trial Number: " tn "\n" \
#         "-----------------------";
      flag=3;
      print accuracy time[1] "\n" $11+1 $12 $13 $14 pos; 
#       print accuracy time[1]-time[0] "\n" $11+1 $12 $13 $14 pos >> $1;              

    }
}
END{}
   ]

However, when I wanted to change it up a little bit, for another experiment, and have the target appear in only four positions I run into more errors.

I have a file that looks like this:

RECORDING_SESSION_LABEL TRIAL_START_TIME TRIAL_FIXATION_TOTAL CURRENT_FIX_INDEX CURRENT_FIX_X CURRENT_FIX_Y CURRENT_FIX_START CURRENT_FIX_END identifier trialtype cueimage preimage staticimage rotatedimage targetloc targetroc rot
1092166997352530.8366.8230836101stimN181cue.jpgstimN181pre.jpgstimN181sta.jpgstimN181-of1.jpgright-718,303-11092166997353688.3367.18791077101stimN181cue.jpgstimN181pre.jpgstimN181sta.jpgstimN181-of1.jpgright(718, 303)-11092166997354561.1356.611061323101stimN181cue.jpgstimN181pre.jpgstimN181sta.jpgstimN181-of1.jpgright(718, 303)-11092166997355687.9297.913661596101stimN181cue.jpgstimN181pre.jpgstimN181sta.jpgstimN181-of1.jpgright(718, 303)-11092158626431508.3391.27235110stimN191cue.jpgstimN191pre.jpgstimN191sta.jpgstimN191-of1.jpgright(718, 303)-11092158626432360.1375.7276711110stimN191cue.jpgstimN191pre.jpgstimN191sta.jpgstimN191-of1.jpgright(718, 303)-11092158626433693.8378765813110stimN191cue.jpgstimN191pre.jpgstimN191sta.jpgstimN191-of1.jpgright(718, 303)-11092158843631516.8367.67746120stimN201cue.jpgstimN201pre.jpgstimN201sta.jpgstimN201-of1.jpgright(718, 303)-11092158843632649.6372.5774909120stimN201cue.jpgstimN201pre.jpgstimN201sta.jpgstimN201-of1.jpgright(718, 303)-11092158843633700.9365.29301110120stimN201cue.jpgstimN201pre.jpgstimN201sta.jpgstimN201-of1.jpgright(718, 303)-11092157832251510.3374.87271131stimN211cue.jpgstimN211pre.jpgstimN211sta.jpgstimN211-of1.jpgright(718, 303)-11092157832252531.3373.3280751131stimN211cue.jpgstimN211pre.jpgstimN211sta.jpgstimN211-of1.jpgright(718, 303)-11092157832253675.2372.57821040131stimN211cue.jpgstimN211pre.jpgstimN211sta.jpgstimN211-of1.jpgright(718, 303)-11092157832254707.334910581169131stimN211cue.jpgstimN211pre.jpgstimN211sta.jpgstimN211-of1.jpgright(718, 303)-1109215783225572029411941431131stimN211cue.jpgstimN211pre.jpgstimN211sta.jpgstimN211-of1.jpgright(718, 303)-11092170561551516.63847213141stimN21cue.jpgstimN21pre.jpgstimN21sta.jpgstimN21-of1.jpgright(718, 303)-11092170561552529374223752141stimN21cue.jpgstimN21pre.jpgstimN21sta.jpgstimN21-of1.jpgright(718, 303)-11092170561553699.6361.67941045141stimN21cue.jpgstimN21pre.jpgstimN21sta.jpgstimN21-of1.jpgright(718, 303)-11092170561554701.932910631224141stimN21cue.jpgstimN21pre.jpgstimN21sta.jpgstimN21-of1.jpgright(718, 303)-11092170561555715.428012451293141stimN21cue.jpgstimN21pre.jpgstimN21sta.jpgstimN21-of1.jpgright(718, 303)-11092176406941516.8370.27211150stimN221cue.jpgstimN221pre.jpgstimN221sta.jpgstimN221-of1.jpgright(718, 303)-11092176406942532.1370219708150stimN221cue.jpgstimN221pre.jpgstimN221sta.jpgstimN221-of1.jpgright(718, 303)-11092176406943658.1365.5750897150stimN221cue.jpgstimN221pre.jpgstimN221sta.jpgstimN221-of1.jpgright(718, 303)-11092176406944711.53639181152150stimN221cue.jpgstimN221pre.jpgstimN221sta.jpgstimN221-of1.jpgright(718, 303)-11092162016551506.7376.67270161stimN231cue.jpgstimN231pre.jpgstimN231sta.jpgstimN231-of1.jpgright(718, 303)-11092162016552520.5371.2278709161stimN231cue.jpgstimN231pre.jpgstimN231sta.jpgstimN231-of1.jpgright(718, 303)-11092162016553669363.2746927161stimN231cue.jpgstimN231pre.jpgstimN231sta.jpgstimN231-of1.jpgright(718, 303)-11092162016554701.2421.89521016161stimN231cue.jpgstimN231pre.jpgstimN231sta.jpgstimN231-of1.jpgright(718, 303)-11092162016555707338.610491183161stimN231cue.jpgstimN231pre.jpgstimN231sta.jpgstimN231-of1.jpgright(718, 303)-11092170335241523.1393.37222170stimN241cue.jpgstimN241pre.jpgstimN241sta.jpgstimN241-of1.jpgright(718, 303)-11092170335242523.2386.7230404170stimN241cue.jpgstimN241pre.jpgstimN241sta.jpgstimN241-of1.jpgright(718, 303)-11092170335243373.9359.2442691170stimN241cue.jpgstimN241pre.jpgstimN241sta.jpgstimN241-of1.jpgright(718, 303)-11092170335244674.2361.3733819170stimN241cue.jpgstimN241pre.jpgstimN241sta.jpgstimN241-of1.jpgright(718, 303)-11092161482931521.63717881180stimN251cue.jpgstimN251pre.jpgstimN251sta.jpgstimN251-of1.jpgright(718, 303)-11092161482932642.1368.19171050180stimN251cue.jpgstimN251pre.jpgstimN251sta.jpgstimN251-of1.jpgright(718, 303)-11092161482933687.3369.210711263180stimN251cue.jpgstimN251pre.jpgstimN251sta.jpgstimN251-of1.jpgright(718, 303)-11092168294121522.4374.57843190stimN261cue.jpgstimN261pre.jpgstimN261sta.jpgstimN261-of1.jpgright(718, 303)-11092168294122697.9369.78821075190stimN261cue.jpgstimN261pre.jpgstimN261sta.jpgstimN261-of1.jpgright(718, 303)-11092163358051524.3372.27766201stimN271cue.jpgstimN271pre.jpgstimN271sta.jpgstimN271-of1.jpgright(718, 303)-11092163358052672.1371.7797991201stimN271cue.jpgstimN271pre.jpgstimN271sta.jpgstimN271-of1.jpgright(718, 303)-11092163358053701.9413.310121049201stimN271cue.jpgstimN271pre.jpgstimN271sta.jpgstimN271-of1.jpgright(718, 303)-11092163358054702.1336.710741243201stimN271cue.jpgstimN271pre.jpgstimN271sta.jpgstimN271-of1.jpgright(718, 303)-11092163358055719292.312631316201stimN271cue.jpgstimN271pre.jpgstimN271sta.jpgstimN271-of1.jpgright(718, 303)-11092173277841526.13777865211stimN281cue.jpgstimN281pre.jpgstimN281sta.jpgstimN281-of1.jpgright(718, 303)-11092173277842683.5370.29071090211stimN281cue.jpgstimN281pre.jpgstimN281sta.jpgstimN281-of1.jpgright(718, 303)-11092173277843707.9422.911151242211stimN281cue.jpgstimN281pre.jpgstimN281sta.jpgstimN281-of1.jpgright(718, 303)-11092173277844709.5289.212791343211stimN281cue.jpgstimN281pre.jpgstimN281sta.jpgstimN281-of1.jpgright(718, 303)-110921506395121506.7408.17295221stimN31cue.jpgstimN31pre.jpgstimN31sta.jpgstimN31-of1.jpgright(718, 303)-110921506395122519.7408.8302851221stimN31cue.jpgstimN31pre.jpgstimN31sta.jpgstimN31-of1.jpgright(718, 303)-110921506395123703.5408.29261128221stimN31cue.jpgstimN31pre.jpgstimN31sta.jpgstimN31-of1.jpgright(718, 303)-110921506395124696.3356.311511271221stimN31cue.jpgstimN31pre.jpgstimN31sta.jpgstimN31-of1.jpgright(718, 303)-1
I changed the code up a bit, it follows the same logic as the above code, but instead of printing trial numbers I want the code to print accurary, error, and the identifier field. I get some syntax errors.


[CODEBEGIN{FS="\t"; RS="\n"; d=50;
xx[0]= 523;yy[0]= 183;
xx[1]= 602;yy[1]= 169;
xx[2]= 668;yy[2]= 240;
xx[3]= 718;yy[3]= 303; #counter
xx[4]= 737;yy[4]= 379;
xx[5]= 715;yy[5]= 447; #clock
xx[6]= 669;yy[6]= 512;
xx[7]= 602;yy[7]= 554;
xx[8]= 523;yy[8]= 571;
xx[9]= 444;yy[9]= 553;
xx[10]=379;yy[10]= 512;
xx[11]=338;yy[11]= 452; #counter
xx[12]=327;yy[12]= 378;
#xx[13]=339;yy[13]= 300; #clock
xx[14]=377;yy[14]= 239;
xx[15]=446;yy[15]= 198;
}
{

xxxx=xxxx+1;
if(xxxx>5){
# if(subj!=$1){ print "END\n" >>subj;}
}
subj=$1;
if ($16 == "(718, 303)"){pos=3;}
if ($16 == "(715, 447)"){pos=5;} # target can only appear in one of four places as indicated
if ($16 == "(338, 452)"){pos=11;}
if ($16 == "(339, 300)"){pos=13;}
## Generate point sets (The remainder works well when adding but not subtracting.)
## Positions start at 0 and increase as you move counter clockwise around the circle.
## So, on counter-clockwise rotation trials, the distractor will be 2 positions lower than
## the final target position. The following is a reference:
##
## No Rotatio Counter-Clockwise Rotation Clockwise Rotation
## 0 15-0-1 1-2-3 15-14-13 1-0-15
## 14 2 13-14-15 3-4-5 13-12-11 3-2-1
## 12 4
## 10 6 11-12-13 5-6-7 11-10-9 5-4-3
## 8 9-10-11 7-8-9 9-8-7 7-6-5
##

tx=xx[pos];
ty=yy[pos];


if($17==(-1)){
if(pos<11){
cx=xx[pos+1];
cy=yy[pos+1];
dx=xx[pos+2];
dy=yy[pos+2];
}
if(pos==11){
cx=xx[0];
cy=yy[0];
dx=xx[1];
dy=yy[1];
}
}
if($17==1){
if(pos>3){
cx=xx[pos-1];
cy=yy[pos-1];
dx=xx[pos-2];
dy=yy[pos-2];
}
if(pos==3){
cx=xx[0];
cy=yy[0];
dx=xx[15];
dy=yy[15];
}
}
if($10==0){
tx=cx=dx=xx[pos];
ty=cy=dy=yy[pos];
}
if ($4==1){tn=tn+1; flag=0; time[0]=time[1]=0; accuracy="";}

if (flag==0){
if(sqrt(($5-cx)^2+($6-cy)^2) <= d){time[0]=$7;flag=1;fix0=$4}
}
if($10!=0){
if (($4-1)==fix0 && flag==1 && sqrt(($5-tx)^2+($6-ty)^2) <= d){time[1]=$7-begin;flag=2;accuracy="c";correctcount=correctcount+1;}
# if (($4-1)==fix0 && flag==1 && sqrt(($5-tx)^2+($6-ty)^2) <= d){time[1]=$8;flag=2;accuracy="c";correctcount=correctcount+1;}
# if (($4-1)==fix0 && flag==1 && flag==1 && sqrt(($5-dx)^2+($6-dy)^2) <= d){time[1]=$7;flag=2;accuracy="e";errorcount=errorcount+1;}
if (($4-1)==fix0 && flag==1 && flag==1 && sqrt(($5-dx)^2+($6-dy)^2) <= d){time[1]=$7-begin;flag=2;accuracy="e";errorcount=errorcount+1;}
}

begin=$8;

#### This means to print a easy to read description of time[0] and time[1] with trial labels, latency, and
#### rotation. It is indicating something is wrong with the script: I have negative latencies sometimes.
if (flag==2 && $10!=0) {
# print $1 "\t" pos "\n"\
# "Crit \t\t\t\t" cx "\t" cy "\t" time[0] "\n"\
# "Target \t\t\t" $12 "\t" tx "\t" ty "\n"\
# "Distra \t\t\t" $13 "\t" dx "\t" dy "\n"\
# "Actual \t\t\t\t" $4 "\t" $5 "\t" time[1] "\n"\
# "Error/correct: " accuracy "\n" \
# "Latency:" time[1]-time[0] "\t" "Rotation: " $17 "\t" "Flag: "
flag=3;
print accuracy time[1] "\n" $9 pos
# print accuracy time[1]-time[0] "\n" $11+1 $12 $13 $14 pos >> $1;
}
}
END{}
[/CODE]

Last edited by vbe; 02-10-2012 at 04:48 PM.. Reason: corrected code tags - nice try...
# 4  
Old 02-14-2012
Any suggestions?
# 5  
Old 02-14-2012
Quote:
This code works on the above file:
It may run without errors, but it doesn't do anything useful -- it doesn't print anything. The FS is set to "\t" but there are no tabs in the sample input you posted.
Quote:
I get some syntax errors.
Like what? Can you please post the errors you are getting? What system are you on? Which awk are you using? What is your desired output?

Quote:
Any suggestions?
You should take the time to post the exact input and desired output, using CODE tags, and be more specific about your problems, to increase your chances of getting help. Just posting a bunch of code is not enough.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

awk script to call another script based on second column entry

Hi I have a text file (Input.txt) with two column entries separated by tab as given below: aaa str1 bbb str2 cccccc str3 dddd str4 eee str3 ssss str2 sdf str3 hhh str1 fff str2 ccc str3 ..... ..... ..... (1 Reply)
Discussion started by: my_Perl
1 Replies

3. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

4. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

5. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

6. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

Help: How to convert this bash+awk script in awk script only?

This is the final first release of the dynamic menu generator for pekwm (WM). #!/bin/bash function param_val { awk "/^${1}=/{gsub(/^${1}="'/,""); print; exit}' $2 } echo "Dynamic {" for CF in `ls -c1 /usr/share/applications/*.desktop` do name=$(param_val Name $CF) ... (3 Replies)
Discussion started by: alexscript
3 Replies

8. Shell Programming and Scripting

Call shell script function from awk script

hi everyone i am trying to do this bash> cat abc.sh deepak() { echo Deepak } deepak bash>./abc.sh Deepak so it is giving me write simply i created a func and it worked now i modified it like this way bash> cat abc.sh (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

9. Shell Programming and Scripting

want to pass parameters to awk script from shell script

Hello, I have this awk script that I want to execute by passing parameters through a shell script. I'm a little confused. This awk script removes duplicates from an input file. Ok, so I have a .sh file called rem_dups.sh #!/usr/bin/sh... (4 Replies)
Discussion started by: script_op2a
4 Replies

10. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question