Esempio n. 1
0
int checkequal(struct data *d1,struct data *d2,char *par,char *comment)
{
  int i;
  double *val1,*val2;

  if (nvals(par,&d1->p) != nvals(par,&d2->p)) {
#ifdef DEBUG
  fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__);
  fprintf(stdout,"  %s and %s have different number of %s\n",d2->procpar,d1->procpar,comment);
  fprintf(stdout,"  Aborting recon of %s ...\n",d1->file);
  fflush(stdout);
#endif
    return(FALSE);
  }
  val1=val(par,&d1->p);
  val2=val(par,&d2->p);
  for (i=0;i<nvals(par,&d1->p);i++) {
    if (val1[i] != val2[i]) {
#ifdef DEBUG
  fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__);
  fprintf(stdout,"  %s and %s have different %s\n",d2->procpar,d1->procpar,comment);
  fprintf(stdout," Aborting recon of %s ...\n",d1->file);
  fflush(stdout);
#endif
      return(FALSE);
    }
  }
  return(TRUE);
}
Esempio n. 2
0
void del3Draw(struct data *d,char *dir)
{
  char filename[MAXPATHLEN];
  int volindex;
  int ne,ns;
  int slab,image,echo;

  volindex=d->vol;

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

  /* Number of slices (slabs) */
  ns=nvals("pss",&d->p);
  if (ns < 1) ns=1; /* Set ns to 1 if 'ns' does not exist */

  /* Allow for compressed multi-echo loop and multiple slabs */
  image=volindex/(ne*ns);
  slab=(volindex/ne)%ns;
  echo=volindex%ne;

  sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dir,slab+1,image+1,echo+1);
  remove(filename);
}
Esempio n. 3
0
double getelem(struct data *d,char *par,int image)
{
  double *dbl;
  int cycle,n,id;
  dbl=val(par,&d->p);
  if (arraycheck(par,&d->a)) { /* parameter is arrayed */
    cycle=getcycle(par,&d->a);
    n=nvals(par,&d->p);
    id=(image/cycle)%n;
    return(dbl[id]);
  } else { /* par is not in array string */
    n=nvals(par,&d->p);
    if (n>1) {
      id=image%n; /* assume cycle=1 */
      return(dbl[id]);
    } else {
      return(dbl[0]);
    }
  }
}
Esempio n. 4
0
void setnvols(struct data *d)
{
  int nvols;
  int listlen;
  char seqcon[6];

  /* To figure the number of volumes insist we must have the following */
  if ((ptype("np",&d->p) < 0) || (ptype("nv",&d->p) < 0)
    || (ptype("nv2",&d->p) < 0) || (ptype("pss",&d->p) < 0) 
    || (ptype("rcvrs",&d->p) < 0) || (ptype("seqcon",&d->p) < 0) 
    || (ptype("arraydim",&d->p) < 0) || (ptype("nf",&d->p) < 0)) {
    fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
    fprintf(stderr,"  The following values are required from a 'procpar':\n");
    fprintf(stderr,"  np nv nv2 pss rcvrs seqcon arraydim nf\n\n");
    fprintf(stderr," Aborting ...\n\n");
    fflush(stderr);
    exit(1);
  }

  if (d->seqmode>=IM4D) {  /* 4D or 3D CSI */
    if(ptype("nv3",&d->p) < 0)
      {
	fprintf(stderr,"  Invalid value for nv3 in procpar \n\n");
	fprintf(stderr,"  Aborting ...\n\n");
	fflush(stderr);
	exit(1);
      }
  }

  /* Sanity check */
  if ((d->np != d->fh.np) || ((int)*val("nf",&d->p) != d->fh.ntraces)) {
    fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
    fprintf(stderr,"  Check data file and procpar file are compatible\n");
    fprintf(stderr,"  procpar np = %d and nf = %d\n",d->np,(int)*val("nf",&d->p));
    fprintf(stderr,"  fid     np = %d and ntraces= %d\n",d->fh.np,d->fh.ntraces);
    fprintf(stderr,"  Aborting ...\n\n");
    fflush(stderr);
    exit(1);
  }

  /* Use value of arraydim to calculate the total number of volumes */
  nvols=(int)*val("arraydim",&d->p);
  /* Multiple echoes generate 'ne' volumes that are not arrayed */
  nvols*=d->ne;
  /* Multiple receivers generate 'nr' volumes included in arraydim */
  if (nvols%d->nr != 0) {
    fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
    fprintf(stderr,"  Problem calculating number of volumes\n");
    fprintf(stderr,"  Check data file and procpar file are compatible\n");
    fprintf(stderr,"  Aborting ...\n\n");
    fflush(stderr);
    exit(1);
  }
  nvols/=d->nr;

  /* Check for 'standard' slice and phase loops as these
     generate volumes included in arraydim */
  strcpy(seqcon,*sval("seqcon",&d->p));
  if (d->seqmode<IM3D) {  /* 2D */
    /* 'standard' slice loop has pss arrayed */
    if (seqcon[1] == 's') nvols/=d->ns;
  } else { /* 3D */
    /* 'compressed' slice loop generates 'ns' extra volumes  */
    if (seqcon[1] == 'c') nvols*=d->ns;
  }

  if (seqcon[2] == 's') /* 'standard' phase loop */
    nvols/=d->nseg;
  if (seqcon[3] == 's') /* 'standard' phase loop */
    nvols/=d->nv2;
  if (seqcon[4] == 's') /* volumes = slice encodes for 3D csi */
    nvols/=d->nv3;

  /* Allow for 2D LookLocker */
  if (im2DLL(d)) nvols*=nvals("ti",&d->p);

  /* special case for CSI and elliptical acquires NOT using DI's functions */
  if(imCSI(d) && nvols < 1)
  {
	  d->korder = TRUE;
	  nvols=(int)*val("arraydim",&d->p);
	  nvols*=d->ne;
	  nvols /= d->nr;
	  listlen = nvals("pelist",&d->p);
	  if(listlen > 0)
		  nvols /= listlen;

	 if(im4D(d))  // 3D csi
		  nvols *= d->nv3;  // for 3d nvols is number of slices
	  else
		  nvols *= d->ns;
  }
  else if(imCSI(d) && (im4D(d)))
  {
	  nvols *= d->nv3;
  }

  /* We now have the total number of volumes (nvols) according to
     the input parameter set */

  /* Set nvols */
  d->nvols=nvols;

  /* Set start volume and end volume */
  setstartendvol(d);

  /* Initialise volume counter */
  d->vol=d->startvol;

  /* Initialise block counter */
  d->block=0;

#ifdef DEBUG
  fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__);
  fprintf(stdout,"  Total number of volumes (d->nvols) = %d\n",d->nvols);
  fprintf(stdout,"  Start volume (d->startvol+1) = %d\n",d->startvol+1);
  fprintf(stdout,"  End volume (d->endvol) = %d\n",d->endvol);
  fflush(stdout);
#endif
}
Esempio n. 5
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. 6
0
int phaseorder2D(struct data *d)
{
  /* There is a problem if data was acquired using a 'tablib' file.
     The file is not stored with data.
     The plan is to write table values to pelist to give a permanent record
     of the order with saved data */
  /* For the moment just accomodate for FSE acquired with standard ordering */
  fftw_complex *slice;
  double *pelist;
  int *tab,*petab;
  int dim1,dim2,ns,nr;
  int etl,kzero;
  int i,j,k,l,m;

#ifdef DEBUG
  struct timeval tp;
  double t1,t2;
  char function[20];
  strcpy(function,"phaseorder2D"); /* Set function name */
  fprintf(stdout,"\n%s: %s()\n",SOURCEFILE,function);
  gettimeofday(&tp, NULL);
  t1=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
  fflush(stdout);
#endif

  /* Data dimensions */
  dim1=d->np/2; dim2=d->nv; ns=d->ns; nr=d->nr;

  if ((tab = (int *)malloc(dim2*sizeof(int))) == NULL) nomem();
  if ((petab = (int *)malloc(dim2*sizeof(int))) == NULL) nomem();

  etl=1;
  if (!(strcmp(*sval("apptype",&d->p),"im2Dfse"))) { /* 2D FSE */
    /* Calculate PE table for kzero=1 */
    /* Data will end up in petab */
    etl=(int)*val("etl",&d->p);
    kzero=(int)*val("kzero",&d->p);
    for (i=0;i<dim2/2;i++)
      tab[i]= -(((i+1)*(dim2/(2*etl))-1)%(dim2/2))+i/etl;
    for (i=dim2/2;i<dim2;i++)
      tab[i]= ((i-dim2/2)*(dim2/(2*etl))%(dim2/2))+(i-dim2/2)/etl+1;

    /* Adjust for actual kzero filling petab as we go */
    for (i=0;i<dim2/etl;i++) {
      for (j=0;j<etl;j++) {
        k=i*etl;
        if (j < kzero-1) k+=etl-j-1;
        else k+=j-kzero+1;
        petab[i*etl+j]=tab[k];
      }
    }
  } else {
    /* Check pelist */
    if (nvals("pelist",&d->p) != dim2) {
      free(tab);
      free(petab);
#ifdef DEBUG
  gettimeofday(&tp, NULL);
  t2=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
  fprintf(stdout,"  Phase reordering not required (took %f secs)\n",t2-t1);
  fflush(stdout);
#endif
      return(1);
    }
    pelist=val("pelist",&d->p);
    for (i=0;i<dim2;i++) petab[i]=(int)pelist[i];
  }

#ifdef DEBUG
/*
  fprintf(stdout,"\n%s: %s()\n",SOURCEFILE,function);
  fprintf(stdout,"  Calculated PE table for reordering:\n");
  for (i=0;i<dim2/etl;i++) {
    for (j=0;j<etl;j++)
      fprintf(stdout,"%6.1d",petab[i*etl+j]);
    fprintf(stdout,"\n");
  }
  fflush(stdout);
*/
#endif

  /* Fill tab with the required order */
  for (i=0;i<dim2;i++) tab[i]=i-dim2/2+1;

#ifdef DEBUG
/*
  fprintf(stdout,"\n%s: %s()\n",SOURCEFILE,function);
  fprintf(stdout,"  Required PE table:\n");
  for (i=0;i<dim2/etl;i++) {
    for (j=0;j<etl;j++)
      fprintf(stdout,"%6.1d",tab[i*etl+j]);
    fprintf(stdout,"\n");
  }
  fflush(stdout);
*/
#endif

  /* Allocate memory for slice data */
  if ((slice = (fftw_complex *)fftw_malloc(dim2*dim1*sizeof(fftw_complex))) == NULL) nomem();

  /* Fill slice with the required order and copy back to d->data */
  for (i=0;i<nr;i++) {
    for (j=0;j<ns;j++) {
      /* Fill slice with the required order */
      for (k=0;k<dim2;k++) {
        for (l=0;l<dim2;l++) {
          if (petab[k] == tab[l]) {
            for (m=0;m<dim1;m++) {
              slice[l*dim1+m][0]=d->data[i][j][k*dim1+m][0];
              slice[l*dim1+m][1]=d->data[i][j][k*dim1+m][1];
            }
            break;
          }
        }
      }
      /* Copy new PE ordering back to d->data */
      for (k=0;k<dim2*dim1;k++) {
        d->data[i][j][k][0]=slice[k][0];
        d->data[i][j][k][1]=slice[k][1];
      }
    }
  }

  fftw_free(slice);

#ifdef DEBUG
  gettimeofday(&tp, NULL);
  t2=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
  if (!(strcmp(*sval("apptype",&d->p),"im2Dfse"))) { /* 2D FSE */
    fprintf(stdout,"  Calculated PE table for reordering:\n");
    for (i=0;i<dim2/etl;i++) {
      for (j=0;j<etl;j++)
        fprintf(stdout,"%6.1d",petab[i*etl+j]);
      fprintf(stdout,"\n");
    }
  }
/*
  fprintf(stdout,"  Required PE table:\n");
  for (i=0;i<dim2/etl;i++) {
    for (j=0;j<etl;j++)
      fprintf(stdout,"%6.1d",tab[i*etl+j]);
    fprintf(stdout,"\n");
  }
*/
  fprintf(stdout,"  Took %f secs\n",t2-t1);
  fflush(stdout);
#endif

  free(tab);
  free(petab);

  return(0);
}
Esempio n. 7
0
void setarray(struct pars *p,struct pars *a)
{
  int i,j,k,n;
  int joint;
  double *cycles;
  char str[MAXPATHLEN];

  if (!list2array("array",p,a)) return;

  /* Take a copy of the array string */
  strcpy(str,*sval("array",p));

  /* Fill with parameter names from the array string */
  /* 'array' is a string, so we will use member 'd' to hold a 'joint' index
     with which we can track parameters that are jointly arrayed */
  /* Allocate memory for a->d */
  if ((a->d = (double **)malloc(sizeof(double *))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
  if ((a->d[0] = (double *)malloc(*a->nvals*sizeof(double))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
  /* Initialise a->d */
  for (i=0;i<*a->nvals;i++) a->d[0][i]=0;
  joint=0; j=0; k=0;
  for (i=0;i<strlen(str);i++) {
    if (str[i] == '(') {
      i++; a->d[0][j]=1; joint=1;
    }
    if (str[i] == ')') {
      i++; joint=0;
    }
    if (str[i] == ',') {
      if (joint) {
        a->d[0][j]++;
        a->d[0][j+1]=a->d[0][j]; /* for a ',' j+1 will always exist */
      }
      a->s[0][j++][k]=0; /* NULL terminate */
      k=0;
    }
    else
      a->s[0][j][k++]=str[i];
  }
  a->s[0][j][k]=0; /* NULL terminate */

  /* As such:
     The 'joint' index is 0 for parameters that are not jointly arrayed.
     Arrayed parameters generate indices as follows:

       array                     'joint' index
                     parameter   a  b  c  d  e
     (a,b),c,d,e   :             2  2  0  0  0
     a,(b,c),d,e   :             0  2  2  0  0
     (a,b,c),d,e   :             2  3  3  0  0
     a,(b,c,d),e   :             0  2  3  3  0
     a,(b,c,d,e)   :             0  2  3  4  4
     a,(b,c),(d,e) :             0  2  2  2  2
     (a,b,c,d,e)   :             2  3  4  5  5

     Starting from the last parameter (which cycles the quickest) we can
     now easily figure how many parameters are jointly arrayed
  */

  /* Convert the 'joint' index to 'cycles' which describes the number of
     volumes over which the parameter cycles */
  /* Allocate for a->nvals 'cycles' */
  if ((cycles = (double *)malloc(*a->nvals*sizeof(double))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);

  /* Initialise cycles and joint for the last parameter */
  cycles[*a->nvals-1]=1;
  if (a->d[0][*a->nvals-1] > 0) joint=1;
  else joint=0;

  for (i=*a->nvals-2;i>=0;i--) {
    if (joint) {
      n=a->d[0][i+1]-1;
      for (j=0;j<n;j++) { /* was for (j=0;j<a->d[0][i+1]-1;j++) { */
        cycles[i]=cycles[i+1];
        i--;
      }
      i++; joint=0;
    } else {
      cycles[i]=cycles[i+1]*nvals(a->s[0][i+1],p);
      if (a->d[0][i] > 0) joint=1;
    }
  }

  /* Copy cycles to a->d */
  for (i=0;i<*a->nvals;i++) a->d[0][i]=cycles[i];

#ifdef DEBUG
  fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__);
  printarray(a,*sval("array",p));
#endif

}
Esempio n. 8
0
void gen3Dfdfhdr(struct data *d,int image,int slab,int echo,int receiver,int type,int precision)
{

  char str[100];
  int cycle,n,id;
  double pro,ppe,pss,psi,phi,theta;
  double cospsi,cosphi,costheta;
  double sinpsi,sinphi,sintheta;
  double or0,or1,or2,or3,or4,or5,or6,or7,or8;
  double value;
  int dim1,dim2,dim3,ns,nr;
  int ne;
  int i,j,add;
  int align=0,hdrlen,pad_cnt;
  int *intval;
  double *dblval;
  char **strval;
  int datamode;

  /* Check that type is valid */
  if (!validtype(type) || (type == VJ)) {
    fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
    fprintf(stderr,"  Invalid 6th argument %s(*,*,*,*,*,'type',*)\n",__FUNCTION__);
    fflush(stderr);
    return;
  }

  datamode=FID;
  /* If FT has been done flag it as IMAGE */
  if ((d->dimstatus[0] & FFT) || (d->dimstatus[1] & FFT) || (d->dimstatus[2] & FFT)) datamode=IMAGE;

  /* Allocate for header */
  if ((d->fdfhdr = (char *)malloc(FDFHDRLEN*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);

  /* Data dimensions */
  dim1=d->np/2; dim2=d->nv; dim3=d->nv2; nr=d->nr;

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

  /* Number of slices (slabs) */
  ns=nvals("pss",&d->p);
  if (ns < 1) ns=1; /* Set ns to 1 if 'ns' does not exist */

  /* Allow for compressed multi-echo loop and multiple slabs */
/*
  image=(volindex-IMAGEOFFSET)/(ne*ns);
  slab=((volindex-IMAGEOFFSET)/ne)%ns;
  echo=(volindex-IMAGEOFFSET)%ne;
*/

  /* Set up for orientation */
  pro=getelem(d,"pro",image);
  ppe=getelem(d,"ppe",image);
  pss=sliceposition(d,slab); /* position in 2nd phase encode dimension */
  psi=getelem(d,"psi",image);
  phi=getelem(d,"phi",image);
  theta=getelem(d,"theta",image);

  /* Create header */
  sprintf(d->fdfhdr,"#!/usr/local/fdf/startup\n");
  strcat(d->fdfhdr,"float  rank = 3;\n");
  strcat(d->fdfhdr,"char  *spatial_rank = \"3dfov\";\n");
  switch(precision) {
    case FLT32: /* 32 bit float */
      strcat(d->fdfhdr,"char  *storage = \"float\";\n");
      strcat(d->fdfhdr,"float  bits = 32;\n");
      break;
    case DBL64: /* 64 bit double */
      strcat(d->fdfhdr,"char  *storage = \"double\";\n");
      strcat(d->fdfhdr,"float  bits = 64;\n");
      break;
    default:
      strcat(d->fdfhdr,"char  *storage = \"not supported\";\n");
      strcat(d->fdfhdr,"float  bits = ?;\n");
      break;
  } /* end precision switch */
  switch(type) {
    case MG: /* Magnitude */
      strcat(d->fdfhdr,"char  *type = \"absval\";\n");
      break;
    case RE: /* Real */
      strcat(d->fdfhdr,"char  *type = \"real\";\n");
      break;
    case IM: /* Imaginary */
      strcat(d->fdfhdr,"char  *type = \"imag\";\n");
      break;
    case PH: /* Phase */
      strcat(d->fdfhdr,"char  *type = \"phase\";\n");
      break;
    case MK: /* Mask */
      strcat(d->fdfhdr,"char  *type = \"mask\";\n");
      break;
    case RMK: /* Reverse mask of magnitude */
      strcat(d->fdfhdr,"char  *type = \"absval\";\n");
      break;
    case SM: /* Sensitivity map */
      strcat(d->fdfhdr,"char  *type = \"smap\";\n");
      break;
    case GF: /* Geometry factor */
      strcat(d->fdfhdr,"char  *type = \"gmap\";\n");
      break;
    case RS: /* Relative SNR */
      strcat(d->fdfhdr,"char  *type = \"rsnrmap\";\n");
      break;
    default:
      break;
  } /* end type switch */
  sprintf(str,"float  matrix[] = {%d, %d, %d};\n",dim1,dim2,dim3);
  strcat(d->fdfhdr,str);
  switch(datamode) {
    case IMAGE: /* Image */
      strcat(d->fdfhdr,"char  *abscissa[] = {\"cm\", \"cm\", \"cm\"};\n");
      break;
    case FID: /* FID */
/*
      strcat(d->fdfhdr,"char  *abscissa[] = {\"s\", \"s\", \"s\"};\n");
*/
      /* We must define as for image space to get a good display in VnmrJ */
      strcat(d->fdfhdr,"char  *abscissa[] = {\"cm\", \"cm\", \"cm\"};\n");
      break;
    default:
      strcat(d->fdfhdr,"char  *abscissa[] = {\"cm\", \"cm\", \"cm\"};\n");
      break;
  } /* end datamode switch */
  switch(type) {
    case PH: /* Phase */
      strcat(d->fdfhdr,"char  *ordinate[] = { \"radians\" };\n");
      break;
    case MK: /* Mask */
      strcat(d->fdfhdr,"char  *ordinate[] = { \"mask\" };\n");
      break;
    default:
      strcat(d->fdfhdr,"char  *ordinate[] = { \"intensity\" };\n");
      break;
  } /* end type switch */
  switch(datamode) {
    case IMAGE: /* Image */
      sprintf(str,"float  span[] = {%.6f, %.6f, %.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p));
      strcat(d->fdfhdr,str);
      sprintf(str,"float  origin[] = {%.6f,%.6f,%.6f};\n",-pro-*val("lro",&d->p)/2,ppe-*val("lpe",&d->p)/2,pss-*val("lpe2",&d->p)/2);
      strcat(d->fdfhdr,str);
      break;
    case FID: /* FID */
/*
      sprintf(str,"float  span[] = {%.6f, %.6f, %.6f};\n",dim1/(*val("sw",&d->p)),dim2/(*val("sw1",&d->p)),dim3/(*val("sw2",&d->p)));
      strcat(d->fdfhdr,str);
      sprintf(str,"float  origin[] = {%.6f, %.6f, %.6f};\n",0.0,0.0,0.0);
      strcat(d->fdfhdr,str);
*/
      /* We must define as for image space to get a good display in VnmrJ */
      sprintf(str,"float  span[] = {%.6f, %.6f, %.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p));
      strcat(d->fdfhdr,str);
      sprintf(str,"float  origin[] = {%.6f,%.6f,%.6f};\n",-pro-*val("lro",&d->p)/2,ppe-*val("lpe",&d->p)/2,pss-*val("lpe2",&d->p)/2);
      strcat(d->fdfhdr,str);
      break;
    default:
      sprintf(str,"float  span[] = {%.6f, %.6f, %.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p));
      strcat(d->fdfhdr,str);
      sprintf(str,"float  origin[] = {%.6f,%.6f,%.6f};\n",-pro-*val("lro",&d->p)/2,ppe-*val("lpe",&d->p)/2,pss-*val("lpe2",&d->p)/2);
      strcat(d->fdfhdr,str);
      break;
  } /* end datamode switch */
  sprintf(str,"char  *nucleus[] = {\"%s\",\"%s\"};\n",*sval("tn",&d->p),*sval("dn",&d->p));
  strcat(d->fdfhdr,str);
  sprintf(str,"float  nucfreq[] = {%.6f,%.6f};\n",*val("sfrq",&d->p),*val("dfrq",&d->p));
  strcat(d->fdfhdr,str);
  switch(datamode) {
    case IMAGE: /* Image */
      sprintf(str,"float  location[] = {%.6f,%.6f,%.6f};\n",-pro,ppe,pss);
      strcat(d->fdfhdr,str);
      sprintf(str,"float  roi[] = {%.6f,%.6f,%.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p));
      strcat(d->fdfhdr,str);
      break;
    case FID: /* FID */
      sprintf(str,"float  location[] = {%.6f,%.6f,%.6f};\n",-pro,ppe,pss);
      strcat(d->fdfhdr,str);
      sprintf(str,"float  roi[] = {%.6f,%.6f,%.6f};\n",dim1/(*val("sw",&d->p)),dim2/(*val("sw1",&d->p)),dim3/(*val("sw2",&d->p)));
      strcat(d->fdfhdr,str);
      break;
    default:
      sprintf(str,"float  location[] = {%.6f,%.6f,%.6f};\n",-pro,ppe,pss);
      strcat(d->fdfhdr,str);
      sprintf(str,"float  roi[] = {%.6f,%.6f,%.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p));
      strcat(d->fdfhdr,str);
      break;
  } /* end datamode switch */
  sprintf(str,"float  gap = %.6f;\n",*val("gap",&d->p));
  strcat(d->fdfhdr,str);
  sprintf(str,"char  *file = \"%s\";\n",d->file);
  strcat(d->fdfhdr,str);
  sprintf(str,"int    slab_no = %d;\n",slab+1);
  strcat(d->fdfhdr,str);
  sprintf(str,"int    slabs = %d;\n",ns);
  strcat(d->fdfhdr,str);
  sprintf(str,"int    echo_no = %d;\n",echo+1);
  strcat(d->fdfhdr,str);
  sprintf(str,"int    echoes = %d;\n",ne);
  strcat(d->fdfhdr,str);

  if (ne < 2)
    value=getelem(d,"te",image);
  else { /* a multi echo expt */
    /* The TE array should hold the echo time of each echo */
    if (nvals("TE",&d->p) == *val("ne",&d->p)) {
      dblval=val("TE",&d->p);
      value=dblval[echo]/1000.0;
    } else {
      value=1.0; /* Just set a silly value */
    }
  }
  sprintf(str,"float  TE = %.3f;\n",1000.0*value);
  strcat(d->fdfhdr,str);
  sprintf(str,"float  te = %.6f;\n",value);
  strcat(d->fdfhdr,str);

  value=getelem(d,"tr",image);
  sprintf(str,"float  TR = %.3f;\n",1000.0*value);
  strcat(d->fdfhdr,str);
  sprintf(str,"float  tr = %.6f;\n",value);
  strcat(d->fdfhdr,str);

  sprintf(str,"int    ro_size = %d;\n",(int)*val("np",&d->p)/2);
  strcat(d->fdfhdr,str);
  sprintf(str,"int    pe_size = %d;\n",(int)*val("nv",&d->p));
  strcat(d->fdfhdr,str);
  sprintf(str,"int    pe2_size = %d;\n",(int)*val("nv2",&d->p));
  strcat(d->fdfhdr,str);
  sprintf(str,"char  *sequence = \"%s\";\n",*sval("seqfil",&d->p));
  strcat(d->fdfhdr,str);
  sprintf(str,"char  *studyid = \"%s\";\n",*sval("studyid_",&d->p));
  strcat(d->fdfhdr,str);
/*
  sprintf(str,"char  *position1 = \"%s\";\n","");
  strcat(d->fdfhdr,str);
  sprintf(str,"char  *position2 = \"%s\";\n","");
  strcat(d->fdfhdr,str);
*/

  value=getelem(d,"ti",image);
  sprintf(str,"float  TI = %.3f;\n",1000.0*value);
  strcat(d->fdfhdr,str);
  sprintf(str,"float  ti = %.6f;\n",value);
  strcat(d->fdfhdr,str);

  sprintf(str,"int    array_index = %d;\n",image+1-IMAGEOFFSET);
  strcat(d->fdfhdr,str);

  /* The array_dim is the number of *image???*.fdf = (for 3D) # volumes divided by # echoes*slices */
  value=(double)d->nvols/(ne*ns);
  /* But if there are reference volumes they must be accounted for */
  /* Check for image parameter array, since that is used to signify reference scans */
  if (arraycheck("image",&d->a)) {
    /* count # image=1 values */
    for (i=0;i<nvals("image",&d->p);i++) if (getelem(d,"image",i)<1) value--;
  }
  sprintf(str,"float  array_dim = %.4f;\n",value);
  strcat(d->fdfhdr,str);
/*
  sprintf(str,"float  image = 1.0;\n");
  strcat(d->fdfhdr,str);
*/

  /* The following assumes that fid data is always stored bigendian ..
     .. if we must reverse byte order to interpret then CPU is lilendian */
  if (reverse_byte_order) {
    sprintf(str,"int    bigendian = 0;\n");
    strcat(d->fdfhdr,str);
  }

  /* Image scaling */
  value=*val("aipScale",&d->p);
  if (FP_EQ(value,0.0)) value=1.0;
  sprintf(str,"float  imagescale = %.9f;\n",value);
  strcat(d->fdfhdr,str);

  sprintf(str,"float  psi = %.4f;\n",psi);
  strcat(d->fdfhdr,str);
  sprintf(str,"float  phi = %.4f;\n",phi);
  strcat(d->fdfhdr,str);
  sprintf(str,"float  theta = %.4f;\n",theta);
  strcat(d->fdfhdr,str);

  /* Generate direction cosine matrix from "Euler" angles just as recon_all */
  cospsi=cos(DEG2RAD*psi);
  sinpsi=sin(DEG2RAD*psi);
  cosphi=cos(DEG2RAD*phi);
  sinphi=sin(DEG2RAD*phi);
  costheta=cos(DEG2RAD*theta);
  sintheta=sin(DEG2RAD*theta);

  /* For 2D ...
  or0=-1*cosphi*cospsi - sinphi*costheta*sinpsi;
  or1=-1*cosphi*sinpsi + sinphi*costheta*cospsi;
  or2=-1*sinphi*sintheta;
  or3=-1*sinphi*cospsi + cosphi*costheta*sinpsi;
  or4=-1*sinphi*sinpsi - cosphi*costheta*cospsi;
  or5=cosphi*sintheta;
  or6=-1*sintheta*sinpsi;
  or7=sintheta*cospsi;
  or8=costheta;
  */
  /* For 3D ... */
  or0=-1*sinphi*sinpsi - cosphi*costheta*cospsi; /* the 2D or4  */
  or1=sinphi*cospsi - cosphi*costheta*sinpsi;    /* the 2D -or3 */
  or2=cosphi*sintheta;                           /* the 2D or5  */
  or3=cosphi*sinpsi - sinphi*costheta*cospsi;    /* the 2D -or1 */
  or4=-1*cosphi*cospsi - sinphi*costheta*sinpsi; /* the 2D or0  */
  or5=sinphi*sintheta;                           /* the 2D -or2 */
  or6=sintheta*cospsi;                           /* the 2D or7  */
  or7=sintheta*sinpsi;                           /* the 2D -or6  */
  or8=costheta;                                  /* the 2D or8  */

  sprintf(str,"float  orientation[] = {%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f};\n",
    or0,or1,or2,or3,or4,or5,or6,or7,or8);
  strcat(d->fdfhdr,str);

  sprintf(str,"char  *array_name = \"none\";\n");
  strcat(d->fdfhdr,str);

  /* Add arrayed parameters */
  if (d->a.npars>0) {
    for (i=0;i<*d->a.nvals;i++) {
      if (addpar2hdr(&d->a,i)) { /* If not already included by default */
        cycle=(int)d->a.d[0][i];
        n=nvals(d->a.s[0][i],&d->p);
        id=(image/cycle)%n;
        switch (ptype(d->a.s[0][i],&d->p)) {
          case 0:
            strcat(d->fdfhdr,"int    ");
            intval=ival(d->a.s[0][i],&d->p);
            sprintf(str,"%s = %d;\n",d->a.s[0][i],intval[id]);
            strcat(d->fdfhdr,str);
            break;
          case 1:
            strcat(d->fdfhdr,"float  ");
            dblval=val(d->a.s[0][i],&d->p);
            sprintf(str,"%s = %.6f;\n",d->a.s[0][i],dblval[id]);
            strcat(d->fdfhdr,str);
            break;
          case 2:
            strcat(d->fdfhdr,"char  *");
            strval=sval(d->a.s[0][i],&d->p);
            sprintf(str,"%s = \"%s\";\n",d->a.s[0][i],strval[id]);
            strcat(d->fdfhdr,str);
            break;
        }
      }
    }
  }

  /* Add sviblist parameters */
  if (d->s.npars>0) {
    for (i=0;i<*d->s.nvals;i++) {
      if (addpar2hdr(&d->s,i)) { /* If not already included by default */
        add = 1;
        if (d->a.npars>0) { /* Don't include arrayed parameters */
          for (j=0;j<*d->a.nvals;j++)
            if (!strcmp(d->a.s[0][j],d->s.s[0][i])) add--;
        }
        if (add) {
          /* NB The parameter may be arrayed with setprotect('par','on',256) */
          n=nvals(d->s.s[0][i],&d->p);
          if (n>0) {
            id=image%n; /* Assume 'cycle' is 1 - no mechanism exists to suggest otherwise */
            switch (ptype(d->s.s[0][i],&d->p)) {
              case 0: /* Integer */
                strcat(d->fdfhdr,"int    ");
                intval=ival(d->s.s[0][i],&d->p);
                sprintf(str,"%s = %d;\n",d->s.s[0][i],intval[id]);
                strcat(d->fdfhdr,str);
                break;
              case 1: /* Real */
                strcat(d->fdfhdr,"float  ");
                dblval=val(d->s.s[0][i],&d->p);
                sprintf(str,"%s = %.6f;\n",d->s.s[0][i],dblval[id]);
                strcat(d->fdfhdr,str);
                break;
              case 2: /* String */
                strcat(d->fdfhdr,"char  *");
                strval=sval(d->s.s[0][i],&d->p);
                sprintf(str,"%s = \"%s\";\n",d->s.s[0][i],strval[id]);
                strcat(d->fdfhdr,str);
                break;
            }
          }
        }
      }
    }
  }

/* For 2D strcat(d->fdfhdr,"int checksum = 1291708713;\n"); is used for some unknown reason */
  strcat(d->fdfhdr,"int checksum = 0;\n");
  strcat(d->fdfhdr,"\f\n");

  /* Add padding */
  switch(precision) {
    case FLT32: /* 32 bit float */
      align = sizeof(float);
      break;
    case DBL64: /* 64 bit double */
      align = sizeof(double);
      break;
    default:
      break;
  } /* end precision switch */
  hdrlen=strlen(d->fdfhdr);
  hdrlen++; /* allow for NULL terminator */
  pad_cnt=hdrlen%align;
  pad_cnt=(align-pad_cnt)%align;
  for(i=0;i<pad_cnt;i++) strcat(d->fdfhdr,"\n");

}
Esempio n. 9
0
void gen3Dfdfs(struct data *d,int mode,char *outdir,int type,int precision,int volindex)
{
  char basename[MAXPATHLEN],dirname[MAXPATHLEN],filename[MAXPATHLEN];
  int ne,ns;
  int start,end;
  int startpos,endpos,blockslices;
  int i;
  int slab,image,echo;
  int offline=FALSE;

  /* This function checks the output type requested and sets the output
     filename accordingly. 3D FDF data from each slice is output according
     to the specified mode using functions w3Dfdf() and wcomb3Dfdf().
     These functions output data either from individual receivers (w3Dfdf)
     or using a combination of data from all receivers (wcomb3Dfdf). */

  /* Check that type is valid */
  if (!validtype(type) || (type == VJ)) {
    fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
    fprintf(stderr,"  Invalid 4th argument %s(*,*,*,'type',*,*)\n",__FUNCTION__);
    fflush(stderr);
    return;
  }

  /* For mask and reverse mask of magnitude we allow the start and end positions
     to be defined. */
  switch(type) {
    case MK:
      start=(int)*val("maskstartslice",&d->p);
      if ((start<0) || (start>d->nv2)) start=1;
      start--;
      end=(int)*val("maskendslice",&d->p);
      if ((end<1) || (end>d->nv2)) end=d->nv2;
      break;
    case RMK:
      start=(int)*val("maskstartslice",&d->p);
      if ((start<0) || (start>d->nv2)) start=1;
      start--;
      end=(int)*val("maskendslice",&d->p);
      if ((end<1) || (end>d->nv2)) end=d->nv2;
      break;
    default:
      start=0;
      end=d->nv2;
      break;
  } /* end type switch */

  startpos=d->startpos; endpos=d->endpos;

  if ((start>=endpos) || (end<=startpos)) {
#ifdef DEBUG
  fprintf(stdout,"\n  %s(): skipping writing of block %d (of %d)\n",__FUNCTION__,d->block+1,d->nblocks);
#endif
    return;
  }

  /* Adjust start and end according to data block */
  start=start-startpos;
  end=end-startpos;
  if (start<0) start=0;
  blockslices=endpos-startpos;
  if (end>blockslices) end=blockslices;

  /* Check for VnmrJ recon to figure if we are offline */
  if (vnmrj_recon) strcpy(basename,vnmrj_path);
  else {
    for (i=0;i<=strlen(d->file)-9;i++)
      basename[i]=d->file[i];
    basename[i]=0;
    offline=TRUE;
  }

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

  /* Number of slices (slabs) */
  ns=nvals("pss",&d->p);
  if (ns < 1) ns=1; /* Set ns to 1 if 'ns' does not exist */

  /* Allow for compressed multi-echo loop and multiple slabs */
  image=(volindex-IMAGEOFFSET)/(ne*ns);
  slab=((volindex-IMAGEOFFSET)/ne)%ns;
  echo=(volindex-IMAGEOFFSET)%ne;

  switch(mode) {
    case 'i': /* Individual output */
      for (i=0;i<d->nr;i++) {
        sprintf(dirname,"%s%s%.3d",basename,outdir,i+1);
        if (offline) strcat(dirname,".img");
        createdir(dirname);
        sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.fdf",dirname,slab+1,image+1,echo+1);
        w3Dfdf(filename,d,image,slab,echo,i,type,precision);
        /* Write procpar */
        sprintf(filename,"%s/procpar",dirname);
        wprocpar(d,filename);
      }
      break;
    case 'c': /* Combined output (Magnitude only) */
      sprintf(dirname,"%s%s",basename,outdir);
      if (offline) strcat(dirname,".img");
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.fdf",dirname,slab+1,image+1,echo+1);
      wcomb3Dfdf(filename,d,image,slab,echo,type,precision);
      /* Write procpar */
      sprintf(filename,"%s/procpar",dirname);
      wprocpar(d,filename);
      break;
    case 's': /* Single receiver */
      sprintf(dirname,"%s%s",basename,outdir);
      if (offline) strcat(dirname,".img");
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.fdf",dirname,slab+1,image+1,echo+1);
      w3Dfdf(filename,d,image,slab,echo,0,type,precision);
      /* Write procpar */
      sprintf(filename,"%s/procpar",dirname);
      wprocpar(d,filename);
      break;
    case 'g': /* Geometry Factor output */   
      sprintf(dirname,"%s%s",basename,outdir);
      if (offline) strcat(dirname,".img");
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.fdf",dirname,slab+1,image+1,echo+1);
      w3Dfdf(filename,d,image,slab,echo,0,type,precision);
      /* Write procpar */
      sprintf(filename,"%s/procpar",dirname);
      wprocpar(d,filename);
      break;
    case 'r': /* Relative SNR */
      sprintf(dirname,"%s%s",basename,outdir);
      if (offline) strcat(dirname,".img");
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.fdf",dirname,slab+1,image+1,echo+1);
      w3Dfdf(filename,d,image,slab,echo,1,type,precision);
      /* Write procpar */
      sprintf(filename,"%s/procpar",dirname);
      wprocpar(d,filename);
      break;
    default:
      fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
      fprintf(stderr,"  Invalid 2nd argument %s(*,'mode',*,*,*,*)\n",__FUNCTION__);
      fflush(stderr);
      break;
  } /* end mode switch */
}
Esempio n. 10
0
void get3Draw(struct data *d,int mode,char *indir,int dataorder)
{
  char basename[MAXPATHLEN],dirname[MAXPATHLEN],filename[MAXPATHLEN];
  int dim1=0,dim2=0,dim3=0,nr=0;
  int volindex;
  int startpos,endpos;
  int ne,ns;
  int slab,image,echo;
  int i,j;

  /* This function checks the output type requested and sets the input
     filename accordingly. 3D raw data is input according to the specified
     mode using functions w3Dfdf() and wcomb3Dfdf().
     These functions output data either from individual receivers (w3Dfdf)
     or using a combination of data from all receivers (wcomb3Dfdf). */

  volindex=d->vol;

  /* Set start and end position of block */
  startpos=d->startpos; endpos=d->endpos;

  /* Set data dimensions */
  switch (dataorder) {
    case D12:
      /* If a previous block has been zero filled matrix size will be incorrect */
      d->nv2=(int)*val("nv2",&d->p);
      dim1=d->np/2; dim2=d->endpos-d->startpos; dim3=d->nv2; nr=d->nr; 
      break;
    case D3:  dim1=d->np/2; dim2=d->nv; dim3=d->endpos-d->startpos; nr=d->nr; break;
  }

  /* Allocate memory according to nr */
  if ((d->data = (fftw_complex ***)fftw_malloc(nr*sizeof(fftw_complex **))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);

  /* Allocate memory according to block size */
  switch (dataorder) {
    case D12: /* in this case we read "D12" processing block into "D3" processing block */
      for (i=0;i<nr;i++) { /* loop over receivers and malloc for "D3" processing block */
        if ((d->data[i] = (fftw_complex **)fftw_malloc(dim1*dim2*sizeof(fftw_complex *))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
        for (j=0;j<dim1*dim2;j++) /* loop over dim1 and 1st phase encode block */
          if ((d->data[i][j] = (fftw_complex *)fftw_malloc(dim3*sizeof(fftw_complex))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
      }
      break;
    case D3: /* in this case we read "D3" processing block into "D12" processing block */
      for (i=0;i<nr;i++) { /* loop over receivers and malloc for "D12" processing block */
        if ((d->data[i] = (fftw_complex **)fftw_malloc(dim3*sizeof(fftw_complex *))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
        for (j=0;j<dim3;j++) /* loop over dim3 */
          if ((d->data[i][j] = (fftw_complex *)fftw_malloc(dim2*dim1*sizeof(fftw_complex))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__);
      }
      break;
  }

  /* Check for VnmrJ recon to figure if we are offline */
  if (vnmrj_recon) strcpy(basename,vnmrj_path);
  else {
    for (i=0;i<=strlen(d->file)-9;i++)
      basename[i]=d->file[i];
    basename[i]=0;
  }

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

  /* Number of slices (slabs) */
  ns=nvals("pss",&d->p);
  if (ns < 1) ns=1; /* Set ns to 1 if 'ns' does not exist */

  /* Allow for compressed multi-echo loop and multiple slabs */
  image=volindex/(ne*ns);
  slab=(volindex/ne)%ns;
  echo=volindex%ne;

  switch(mode) {
    case 'i': /* Individual input */
      for (i=0;i<d->nr;i++) {
        sprintf(dirname,"%s%s%.3d",basename,indir,i+1);
        sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
        switch(dataorder) {
          case D12: r3Draw(filename,d,i);   break;
          case D3:  r3DrawD3(filename,d,i); break;
        }
      }
      break;
    case 's': /* Single receiver */
      sprintf(dirname,"%s%s",basename,indir);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
      switch(dataorder) {
        case D12: r3Draw(filename,d,0);   break;
        case D3:  r3DrawD3(filename,d,0); break;
      }
      break;
    default:
      fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
      fprintf(stderr,"  Invalid 2nd argument %s(*,'mode',*,*,*,*)\n",__FUNCTION__);
      fflush(stderr);
      break;
  } /* end mode switch */
}
Esempio n. 11
0
void gen3Draw(struct data *d,int output,char *outdir,int dataorder,int type,int precision)
{
  char basename[MAXPATHLEN],dirname[MAXPATHLEN],filename[MAXPATHLEN];
  int ne,ns;
  int i;
  int slab,image,echo;
  int volindex;

  /* This function checks the output type requested and sets the output
     filename accordingly. 3D raw data is output according to the specified
     mode using functions w3Draw() and wcomb3Draw().
     These functions output data either from individual receivers (w3Draw)
     or using a combination of data from all receivers (wcomb3Draw). */

  /* Check for VnmrJ recon to figure if we are offline */
  if (vnmrj_recon) strcpy(basename,vnmrj_path);
  else {
    for (i=0;i<=strlen(d->file)-9;i++)
      basename[i]=d->file[i];
    basename[i]=0;
  }

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

  /* Number of slices (slabs) */
  ns=nvals("pss",&d->p);
  if (ns < 1) ns=1; /* Set ns to 1 if 'ns' does not exist */

  /* Allow for compressed multi-echo loop and multiple slabs */
  volindex=d->vol;
  image=volindex/(ne*ns);
  slab=(volindex/ne)%ns;
  echo=volindex%ne;

  switch(output) {
    case 'i': /* Individual output */
      for (i=0;i<d->nr;i++) {
        sprintf(dirname,"%s%s%.3d",basename,outdir,i+1);
        createdir(dirname);
        sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
        switch(dataorder) {
          case D3: w3DrawD3(filename,d,i); break;
          default: w3Draw(filename,d,i,type,precision); break;
        }
      }
      break;
    case 'c': /* Combined output (Magnitude only) */
      sprintf(dirname,"%s%s",basename,outdir);
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
      wcomb3Draw(filename,d,type,precision);
      break;
    case 's': /* Single receiver */
      sprintf(dirname,"%s%s",basename,outdir);
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
      switch(dataorder) {
        case D3: w3DrawD3(filename,d,0); break;
        default: w3Draw(filename,d,0,type,precision); break;
      }
      break;
    case 'g': /* Geometry Factor output */
      sprintf(dirname,"%s%s",basename,outdir);
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
      w3Draw(filename,d,0,type,precision);
      break;
    case 'r': /* Relative SNR */
      sprintf(dirname,"%s%s",basename,outdir);
      createdir(dirname);
      sprintf(filename,"%s/slab%.3dimage%.3decho%.3d.raw",dirname,slab+1,image+1,echo+1);
      w3Draw(filename,d,1,type,precision);
      break;
    default:
      fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__);
      fprintf(stderr,"  Invalid 2nd argument %s(*,'mode',*,*,*,*)\n",__FUNCTION__);
      fflush(stderr);
      break;
  } /* end output switch */
}