예제 #1
0
파일: ft_move.c 프로젝트: mlevieux/Save
void	ft_move(t_stack **stack, t_stack *stack_two, int dir_ind[], char **sols)
{
	int	i;

	i = 0;
	if (dir_ind[0] % 10 == 1)
		while ((*stack)->index != dir_ind[1])
		{
			ft_r(stack);
			*sols = ft_strjoin_free(*sols, " ra");
			if (dir_ind[0] > 10)
			{
				write(1, "\nAction : ra", 12);
				ft_print_stack(*stack, stack_two);
			}
		}
	else
		while ((*stack)->index != dir_ind[1])
		{
			ft_rr(stack);
			*sols = ft_strjoin_free(*sols, " rra");
			if (dir_ind[0] > 10)
			{
				write(1, "\nAction : rra", 13);
				ft_print_stack(*stack, stack_two);
			}
		}
}
예제 #2
0
void	ft_add_ls(t_steve *list, t_opts *opt)
{
	if (opt->r)
		ft_r(&list, opt);
	if (opt->l)
		ft_l(list, opt);
	else
		ft_ls(list, opt);
	if (opt->gr)
		ft_add_gr(list, opt);
}
예제 #3
0
파일: Fourier.c 프로젝트: AZed/cdo
void *Fourier(void *argument)
{
  int bit, sign;
  int gridsize;
  int nrecs;
  int gridID, varID, levelID, recID;
  int tsID;
  int i;
  int nts;
  int nalloc = 0;
  int streamID1, streamID2;
  int vlistID1, vlistID2, taxisID1, taxisID2;
  int nmiss;
  int nvars, nlevel;
  int *vdate = NULL, *vtime = NULL;
  double missval;
  field_t ***vars = NULL;
  typedef struct
  {
    double *real;
    double *imag;
    double *work_r;
    double *work_i;
  } memory_t;
  memory_t *ompmem = NULL;


  cdoInitialize(argument);

  operatorInputArg("the sign of the exponent (-1 for normal or 1 for reverse transformation)!");
  sign = parameter2int(operatorArgv()[0]);

  streamID1 = streamOpenRead(cdoStreamName(0));

  vlistID1 = streamInqVlist(streamID1);
  vlistID2 = vlistDuplicate(vlistID1);

  taxisID1 = vlistInqTaxis(vlistID1);
  taxisID2 = taxisDuplicate(taxisID1);
  vlistDefTaxis(vlistID2, taxisID2);

  streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());

  streamDefVlist(streamID2, vlistID2);

  nvars = vlistNvars(vlistID1);

  tsID = 0;
  while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
    {
      if ( tsID >= nalloc )
	{
	  nalloc += NALLOC_INC;
	  vdate = (int*) realloc(vdate, nalloc*sizeof(int));
	  vtime = (int*) realloc(vtime, nalloc*sizeof(int));
	  vars  = (field_t ***) realloc(vars, nalloc*sizeof(field_t **));
	}

      vdate[tsID] = taxisInqVdate(taxisID1);
      vtime[tsID] = taxisInqVtime(taxisID1);

      vars[tsID] = field_malloc(vlistID1, FIELD_NONE);

      for ( recID = 0; recID < nrecs; recID++ )
	{
	  streamInqRecord(streamID1, &varID, &levelID);
	  gridID   = vlistInqVarGrid(vlistID1, varID);
	  gridsize = gridInqSize(gridID);
	  vars[tsID][varID][levelID].ptr = (double*) malloc(2*gridsize*sizeof(double));
	  streamReadRecord(streamID1, vars[tsID][varID][levelID].ptr, &nmiss);
	  vars[tsID][varID][levelID].nmiss = nmiss;
	}

      tsID++;
    }

  nts = tsID;

  for ( bit = nts; !(bit & 1); bit >>= 1 );

  ompmem = (memory_t*) malloc(ompNumThreads*sizeof(memory_t));
  for ( i = 0; i < ompNumThreads; i++ )
    {
      ompmem[i].real = (double*) malloc(nts*sizeof(double));
      ompmem[i].imag = (double*) malloc(nts*sizeof(double));
      if ( bit != 1 )
	{
	  ompmem[i].work_r = (double*) malloc(nts*sizeof(double));
	  ompmem[i].work_i = (double*) malloc(nts*sizeof(double));
	}
    }

  for ( varID = 0; varID < nvars; varID++ )
    {
      gridID   = vlistInqVarGrid(vlistID1, varID);
      missval  = vlistInqVarMissval(vlistID1, varID);
      gridsize = gridInqSize(gridID);
      nlevel   = zaxisInqSize(vlistInqVarZaxis(vlistID1, varID));
      for ( levelID = 0; levelID < nlevel; levelID++ )
	{
#if defined(_OPENMP)
#pragma omp parallel for default(shared) private(i, tsID)
#endif
	  for ( i = 0; i < gridsize; i++ )
	    {
	      int lmiss = 0;
              int ompthID = cdo_omp_get_thread_num();

	      for ( tsID = 0; tsID < nts; tsID++ )
		{
		  ompmem[ompthID].real[tsID] = vars[tsID][varID][levelID].ptr[2*i];
		  ompmem[ompthID].imag[tsID] = vars[tsID][varID][levelID].ptr[2*i+1];
		  if ( DBL_IS_EQUAL(ompmem[ompthID].real[tsID], missval) ||
		       DBL_IS_EQUAL(ompmem[ompthID].imag[tsID], missval) ) lmiss = 1;
		}

	      if ( lmiss == 0 )
		{
		  if ( bit == 1 )	/* nts is a power of 2 */
		    fft(ompmem[ompthID].real, ompmem[ompthID].imag, nts, sign);
		  else
		    ft_r(ompmem[ompthID].real, ompmem[ompthID].imag, nts, sign, ompmem[ompthID].work_r, ompmem[ompthID].work_i);

		  for ( tsID = 0; tsID < nts; tsID++ )
		    {
		      vars[tsID][varID][levelID].ptr[2*i]   = ompmem[ompthID].real[tsID];
		      vars[tsID][varID][levelID].ptr[2*i+1] = ompmem[ompthID].imag[tsID];
		    }
		}
	      else
		{
		  for ( tsID = 0; tsID < nts; tsID++ )
		    {
		      vars[tsID][varID][levelID].ptr[2*i]   = missval;
		      vars[tsID][varID][levelID].ptr[2*i+1] = missval;
		    }
		}
	    }
	}
    }

  for ( i = 0; i < ompNumThreads; i++ )
    {
      free(ompmem[i].real);
      free(ompmem[i].imag);
      if ( bit != 1 )
	{
	  free(ompmem[i].work_r);
	  free(ompmem[i].work_i);
	}
    }
  free(ompmem);

  for ( tsID = 0; tsID < nts; tsID++ )
    {
      taxisDefVdate(taxisID2, vdate[tsID]);
      taxisDefVtime(taxisID2, vtime[tsID]);
      streamDefTimestep(streamID2, tsID);

      for ( varID = 0; varID < nvars; varID++ )
	{
	  nlevel = zaxisInqSize(vlistInqVarZaxis(vlistID1, varID));
	  for ( levelID = 0; levelID < nlevel; levelID++ )
	    {
	      if ( vars[tsID][varID][levelID].ptr )
		{
		  nmiss = vars[tsID][varID][levelID].nmiss;
		  streamDefRecord(streamID2, varID, levelID);
		  streamWriteRecord(streamID2, vars[tsID][varID][levelID].ptr, nmiss);
		  free(vars[tsID][varID][levelID].ptr);
		  vars[tsID][varID][levelID].ptr = NULL;
		}
	    }
	}

      field_free(vars[tsID], vlistID1);
    }

  if ( vars  ) free(vars);
  if ( vdate ) free(vdate);
  if ( vtime ) free(vtime);

  streamClose(streamID2);
  streamClose(streamID1);

  cdoFinish();

  return (NULL);
}