Esempio n. 1
0
File: rdbu.c Progetto: Accio/ribios
void rdbu_initLoginInfo (char *filename) {
  /**
     Looks in the following places for user/password\@database
     info needed for logging into database in this order
     1. a file named .login_db in the user's home directory
     2. a file named .login_db in the current directory
     3. a file named 'filename' (optional input parameter)
     4. arguments 'dbuser', 'dbpassword', 'dbname' present  the command line
     Syntax of the files:
     - only the first line is read
     - this line must have the form user/password\@dbname
     - each of these fields can be '-'; in this case the value
       of this field is not changed. E.g. if $HOME/.login_db contains
       -/-\@testdb
      and 'filename' contains
      scott/-@-
      and on the command line there is an argument
      -dbpassword tiger
      then username will be scott, password will be tiger and
      database will be testdb
      optional: if arg_init() was called before then the command line will be
                considered; else the command line is ignored
      Postcondition: rdbu_user() etc can be called
  */
  Stringa fn;
  char *home = getenv ("HOME");
  if (user != NULL)
    die ("rdbu_getLoginInfo() twice");
  user = stringCreate(10);
  password = stringCreate(10);
  database = stringCreate(10);
  if (home != NULL) {
    fn = stringCreate (100);
    stringPrintf (fn,"%s/.login_db",home);
    readUserInfoFile (string (fn));
    stringDestroy (fn);
  }
  readUserInfoFile (".login_db");
  if (filename != NULL && *filename != '\0')
    readUserInfoFile (filename);
  if (arg_isInit ()) {
    if (arg_present ("dbuser"))
      stringCpy (user,arg_get ("dbuser"));
    if (arg_present ("dbpassword"))
      stringCpy (password,arg_get ("dbpassword"));
    if (arg_present ("dbname"))
      stringCpy (database,arg_get ("dbname"));
  }
}
Esempio n. 2
0
File: rdbu.c Progetto: Accio/ribios
void rdbu_loginFunc (char* (*rdbr_login)(char *server,char *dbname,
                                         char *user,char *passwd)) {
  /**
     Tries to login into the database based on the procedure described
     in rdbu_initLoginInfo(). In addition, if there is a command line
     argument "-dbfile filename", then parameters are also looked for
     in 'filename'.
     If the login fails, there is a terse message 'PROBLEM: oracle logon
     failed' on order not to show the password to the user of the program.
     At debugging time however it might be desirable to know the login
     parameters. In this case establish the environment variable 'RDBU_DEBUG'
     to get a detailed message.<br>
     Postcondition: rdbr_logout() and other rdbr_ routines can be called.<br>
     Note: do not invoke this function in your program; use rdbu_login()
     instead
  */
  /*
    implementation:
    why did we use the function pointer? :
    because we wanted to keep this module independent from linking with
    ORACLE or PostgreSQL; so rdbr.o can go into libkern.a
  */
  char *msg;
  char *filename = NULL;
  static int first = 1;
  if (first) {
    if (arg_isInit () && arg_present ("dbfile"))
      filename = arg_get ("dbfile");
    rdbu_initLoginInfo (filename);
    first = 0;
  }
  if ((msg = (*rdbr_login)(rdbu_database (),NULL,
                           rdbu_user (),rdbu_password ())) != NULL) {
    warn (msg);
    if (getenv ("RDBU_DEBUG") != NULL)
      romsg ("rdbu_login failed for %s/%s@%s",rdbu_user (),rdbu_password (),
             rdbu_database ());
    return;
  }
}
Esempio n. 3
0
static int
_steph_Cmd_ (ClientData clientData,
	  Tcl_Interp *interp,
	  int        argc,
	  char       **argv)
{ 
  /* Command line definition */
  char * options[] = {
    "",
    "cmdlist", "",
    NULL
  };

  char * helpMsg = {
    (
     " List the C-defined commands of the package.\n"
     "\n"
     "Parameters :\n"
     "  none."
     )
  };

  /* Command's parameters */

  /* Options's presence */
  int isCmdlist;

  /* Options's parameters */

  /* Other variables */
  register cmdInfo *cmdInfoPtr;

  /* Command line analysis */
  if (arg_init (interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get (0) == TCL_ERROR)
    return TCL_ERROR;

  isCmdlist = arg_present (1);

  /* Parameters validity and initialisation */

  /* Treatement */
  if (isCmdlist) {
    Tcl_AppendResult (interp, "{", (char *) NULL);

    cmdInfoPtr = StephCmdInfoArray;
    Tcl_AppendResult (interp, cmdInfoPtr->name, (char *) NULL);
    for (cmdInfoPtr++;
	 cmdInfoPtr->name != NULL;
	 cmdInfoPtr++) {
      Tcl_AppendResult (interp, " ", cmdInfoPtr->name, (char *) NULL);
    }
    Tcl_AppendResult (interp, "}", (char *) NULL);
  } else {
    sprintf (interp->result, "The steph package blablabla.");
  }

  return TCL_OK;
}
Esempio n. 4
0
static int
_bic_Cmd_ (ClientData clientData,
	   Tcl_Interp *interp,
	   int        argc,
	   char       **argv)      

{

  /* Command line definition */
  char * options[] = {
    "SSSs",
    "-fit","S",
    NULL
  };

  char * helpMsg = {
    (
     "  Fit the data by with a bic model (correlation functions of fractionnal brownian).\n"
     " y=s^2*pow(fabs(x+d),2.*h)+pow(fabs(x-d),2.*h)-2.*pow(fabs(x),2.*h)/2.\n"
     "\n"
     "Arguments :\n"
     "  3 signals - signal to fit, \n"
     "              signal containing the incertaity for each point, \n"
     "              signal containing the initial values (s,h,d).\n"
     "  string    - name of the result (s,h,d,chisq,goodness,covar --> size=14)\n."
     "\n"
     "Options :\n"
     "   -fit   : signal containing the x-value (REALY)\n" 
     "            --> return the bic fit in this signal (REALXY).\n"
     )
  };

  Signal *datasignal,*sigmasignal, *valsignal;
  Signal *result, *xsignal = NULL;
  char   *resultName;
  int i,j,size;
  
  real *X;
  int ma;
  int *ia;
  real *a,**covar,**alpha;
  real chisq;
  
  int u;

  if (arg_init(interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get(0, &datasignal, &sigmasignal, &valsignal, &resultName) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(1, &xsignal) == TCL_ERROR)
    return TCL_ERROR;

  size = datasignal->size;
  if(sigmasignal->size != size) {
    Tcl_AppendResult (interp,
		      "The sigma signal should be of the same size as the input signal.",
		      (char *) NULL);
    return TCL_ERROR;
  }
  
  if (datasignal->type == REALY) 
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->x0 + i*datasignal->dx;
    }
  else if (datasignal->type == REALXY)
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->dataX[i]; 
    }
  else {
        Tcl_AppendResult (interp,
		      "Bad type for the signal (only REALY or REALXY).",
		      (char *) NULL);
    return TCL_ERROR;
  }

  ma = valsignal->size;
  if (ma != 3) {
    Tcl_AppendResult (interp,
		      "Bad number of initial value (we need 3 values s,h and d).",
		      (char *) NULL);
    return TCL_ERROR;
  }
  NonLinFitInit(&a,&ia,ma,&covar,&alpha);
  for(i=0;i<valsignal->size;i++)
	{
	  a[i+1]=valsignal->dataY[i];
	  ia[i+1] = 1;
	}
  NonLinFit(X-1,datasignal->dataY-1,sigmasignal->dataY-1,size,a,ia,ma,covar,alpha,
		&chisq,&BrowIncrCorr);


  result = sig_new (REALY, 0, ma+ma*ma+1);
  result->x0 = 0.0;
  result->dx = 1;
  u =0;
  for(i=1;i<=ma;i++) {
    result->dataY[u]=a[i];
    u=u+1;
  }
  result->dataY[u++]=chisq;
  result->dataY[u++]=NonLinFitConfidence(chisq,size,ma);
  for(i=1;i<=ma;i++) {
    	  for(j=1;j<=ma;j++)
	    {	      
	      result->dataY[u++]=covar[i][j];
	    }
  }


  if (!result)
    return TCL_ERROR;
  
  store_signal_in_dictionary(resultName, result);
  
  if (arg_present(1)) {
    if (xsignal->type != REALY) {
      Tcl_AppendResult (interp,
			"Type for xsignal must be REALY!!",
			(char *) NULL);
      return TCL_ERROR;
    }
    else {
      sig_realy2realxy(xsignal);
      sig_put_y_in_x(xsignal);
      for (i=0;i<xsignal->size;i++) 
	BrowIncrCorr(xsignal->dataX[i],a,&(xsignal->dataY[i]),NULL,ma);

    }


  }

  NonLinFitDelete(a,ia,ma,covar,alpha);

  return TCL_OK;

}
Esempio n. 5
0
static int
_mwc_Cmd_ (ClientData clientData,
	   Tcl_Interp *interp,
	   int        argc,
	   char       **argv)      

{

  /* Command line definition */
  char * options[] = {
    "SSSs",
    "-fit","S",
    NULL
  };

  char * helpMsg = {
    (
     "  Fit the data by with a mwc model (model for tensio-actif membrane).\n"
     "  (y=f0*prefactor*(85*(h0/x-0.5 +0.1 -x^5/(h0^5*320)- 0.5 + x^2/(h0^2*8.))\n"
     " + 0.5*(h0-x/2.+h0*log(2.*h0/x)) - (h0-x/2.)/10. + (64.*h0^6 - x^6)/(3840.*h0^5)\n"
     " + (h0-x/2.)/2. - (8*h0^3-x^3)/(48*h0^2)).\n"
     "\n"
     "Arguments :\n"
     "  3 signals - signal to fit, \n"
     "              signal containing the incertaity for each point, \n"
     "              signal containing the initial values (h0,f0).\n"
     "  string    - name of the result (h0,f0,chisq,goodness,covar --> size=8)\n."
     "\n"
     "Options :\n"
     "   -fit   : signal containing the x-value (REALY)\n" 
     "            --> return the mwc fit in this signal (REALXY).\n"
     )
  };

  Signal *datasignal,*sigmasignal, *valsignal;
  Signal *result, *xsignal = NULL;
  char   *resultName;
  int i,j,size;
  
  real *X;
  int ma;
  int *ia;
  real *a,**covar,**alpha;
  real chisq;
  
  int u;

  if (arg_init(interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get(0, &datasignal, &sigmasignal, &valsignal, &resultName) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(1, &xsignal) == TCL_ERROR)
    return TCL_ERROR;

  size = datasignal->size;
  if(sigmasignal->size != size) {
    Tcl_AppendResult (interp,
		      "The sigma signal should be of the same size as the input signal.",
		      (char *) NULL);
    return TCL_ERROR;
  }
  
  if (datasignal->type == REALY) 
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->x0 + i*datasignal->dx;
    }
  else if (datasignal->type == REALXY)
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->dataX[i]; 
    }
  else {
        Tcl_AppendResult (interp,
		      "Bad type for the signal (only REALY or REALXY).",
		      (char *) NULL);
    return TCL_ERROR;
  }

  ma = valsignal->size;
  if (ma != 2) {
    Tcl_AppendResult (interp,
		      "Bad number of initial value (we need 2 values h0 and f0).",
		      (char *) NULL);
    return TCL_ERROR;
  }
  NonLinFitInit(&a,&ia,ma,&covar,&alpha);
  for(i=0;i<valsignal->size;i++)
	{
	  a[i+1]=valsignal->dataY[i];
	  ia[i+1] = 1;
	}
  NonLinFit(X-1,datasignal->dataY-1,sigmasignal->dataY-1,size,a,ia,ma,covar,alpha,
		&chisq,&MWC);


  result = sig_new (REALY, 0, ma+ma*ma+1);
  result->x0 = 0.0;
  result->dx = 1;
  u =0;
  for(i=1;i<=ma;i++) {
    result->dataY[u]=a[i];
    u=u+1;
  }
  result->dataY[u++]=chisq;
  result->dataY[u++]=NonLinFitConfidence(chisq,size,ma);
  for(i=1;i<=ma;i++) {
    	  for(j=1;j<=ma;j++)
	    {	      
	      result->dataY[u++]=covar[i][j];
	    }
  }


  if (!result)
    return TCL_ERROR;
  
  store_signal_in_dictionary(resultName, result);
  
  if (arg_present(1)) {
    if (xsignal->type != REALY) {
      Tcl_AppendResult (interp,
			"Type for xsignal must be REALY!!",
			(char *) NULL);
      return TCL_ERROR;
    }
    else {
      sig_realy2realxy(xsignal);
      sig_put_y_in_x(xsignal);
      for (i=0;i<xsignal->size;i++) 
	MWC(xsignal->dataX[i],a,&(xsignal->dataY[i]),NULL,ma);

    }


  }

  NonLinFitDelete(a,ia,ma,covar,alpha);

  return TCL_OK;

}
Esempio n. 6
0
static int
_lf_Cmd_ (ClientData clientData,
	   Tcl_Interp *interp,
	   int        argc,
	   char       **argv)      
{
  /* Command line definition */
  char * options[] = {
    "Ss",
    "-x","ff",
    "-sigma","S",
    "-fit","S",
    NULL
  };

  char * helpMsg = {
    (
     "  Fit the data by a straight line (y=ax+b)."
     "\n"
     "Arguments :\n"
     "  1 signal - signal to fit.\n"
     "  string    - name of the result (a, b,siga,sigb,chi2,goodness-of-fit)\n."
     "\n"
     "Options :\n"
     "   -x     : domain to fit.\n"
     "   -sigma : signal containing the dy of each points of the signal to fit.\n"
     "   -fit   : signal containing the x-value (REALY)\n"
     "            --> return y=ax+b in this signal (REALXY).\n"
     )
  };

  /* Command's parameters */
  Signal *datasignal,*sigmasignal =  NULL, *result, *xsignal = NULL;
  char   *resultName;
  real   xMin,xMax;
  int flagWithWeight=0;
  int size,i;
  real *X, *sigmaY;
  real a,b,siga,sigb,chi2,q;
  int iMin, iMax;


  xMin=1.0;
  xMax=-1.0;

  if (arg_init(interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get(0, &datasignal, &resultName) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(1, &xMin, &xMax) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(2, &sigmasignal) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(3, &xsignal) == TCL_ERROR)
    return TCL_ERROR;

  if ((arg_present(2) && (datasignal->size != sigmasignal ->size))) {
    Tcl_AppendResult (interp,
		      "The sigma signal should be of the same size as the input signal.",
		      (char *) NULL);
    return TCL_ERROR;
  }


  size = datasignal->size;

  if (datasignal->type == REALY) 
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) { 
	X[i] = datasignal->x0 + i*datasignal->dx;
      }
    }
  else if (datasignal->type == REALXY)
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) { 
	X[i] = datasignal->dataX[i];
      }
    }
  else {
        Tcl_AppendResult (interp,
		      "Bad type for the signal (only REALY or REALXY).",
		      (char *) NULL);
    return TCL_ERROR;
  }
    
  if (arg_present(2))
    {
      sigmaY = sigmasignal->dataY - 1;
      flagWithWeight = 1;
    }
  else
    {
      sigmaY = NULL;
      flagWithWeight = 0;
    }

    
  iMin =0;
  iMax = size -1;

  if (arg_present(1)) {
    if (xMin >= xMax) {
      Tcl_AppendResult (interp,
			"xmin should be smaller than xmax",
			(char *) NULL);
      return TCL_ERROR;
    }
    iMin = IsigCeil(datasignal,xMin);
    iMax = IsigFloor(datasignal,xMax);
  }

  size = iMax - iMin + 1;
  printf("imin=%d %d\n",iMin,iMax);
  
  if(size <= 1) {
    Tcl_AppendResult (interp,
		      "Can't fit on less than two points!!",
		      (char *) NULL);
    return TCL_ERROR;
  }

  fit(X-1+iMin,datasignal->dataY-1+iMin,size,
      ((sigmaY == NULL) ? sigmaY : sigmaY + iMin),
      flagWithWeight,&a,&b,&siga,&sigb,&chi2,&q);
 
  free(X);

  result = sig_new (REALY, 0, 5);
  result->x0 = 0.0;
  result->dx = 1;
  result->dataY[0]=a;
  result->dataY[1]=b;
  result->dataY[2]=siga;
  result->dataY[3]=sigb;
  result->dataY[4]=chi2;
  result->dataY[5]=q;
  if (!result)
    return TCL_ERROR;
  
  store_signal_in_dictionary(resultName, result);
  
  if (arg_present(3)) {
    if (xsignal->type != REALY) {
      Tcl_AppendResult (interp,
			"Type for xsignal must be REALY!!",
			(char *) NULL);
      return TCL_ERROR;
    }
    else {
      /*    DEMAIN REGARDER COMMENT CHANGER REALY EN REALXY
	    size=xsignal->size;
    X = (float *) malloc(sizeof(float)*size);      
    X = xsignal->dataY;
    sig_free(xsignal);
    */
    }


  }
  return TCL_OK;
}
Esempio n. 7
0
int
_my_iinssig_Cmd_ (ClientData clientData,
		       Tcl_Interp *interp,
		       int        argc,
		       char       **argv)
{ 
  /* Command line definition */
  char * options[] =
  {
    "ISd",
    "-y", "",
    "-45","",
    "-m45","",
    NULL
  };

  char * help_msg =
  {
    (" Insert a signal in an image at a given position.\n"
     "\n"
     "Parameters :\n"
     "  Image   - image to treat.\n"
     "  Signal  - signal to add.\n"
     "  integer - position.\n"
     "\n"
     "Options :\n"
     "  -y   : Add in the y-direction.\n"
     "  -45  : The direction of insertion is 45 degree.\n"
     "  -m45 : The direction of insertion is m45 degree.")
  };

  /* Command's parameters */
  Image  *im;
  Signal *sig;
  int    position;

  /* Options's presence */
  int is_y,is_45, is_m45;


  /* Other variables */
  int i;
  int lx,ly;
  int x;

  /* Command line analysis */
  if (arg_init (interp, argc, argv, options, help_msg))
    return TCL_OK;
  
  if (arg_get (0, &im, &sig, &position) == TCL_ERROR)
    return TCL_ERROR;

  is_y = arg_present(1);
  is_45 = arg_present(2);
  is_m45 = arg_present(3);

  /* Parameters validity and initialisation */
  if (is_y) {
    if (sig->size > im->ly) {
      sprintf(interp->result,
	      "The signal size (%d) must be lesser than the image heigth (%d).",
	      sig->size, im->ly);
      return TCL_ERROR;
    } 
  }
  else {
    if (sig->size > im->lx) {
      sprintf(interp->result,
	      "The signal size (%d) must be lesser than the image width (%d).",
	      sig->size, im->lx);
      return TCL_ERROR;
    }
  }
  
  /* Treatement */

  lx = im->lx;
  ly = im->ly;
  for (i = 0; i < sig->size; i++) {
    x = i;
    if (is_y) {
      if ((position >= 0) && (position < ly)) {
	if (is_m45) {
	  im->data[position+lx*(ly-x-1)] = sig->dataY[i];
	} else {
	  im->data[position+lx*x] = sig->dataY[i];
	}
      }
      position = (is_45 ? position+1 : position);
      position = (is_m45 ? position+1 : position);
    } else {
      if ((position >= 0) && (position < lx)) 
	im->data[x+lx*position] = sig->dataY[i];
      position = (is_45 ? position+1 : position);
      position = (is_m45 ? position-1 : position);
    }
  }

  return TCL_OK;
}