Esempio n. 1
0
void setdatapars(struct data *d)
{
  int i;
  char rcvrs[MAXRCVRS];

  /* Set the sequence mode from seqcon and apptype parameters */
  setseqmode(d);

  /* Set data dimensions */
  setdim(d);

  /* Number of segments and echo train length */
  /* Number of segments takes precidence, as in the setloop macro */
  d->nseg=(int)*val("nseg",&d->p);
  if (d->nseg>0) {
    d->etl=d->nv/d->nseg;
    if (d->nv%d->nseg>0) d->etl++;
  } else {
    d->etl=(int)*val("etl",&d->p);
    if (d->etl>0) {
      d->nseg=d->nv/d->etl;
      if (d->nv%d->etl>0) d->nseg++;
    }
  }
  if (d->nseg<1) {
    d->nseg=d->nv;
    d->etl=1;
  }

  /* Number of echoes */
  d->ne=(int)*val("ne",&d->p);
  if (d->ne < 1) d->ne=1; /* Set ne to 1 if 'ne' does not exist */

  /* Number of receivers */
  strcpy(rcvrs,*sval("rcvrs",&d->p));
  d->nr=0;
  for (i=0;i<strlen(rcvrs);i++)
    if (rcvrs[i] == 'y') d->nr++;

  /* Number of pss values = slices */
  d->ns=nvals("pss",&d->p);

  /* There must be at least one block per volume */
  d->nblocks=(int)*val("nblocks",&d->p);
  if (!d->nblocks) d->nblocks++;

  /* Number of points and views for resizing data */
  d->fn=(int)*val("fn",&d->p);
  d->fn1=(int)*val("fn1",&d->p);
  d->fn2=(int)*val("fn2",&d->p);
  d->fn3=(int)*val("fn3",&d->p);

  /* for cropping csi result */
  d->startd1 =(int)*val("snv",&d->p);
  d->startd1 += -1;
  d->startd2 =(int)*val("snv2",&d->p);
  d->startd2 += -1;
  d->cropd1 =(int)*val("cnv",&d->p);
  d->cropd2 =(int)*val("cnv2",&d->p);

  // for reversal of dimensions in csi
  d->d1rev = (int)*val("d1rev",&d->p);
  d->d2rev = (int)*val("d2rev",&d->p);
  d->d3rev = (int)*val("d3rev",&d->p);

  /* Navigators */
  d->nav=FALSE; /* Default is no navigator */
  if (spar(d,"navigator","y")) {
    d->nav=TRUE;
    d->nnav=nvals("nav_echo",&d->p);
    if (d->nnav>0) {
      if ((d->navpos = (int *)malloc(d->nnav*sizeof(int))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
      for (i=0;i<d->nnav;i++) d->navpos[i]=(int)val("nav_echo",&d->p)[i];
    }
  }

  /* Set profile flag */
  d->profile=FALSE;
  if (spar(d,"profile","y") && im2D(d)) d->profile=TRUE;
  if (spar(d,"profile","yy") && im3D(d)) d->profile=TRUE;

  /* Set proj2D flag */
  d->proj2D=FALSE;
  if (im3D(d)) {
    if (spar(d,"profile","yn") || spar(d,"profile","ny")) d->proj2D=TRUE;
  }

  /* Set number of dimensions */
  /* 1Ds are just 1D */
  if (im1D(d)) d->ndim=1;
  /* Multislice 2Ds and 3Ds both work on volumes, i.e. 3D */
  else if (im2D(d)) d->ndim=3;
  else if (im3D(d)) d->ndim=3;

  /* Set default status of each dimension to flag no data */
  if ((d->dimstatus = (int *)malloc(d->ndim*sizeof(int))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
  for (i=0;i<d->ndim;i++) d->dimstatus[i]=NONE;

#ifdef DEBUG
  fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__);
  fprintf(stdout,"  d->nseg    = %d\n",d->nseg);
  fprintf(stdout,"  d->etl     = %d\n",d->etl);
  fprintf(stdout,"  d->ne      = %d\n",d->ne);
  fprintf(stdout,"  d->nr      = %d\n",d->nr);
  fprintf(stdout,"  d->ns      = %d\n",d->ns);
  fprintf(stdout,"  d->fn      = %d\n",d->fn);
  fprintf(stdout,"  d->fn1     = %d\n",d->fn1);
  fprintf(stdout,"  d->fn2     = %d\n",d->fn2);
  if (d->nav) {
    fprintf(stdout,"  d->nnav    = %d",d->nnav);
    fprintf(stdout,", d->navpos = %d",d->navpos[0]);
    for (i=1;i<d->nnav;i++) fprintf(stdout,",%d",d->navpos[i]);
    fprintf(stdout,"\n");
  }
  if (d->profile) fprintf(stdout,"  d->profile = TRUE\n");
  if (d->proj2D)  fprintf(stdout,"  d->proj2D  = TRUE\n");
  fflush(stdout);
#endif
}
Esempio n. 2
0
File: ps.c Progetto: 00001/plan9port
Document*
initps(Biobuf *b, int argc, char **argv, uchar *buf, int nbuf)
{
	Document *d;
	PSInfo *ps;
	char *p;
	char *q, *r;
	char eol;
	char *nargv[1];
	char fdbuf[20];
	char tmp[32];
	int fd;
	int i;
	int incomments;
	int cantranslate;
	int trailer=0;
	int nesting=0;
	int dumb=0;
	int landscape=0;
	long psoff;
	long npage, mpage;
	Page *page;
	Rectangle bbox = Rect(0,0,0,0);

	if(argc > 1) {
		fprint(2, "can only view one ps file at a time\n");
		return nil;
	}

	fprint(2, "reading through postscript...\n");
	if(b == nil){	/* standard input; spool to disk (ouch) */
		fd = spooltodisk(buf, nbuf, nil);
		sprint(fdbuf, "/dev/fd/%d", fd);
		b = Bopen(fdbuf, OREAD);
		if(b == nil){
			fprint(2, "cannot open disk spool file\n");
			wexits("Bopen temp");
		}
		nargv[0] = fdbuf;
		argv = nargv;
	}

	/* find %!, perhaps after PCL nonsense */
	Bseek(b, 0, 0);
	psoff = 0;
	eol = 0;
	for(i=0; i<16; i++){
		psoff = Boffset(b);
		if(!(p = Brdline(b, eol='\n')) && !(p = Brdline(b, eol='\r'))) {
			fprint(2, "cannot find end of first line\n");
			wexits("initps");
		}
		if(p[0]=='\x1B')
			p++, psoff++;
		if(p[0] == '%' && p[1] == '!')
			break;
	}
	if(i == 16){
		werrstr("not ps");
		return nil;
	}

	/* page counting */
	npage = 0;
	mpage = 16;
	page = emalloc(mpage*sizeof(*page));
	memset(page, 0, mpage*sizeof(*page));

	cantranslate = goodps;
	incomments = 1;
Keepreading:
	while(p = Brdline(b, eol)) {
		if(p[0] == '%')
			if(chatty) fprint(2, "ps %.*s\n", utfnlen(p, Blinelen(b)-1), p);
		if(npage == mpage) {
			mpage *= 2;
			page = erealloc(page, mpage*sizeof(*page));
			memset(&page[npage], 0, npage*sizeof(*page));
		}

		if(p[0] != '%' || p[1] != '%')
			continue;

		if(prefix(p, "%%BeginDocument")) {
			nesting++;
			continue;
		}
		if(nesting > 0 && prefix(p, "%%EndDocument")) {
			nesting--;
			continue;
		}
		if(nesting)
			continue;

		if(prefix(p, "%%EndComment")) {
			incomments = 0;
			continue;
		}
		if(reverse == -1 && prefix(p, "%%PageOrder")) {
			/* glean whether we should reverse the viewing order */
			p[Blinelen(b)-1] = 0;
			if(strstr(p, "Ascend"))
				reverse = 0;
			else if(strstr(p, "Descend"))
				reverse = 1;
			else if(strstr(p, "Special"))
				dumb = 1;
			p[Blinelen(b)-1] = '\n';
			continue;
		} else if(prefix(p, "%%Trailer")) {
			incomments = 1;
			page[npage].offset = Boffset(b)-Blinelen(b);
			trailer = 1;
			continue;
		} else if(incomments && prefix(p, "%%Orientation")) {
			if(strstr(p, "Landscape"))
				landscape = 1;
		} else if(incomments && Dx(bbox)==0 && prefix(p, q="%%BoundingBox")) {
			bbox = rdbbox(p+strlen(q)+1);
			if(chatty)
				/* can't use %R because haven't initdraw() */
				fprint(2, "document bbox [%d %d %d %d]\n",
					RECT(bbox));
			continue;
		}

		/*
		 * If they use the initgraphics command, we can't play our translation tricks.
		 */
		p[Blinelen(b)-1] = 0;
		if((q=strstr(p, "initgraphics")) && ((r=strchr(p, '%'))==nil || r > q))
			cantranslate = 0;
		p[Blinelen(b)-1] = eol;

		if(!prefix(p, "%%Page:"))
			continue;

		/* 
		 * figure out of the %%Page: line contains a page number
		 * or some other page description to use in the menu bar.
		 * 
		 * lines look like %%Page: x y or %%Page: x
		 * we prefer just x, and will generate our
		 * own if necessary.
		 */
		p[Blinelen(b)-1] = 0;
		if(chatty) fprint(2, "page %s\n", p);
		r = p+7;
		while(*r == ' ' || *r == '\t')
			r++;
		q = r;
		while(*q && *q != ' ' && *q != '\t')
			q++;
		free(page[npage].name);
		if(*r) {
			if(*r == '"' && *q == '"')
				r++, q--;
			if(*q)
				*q = 0;
			page[npage].name = estrdup(r);
			*q = 'x';
		} else {
			snprint(tmp, sizeof tmp, "p %ld", npage+1);
			page[npage].name = estrdup(tmp);
		}

		/*
		 * store the offset info for later viewing
		 */
		trailer = 0;
		p[Blinelen(b)-1] = eol;
		page[npage++].offset = Boffset(b)-Blinelen(b);
	}
	if(Blinelen(b) > 0){
		fprint(2, "page: linelen %d\n", Blinelen(b));
		Bseek(b, Blinelen(b), 1);
		goto Keepreading;
	}

	if(Dx(bbox) == 0 || Dy(bbox) == 0)
		bbox = Rect(0,0,612,792);	/* 8½×11 */
	/*
	 * if we didn't find any pages, assume the document
	 * is one big page
	 */
	if(npage == 0) {
		dumb = 1;
		if(chatty) fprint(2, "don't know where pages are\n");
		reverse = 0;
		goodps = 0;
		trailer = 0;
		page[npage].name = "p 1";
		page[npage++].offset = 0;
	}

	if(npage+2 > mpage) {
		mpage += 2;
		page = erealloc(page, mpage*sizeof(*page));
		memset(&page[mpage-2], 0, 2*sizeof(*page));
	}

	if(!trailer)
		page[npage].offset = Boffset(b);

	Bseek(b, 0, 2); /* EOF */
	page[npage+1].offset = Boffset(b);

	d = emalloc(sizeof(*d));
	ps = emalloc(sizeof(*ps));
	ps->page = page;
	ps->npage = npage;
	ps->bbox = bbox;
	ps->psoff = psoff;

	d->extra = ps;
	d->npage = ps->npage;
	d->b = b;
	d->drawpage = psdrawpage;
	d->pagename = pspagename;

	d->fwdonly = ps->clueless = dumb;
	d->docname = argv[0];
	/*
	 * "tag" the doc as an image for now since there still is the "blank page"
	 * problem for ps files.
	 */
	d->type = Tgfx;

	if(spawngs(&ps->gs, "-dSAFER") < 0)
		return nil;

	if(!cantranslate)
		bbox.min = ZP;
	setdim(&ps->gs, bbox, ppi, landscape);

	if(goodps){
		/*
		 * We want to only send the page (i.e. not header and trailer) information
	 	 * for each page, so initialize the device by sending the header now.
		 */
		pswritepage(d, ps->gs.gsfd, -1);
		waitgs(&ps->gs);
	}

	if(dumb) {
		fprint(ps->gs.gsfd, "(%s) run\n", argv[0]);
		fprint(ps->gs.gsfd, "(/dev/fd/3) (w) file dup (THIS IS NOT A PLAN9 BITMAP 01234567890123456789012345678901234567890123456789\\n) writestring flushfile\n");
	}

	ps->bbox = bbox;

	return d;
}
Esempio n. 3
0
void defaultEPI(struct data *d)
{
  int DISCARD=-1;
  int refEPI=FALSE,refSGE=FALSE;
  int getscaleref=FALSE;
  double oversample;
  struct data ref1,ref2,ref3,ref4,ref5,ref6;
  struct segscale scale1,scale2;

  enum {
    OFF = 0,
    POINTWISE = 1,
    TRIPLE = 2,
    SCALED_TRIPLE = 3
  } epi_pc;

  setnvolsEPI(d);                     /* Set the number of data volumes */

  d->nv=(int)*val("nphase",&d->p);    /* Set d->nv for dimorder2D */
  d->pssorder=sliceorder(d,d->ns,"pss"); /* Fill pssorder with the slice order */
  d->dim2order=phaseorder(d,d->nv,d->nv,"par_does_not_exist"); /* Set dim2order=-1 for sequential phase encode order */
  d->dim3order=phaseorder(d,d->nv,d->nv,"sgepelist"); /* Fill dim3order with the standard gradient echo phase encode order */
  d->nv2=d->nv;                       /* Set d->nv2 for dim3order */
  d->nv=(int)*val("nseg",&d->p);      /* Use d->nv for the number of shots */

  /* Set EPI correction scheme */
  if (spar(d,"epi_pc","POINTWISE")) epi_pc=POINTWISE;
  else if (spar(d,"epi_pc","TRIPLE")) epi_pc=TRIPLE;
  else if (spar(d,"epi_pc","SCALED_TRIPLE")) epi_pc=SCALED_TRIPLE;
  else epi_pc=OFF;

  /* Check whether to output or discard reference scans */
  if (spar(d,"imRF","y")) refEPI=TRUE;
  if (spar(d,"imSGE","y")) refSGE=TRUE;

  /* Set reference data */
  if (epi_pc > OFF) {        /* Pointwise or triple reference phase correction */
    initdatafrom(d,&ref1);
    initdatafrom(d,&ref3);   /* ref3 used in pointwise phase correction of inverted
                                reference scans if reference output is selected */
  }
  if (epi_pc > POINTWISE) {  /* Triple reference phase corrections */
    initdatafrom(d,&ref2);
    initdatafrom(d,&ref4);
  }
  if (epi_pc > TRIPLE) { /* Scaled triple reference phase correction */
    initdatafrom(d,&ref5);
    initdatafrom(d,&ref6);
  }

  /* Set default of no compressed segment scaling just in case it's never set */
  scale1.data=FALSE;
  scale2.data=FALSE;

  /* Loop over data blocks */
  for (d->block=0;d->block<d->nblocks;d->block++) {

    if (interupt) return;             /* Interupt/cancel from VnmrJ */

    d->outvol=0; /* Initialise output data volume (that will not include reference scans) */

    for (d->vol=0;d->vol<d->nvols;d->vol++) { /* Loop over "volumes" */

      setoutvolEPI(d);                /* Set output data volume */

      if (d->outvol>d->endvol) break; /* Break if last requested volume has been processed */

      getblockEPI(d,d->vol,NDCC);     /* Get block without applying dbh.lvl and dbh.tlt */
      zeromax(d);                     /* Zero max structure & coordinates of maximum */
      zeronoise(d);                   /* Zero values in noise structure */

#ifdef DEBUG
  fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__);
  switch (epi_pc) {
    case OFF: fprintf(stdout,"  Correction: OFF \n"); break;
    case POINTWISE: fprintf(stdout,"  Correction: POINTWISE \n"); break;
    case TRIPLE: fprintf(stdout,"  Correction: TRIPLE \n"); break;
    case SCALED_TRIPLE: fprintf(stdout,"  Correction: SCALED_TRIPLE \n"); break;
  }
  fflush(stdout);
#endif

      /* Process data as directed by image parameter */
      switch ((int)getelem(d,"image",d->vol)) {

        case 0:   /* Reference, no phase-encode */
          setblockEPI(d);                     /* Set block for 2D data (d->nv > 1) and navigators */
          if (refEPI) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */
          if (epi_pc > OFF) {                 /* If there is phase correction */
            ftnpEPI(d);                       /* FT along readout dimension */
            clear2Ddata(&ref1);               /* Clear ref1 */
            copy2Ddata(d,&ref1);              /* Copy to ref1 */
            ref1.datamode=EPIREF;             /* Flag as EPIREF data */
          } else {                            /* else there is no phase correction */
            ref1.datamode=NONE;               /* Flag as no data */
            if (refEPI) ftnpEPI(d);           /* FT along readout dimension */
          }
          setsegscale(d,&scale1);             /* Set scaling for compressed segments */
          segscale(d,&scale1);                /* Scale compressed segments */
          if (refEPI)                         /* If reference output is requested */
            w2Dfdfs(d,VJ,FLT32,d->vol);       /* Output data for the volume */
          else w2Dfdfs(d,VJ,FLT32,DISCARD);   /* Else use DISCARD to flag skip the volume */
          wnifti(d,VJ,FLT32,DISCARD);
          break;
        case -1:  /* Inverted Readout Reference, with phase-encode */
#ifdef DEBUG
  fprintf(stdout,"  Processing reference -1 data ...\n");
  fflush(stdout);
#endif
          setblockEPI(d);                     /* Set block for 2D data (d->nv > 1) and navigators */
          if (refEPI) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */
          ftnpEPI(d);                         /* FT along readout dimension */
          segscale(d,&scale2);                /* Scale compressed segments */
          if (epi_pc > POINTWISE) {           /* if triple or scaled triple reference phase correction */
            clear2Ddata(&ref2);               /* Clear ref2 */
            copy2Ddata(d,&ref2);              /* Copy to ref2 */
            ref2.datamode=EPIREF;             /* Flag ref2 as EPIREF data */
            if (ref3.datamode == EPIREF) {    /* if there is ref3 reference data */
              phaseEPIref(&ref2,&ref3,&ref4); /* Phase correct ref2 data using ref3 and put result in ref4 */
/*              analyseEPInav(&ref4);           // Analyse the navigators */
              stripEPInav(&ref4);             /* Strip the navigator scans */
              ftnvEPI(&ref4);                 /* FT along phase encode dimension */
              revreadEPI(&ref4);              /* Reverse the data in readout dimension */
              getscaleref=TRUE;               /* Flag to store the next regular image for scaling in SCALED_TRIPLE */
            }
          }
          if (refEPI) {                       /* if reference output is requested */
            if (ref3.datamode == EPIREF) {    /* if there is ref3 reference data */
              phaseEPI(d,&ref3);              /* Phase correct with the reference */
            }
            navcorrEPI(d);                    /* Phase correct with the navigator */
            stripEPInav(d);                   /* Strip the navigator scans */
            ftnvEPI(d);                       /* FT along phase encode dimension */
            revreadEPI(d);                    /* Reverse the data in readout dimension */
            w2Dfdfs(d,VJ,FLT32,d->vol);       /* Output data for the volume */
          }
          else w2Dfdfs(d,VJ,FLT32,DISCARD);   /* Use DISCARD to flag skip the volume */
          wnifti(d,VJ,FLT32,DISCARD);
          break;
        case -2:  /* Inverted Readout Reference, no phase-encode */
#ifdef DEBUG
  fprintf(stdout,"  Processing reference -2 data ...\n");
  fflush(stdout);
#endif
          setblockEPI(d);                     /* Set block for 2D data (d->nv > 1) and navigators */
          if (refEPI) w2Dfdfs(d,VJ,FLT32,d->vol);
          ftnpEPI(d);                         /* FT along readout dimension */
          setsegscale(d,&scale2);             /* Set scaling for compressed segments */
          segscale(d,&scale2);                /* Scale compressed segments */
          if (epi_pc > POINTWISE) {           /* if old triple or triple reference phase correction */
            clear2Ddata(&ref3);               /* Clear ref3 */
            copy2Ddata(d,&ref3);              /* Copy to ref3 */
            ref3.datamode=EPIREF;             /* Flag ref3 as EPIREF data */
            if (ref2.datamode == EPIREF) {    /* if there is ref2 reference data */
              phaseEPIref(&ref2,&ref3,&ref4); /* Phase correct ref2 data using ref3 and put result in ref4 */
/*              analyseEPInav(&ref4);           // Analyse the navigators */
              stripEPInav(&ref4);             /* Strip the navigator scans */
              ftnvEPI(&ref4);                 /* FT along phase encode dimension */
              revreadEPI(&ref4);              /* Reverse the data in readout dimension */
              getscaleref=TRUE;               /* Flag to store the next regular image for scaling in SCALED_TRIPLE */
            }
          }
          if (refEPI) {                       /* if reference output is requested */
            if (epi_pc == POINTWISE) {        /* if pointwise reference phase correction */
              clear2Ddata(&ref3);             /* Clear ref3 */
              copy2Ddata(d,&ref3);            /* Copy to ref3 */
              ref3.datamode=EPIREF;           /* Flag ref3 as EPIREF data */
            }
            revreadEPI(d);                    /* Reverse the data in readout dimension */
            w2Dfdfs(d,VJ,FLT32,d->vol);       /* Output data for the volume */
          }
          else w2Dfdfs(d,VJ,FLT32,DISCARD);   /* Use DISCARD to flag skip the volume */
          wnifti(d,VJ,FLT32,DISCARD);
          break;
        case 1:   /* Regular image */
#ifdef DEBUG
  fprintf(stdout,"  Processing image 1 data ...\n");
  fflush(stdout);
#endif
          setblockEPI(d);                     /* Set block for 2D data (d->nv > 1) and navigators */
          if (d->outvol>=d->startvol)
            w2Dfdfs(d,VJ,FLT32,d->vol);       /* Output raw data for the volume, if requested */
          switch (epi_pc) {
            case SCALED_TRIPLE:               /* Scaled triple reference phase correction */
              if (getscaleref) {              /* If the scale reference has just been acquired */
                clear2Ddata(&ref5);           /* Clear ref5 */
                copy2Ddata(d,&ref5);          /* Copy to ref5 */
                ref5.datamode=EPIREF;         /* Flag ref5 as EPIREF data */
                prepEPIref(&ref5,&ref1);      /* Prepare ref5 data so it can be used to scale ref4 data */
              }
              break;
            default:
              break;
          }
          ftnpEPI(d);                         /* FT along readout dimension */
          segscale(d,&scale1);                /* Scale compressed segments */
          phaseEPI(d,&ref1);                  /* Phase correct with the reference */
          navcorrEPI(d);                      /* Phase correct with the navigator */
/*          analyseEPInav(d);                   // Analyse the navigators */
          stripEPInav(d);                     /* Strip the navigator scans */
          ftnvEPI(d);                         /* FT along phase encode dimension */
          switch (epi_pc) {
            case TRIPLE:                      /* Triple reference phase correction */
              addEPIref(d,&ref4);             /* Add ref4 data to cancel N/2 ghost */
              break;
            case SCALED_TRIPLE:               /* Scaled triple reference phase correction */
              if (getscaleref) {              /* If the scale reference has just been acquired */
                addEPIref(d,&ref4);           /* Add ref4 data to cancel N/2 ghost */
                getscaleref=FALSE;            /* Flag that scale reference has been acquired */
              } else {
                addscaledEPIref(d,&ref4,&ref5); /* Scale ref4 data according to d/ref5, then add to d */
              }
              break;
            default:
              break;
          }
          if (d->outvol>=d->startvol) {
            phasedata2D(d,VJ);                /* Phase data if required */
            w2Dfdfs(d,VJ,FLT32,d->vol);       /* Write 2D fdf data from volume */
            wnifti(d,VJ,FLT32,d->vol);
          }
          break;
        default: /* Reference Standard Gradient Echo */
          setblockSGE(d);
          if (refSGE) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */
          shiftdata2D(d,STD);                 /* Shift FID data for fft */
          zeronoise(d);                       /* Zero any noise measurement */
          equalizenoise(d,STD);               /* Scale for equal noise in all receivers */
          phaseramp2D(d,READ);                /* Phase ramp the data to correct for readout offset pro */
          phaseramp2D(d,PHASE);               /* Phase ramp the data to correct for phase encode offset ppe */
          weightdata2D(d,STD);                /* Weight data using standard VnmrJ parameters */
          zerofill2D(d,STD);                  /* Zero fill data using standard VnmrJ parameters */
          fft2D(d,STD);                       /* 2D fft */
          phasedata2D(d,VJ);                  /* Phase data if required */
          shiftdata2D(d,STD);                 /* Shift data to get images */
          oversample=*val("oversample",&d->p); /* Check to see if there is oversampling */
          if (oversample>1) zoomEPI(d);       /* If oversampled, zoom to get the requested FOV */
          if (refSGE)                         /* If standard gradient echo reference output is requested */
            w2Dfdfs(d,VJ,FLT32,d->vol);       /* Output data for the volume */
          else w2Dfdfs(d,VJ,FLT32,DISCARD);   /* Else use DISCARD to flag skip the volume */
          wnifti(d,VJ,FLT32,DISCARD);
          break;
      } /* end image parameter switch */

      clear2Ddata(d);               /* Clear data volume from memory */
      setdim(d);                    /* Reset data dimensions in case data has been zerofilled (sets d->nv=1) */
      d->nv=*val("nseg",&d->p);     /* Use d->nv for the number of shots */
      d->nv2=(int)*val("nphase",&d->p); /* Use d->nv2 for number of standard gradient echo phase encodes */
      d->dimstatus[0] = NONE;       /* Make sure ZEROFILL status is not set, otherwise setdim will be called in getblock() */
      d->dimstatus[1] = NONE;       /* Make sure ZEROFILL status is not set, otherwise setdim will be called in getblock() */

    } /* end volume loop */

  } /* end data block loop */

  /* Clear all reference data */
  if (epi_pc > OFF) {        /* Pointwise or triple reference phase correction */
    clear2Dall(&ref1);
    clear2Dall(&ref3);
  }
  if (epi_pc > POINTWISE) {  /* Triple and scaled triple reference phase correction */
    clear2Dall(&ref2);
    clear2Dall(&ref4);
  }
  if (epi_pc > TRIPLE) {     /* Scaled triple reference phase correction */
    clear2Dall(&ref5);
    clear2Dall(&ref6);
  }

  clear2Dall(d);             /* Clear everything from memory */

}
Esempio n. 4
0
void
emulate(void)
{
	char buf[BUFS+1];
	int i;
	int n;
	int c;
	int operand[10];
	int noperand;
	int savex, savey, saveattr, saveisgraphics;
	int isgraphics;
	int g0set, g1set;
	int dch;

	isgraphics = 0;
	g0set = 'B';	/* US ASCII */
	g1set = 'B';	/* US ASCII */
	savex = savey = 0;
	yscrmin = 0;
	yscrmax = ymax;
	saveattr = 0;
	saveisgraphics = 0;
	/* set initial tab stops to DEC-standard 8-column spacing */
	for(c=0; (c+=8)<nelem(tabcol);)
		tabcol[c] = 1;

	for (;;) {
		if (y > ymax) {
			x = 0;
			newline();
		}
		buf[0] = get_next_char();
		buf[1] = '\0';
		switch(buf[0]) {

		case '\000':
		case '\001':
		case '\002':
		case '\003':
		case '\004':
		case '\005':
		case '\006':
			goto Default;

		case '\007':		/* bell */
			ringbell();
			break;

		case '\010':		/* backspace */
			if (x > 0)
				--x;
			break;

		case '\011':		/* tab to next tab stop; if none, to right margin */
			for(c=x+1; c<nelem(tabcol) && !tabcol[c]; c++)
				;
			if(c < nelem(tabcol))
				x = c;
			else
				x = xmax;
			break;

		case '\012':		/* linefeed */
		case '\013':
		case '\014':
			newline();
			if (ttystate[cs->raw].nlcr)
				x = 0;
			break;

		case '\015':		/* carriage return */
			x = 0;
			if (ttystate[cs->raw].crnl)
				newline();
			break;

		case '\016':	/* SO: invoke G1 char set */
			isgraphics = (isdigit(g1set));
			break;
		case '\017':	/* SI: invoke G0 char set */
			isgraphics = (isdigit(g0set));
			break;

		case '\020':	/* DLE */
		case '\021':	/* DC1 */
		case '\022':	/* XON */
		case '\023':	/* DC3 */
		case '\024':	/* XOFF */
		case '\025':	/* NAK */
		case '\026':	/* SYN */
		case '\027':	/* ETB */
		case '\030':	/* CAN: cancel escape sequence, display checkerboard (not implemented) */
		case '\031':	/* EM */
		case '\032':	/* SUB: same as CAN */
			goto Default;
;
		/* ESC, \033, is handled below */
		case '\034':	/* FS */
		case '\035':	/* GS */
		case '\036':	/* RS */
		case '\037':	/* US */
			break;
		case '\177':	/* delete: ignored */
			break;

		case '\033':
			switch(dch = get_next_char()){
			/*
			 * 1 - graphic processor option on (no-op; not installed)
			 */
			case '1':
				break;

			/*
			 * 2 - graphic processor option off (no-op; not installed)
			 */
			case '2':
				break;

			/*
			 * 7 - save cursor position.
			 */
			case '7':
//print("save\n");
				savex = x;
				savey = y;
				saveattr = attr;
				saveisgraphics = isgraphics;
				break;

			/*
			 * 8 - restore cursor position.
			 */
			case '8':
//print("restore\n");
				x = savex;
				y = savey;
				attr = saveattr;
				isgraphics = saveisgraphics;
				break;

			/*
			 * c - Reset terminal.
			 */
			case 'c':
print("resetterminal\n");
				cursoron = 1;
				ttystate[cs->raw].nlcr = 0;
				break;

			/*
			 * D - active position down a line, scroll if at bottom margin.
			 * (Original VT100 had a bug: tracked new-line/line-feed mode.)
			 */
			case 'D':
				if(++y > yscrmax) {
					y = yscrmax;
					scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmax);
				}
				break;

			/*
			 * E - active position to start of next line, scroll if at bottom margin.
			 */
			case 'E':
				x = 0;
				if(++y > yscrmax) {
					y = yscrmax;
					scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmax);
				}
				break;

			/*
			 * H - set tab stop at current column.
			 * (This is cursor home in VT52 mode (not implemented).)
			 */
			case 'H':
				if(x < nelem(tabcol))
					tabcol[x] = 1;
				break;

			/*
			 * M - active position up a line, scroll if at top margin..
			 */
			case 'M':
				if(--y < yscrmin) {
					y = yscrmin;
					scroll(yscrmin, yscrmax, yscrmin+1, yscrmin);
				}
				break;

			/*
			 * Z - identification.  the terminal
			 * emulator will return the response
			 * code for a generic VT100.
			 */
			case 'Z':
			Ident:
				sendnchars2(7, "\033[?1;2c");	/* VT100 with AVO option */
//				sendnchars2(5, "\033[?6c");	/* VT102 (insert/delete-char, etc.) */
				break;

			/*
			 * < - enter ANSI mode
			 */
			case '<':
				break;

			/*
			 * > - set numeric keypad mode on (not implemented)
			 */
			case '>':
				break;

			/*
			 * = - set numeric keypad mode off (not implemented)
			 */
			case '=':
				break;

			/*
			 * # - Takes a one-digit argument
			 */
			case '#':
				switch(get_next_char()){
				case '3':		/* Top half of double-height line */
				case '4':		/* Bottom half of double-height line */
				case '5':		/* Single-width single-height line */
				case '6':		/* Double-width line */
				case '7':		/* Screen print */
				case '8':		/* Fill screen with E's */
					break;
				}
				break;

			/*
			 * ( - switch G0 character set
			 */
			case '(':
				g0set = get_next_char();
				break;

			/*
			 * - switch G1 character set
			 */
			case ')':
				g1set = get_next_char();
				break;

			/*
			 * Received left bracket.
			 */
			case '[':
				/*
				 * A semi-colon or ? delimits arguments.
				 */
				memset(operand, 0, sizeof(operand));
				operand[0] = number(buf, &i);
				noperand = 1;
				while(buf[0] == ';' || buf[0] == '?'){
					if(noperand < nelem(operand)){
						noperand++;
						operand[noperand-1] = number(buf, nil);
					} else
						number(buf, nil);
				}

				/*
				 * do escape2 stuff
				 */
				switch(dch = buf[0]){
					/*
					 * c - same as ESC Z: what are you?
					 */
					case 'c':
						goto Ident;

					/*
					 * g - various tabstop manipulation
					 */
					case 'g':
						switch(operand[0]){
						case 0:	/* clear tab at current column */
							if(x < nelem(tabcol))
								tabcol[x] = 0;
							break;
						case 3:	/* clear all tabs */
							memset(tabcol, 0, sizeof tabcol);
							break;
						}
						break;

					/*
					 * l - clear various options.
					 */
					case 'l':
						if(noperand == 1){
							switch(operand[0]){
							case 20:	/* set line feed mode */
								ttystate[cs->raw].nlcr = 1;
								break;
							case 30:	/* screen invisible (? not supported through VT220) */
								break;
							}
						}else while(--noperand > 0){
							switch(operand[noperand]){
							case 1:	/* set cursor keys to send ANSI functions: ESC [ A..D */
								break;
							case 2:	/* set VT52 mode (not implemented) */
								break;
							case 3:	/* set 80 columns */
								setdim(-1, 80);
								break;
							case 4:	/* set jump scrolling */
								break;
							case 5:	/* set normal video on screen */
								break;
							case 6:	/* set origin to absolute */
								originrelative = 0;
								x = y = 0;
								break;
							case 7:	/* reset auto-wrap mode */
								wraparound = 0;
								break;
							case 8:	/* reset auto-repeat mode */
								break;
							case 9:	/* reset interlacing mode */
								break;
							case 25:	/* text cursor off (VT220) */
								cursoron = 0;
								break;
							}
						}
						break;

					/*
					* s - some dec private stuff. actually [ ? num s, but we can't detect it.
					*/
					case 's':
						break;

					/*
					 * h - set various options.
					 */
					case 'h':
						if(noperand == 1){
							switch(operand[0]){
							default:
								break;
							case 20:	/* set newline mode */
								ttystate[cs->raw].nlcr = 0;
								break;
							case 30:	/* screen visible (? not supported through VT220) */
								break;
							}
						}else while(--noperand > 0){
							switch(operand[noperand]){
							default:
								break;
							case 1:	/* set cursor keys to send application function: ESC O A..D */
								break;
							case 2:	/* set ANSI */
								break;
							case 3:	/* set 132 columns */
								setdim(-1, 132);
								break;
							case 4:	/* set smooth scrolling */
								break;
							case 5:	/* set screen to reverse video (not implemented) */
								break;
							case 6:	/* set origin to relative */
								originrelative = 1;
								x = 0;
								y = yscrmin;
								break;
							case 7:	/* set auto-wrap mode */
								wraparound = 1;
								break;
							case 8:	/* set auto-repeat mode */
								break;
							case 9:	/* set interlacing mode */
								break;
							case 25:	/* text cursor on (VT220) */
								cursoron = 1;
								break;
							}
						}
						break;

					/*
					 * m - change character attrs.
					 */
					case 'm':
						setattr(noperand, operand);
						break;

					/*
					 * n - request various reports
					 */
					case 'n':
						switch(operand[0]){
						case 5:	/* status */
							sendnchars2(4, "\033[0n");	/* terminal ok */
							break;
						case 6:	/* cursor position */
							sendnchars2(sprint(buf, "\033[%d;%dR",
								originrelative ? y+1 - yscrmin : y+1, x+1), buf);
							break;
						}
						break;

					/*
					 * q - turn on list of LEDs; turn off others.
					 */
					case 'q':
						break;

					/*
					 * r - change scrolling region.  operand[0] is
					 * min scrolling region and operand[1] is max
					 * scrolling region.
					 */
					case 'r':
						yscrmin = 0;
						yscrmax = ymax;
						switch(noperand){
						case 2:
							yscrmax = operand[1]-1;
							if(yscrmax > ymax)
								yscrmax = ymax;
						case 1:
							yscrmin = operand[0]-1;
							if(yscrmin < 0)
								yscrmin = 0;
						}
						x = 0;
						y = yscrmin;
						break;

					/*
					 * x - report terminal parameters
					 */
					case 'x':
						sendnchars2(20, "\033[3;1;1;120;120;1;0x");
						break;

					/*
					 * y - invoke confidence test
					 */
					case 'y':
						break;

					/*
					 * A - cursor up.
					 */
					case 'e':
					case 'A':
						fixops(operand);
						y -= operand[0];
						if(y < yscrmin)
							y = yscrmin;
						olines -= operand[0];
						if(olines < 0)
							olines = 0;
						break;

					/*
					 * B - cursor down
					 */
					case 'B':
						fixops(operand);
						y += operand[0];
						if(y > yscrmax)
							y=yscrmax;
						break;

					/*
					 * C - cursor right
					 */
					case 'a':
					case 'C':
						fixops(operand);
						x += operand[0];
						/*
						 * VT-100-UG says not to go past the
						 * right margin.
						 */
						if(x > xmax)
							x = xmax;
						break;

					/*
					 * D - cursor left
					 */
					case 'D':
						fixops(operand);
						x -= operand[0];
						if(x < 0)
							x = 0;
						break;

					/*
					 *	G - cursor to column
					 */
					case '\'':
					case 'G':
						fixops(operand);
						x = operand[0] - 1;
						if(x > xmax)
							x = xmax;
						break;

					/*
					 * H and f - cursor motion.  operand[0] is row and
					 * operand[1] is column, origin 1.
					 */
					case 'H':
					case 'f':
						fixops(operand+1);
						x = operand[1] - 1;
						if(x > xmax)
							x = xmax;

						/* fallthrough */

					/*
					 * d - cursor to line n (xterm)
					 */
					case 'd':
						fixops(operand);
						y = operand[0] - 1;
						if(originrelative){
							y += yscrmin;
							if(y > yscrmax)
								y = yscrmax;
						}else{
							if(y > ymax)
								y = ymax;
						}
						break;

					/*
					 * J - clear some or all of the display.
					 */
					case 'J':
						switch (operand[0]) {
							/*
							 * operand 2:  whole screen.
							 */
							case 2:
								clear(Rpt(pt(0, 0), pt(xmax+1, ymax+1)));
								break;
							/*
							 * operand 1: start of screen to active position, inclusive.
							 */
							case 1:
								clear(Rpt(pt(0, 0), pt(xmax+1, y)));
								clear(Rpt(pt(0, y), pt(x+1, y+1)));
								break;
							/*
							 * Default:  active position to end of screen, inclusive.
							 */
							default:
								clear(Rpt(pt(x, y), pt(xmax+1, y+1)));
								clear(Rpt(pt(0, y+1), pt(xmax+1, ymax+1)));
								break;
						}
						break;

					/*
					 * K - clear some or all of the line.
					 */
					case 'K':
						switch (operand[0]) {
							/*
							 * operand 2: whole line.
							 */
							case 2:
								clear(Rpt(pt(0, y), pt(xmax+1, y+1)));
								break;
							/*
							 * operand 1: start of line to active position, inclusive.
							 */
							case 1:
								clear(Rpt(pt(0, y), pt(x+1, y+1)));
								break;
							/*
							 * Default: active position to end of line, inclusive.
							 */
							default:
								clear(Rpt(pt(x, y), pt(xmax+1, y+1)));
								break;
						}
						break;

					/*
					 *	P - delete character(s) from right of cursor (xterm)
					 */
					case 'P':
						fixops(operand);
						i = x + operand[0];
						draw(screen, Rpt(pt(x, y), pt(xmax+1, y+1)), screen, nil, pt(i, y));
						clear(Rpt(pt(xmax-operand[0], y), pt(xmax+1, y+1)));
						break;

					/*
					 *	@ - insert blank(s) to right of cursor (xterm)
					 */
					case '@':
						fixops(operand);
						i = x + operand[0];
						draw(screen, Rpt(pt(i, y), pt(xmax+1, y+1)), screen, nil, pt(x, y));
						clear(Rpt(pt(x, y), pt(i, y+1)));
						break;


					/*
					 *	X - erase character(s) at cursor and to the right (xterm)
					 */
					case 'X':
						fixops(operand);
						i = x + operand[0];
						clear(Rpt(pt(x, y), pt(i, y+1)));
						break;

					/*
					 * L - insert a line at cursor position (VT102 and later)
					 */
					case 'L':
						fixops(operand);
						for(i = 0; i < operand[0]; ++i)
							scroll(y, yscrmax, y+1, y);
						break;

					/*
					 * M - delete a line at cursor position (VT102 and later)
					 */
					case 'M':
						fixops(operand);
						for(i = 0; i < operand[0]; ++i)
							scroll(y+1, yscrmax+1, y, yscrmax);
						break;

					/*
					 * S,T - scroll up/down (xterm)
					 */
					case 'T':
						fixops(operand);
						for(i = 0; i < operand[0]; ++i)
							scroll(yscrmin, yscrmax, yscrmin+1, yscrmin);
						break;

					case 'S':
						fixops(operand);
						for(i = 0; i < operand[0]; ++i)
							scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmin);
						break;

					case '=':	/* ? not supported through VT220 */
						number(buf, nil);
						switch(buf[0]) {
						case 'h':
						case 'l':
							break;
						}
						break;

					/*
					 * Anything else we ignore for now...
					 */
					default:
print("unknown escape2 '%c' (0x%x)\n", dch, dch);
						break;
				}

				break;

			/*
			 * Collapse multiple '\033' to one.
			 */
			case '\033':
				peekc = '\033';
				break;

			/* set title */
			case ']':	/* it's actually <esc> ] num ; title <bel> */
				{
					int ch, fd;
					number(buf, nil);
					i = 0;
					while((ch = get_next_char()) != '\a')
						if(i < sizeof buf)
							buf[i++] = ch;
					fd = open("/dev/label", OWRITE);
					write(fd, buf, i);
					close(fd);
				}
				break;

			/*
			 * Ignore other commands.
			 */
			default:
print("unknown command '%c' (0x%x)\n", dch, dch);
				break;

			}
			break;

		default:		/* ordinary char */
Default:
			if(isgraphics && gmap[(uint8_t) buf[0]])
				buf[0] = gmap[(uint8_t) buf[0]];

			/* line wrap */
			if (x > xmax){
				if(wraparound){
					x = 0;
					newline();
				}else{
					continue;
				}
			}
			n = 1;
			c = 0;
			while (!cs->raw && host_avail() && x+n<=xmax && n<BUFS
			    && (c = get_next_char())>=' ' && c<'\177') {
				buf[n++] = c;
				c = 0;
			}
			buf[n] = 0;
//			clear(Rpt(pt(x,y), pt(x+n, y+1)));
			drawstring(pt(x, y), buf, attr);
			x += n;
			peekc = c;
			break;
		}
	}
}
Esempio n. 5
0
void prescanEPI(struct data *d)
{
  int dim1,dim2,dim3,nr;
  double oversample;
  int nread;
  int rampsamp=FALSE,linearsamp=FALSE;

  setnvolsEPI(d);                     /* Set the number of data volumes */

  d->nv=(int)*val("nphase",&d->p);    /* Set d->nv for dimorder2D */
  d->pssorder=sliceorder(d,d->ns,"pss"); /* Fill pssorder with the slice order */
  d->dim2order=phaseorder(d,d->nv,d->nv,"par_does_not_exist"); /* Set dim2order=-1 for sequential phase encode order */
  d->dim3order=phaseorder(d,d->nv,d->nv,"sgepelist"); /* Fill dim3order with the standard gradient echo phase encode order */
  d->nv2=d->nv;                       /* Set d->nv2 for dim3order */
  d->nv=(int)*val("nseg",&d->p);      /* Use d->nv for the number of shots */

  /* Set data dimensions */
  dim3=d->endpos-d->startpos; nr=d->nr;

  /* Check for oversampling */
  oversample=*val("oversample",&d->p);
  if (spar(d,"rampsamp","y")) rampsamp=TRUE;
  if (spar(d,"linearsamp","y")) linearsamp=TRUE;
  nread=(int)*val("nread",&d->p)/2;

  for (d->vol=0;d->vol<d->nvols;d->vol++) { /* loop over "volumes" */

    if (interupt) return;           /* Interupt/cancel from VnmrJ */

    /* Loop over data blocks */
    for (d->block=0;d->block<d->nblocks;d->block++) {

      getblockEPI(d,d->vol,NDCC);   /* Get block without applying dbh.lvl and dbh.tlt */
      zeromax(d);                   /* Zero max structure & coordinates of maximum */
      zeronoise(d);                 /* Zero values in noise structure */

      setblockEPI(d);

      /* Set data dimensions */
      dim1=d->np/2; dim2=d->nv;

      if (vnmrj_recon) settep(d,STD);

      /* If oversampled or ramp and linear sampling, zoom to get the requested matrix size */
      if ((oversample==1) && rampsamp && linearsamp) zoomdata2D(d,(dim1-nread)/2,nread,0,dim2);
      else if ((oversample>1) || (rampsamp && linearsamp)) zoomdata2D(d,(dim1-1.5*nread)/2,1.5*nread,0,dim2);

      /* Flag the data as IMAGE since magnitude output is combined from multiple receivers */
      d->dimstatus[0]+=FFT;

      /* We always want to view prescan with same orientation so fix it as though it's axial */
      setval(&d->p,"psi",180.0);
      setval(&d->p,"phi",0.0);
      setval(&d->p,"theta",0.0);

      w2Dfdfs(d,VJ,FLT32,d->vol);   /* Write 2D fdf raw data from volume */

      /* Properly flag the data as FID */
      d->dimstatus[0]-=FFT;

      clear2Ddata(d);               /* Clear data volume from memory */
      setdim(d);                    /* Reset data dimensions in case data has been zerofilled (sets d->nv=1) */
      d->nv=*val("nseg",&d->p);     /* Use d->nv for the number of shots */
      d->dimstatus[0] = NONE;       /* Make sure ZEROFILL status is not set, otherwise setdim will be called in getblock() */
      d->dimstatus[1] = NONE;       /* Make sure ZEROFILL status is not set, otherwise setdim will be called in getblock() */

    }

  }

}