/*

    File:               ss_data.c
    Author:             michael stevens
    Experiment:         Stroop vs Simon experiment
                        Simon & Berbaum 1990

        Data-management and randomization

            Between:    Task (color/position relevant)
                        Response mapping

            Within:     Stimulus color (red/green)
                        Stimulus word (red/green)
                        Stimulus position (L/R)
                        Stimulus duration (100/400ms)

            Derived variables:
                        Congruency color/meaning word
                        Spatial correspondence stimulus/response

            Measured variables:
                        Response
                        Reaction time

            Time course experiment:
                        16 practice trials (every within cell appears once)
                        16 warmup trials (every within cell appears once)
                        192 experimental trials
                            (all within cells 3 times per block / 4 blocks)

*/


#include <tscope.h>

// number of levels of each variable
#define NTASK       2
#define NRESPMAP    2

#define NWORDS      2
#define NCOLORS     2
#define NPOS        2
#define NDUR        2

// number of trials
#define CELLS       (NWORDS*NCOLORS*NPOS*NDUR)
#define REPS        3
#define BLOCKLEN    (CELLS*REPS)
#define NBLOCK      4

#define NPRACT      CELLS
#define NWARMUP     CELLS
#define NEXP        (BLOCKLEN*NBLOCK)
#define NTRIALS     (NPRACT+NWARMUP+NEXP)

// data structure with all trial variables
struct {
    int session;
    int subj;
    enum { M, V } sex;

    enum { COLOR, MEANING } task;
    enum { RL, RR } respmap;    // red->left, red->right

    enum { PRACT, WARMUP, EXP } phase;
    int block;                  // 4 * 48 trials in experimental phase

    enum color { CRED, CGREEN } mword;  // MEANING word
    enum color cword;           // COLOR word
    enum pos { NORESP, LEFT, RIGHT } stimpos;
    enum { SHORTD, LONGD } stimdur;

    enum cong { INCONG, CONG } semcong; // semantic congruency
    enum cong spcong;           // spatial congruency

    enum pos xr;                // expected response
    enum pos r;                 // recorded response
    enum { E, C } corr;         // feedback

    int rt, re;                 // reaction time and measurement error
} data[NTRIALS];

// initialize all variables to -1
void initdata()
{
    int i;
    for (i = 0; i < NTRIALS; i++) {
        data[i].session = -1;
        data[i].subj = -1;
        data[i].sex = -1;
        data[i].task = -1;
        data[i].respmap = -1;
        data[i].phase = -1;
        data[i].block = -1;
        data[i].mword = -1;
        data[i].cword = -1;
        data[i].stimpos = -1;
        data[i].stimdur = -1;
        data[i].semcong = -1;
        data[i].spcong = -1;
        data[i].xr = -1;
        data[i].r = -1;
        data[i].corr = -1;
        data[i].rt = -1;
        data[i].re = -1;
    }
}

// write data
void writedata()
{
    // use session nr to determine filename
    char fname[40];
    sprintf(fname, "ss%03d.dat", data[0].session);

    // open file
    FILE *fp;
    fp = fopen(fname, "a+");

    if (fp == NULL) {
        printf("error opening output file %s.\n", fname);
        exit(EXIT_FAILURE);
    }
    // write trial info
    int i;
    for (i = 0; i < NTRIALS; i++) {
        fprintf(fp, "%03d ", data[i].session);
        fprintf(fp, "%d ", data[i].subj);
        fprintf(fp, "%d ", data[i].sex);
        fprintf(fp, "%d ", data[i].task);
        fprintf(fp, "%d \t", data[i].respmap);

        fprintf(fp, "%03d ", i);
        fprintf(fp, "%d ", data[i].phase);
        fprintf(fp, "%d \t", data[i].block);

        fprintf(fp, "%d ", data[i].mword);
        fprintf(fp, "%d ", data[i].cword);
        fprintf(fp, "%d ", data[i].stimpos);
        fprintf(fp, "%d ", data[i].stimdur);
        fprintf(fp, "%d ", data[i].semcong);
        fprintf(fp, "%d ", data[i].spcong);
        fprintf(fp, "%d \t", data[i].xr);

        fprintf(fp, "%d ", data[i].r);
        fprintf(fp, "%d ", data[i].corr);
        fprintf(fp, "%d ", data[i].rt);
        fprintf(fp, "%d ", data[i].re);
        fprintf(fp, "\n");
    }

    // close file
    fclose(fp);
}

// randomize trial list
#define RNDTEST 0
void randomize(int subj, int sex)
{
    initdata();

    // random list that is used to
    // determine all random trial variables
    int tmplist[NTRIALS];
    if (RNDTEST) {
        // use a predictable list for testing
        int i;
        for (i = 0; i < NTRIALS; i++)
            tmplist[i] = i % CELLS;
    } else {
        // use a random list during the 'real' experiment
        ts_rlist(CELLS, 1, &tmplist[0]);    // trial 0-15 practice
        ts_rlist(CELLS, 1, &tmplist[NPRACT]);   // trial 16-31 warmup
        ts_rlist(CELLS, REPS, &tmplist[NPRACT + NWARMUP]);  // from trial 32 onwards: 3 blocks of 48 trials
        ts_rlist(CELLS, REPS, &tmplist[NPRACT + NWARMUP + BLOCKLEN]);
        ts_rlist(CELLS, REPS, &tmplist[NPRACT + NWARMUP + BLOCKLEN * 2]);
        ts_rlist(CELLS, REPS, &tmplist[NPRACT + NWARMUP + BLOCKLEN * 3]);
    }

    // derive random variables for each trial
    int i;
    for (i = 0; i < NTRIALS; i++) {

        // information about participant
        data[i].session = sex * 100 + subj;
        data[i].subj = subj;
        data[i].sex = sex;

        // use participant nr to determine task and response mapping
        data[i].task = subj % NTASK;
        data[i].respmap = (subj / NTASK) % NRESPMAP;

        // use trial nr to determine phase and block 
        if (i < NPRACT)
            data[i].phase = PRACT;
        else if (i < NPRACT + NWARMUP)
            data[i].phase = WARMUP;
        else
            data[i].phase = EXP;

        if (data[i].phase != EXP)
            data[i].block = 0;
        else
            data[i].block = ((i - NPRACT - NWARMUP) / BLOCKLEN) + 1;

        // use random list to determine within variables
        //(NWORDS*NCOLORS*NPOS*NDUR)
        data[i].mword = tmplist[i] % NWORDS;
        data[i].cword = (tmplist[i] / NWORDS) % NCOLORS;
        data[i].stimpos = (tmplist[i] / NWORDS / NCOLORS) % NPOS + 1;
        data[i].stimdur = (tmplist[i] / NWORDS / NCOLORS / NPOS) % NDUR;

        // compute expected response using
        // task, responsmap and stimulus
        if (data[i].task == COLOR) {
            if (data[i].respmap == RL) {
                if (data[i].cword == CRED)
                    data[i].xr = LEFT;
                else
                    data[i].xr = RIGHT;
            } else {
                if (data[i].cword == CRED)
                    data[i].xr = RIGHT;
                else
                    data[i].xr = LEFT;
            }
        } else {
            if (data[i].respmap == RL) {
                if (data[i].mword == CRED)
                    data[i].xr = LEFT;
                else
                    data[i].xr = RIGHT;
            } else {
                if (data[i].mword == CRED)
                    data[i].xr = RIGHT;
                else
                    data[i].xr = LEFT;
            }
        }

        // determine congruency variables
        if (data[i].mword == data[i].cword)
            data[i].semcong = CONG;
        else
            data[i].semcong = INCONG;

        if (data[i].stimpos == data[i].xr)
            data[i].spcong = CONG;
        else
            data[i].spcong = INCONG;
    }
}

// test-function that makes 1 data file
#ifndef SS_TRIAL_C
int main()
{
    randomize(0, 0);
    writedata();
    return 0;
}

END_OF_MAIN();
#endif                          // SS_TRIAL_C


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information