#!/bin/ksh # extract dm-format data from a single sl4 datafile given in arg1 and # save the result in sRRpS.dm, where RR is the randomization, p is the # pair (a or b), and S is the SOA code (S+00 unless S=0, in which case 1000). # The output is written into the same directory as the input file. # Two versions are written, one with an initial flag column, the without # added flg column 1: # p = response to prime # n = no response # z = rt <= 0 # we want: sid [grp] [prm targ] ptype ttype res rt # we skip all header lines (always 6?) # there are three types of data lines, all with 17 columns: # 1 2 3 4 5 6 7 8 9 10 11 .... #Grp Sid Blk Trial&num Event&details R K H Expected C RT .... #YN upipfh Experimental_Blocks Experimental_Trial,_1 ITI_(1,_1_coffin_agriot_up_nw) _ _ _ (any_response) NR 0 _ _ _ _ _ _ #YN upipfh Experimental_Blocks Experimental_Trial,_1 Prime_(1,_COFFIN) _ _ _ (any_response) NR 0 _ _ _ _ _ _ #YN upipfh Experimental_Blocks Experimental_Trial,_1 Target_(1,_AGRIOT) Yes 1 Pressed Yes;_No C 756 _ _ _ _ _ _ # R = response label # K = key # H = how responded # C = classification of response err(){ print -u2 "Err: $*" exit 1 } if [[ "$1" == "" ]] ; then err "Usage: cvtsl4 sl4file.txt" fi infile=$1 # ITI_(1,_1_coffin_agriot_up_nw) function getinfo { typeset ev i x ev=$1 ev=${ev//[()]/} ev=${ev//,/} ev=${ev//_/ } sp= info= ((i=0)) for x in $ev ; do ((i++)) if [[ i -lt 3 ]] ; then continue fi info=$info$sp$x sp=" " done } # set the variable ms to the soa # the name is sCCpX where X is the # soa code setms(){ expcode=`head -2 < $infile | tail -1` soa=${expcode#????} if [[ $soa == 0 ]] ; then ms=1000 else ms=${soa}00 fi } setms $infile oufile=$(dirname $infile)/$expcode.dm flgfile=$(dirname $infile)/$expcode.dm-flg flg= exec 5> $flgfile.tmp tab2dm 6 < $infile | dm "'$expcode'" INPUT \ | while read set grp sid blo tri evnt rlab rkey rhow rexpect rclass rt junque ; do case $evnt in ITI* ) getinfo $evnt ; continue ;; Prime* ) if [[ $rclass != NR || $rt -gt 0 ]] ; then flg=p$flg fi continue ;; Target* ) ;; Pressed ) print -u2 "$grp $set.$sid $blo $tri $evnt $rlab $rkey $rhow $rexpect $rclass $rt $junque" ;; * ) err "Unknown event '$evnt'" ;; esac # this should weed out certain superlab glitches if [[ $rclass == NR ]] ; then flg=n$flg fi if [[ $rt -le 0 ]] ; then flg=z$flg fi if [[ "$flg" == "" ]] ; then flg=ok fi print -u5 $flg $set.$sid $grp $ms $info $rkey $rt # only "perfect" or prime-reponse trials are kept if [[ $flg == ok || $flg == p ]] ; then print $set.$sid $grp $ms $info $rkey $rt fi flg= done | tr A-Z a-z > $oufile touch -r $infile $oufile tr A-Z a-z < $flgfile.tmp > $flgfile ; rm $flgfile.tmp exit 0