Esempio n. 1
0
int closeVnmrInfo()
{
   if (inmd != NULL)
      mClose(inmd);
   inmd = NULL;
   return(0);
}
Esempio n. 2
0
/* when nvlocki exit, this func will be called */
static void
clear_nvlocki(int pid)
{
    if (verbose)
        fprintf(stderr, " clear locki pid %d \n", pid);
    if (pid > 0 && (pid == nvlockiPid)) {
	nvlockiPid = 0;
	acqi_can_acquire = FALSE;
        if (lockiFd >= 0)
	    close(lockiFd);
	lockiFd = -1;
        if (ifile != NULL) {
	    mClose(ifile);
	    ifile = NULL;
	}
    }
    if (nvlockiPid < 1) {
	if (out[0] != NULL) free(out[0]);
	if (out[1] != NULL) free(out[1]);
	if (imgout[0] != NULL) free(imgout[0]);
	if (imgout[1] != NULL) free(imgout[1]);
	out[0] = NULL;      out[1] = NULL;
	imgout[0] = NULL;   imgout[1] = NULL;
	ybarW = 0;
        ybarLen = 0;
    }
}
Esempio n. 3
0
/*
 * ModemShutdown()
 *
 * This function will shut down the modem.
 */
void ModemShutdown(char KillCarr)
{
    mClose();
		/* Use user-provided code for here      */
    if (KillCarr) {
	mHangUp();
	DisableModem(TRUE);		/* valid re-use for this port */
    }
}
Esempio n. 4
0
int closeTclInfo()
{
   if (magicHdl != NULL)
      mClose(magicHdl);
   magicHdl = NULL;
   if (saveBuf != NULL)
      free(saveBuf);
   saveBuf = NULL;
   allocMagicVar = 0;
   return(0);
}
Esempio n. 5
0
/*
 * HangUp()
 *
 * This function will hang up the modem.
 */
void HangUp(char FromNet)
{
    if (!FromNet && cfg.DepData.LockPort >= 0) pause(100);

    mClose();

    mHangUp();

    if (gotCarrier())	/* do it twice if necessary! */
	mHangUp();

    ModemOpen(FALSE);

    ReInitModem();

    while (MIReady()) Citinp();    /* Clear buffer of garbage */
}
Esempio n. 6
0
void ra_inovaacqparms(unsigned int fidn)
{
   char fidpath[512];
   int curct;

   sprintf(fidpath,"%s/fid",ExpInfo.DataFile);
   if (fidn == 1)
   {
     ifile = mOpen(fidpath,ExpInfo.DataSize,O_RDONLY );
     if (ifile == NULL)
     {
	text_error("Cannot open data file: '%s', RA aborted.\n",
		ExpInfo.DataFile);
       psg_abort(1);
     }
     /* read in file header */
     memcpy((void*) &acqfileheader, (void*) ifile->offsetAddr,
					sizeof(acqfileheader));
     if (acqfileheader.np != ExpInfo.NumDataPts)
     {
	text_error("FidFile np: %d not equal NumDataPts: %d, RA aborted.\n",
		acqfileheader.np,ExpInfo.NumDataPts);
       psg_abort(1);
     }
     if (acqfileheader.ebytes != ExpInfo.DataPtSize)
     {
	text_error("FidFile dp: %d not equal DataPtSize: %d, RA aborted.\n",
		acqfileheader.ebytes,ExpInfo.DataPtSize);
       psg_abort(1);
     }
     if (acqfileheader.ntraces != ExpInfo.NumFids)
     {
	text_error("FidFile nf: %d not equal NumFids: %d, RA aborted.\n",
		acqfileheader.ntraces,ExpInfo.NumFids);
       psg_abort(1);
     }
     ifile->offsetAddr += sizeof(acqfileheader);  /* move my file pointers */
     savedoffsetAddr = ifile->offsetAddr;
   }
   /* offset to fid location */
   if (fidn <= getStartFidNum())
   {
	ifile->offsetAddr = savedoffsetAddr +
		((ExpInfo.DataPtSize * ExpInfo.NumDataPts *
			ExpInfo.NumFids) + sizeof(acqblockheader)) * (fidn-1);
	memcpy((void*) &acqblockheader, (void*) ifile->offsetAddr,
					sizeof(acqblockheader));
	curct = acqblockheader.ctcount;
	if (getIlFlag())
	{
	   if (fidn < getStartFidNum())
	   {
	      if (curct != (((ExpInfo.CurrentTran/ExpInfo.NumInBS)+1) *
							ExpInfo.NumInBS))
	    text_error("Warning: File_ct(%d): %d not equal ct+bs: %d\n",
		fidn,curct,ExpInfo.CurrentTran+ExpInfo.NumInBS);
	   }
	   else
	   {
	      if (curct != ExpInfo.CurrentTran)
	    text_error("Warning: File_ct(%d): %d not equal ct: %d\n",
		fidn,curct,ExpInfo.CurrentTran);
	   }
	}
	else
	{
	   if (fidn < getStartFidNum())
	   {
	      if (curct != ExpInfo.NumTrans)
	    text_error("Warning: File_ct(%d): %d not equal nt: %d\n",
		fidn,curct,ExpInfo.NumTrans);
	   }
	   else
	   {
	      if (curct != ExpInfo.CurrentTran)
	    text_error("Warning: File_ct(%d): %d not equal ct: %d\n",
		fidn,curct,ExpInfo.CurrentTran);
	   }
	}

   }
   else if (getIlFlag() && (fidn > getStartFidNum()) &&
		(ExpInfo.CurrentTran >= ExpInfo.NumInBS))
   {
	/* Only when interleaving after 1st blocksize */
	ifile->offsetAddr = savedoffsetAddr +
		((ExpInfo.DataPtSize * ExpInfo.NumDataPts *
			ExpInfo.NumFids) + sizeof(acqblockheader)) * (fidn-1);
	memcpy((void*) &acqblockheader, (void*) ifile->offsetAddr,
					sizeof(acqblockheader));
	curct = acqblockheader.ctcount;
	if (curct != ExpInfo.CurrentTran)
	  text_error("Warning: File_ct(%d): %d not equal CurrentTran: %d\n",
		fidn,curct,ExpInfo.CurrentTran);
   }
   else curct = 0;

   if (fidn >= ExpInfo.NumAcodes)
        mClose(ifile);
   Alc->ct = curct;
}
Esempio n. 7
0
static int nf_flash_convert (char *default_fid, char *temp_fid,
           double arraydim, int format, double ncomp, double necho,
           double nf, double *pni )
/* 
Purpose:
-------
     Routine nf_flash_convert shall replace a fid file in flash format with
     one in the format of a standard compressed two dimensional image fid.
     This routine also sets the "file" parameter in the CURRENT tree.

Arguments:
---------
default_fid  :  (I  )  The path of the fid file to be edited.
temp_fid     :  (I  )  The path of a parallel scratch file.
arraydim     :  (I  )  (Old) value of the process parameter of the same name.
format       :  (I  )  image compression format; 
			0 = standard or compressed multi-image,
			1 = compressed multi-slice.
			2 = rare-type with pe - echo train.
ncomp        :  (I  )  Number of traces to keep in compressed nf form.
necho	     :  (I  )  Number of echos. (in echo train for format 2)
nf	     :  (I)  Ditto.
pni	     :  (I/O)  Ditto.
*/

{ /* Begin function flash_convert */
   /*
   Local Variables:
   ---------------
   fid_file    :  Stdio file indicator for the (input) fid file.
   tmp_file    :  Stdio file indicator for the (output) temporary file.
   file_head   :  A datafilehead struct for holding file header.
   block_head  :  A datablockhead struct for holding block header.
   ptrace      :  Allocated space to hold one trace of fid data.
   trace_size  :  Number of bytes per trace of fid data.
   slice_ctr   :  Loop control variable for slices in a multi-slice experiment,
		  or echoes in a multi-echo experiment.
   trace_ctr   :  Loop control variable for traces.
   old_bbytes  :  Block size (including block header) of input (flash format)
		  fid file.
   offset      :  Offset into input file, for reading next trace.
   nbytes      :  Number of bytes desired for a file read or write.
   */
   int  array_ctr;
   int  ctr,single_trace_sz,trace_size,slice_ctr,trace_ctr,echo_ctr,nbytes;
   int	inecho,incomp,inni,inarray,blockindex;
   long old_bbytes, offset;
   struct datafilehead *src_file_head,*dest_file_head;
   struct datafilehead src_file_head_data;
   struct datablockhead *src_block_head,*dest_block_head;
   MFILE_ID fid_file, tmp_file;
   uint64_t	newbytelen;
   /*
   Begin Executable Code:
   ---------------------
   */
   inecho = (int) (necho+0.5);
   incomp = (int) (ncomp+0.5);

   if (incomp < 1)
   {
      Werrprintf ( "flashc: Number of traces (%d) must be at least 1", incomp);
      ABORT;
   }    
   /* Open the two files */
   if ( ( fid_file = mOpen(default_fid, (uint64_t) 0, O_RDONLY) ) == 0 )
   {  Vperror ( "flash_convert: mOpen (fid file)" );
      ABORT;
   }
   newbytelen = fid_file->byteLen + ((uint64_t) incomp * (uint64_t)(arraydim+0.5) * 
   						(uint64_t) sizeof(struct datablockhead));
   if ( ( tmp_file = mOpen(temp_fid,newbytelen,O_RDWR | O_CREAT)) == 0)
   {  Vperror ( "flash_convert: mOpen (temporary file)" );
      mClose(fid_file);
      ABORT;
   }

   /* Set src file header */
   src_file_head = &src_file_head_data;
   memcpy(src_file_head,fid_file->mapStrtAddr,sizeof(struct datafilehead));
   DATAFILEHEADER_CONVERT_NTOH(src_file_head);
   /* Set dest file header */
   dest_file_head = (struct datafilehead *)tmp_file->mapStrtAddr;

/*    fprintf(stderr,"nf_flash_convert: oldblocks=%d oldtraces=%d\n", */
/*			src_file_head->nblocks,src_file_head->ntraces); */

   /* Check contents before modifying. 		       */
   /* Recall that a value of -1 means "not set yet" */
   if ( *pni == -1.0 )
   {  
      *pni = 1.0;
      if (( src_file_head->nblocks < 1 ) ||
	  ( src_file_head->nblocks != floor(arraydim+0.5) ))
      {  Werrprintf ( "flash_convert: Bad nblocks field in file header" );
	 mClose(fid_file);
	 mClose(tmp_file);
	 unlink ( temp_fid );
	 ABORT;
      }
   }
   else
   {
      if ( src_file_head->nblocks != floor(arraydim+0.5) )
      {  Werrprintf ( "flash_convert: nblocks %d not equal to arraydim %d",
		src_file_head->nblocks, (int)floor(arraydim+0.5));

	 mClose(fid_file);
	 mClose(tmp_file);
	 unlink ( temp_fid );
	 ABORT;
      }
   }
   inni = floor(*pni+0.5);

   if ( src_file_head->ntraces != nf )
   {  Werrprintf ( "flash_convert: bad ntraces field in file header" );
      mClose(fid_file);
      mClose(tmp_file);
      unlink ( temp_fid );
      ABORT;
   }

   /* copy file header */
   memcpy(dest_file_head,src_file_head,sizeof(struct datafilehead));

   /* fprintf(stderr,"nf_flash_convert: ncomp=%g, necho=%g nf=%g pni=%g\n", */
   /*		ncomp, necho, nf, *pni);				   */
   /* Update vers_id,status in fid header */
   fidversion(dest_file_head,FILEHEAD,-1);

   /* Save the size of the input file blocks */
   old_bbytes = src_file_head->bbytes;

   /* Edit parameters and write file header back out to disk */
   dest_file_head->nblocks = (int)(((arraydim/(*pni)) * ncomp) + 0.5);
   dest_file_head->ntraces = (int)(((nf)/ncomp) * (*pni));
   single_trace_sz = src_file_head->tbytes;
   trace_size = (int)((nf/ncomp)+0.5) * src_file_head->tbytes;
   dest_file_head->bbytes  = (dest_file_head->ntraces*single_trace_sz)
						 + sizeof(struct datablockhead);

   /* Do some consistency checks */
   if ((format == 1) && ((int)(nf/ncomp) <= 1))
   {
	/* not a true multislice */
      Werrprintf("flash_convert_warning: Single slice, conversion not done.");
      mClose(fid_file);
      mClose(tmp_file);
      unlink ( temp_fid );
      ABORT;
   }
   if (format == 2)
   {
      int ok = 1;

      if (inecho < 1)
      {
         ok = 0;
         Werrprintf("flashc: For 'rare', number of echos (%d) must be at least 1.",
            inecho);
      }
      if (ok)
      {
         int tmp, intNf;

         intNf = (int) nf;
         tmp = (int)((nf/(ncomp*inecho))+0.5);
         ok = ((tmp * inecho * incomp) == intNf);
         if (!ok)
            Werrprintf("flashc: For 'rare', slices (%d) * echos (%d) must be a factor of nf (%d).",
               incomp, inecho, intNf);
      }
      if (!ok)
      {
         mClose(fid_file);
         mClose(tmp_file);
         unlink ( temp_fid );
         ABORT;
      }
   }

   /* advance dest data pointer, write file header */
   tmp_file->offsetAddr += sizeof(struct datafilehead);
   tmp_file->newByteLen = sizeof(struct datafilehead);
   
   DATAFILEHEADER_CONVERT_HTON(dest_file_head);

/*   fprintf(stderr,"nf_flash_convert: blocks=%d traces=%d bbytes=%d\n", */
/* 			file_head.nblocks,file_head.ntraces,old_bbytes); */

   /* Advance dest data pointer, Obtain block header */
   fid_file->offsetAddr += sizeof(struct datafilehead);
   src_block_head = (struct datablockhead *)fid_file->offsetAddr;
   nbytes = sizeof ( src_block_head );

   blockindex = 0;

   inarray = floor((arraydim/(*pni))+0.5);
   /* Loop over arrayed data */
   for (array_ctr=0; array_ctr< inarray; array_ctr++)
   {

   /* Loop over input slices or echoes */
   for ( slice_ctr = 0; slice_ctr < floor(ncomp+0.5); slice_ctr++ )
   {
     /* write a block header */
     blockindex++;
     /* copy block and update index */
     dest_block_head = (struct datablockhead *)tmp_file->offsetAddr;
     memcpy(tmp_file->offsetAddr,src_block_head,
					sizeof(struct datablockhead));

     /* Update vers_id,status in fid header */
     /* version = dest_file_head->vers_id & 0x3; */	/* VERSION */
     /* fidversion(dest_block_head,BLOCKHEAD,version); */

     tmp_file->offsetAddr += sizeof(struct datablockhead);
     tmp_file->newByteLen += sizeof(struct datablockhead);
     dest_block_head->index = htons(blockindex);
     dest_block_head->status = dest_file_head->status;

     echo_ctr = 0;
     /*for ( echo_ctr = 0 ; echo_ctr < floor(necho+0.5) ; echo_ctr++ ) */
     /*{ */
      /* Display slice or echo number, occasionally */
      if ( (slice_ctr*(inecho) + echo_ctr) % 16 == 0 )
	 disp_index ( slice_ctr );

      /* Loop over input phase encode elements */
      for ( trace_ctr = 0 ; trace_ctr < *pni ; trace_ctr++ )
      {
         switch (format) {
	   case 0:  /* standard phase-encode and compressed multi-image */
	     /* Compute position in input (flash) file for the current trace */
	     offset = sizeof(struct datafilehead) + 
		      (array_ctr)*old_bbytes + 
		      (trace_ctr*inarray)*old_bbytes +
		      sizeof(struct datablockhead) + (slice_ctr)*trace_size;

	     /* Position the input file */
	     fid_file->offsetAddr = fid_file->mapStrtAddr + offset;

	     /* Copy one trace of fid data */
	     memcpy(tmp_file->offsetAddr,fid_file->offsetAddr,trace_size);
	     tmp_file->offsetAddr += trace_size;
	     tmp_file->newByteLen += trace_size;
	     break;

           case 1: /* compressed multi-slice */
	     for (ctr=0; ctr<(int)((nf/ncomp)+0.5); ctr++) { 
	     /* Compute position in input file for the current single trace */
	         offset = sizeof(struct datafilehead) + 
			(array_ctr)*old_bbytes + 
			(trace_ctr*inarray)*old_bbytes + 
			sizeof(struct datablockhead) +
			(ctr*ncomp + slice_ctr)*(single_trace_sz);
	 
	    	 /* Position the input file */
	     	 fid_file->offsetAddr = fid_file->mapStrtAddr + offset;

	    	 /* Copy one trace of fid data */
		 /* trace_size = single_trace_sz? */
	   	 memcpy(tmp_file->offsetAddr,fid_file->offsetAddr,
							single_trace_sz);
	    	 tmp_file->offsetAddr += single_trace_sz;
	    	 tmp_file->newByteLen += single_trace_sz;
	     }
	     break;

           case 2: /* compressed echo-train, multi-slice, and phase-encode */
	     for (ctr=0; ctr<(int)((nf/(ncomp*inecho))+0.5); ctr++) {
	        /* Compute position in input file for  current single trace */
		/* fprintf(stderr,					    */
		/* "slice_ctr:%d trace_ctr:%d ctr:%d necho:%d ncomp:%d\n",  */
		/* 	slice_ctr,echo_ctr,trace_ctr,ctr,inecho,incomp);    */
	        offset = sizeof(struct datafilehead) +  
			  (array_ctr)*old_bbytes + 
			  (trace_ctr*inarray)*old_bbytes + 
			  sizeof(struct datablockhead) +
			  ctr*inecho*incomp*single_trace_sz +
			  (slice_ctr*inecho)*single_trace_sz;
	 
	        /* Position the input file */
		fid_file->offsetAddr = fid_file->mapStrtAddr + offset;

	        /* Copy a single trace of fid data */
		memcpy(tmp_file->offsetAddr,fid_file->offsetAddr,
						single_trace_sz*inecho);
		tmp_file->offsetAddr += single_trace_sz*inecho;
		tmp_file->newByteLen += single_trace_sz*inecho;
	     }
	     break;
	 }  /* end switch */

      }  /* End loop over input traces */

    /* } */  /* End loop over input echo train */

   }  /* End loop over input slices or echoes */

   }  /* End array loop */

   /* Clear display of slice or echo number */
   disp_index ( 0 );

   /* Close the files */
   mClose(fid_file);
   mClose(tmp_file);

   /* Get rid of the original fid file,       */
   /* and replace it with the temporary file. */
   if ( unlink ( default_fid ) != 0 )
   {  Vperror ( "flash_convert: unlink" );
      ABORT;
   }
   if ( rename ( temp_fid, default_fid ) != 0 )
   {  Vperror ( "flash_convert: rename" );
      ABORT;
   }

   /* Set file name parameter */
   P_setstring ( PROCESSED, "file", default_fid, 0 );
   P_setstring ( CURRENT, "file", default_fid, 0 );

   /* Normal successful return */
   RETURN;

} /* End function flash_convert */