Example #1
0
void tryStringFind()
{
    std::ostringstream oss(std::ostringstream::out);
    oss<<"ls -l | wc -w";

    std::string cmd = oss.str();
    std::string mem1(10,' ');
    std::copy(cmd.begin(), std::find(cmd.begin(), cmd.end(), '|'), mem1.begin());

    std::cout<<"cmd : "<<cmd<<std::endl;
    std::cout<<"membre1 : "<<mem1<<std::endl;
}
Example #2
0
int sc_main (int argc, char* argv[]) {
	sc_signal<unsigned int> data;
	sc_signal<unsigned int> addr_last;
	sc_signal<unsigned int> address;
	sc_signal<bool> we,ce;

	memory mem1("mem1", 1040,"T1.txt");
	tb_mem test1("test1");
	mem1.ce(ce);
	mem1.we(we);
	mem1.data(data);
	mem1.addr_last(addr_last);
	mem1.address(address);

	test1.ce(ce);
	test1.we(we);
	test1.data(data);
	test1.addr_last(addr_last);
	test1.address(address);

	sc_start();
	return 0;
}
Example #3
0
int main( int argc, char ** argv )
{
  FILE * pFile;
  int i, do_continue;
  char in_file[MAX_STR+1], out_file[MAX_STR+1], line[MAX_STR+1];

  do_continue = i = 0;
  pFile = NULL;

do
  {
  printf("Input file? "); fgets( in_file, MAX_STR, stdin );
  printf("Output file? "); fgets( out_file, MAX_STR, stdin );
  sscanf( in_file, "%s\n", in_file );
  sscanf( out_file, "%s\n", out_file );

  pFile = fopen( in_file, "r" );
  if( pFile == NULL ) return 1;

  fout = fopen( out_file, "w" );
  if( fout == NULL ) return 2;
  
  if( init( pFile ) ) goto unable_to_parse;

  do 
    {
      fprintf( fout, "c#%d ", cycle );
      wb(); mem3(); mem2(); mem1(); ex(); id(); if2(); if1(); /* pretend all stages are happening simultaneously */
      fprintf( fout, "\n");
      /* move everything down the pipeline */
      if( !MEM3_stall ) { WB = MEM3; WB_count = MEM3_count; }
      if( !MEM2_stall ) { MEM3 = MEM2; MEM3_count = MEM2_count; }
      if( !MEM1_stall ) { MEM2 = MEM1; MEM2_count = MEM1_count; }
      if( !EX_stall   ) { MEM1 = EX; MEM1_count = EX_count; }
      if( !ID_stall   ) { EX = ID; EX_count = ID_count; } else MEM1 = EMPTY;
      if( !IF2_stall  ) { ID = IF2; ID_count = IF2_count; }
      if( !IF1_stall  ) { IF2 = IF1; IF2_count = IF1_count; ++inst_cycle; }
      if( flush ) { IF1 = EMPTY; IF2 = EMPTY; ID = EMPTY; EX = EMPTY; flush = FALSE; --inst_cycle; }
      ++cycle;
      Registers[0] = 0; /* reset R0 if it was accidently set */
    } while( ( (IF1 != EMPTY) || (IF2 != EMPTY) || (ID != EMPTY) || (EX != EMPTY) || (MEM1 != EMPTY) || (MEM2 != EMPTY) || (MEM3 != EMPTY) || (WB != EMPTY) ) );

  /* print end status */
  print_regs( fout ); print_mem( fout );

  unable_to_parse:
  for( i = 0; i < instcount; ++i )
    free( Instructions[i] );
  fclose( pFile );
  fclose( fout );

  printf("would you like to run again? ");
  fgets( line, MAX_STR, stdin );
  do_continue = ( line[0] == 'y' || line[0] == 'Y' ) ? 1 : 0;
  } while( do_continue );

 goto end;
 for( i = 0; i < instcount; ++i )
   free( Instructions[i] );
 fclose( pFile );
 fclose( fout );
 end:
 return 0;
}
Example #4
0
File: pml.c Project: emguy/ezfdtd
int setup_pml (char* file_name)
{
    double pml_grading_order; 

    double pml_sigma_max;
    double pml_factor;
    double pml_sigma_e;
    double pml_sigma_h;

    int layer_index;
    int status;

    status = h5_get_attr(file_name, "boundaries", "pml_sigma_max", &pml_sigma_max);
    inspect(status, "fail to get h5 attributes");
    status = h5_get_attr(file_name, "boundaries", "pml_grading_order", &pml_grading_order);
    inspect(status, "fail to get h5 attributes");

    hxy = bx;
    hyz = by;
    hzx = bz;
    exy = dx;
    eyz = dy;
    ezx = dz;

    pml_c1x = (double *)mem1(type_double, abc_size);
    inspect(pml_c1x, "fail to allocate mem1ory for field");
    pml_c1y = (double *)mem1(type_double, abc_size);
    inspect(pml_c1y, "fail to allocate mem1ory for field");
    pml_c1z = (double *)mem1(type_double, abc_size);
    inspect(pml_c1z, "fail to allocate mem1ory for field");
    pml_d1x = (double *)mem1(type_double, abc_size);
    inspect(pml_d1x, "fail to allocate mem1ory for field");
    pml_d1y = (double *)mem1(type_double, abc_size);
    inspect(pml_d1y, "fail to allocate mem1ory for field");
    pml_d1z = (double *)mem1(type_double, abc_size);
    inspect(pml_d1z, "fail to allocate mem1ory for field");

    pml_c2x = (double *)mem1(type_double, abc_size);
    inspect(pml_c2x, "fail to allocate mem1ory for field");
    pml_c2y = (double *)mem1(type_double, abc_size);
    inspect(pml_c2y, "fail to allocate mem1ory for field");
    pml_c2z = (double *)mem1(type_double, abc_size);
    inspect(pml_c2z, "fail to allocate mem1ory for field");

    pml_d2x = (double *)mem1(type_double, abc_size);
    inspect(pml_d2x, "fail to allocate mem1ory for field");
    pml_d2y = (double *)mem1(type_double, abc_size);
    inspect(pml_d2y, "fail to allocate mem1ory for field");
    pml_d2z = (double *)mem1(type_double, abc_size);
    inspect(pml_d2z, "fail to allocate mem1ory for field");


    pml_c2x_0 = d_t / (EPSILON0 * d_x);
    pml_c2y_0 = d_t / (EPSILON0 * d_y);
    pml_c2z_0 = d_t / (EPSILON0 * d_z);

    pml_d2x_0 = d_t / (MU0 * d_x);
    pml_d2y_0 = d_t / (MU0 * d_y);
    pml_d2z_0 = d_t / (MU0 * d_z);

    //boundaryThickness = (double )abc_size * dh;
    //pml_sigma_max = -log(reflectionCoefficient0) * (grading_order + 1.0) 
    //    * boundaryEpsilon * EPSILON0 * C0 / (2.0 * boundaryThickness);

    pml_factor = pml_sigma_max 
        / ((pml_grading_order + 1) * pow(2, pml_grading_order + 1) * pow(abc_size, pml_grading_order));

    for (layer_index = 0; layer_index < abc_size; layer_index++)
    {
        if (layer_index == 0)
            pml_sigma_e = pml_factor;
        else
            pml_sigma_e = pml_factor * (pow(2 * layer_index + 1, pml_grading_order + 1) 
                    - pow(2 * layer_index - 1, pml_grading_order + 1));

        pml_sigma_h = pml_sigma_e * MU0 / EPSILON0;

        pml_c1x[layer_index] = (1.0 - (pml_sigma_e * d_t) / (2.0 * EPSILON0)) / (1.0 + (pml_sigma_e * d_t) / (2.0 * EPSILON0));
        pml_c1y[layer_index] = (1.0 - (pml_sigma_e * d_t) / (2.0 * EPSILON0)) / (1.0 + (pml_sigma_e * d_t) / (2.0 * EPSILON0));
        pml_c1z[layer_index] = (1.0 - (pml_sigma_e * d_t) / (2.0 * EPSILON0)) / (1.0 + (pml_sigma_e * d_t) / (2.0 * EPSILON0));
        pml_d1x[layer_index] = (1.0 - (pml_sigma_h * d_t) / (2.0 * MU0)) / (1.0 + (pml_sigma_h * d_t) / (2.0 * MU0));
        pml_d1y[layer_index] = (1.0 - (pml_sigma_h * d_t) / (2.0 * MU0)) / (1.0 + (pml_sigma_h * d_t) / (2.0 * MU0));
        pml_d1z[layer_index] = (1.0 - (pml_sigma_h * d_t) / (2.0 * MU0)) / (1.0 + (pml_sigma_h * d_t) / (2.0 * MU0));
        pml_c2x[layer_index] = (d_t / d_x / EPSILON0) / (1.0 + pml_sigma_e * d_t / (2.0 * EPSILON0));
        pml_c2y[layer_index] = (d_t / d_y / EPSILON0) / (1.0 + pml_sigma_e * d_t / (2.0 * EPSILON0));
        pml_c2z[layer_index] = (d_t / d_z / EPSILON0) / (1.0 + pml_sigma_e * d_t / (2.0 * EPSILON0));
        pml_d2x[layer_index] = (d_t / d_x / MU0) / (1.0 + pml_sigma_h * d_t / (2.0 * MU0));
        pml_d2y[layer_index] = (d_t / d_y / MU0) / (1.0 + pml_sigma_h * d_t / (2.0 * MU0));
        pml_d2z[layer_index] = (d_t / d_z / MU0) / (1.0 + pml_sigma_h * d_t / (2.0 * MU0));
    }
    return 1;
}