int
main ()
{
  char c;
  char *line, *buffer, *tmp, *x;
  int i, linelen, nothree;
  long buflen, seqlen;

  line = malloc (256);
  if (!line)
    return -1;
  seqlen = 0;
  nothree = 1;

  while (nothree && fgets (line, 255, stdin))
    if (line[0] == '>' && line[1] == 'T' && line[2] == 'H')
      nothree = 0;
  free (line);

  buflen = 10240;
  buffer = malloc (buflen + 1);
  if (!buffer)
    return -1;
  x = buffer;

  while (fgets (x, 255, stdin))
    {
      linelen = strlen (x);
      if (linelen)
	{
	  if (x[linelen - 1] == '\n')
	    linelen--;
	  c = x[0];
	  if (c == '>')
	    break;
	  else if (c != ';')
	    {
	      seqlen = seqlen + linelen;
	      if (seqlen + 512 >= buflen)
		{
		  buflen = buflen + 10240;
		  tmp = realloc (buffer, buflen + 1);
		  if (tmp == NULL)
		    return -1;
		  buffer = tmp;
		  x = &(buffer[seqlen]);
		}
	      else
		x = &(x[linelen]);
	      x[0] = 0;
	    }
	}
    }
  for (i = 0; i < seqlen; i++)
    buffer[i] = toupper (buffer[i]);
  write_frequencies (1, buffer, seqlen);
  write_frequencies (2, buffer, seqlen);
  write_count ("GGT", buffer, seqlen);
  write_count ("GGTA", buffer, seqlen);
  write_count ("GGTATT", buffer, seqlen);
  write_count ("GGTATTTTAATT", buffer, seqlen);
  write_count ("GGTATTTTAATTTATAGT", buffer, seqlen);
  free (buffer);
  return 0;
}
示例#2
0
int
main (int argc, char **argv)
{
    struct bloch_sim *b = malloc(sizeof(*b));

    int option = 0;

    realtype p_0 = 0.0;
    realtype p_1 = 0.0;

    int num_cells = 9;

    int freq_write_flag = 0;
    char *freq_file_str;
    int env_write_flag = 0;
    char *env_file_str;
    // int param_write_flag;



    while ((option = getopt(argc, argv,"l:q:h:e:c:")) != -1)
    {
        switch (option)
        {
            case 'l' :
                p_0 = strtod(optarg, NULL);
                break;

            case 'q' :
                p_1 = strtod(optarg, NULL);
                break;

            case 'h' :
                freq_write_flag = 1;
                freq_file_str = optarg;
                break;

            case 'e' :
                env_write_flag = 1;
                env_file_str = optarg;
                break;

            case 'c':
                num_cells = atoi(optarg);

            default:
                //print_usage();
                break;
        }
    }


    initialize_bloch(b, p_0, p_1, num_cells);
    simulate_nmr_pulse(b);

    if (freq_write_flag)
    {
        FILE *freq_file = fopen(freq_file_str, "w");
        if (freq_file == NULL) {
            fprintf(stderr, "ERROR: failed to open frequency output file!\n");
            exit(1);
        }
        write_frequencies(b, freq_file);
        fclose(freq_file);
    }

    if (env_write_flag)
    {
        FILE *env_file = fopen(env_file_str, "w");
        if (env_file == NULL) {
            fprintf(stderr, "ERROR: failed to open envelope output file!\n");
            exit(1);
        }
        write_envelope(b, env_file);
        fclose(env_file);
    }

    free_bloch(b);
    return 0;
}