コード例 #1
0
ファイル: init_format.c プロジェクト: brd6/my_printf2
int		init_ptf_format(const char *format,
				int *i,
				t_ptf_format *ptf_format)
{
  int		flag_cp;
  int		var_set;

  *i = *i + 1;
  var_set = 0;
  while (format && format[*i])
    {
      init_flag(format[*i], &flag_cp, ptf_format, &var_set);
      skip_char(format, i, ' ');
      if (!init_field_width(format, i, &var_set, ptf_format))
	return (0);
      init_precision(format, i, ptf_format);
      if (getchar_pos("hl", format[*i]) != -1)
	ptf_format->length_modifier = format[*i];
      else if (is_alpha(format[*i], 0) || format[*i] == '%')
	{
	  if (format[*i] == 'n' &&
	      (ptf_format->field_width = printf_my_itoa(g_prog.i)) == NULL)
	    return (0);
	  ptf_format->conv_char = format[*i];
	  return (1);
	}
      *i = *i + 1;
    }
  return (1);
}
コード例 #2
0
ファイル: prt.c プロジェクト: acralfs/fricas
void
delete_line(void)
{
    int count;

    /*** deletes the entire line                                 *****/

    if (buff_pntr == 0)
        return;                 /** There is nothing to do **/

    /** first I have to back up to the beginning of the line     ****/
    for (count = curr_pntr; count > 0; count--)
        myputchar(_BKSPC);

    /** blank over the end of the line      ***/
    for (count = 0; count < buff_pntr; count++) {
        myputchar(_BLANK);
    }
    /** back up again ***/
    for (count = buff_pntr; count > 0; count--)
        myputchar(_BKSPC);

    /* Also clear the buffer */
    init_buff(buff, buff_pntr);
    init_flag(buff_flag, buff_pntr);
    buff_pntr = curr_pntr = 0;

    fflush(stdout);
    return;

}
コード例 #3
0
ファイル: flagtracking.c プロジェクト: ensiform/agostats
void create_new_flag( char *flag ) 
{	
	init_flag( flag_count );
	strcpy( FLAGS[ flag_count].name, flag );
	
	flag_count++;
}
コード例 #4
0
int main(int argc, char **argv)
{
 pthread_t runner[MAXTH];
 int i, resume = TRUE;

 sem_init(&done, 0, 0);
 for(i = 0; i < MAXTH; i++)
 {
  init_flag(i);
  pthread_create(&runner[i], 0, &func, (void *)i);
 }

 while(resume)
 {
  resume = some_event_for_thread_resume();
  if(resume) for(i = 0; i < MAXTH; i++) set_flag(i, TRUE);
  else break;

  for(i = 0; i < MAXTH; i++) sem_wait(&done);
  printf("back to main!\n");
 }
	
 for(i = 0; i < MAXTH; i++)
 {
  pthread_cancel(runner[i]);
  pthread_join(runner[i], 0);
  printf("thread %d returned\n", runner[i]);
 }
 return 0;
}
コード例 #5
0
ファイル: flagtracking.c プロジェクト: ensiform/agostats
// public functions
void clear_flag_table( void )
{
	int i;

	for ( i = 0; i < MAX_FLAGS ; i++ ) {
		init_flag( i );
	}

	flag_count = 0;
}
コード例 #6
0
ファイル: system.c プロジェクト: Soupalognon/Code_Robot_2016
void init_system (void)
{
    init_clock();

    OVERFLOW_CODEUR[CODEUR_D] = PAS_D_OVERFLOW_CODEUR;
    OVERFLOW_CODEUR[CODEUR_G] = PAS_D_OVERFLOW_CODEUR;

    position[CODEUR_D].ancien = 0;
    position[CODEUR_G].ancien = 0;
    position[CODEUR_D].nouvelle = 0;
    position[CODEUR_G].nouvelle = 0;
    
    config_timer_10ms();
    config_timer_5ms();
    config_timer_90s();

    ConfigMapping ();
    ConfigPorts ();
    ConfigQEI ();
    ConfigInterrupt ();
    ConfigPWM();
    //ConfigADC();

    InitUART(UART_XBEE, 115200);
    InitUART(UART_AX12, 500000);

    // Evitement
    DETECTION = OFF;
    EVITEMENT_ADV_AVANT = OFF;
    EVITEMENT_ADV_ARRIERE = OFF;
    STRATEGIE_EVITEMENT = STOP;
    FLAG_EVITEMENT_STRATEGIQUE = NE_RIEN_FAIRE;

    // AUTOMS
    FLAG_ACTION = NE_RIEN_FAIRE;
    ETAT_AUTOM = NE_RIEN_FAIRE;
    COULEUR = VIOLET;
    COMPTEUR_MARCHE = 0;

    COMPTEUR_TEMPS_MATCH = 0;

    TIMER_5ms = ACTIVE;

#ifdef PETIT_ROBOT
    TRISCbits.TRISC2 = 0;
#endif
#ifdef GROS_ROBOT
    //TRISAbits.TRISA3 = 0;
#endif
    
    init_flag();
}
コード例 #7
0
ファイル: paint-map.c プロジェクト: coldhiber/Paint-Map
void mouse(int button, int state, int x, int y)
{
  int new_y = HEIGHT_WINDOW - y;
  int a;
  a = (x > 60);

  init_flag(x, new_y); 
  if (flag == 1 && a) {
    draw_rectangle2(x, new_y);
  } else if (flag == 4 && a) {
    draw_circle2(x, new_y, 10);
  }
}
コード例 #8
0
ファイル: read.c プロジェクト: Fusiow/msh
char	*take_cmd(int choice)
{
	char			*result;
	char			*buffer;
	struct termios	term;

	init_flag(&term);
	buffer = (char *)ft_memalloc(sizeof(char) * 3);
	result = in_while(buffer, choice);
	ft_putstr("\n");
	ft_free(buffer);
	show_autocomplete(NULL, 0);
	re_flag(&term);
	return (result);
}
コード例 #9
0
ファイル: my_printf.c プロジェクト: PhilippeLefevre/Raytracer
t_fonct			*init_struct(t_fonct *tab)
{
  if ((tab = malloc(12 * sizeof(t_fonct))) == NULL)
    return (NULL);
  init_flag(tab);
  (tab[0].f) = va_my_putchar;
  (tab[1].f) = va_my_putstr;
  (tab[2].f) = va_my_putnbr;
  (tab[3].f) = va_my_putnbr;
  (tab[4].f) = va_my_putunbr;
  (tab[5].f) = va_my_octal;
  (tab[6].f) = va_my_examin;
  (tab[7].f) = va_my_examaj;
  (tab[8].f) = va_my_bin;
  (tab[9].f) = va_my_disp_unp;
  (tab[10].f) = va_my_adress;
  (tab[11].f) = va_my_putfnbr;
  return (tab);
}
コード例 #10
0
ファイル: prt.c プロジェクト: acralfs/fricas
void
clear_buff(void)
{
    int count;

    /*** called when spadbuf gives me a line incase there is something already
      on the line ****/
    if (buff_pntr > 0) {
        /*** backup to the beginning of the line ***/
        for (count = curr_pntr; count > 0; count--)
            myputchar(_BKSPC);
        /** blank over the line      ***/
        for (count = 0; count < buff_pntr; count++) {
            myputchar(_BLANK);
        }
        /** back up again ***/
        for (count = buff_pntr; count > 0; count--)
            myputchar(_BKSPC);
        init_buff(buff, buff_pntr);
        init_flag(buff_flag, buff_pntr);
        curr_pntr = buff_pntr = 0;
    }
}
コード例 #11
0
ファイル: main.c プロジェクト: apachalieva/CFD_Lab
int main(int argc, char** args){
	
	double Re, UI, VI, PI, GX, GY, t_end, xlength, ylength, dt, dx, dy, alpha, omg, tau, eps, dt_value, t, res, dp, nu;
	double **U, **V, **P, **F, **G, **RS;
	double **K, **E;					/* turbulent kinetic energy k, dissipation rate epsilon*/
	double Fu, Fv;						/* force integration variables */
	double KI, EI, cn, ce, c1, c2; 			/* K and E: Initial values for k and epsilon */

	int n, it, imax, jmax, itermax, pb, boundaries[4];
	int fluid_cells;		/* Number of fluid cells in our geometry */
	int **Flag;			/* Flagflield matrix */
	
	char vtkname[200];
	char pgm[200];
	char problem[10];		/* Problem name */
	char fname[200];

	if(argc<2){
		printf("No parameter file specified. Terminating...\n");
		exit(1);
	}

	sprintf(fname, "%s%s", CONFIGS_FOLDER, args[1]);
	printf("%s\n",fname);
	read_parameters(fname, &Re, &UI, &VI, &PI, &GX, &GY, &t_end, &xlength, &ylength, &dt, &dx, &dy, &imax, &jmax, &alpha, &omg, &itermax, &eps, boundaries, &dp, &pb, &KI, &EI, &cn, &ce, &c1, &c2, pgm, &nu, problem);

	/* Allocate Flag matrix */
	Flag = imatrix( 0, imax+1, 0, jmax+1 );

	U = matrix ( 0 , imax+1 , 0 , jmax+1 );
	V = matrix ( 0 , imax+1 , 0 , jmax+1 );
	P = matrix ( 0 , imax+1 , 0 , jmax+1 );

	F = matrix ( 0 , imax , 0 , jmax );
	G = matrix ( 0 , imax , 0 , jmax );
	RS = matrix ( 0 , imax , 0 , jmax );

	K = matrix ( 0 , imax+1 , 0 , jmax+1 );
	E = matrix ( 0 , imax+1 , 0 , jmax+1 );
	
	/* Initialize values to the Flag, u, v and p */
	init_flag(CONFIGS_FOLDER,pgm, imax, jmax, &fluid_cells, Flag );
	init_uvp(UI, VI, PI, KI, EI, imax, jmax, U, V, P, K, E, Flag, problem );

	printf("Problem: %s\n", problem );
	printf( "xlength = %f, ylength = %f\n", xlength, ylength );
	printf( "imax = %d, jmax = %d\n", imax, jmax );
	printf( "dt = %f, dx = %f, dy = %f\n", dt, dx, dy);
	printf( "Number of fluid cells = %d\n", fluid_cells );
	printf( "Reynolds number: %f\n\n", Re);

	t=.0;
	n=0;

	while( t <= t_end ){
		boundaryvalues( imax, jmax, U, V, K, E, boundaries, Flag );

		/* special inflow boundaries, including k and eps */
		spec_boundary_val( problem, imax, jmax, U, V, K, E, Re, dp, cn, ylength);

		/* calculate new values for k and eps */
		comp_KAEP(Re, nu, cn, ce, c1, c2, alpha, dt, dx, dy, imax, jmax, U, V, K, E, GX, GY, Flag);


		/* calculate new values for F and G */
		calculate_fg( Re, GX, GY, alpha, dt, dx, dy, imax, jmax, U, V, F, G, K, E, nu, cn, Flag );

		/* calculate right hand side */
		calculate_rs( dt, dx, dy, imax, jmax, F, G, RS, Flag );

		it = 0;
		res = 10000.0;
		while( it < itermax && fabs(res) > eps ){
			sor( omg, dx, dy, imax, jmax, fluid_cells, P, RS, Flag, &res, problem, dp );
			it++;
		}

		printf("[%5d: %f] dt: %f, sor iterations: %4d \n", n, t, dt, it);

		/* calculate new values for u and v */
		calculate_uv( dt, dx, dy, imax, jmax, U, V, F, G, P, Flag );

		t += dt;
		n++;
	}

	sprintf(vtkname, "%s%s", VISUA_FOLDER,  args[1]);
	write_vtkFile( vtkname, 1, xlength, ylength, imax, jmax, dx, dy, U, V, P, K, E, Flag);
	
	comp_surface_force( Re, dx, dy, imax, jmax, U, V, P, Flag, &Fu, &Fv);

	printf( "\nProblem: %s\n", problem );
	printf( "xlength = %f, ylength = %f\n", xlength, ylength );
	printf( "imax = %d, jmax = %d\n", imax, jmax );
	printf( "dt = %f, dx = %f, dy = %f\n", dt, dx, dy);
	printf( "Number of fluid cells = %d\n", fluid_cells );
	printf( "Reynolds number: %f\n", Re);
	printf( "Drag force = %f Lift force = %f\n", Fu, Fv);

	/* free memory */
	free_matrix(U,0,imax+1,0,jmax+1);
	free_matrix(V,0,imax+1,0,jmax+1);
	free_matrix(P,0,imax+1,0,jmax+1);
	free_matrix(K,0,imax+1,0,jmax+1);
	free_matrix(E,0,imax+1,0,jmax+1);
	
	free_matrix(F,0,imax,0,jmax);
	free_matrix(G,0,imax,0,jmax);
	free_matrix(RS,0,imax,0,jmax);

	free_imatrix(Flag,0,imax+1,0,jmax+1);

	return 0;
}
コード例 #12
0
ファイル: edible.c プロジェクト: acralfs/fricas
int
main(int argc, char *argv[])
{
  fd_set rfds;                  /* the structure for the select call */
  int code;                    /* return code from system calls */
  char out_buff[MAXLINE];       /* from child and stdin */
  int out_flag[MAXLINE] ; /* initialize the output flags */
  char *program;          /* a string to hold the child program invocation */
  char **pargs = 0;             /* holds parts of the command line */
  int not_command = 1;          /* a flag while parsing the command line */



  /* try to get a pseudoterminal to play with */
  if (ptyopen(&contNum, &serverNum, controllerPath, serverPath) == -1) {
    perror("ptyopen failed");
    exit(-1);
  }

  /* call the routine that handles signals */
  catch_signals();

  /* parse the command line arguments - as with the aixterm  the command
     argument -e should be last on the line. */

  while(*++argv && not_command) {
    if(!strcmp(*argv, "-f"))
      load_wct_file(*++argv);
    else if(!strcmp(*argv, "-e")) {
      not_command = 0;
      pargs = ++argv;
    }
    else {
      fprintf(stderr, "usage: clef [-f fname] -e command\n");
      exit(-1);
    }
  }
  skim_wct();

#ifdef log
  sprintf(logpath, "/tmp/cleflog%d", getpid());
  logfd = open(logpath, O_CREAT | O_RDWR, 0666);
#endif

  /* get the original termio settings, so the child has them */

  if(tcgetattr(0,&childbuf) == -1) {
    perror("clef trying to get the initial terminal settings");
    exit(-1);
  }

  /* start the child process */

  child_pid = fork();
  switch(child_pid) {
  case -1 :
    perror("clef can't create a new process");
    exit(-1);
  case 0:
    /* CHILD */
    /* Dissasociate form my parents group so all my child processes
       look at my terminal as the controlling terminal for the group */
    setsid();

    serverNum = open(serverPath,O_RDWR);
    if (serverNum == -1) perror("open serverPath failed");

    /* since I am the child, I can close ptc, and dup pts for all it
       standard descriptors */
    if (dup2(serverNum, 0) == -1) perror("dup2 0 failed");
    if (dup2(serverNum, 1) == -1) perror("dup2 1 failed");
    if (dup2(serverNum, 2) == -1) perror("dup2 2 failed");
    if( (dup2(serverNum, 0) == -1)  ||
        (dup2(serverNum, 1) == -1) ||
        (dup2(serverNum, 2) == -1)  ) {
      perror("clef trying to dup2");
      exit(-1);
    }

    /* since they have been duped, close them */
    close(serverNum);
    close(contNum);


    /* To make sure everything is nice, set off enhedit */
    /*    childbuf.c_line = 0; */

    /* reconfigure the child's terminal get echoing */
    if(tcsetattr(0, TCSAFLUSH, &childbuf) == -1) {
      perror("clef child trying to set child's terminal");
      exit(-1);
    }

    /* fire up the child's process */
    if(pargs){
      execvp( pargs[0], pargs);
      perror("clef trying to execvp its argument");
      fprintf(stderr, "Process --> %s\n", pargs[0]);
    }
    else{
      program = getenv("SHELL");
      if (!program)
        program = strdup("/bin/sh");
      else
        program = strdup (program);
      execlp( program,program, 0);
      perror("clef trying to execlp the default child");
      fprintf(stderr, "Process --> %s\n", program);
    }
    exit(-1);
    break;
    /* end switch */
  }
  /* PARENT */
  /* Since I am the parent, I should start to initialize some stuff.
     I have to close the pts side for it to work properly */

  close(serverNum);
  ppid = getppid();

  /* Iinitialize some stuff for the reading and writing */
  init_flag(out_flag, MAXLINE);
  define_function_keys();
  init_reader();
  PTY = 1;
  init_parent();

  /* Here is the main loop, it simply starts reading characters from
     the std input, and from the child. */

  while(1)  {           /* loop forever */

    /* use select to see who has stuff waiting for me to handle */
    /* set file descriptors for ptc and stdin */
    FD_ZERO(&rfds);
    FD_SET(contNum,&rfds);
    FD_SET(0,&rfds);
    set_function_chars();
#ifdef log
    {
      char modepath[30];
      sprintf(modepath, "\nMODE = %d\n", MODE);
      write(logfd, modepath, strlen(modepath));
    }
#endif
#ifdef logterm
    {
      struct termio ptermio;
      char pbuff[1024];
      tcgetattr(contNum, &ptermio);
      sprintf(pbuff, "child's settings: Lflag = %d, Oflag = %d, Iflag = %d\n",
              ptermio.c_lflag, ptermio.c_oflag, ptermio.c_iflag);
      write(logfd, pbuff, strlen(pbuff));
    }
#endif

    code = select(FD_SETSIZE,(void *) &rfds, NULL, NULL, NULL);
    for(; code < 0 ;) {
      if(errno == EINTR) {
        check_flip();
        code = select(FD_SETSIZE,(void *) &rfds, NULL, NULL, NULL);
      }
      else  {
        perror("clef select failure");
        exit(-1);
      }
    }

    /* reading from the child **/
    if( FD_ISSET(contNum,&rfds)) {
      if( (num_read = read(contNum, out_buff, MAXLINE)) == -1) {
        num_read = 0;
      }
#ifdef log
      write(logfd, "OUT<<<<<", strlen("OUT<<<<<"));
      write(logfd, out_buff, num_read);
#endif
      if(num_read > 0) {
        /* now do the printing to the screen */
        if(MODE!= CLEFRAW) {
          back_up(buff_pntr);
          write(1,out_buff, num_read);
          print_whole_buff();    /* reprint the input buffer */
        }
        else write(1,out_buff, num_read);
      }
    } /* done the child stuff */
    /* I should read from std input */
    else  {
      if(FD_ISSET(0,&rfds)) {
        num_read = read(0, in_buff, MAXLINE);
#ifdef log
        write(logfd, "IN<<<<<", strlen("IN<<<<<"));
        write(logfd, in_buff, num_read);
#endif
        check_flip();
        if(MODE == CLEFRAW )
          write(contNum, in_buff, num_read);
        else
          do_reading();
      }
    }
  }
}
コード例 #13
0
ファイル: msearch.c プロジェクト: axelrod9/ladr
/* PUBLIC */
void init_mace_options(Mace_options opt)
{
  opt->domain_size       = init_parm("domain_size",      0,       0, INT_MAX);
  opt->start_size        = init_parm("start_size",       2,       2, INT_MAX);
  opt->end_size          = init_parm("end_size",        -1,      -1, INT_MAX);
  opt->iterate_up_to     = init_parm("iterate_up_to",   -1,      -1, INT_MAX);
  opt->max_models        = init_parm("max_models",       1,      -1, INT_MAX);
  opt->max_seconds       = init_parm("max_seconds",     -1,      -1, INT_MAX);
  opt->max_seconds_per   = init_parm("max_seconds_per", -1,      -1, INT_MAX);
  opt->selection_order   = init_parm("selection_order",  2,       0, 2);
  opt->selection_measure = init_parm("selection_measure",4,       0, 4);
  opt->increment         = init_parm("increment",        1,       1, INT_MAX);
  opt->max_megs          = init_parm("max_megs",       500,      -1, INT_MAX);
  opt->report_stderr     = init_parm("report_stderr",   -1,      -1, INT_MAX);

  opt->print_models           = init_flag("print_models",           TRUE);
  opt->print_models_tabular   = init_flag("print_models_tabular",   FALSE);
  opt->lnh                    = init_flag("lnh",                    TRUE);
  opt->trace                  = init_flag("trace",                  FALSE);
  opt->negprop                = init_flag("negprop",                TRUE);
  opt->neg_assign             = init_flag("neg_assign",             TRUE);
  opt->neg_assign_near        = init_flag("neg_assign_near",        TRUE);
  opt->neg_elim               = init_flag("neg_elim",               TRUE);
  opt->neg_elim_near          = init_flag("neg_elim_near",          TRUE);
  opt->verbose                = init_flag("verbose",                FALSE);
  opt->integer_ring           = init_flag("integer_ring",           FALSE);
  opt->order_domain           = init_flag("order_domain",           FALSE);
  opt->arithmetic             = init_flag("arithmetic",             FALSE);
  opt->iterate_primes         = init_flag("iterate_primes",         FALSE);
  opt->iterate_nonprimes      = init_flag("iterate_nonprimes",      FALSE);
  opt->skolems_last           = init_flag("skolems_last",           FALSE);
  opt->return_models          = init_flag("return_models",          FALSE);

  opt->iterate = init_stringparm("iterate", 5,
				 "all",
				 "evens",
				 "odds",
				 "primes",
				 "nonprimes");

  /* dependencies */

  flag_flag_dependency(opt->print_models_tabular,TRUE,opt->print_models,FALSE);
  flag_flag_dependency(opt->print_models,TRUE,opt->print_models_tabular,FALSE);

  flag_flag_dependency(opt->iterate_primes, TRUE,opt->iterate_nonprimes,FALSE);
  flag_flag_dependency(opt->iterate_nonprimes, TRUE,opt->iterate_primes,FALSE);

  parm_parm_dependency(opt->domain_size, opt->start_size, 1, TRUE);
  parm_parm_dependency(opt->domain_size, opt->end_size, 1, TRUE);

  parm_parm_dependency(opt->iterate_up_to, opt->end_size, 1, TRUE);

  flag_stringparm_dependency(opt->iterate_primes,TRUE,opt->iterate,"primes");
  flag_stringparm_dependency(opt->iterate_nonprimes,TRUE,opt->iterate,"nonprimes");

  flag_flag_dependency(opt->integer_ring, TRUE, opt->lnh, FALSE);
  flag_flag_dependency(opt->order_domain, TRUE, opt->lnh, FALSE);
  flag_flag_dependency(opt->arithmetic, TRUE, opt->lnh, FALSE);

  flag_parm_dependency(opt->arithmetic,TRUE,opt->selection_order,0);

}  /* init_mace_options */
コード例 #14
0
ファイル: check_precis.c プロジェクト: Daykz/ft_printf
void			init(t_flag *flag, t_precis *nb)
{
	init_precis(nb);
	init_flag(flag);
}
コード例 #15
0
ファイル: PlmLine.cpp プロジェクト: deNULL/seman
bool CPlmLine :: LoadPlmLineFromString (string LineStr, bool bStartLine, const CAgramtab* pRusGramTab) 
{
	m_bToDelete = false;
	m_bQuoteMarks = false;
	
	if (!bStartLine)
	{
		m_bHomonym = (LineStr[0] == ' ');

		Trim(LineStr);
		SetWord(::GetWordForm(LineStr) );
	}
	else
	{
		m_bHomonym = false;
		SetWord( "" );

	};


	long i = 1; // the first char can be a space (if this line contains a homonym)
	for (; i < LineStr.length(); i++)
		if (!isspace((BYTE) LineStr[i]) == 0)
			break;

	if (sscanf (LineStr.c_str()+i, "%i %i", &m_FilePosition, &m_TokenLengthInFile) != 2)
		return false;

	// pass all numbers
	for (; i < LineStr.length(); i++)
		 if (		(isdigit((BYTE) LineStr[i]) == 0)
				&&	(isspace((BYTE) LineStr[i]) == 0)
				&&	(((BYTE)LineStr[i]) != '-')
			)
			break;

	int MorphSignPos = GetMorphSignPosition(LineStr.c_str()+i);
	if (MorphSignPos == -1)
		MorphSignPos = LineStr.length();
	else
		MorphSignPos += i; // make MorphSignPos an absolute offset in LineStr

	m_GraphDescr = LineStr.substr (i, MorphSignPos - i);
	/* вставим пробел в начало, потому что часто ищут графету с пробелом в начале,
	например, " ЛЕ"*/
	m_GraphDescr = " " + m_GraphDescr;

	if (MorphSignPos != LineStr.length())
	{
		StringTokenizer tok(LineStr.c_str()+MorphSignPos," ");

		if (!tok() ) return false;
		string MorphSign  = tok.val();
		if (MorphSign.length() != 3) return false;
		m_MorphSign = MorphSign[0];
		m_CommonGramCode = MorphSign.substr(1);

		
		if (!tok() ) return false;
		m_Lemma = tok.val();
		if (m_Lemma.empty())  return false;
		
		if (!tok() ) return false;
		SetGramCodes ( tok.val(), pRusGramTab);

		if (!tok() ) return false;
		m_ParadigmId = tok.val();

		if (!tok() ) return false;
		m_HomoWeight = tok.val();

	};

	m_TokenType = OTHER_TOKEN_TYPE;
	for (int k=(int)RLE; k < OTHER_TOKEN_TYPE; k++)
		if (init_flag (m_GraphDescr, TokenTypeToString((MainTokenTypeEnum)k).c_str() ))
		{
            m_TokenType = (MainTokenTypeEnum)k;
			break;
		};

	if (init_flag (m_GraphDescr, "Aa"))
		m_Register = UpLow;
	else
	if (init_flag (m_GraphDescr, "AA"))
		m_Register = UpUp;
	else
	{
		init_flag (m_GraphDescr, "aa");
		m_Register = LowLow;		
	};

	m_bFirstUpperAlpha =  (m_Register == UpUp) || (m_Register == UpLow);

	m_bFI1 = init_flag (m_GraphDescr, "FAM1");
	m_bFI2 = init_flag (m_GraphDescr, "FAM2");
	m_bName = init_flag (m_GraphDescr, "NAM?");
	m_bSent2 = init_flag (m_GraphDescr, "SENT_END");
	int hyphen_occur = m_Word.find("-");
	m_bHyphenWord = (hyphen_occur != string::npos) && ( (m_TokenType == RLE) ||(m_TokenType == LLE));

	m_bOborot1 = (m_GraphDescr.find("EXPR1") != string::npos);
	m_bOborot2 = (m_GraphDescr.find("EXPR2") != string::npos);
	bool bRomanNumber = is_roman_number(m_Word.c_str(), m_Word.length());
	
	if ((hyphen_occur != string::npos) && (hyphen_occur!=0))
	{
		// "Павла I-го" 
		// "I-го" - одно слово
		bRomanNumber = is_roman_number(m_Word.c_str(), hyphen_occur);
	};
	if (bRomanNumber)
	{
		m_TokenType = ROMAN_NUM;
		m_CommonGramCode = "";
		m_MorphSign = 0;
		m_ParadigmId = "";
	};
	Trim(m_GraphDescr);
	return true;

};
コード例 #16
0
ファイル: test_boundary_main.c プロジェクト: EvaBr/CFD-Lab
int main(int argn, char** args){
 	if (argn !=2 ) {
        	printf("When running the simulation, please give a valid scenario file name!\n");
        	return 1;
        }
	//set the scenario
	char *filename = NULL;
	filename = args[1];

	//initialize variables
	double t = 0; /*time start*/
	int it, n = 0; /*iteration and time step counter*/
	double res; /*residual for SOR*/
		/*arrays*/
	double **U, **V, **P;
	double **RS, **F, **G;
	int **Flag; //additional data structure for arbitrary geometry
		/*those to be read in from the input file*/
	double Re, UI, VI, PI, GX, GY, t_end, xlength, ylength, dt, dx, dy, alpha, omg, tau, eps, dt_value;
	int  imax, jmax, itermax;

	double presLeft, presRight, presDelta; //for pressure stuff
	int wl, wr, wt, wb;
	char problem[32];
	double vel; //in case of a given inflow or wall velocity

	//read the parameters, using problem.dat, including wl, wr, wt, wb
	read_parameters(filename, &Re, &UI, &VI, &PI, &GX, &GY, &t_end, &xlength, &ylength, &dt, &dx, &dy, &imax,
			&jmax, &alpha, &omg, &tau, &itermax, &eps, &dt_value, &wl, &wr, &wt, &wb, problem, &presLeft, &presRight, &presDelta, &vel);

	int pics = dt_value/dt; //just a helping variable for outputing vtk


	//allocate memory, including Flag
	U = matrix(0, imax+1, 0, jmax+1);
	V = matrix(0, imax+1, 0, jmax+1);
	P = matrix(0, imax+1, 0, jmax+1);
	RS = matrix(1, imax, 1, jmax);
	F = matrix(0, imax, 1, jmax);
	G = matrix(1, imax, 0, jmax);
	Flag = imatrix(0, imax+1, 0, jmax+1); // or Flag = imatrix(1, imax, 1, jmax);

	int kmax = 20; //test no slip boundary value function
	double ***U3d  = (double ***) malloc((size_t)((imax+1)*(jmax+1)*(kmax+1) * sizeof(double*)) ); //test no slip boundary value function
	double ***V3d  = (double ***) malloc((size_t)((imax+1)*(jmax+1)*(kmax+1) * sizeof(double*)) ); //test no slip boundary value function
	double ***W3d  = (double ***) malloc((size_t)((imax+1)*(jmax+1)*(kmax+1) * sizeof(double*)) ); //test no slip boundary value function
	int ***Flag3d  = (int ***) malloc((size_t)((imax+1)*(jmax+1)*(kmax+1) * sizeof(int*)) ); //test no slip boundary value function

	//initialisation, including **Flag
	init_flag(problem, imax, jmax, presDelta, Flag);
	init_uvp(UI, VI, PI, imax, jmax, U, V, P, problem);

	//going through all time steps
	while(t < t_end){
		//adaptive time stepping
		calculate_dt(Re, tau, &dt, dx, dy, imax, jmax, U, V);
		
		//setting bound.values
		boundaryvalues(imax, jmax, U, V, P, wl, wr, wt, wb, F, G, problem, Flag, vel); //including P, wl, wr, wt, wb, F, G, problem

                //test no slip boundary value function
                for(int i=1; i<=imax; i++){
                        for(int j=1; j<=jmax; j++){
                                for(int k=1; k<=kmax; k++){
                                        boundaryvalues_no_slip(i, j, k, U3d, V3d, W3d, Flag3d); //test no slip boundary value function
                                }
                        }
		}
		
		//computing F, G and right hand side of pressue eq.
		calculate_fg(Re, GX, GY, alpha, dt, dx, dy, imax, jmax, U, V, F, G, Flag);
		calculate_rs(dt, dx, dy, imax, jmax, F, G, RS);
		
		//iteration counter
		it = 0;
		
		do{
			//
			//perform SOR iteration, at same time set bound.values for P and new residual value
			sor(omg, dx, dy, imax, jmax, P, RS, &res, Flag, presLeft, presRight);

			it++;
		}while(it<itermax && res>eps);
/*		if (it == itermax) {
			printf("Warning: sor while loop exits because it reaches the itermax. res = %f, time =%f\n", res, t);
		}
*/		//calculate U and V of this time step
		calculate_uv(dt, dx, dy, imax, jmax, U, V, F, G, P, Flag);
		
		//indent time and number of time steps
		n++;
		t += dt;
		
		//output of pics for animation
		if (n%pics==0 ){
			write_vtkFile(filename, n, xlength, ylength, imax, jmax, dx, dy, U, V, P);
		}
	}
	//output of U, V, P at the end for visualization
	//write_vtkFile("DrivenCavity", n, xlength, ylength, imax, jmax, dx, dy, U, V, P);

	//free memory
	free_matrix(U, 0, imax+1, 0, jmax+1);
	free_matrix(V, 0, imax+1, 0, jmax+1);
	free_matrix(P, 0, imax+1, 0, jmax+1);
	free_matrix(RS, 1, imax, 1, jmax);
	free_matrix(F, 0, imax, 1, jmax);
	free_matrix(G, 1, imax, 0, jmax);
	free_imatrix(Flag, 0, imax+1, 0, jmax+1);

	free(U3d);
	free(V3d);
	free(W3d);
	free(Flag3d);
	return -1;
}
コード例 #17
0
ファイル: main.c プロジェクト: EvaBr/CFD-Lab
int main(int argn, char** args){
	if (argn !=2 ) {
		printf("When running the simulation, please give a valid geometry file name!\n");
		return 1;
	}


	//set the geometry file
	char *filename = NULL;
	filename = args[1];

	//initialize variables
	double t = 0; /*time start*/
	int it, n = 0; /*iteration and time step counter*/
	double res; /*residual for SOR*/
	/*arrays*/
	double ***U, ***V, ***W, ***P;
	double ***RS, ***F, ***G, ***H;

	int ***Flag; //additional data structure for arbitrary geometry
	int ***S; //additional data structure for arbitrary geometry
	int matrix_output = 0;
	/*those to be read in from the input file*/
	double Re, UI, VI, WI, PI, GX, GY, GZ, t_end, xlength, ylength, zlength, dt, dx, dy, dz, alpha, omg, tau, eps, dt_value;
	int  imax, jmax, kmax, itermax;

	//double presLeft, presRight, presDelta; //for pressure stuff  ...TODO: not allowed for now
	int wl, wr, wt, wb, wf, wh;
	char problemGeometry[200];
	//in case of a given inflow or wall velocity  TODO: will we have this? needs to be a vector?
	double velIN;
	double velMW[3]; // the moving wall velocity is a vector

	struct particleline *Partlines = (struct particleline *)malloc((unsigned)(1 * sizeof(struct particleline)));
	//char szFileName[80];

	//read the parameters, using problem.dat, including wl, wr, wt, wb
	read_parameters(filename, &Re, &UI, &VI, &WI, &PI, &GX, &GY, &GZ, &t_end, &xlength, &ylength, &zlength, &dt, &dx, &dy, &dz, &imax,
			&jmax, &kmax, &alpha, &omg, &tau, &itermax, &eps, &dt_value, &wl, &wr,  &wf, &wh, &wt, &wb, problemGeometry, &velIN, &velMW[0]); //&presLeft, &presRight, &presDelta, &vel);


	//printf("d: %f, %f, %f\n", dx,dy,dz);


	//int pics = dt_value/dt; //just a helping variable for outputing vtk
	double last_output_t = -dt_value;
	//double every = t_end/10; //helping variable. Can be used for displaying info every tenth of the progress during simulation

	//allocate memory, including Flag
	U = matrix2(0, imax+1, 0, jmax+1, 0, kmax+1);
	V = matrix2(0, imax+1, 0, jmax+1, 0, kmax+1);
	W = matrix2(0, imax+1, 0, jmax+1, 0, kmax+1);
	P = matrix2(0, imax+1, 0, jmax+1, 0, kmax+1);
	RS = matrix2(1, imax, 1, jmax, 1, kmax);

	F = matrix2(0, imax, 1, jmax, 1, kmax);
	G = matrix2(1, imax, 0, jmax, 1, kmax);
	H = matrix2(1, imax, 1, jmax, 0, kmax);


	Flag = imatrix2(0, imax+1, 0, jmax+1, 0, kmax+1); // or Flag = imatrix(1, imax, 1, jmax);

	S    = imatrix2(0, imax+1, 0, jmax+1, 0, kmax+1);
	//S = Flag -> adjust C_x Flags in helper.h

	//initialisation, including **Flag


	init_flag(problemGeometry, imax, jmax, kmax, Flag, wl, wr, wf, wh, wt, wb);  //presDelta, Flag);

	init_particles(Flag,dx,dy,dz,imax,jmax,kmax,3,Partlines);

	printf("!!!!!!!!%d\n",binMatch(B_NO,B_N));


	init_uvwp(UI, VI, WI, PI, Flag,imax, jmax, kmax, U, V, W, P, problemGeometry);

	write_particles("particles_init",0, 1, Partlines);

	write_imatrix2("Flag_start.txt",t,Flag, 0, imax, 1, jmax, 1, kmax);
	//write_flag_imatrix("Flag.txt",t,Flag, 0, imax+1, 0, jmax+1, 0, kmax+1);
	write_vtkFile(filename, -1, xlength, ylength, zlength, imax, jmax, kmax, dx, dy, dz, U, V, W, P,Flag);

	//write_vtkFile("init", n, xlength, ylength, zlength, imax, jmax, kmax, dx, dy, dz, U, V, W, P);
	//going through all time steps
	/*
	write_matrix2("P_start.txt",t,P, 0, imax+1, 0, jmax+1, 0, kmax+1);
	write_matrix2("U_start.txt",t,U, 0, imax+1, 0, jmax+1, 0, kmax+1);
	write_matrix2("V_start.txt",t,V, 0, imax+1, 0, jmax+1, 0, kmax+1);
	write_matrix2("W_start.txt",t,W, 0, imax+1, 0, jmax+1, 0, kmax+1);
	*/
	//setting bound.values
	boundaryvalues(imax, jmax, kmax, U, V, W, P, F, G, H, problemGeometry, Flag, velIN, velMW); //including P, wl, wr, wt, wb, F, G, problem
	//    printf("calc bc \n");


	while(t < t_end){
		/*if(t - every >= 0){
      	  	  printf("Calculating time %f ... \n", t);
      	  	  every += t;
    	}*/

		//adaptive time stepping
		calculate_dt(Re, tau, &dt, dx, dy, dz, imax, jmax, kmax, U, V, W);
		//    printf("calc dt \n");

		/*
		mark_cells(Flag,dx,dy,dz,imax,jmax,kmax,1,Partlines);


		set_uvwp_surface(U,V,W,P,Flag,dx,dy,dz,imax,jmax,kmax,GX,GY,GZ,dt,Re);
*/

		//computing F, G, H and right hand side of pressue eq.
		calculate_fgh(Re, GX, GY, GZ, alpha, dt, dx, dy, dz, imax, jmax, kmax, U, V, W, F, G, H, Flag);
		//    printf("calc fgh \n");

		calculate_rs(dt, dx, dy, dz, imax, jmax, kmax, F, G, H, RS,Flag);
		//    printf("calc rs \n");

		//iteration counter
		it = 0;

		//write_matrix2("RS.txt",t,RS, 1, imax, 1, jmax, 1, kmax);
		//write_matrix2("F.txt",t,F, 0, imax, 1, jmax, 1, kmax);
		//write_matrix2("G.txt",t,G, 1, imax, 0, jmax, 1, kmax);
		//write_matrix2("H.txt",t,H, 1, imax, 1, jmax, 0, kmax);
		do{
			// sprintf( szFileName, "P_%d.txt",it );
			//write_matrix2(szFileName,1000+t,P, 0, imax+1, 0, jmax+1, 0, kmax+1);
			//perform SOR iteration, at same time set bound.values for P and new residual value
			sor(omg, dx, dy, dz, imax, jmax, kmax, P, RS, &res, Flag); //, presLeft, presRight);

			it++;
		}while(it<itermax && res>eps);

		/*if (it == itermax) {
	printf("Warning: sor while loop exits because it reaches the itermax. res = %f, time =%f\n", res, t);
		} */

		//write_matrix2("P.txt",t,P, 0, imax+1, 0, jmax+1, 0, kmax+1);
		//calculate U, V and W of this time step
		calculate_uvw(dt, dx, dy, dz, imax, jmax, kmax, U, V, W, F, G, H, P, Flag);
		//write_matrix2("U.txt",t,U, 0, imax+1, 0, jmax+1, 0, kmax+1);
		//write_matrix2("V.txt",t,V, 0, imax+1, 0, jmax+1, 0, kmax+1);
		//write_matrix2("W.txt",t,W, 0, imax+1, 0, jmax+1, 0, kmax+1);

		//    printf("calc uvw \n");


			//sprintf( szFileName, "simulation/%s.%i_debug.vtk", szProblem, timeStepNumber );


		//setting bound.values
		boundaryvalues(imax, jmax, kmax, U, V, W, P, F, G, H, problemGeometry, Flag, velIN, velMW); //including P, wl, wr, wt, wb, F, G, problem

		/*
		set_uvwp_surface(U,V,W,P,Flag,dx,dy,dz,imax,jmax,kmax,GX,GY,GZ,dt,Re);

		printf("advance_particles!\n");
		advance_particles(dx,dy, dz,imax,jmax,kmax, dt,U,V,W,1,Partlines);
*/

		//indent time and number of time steps
		printf("timer\n");
		n++;
		t += dt;

		//output of pics for animation
		if ( t-last_output_t  >= dt_value ){  //n%pics==0 ){
			printf("output\n!");









			write_particles(filename,n, 1, Partlines);
			write_vtkFile(filename, n, xlength, ylength, zlength, imax, jmax, kmax, dx, dy, dz, U, V, W, P,Flag);

			printf("output vtk (%d)\n",n);
			last_output_t = t;
			matrix_output++;
		}
		printf("timestep: %f   - next output: %f   (dt: %f) \n",t,dt_value- (t-last_output_t),dt);
	}

	//output of U, V, P at the end for visualization
	//write_vtkFile("DrivenCavity", n, xlength, ylength, imax, jmax, dx, dy, U, V, P);
	//free memory
	free_matrix2(U, 0, imax+1, 0, jmax+1, 0, kmax+1);
	free_matrix2(V, 0, imax+1, 0, jmax+1, 0, kmax+1);
	free_matrix2(W, 0, imax+1, 0, jmax+1, 0, kmax+1);
	free_matrix2(P, 0, imax+1, 0, jmax+1, 0, kmax+1);
	free_matrix2(RS, 1, imax, 1, jmax, 1, kmax);


	free_matrix2(F, 0, imax, 1, jmax, 1, kmax);
	free_matrix2(G, 1, imax, 0, jmax, 1, kmax);
	free_matrix2(H, 1, imax, 1, jmax,  0, kmax);


	free_imatrix2(Flag, 0, imax+1, 0, jmax+1, 0, kmax+1);
	free_imatrix2(S, 0, imax+1, 0, jmax+1, 0, kmax+1);
	//printf("\n-\n");
	return -1;
}
コード例 #18
0
ファイル: main.c プロジェクト: ludcila/CFD-Lab
int main(int argn, char** args){

	double **U, **V, **P, **F, **G, **RS;
	int **Flag;
	char problem[60];
	char parameters_filename[60];
	char pgm[60];
	char output_dirname[60];
	double Re, UI, VI, PI, GX, GY, t_end, xlength, ylength, dt, dx, dy, alpha, omg, tau, eps, dt_value, dp;
	double res = 0, t = 0, n = 0;
	int imax, jmax, itermax, it;
	int wl, wr, wt, wb;
	int timestepsPerPlotting;
	char old_output_filename[128];
	struct dirent *old_outputfile;
	DIR *output_dir;
	/* Variables for parallel program */
	int iproc, jproc, myrank, il, ir, jb, jt, rank_l, rank_r, rank_b, rank_t, omg_i, omg_j, num_proc;
	double min_dt;
	double *bufSend, *bufRecv;
	double totalTime = 0;
	struct timespec previousTime, currentTime;
	
	MPI_Init(&argn, &args);
	MPI_Comm_size(MPI_COMM_WORLD, &num_proc);

	/* Read name of the problem from the command line arguments */
	if(argn > 1) {
		strcpy(problem, args[1]);
	} else {
		printf("\n=== ERROR: Please provide the name of the problem\n=== e.g. Run ./sim problem_name if there is a problem_name.dat file.\n\n");
		MPI_Finalize();
		return 1;
	}

	/* Generate input filename based on problem name */
	strcpy(parameters_filename, problem);
	strcat(parameters_filename, ".dat");

	/* Read the program configuration file using read_parameters() */
	read_parameters(parameters_filename, pgm, &Re, &UI, &VI, &PI, &GX, &GY, &t_end, &xlength, &ylength, &dt, &dx, &dy, &imax, &jmax, &alpha, &omg, &tau, &itermax, &eps, &dt_value, problem, &dp, &wl, &wr, &wt, &wb, &timestepsPerPlotting, &iproc, &jproc);
	printf("%s\n", pgm);
	
	/* Check if the number of processes is correct */
	if(iproc * jproc != num_proc) {
		printf("\n=== ERROR: Number of processes is incorrect (iproc=%d, jproc=%d, -np=%d) ===\n\n", iproc, jproc, num_proc);
		MPI_Finalize();
		return 1;
	}

	/* Create folder with the name of the problem */
	strcpy(output_dirname, problem);
	strcat(output_dirname, "/");
	strcat(output_dirname, problem);
	mkdir(problem, 0777);
	output_dir = opendir(problem);

	/* Delete existing files in output folder*/
	while((old_outputfile = readdir(output_dir))) {
		sprintf(old_output_filename, "%s/%s", problem, old_outputfile->d_name);
		remove(old_output_filename);
	}
	
	/* Determine subdomain and neighbours for each process */
	init_parallel(iproc, jproc, imax, jmax, &myrank, &il, &ir, &jb, &jt, &rank_l, &rank_r, &rank_b, &rank_t, &omg_i, &omg_j, num_proc);

	/* Set up the matrices (arrays) needed using the matrix() command */
	U = matrix(il-2, ir+1, jb-1, jt+1);
	V = matrix(il-1, ir+1, jb-2, jt+1);
	P = matrix(il-1, ir+1, jb-1, jt+1);
	F = matrix(il-2, ir+1, jb-1, jt+1);
	G = matrix(il-1, ir+1, jb-2, jt+1);
	RS= matrix(il, ir, jb, jt);
	Flag = imatrix(il-1, ir+1, jb-1, jt+1);
	
	/* Assign initial values to u, v, p */
	init_uvp(UI, VI, PI, il, ir, jb, jt, U, V, P);
	
	/* Allocate memory for buffers */
	bufSend = malloc(max(ir-il+3, jt-jb+3) * sizeof(double));
	bufRecv = malloc(max(ir-il+3, jt-jb+3) * sizeof(double));
	
	/* Initialize lower part of the domain with UI = 0 for the flow_over_step problem */
	/* (this code might be moved to somewhere else later) */
	if(strcmp(problem, "flow_over_step") == 0) {
		init_matrix(U, il, ir, jb, min(jmax/2, jt), 0);
	}

	/* Initialization of flag field */
	init_flag(pgm, imax, jmax, il, ir, jb, jt, Flag, dp);
	
	if(myrank == 0) {
		clock_gettime(CLOCK_MONOTONIC, &currentTime);
	}

	while(t <= t_end){
	
		/* Select δt */
		calculate_dt(Re, tau, &dt, dx, dy, il, ir, jb, jt, U, V);
		MPI_Allreduce(&dt, &min_dt, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);

		dt = min_dt;
		
		/* Set boundary values for u and v */
		boundaryvalues(il, ir, jb, jt, imax, jmax, U, V, wl, wr, wt, wb, Flag);
	
		/* Set special boundary values */
		spec_boundary_val(problem, il, ir, jb, jt, imax, jmax, U, V, P, Re, xlength, ylength, dp);

		/* Compute F(n) and G(n) */
		calculate_fg(Re, GX, GY, alpha, dt, dx, dy, il, ir, jb, jt, imax, jmax, U, V, F, G, Flag);
		
		/* Compute the right-hand side rs of the pressure equation */
		calculate_rs(dt, dx, dy, il, ir, jb, jt, imax, jmax, F, G, RS);
		
		/* Perform SOR iterations */
		it = 0;
		res = 1e6;
		while(it < itermax && res > eps){
			sor(omg, dx, dy, dp, il, ir, jb, jt, imax, jmax, rank_l, rank_r, rank_b, rank_t, P, RS, &res, Flag, bufSend, bufRecv);
			it++;
		}
		
		/* Compute u(n+1) and v(n+1) */
		calculate_uv(dt, dx, dy, il, ir, jb, jt, imax, jmax, U, V, F, G, P, Flag);
		
		/* Exchange velocity strips */
		uv_com(U, V, il, ir, jb, jt, rank_l, rank_r, rank_b, rank_t, bufSend, bufRecv);
		
		t = t + dt;
		n++;
		
		/* Generate snapshot for current timestep */
		if((int) n % timestepsPerPlotting == 0) {
			write_vtkFile(output_dirname, myrank, n, xlength, ylength, il, ir, jb, jt, imax, jmax, dx, dy, U, V, P);
		}
		
		/* Print out simulation time and whether the SOR converged */
		if(myrank == 0) {
			/* Print simulation time */
			printf("Time: %.4f", t);
			/* Print runtime */
			previousTime = currentTime;
			clock_gettime(CLOCK_MONOTONIC, &currentTime);
			totalTime += (double)currentTime.tv_sec + 1e-9 * currentTime.tv_nsec - (double)previousTime.tv_sec - 1e-9 * previousTime.tv_nsec;
			printf("\tRuntime: %.3f s (avg runtime/step: %.3f s)", totalTime, totalTime/n);
			if(res > eps) printf("\tDid not converge (res=%f, eps=%f)", res, eps);
			printf("\n");
		}

	}
	
	/* Close the output folder */
	closedir(output_dir);
	
	/* Tell user where to find the output */
	if(myrank == 0) {
		printf("Please find the output in the folder \"%s\".\n", problem);
	}
	
	/* Free allocated memory */
	free_matrix(U, il-2, ir+1, jb-1, jt+1);
	free_matrix(V, il-1, ir+1, jb-2, jt+1);
	free_matrix(P, il-1, ir+1, jb-1, jt+1);
	free_matrix(F, il-2, ir+1, jb-1, jt+1);
	free_matrix(G, il-1, ir+1, jb-2, jt+1);
	free_matrix(RS, il, ir, jb, jt);
	free_imatrix(Flag, il-1, ir+1, jb-1, jt+1);
	free(bufSend);
	free(bufRecv);
	
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Finalize();
	
	return 0;
	
}
コード例 #19
0
ファイル: fnct_key.c プロジェクト: acralfs/fricas
void
handle_function_key(int key,int  chann)
{
    /** this procedure simply adds the string specified by the function key
      to the buffer                                               ****/
    int count, fd;
    int amount = strlen(function_key[key].str);
    int id;
    int save_echo;

    /*** This procedure takes the character at in_buff[num_proc] and adds
      it to the buffer. It first checks to see if we should be inserting
      or overwriting, and then does the appropriate thing      *******/

    switch ((function_key[key]).type) {
      case IMMEDIATE:
        if (INS_MODE) {
            forwardcopy(&buff[curr_pntr + amount],
                        &buff[curr_pntr],
                        buff_pntr - curr_pntr);
            forwardflag_cpy(&buff_flag[curr_pntr + amount],
                            &buff_flag[curr_pntr],
                            buff_pntr - curr_pntr);
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
            }
            ins_print(curr_pntr, amount + 1);
            buff_pntr = buff_pntr + amount;
        }
        else {
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
                myputchar((function_key[key].str)[count]);
            }
        }
        num_proc = num_proc + 6;
        curr_pntr = curr_pntr + amount;
        buff_pntr = buff_pntr + amount;
        send_function_to_child();
        break;
      case DELAYED:
        if (INS_MODE) {
            forwardcopy(&buff[curr_pntr + amount],
                        &buff[curr_pntr],
                        buff_pntr - curr_pntr);
            forwardflag_cpy(&buff_flag[curr_pntr + amount],
                            &buff_flag[curr_pntr],
                            buff_pntr - curr_pntr);
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
            }
            ins_print(curr_pntr, amount + 1);
            buff_pntr = buff_pntr + amount;
        }
        else {
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
                myputchar((function_key[key].str)[count]);
            }
        }
        num_proc = num_proc + 6;
        curr_pntr = curr_pntr + amount;
        buff_pntr = buff_pntr + amount;
        fflush(stdout);
        break;
      case SPECIAL:
        /* fprintf(stderr, "Here I am \n"); */
        if (access(editorfilename, F_OK) < 0) {
            fd = open(editorfilename, O_RDWR | O_CREAT, 0666);
            write(fd, buff, buff_pntr);
            back_up(buff_pntr);
            close(fd);
        }
        else {
            if (buff_pntr > 0) {
                fd = open(editorfilename, O_RDWR | O_TRUNC);
                write(fd, buff, buff_pntr);
                back_up(buff_pntr);
                close(fd);
            }
        }
#if defined(MACOSXplatform) || defined(BSDplatform)
        bsdSignal(SIGCHLD, null_fnct,RestartSystemCalls);
#else
        bsdSignal(SIGCLD, null_fnct,RestartSystemCalls);
#endif
        switch (id = fork()) {
          case -1:
            perror("Special key");
            break;
          case 0:
            execlp((function_key[12]).str,
                   (function_key[12]).str,
                   editorfilename, NULL);
            perror("Returned from exec");
            exit(0);

        }
        while (wait((int *) 0) < 0);
        /** now I should read that file and send all it stuff thru the
                  reader                                            *****/
        fd = open(editorfilename, O_RDWR);
        if (fd == -1) {
            perror("Opening temp file");
            exit(-1);
        }
        num_proc += 6;

        /** reinitialize the buffer  ***/
        init_flag(buff_flag, buff_pntr);
        init_buff(buff, buff_pntr);
        /**  reinitialize my buffer pointers **/
        buff_pntr = curr_pntr = 0;
        /** reset the ring pointer **/
        current = NULL;
        save_echo = ECHOIT;
        ECHOIT = 0;
        while ((num_read = read(fd, in_buff, MAXLINE))) {
            do_reading();
        }
        close(fd);
        break;
    }
    return;

}