Ejemplo n.º 1
0
Task::Task(Project* project, const std::string taskDef) {
    qDebug("Task::Task(Project* project, std::string* taskDef)");
    _project = project;
    _totalTime = 0;
    _logs = new vector<TaskLog*>();

    hashmap* values = parseTextFormat(taskDef);

    _id = new std::string(READ_ELEMENT(values, "task-id"));
    qDebug("Loading task id: %s", _id->c_str());
    _shortDescription =  new std::string(READ_ELEMENT(values, "short-description"));
    _longDescription = new std::string(READ_ELEMENT(values, "long-description"));
    _duration = Duration(READ_ELEMENT(values, "duration").c_str());
    _startDate = new DateTime(READ_ELEMENT(values, "startdate"));
    _endDate = new DateTime(READ_ELEMENT(values, "enddate"));
    _templateName = new string(READ_ELEMENT(values, "template-name"));
    _status = new string(READ_ELEMENT(values, "status"));

    Template* tpl = readTemplate(*_templateName);
    // Check the current template existance
    if (tpl == NULL) {
        qDebug("Warning: The task with id: %s contains an invalid template: %s", _id->c_str(), _templateName->c_str());
        _templateName = defaultTemplate()->name();
        _status = new string(*defaultTemplate()->statusList().begin());
    }

    int red = randColor();
    int green = randColor();
    int blue = randColor();
    _taskColor = QColor(red, green, blue);
    _parentTask = NULL;
    delete(values);
    qDebug("out Task::Task(Project* project, std::string* taskDef)");
}
Ejemplo n.º 2
0
/*{{{  recode(transform_info_ptr tinfo) {*/
METHODDEF DATATYPE *
recode(transform_info_ptr tinfo) {
 struct recode_storage *local_arg=(struct recode_storage *)tinfo->methods->local_storage;
 transform_info_ptr const tinfoptr=tinfo;
 array myarray;

  int itempart;
  int shift, nrofshifts=1;
  DATATYPE *save_tsdata;

  tinfo_array(tinfoptr, &myarray);	/* The channels are the vectors */
  save_tsdata=myarray.start;

  if (tinfoptr->data_type==FREQ_DATA) {
   nrofshifts=tinfoptr->nrofshifts;
  }
  for (shift=0; shift<nrofshifts; shift++) {
   myarray.start=save_tsdata+shift*tinfo->nroffreq*tinfo->nr_of_channels*tinfo->itemsize;
   array_setreadwrite(&myarray);
   for (itempart=local_arg->fromitem; itempart<=local_arg->toitem; itempart++) {
    array_use_item(&myarray, itempart);
    do {
     if (local_arg->have_channel_list && !is_in_channellist(myarray.current_vector+1, local_arg->channel_list)) {
      array_nextvector(&myarray);
      continue;
     }
     do {
      DATATYPE hold=READ_ELEMENT(&myarray);
      struct blockdef *inblocks=local_arg->blockdefs;
      while (inblocks!=NULL) {
       if (isnan(inblocks->fromstart) && isnan(hold)) {
	/* Recode NaN values */
	hold=inblocks->tostart;
       } else
       if (hold>=inblocks->fromstart && hold<=inblocks->fromend) {
	if (inblocks->fromend==inblocks->fromstart || inblocks->toend==inblocks->tostart) {
	 hold=inblocks->tostart;
	} else {
	 hold=((hold-inblocks->fromstart)/(inblocks->fromend-inblocks->fromstart))*(inblocks->toend-inblocks->tostart)+inblocks->tostart;
	}
	break;
       }
       if (inblocks->last_block) break;
       inblocks++;
      }
      array_write(&myarray, hold);
     } while (myarray.message==ARRAY_CONTINUE);
    } while (myarray.message==ARRAY_ENDOFVECTOR);
   }
  }

 return tinfo->tsdata;
}
Ejemplo n.º 3
0
/*{{{  export_point(transform_info_ptr tinfo) {*/
METHODDEF DATATYPE *
export_point(transform_info_ptr tinfo) {
 struct export_point_info *exp_info=(struct export_point_info *)tinfo->methods->local_storage;
 transform_argument *args=tinfo->methods->arguments;
 array_dump_format format=(args[ARGS_MATLAB].is_set ? ARRAY_MATLAB : ARRAY_ASCII);
 int channel, itempart, i;
 double *channelpos;
 array myarray, newarray;

 if (exp_info->pointno<0 || exp_info->pointno>=tinfo->nr_of_points) {
  ERREXIT1(tinfo->emethods, "export_point: Point number %d is out of range.\n", MSGPARM(exp_info->pointno));
 }
 TRACEMS2(tinfo->emethods, 1, "export_point: Exporting point number %d to file %s\n", MSGPARM(exp_info->pointno), MSGPARM(args[ARGS_OFILE].arg.s));
 if (args[ARGS_CLOSE].is_set) export_file_open(tinfo);
 tinfo_array(tinfo, &myarray);
 myarray.current_element=exp_info->pointno;
 if (exp_info->channelcoords_to_display==0 && tinfo->itemsize==1) {
  /*{{{  Don't need to build new array, just access tinfo*/
  newarray=myarray;
  array_transpose(&newarray);
  array_setto_vector(&newarray);	/* Select only one element */
  array_transpose(&newarray);
  /*}}}  */
 } else {
  /*{{{  Build new array containing the data*/
  newarray.nr_of_vectors=myarray.nr_of_vectors;
  newarray.nr_of_elements=exp_info->channelcoords_to_display+tinfo->itemsize;
  newarray.element_skip=1;
  if (array_allocate(&newarray)==NULL) {
   ERREXIT(tinfo->emethods, "export_point: Can't allocate output array\n");
  }
  for (channel=0; channel<tinfo->nr_of_channels; channel++) {
   channelpos=tinfo->probepos+3*channel;
   for (i=0; i<exp_info->channelcoords_to_display; i++) {
    array_write(&newarray, channelpos[i]);
   }
   myarray.current_vector=channel;
   for (itempart=0; itempart<tinfo->itemsize; itempart++) {
    array_use_item(&myarray, itempart);
    array_write(&newarray, READ_ELEMENT(&myarray));
   }
  }
  /*}}}  */
 }
 array_dump(exp_info->file, &newarray, format);
 if (newarray.nr_of_elements>1) array_free(&newarray);

 if (args[ARGS_CLOSE].is_set) export_file_close(tinfo);

 return tinfo->tsdata;
}
Ejemplo n.º 4
0
char* readValue(std::string cont, std::string key) {
    hashmap* map = parseTextFormat(cont);
    std::string value = READ_ELEMENT(map, key);

    char* res = NULL;
    if (value.size() == 0) {
        res = strcpy("");
    } else {
        res = strcpy(value);
    }

    delete(map);
    return res;
}
Ejemplo n.º 5
0
/*{{{  rereference(transform_info_ptr tinfo)*/
METHODDEF DATATYPE *
rereference(transform_info_ptr tinfo) {
 struct rereference_args_struct *rereference_args=(struct rereference_args_struct *)tinfo->methods->local_storage;
 transform_argument *args=tinfo->methods->arguments;
 int itempart;
 transform_info_ptr const tinfoptr=tinfo;
 array indata;

  tinfo_array(tinfoptr, &indata);
  array_transpose(&indata);	/* Vector=map */
  for (itempart=0; itempart<tinfoptr->itemsize-tinfoptr->leaveright; itempart++) {
   array_use_item(&indata, itempart);
   do {
    DATATYPE mean=0;
    int n=0;

    do {
     if (is_in_channellist(indata.current_element+1, rereference_args->refchannel_numbers)) {
      mean+=array_scan(&indata);
      n++;
     } else {
      array_advance(&indata);
     }
    } while (indata.message==ARRAY_CONTINUE);
    mean/=n;
    array_previousvector(&indata);
    do {
     if ((args[ARGS_EXCLUDEOTHER].is_set && !is_in_channellist(indata.current_element+1, rereference_args->refchannel_numbers)) 
      || is_in_channellist(indata.current_element+1, rereference_args->excludechannel_numbers)) {
      array_advance(&indata);
     } else {
      array_write(&indata, READ_ELEMENT(&indata)-mean);
     }
    } while (indata.message==ARRAY_CONTINUE);
   } while (indata.message!=ARRAY_ENDOFSCAN);
  }

 return tinfo->tsdata;
}
Ejemplo n.º 6
0
GLOBAL void
array_tqli(array *d, array *e, array *z) {
 int n=d->nr_of_elements,m,l,iter,i,k;
 DATATYPE s,r,p,g,f,dd,c,b,hold;

 for (i=1;i<n;i++) {
  e->current_element=i;
  hold=READ_ELEMENT(e);
  e->current_element=i-1;
  WRITE_ELEMENT(e, hold);
 }
 e->current_element=n-1;
 WRITE_ELEMENT(e, 0.0);
 for (l=0;l<n;l++) {
  iter=0;
  do {
   for (m=l;m<n-1;m++) {
    /*{{{}}}*/
    /*{{{  */
    d->current_element=e->current_element=m;
    hold=fabs(READ_ELEMENT(d));
    d->current_element=m+1;
    dd=hold+fabs(READ_ELEMENT(d));
    if ((DATATYPE)(fabs(READ_ELEMENT(e))+dd) == dd) break;
    /*}}}  */
   }
   if (m != l) {
    /*{{{  */
    if (iter++ == 30) nrerror("Too many iterations in tqli");
    d->current_element=l+1;
    hold=READ_ELEMENT(d);
    d->current_element=e->current_element=l;
    g=(hold-READ_ELEMENT(d))/(2.0*READ_ELEMENT(e));
    r=pythag(g,1.0);
    hold=READ_ELEMENT(d);
    d->current_element=m;
    g=READ_ELEMENT(d)-hold+READ_ELEMENT(e)/(g+SIGN(r,g));
    s=c=1.0;
    p=0.0;
    for (i=m-1;i>=l;i--) {
     e->current_element=i;
     hold=READ_ELEMENT(e);
     f=s*hold;
     b=c*hold;
     e->current_element=d->current_element=i+1;
     WRITE_ELEMENT(e, r=pythag(f,g));
     if (r == 0.0) {
      WRITE_ELEMENT(d, READ_ELEMENT(d)-p);
      e->current_element=m;
      WRITE_ELEMENT(e, 0.0);
      break;
     }
     s=f/r;
     c=g/r;
     g=READ_ELEMENT(d)-p;
     d->current_element=i;
     r=(READ_ELEMENT(d)-g)*s+2.0*c*b;
     d->current_element=i+1;
     WRITE_ELEMENT(d, g+(p=s*r));
     g=c*r-b;
     for (k=0;k<n;k++) {
      z->current_element=k;
      z->current_vector=i+1;
      f=READ_ELEMENT(z);
      z->current_vector=i;
      hold=READ_ELEMENT(z);
      z->current_vector=i+1;
      WRITE_ELEMENT(z, s*hold+c*f);
      z->current_vector=i;
      WRITE_ELEMENT(z, c*hold-s*f);
     }
    }
    if (r == 0.0 && i >= l) continue;
    d->current_element=e->current_element=l;
    WRITE_ELEMENT(d, READ_ELEMENT(d)-p);
    WRITE_ELEMENT(e, g);
    e->current_element=m;
    WRITE_ELEMENT(e, 0.0);
    /*}}}  */
   }
  } while (m != l);
 }
}
Ejemplo n.º 7
0
int main(int argc, char **argv) {
 FILE *fp;
 surfspline_desc sspline;
 int err, npoints, itempart=0;
 int binary_output=FALSE, matlab_output=FALSE, mtv_output=FALSE, interpolate_only=FALSE;
 float fbuf, external_value=0.0;
 DATATYPE f, x, y, xmin, xmax, ymin, ymax, xstep, ystep;
 array index;
 pid_t pid;
 char outname[L_tmpnam], inname[L_tmpnam], **inargs, *infile;

 /*{{{  Read command line args*/
 for (inargs=argv+1; inargs-argv<argc && **inargs=='-'; inargs++) {
  switch(inargs[0][1]) {
   case 'B':
    binary_output=TRUE;
    break;
   case 'I':
    if (inargs[0][2]!='\0') {
     itempart=atoi(*inargs+2);
    }
    break;
   case 'i':
    interpolate_only=TRUE;
    if (inargs[0][2]!='\0') {
     external_value=atof(*inargs+2);
    }
    break;
   case 'M':
    matlab_output=TRUE;
    break;
   case 'm':
    mtv_output=TRUE;
    break;
   default:
    fprintf(stderr, "%s: Ignoring unknown option %s\n", argv[0], *inargs);
    continue;
  }
 }
 if (argc-(inargs-argv)!=3) {
  fprintf(stderr, "Usage: %s array_filename degree npoints\n"
          "Options:\n"
          " -Iitem: Use item number item as z-axis (2+item'th column); default: 0\n"
          " -i[value]: Interpolate only; set external values to value (default: 0.0)\n"
          " -B: Binary output (gnuplot floats)\n"
          " -M: Matlab output (x, y vectors and z matrix)\n"
          " -m: Plotmtv output\n"
  	  , argv[0]);
  return -1;
 }
 infile= *inargs++;
 if ((fp=fopen(infile, "r"))==NULL) {
  fprintf(stderr, "Can't open %s\n", infile);
  return -2;
 }
 array_undump(fp, &sspline.inpoints);
 fclose(fp);
 if (sspline.inpoints.message==ARRAY_ERROR) {
  fprintf(stderr, "Error in array_undump\n");
  return -3;
 }
 if (sspline.inpoints.nr_of_elements<3+itempart) {
  fprintf(stderr, "Not enough columns in array %s\n", *(inargs-1));
  return -3;
 }
 sspline.degree=atoi(*inargs++);;
 npoints=atoi(*inargs++);
 /*}}}  */

 /*{{{  Get the index of qhull point pairs by running qhull*/
 tmpnam(outname); tmpnam(inname);
 if ((pid=fork())==0) {	/* I'm the child */
#define LINEBUF_SIZE 128
  char linebuf[LINEBUF_SIZE];
  array tmp_array;

  /*{{{  Dump xy positions to tmp file inname*/
  tmp_array.nr_of_elements=2;
  tmp_array.nr_of_vectors=sspline.inpoints.nr_of_vectors;
  tmp_array.element_skip=1;
  if (array_allocate(&tmp_array)==NULL) {
   fprintf(stderr, "Error allocating tmp_array\n");
   return -4;
  }
  array_reset(&sspline.inpoints);
  do {
   array_write(&tmp_array, array_scan(&sspline.inpoints));
   array_write(&tmp_array, array_scan(&sspline.inpoints));
   array_nextvector(&sspline.inpoints);
  } while (tmp_array.message!=ARRAY_ENDOFSCAN);
  if ((fp=fopen(inname, "w"))==NULL) {
   fprintf(stderr, "Can't open %s\n", inname);
   return -5;
  }
  array_dump(fp, &tmp_array, ARRAY_ASCII);
  fclose(fp);
  array_free(&tmp_array);
  /*}}}  */

  snprintf(linebuf, LINEBUF_SIZE, "qhull C0 i b <%s >%s", inname, outname);
  execl("/bin/sh", "sh", "-c", linebuf, 0);
#undef LINEBUF_SIZE
 } else {
  wait(NULL);
 }
 unlink(inname);
 if ((fp=fopen(outname, "r"))==NULL) {
  fprintf(stderr, "Can't open %s\n", outname);
  return -6;
 }
 array_undump(fp, &index);
 fclose(fp);
 unlink(outname);
 /*}}}  */

 /*{{{  Find min, max and mean coordinates*/
 array_transpose(&sspline.inpoints);
 array_reset(&sspline.inpoints);
 xmin=array_min(&sspline.inpoints);
 ymin=array_min(&sspline.inpoints);
 array_reset(&sspline.inpoints);
 xmax=array_max(&sspline.inpoints);
 ymax=array_max(&sspline.inpoints);
 array_reset(&sspline.inpoints);
 xmean=array_mean(&sspline.inpoints);
 ymean=array_mean(&sspline.inpoints);
 xstep=(xmax-xmin)/npoints;
 ystep=(ymax-ymin)/npoints;
 array_transpose(&sspline.inpoints);
 array_reset(&sspline.inpoints);
 /*}}}  */

 /*{{{  Copy itempart to 3rd location if necessary*/
 /* Note: For this behavior it is essential that array_surfspline
  * will accept vectors of any size >=3 and only process the first three
  * elements ! */
 if (itempart>0) {
  DATATYPE hold;
  do {
   sspline.inpoints.current_element=2+itempart;
   hold=READ_ELEMENT(&sspline.inpoints);
   sspline.inpoints.current_element=2;
   WRITE_ELEMENT(&sspline.inpoints, hold);
   array_nextvector(&sspline.inpoints);
  } while (sspline.inpoints.message!=ARRAY_ENDOFSCAN);
 }
 /*}}}  */

 /*{{{  Do surface spline*/
 if ((err=array_surfspline(&sspline))!=0) {
  fprintf(stderr, "Error %d in array_surfspline\n", err);
  return err;
 }
 xmin-=xstep; xmax+=2*xstep;
 ymin-=ystep; ymax+=2*ystep;

 if (binary_output) {
  /*{{{  Gnuplot binary output*/
  int n_xval=(xmax-xmin)/xstep+1, n;	/* Number of x values */

  fbuf=n_xval;
  fwrite(&fbuf, sizeof(float), 1, stdout);
  for (fbuf=xmin, n=0; n<n_xval; fbuf+=xstep, n++) {	/* x values */
   fwrite(&fbuf, sizeof(float), 1, stdout);
  }
  for (y=ymin; y<=ymax; y+=ystep) {
   fbuf=y; fwrite(&fbuf, sizeof(float), 1, stdout);
   for (x=xmin, n=0; n<n_xval; x+=xstep, n++) {
    if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) {
     f=external_value;
    } else {
     f=array_fsurfspline(&sspline, x, y);
    }
    fbuf=f; fwrite(&fbuf, sizeof(float), 1, stdout);
   }
  }
  /*}}}  */
 } else if (matlab_output) {
  /*{{{  Matlab output*/
  array xm, ym, zm;
  xm.nr_of_elements=ym.nr_of_elements=1;
  xm.nr_of_vectors=zm.nr_of_elements=(xmax-xmin)/xstep+1;
  ym.nr_of_vectors=zm.nr_of_vectors=(ymax-ymin)/ystep+1;
  xm.element_skip=ym.element_skip=zm.element_skip=1;
  array_allocate(&xm); array_allocate(&ym); array_allocate(&zm);
  if (xm.message==ARRAY_ERROR || ym.message==ARRAY_ERROR || zm.message==ARRAY_ERROR) {
   fprintf(stderr, "Error allocating output arrays\n");
   return -7;
  }
  x=xmin; do {
   array_write(&xm, x);
   x+=xstep;
  } while (xm.message!=ARRAY_ENDOFSCAN);
  y=ymin; do {
   array_write(&ym, y);
   x=xmin; do {
    if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) {
     f=external_value;
    } else {
     f=array_fsurfspline(&sspline, x, y);
    }
    array_write(&zm, f);
    x+=xstep;
   } while (zm.message==ARRAY_CONTINUE);
   y+=ystep;
  } while (zm.message!=ARRAY_ENDOFSCAN);
  array_dump(stdout, &xm, ARRAY_MATLAB);
  array_dump(stdout, &ym, ARRAY_MATLAB);
  array_dump(stdout, &zm, ARRAY_MATLAB);
  array_free(&xm); array_free(&ym); array_free(&zm);
  /*}}}  */
 } else if (mtv_output) {
  /*{{{  Plotmtv output*/
  array zm;
  DATATYPE zmin=FLT_MAX, zmax= -FLT_MAX;
  zm.nr_of_elements=(xmax-xmin)/xstep+1;
  zm.nr_of_vectors=(ymax-ymin)/ystep+1;
  zm.element_skip=1;
  array_allocate(&zm);
  if (zm.message==ARRAY_ERROR) {
   fprintf(stderr, "Error allocating output arrays\n");
   return -7;
  }
  y=ymin; do {
   x=xmin; do {
    if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) {
     f=external_value;
    } else {
     f=array_fsurfspline(&sspline, x, y);
    }
    array_write(&zm, f);
    if (f<zmin) zmin=f;
    if (f>zmax) zmax=f;
    x+=xstep;
   } while (zm.message==ARRAY_CONTINUE);
   y+=ystep;
  } while (zm.message!=ARRAY_ENDOFSCAN);
  /*{{{  Print file header*/
  printf(
  "# Output of Spline_Gridder (C) Bernd Feige 1995\n\n"
  "$ DATA=CONTOUR\n\n"
  "%% toplabel   = \"Spline_Gridder output\"\n"
  "%% subtitle   = \"File: %s\"\n\n"
  "%% interp     = 0\n"
  "%% contfill   = on\n"
  "%% meshplot   = off\n\n"
  "%% xmin = %g  xmax = %g\n"
  "%% ymin = %g  ymax = %g\n"
  "%% zmin = %g  zmax = %g\n"
  "%% nx   = %d\n"
  "%% ny   = %d\n"
  , infile, 
  xmin, xmax, 
  ymin, ymax, 
  zmin, zmax, 
  zm.nr_of_elements, 
  zm.nr_of_vectors);
  /*}}}  */
  array_dump(stdout, &zm, ARRAY_MATLAB);
  array_free(&zm);
  /*}}}  */
 } else {
  /*{{{  Gnuplot output*/
  for (x=xmin; x<=xmax; x+=xstep) {
   for (y=ymin; y<=ymax; y+=ystep) {
    if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) {
     f=external_value;
    } else {
     f=array_fsurfspline(&sspline, x, y);
    }
    printf("%g %g %g\n", x, y, f);
   }
   printf("\n");
  }
  /*}}}  */
 }
 /*}}}  */

 return 0;
}
Ejemplo n.º 8
0
/*{{{  normalize_channelbox(transform_info_ptr tinfo) {*/
METHODDEF DATATYPE *
normalize_channelbox(transform_info_ptr tinfo) {
 struct normalize_channelbox_storage *local_arg=(struct normalize_channelbox_storage *)tinfo->methods->local_storage;
 transform_argument *args=tinfo->methods->arguments;
 transform_info_ptr const tinfoptr=tinfo;
 int channel, xmaxchan, xminchan, ymaxchan, yminchan, zmaxchan, zminchan;
 DATATYPE value, value2, xmax, ymax, zmax, xmin, ymin, zmin, xmid, ymid, zmid;
 DATATYPE tval[9];
 double phi;
 array myarray, t;
 local_arg->view_from_left=FALSE;

  /*{{{  Construct array myarray*/
  myarray.start=(DATATYPE *)tinfoptr->probepos;
  myarray.nr_of_elements=3;
  myarray.nr_of_vectors=tinfoptr->nr_of_channels;
  myarray.vector_skip=3;
  myarray.element_skip=1;
  array_setreadwrite_double(&myarray);
  /*}}}  */

  /*{{{  Swap x and y if data set is 'Roma' (x=left->right)*/
  if (strncmp(tinfo->comment, "Roma ", 5)==0) {
   /* This is the trace that vp2mfx leaves in Roma files. Though generality
    * lacks, this seems unavoidable in this module */
   array_reset(&myarray);
   do {
    value=array_scan(&myarray);
    value2=array_scan(&myarray);
    myarray.current_element=0;
    array_write(&myarray, value2);
    array_write(&myarray, -value);
    array_advance(&myarray);
   } while (myarray.message!=ARRAY_ENDOFSCAN);
  }
  /*}}}  */

  /*{{{  Find min and max values of the box*/
  array_reset(&myarray);
  xmax=xmin=array_scan(&myarray);
  ymax=ymin=array_scan(&myarray);
  zmax=zmin=array_scan(&myarray);
  xmaxchan=xminchan=ymaxchan=yminchan=zmaxchan=zminchan=0;
  channel=1;
  do {
   value=array_scan(&myarray);
   if (value>xmax) { xmax=value; xmaxchan=channel; }
   if (value<xmin) { xmin=value; xminchan=channel; }
   value=array_scan(&myarray);
   if (value>ymax) { ymax=value; ymaxchan=channel; }
   if (value<ymin) { ymin=value; yminchan=channel; }
   value=array_scan(&myarray);
   if (value>zmax) { zmax=value; zmaxchan=channel; }
   if (value<zmin) { zmin=value; zminchan=channel; }
   channel++;
  } while (myarray.message!=ARRAY_ENDOFSCAN);
#  ifdef DEBUG
  printf("zmaxchan=%s, xmaxchan=%s\n", tinfoptr->channelnames[zmaxchan], tinfoptr->channelnames[xmaxchan]);
#  endif
  /*}}}  */
  
  /*{{{  Subtract midpoint*/
  xmid=(xmax+xmin)/2; ymid=(ymax+ymin)/2; zmid=(zmax+zmin)/2;
#  ifdef DEBUG
  printf("xmid=%g, ymid=%g, zmid=%g\n", xmid, ymid, zmid);
#  endif
  array_reset(&myarray);
  do {
   array_write(&myarray, READ_ELEMENT(&myarray)-xmid);
   array_write(&myarray, READ_ELEMENT(&myarray)-ymid);
   array_write(&myarray, READ_ELEMENT(&myarray)-zmid);
  } while (myarray.message!=ARRAY_ENDOFSCAN);
  /*}}}  */
  
  /*{{{  Construct array t to be used for rotations*/
  t.start=tval;
  t.nr_of_elements=3;
  t.nr_of_vectors=3;
  t.element_skip=1;
  t.vector_skip=3;
  array_setreadwrite(&t);
  /*}}}  */
  
  /*{{{  rotate zmaxchan about the x axis by its angle to the y axis (maximize y)*/
  /* By this rotation, the z component of zmaxchan is removed. */
  array_reset(&t);
  myarray.current_vector=zmaxchan;
  myarray.current_element=1;
  value=array_scan(&myarray);	/* y value */
  value2=READ_ELEMENT(&myarray);	/* z value */
  value/=sqrt(value*value+value2*value2);
  phi=(value2>0 ? -acos(value) : acos(value));
#  ifdef DEBUG
  printf("z=%g, cos phi=%g=%g, phi=%g\n", value2, value, cos(phi), phi);
#  endif
  array_write(&t, 1.0);
  array_write(&t, 0.0);
  array_write(&t, 0.0);

  array_write(&t, 0.0);
  array_write(&t, cos(phi));
  array_write(&t, sin(phi));

  array_write(&t, 0.0);
  array_write(&t, -sin(phi));
  array_write(&t, cos(phi));

  array_transpose(&t);
  array_reset(&myarray);
  do {
   DATATYPE x, y, z;
   x=array_multiply(&t, &myarray, MULT_SAMESIZE);
   y=array_multiply(&t, &myarray, MULT_SAMESIZE);
   z=array_multiply(&t, &myarray, MULT_SAMESIZE);
   array_previousvector(&myarray);
   array_write(&myarray, x);
   array_write(&myarray, y);
   array_write(&myarray, z);
  } while (myarray.message!=ARRAY_ENDOFSCAN);
  /*}}}  */
  
  /*{{{  rotate zmaxchan about the z axis by its angle to the y axis (maximize y)*/
  /* Now remove the x component of zmaxchan. Coordinates should be 0, z, 0 */
  array_reset(&t);
  myarray.current_element=0;
  myarray.current_vector=zmaxchan;
  value2=array_scan(&myarray);	/* x value */
  value=READ_ELEMENT(&myarray); /* y value */
  value/=sqrt(value*value+value2*value2);
  phi=(value2>0 ? -acos(value) : acos(value));
#  ifdef DEBUG
  printf("z=%g, cos phi=%g=%g, phi=%g\n", value2, value, cos(phi), phi);
#  endif
  array_write(&t, cos(phi));
  array_write(&t, sin(phi));
  array_write(&t, 0.0);

  array_write(&t, -sin(phi));
  array_write(&t, cos(phi));
  array_write(&t, 0.0);

  array_write(&t, 0.0);
  array_write(&t, 0.0);
  array_write(&t, 1.0);

  if (value2<0.0) array_transpose(&t);
  array_reset(&myarray);
  do {
   DATATYPE x, y, z;
   x=array_multiply(&t, &myarray, MULT_SAMESIZE);
   y=array_multiply(&t, &myarray, MULT_SAMESIZE);
   z=array_multiply(&t, &myarray, MULT_SAMESIZE);
   array_previousvector(&myarray);
   array_write(&myarray, x);
   array_write(&myarray, y);
   array_write(&myarray, z);
  } while (myarray.message!=ARRAY_ENDOFSCAN);
  /*}}}  */

  /*{{{  rotate xmaxchan about the y axis by its angle to the x axis (maximize x)*/
  /* This is the only rotation that will leave zmaxchan at its position */
  array_reset(&t);
  myarray.current_element=0;
  myarray.current_vector=(args[ARGS_DECIDE_LEFTRIGHT].is_set && ymid>0.0 ? local_arg->view_from_left=TRUE,xminchan : xmaxchan);
  value=array_scan(&myarray);	/* x value */
  array_advance(&myarray);
  value2=READ_ELEMENT(&myarray); /* z value */
  value/=sqrt(value*value+value2*value2);
  phi=(value2>0 ? -acos(value) : acos(value));
#  ifdef DEBUG
  printf("z=%g, cos phi=%g=%g, phi=%g\n", value2, value, cos(phi), phi);
#  endif
  array_write(&t, cos(phi));
  array_write(&t, 0.0);
  array_write(&t, -sin(phi));

  array_write(&t, 0.0);
  array_write(&t, 1.0);
  array_write(&t, 0.0);

  array_write(&t, sin(phi));
  array_write(&t, 0.0);
  array_write(&t, cos(phi));

  if (value2<0.0) array_transpose(&t);
  array_reset(&myarray);
  do {
   DATATYPE x, y, z;
   x=array_multiply(&t, &myarray, MULT_SAMESIZE);
   y=array_multiply(&t, &myarray, MULT_SAMESIZE);
   z=array_multiply(&t, &myarray, MULT_SAMESIZE);
   array_previousvector(&myarray);
   array_write(&myarray, x);
   array_write(&myarray, y);
   array_write(&myarray, z);
  } while (myarray.message!=ARRAY_ENDOFSCAN);
  /*}}}  */

 return tinfo->tsdata;
}
Ejemplo n.º 9
0
GLOBAL void 
array_tred2(array *a, array *d, array *e) {
 int n=a->nr_of_elements,l,k,j,i;
 DATATYPE scale,hh,h,g,f,hold;

 for (i=n-1;i>=1;i--) {
  l=i-1;
  h=scale=0.0;
  if (l > 0) {
   /*{{{}}}*/
   /*{{{  */
   a->current_element=i;
   for (k=0;k<=l;k++) {
    a->current_vector=k;
    scale += fabs(READ_ELEMENT(a));
   }
   if (scale == 0.0) {
    a->current_vector=l;
    e->current_element=i;
    WRITE_ELEMENT(e, READ_ELEMENT(a));
   } else {
    /*{{{  */
    a->current_element=i;
    for (k=0;k<=l;k++) {
     a->current_vector=k;
     WRITE_ELEMENT(a, hold=READ_ELEMENT(a)/scale);
     h += hold*hold;
    }
    a->current_vector=l;
    f=READ_ELEMENT(a);
    g=(f >= 0.0 ? -sqrt(h) : sqrt(h));
    e->current_element=i;
    WRITE_ELEMENT(e, scale*g);
    h -= f*g;
    WRITE_ELEMENT(a, f-g);
    f=0.0;
    for (j=0;j<=l;j++) {
     a->current_element=i;
     a->current_vector=j;
     hold=READ_ELEMENT(a);
     a->current_element=j;
     a->current_vector=i;
     WRITE_ELEMENT(a, hold/h);
     g=0.0;
     for (k=0;k<=j;k++) {
      a->current_element=j;
      a->current_vector=k;
      hold=READ_ELEMENT(a);
      a->current_element=i;
      a->current_vector=k;
      g += hold*READ_ELEMENT(a);
     }
     for (k=j+1;k<=l;k++) {
      a->current_element=k;
      a->current_vector=j;
      hold=READ_ELEMENT(a);
      a->current_element=i;
      a->current_vector=k;
      g += hold*READ_ELEMENT(a);
     }
     e->current_element=j;
     WRITE_ELEMENT(e, hold=g/h);
     a->current_element=i;
     a->current_vector=j;
     f += hold*READ_ELEMENT(a);
    }
    hh=f/(h+h);
    for (j=0;j<=l;j++) {
     a->current_element=i;
     a->current_vector=j;
     f=READ_ELEMENT(a);
     e->current_element=j;
     g=READ_ELEMENT(e)-hh*f;
     WRITE_ELEMENT(e, g);
     for (k=0;k<=j;k++) {
      a->current_element=i;
      a->current_vector=k;
      hold=READ_ELEMENT(a);
      a->current_element=j;
      a->current_vector=k;
      e->current_element=k;
      hold=f*READ_ELEMENT(e)+g*hold;
      WRITE_ELEMENT(a, READ_ELEMENT(a)-hold);
     }
    }
    /*}}}  */
   }
   /*}}}  */
  } else {
   /*{{{  */
   e->current_element=a->current_element=i;
   a->current_vector=l;
   WRITE_ELEMENT(e, READ_ELEMENT(a));
   /*}}}  */
  }
  d->current_element=i;
  WRITE_ELEMENT(d, h);
 }
 d->current_element=0;
 WRITE_ELEMENT(d, 0.0);
 e->current_element=0;
 WRITE_ELEMENT(e, 0.0);

 for (i=0;i<n;i++) {
  l=i-1;
  d->current_element=i;
  if (READ_ELEMENT(d)) {
   for (j=0;j<=l;j++) {
    g=0.0;
    for (k=0;k<=l;k++) {
     a->current_element=i;
     a->current_vector=k;
     hold=READ_ELEMENT(a);
     a->current_element=k;
     a->current_vector=j;
     g += hold*READ_ELEMENT(a);
    }
    for (k=0;k<=l;k++) {
     a->current_element=k;
     a->current_vector=i;
     hold=READ_ELEMENT(a);
     a->current_element=k;
     a->current_vector=j;
     WRITE_ELEMENT(a, READ_ELEMENT(a)-g*hold);
    }
   }
  }
  a->current_element=i;
  a->current_vector=i;
  WRITE_ELEMENT(d, READ_ELEMENT(a));
  WRITE_ELEMENT(a, 1.0);
  for (j=0;j<=l;j++) {
   a->current_element=j;
   a->current_vector=i;
   WRITE_ELEMENT(a, 0.0);
   a->current_element=i;
   a->current_vector=j;
   WRITE_ELEMENT(a, 0.0);
  }
 }
}
Ejemplo n.º 10
0
/*{{{  project_init(transform_info_ptr tinfo)*/
METHODDEF void
project_init(transform_info_ptr tinfo) {
 struct project_args_struct *project_args=(struct project_args_struct *)tinfo->methods->local_storage;
 transform_argument *args=tinfo->methods->arguments;
 transform_info_ptr side_tinfo= &project_args->side_tinfo;
 array *vectors= &project_args->vectors;
 growing_buf buf;
#define BUFFER_SIZE 80
 char buffer[BUFFER_SIZE];

 side_tinfo->methods= &project_args->methods;
 side_tinfo->emethods=tinfo->emethods;
 select_readasc(side_tinfo);
 growing_buf_init(&buf);
 growing_buf_allocate(&buf, 0);
 if (args[ARGS_FROMEPOCH].is_set) {
  snprintf(buffer, BUFFER_SIZE, "-f %ld ", args[ARGS_FROMEPOCH].arg.i);
  growing_buf_appendstring(&buf, buffer);
 }
 if (args[ARGS_EPOCHS].is_set) {
  project_args->epochs=args[ARGS_EPOCHS].arg.i;
  if (project_args->epochs<=0) {
   ERREXIT(tinfo->emethods, "project_init: The number of epochs must be positive.\n");
  }
 } else {
  project_args->epochs=1;
 }
 snprintf(buffer, BUFFER_SIZE, "-e %d ", project_args->epochs);
 growing_buf_appendstring(&buf, buffer);
 growing_buf_appendstring(&buf, args[ARGS_PROJECTFILE].arg.s);
 if (!buf.can_be_freed || !setup_method(side_tinfo, &buf)) {
  ERREXIT(tinfo->emethods, "project_init: Error setting readasc arguments.\n");
 }

 project_args->points=(args[ARGS_POINTS].is_set ? args[ARGS_POINTS].arg.i : 1);
 project_args->nr_of_item=(args[ARGS_NROFITEM].is_set ? args[ARGS_NROFITEM].arg.i : 0);
 project_args->orthogonalize_vectors_first=args[ARGS_ORTHOGONALIZE].is_set;
 if (args[ARGS_SUBSPACE].is_set) {
  project_args->project_mode=PROJECT_MODE_SSP;
 } else if (args[ARGS_SUBTRACT_SUBSPACE].is_set) {
  project_args->project_mode=PROJECT_MODE_SSPS;
 } else if (args[ARGS_MULTIPLY].is_set) {
  project_args->project_mode=PROJECT_MODE_MULTIPLY;
 } else {
  project_args->project_mode=PROJECT_MODE_SCALAR;
 }
 if (args[ARGS_CHANNELNAMES].is_set) {
  project_args->channel_list=expand_channel_list(tinfo, args[ARGS_CHANNELNAMES].arg.s);
  if (project_args->channel_list==NULL) {
   ERREXIT(tinfo->emethods, "project_init: Zero channels were selected by -N!\n");
  }
 } else {
  project_args->channel_list=NULL;
 }

 (*side_tinfo->methods->transform_init)(side_tinfo);

 /*{{{  Read first project_file epoch and allocate vectors array accordingly*/
 if ((side_tinfo->tsdata=(*side_tinfo->methods->transform)(side_tinfo))==NULL) {
  ERREXIT(tinfo->emethods, "project_init: Can't get the first project epoch.\n");
 }
 if (project_args->project_mode==PROJECT_MODE_MULTIPLY) {
  /* Save channel names and positions for later */
  project_args->save_side_tinfo.nr_of_channels=side_tinfo->nr_of_channels;
  copy_channelinfo(&project_args->save_side_tinfo, side_tinfo->channelnames, side_tinfo->probepos);
 }
 if (project_args->points==0) project_args->points=side_tinfo->nr_of_points;
 if (project_args->points>side_tinfo->nr_of_points) {
  ERREXIT1(tinfo->emethods, "project_init: There are only %d points in the project_file epoch.\n", MSGPARM(side_tinfo->nr_of_points));
 }
 if (args[ARGS_AT_XVALUE].is_set) {
  project_args->nr_of_point=find_pointnearx(side_tinfo, (DATATYPE)atof(args[ARGS_NROFPOINT].arg.s));
 } else {
 project_args->nr_of_point=gettimeslice(side_tinfo, args[ARGS_NROFPOINT].arg.s);
 }
 vectors->nr_of_vectors=project_args->epochs*project_args->points;
 vectors->nr_of_elements=side_tinfo->nr_of_channels;
 vectors->element_skip=1;
 if (array_allocate(vectors)==NULL) {
  ERREXIT(tinfo->emethods, "project_init: Error allocating vectors memory\n");
 }
 /*}}}  */

 do {
  /*{{{  Copy [points] vectors from project_file to vectors array*/
  array indata;
  int point;

  if (vectors->nr_of_elements!=side_tinfo->nr_of_channels) {
   ERREXIT(side_tinfo->emethods, "project_init: Varying channel numbers in project file!\n");
  }
  if (project_args->nr_of_point>=side_tinfo->nr_of_points) {
   ERREXIT2(side_tinfo->emethods, "project_init: nr_of_point=%d, nr_of_points=%d\n", MSGPARM(project_args->nr_of_point), MSGPARM(side_tinfo->nr_of_points));
  }
  if (project_args->nr_of_item>=side_tinfo->itemsize) {
   ERREXIT2(side_tinfo->emethods, "project_init: nr_of_item=%d, itemsize=%d\n", MSGPARM(project_args->nr_of_item), MSGPARM(side_tinfo->itemsize));
  }

  for (point=0; point<project_args->points; point++) {
   tinfo_array(side_tinfo, &indata);
   array_transpose(&indata);	/* Vector = map */
   if (vectors->nr_of_elements!=indata.nr_of_elements) {
    ERREXIT(side_tinfo->emethods, "project_init: vector size doesn't match\n");
   }
   indata.current_vector=project_args->nr_of_point+point;
   array_setto_vector(&indata);
   array_use_item(&indata, project_args->nr_of_item);
   array_copy(&indata, vectors);
  }
  /*}}}  */
  free_tinfo(side_tinfo);
 } while ((side_tinfo->tsdata=(*side_tinfo->methods->transform)(side_tinfo))!=NULL);

 if (vectors->message!=ARRAY_ENDOFSCAN) {
  ERREXIT1(tinfo->emethods, "project_init: Less than %d epochs in project file\n", MSGPARM(vectors->nr_of_vectors));
 }
 
 /*{{{  Set unused channels to zero if requested*/
 if (args[ARGS_ZERO_UNUSEDCOEFFICIENTS].is_set) {
  if (project_args->channel_list!=NULL) {
   do {
    do {
     if (is_in_channellist(vectors->current_element+1, project_args->channel_list)) {
      array_advance(vectors);
     } else {
      array_write(vectors, 0.0);
     }
    } while (vectors->message==ARRAY_CONTINUE);
   } while (vectors->message!=ARRAY_ENDOFSCAN);
  } else {
   ERREXIT(tinfo->emethods, "project_init: Option -z only makes sense in combination with -N!\n");
  }
 }
 /*}}}  */
 /*{{{  De-mean vectors if requested*/
 if (args[ARGS_CORRELATION].is_set) {
  do {
   DATATYPE mean=0.0;
   int nrofaverages=0;
   do {
    if (project_args->channel_list!=NULL && !is_in_channellist(vectors->current_element+1, project_args->channel_list)) {
     array_advance(vectors);
    } else {
     mean+=array_scan(vectors);
     nrofaverages++;
    }
   } while (vectors->message==ARRAY_CONTINUE);
   mean/=nrofaverages;
   array_previousvector(vectors);
   do {
    array_write(vectors, READ_ELEMENT(vectors)-mean);
   } while (vectors->message==ARRAY_CONTINUE);
  } while (vectors->message!=ARRAY_ENDOFSCAN);
 }
 /*}}}  */
 /*{{{  Orthogonalize vectors if requested*/
 if (project_args->orthogonalize_vectors_first) {
  array_make_orthogonal(vectors);
  if (vectors->message==ARRAY_ERROR) {
   ERREXIT(tinfo->emethods, "project_init: Error orthogonalizing projection vectors\n");
  }
 }
 /*}}}  */
 if (!args[ARGS_NONORMALIZATION].is_set) {
 /*{{{  Normalize vectors*/
 do {
  DATATYPE length=0.0;
  do {
   if (project_args->channel_list!=NULL && !is_in_channellist(vectors->current_element+1, project_args->channel_list)) {
    array_advance(vectors);
   } else {
    const DATATYPE hold=array_scan(vectors);
    length+=hold*hold;
   }
  } while (vectors->message==ARRAY_CONTINUE);
  length=sqrt(length);

  array_previousvector(vectors);
  if (length==0.0) {
   ERREXIT1(tinfo->emethods, "project_init: Vector %d has zero length !\n", MSGPARM(vectors->current_vector));
  }
  array_scale(vectors, 1.0/length);
 } while (vectors->message!=ARRAY_ENDOFSCAN);
 /*}}}  */
 }
 /*{{{  Dump vectors if requested*/
 if (args[ARGS_DUMPVECTORS].is_set) {
  FILE * const fp=fopen(args[ARGS_DUMPVECTORS].arg.s, "w");
  if (fp==NULL) {
   ERREXIT1(tinfo->emethods, "project_init: Error opening output file >%s<.\n", MSGPARM(args[ARGS_DUMPVECTORS].arg.s));
  }
  array_transpose(vectors); /* We want one vector to be one column */ 
  array_dump(fp, vectors, ARRAY_MATLAB);
  array_transpose(vectors);
  fclose(fp);
 }
 /*}}}  */

 (*side_tinfo->methods->transform_exit)(side_tinfo);
 free_methodmem(side_tinfo);
 growing_buf_free(&buf);

 tinfo->methods->init_done=TRUE;
}
Ejemplo n.º 11
0
/*{{{  project(transform_info_ptr tinfo)*/
METHODDEF DATATYPE *
project(transform_info_ptr tinfo) {
 struct project_args_struct *project_args=(struct project_args_struct *)tinfo->methods->local_storage;
 transform_argument *args=tinfo->methods->arguments;
 DATATYPE *retvalue=tinfo->tsdata;
 array indata, scalars, *vectors= &project_args->vectors;
 int itempart, itemparts=tinfo->itemsize-tinfo->leaveright;

 if (project_args->project_mode==PROJECT_MODE_MULTIPLY) {
  if (!(tinfo->nr_of_channels==vectors->nr_of_vectors
      ||(tinfo->nr_of_channels==1 && tinfo->itemsize==vectors->nr_of_vectors))) {
   ERREXIT(tinfo->emethods, "project: Number of scalars and maps doesn't match!\n");
  }
 } else {
 if (vectors->nr_of_elements!=tinfo->nr_of_channels) {
  ERREXIT2(tinfo->emethods, "project: %d channels in epoch, but %d channels in project file.\n", MSGPARM(tinfo->nr_of_channels), MSGPARM(vectors->nr_of_elements));
 }
 }

 array_reset(vectors);

 tinfo_array(tinfo, &indata);
 array_transpose(&indata);	/* Vectors are maps */

 /* Be sure that different output items are adjacent... */
 scalars.nr_of_elements=vectors->nr_of_vectors;
 switch (project_args->project_mode) {
  case PROJECT_MODE_SCALAR:
   scalars.nr_of_vectors=tinfo->nr_of_points;
   scalars.element_skip=itemparts;
   break;
  case PROJECT_MODE_SSP:
  case PROJECT_MODE_SSPS:
   scalars.nr_of_vectors=1;
   scalars.element_skip=1;
   break;
  case PROJECT_MODE_MULTIPLY:
   scalars=indata;
   if (tinfo->nr_of_channels!=vectors->nr_of_vectors) {
    /* Ie, one channel and weights in the items: Convert from 1 element to
     * itemsize elements */
    scalars.element_skip=1;
    scalars.nr_of_elements=tinfo->itemsize;
    itemparts=1;
   }
   indata.element_skip=itemparts;
   indata.nr_of_elements=vectors->nr_of_elements; /* New number of channels */
   indata.nr_of_vectors=scalars.nr_of_vectors; /* New number of points */
   if (array_allocate(&indata)==NULL) {
    ERREXIT(tinfo->emethods, "project: Can't allocate new indata array\n");
   }
   break;
 }

 if (project_args->project_mode==PROJECT_MODE_MULTIPLY) {
  array_transpose(vectors); /* Now the elements are the subspace dimensions */
  for (itempart=0; itempart<itemparts; itempart++) {
   array_use_item(&indata, itempart);
   array_use_item(&scalars, itempart);
   do {
    /*{{{  Build the signal subspace vector*/
    do {
     array_write(&indata, array_multiply(vectors, &scalars, MULT_SAMESIZE));
    } while (indata.message==ARRAY_CONTINUE);
    /*}}}  */
   } while (indata.message!=ARRAY_ENDOFSCAN);
  }
  array_transpose(vectors);
 } else {

 if (array_allocate(&scalars)==NULL) {
  ERREXIT(tinfo->emethods, "project: Can't allocate scalars array\n");
 }

 for (itempart=0; itempart<itemparts; itempart++) {
  array_use_item(&indata, itempart);
  if (project_args->project_mode==PROJECT_MODE_SCALAR) {
   array_use_item(&scalars, itempart);
  }

  do {
   /*{{{  Calculate the projection scalars*/
   do {
    /* With all vectors in turn: */
    DATATYPE product=0.0;
    do {
     if (project_args->channel_list!=NULL && !is_in_channellist(vectors->current_element+1, project_args->channel_list)) {
      array_advance(vectors);
      array_advance(&indata);
     } else {
      product+=array_scan(&indata)*array_scan(vectors);
     }
    } while (vectors->message==ARRAY_CONTINUE);

    array_write(&scalars, product);
    if (scalars.message==ARRAY_CONTINUE) array_previousvector(&indata);
   } while (scalars.message==ARRAY_CONTINUE);
   /*}}}  */
   
   switch (project_args->project_mode) {
    case PROJECT_MODE_SCALAR:
     break;
    case PROJECT_MODE_SSP:
     /*{{{  Build the signal subspace vector*/
     array_transpose(vectors); /* Now the elements are the subspace dimensions */
     array_previousvector(&indata);
     do {
      array_write(&indata, array_multiply(vectors, &scalars, MULT_VECTOR));
     } while (indata.message==ARRAY_CONTINUE);
     array_transpose(vectors);
     /*}}}  */
     break;
    case PROJECT_MODE_SSPS:
     /*{{{  Subtract the signal subspace vector*/
     array_transpose(vectors); /* Now the elements are the subspace dimensions */
     array_previousvector(&indata);
     do {
      array_write(&indata, READ_ELEMENT(&indata)-array_multiply(vectors, &scalars, MULT_VECTOR));
     } while (indata.message==ARRAY_CONTINUE);
     array_transpose(vectors);
     /*}}}  */
     break;
    default:
     /* Can't happen, just to keep the compiler happy... */
     ERREXIT(tinfo->emethods, "project: This cannot happen!\n");
     break;
   }
  } while (indata.message!=ARRAY_ENDOFSCAN);
 }
 }

 /*{{{  Prepare tinfo to reflect the data structure returned*/
 switch (project_args->project_mode) {
  case PROJECT_MODE_SCALAR:
   if (args[ARGS_USE_CHANNELS].is_set) {
    tinfo->nr_of_channels=vectors->nr_of_vectors;
    tinfo->itemsize=itemparts;
   } else {
    tinfo->nr_of_channels=1;
    tinfo->itemsize=itemparts*vectors->nr_of_vectors;
   }
   tinfo->length_of_output_region=scalars.nr_of_elements*scalars.element_skip*scalars.nr_of_vectors;
   tinfo->leaveright=0;
   tinfo->multiplexed=TRUE;
   if (tinfo->channelnames!=NULL) {
    free_pointer((void **)&tinfo->channelnames[0]);
    free_pointer((void **)&tinfo->channelnames);
   }
   free_pointer((void **)&tinfo->probepos);
   create_channelgrid(tinfo);
   retvalue=scalars.start;
   break;
  case PROJECT_MODE_SSP:
  case PROJECT_MODE_SSPS:
   array_free(&scalars);
   retvalue=tinfo->tsdata;
   break;
  case PROJECT_MODE_MULTIPLY:
   /* Note that we don't free `scalars' because it just points to the original tsdata! */
   /* Have to set this correctly so that copy_channelinfo works... */
   tinfo->nr_of_channels=indata.nr_of_elements;
   copy_channelinfo(tinfo, project_args->save_side_tinfo.channelnames, project_args->save_side_tinfo.probepos);
   tinfo->nr_of_points=indata.nr_of_vectors;
   tinfo->itemsize=indata.element_skip;
   tinfo->length_of_output_region=tinfo->nr_of_channels*tinfo->nr_of_points*tinfo->itemsize;
   retvalue=indata.start;
   tinfo->multiplexed=TRUE;
   break;
 }
 /*}}}  */

 return retvalue;
}