Esempio n. 1
0
/* Print the quantum yield (QY) values obtained by using the 2MM measurement
 * method and by using the 3MM method. 2MM will be obtained for each of 
 * IN_BEAM_DATA and OUT_DATA that are provided, 3MM will be obtained only if
 * both are provided. LMIN, LMAX, PMIN, and PMAX set bounds on peak integration.
 * Emission correction for the sensitivity of the detector is specified as
 * EMISSION_CORRECTION, and can be either "default" or "quanta" or any prefix
 * of them.
 */
void QuantumYield(char* solvent_data_file = "",
                     char* in_beam_data = "",
                     int lmin = 0, int lmax = 0,
                     int pmin = 0, int pmax = 0,
                     char* out_beam_data = "",
                     char* emission_correction = "d") {
    double QY;
    double error;
    
    FILE* solvent = open_data(solvent_data_file);
    FILE* in_data = open_data(in_beam_data);
    FILE* out_data = open_data(out_beam_data);
    FILE* correction = open_correction(emission_correction);

    if (!solvent || (!in_data && !out_data)) {
        printf("Invalid data file.\n");
        printf("Arguments: reference data file, in-beam data file, lmin, lmax, pmin, pmax, indirect data file, correction name.\n");
        close_files(solvent, in_data, out_data, correction);
        return;
    }

    if (is_corr) {
        read_correction(correction);
    }

    get_L_a(solvent, lmin, lmax);
    
    if (in_data) {
        QY = TwoMMQY(in_data, lmin, lmax, pmin, pmax);
        error = get_error();
        printf("\n\nL_a %f\nL_b %f\nP_b %f\n2MMQY %f +/- %f\n", L_a, L_b, P_b,
                                                              QY, error);
        printf("L_a - L_b = %f\n", L_a - L_b);
        if (out_data) {
            QY = ThreeMMQY(out_data, lmin, lmax, pmin, pmax);
            error = get_error();
            printf("L_c %f\nP_c %f\n3MMQY %f +/- %f\n", L_c, P_c, QY, error);
            printf("L_a - L_c = %f\n", L_a - L_c);
        }
    }
    if (out_data) {
        rewind(out_data);
        L_b = 0;
        P_b = 0;
        QY = TwoMMQY(out_data, lmin, lmax, pmin, pmax);
        error = get_error();
        printf("2MMQY (out data) %f +/- %f\n", QY, error);
    }
    printf("\n");
    
    close_files(solvent, in_data, out_data, correction);
}
int m__GetData(struct soap *soap, struct x__Keys *keys, struct m__GetDataResponse *response)
{ int i;
  if ((soap->omode & SOAP_IO) == SOAP_IO_STORE)
    soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_BUFFER;
  if (!keys)
    return soap_sender_fault(soap, "No keys", NULL);
  /* Set up array of attachments to return */
  response->x__data.__size = keys->__size;
  response->x__data.item = soap_malloc(soap, keys->__size*sizeof(struct x__Data));
  for (i = 0; i < keys->__size; ++i)
    open_data(soap, keys->key[i], &response->x__data.item[i]);
  return SOAP_OK;
}
int client_putData(struct soap *soap, int argc, char **argv)
{ int i;
  struct x__DataSet data;
  struct m__PutDataResponse response;
  data.__size = argc - 2;
  data.item = soap_malloc(soap, (argc - 2)*sizeof(struct x__Data));
  for (i = 2; i < argc; i++)
    open_data(soap, argv[i], &data.item[i - 2]);
  if (soap_call_m__PutData(soap, endpoint, NULL, &data, &response))
    soap_print_fault(soap, stderr);
  else
  { printf("Data stored with keys:\n");
    for (i = 0; i < response.x__keys.__size; i++)
      printf("\t%s\n", response.x__keys.key[i]);
    printf("Use these keys to retrieve the data with -g key1 key2 ...\n");
  }
  return soap->error;
}
Esempio n. 4
0
/* 
 * get the current file revision 
 * it is stored in the cvs var $Revision: 1.14 $
 */
static int get_current_rev(char *file, char **curr, char *errbuf)
{
   FILE *fd;
   char line[128];
   char *ptr;
  
   /* do not permit to insert ../../../ in the filename */
   if (strchr(file, '/')) {
      snprintf(errbuf, ERR_MAX_LEN, "invalid file");
      return 0;
   }
   
   /* check if the file exists */
   fd = open_data("share", file, FOPEN_READ_TEXT);
   if (fd == NULL) {
      snprintf(errbuf, ERR_MAX_LEN, "cannot open file %s", file);
      return 0;
   }

   /* search the right line */
   while (fgets(line, sizeof(line), fd) != 0) {
      if ( (ptr = strstr(line, "Revision: ")) ) {
         /* get the revision */
         *curr = strdup(ptr + strlen("Revision: "));
         /* truncate at the first blank space */
         ptr = *curr;
         while (*ptr != ' ') ptr++;
         *ptr = '\0';

         return 1;
         break;
      }
   }

   fclose(fd);   
   snprintf(errbuf, ERR_MAX_LEN, "bad revision number");
   return 0;
}
Esempio n. 5
0
void load_conf(void)
{
   FILE *fc;
   char line[128];
   char *p, *q, **tmp;
   int lineno = 0;
   size_t tmplen;
   struct conf_entry *curr_section = NULL;
   void *value = NULL;

   /* initialize the structures */
   init_structures();
   
   DEBUG_MSG("load_conf");
  
   /* the user has specified an alternative config file */
   if (GBL_CONF->file) {
      DEBUG_MSG("load_conf: alternative config: %s", GBL_CONF->file);
      fc = fopen(GBL_CONF->file, FOPEN_READ_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", GBL_CONF->file);
   } else {
      /* errors are handled by the function */
      fc = open_data("etc", ETTER_CONF, FOPEN_READ_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", ETTER_CONF);
   }
  
   /* read the file */
   while (fgets(line, 128, fc) != 0) {
      
      /* update the line count */
      lineno++;
      
      /* trim out the comments */
      if ((p = strchr(line, '#')))
         *p = '\0';
      
      /* trim out the new line */
      if ((p = strchr(line, '\n')))
         *p = '\0';

      q = line;
      
      /* trim the initial spaces */
      while (q < line + sizeof(line) && *q == ' ')
         q++;
      
      /* skip empty lines */
      if (line[0] == '\0' || *q == '\0')
         continue;
      
      /* here starts a new section [...] */
      if (*q == '[') {
         
         /* remove the square brackets */
         if ((p = strchr(line, ']')))
            *p = '\0';
         else
            FATAL_ERROR("Missing ] in %s line %d", ETTER_CONF, lineno);
         
         p = q + 1;
         
         DEBUG_MSG("load_conf: SECTION: %s", p);

         /* get the pointer to the right structure */
         if ( (curr_section = search_section(p)) == NULL)
            FATAL_ERROR("Invalid section in %s line %d", ETTER_CONF, lineno);
         
         /* read the next line */
         continue;
      }
   
      /* variable outside a section */
      if (curr_section == NULL)
         FATAL_ERROR("Entry outside a section in %s line %d", ETTER_CONF, lineno);
      
      /* sanity check */
      if (!strchr(q, '='))
         FATAL_ERROR("Parse error %s line %d", ETTER_CONF, lineno);
      
      p = q;

      /* split the entry name from the value */
      do {
         if (*p == ' ' || *p == '='){
            *p = '\0';
            break;
         }
      } while (p++ < line + sizeof(line) );
      
      /* move p to the value */
      p++;
      do {
         if (*p != ' ' && *p != '=')
            break;
      } while (p++ < line + sizeof(line) );
      
      /* 
       * if it is the "dissector" section,
       * do it in a different way
       */
      if (curr_section == (struct conf_entry *)&dissectors) {
         set_dissector(q, p, lineno);
         continue;
      }
     
      /* search the entry name */
      if ( (value = search_entry(curr_section, q)) == NULL)
         FATAL_ERROR("Invalid entry in %s line %d", ETTER_CONF, lineno);
   
      /* strings must be handled in a different way */
      if (curr_section == (struct conf_entry *)&strings) {
         /* trim the quotes */
         if (*p == '"')
            p++;
         
         /* set the string value */ 
         tmp = (char **)value;
         *tmp = strdup(p);
         
         /* trim the ending quotes */
         p = *tmp;
         tmplen = strlen(*tmp);
         do {
            if (*p == '"') {
               *p = 0;
               break;
            }
         } while (p++ < *tmp + tmplen );
         
         DEBUG_MSG("load_conf: \tENTRY: %s  [%s]", q, *tmp);
      } else {
         /* set the integer value */ 
         *(int *)value = strtol(p, (char **)NULL, 10);
         DEBUG_MSG("load_conf: \tENTRY: %s  %d", q, *(int *)value);
      }
   }

   sanity_checks();
   fclose(fc);
}
Esempio n. 6
0
/* 
 * download the file and replace 
 * the existing one
 */
static int do_update(char *file, char *url, char *errbuf)
{
   FILE *fd;
   int sock;
   int len, header_skipped = 0;
   char *ptr = NULL;
   char *host;
   char getmsg[512];
   char buffer[4096];
 
   memset(buffer, 0, sizeof(buffer));
   
   /* check if the url is valid */
   if (!match_pattern(url, "http://*/*")) {
      snprintf(errbuf, ERR_MAX_LEN, "invalid URL");
      return 0;
   }

   /* get the hostname */
   host = strdup(url + strlen("http://"));
   ptr = host;
   while (*ptr != '/') ptr++;
   *ptr = '\0';
   
   /* open the file for writing */
   fd = open_data("share", file, FOPEN_WRITE_TEXT);
   if (fd == NULL) {
      snprintf(errbuf, ERR_MAX_LEN, "cannot open %s", file);
      return 0;
   }
  
   sock = open_socket(host, 80);
   
   switch(sock) {
      case -ENOADDRESS:
         FATAL_MSG("Cannot resolve %s", host);
         break;
      case -EFATAL:
         FATAL_MSG("Cannot create the socket");
         break;
      case -ETIMEOUT:
         FATAL_MSG("Connect timeout to %s on port 80", host);
         break;
      case -EINVALID:
         FATAL_MSG("Error connecting to %s on port 80", host);
         break;
   }
   
   /* prepare the HTTP request */
   snprintf(getmsg, sizeof(getmsg), "GET %s HTTP/1.0\r\n"
                                     "Host: %s\r\n"
                                     "User-Agent: %s (%s)\r\n"
                                     "\r\n", url, host, GBL_PROGRAM, GBL_VERSION );
   
   /* send the request to the server */
   socket_send(sock, getmsg, strlen(getmsg));

   DEBUG_MSG("do_update - SEND \n\n%s\n\n", getmsg);

   /* get the server response */
   while ( (len = socket_recv(sock, buffer, sizeof(buffer) - 1)) ) {

      DEBUG_MSG("do_update - RECEIVE \n\n%s\n\n", buffer);

      /* skip the HTTP header */
      if ( (ptr = strstr(buffer, "\r\n\r\n")))
         header_skipped = 1;
   
      /* write the data in the file */
      if (header_skipped) {
         if (ptr) {
            write(fileno(fd), ptr + 4, len - (ptr + 4 - buffer));
         } else {
            write(fileno(fd), buffer, len);
         }
      }
   
      memset(buffer, 0, sizeof(buffer));
      ptr = NULL;

   }

   SAFE_FREE(host);
   close_socket(sock);
   fclose(fd);

   return 1;
}
Esempio n. 7
0
int rnc_retrieveconf(BIO *ssl)
{
   FILE *fc;
   RncProtoHeader pheader;
   RncProtoConfig pconfig;
   int found = 0;
   char *conf;

   /* header parameters */
   pheader.code = RNC_PROTO_CONF;
   pheader.size = 0;

   /* send request to check if there is new config */
   if (ssl_proto_write(ssl, &pheader, sizeof(pheader)) <= 0)
      return -1;

   /* loop to receive the new conf */
   LOOP {
      memset(&pheader, 0, sizeof(pheader));
      memset(&pconfig, 0, sizeof(pconfig));

      /* read the response from RNC */
      if (ssl_proto_read(ssl, &pheader, sizeof(pheader)) <= 0)
         break;

      /* there is NOT a new config */
      if (pheader.code != RNC_PROTO_CONF)
         break;

      /* retrieve the config header */
      if (ssl_proto_read(ssl, &pconfig, sizeof(pconfig)) <= 0)
         break;

      /* allocate the buffer and read the conf from RNC */
      SAFE_CALLOC(conf, pconfig.size, sizeof(char));
      if (ssl_proto_read(ssl, conf, pconfig.size) <= 0)
         break;

      DEBUG_MSG(D_INFO, "Received new config file [%s]", pconfig.filename);

      /* open the config file for writing */
      fc = open_data("etc", pconfig.filename, FOPEN_WRITE_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", pconfig.filename);

      /* dump the content of the buffer received from RNC into the file */
      if (fwrite(conf, sizeof(char), pconfig.size, fc) < pconfig.size)
         DEBUG_MSG(D_ERROR, "Cannot write conf file [%s]", pconfig.filename);

      DEBUG_MSG(D_DEBUG, "Config file [%s] written (%d bytes)", pconfig.filename, pconfig.size);

      fclose(fc);

      /* if the file is a ZIP archive, extract it */
      if (!strcasecmp(pconfig.filename + strlen(pconfig.filename) - 4, ".zip")) {
         char *path, *dir, *p;
         char argv[1024];
         int ret;

         /* get the path of the file */
         if ((path = get_path("etc", pconfig.filename)) == NULL)
            continue;

         dir = strdup(path);

         /* trim the filename, get the dirname */
         if ((p = strrchr(dir, '/')) != NULL)
            *p = 0;

         /* clean the vectors directory */
         snprintf(argv, sizeof(argv), "/bin/rm -f %s/vectors/*", dir);

         DEBUG_MSG(D_INFO, "Cleaning vectors directory...");
         /* execute the command */
         ret = system(argv);
         if (ret == -1 || ret == 127)
            DEBUG_MSG(D_ERROR, "Clean failed");

         /* prepare the commandline for unzip */
         snprintf(argv, sizeof(argv), "/usr/bin/unzip -o %s -d %s", path, dir);

         DEBUG_MSG(D_INFO, "Uncompressing configuration file...");
         /* execute the command */
         ret = system(argv);

         if (ret == -1 || ret == 127)
            DEBUG_MSG(D_ERROR, "Unzip failed");

         unlink(path);

         SAFE_FREE(dir);
         SAFE_FREE(path);
      }

      /* increment the number of received config */
      found++;
   }

   return found;
}