Exemplo n.º 1
0
int main() {
    int n, q;
    geti(n, q);
    for(int i = 1; i < n; i++) {
        int u, v;
        geti(u, v);
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    init(n);
    dfs(0, -1);
    HLD(0, -1);

    while(q--) {
        int type, x;
        geti(type, x);
        x--;
        if(type == 0) {
            updateTree(x);
        } else {
            printf("%d\n", queryTree(x));
        }
    }
}
Exemplo n.º 2
0
int printmsg( int msgtype, int msgnum )
{
   char lnout[200], msg2[128];
   int l1, l2, l, error, cflag, msglen, count, termfg ;
   char *msg ;
   error = 0 ;
   if ( msgtype == 0 ) {
      sprintf( msg2, "cyc %d %d %d",
               cyc[msgnum].c1, cyc[msgnum].c2, cyc[msgnum].dc ) ;
      ctlmsg(msg2) ;
      msg    = cyc[msgnum].msg ;
      msglen = cyc[msgnum].msglen ;
   }
   if ( msgtype == 1 ) {
      sprintf( msg2, "do %e %e %e",
               fq[msgnum].t1, fq[msgnum].t2, fq[msgnum].dt ) ;
      ctlmsg(msg2) ;
      msg    = fq[msgnum].msg ;
      msglen = fq[msgnum].msglen ;
   }
   if ( msgtype == 2 ) {
      sprintf( msg2, "timeplot %e %e %e",
               fq[msgnum].t1, fq[msgnum].t2, fq[msgnum].dt ) ;
      ctlmsg(msg2) ;
      msg    = fq[msgnum].msg ;
      msglen = fq[msgnum].msglen;
   }
   if ( msgtype == 4 ) {
      error = conditionals_show(msgnum, &msg, &msglen);
      if (error != 0) return(-1);
   }
   msglen -= 17 ;
   if ( lfchk() == 1 ) {
      l1 =   1 ;
      l2 = 300 ;
   } else {
      l1 = geti(&cflag) ;
      l2 = geti(&cflag) ;
   }
   if ( l1 <   1 )  l1 =   1 ;
   if ( l2 > 300 )  l2 = 300 ;
   count  = 0 ;
   termfg = 0 ;
   for ( l = 1 ; l < l1 ; l++ ) {
      termfg = lnadv(lnout,msg,msglen,&count) ;
      if (termfg) {
         break ;
      }
   }
   for ( l = l1 ; l <= l2 ; l++ ) {
      termfg = lnadv(lnout,msg,msglen,&count) ;
      if (termfg) {
         break ;
      } else {
        sprintf(msg2,"%d %s",l,lnout) ;
        ctlmsg(msg2);
      }
   }
   return(error) ;
}
Exemplo n.º 3
0
int main()
{
    geti(V); geti(M);
    int cnt = 0;
    while (M--){
        int a, b;
        scanf("%d%d", &a, &b);
        if (a > 0 && b > 0 ){
            addEdge(a + V, b);
            addEdge(b + V, a);

        }
        else if (a > 0 && b < 0){
            b = -b;
            addEdge(a + V, b + V);
            addEdge(b , a);
        }
        else if (a < 0 && b > 0){
            a = -a;            
            addEdge(a, b);
            addEdge(b + V, a + V);

    
        }
        else{
            a = -a; b = -b;
            addEdge(a, b + V);
            addEdge(b, a + V);

        }
    }
    
    memset(vis, false, sizeof(vis));
    for (int i = 1; i <= 2*V; i++){
        if (!vis[i]) dfs(i);
    }

    memset(vis, false, sizeof(vis));
    int k = 0;
    for (int i = vs.size()-1; i >= 0 ; i--){
        if (!vis[vs[i]]) rdfs(vs[i],k++);
    }
    
    for (int i = 1; i <= V; i++){
        if (cmp[i] == cmp[V + i]){
            printf("0\n");
            return 0;
        }
    }
    printf("1\n");

    for (int i = 1; i <= V; i++){
        if (cmp[i] > cmp[V + i]){
            printf("1 ");
        }
        else printf("0 ");
    }
}
Exemplo n.º 4
0
void CameraColorSampler::initValues() {
    ps3eye.setGain( getf("gain") );
	ps3eye.setShutter( getf("shutter") );
	ps3eye.setGamma( getf("gamma") );
	ps3eye.setBrightness( getf("brightness") );
	ps3eye.setContrast( getf("contrast") );
	ps3eye.setHue( getf("hue") );
	ps3eye.setFlicker( geti("flicker") );
	ps3eye.setWhiteBalance( geti("white_balance") );
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: glaydston/ed
void filter( int op, struct tlist *l)
{
    filter_pass = 1;
    int i, num;
    do
    {
        //verifica opção selecionada pelo usuario.
        if(op == 1)
        {
            cabecalho("INSERIR");
            if(l->last == MAX)
            {
                printf("\t\t# ERRO: Lista cheia! [ENTER]");
                getche();
                break;
            }
            else
            {
                printf("\t\tDIGITE UM NUMERO: ");
                geti(&num);
                i = search(num, l);
                if(i != -1)
                {
                    printf("\n\t\t# NUMERO JA ESTA NA LISTA! [ENTER]");
                    getche();
                }
                else add(num, l);
            }
        }
        else
        {
            cabecalho("REMOVER");
            printf("\t\tDIGITE O NUMERO: ");
            geti(&num);
            i = search(num, l);
            if(i == -1)
            {
                printf("\n\t\t# NUMERO NAO ENCONTRADO! [ENTER]");
                getche();
            }
            else retire(i, l);
        }
        printf("\n\n\t\t# DESEJA CONTINUAR? [1] SIM [9] NAO");
        printf("\n\t\t# OPCAO: ");
        geti(&op);

    }
    while(op == 1);

}
Exemplo n.º 6
0
static
void
test21(void)
{
	tprintf("Enter random seed: ");
	stresstest(geti(), true);
}
Exemplo n.º 7
0
int write_pipe(){
  //printf("write_pipe not yet implemented\n");
  char buf[1024];
  int fd, nbytes;
  int n = 0;

  printf("enter fd to write to: ");
  fd = geti();

  printf("enter text to write: ");
  bzero(buf, 1024);
  gets(buf);

  nbytes = strlen(buf);
  
  printf("fd=%d nbytes=%d : %s\n", fd, nbytes, buf);
  n = syscall(12,fd, buf, nbytes);

  if(n>=0){
    printf("\nback to Umode, wrote %d bytes to pipe\n", n);

  }else{
    printf("write pipe failed\n");
  }


}
Exemplo n.º 8
0
int
main(int argc, char *argv[])
{
	int i, tn, menu=1;

	if (argc > 1) {
		for (i=1; i<argc; i++) {
			dotest(atoi(argv[i]));
		}
		return 0;
	}

	while (1) {
		if (menu) {
			for (i=0; tests[i].num>=0; i++) {
				printf("  %2d  %s\n", tests[i].num, 
				       tests[i].desc);
			}
			menu = 0;
		}
		printf("malloctest: ");
		tn = geti();
		if (tn < 0) {
			break;
		}

		if (dotest(tn)) {
			menu = 1;
		}
	}

	return 0;
}
Exemplo n.º 9
0
static
void
test18(void)
{
	tprintf("Enter random seed: ");
	stresstest(geti(), false);
}
Exemplo n.º 10
0
INT  MPD_CCIT_T6::get_plage_gray(INT a0,bool last)
{
     INT l =  get_length_gray();
     INT a1 = last ? (a0-l) : (a0+l);
     if (last)
        ElSwap(a0,a1);

     if (_vals)
         for (INT a=a0 ; a<a1 ; a++)
             _vals[a] = geti(_nbb);
     else
         for (INT a=a0 ; a<a1 ; a++)
             geti(_nbb);

     return a1;
}
Exemplo n.º 11
0
int close_pipe(){
  //printf("close_pipe not yet implemented\n");
  int fd;
  printf("fd to close: ");
  fd = geti();

  syscall(13,fd,0);
}
Exemplo n.º 12
0
int main(){

	int I;
	scanf("%d%d%d",&n,&m,&p);
	I= geti();
	printf("%d\n",I);
	return 0;
}
Exemplo n.º 13
0
//calls exit in int.c using syscall
int exit()
{
   int exitValue;
   printf("enter an exitValue (0-9): ");
   exitValue = geti();
   printf("exitvalue=%d\n", exitValue);
   printf("enter kernel to die with exitValue=%d\n", exitValue);
   return syscall(6,exitValue,0);
}
Exemplo n.º 14
0
int exit()
{
	int exitValue;
	printf("enter an exitValue: ");
	exitValue = geti();
	printf("exitvalue=%d\n", exitValue);
	printf("enter kernel to die with exitValue=%d\n", exitValue);
	_exit(exitValue);
}
Exemplo n.º 15
0
static void printe(const char *msg){
   scrollok(winmsg, FALSE);
   cbreak();
   refi();
   wprintw(winses, "%s: %m\n", msg);
   wprintw(winses, "Exiting...");
   refo();
   geti();
   endwin();
   exit(EXIT_FAILURE);
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: glaydston/ed
void menu(int *op)
{
    cabecalho("MENU PRINCIPAL");
    printf("\t\t[1] INSERIR LISTA\n");
    printf("\t\t[2] RETIRAR LISTA\n");
    printf("\t\t[3] VERIFICAR NUMERO\n");
    printf("\t\t[4] IMPRIMIR LISTA\n");
    printf("\t\t[9] SAIR\n\n");
    printf("\t\t# OPCAO: ");
    geti(op);

}
Exemplo n.º 17
0
int do_exit()
{
  int exitValue;
  if (running->pid == 1 && nproc > 2){
      printf("other killMods still exist, P1 can't die yet !%c\n",007);
      return -1;
  }
  printf("enter an exitValue : ");
  exitValue = geti();
  printf("\n");
  kexit(exitValue);
}
Exemplo n.º 18
0
int step( void )
{
   int ncycle, cflag ;
   double ntime ;
   ncycle = geti(&cflag) ;
   ntime  = getf(&cflag) ;
   signal(SIGINT,setirup) ;
   xirs(ncycle,ntime) ;
   signal(SIGINT,SIG_DFL) ;
   printtc() ;
   return(0);
}
Exemplo n.º 19
0
static
void
test7(void)
{
	unsigned long seed;

	printf("Beginning malloc test 7\n");

	printf("Enter random seed: ");
	seed = geti();

	test567(7, seed);
}
Exemplo n.º 20
0
int read_pipe(){
  //printf("read_pipe not yet implemented\n");
  char buf[1024];
  int fd, nbytes;
  int n = 0;

  printf("enter fd to read: ");
  fd = geti();

  printf("enter nbytes to read: ");
  nbytes = geti();
  bzero(buf, 1024);
  n = syscall(11, fd, buf, nbytes);

  if(n >=0){
    printf("%d bytes read from.\n", n);
    printf("content read: %s\n", buf);
  }else{
    printf("read pipe failed in kernel\n");
  }

}
Exemplo n.º 21
0
int OpacTypesIn_Kr( int number, int form )
{
   char *me = "OpacTypesIn_Kr";
   char msg[128] ;
   int error, cflag, n, i, ir, iopac ;
   error = 0 ;
   ir    = current_region ;
   iopac = current_eos ;
   if ( reg[ir].opacityGroup[iopac].rosTable.ndata > 0 ) {
         FREEMEM(reg[ir].opacityGroup[iopac].rosTable.data) ;
   }
   reg[ir].opacityGroup[iopac].rosTable.number = number ;
   reg[ir].opacityGroup[iopac].rosTable.form   = form   ;
   reg[ir].opacityGroup[iopac].rosTable.type   = _Form_ ;
        if ( form == 0 )  { n = geti(&cflag) ; }
   else if ( form == 1 )    n = 1 ;
   else if ( form == 2 )    n = 0 ;
   else if ( form == 3 )    n = 1 ;
   else if ( form == 4 )    n = 0 ;
   else if ( form == 5 )    n = 0 ;
   else if ( form == 6 )    n = 3 ;
   else if ( form == 7 )    n = 3 ;
   else if ( form == 8 )    n = 1 ;
   else if ( form == 9 )    n = 8 ;
   else {
      error = 1 ;
      sprintf( msg,
               "Rosseland opacity form %d not allowed or currently supported.",
               form ) ;
      ctlnotice(me,msg) ;
      return(error) ;
   }
   reg[ir].opacityGroup[iopac].rosTable.ndata = n ;
   if ( (n > 0) && (error == 0) ) {
      reg[ir].opacityGroup[iopac].rosTable.data = MALLOT(double, n) ;
      for ( i = 0 ; i < n ; i++ ) {
         reg[ir].opacityGroup[iopac].rosTable.data[i] = getf(&cflag) ;
         if (cflag) {
            error = 1 ;
            sprintf( msg,
            "Rosseland opacity %d, form %d, should have %d entries not %d.",
                     number, form, n, i ) ;
            ctlwarning(me,msg) ;
            return(error) ;
         }
      }
   }
Exemplo n.º 22
0
Arquivo: main.c Projeto: glaydston/ed
void pesquisar(struct tlist *l)
{
    int num, j;
    cabecalho("PESQUISA");
    if(filter_pass)
    {
        printf("\t\tDIGITE O NUMERO: ");
        geti(&num);
        j = search(num, l);
        if(j != -1)
            printf("\n\n\t\tITEM: %d - POSICAO %d. [ENTER]", l->item[j], j);
        else
            printf("\n\t\t# ERRO: NUMERO NAO ENCONTRADO! [ENTER]");
    }
    else  printf("\n\n\t\t# INSERIR DADOS! [ENTER]");
    getche();
}
Exemplo n.º 23
0
int main() {

	AugmentedMatrix Aug;
	int N; geti(N);
	rep(i,N) rep(j,N) scanf("%lf",&Aug.mat[i][j]);
	for(int i=N;i<2*N;i++) Aug.mat[i-N][i] = 1;
	
	AugmentedMatrix res = GaussianElimination(N, Aug);
	
	// Print inversion of A
	for(int i=0;i<N;i++){
		for(int j=N;j<2*N;j++) printf("%f ",res.mat[i][j]);
		printf("\n");
	}
	

	return 0;
}
Exemplo n.º 24
0
int LuaArgs::geti(int idx, const char *key, int Default)
{
	int ret;
	if (tbl > 0 && lua_checkstack(L, 1)) {
		lua_getfield(L, tbl, key);
		bool success = lua_isnumber(L, -1) != 0;
		if (!success && idx > 0) {
			lua_pop(L, 1);
			lua_pushinteger(L, idx);
			lua_gettable(L, tbl);
			success = lua_isnumber(L, -1) != 0;
		}
		ret = success? lua_tointeger(L, -1) : Default;
		lua_pop(L, 1);
	} else {
		ret = geti(idx, Default);
	}
	return ret;
}
Exemplo n.º 25
0
int main(int argc, char *argv[]){
   int sfd, ch;
   struct sockaddr_in addr;

   ch = getopt(argc, argv, "s:c:
   initwin();

   prints("Creating socket...\n");
   sfd = socket(AF_INET, SOCK_DGRAM, UDP_PROTO);
   if(sfd == -1)
      printe("Socket");
   else
      prints("Socket created\n");

   while(1){
      puto(geti());
   }

   getch();
   endwin();

   return 0;
}
Exemplo n.º 26
0
int
main(int argc, char *argv[])
{
	int i, tn;
	unsigned j;
	bool menu = true;

	setup();

	if (argc > 1) {
		for (i=1; i<argc; i++) {
			dotest(atoi(argv[i]));
		}
		return 0;
	}

	while (1) {
		if (menu) {
			for (j=0; j<numtests; j++) {
				tprintf("  %2d  %s\n", tests[j].num,
				       tests[j].desc);
			}
			menu = false;
		}
		tprintf("sbrktest: ");
		tn = geti();
		if (tn < 0) {
			break;
		}

		if (dotest(tn)) {
			menu = true;
		}
	}

	return 0;
}
Exemplo n.º 27
0
/*------------------------------------------------------*/
int load_PPM_Image(struct PPM_Image * ppmImage, char * fileName)
{ /*----------------------*/
  /* VARIABLE DECLARATION */
  /*----------------------*/

  // to read from file
  char c; bool raw;

  // for loop variables
  int row, col; enum Color color;

  // open the file forreading
  FILE * imageFilePointer = fileOpener(READ, fileName);
  if(imageFilePointer == NULL)
  { fclose(imageFilePointer);
    return - 1;
  }

  // make sure the first char is P
  if(fgetc(imageFilePointer) != 'P')
  { fclose(imageFilePointer);
    return - 1;
  }

  // make sure the second char is either a 3 or 6
  c = fgetc(imageFilePointer);
  if(c != '3' && c != '6')
  { fclose(imageFilePointer);
    return - 1;
  }

  if(c == '6') raw = true; else raw = false;

  // get the width, height and max gray value of the image
  ppmImage->width = geti(imageFilePointer); 
  ppmImage->height = geti(imageFilePointer);
  ppmImage->maxGrayValue = geti(imageFilePointer);
  
  if(ppmImage->width < 0 || ppmImage->height < 0 || 
      ppmImage->maxGrayValue < 0)
  { fclose(imageFilePointer);
    return - 1;
  }

  if(ppmImage->maxGrayValue > 255) ppmImage->maxGrayValue = 255;

  // allocate memory for a COLUMN
  ppmImage->image = (unsigned char * * *)
                     malloc(ppmImage->height * sizeof(char * *));
  if(ppmImage->image == (unsigned char * * *)0)
  { fclose(imageFilePointer);
    return - 1;
  }

  // allocate memory for the ROWS
  for(row = 0; row < ppmImage->height; row++) 
  { ppmImage->image[row] = (unsigned char * *) 
                         malloc(ppmImage->width * sizeof(char *));
    if(ppmImage->image[row] == (unsigned char * *)0)
    { fclose(imageFilePointer);
      return - 1;
    }
  }

  // allocate memory for the pixels
  for(row = 0; row < ppmImage->height; row++)
    for(col = 0; col < ppmImage->width; col++)
    { ppmImage->image[row][col] = (unsigned char *) malloc(3 * sizeof(char));
      if(ppmImage->image[row][col] == (unsigned char *)0)
      { fclose(imageFilePointer);
        return - 1;
      }
    }

  /*-------------------*/
  /* READ IN THE IMAGE */
  /*-------------------*/

  /*--------------*/
  /* ASCII FORMAT */
  /*--------------*/
  if(!raw)
    for(row = 0; row < ppmImage->height; row++)
      for(col = 0; col < ppmImage->width; col++)
        for(color = RED; color <= BLUE; color++)
          ppmImage->image[row][col][color] = geti(imageFilePointer);

  /*------------*/
  /* RAW FORMAT */
  /*------------*/
  if(raw)
    for(row = 0; row < ppmImage->height; row++)
      for(col = 0; col < ppmImage->width; col++)
        for(color = RED; color <= BLUE; color++)
          ppmImage->image[row][col][color] = getc(imageFilePointer);

  // success
  fclose(imageFilePointer);

  return 0; 
}
Exemplo n.º 28
0
int fqcyc (
    int fcflag)	
{
  char *me = "fqcyc";
  char msg[512],  vname[64];
  int  i, cflag, ntplot;
  double tempdbl;
  TimePlotCurve_t    *tpc = NULL, **tpc_array = NULL;
  char *err_maxtimeplot = "\n\t maxtimeplot of %d exceeded"
                      "\n\t This should be >= the total number of"
                      "\n\t timeplot ... endmsg, and"
                      "\n\t do 0.0 25.0 1.0 ... endmsg"
                      "\n\t loops in the deck"
                      "\n\t This can be increased by 'set maxtimeplot 999'"
                      "\n\t Set 999 to whatever limit is necessary";
  char *err_maxcycleplot = "\n\t maxcycleplot of %d exceeded"
                      "\n\t This should be >= the total number of"
                      "\n\t cycleplot ... endmsg"
                      "\n\t loops in the deck"
                      "\n\t This can be increased by 'set maxcycleplot 999'"
                      "\n\t Set 999 to whatever limit is necessary";
  char *err_maxtpdata  = "\n\t maxtpdata of %d exceeded"
                      "\n\t This should be >= the total number of"
                      "\n\t timeplot ... endmsg, and"
                      "\n\t do 0.0 25.0 1.0 ... endmsg and "
                      "\n\t cycleplot ... endmsg"
                      "\n\t loops in the deck"
                      "\n\t This can be increased by 'set maxtpdata 999'"
                      "\n\t Set 999 to whatever limit is necessary";
  char *err_maxtplot = "\n\t maxtplot of %d exceeded"
                      "\n\t This should be >= the largest number pf 'tplot'"
                      "\n\t lines within a single timeplot or cycleplot loop"
                      "\n\t This can be increased by 'set maxtplot 999'"
                      "\n\t Set 999 to whatever limit is necessary";
  if (( fcflag == 1 ) || ( fcflag == 2 )) {
    if ( nfq >= maxtimeplot ) {
      sprintf(msg,err_maxtimeplot,maxtimeplot);
      ctlerror(me,msg);
    }
    fq[nfq].t1 = getf(&cflag);
      if (lfchk() == 1) {
      fq[nfq].t2 = plarge;
      fq[nfq].dt = plarge;
    }
    else {
      fq[nfq].t2 = getf(&cflag);
      if (lfchk() == 1) {
        fq[nfq].dt = plarge;
        sprintf(msg,
          "\n\tTime step unspecified on following line:"
          "\n\t%s"
          "\tDefaulting time step to %e",
          line,fq[nfq].dt);
        ctlnotice(me,msg);
      }
      else {
        fq[nfq].dt = getf(&cflag);	
      }
    }
    ifcomfg = 0 ;
    ifexp   = 0 ;
#ifndef NDEBUG
    if  (fq[nfq].t1 < 0) {
      sprintf(msg,
        "\n\tTime begin of %f on following line is bad--it must be >= 0"
        "\n\t%s",
        fq[nfq].t1,line);
      ctlnotice(me,msg);
      return(1);
    }
    if (fq[nfq].t1 > fq[nfq].t2) {
      sprintf(msg,
        "\n\tTime begin of %f is > time end of %f on following line--"
        "\n\tTime begin must be less than time end"
        "\n\t%s",
        fq[nfq].t1,fq[nfq].t2,line);
      ctlnotice(me,msg);
      return(1);
    }
    if (fq[nfq].dt <= 0) {
      sprintf(msg,
        "\n\tTime step of %f on following line is bad--it must be > 0"
        "\n\t%s",
        fq[nfq].dt,line);
      ctlnotice(me,msg);
      return(1);
    }
#endif
    fq[nfq].nextTime = fq[nfq].t1;
    sprintf(msg,"time_freq_%03d",nfq);
    fq[nfq].name = strsave(msg);
    if ( fcflag == 2 ) {
      if ( ntp >= maxtpdata ) {
        sprintf(msg,err_maxtpdata,maxtpdata);
        ctlerror(me,msg);
      }
      fqtp[nfq] = ntp ;
      if (tpdata[ntp] != NULL) {
          sprintf(msg,"PROGRAMMER ERROR - tpdata[%d] already exists",ntp);
        ctlerror(me,msg);
      }
      tpdata[ntp] = TimePlot_construct(1);
      sprintf(msg,"tp_%03d",ntp);
      tpdata[ntp]->name = strsave(msg);
      tpdata[ntp]->fq_name      = strsave(fq[nfq].name);
      tpdata[ntp]->fq_dat       = &fq[nfq];
      tpdata[ntp]->cyc_name     = NULL;
      tpdata[ntp]->cyc_dat      = NULL;
      tpdata[ntp]->num_data_pts = 0;
      tempdbl = (((fq[nfq].t2 - fq[nfq].t1) / (fq[nfq].dt)) + 10);
      if (tempdbl >= (double)INT_MAX) {
        sprintf(msg,"\n\tTime frequency of %f to %f by %12.10f"
                    "\n\tresults in %e entries."
                    "\n\tTrimming the max number of entries to %d",
                    fq[nfq].t1,fq[nfq].t2,fq[nfq].dt,
                    tempdbl,INT_MAX);
        ctlnotice(me,msg);
        tpdata[ntp]->max_data_pts = INT_MAX;
      }
      else {
        tpdata[ntp]->max_data_pts = (int)tempdbl;
      }
      tpdata[ntp]->inc_data_pts  = NTIMES_INCREMENT;
      tpdata[ntp]->alloc_data_pts = 0;
      tpdata[ntp]->tp_curs       = NULL;
      tpdata[ntp]->tp_curs_names = NULL;
      tpdata[ntp]->num_tp_curs   = 0;
      rgst_add(tpdata[ntp]->name,"TimePlot_t",tpdata[ntp],NULL);
      ntp++;
    }
    rgst_add(fq[nfq].name,"FreqMesg_t",&(fq[nfq]),NULL);
    nfq++;
  }
  else if ((fcflag == 0 ) || (fcflag == 3)) {
    if (ncyc >= maxcycleplot) {
       sprintf(msg,err_maxcycleplot,maxcycleplot);
       ctlerror(me,msg);
    }
    cyc[ncyc].c1 = geti(&cflag) ;
    if (lfchk() == 1) {
      cyc[ncyc].c2 = 10000000;
      cyc[ncyc].dc = 10000000;
    }
    else {
      cyc[ncyc].c2 = geti(&cflag) ;
      if (lfchk() == 1) {
        cyc[ncyc].dc = (cyc[ncyc].c2 - cyc[ncyc].c1) / 10;
        sprintf(msg,
          "\n\tCycle step unspecified on following line:"
          "\n\t%s"
          "\tDefaulting cycle step to %d",
          line,cyc[ncyc].dc);
        ctlnotice(me,msg);
      }
      else {
        cyc[ncyc].dc = geti(&cflag) ;
      }
    }
    ifcomfg = 0 ;
    ifexp   = 0 ;
#ifndef NDEBUG
    if  (cyc[ncyc].c1 < 0) {
      sprintf(msg,
        "\n\tCycle begin of %d on following line is bad--it must be >= 0"
        "\n\t%s",
        cyc[ncyc].c1,line);
      ctlnotice(me,msg);
      return(1);
    }
    if (cyc[ncyc].c1 > cyc[ncyc].c2) {
      sprintf(msg,
        "\n\tCycle begin of %d is > cycle end of %d on following line--"
        "\n\tCycle begin must be less than time end"
        "\n\t%s",
        cyc[ncyc].c1,cyc[ncyc].c2,line);
      ctlnotice(me,msg);
      return(1);
    }
    if (cyc[ncyc].dc <= 0) {
      sprintf(msg,
        "\n\tCycle step of %d on following line is bad--it must be > 0"
        "\n\t%s",
        cyc[ncyc].dc,line);
      ctlnotice(me,msg);
      return(1);
    }
#endif
    cyc[ncyc].nextCycle = cyc[ncyc].c1;
    sprintf(msg,"cycle_freq_%03d",ncyc);
    cyc[ncyc].name = strsave(msg);
    if ( fcflag == 3 ) {
      if ( ntp >= maxtpdata ) {
        sprintf(msg,err_maxtpdata,maxtpdata);
        ctlerror(me,msg);
      }
      cyctp[ncyc] = ntp;
      if (tpdata[ntp] != NULL) {
        sprintf(msg,"PROGRAMMER ERROR - tpdata[%d] already exists",ntp);
        ctlerror(me,msg);
      }
      tpdata[ntp] = TimePlot_construct(1);
      sprintf(msg,"tp_%03d",ntp);
      tpdata[ntp]->name = strsave(msg);
      tpdata[ntp]->fq_name      = NULL;
      tpdata[ntp]->fq_dat       = NULL;
      tpdata[ntp]->cyc_name     = strsave(cyc[ncyc].name);
      tpdata[ntp]->cyc_dat      = &cyc[ncyc];
      tpdata[ntp]->num_data_pts = 0;
      tempdbl =((((double)cyc[ncyc].c2 - (double)cyc[ncyc].c1) /
                 ((double)cyc[ncyc].dc)) + (double)10);
      if (tempdbl >= (double)INT_MAX) {
        sprintf(msg,"\n\tCycle frequency of %d to %d by %d"
                    "\n\t results in %e entries"
                    "\n\tTrimming the max number of entries to %d",
                    cyc[ncyc].c1,cyc[ncyc].c2,cyc[ncyc].dc,
                    tempdbl,INT_MAX);
        ctlnotice(me,msg);
        tpdata[ntp]->max_data_pts = INT_MAX;
      }
      else {
        tpdata[ntp]->max_data_pts = (int)tempdbl;
      }
      tpdata[ntp]->inc_data_pts  = NTIMES_INCREMENT;
      tpdata[ntp]->alloc_data_pts = 0;
      tpdata[ntp]->tp_curs       = NULL;
      tpdata[ntp]->tp_curs_names = NULL;
      tpdata[ntp]->num_tp_curs   = 0;
      rgst_add(tpdata[ntp]->name,"TimePlot_t",tpdata[ntp],NULL);
      ntp++;
    }
    rgst_add(cyc[ncyc].name,"CycleMesg_t",&(cyc[ncyc]),NULL);
    ncyc++;
  }
  else  {
    ctlerror(me,"logic error: fcflag must be between 0 and 2");
  }
  if ((fcflag == 1) || (fcflag == 2)) {
    fq[nfq-1].msglen = lineop_grab(&fq[nfq-1].msg, "endmsg",NULL);
  } else {
    cyc[ncyc-1].msglen = lineop_grab(&cyc[ncyc-1].msg, "endmsg",NULL);
  }
  tpc_array = ALLOT(TimePlotCurve_t *, maxtplot);
  if ((fcflag == 2) || (fcflag == 3)) {
    ifexp = 0;
    if (fcflag == 2) {
      line = fq[nfq-1].msg ;
    } else {
      line = cyc[ncyc-1].msg ;
    }
    ps         = line ;
    symflag    = 0 ;
    if (genmd != 0) 
      ctlerror(me,"time plots must come AFTER gen command in input deck");
    tpc_array[0] = TimePlotCurve_create("time",ntp-1);
    ntplot       = 1;
    geta(sym);
    while (strcmp(sym,"endmsg") != 0) {
      if (strcmp(sym,"tplot") != 0) {
        geta(sym);
      }
      else { 
        geta(sym);
        strcpy(vname,sym);
        if (strcmp(vname,"time") == 0) {
          ctlwarning(me,"time cannot be edited");
        }
        else {
          tpc = TimePlotCurve_create(vname,ntp-1);
          tpc_array[ntplot] = tpc;
          if (ntplot++ >= maxtplot) {
            sprintf(msg,err_maxtplot,maxtplot);
            ctlerror(me,msg);
          }
        }
      }         
    }           
    tpdata[ntp-1]->num_tp_curs   = ntplot;
    tpdata[ntp-1]->tp_curs       = ALLOT(TimePlotCurve_t *, ntplot);
    tpdata[ntp-1]->tp_curs_names = ALLOT(char *,            ntplot);
    for (i=0 ; i<ntplot ; i++) { 
      tpdata[ntp-1]->tp_curs[i]       = tpc_array[i];
      tpdata[ntp-1]->tp_curs_names[i] = strsave(tpc_array[i]->name);
    }
    ifexp = 1;
  }
Exemplo n.º 29
0
int eosin0( int number, int form )
{
   char *me = "eosin0";
   char msg[128];
   int error, cflag, n, i, ir, ieos ;
   error = 0 ;
   ir   = current_region ;
   ieos = current_eos ;
   if ( reg[ir].eosGroup[ieos].database.ndata > 0 ) {
         FREEMEM(reg[ir].eosGroup[ieos].database.data) ;
   }
        if ( form == 0 )  { n = geti(&cflag) ; }
   else if ( form == 1 )   n =  5 ;
   else if ( form == 2 )   n =  7 ;
   else if ( form == 3 )   n = 32 ;
   else if ( form == 4 )   n =  6 ;
   else if ( form == 5 )   n =  1 ;
   else if ( form == 6 )   n = 27 ;
   else if ( form == 7 )   n =  9 ;
   else if ( form == 12 )  n =  7 ;
   else if ( form == 13 )  n =  7 ;
   else if ( form == 15 )  n = 32 ;
   else if ( form == 16 )  n =  0 ;
   else if ( form == 17 )  n = 15 ;
   else if ( form == 18 )  n = 21 ;
   else if ( form == 19 )  n = 18 ;
   else if ( form == 30 )  n =  0 ;
   else if ( form == 105 ) n =  2 ; 
   else if ( form == 107 ) n = 12 ;
   else if ( form == 111 ) n =  4 ;
   else if ( form == 200 ) n =  0 ;
   else if ( form == 211 ) n =  9 ;
   else if ( form == 301 ) n =  0 ;
   else if ( form == 311 ) n =  4 ;
   else if ( form == 312 ) n =  0 ;
   else if ( form == 321 ) n =  9 ;
   else if ( form == 390 ) n =  0 ;
   else if ( form == 900 ) n =  0 ;
   else if ( form == 901 ) n =  0 ;
   else {
      error = 1 ;
      sprintf(msg,"EOS form %d not allowed or currently supported.",form) ;
      ctlnotice(me,msg);
      return(error) ;
   }
   if ( form == 7 ) {
      sprintf(msg,"EOS form 7 is CALE 2-phase water EOS: enter 9 coefs.") ;
      ctlnotice(me,msg);
   }
   reg[ir].eosGroup[ieos].database.ndata = n ;
   if ( (n > 0) && (error == 0) ) {
      reg[ir].eosGroup[ieos].database.data = MALLOT(double, n) ;
      if ( (form == 111) || (form == 211) ||
           (form == 311) || (form == 321)  ) {
         n-- ;
         reg[ir].eosGroup[ieos].database.data[n] = -1.0 ;
      }
      for ( i = 0 ; i < n ; i++ ) {
         reg[ir].eosGroup[ieos].database.data[i] = getf(&cflag) ;
         if (cflag) {
            error = 1 ;
            sprintf( msg,"EOS %d, form %d, should have %d entries not %d.",
                     number, form, n, i ) ;
            ctlwarning(me,msg);
            return(error) ;
         }
      }
   }
Exemplo n.º 30
0
/*------------------------------------------------------*/
int load_PBM_Image(struct PBM_Image * pbmImage, char * fileName)
{ /*----------------------*/
  /* VARIABLE DECLARATION */
  /*----------------------*/

  // to read from file
  char c; bool raw = true; int bitCount;

  // forl oop variables
  int row, col;

  // open the file forreading
  FILE * imageFilePointer = fileOpener(READ, fileName);
  if(imageFilePointer == NULL) return -1;

  // make sure the first char is P
  if(fgetc(imageFilePointer) != 'P')
  { fclose(imageFilePointer);
    return - 1;
  }

  // make sure the second char is either a 1 or 4
  c = fgetc(imageFilePointer);
  if(c != '1' && c != '4')
  { fclose(imageFilePointer);
    return - 1;
  }

  if(c == '4') raw = true; else raw = false;

  // get the width and height of the image
  pbmImage->width = geti(imageFilePointer); 
  pbmImage->height = geti(imageFilePointer);
  if(pbmImage->width < 0 || pbmImage->height < 0)
  { fclose(imageFilePointer);
    return - 1;
  }

  // allocate memory for a COLUMN
  pbmImage->image = (unsigned char * *) 
                    malloc(pbmImage->height * sizeof(char *));
  if(pbmImage->image == (unsigned char * *)0)
  { fclose(imageFilePointer);
    return - 1;
  }

  // allocate memory for the ROWS
  for(row = 0; row < pbmImage->height; row++) 
  { pbmImage->image[row] = (unsigned char *) 
                         malloc(pbmImage->width * sizeof(char));
    if(pbmImage->image[row] == (unsigned char *)0)
    { fclose(imageFilePointer);
      return - 1;
    }
  }

  /*-------------------*/
  /* READ IN THE IMAGE */
  /*-------------------*/

  bitCount = 0;

  /*--------------*/
  /* ASCII FORMAT */
  /*--------------*/
  if(!raw)
    for(row = 0; row < pbmImage->height; row++)
      for(col = 0; col < pbmImage->width; col++) 
      { c = fgetc(imageFilePointer);
        while (c == '\n') c = fgetc(imageFilePointer);
        pbmImage->image[row][col] = c  - '0'; 
      }

  /*------------*/
  /* RAW FORMAT */
  /*------------*/
  if(raw)
    for(row = 0; row < pbmImage->height; row++)
      for(col = 0; col < pbmImage->width; col++)
      { // every 8 bits, read in another character
        if(bitCount == 0)
        { c = fgetc(imageFilePointer);
          bitCount = 8;
        }

        // get a bit from c
        pbmImage->image[row][col] = (c >> --bitCount) & 1;
      }

  // success

  fclose(imageFilePointer);

  return 0; 
}