Exemple #1
0
long long get_WAPP_info(char *filename, FILE * files[], int numfiles, int numwapps,
                        struct HEADERP **h, struct wappinfo *w)
{
    int ii, wappindex;
    struct HEADERP *h2;
    struct wappinfo w2;
    long long N = 0;

    // Read the header of the first file with the yacc/lex generated tools
    // This sets the basic parameters of the conversion
    *h = head_parse(files[0]);
    set_wappinfo(*h, w);
    if (get_hdr_int(*h, "isalfa")) {
        w->beamnum = wapp_beamnum(filename);
        if (w->beamnum == -1) {
            printf("Warning!  isalfa = 1, but beamnum is not set!\n");
            exit(1);
        }
    }
    // Number of samples in the file
    w->numsamples = (chkfilelen(files[0], 1) - w->header_size) / w->bytes_per_sample;
    // This will be the total number of samples to convert
    N = w->numsamples;

    // Skip the ASCII and binary header
    chkfseek(files[0], w->header_size, SEEK_SET);

    // loop through all the other files and check/prep them
    for (ii = 1; ii < numfiles; ii++) {

        // Read the header with the yacc/lex generated tools
        h2 = head_parse(files[ii]);
        set_wappinfo(h2, &w2);
        close_parse(h2);
        // Number of samples in the file
        w2.numsamples = (chkfilelen(files[ii], 1) - w2.header_size) /
            w2.bytes_per_sample;

        // Skip the ASCII and binary header
        chkfseek(files[ii], w2.header_size, SEEK_SET);

        // Do a basic check to see if the files are similar
        wappindex = ii % numwapps;
        if (wappindex == 0) {   // Same WAPP
            if (!compare_samewapp_files(ii, w, &w2))
                exit(1);
            N += w2.numsamples;
        } else {                // Different WAPPs
            if (!compare_diffwapp_files(ii, numwapps, wappindex, w, &w2))
                exit(1);
        }
    }
    return N;
}
Exemple #2
0
static struct _ListNode *Transfer_lyric(const u8 *lrc_buff, size_t size, Node *first)
//int Transfer_lyric()
{
	LrcData data[DATALEN];
	LrcData *p_data = data;
	char lyric_buff[DATALEN];
	char *q = lyric_buff;
	int offset;
	float time[TIMECOUNT][TIME];
//	Node *first = NULL;

	char test[1000] = "   [ti:Shape Of My Heart]\n"
			"[ar:Backstreet Boys]\n"
			"[al:Black And Blue]\n"
			"[by:[email protected]]\n"
			"[offset:500]\n"
//			"[00:03.00]\n"
//			"\n"
			"  [00:04.10]Hmm, yeah, yeah\n"
			"[00:09.80]Baby, please try to forgive me\n"
			"[00:19.50]Stay here don't put out the glow\n"
			"[00:29.17]Hold me now don't bother\n"
//			"[03:11.45][02:51.90][01:48.00][00:47.29]Lookin' back on the things I've done\n"
//			"[03:14.70][02:55.50][01:52.70][00:52.04]I was tryin' to be someone\n"
//			"[03:19.15][02:59.70][01:57.00][00:56.44]I played my part, kept you in the dark\n"
			"[03:24.53][03:05.40][02:47.29][02:02.33][01:01.74]Now let me show you the shape of my heart";
	u8 *p = test;



	while (*p) {
		int flag = 0;
		memset(time, 0, TIMECOUNT * TIME);
		q = lyric_buff;

		while (*p != '\n' && *p) {
			if (*p == '[') {
				p++;
				if (NISNUM(*p)) {
					head_parse(p, &offset);
					continue;
				} else {
					flag += 1;
					while (*p != ':')
						time[flag - 1][0] = time[flag - 1][0] * 10  + (*p++ - '0');

					while (*++p != '.')
						time[flag - 1][1] = time[flag - 1][1] * 10 + (*p - '0');

					while (*++p != ']')
						time[flag - 1][2] = time[flag - 1][2] * 10 + (*p - '0');
				}
			}

			if (*++p != '[' && *p != ' ') {
				while (*p) {
					if (*p == '\n')
						break;
					*q++ = *p++;
				}
				*q = '\0';

				while (flag--) {
					//p_data->str = malloc(512);

					strcpy(p_data->str, lyric_buff);
					p_data->time = time[flag][0] * 60 + time[flag][1] + (time[flag][2] + offset) / 1000 ;

//					printf("%f  ",p_data->time);
//					printf("%s\n",p_data->str);
					first = InsertList(first, *p_data);
					//p_data++;
				}
			}
		}
		p++;
	}

	traverselist(first);
	return first;
}
Exemple #3
0
int main(int argc, char **argv)
{
   int index = -1, need_type = 0;
   int objs_read, objs_to_read, has_suffix;
   long i, j, ct;
   char *cptr, *data, *short_filenm, *extension, key = '\n';
   FILE *infile;
   Cmdline *cmd;
   infodata inf;

   /* Call usage() if we have no command line arguments */

   if (argc == 1) {
      Program = argv[0];
      usage();
      exit(0);
   }

   /* Parse the command line using the excellent program Clig */

   cmd = parseCmdline(argc, argv);

#ifdef DEBUG
   showOptionValues();
#endif

   //fprintf(stdout, "\n\n  PRESTO Binary File Reader\n");
   //fprintf(stdout, "     by Scott M. Ransom\n\n");

   /* Set our index value */

   if (cmd->bytP || cmd->sbytP)
      index = BYTE;
   else if (cmd->fltP || cmd->sfltP)
      index = FLOAT;
   else if (cmd->dblP || cmd->sdblP)
      index = DOUBLE;
   else if (cmd->fcxP || cmd->sfcxP)
      index = FCPLEX;
   else if (cmd->dcxP || cmd->sdcxP)
      index = DCPLEX;
   else if (cmd->shtP || cmd->sshtP)
      index = SHORT;
   else if (cmd->igrP || cmd->sigrP)
      index = INT;
   else if (cmd->lngP || cmd->slngP)
      index = LONG;
   else if (cmd->rzwP || cmd->srzwP)
      index = RZWCAND;
   else if (cmd->binP || cmd->sbinP)
      index = BINCAND;
   else if (cmd->posP || cmd->sposP)
      index = POSITION;
   else if (cmd->pkmbP)
      index = PKMBHDR;
   else if (cmd->bcpmP)
      index = BCPMHDR;
   else if (cmd->wappP)
      index = WAPPHDR;
   else if (cmd->spigotP)
      index = SPIGOTHDR;
   else if (cmd->filterbankP)
      index = SPECTRAINFO;
#ifdef USELOFAR   
   else if (cmd->lofarhdf5P)
      index = SPECTRAINFO;
#endif
   else if (cmd->psrfitsP)
      index = SPECTRAINFO;
   
   /* Try to determine the data type from the file name */

   if (index == -1) {
      has_suffix = split_root_suffix(cmd->argv[0], &short_filenm, &extension);
      if (!has_suffix) {
         need_type = 1;
      } else {
         if (strlen(extension) < 2) {
            need_type = 1;
         } else {
            if (0 == strcmp(extension, "dat")) {
               index = FLOAT;
               fprintf(stdout, "Assuming the data is floating point.\n\n");
            } else if (0 == strcmp(extension, "sdat")) {
               index = SHORT;
               fprintf(stdout, "Assuming the data is short integers.\n\n");
            } else if (0 == strcmp(extension, "fft")) {
               index = FCPLEX;
               fprintf(stdout, "Assuming the data is single precision complex.\n\n");
            } else if ((0 == strcmp(extension, "fits")) ||
                       (0 == strcmp(extension, "sf"))) {
                if (strstr(short_filenm, "spigot_5") != NULL) {
                    cmd->spigotP = 1;
                    index = SPIGOTHDR;
                    fprintf(stdout,
                            "Assuming the data is from the Caltech/NRAO Spigot.\n\n");
                } else if (is_PSRFITS(cmd->argv[0])) {
                    cmd->psrfitsP = 1;
                    index = SPECTRAINFO;
                    fprintf(stdout,
                            "Assuming the data is in PSRFITS format.\n\n");
                }
            } else if (0 == strcmp(extension, "bcpm1") ||
                       0 == strcmp(extension, "bcpm2")) {
               cmd->bcpmP = 1;
               index = BCPMHDR;
               fprintf(stdout, "Assuming the data is from a BCPM machine.\n\n");
            } else if (0 == strcmp(extension, "pkmb")) {
               cmd->pkmbP = 1;
               index = PKMBHDR;
               fprintf(stdout,
                       "Assuming the data is from the Parkes Multibeam machine.\n\n");
            } else if (0 == strcmp(extension, "fil") || 0 == strcmp(extension, "fb")) {
               cmd->filterbankP = 1;
               index = SPECTRAINFO;
               fprintf(stdout,
                       "Assuming the data is a SIGPROC filterbank file.\n\n");
            } else if (0 == strcmp(extension, "h5")) {
               cmd->lofarhdf5P = 1;
               index = SPECTRAINFO;
               fprintf(stdout,
                       "Assuming the data is a LOFAR HDF5 file.\n\n");
            } else if (isdigit(extension[0]) &&
                       isdigit(extension[1]) && isdigit(extension[2])) {
               cmd->wappP = 1;
               index = WAPPHDR;
               fprintf(stdout, "Assuming the data is from a WAPP machine.\n\n");
            } else if (0 == strcmp(extension, "pos")) {
               index = POSITION;
               fprintf(stdout,
                       "Assuming the data contains 'position' structures.\n\n");
            } else if (0 == strcmp(extension, "cand")) {
               /* A binary or RZW search file? */
               if (NULL != (cptr = strstr(cmd->argv[0], "_bin"))) {
                  index = BINCAND;
                  fprintf(stdout,
                          "Assuming the file contains binary candidates.\n\n");
               } else if (NULL != (cptr = strstr(cmd->argv[0], "_rzw"))) {
                  index = RZWCAND;
                  ct = (long) (cptr - cmd->argv[0]);
                  fprintf(stdout, "Assuming the file contains 'RZW' candidates.\n");
                  free(short_filenm);
                  short_filenm = (char *) malloc(ct + 1);
                  short_filenm[ct] = '\0';
                  strncpy(short_filenm, cmd->argv[0], ct);
                  fprintf(stdout, "\nAttempting to read '%s.inf'.  ", short_filenm);
                  readinf(&inf, short_filenm);
                  fprintf(stdout, "Successful.\n");
                  N = (long) (inf.N + DBLCORRECT);
                  dt = inf.dt;
                  if (cmd->nphP)
                     nph = cmd->nph;
                  else
                     nph = 1.0;
                  fprintf(stdout,
                          "\nUsing N = %ld, dt = %g, and DC Power = %f\n\n",
                          N, dt, nph);
               } else if (NULL != (cptr = strstr(cmd->argv[0], "_ACCEL"))) {
                  index = RZWCAND;
                  ct = (long) (cptr - cmd->argv[0]);
                  fprintf(stdout, "Assuming the file contains 'RZW' candidates.\n");
                  free(short_filenm);
                  short_filenm = (char *) malloc(ct + 1);
                  short_filenm[ct] = '\0';
                  strncpy(short_filenm, cmd->argv[0], ct);
                  fprintf(stdout, "\nAttempting to read '%s.inf'.  ", short_filenm);
                  readinf(&inf, short_filenm);
                  fprintf(stdout, "Successful.\n");
                  N = (long) (inf.N + DBLCORRECT);
                  dt = inf.dt;
                  if (cmd->nphP)
                     nph = cmd->nph;
                  else
                     nph = 1.0;
                  fprintf(stdout,
                          "\nUsing N = %ld, dt = %g, and DC Power = %f\n\n",
                          N, dt, nph);
               } else
                  need_type = 1;
            } else
               need_type = 1;
         }
      }

      /* If no file extension or if we don't understand the extension, exit */

      if (need_type) {
         fprintf(stdout, "You must specify a data type for this file.\n\n");
         free(short_filenm);
         exit(-1);
      }
      free(short_filenm);
      if (has_suffix)
         free(extension);
   }

   if (cmd->index[1] == -1 || cmd->index[1] == 0)
      cmd->index[1] = INT_MAX;
   if (cmd->index[1] < cmd->index[0]) {
      fprintf(stdout, "\nThe high index must be >= the low index.");
      fprintf(stdout, "  Exiting.\n\n");
      exit(-1);
   }

   // Use new-style backend reading stuff
   if (cmd->psrfitsP || cmd->filterbankP || cmd->lofarhdf5P) {
       struct spectra_info s;

       // Eventually we should use this...
       // identify_psrdatatype(struct spectra_info *s, int output);
       spectra_info_set_defaults(&s);
       if (cmd->psrfitsP) s.datatype=PSRFITS;
       if (cmd->filterbankP) s.datatype=SIGPROCFB;
       if (cmd->lofarhdf5P) s.datatype=LOFARHDF5;
       s.filenames = cmd->argv;
       s.num_files = cmd->argc;
       s.clip_sigma = 0.0;
       s.apply_flipband = s.apply_weight = s.apply_scale = s.apply_offset = -1;
       s.remove_zerodm = 0;
       read_rawdata_files(&s);
       SPECTRAINFO_print(0, (char *)(&s));
       printf("\n");
       exit(0);
   }

   if (cmd->spigotP) {
      SPIGOT_INFO spigot;

      if (read_SPIGOT_header(cmd->argv[0], &spigot)) {
         print_SPIGOT_header(&spigot);
         printf("\n");
      } else {
         printf("\n  Error reading spigot file!\n\n");
      }
      exit(0);
   }

   if (cmd->wappP) {
       struct HEADERP *hdr = NULL;
       
       infile = chkfopen(cmd->argv[0], "rb");
       hdr = head_parse(infile);
       set_WAPP_HEADER_version(hdr);
       if (hdr) {
           print_WAPP_hdr(hdr);
           printf("\n");
       } else {
           printf("\n  Error reading WAPP file!\n\n");
       }
       exit(0);
   }

   /* Open the file */

   infile = chkfopen(cmd->argv[0], "rb");

   if (cmd->fortranP) {
      chkfileseek(infile, 1, sizeof(long), SEEK_SET);
   }

   /* Skip to the correct first object */

   if (cmd->index[0] > 0) {
      chkfileseek(infile, (long) (cmd->index[0]), type_sizes[index], SEEK_CUR);
   }

   /* Read the file */

   objs_to_read = objs_at_a_time[index];
   data = (char *) malloc(type_sizes[index] * objs_at_a_time[index]);

   i = cmd->index[0];
   do {
      if (objs_to_read > cmd->index[1] - i)
         objs_to_read = cmd->index[1] - i;
      objs_read = chkfread(data, type_sizes[index], objs_to_read, infile);
      for (j = 0; j < objs_read; j++)
         print_funct_ptrs[index] (i + j, data + j * type_sizes[index]);
      /* Just print 1 header for BCPM and WAPP files */
      if (index == BCPMHDR || index == WAPPHDR || index == SPIGOTHDR)
         break;
      i += objs_read;
      if (cmd->pageP) {
         fflush(NULL);
         fprintf(stdout, "\nPress ENTER for next page, or any other key and ");
         fprintf(stdout, "then ENTER to exit.\n\n");
         key = getchar();
      }
   } while (!feof(infile) && i < cmd->index[1] && key == '\n');

   fflush(NULL);
   if (feof(infile)) {
      fprintf(stdout, "\nEnd of file.\n\n");
   }

   free(data);
   fclose(infile);
   exit(0);
}