Exemple #1
0
void twopassfft_scratch(multifile * infile, multifile * scratch,
                        long long nn, int isign)
{
   long long n1, n2, bb, fp, ii, jj, kk, kind, df;
   int move_size;
   unsigned char *move;
   rawtype *data, *dp;
   double tmp1, tmp2, wtemp, wpi, wpr, wi, wr, delta;

   if (nn < 2)
      return;

   /* Treat the input data as a n1 (rows) x n2 (cols) */
   /* matrix.  Make sure that n2 >= n1.               */

   n1 = good_factor(nn);
   if (n1 == 0) {
      printf("\nLength of FFT in twopassfft_scratch() must be factorable\n\n");
      exit(1);
   }
   n2 = nn / n1;
   bb = find_blocksize(n1, n2);
   if (bb == 0) {
      printf("\nCan't factor the FFT length in twopassfft_scratch()\n");
      printf("   into useful sizes.\n\n");
      exit(1);
   }

   data = gen_rawvect(bb * n2);
   move_size = (bb + n2) / 2;
   move = (unsigned char *) malloc(move_size);

   /* First do n2 transforms of length n1 by  */
   /* fetching size bb x n1 blocks in memory. */

   for (ii = 0; ii < n2; ii += bb) {

      /* Read a n1 (rows) x bb (cols) block of data */

      dp = data;
      fp = sizeof(rawtype) * ii;
      df = sizeof(rawtype) * n2;
      for (jj = 0; jj < n1; jj++) {
         fseek_multifile(infile, fp, SEEK_SET);
         fread_multifile(dp, sizeof(rawtype), bb, infile);
         dp += bb;              /* Data ptr */
         fp += df;              /* File ptr */
      }

      /* Transpose the n1 (rows) x bb (cols) block of data */

      transpose_fcomplex(data, n1, bb, move, move_size);

      /* Do bb transforms of length n1 */

      for (jj = 0; jj < bb; jj++)
         COMPLEXFFT(data + jj * n1, n1, isign);

      /* Multiply the matrix A(ii,jj) by exp(isign 2 pi i jj ii / nn). */
      /* Use recursion formulas from Numerical Recipes.                */

      for (jj = 0; jj < bb; jj++) {
         delta = isign * TWOPI * (ii + jj) / nn;
         wr = cos(delta);
         wi = sin(delta);
         wtemp = sin(0.5 * delta);
         wpr = -2.0 * wtemp * wtemp;
         wpi = wi;
         kind = jj * n1 + 1;
         for (kk = 1; kk < n1; kk++, kind++) {
            tmp1 = data[kind].r;
            tmp2 = data[kind].i;
            data[kind].r = tmp1 * wr - tmp2 * wi;
            data[kind].i = tmp2 * wr + tmp1 * wi;
            wtemp = wr;
            wr = wtemp * wpr - wi * wpi + wr;
            wi = wi * wpr + wtemp * wpi + wi;
         }
      }
      fwrite_multifile(data, sizeof(rawtype), bb * n1, scratch);
   }

   /* Now do n1 transforms of length n2 by fetching  */
   /* groups of size n2 (rows) x bb (cols) blocks.   */

   for (ii = 0; ii < n1; ii += bb) {

      /* Read two n2 (rows) x bb (cols) blocks from the file */

      dp = data;
      fp = sizeof(rawtype) * ii;
      df = sizeof(rawtype) * n1;
      for (jj = 0; jj < n2; jj++) {
         fseek_multifile(scratch, fp, SEEK_SET);
         fread_multifile(dp, sizeof(rawtype), bb, scratch);
         dp += bb;              /* Data ptr */
         fp += df;              /* File ptr */
      }

      /* Transpose the n2 (rows) x bb (cols) block of data */

      transpose_fcomplex(data, n2, bb, move, move_size);

      /* Do bb transforms of length n2 */

      for (jj = 0; jj < bb; jj++)
         COMPLEXFFT(data + jj * n2, n2, isign);

      /* Transpose the bb (rows) x n2 (cols) block of data */

      transpose_fcomplex(data, bb, n2, move, move_size);

      /* Scale the data if needed */

      if (isign == 1) {
         tmp1 = 1.0 / (double) nn;
         for (jj = 0; jj < n2 * bb; jj++) {
            data[jj].r *= tmp1;
            data[jj].i *= tmp1;
         }
      }


      /* Write n2 (rows) x bb (cols) blocks to the file  */

      dp = data;
      fp = sizeof(rawtype) * ii;
      df = sizeof(rawtype) * n1;
      for (jj = 0; jj < n2; jj++) {
         fseek_multifile(infile, fp, SEEK_SET);
         fwrite_multifile(dp, sizeof(rawtype), bb, infile);
         dp += bb;              /* Data ptr */
         fp += df;              /* File ptr */
      }
   }
   free(move);
   vect_free(data);
}
Exemple #2
0
int QPhotorec::photorec(alloc_data_t *list_search_space)
{
  pstatus_t ind_stop=PSTATUS_OK;
  const unsigned int blocksize_is_known=params->blocksize;
  params_reset(params, options);
  /* make the first recup_dir */
  params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num);
  for(params->pass=0; params->status!=STATUS_QUIT; params->pass++)
  {
    timer->start();
    switch(params->status)
    {
      case STATUS_UNFORMAT:
	/* FIXME */
	break;
      case STATUS_FIND_OFFSET:
	{
	  uint64_t start_offset=0;
	  if(blocksize_is_known>0)
	  {
	    ind_stop=PSTATUS_OK;
	    if(!td_list_empty(&list_search_space->list))
	      start_offset=(td_list_entry(list_search_space->list.next, alloc_data_t, list))->start % params->blocksize;
	  }
	  else
	  {
	    ind_stop=photorec_find_blocksize(list_search_space);
	    params->blocksize=find_blocksize(list_search_space, params->disk->sector_size, &start_offset);
	  }
	  update_blocksize(params->blocksize, list_search_space, start_offset);
	}
	break;  
      case STATUS_EXT2_ON_BF:
      case STATUS_EXT2_OFF_BF:
	/* FIXME */
	break;
      default:
	ind_stop=photorec_aux(list_search_space);
	break;
    }
    timer->stop();
    qphotorec_search_updateUI();
    session_save(list_search_space, params, options);
    switch(ind_stop)
    {
      case PSTATUS_EACCES:
	{
	  int ret=QMessageBox::warning(this,
	      tr("QPhotoRec: Failed to create file!"),
	      tr("Failed to create file! Please choose another destination"),
	      QMessageBox::Ok| QMessageBox::Cancel, QMessageBox::Ok);
	  if(ret==QMessageBox::Cancel)
	  {
	    params->status=STATUS_QUIT;
	  }
	  else
	  {
	    setExistingDirectory();
	    free(params->recup_dir);
	    QByteArray byteArray = (directoryLabel->text() + "/" + DEFAULT_RECUP_DIR).toUtf8();
	    params->recup_dir=strdup(byteArray.constData());
	    params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num);
	  }
	}
	break;
      case PSTATUS_ENOSPC:
	{
	  int ret=QMessageBox::warning(this,
	      tr("QPhotoRec: Not enough space!"),
	      tr("There is not enough space left! Please free disk space and/or choose another destination"),
	      QMessageBox::Ok| QMessageBox::Cancel, QMessageBox::Ok);
	  if(ret==QMessageBox::Cancel)
	  {
	    params->status=STATUS_QUIT;
	  }
	  else
	  {
	    setExistingDirectory();
	    free(params->recup_dir);
	    QByteArray byteArray = (directoryLabel->text() + "/" + DEFAULT_RECUP_DIR).toUtf8();
	    params->recup_dir=strdup(byteArray.constData());
	    params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num);
	  }
	}
break;
      case PSTATUS_OK:
	status_inc(params, options);
	if(params->status==STATUS_QUIT)
	  unlink("photorec.ses");
	break;
      case PSTATUS_STOP:
	params->status=STATUS_QUIT;
	break;
    }
    update_stats(params->file_stats, list_search_space);
    qphotorec_search_updateUI();
  }
  free_search_space(list_search_space);
  free_header_check();
  free(params->file_stats);
  params->file_stats=NULL;
  return 0;
}