int read_psrdata(float *fdata, int numspect, struct spectra_info *s, int *delays, int *padding, int *maskchans, int *nummasked, mask * obsmask) // This routine reads numspect from the raw pulsar data defined in // "s". Time delays and a mask are applied to each channel. It // returns the # of points read if successful, 0 otherwise. If // padding is returned as 1, then padding was added and statistics // should not be calculated. maskchans is an array of length numchans // contains a list of the number of channels that were masked. The # // of channels masked is returned in nummasked. obsmask is the mask // structure to use for masking. { int ii, jj, numread = 0, offset; double starttime = 0.0; static float *tmpswap, *rawdata1, *rawdata2; static float *currentdata, *lastdata; static int firsttime = 1, numsubints = 1, allocd = 0, mask = 0; static double duration = 0.0; *nummasked = 0; if (firsttime) { if (numspect % s->spectra_per_subint) { fprintf(stderr, "Error!: numspect %d must be a multiple of %d in read_psrdata()!\n", numspect, s->spectra_per_subint); exit(1); } else numsubints = numspect / s->spectra_per_subint; if (obsmask->numchan) mask = 1; rawdata1 = gen_fvect(numsubints * s->spectra_per_subint * s->num_channels); rawdata2 = gen_fvect(numsubints * s->spectra_per_subint * s->num_channels); allocd = 1; duration = numsubints * s->time_per_subint; currentdata = rawdata1; lastdata = rawdata2; } /* Read, convert and de-disperse */ if (allocd) { while (1) { starttime = currentspectra * s->dt; numread = read_rawblocks(currentdata, numsubints, s, padding); if (mask) *nummasked = check_mask(starttime, duration, obsmask, maskchans); currentspectra += numread * s->spectra_per_subint; /* Clip nasty RFI if requested and we're not masking all the channels */ if ((s->clip_sigma > 0.0) && !(mask && (*nummasked == -1))) clip_times(currentdata, numspect, s->num_channels, s->clip_sigma, s->padvals); if (mask) { if (*nummasked == -1) { /* If all channels are masked */ for (ii = 0; ii < numspect; ii++) memcpy(currentdata + ii * s->num_channels, s->padvals, s->num_channels * sizeof(float)); } else if (*nummasked > 0) { /* Only some of the channels are masked */ int channum; for (ii = 0; ii < numspect; ii++) { offset = ii * s->num_channels; for (jj = 0; jj < *nummasked; jj++) { channum = maskchans[jj]; currentdata[offset + channum] = s->padvals[channum]; } } } } if (!firsttime) float_dedisp(currentdata, lastdata, numspect, s->num_channels, delays, 0.0, fdata); SWAP(currentdata, lastdata); if (numread != numsubints) { vect_free(rawdata1); vect_free(rawdata2); allocd = 0; } if (firsttime) firsttime = 0; else break; } return numsubints * s->spectra_per_subint; } else { return 0; } }
static int get_data(float **outdata, int blocksperread, struct spectra_info *s, mask * obsmask, int *idispdts, int **offsets, int *padding) { static int firsttime = 1, *maskchans = NULL, blocksize; static int worklen, dsworklen; static float *tempzz, *data1, *data2, *dsdata1 = NULL, *dsdata2 = NULL; static float *currentdata, *lastdata, *currentdsdata, *lastdsdata; static float *frawdata; static double blockdt; int totnumread = 0, gotblock = 0, numread = 0; int ii, jj, tmppad = 0, nummasked = 0; if (firsttime) { if (cmd->maskfileP) maskchans = gen_ivect(insubs ? s->num_files : s->num_channels); worklen = s->spectra_per_subint * blocksperread; dsworklen = worklen / cmd->downsamp; blocksize = s->spectra_per_subint * cmd->nsub; blockdt = s->spectra_per_subint * s->dt; if (RAWDATA) { frawdata = gen_fvect(2 * s->num_channels * s->spectra_per_subint); // To initialize the data reading and prep_subbands routines firsttime = 2; } data1 = gen_fvect(cmd->nsub * worklen); data2 = gen_fvect(cmd->nsub * worklen); currentdata = data1; lastdata = data2; if (cmd->downsamp > 1) { dsdata1 = gen_fvect(cmd->nsub * dsworklen); dsdata2 = gen_fvect(cmd->nsub * dsworklen); currentdsdata = dsdata1; lastdsdata = dsdata2; } else { currentdsdata = data1; lastdsdata = data2; } { // Make sure that our working blocks are long enough... int testlen = insubs ? s->num_files : s->num_channels; for (ii = 0; ii < testlen; ii++) { if (idispdts[ii] > worklen) printf("WARNING! (myid = %d): (idispdts[%d] = %d) > (worklen = %d)\n", myid, ii, idispdts[ii], worklen); } for (ii = 0; ii < local_numdms; ii++) { for (jj = 0; jj < cmd->nsub; jj++) { if (offsets[ii][jj] > dsworklen) printf("WARNING! (myid = %d): (offsets[%d][%d] = %d) > (dsworklen = %d)\n", myid, ii, jj, offsets[ii][jj], dsworklen); } } } } while (1) { if (RAWDATA) { for (ii = 0; ii < blocksperread; ii++) { if (myid == 0) { gotblock = s->get_rawblock(frawdata, s, &tmppad); if (gotblock && !firsttime) totnumread += s->spectra_per_subint; } MPI_Bcast(&gotblock, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(&tmppad, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(frawdata, s->num_channels * s->spectra_per_subint, MPI_FLOAT, 0, MPI_COMM_WORLD); if (myid > 0) { if (gotblock) { numread = prep_subbands(currentdata + ii * blocksize, frawdata, idispdts, cmd->nsub, s, 0, maskchans, &nummasked, obsmask); if (!firsttime) totnumread += numread; } else { *padding = 1; for (jj = ii * blocksize; jj < (ii + 1) * blocksize; jj++) currentdata[jj] = 0.0; } if (tmppad) *padding = 1; } } } else if (insubs) { short *subsdata = NULL; subsdata = gen_svect(SUBSBLOCKLEN * s->num_files); for (ii = 0; ii < blocksperread; ii++) { if (myid == 0) numread = simple_read_subbands(s->files, s->num_files, subsdata); MPI_Bcast(&numread, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(subsdata, SUBSBLOCKLEN * s->num_files, MPI_SHORT, 0, MPI_COMM_WORLD); convert_subbands(s->num_files, subsdata, currentdata + ii * blocksize, blockdt, maskchans, &nummasked, obsmask, cmd->clip, s->padvals); if (!firsttime) totnumread += numread; } vect_free(subsdata); } /* Downsample the subband data if needed */ if (myid > 0) { if (cmd->downsamp > 1) { int kk, offset, dsoffset, index, dsindex; float ftmp; for (ii = 0; ii < dsworklen; ii++) { dsoffset = ii * cmd->nsub; offset = dsoffset * cmd->downsamp; for (jj = 0; jj < cmd->nsub; jj++) { dsindex = dsoffset + jj; index = offset + jj; currentdsdata[dsindex] = 0.0; for (kk = 0, ftmp = 0.0; kk < cmd->downsamp; kk++) { ftmp += currentdata[index]; index += cmd->nsub; } currentdsdata[dsindex] += ftmp / cmd->downsamp; } } } } if (firsttime) { SWAP(currentdata, lastdata); SWAP(currentdsdata, lastdsdata); firsttime -= 1; } else break; } if (myid > 0) { for (ii = 0; ii < local_numdms; ii++) float_dedisp(currentdsdata, lastdsdata, dsworklen, cmd->nsub, offsets[ii], 0.0, outdata[ii]); } SWAP(currentdata, lastdata); SWAP(currentdsdata, lastdsdata); if (totnumread != worklen) { if (cmd->maskfileP) vect_free(maskchans); vect_free(data1); vect_free(data2); if (RAWDATA) vect_free(frawdata); if (cmd->downsamp > 1) { vect_free(dsdata1); vect_free(dsdata2); } } return totnumread; }
static int get_data(float **outdata, int blocksperread, struct spectra_info *s, mask * obsmask, int *idispdts, int **offsets, int *padding, short **subsdata) { static int firsttime = 1, *maskchans = NULL, blocksize; static int worklen, dsworklen; static float *tempzz, *data1, *data2, *dsdata1 = NULL, *dsdata2 = NULL; static float *currentdata, *lastdata, *currentdsdata, *lastdsdata; static double blockdt; int totnumread = 0, numread = 0, ii, jj, tmppad = 0, nummasked = 0; if (firsttime) { if (cmd->maskfileP) maskchans = gen_ivect(s->num_channels); worklen = s->spectra_per_subint * blocksperread; dsworklen = worklen / cmd->downsamp; // Make sure that our working blocks are long enough... for (ii = 0; ii < cmd->numdms; ii++) { for (jj = 0; jj < cmd->nsub; jj++) { if (offsets[ii][jj] > dsworklen) printf ("WARNING!: (offsets[%d][%d] = %d) > (dsworklen = %d)\n", ii, jj, offsets[ii][jj], dsworklen); } } blocksize = s->spectra_per_subint * cmd->nsub; blockdt = s->spectra_per_subint * s->dt; data1 = gen_fvect(cmd->nsub * worklen); data2 = gen_fvect(cmd->nsub * worklen); currentdata = data1; lastdata = data2; if (cmd->downsamp > 1) { dsdata1 = gen_fvect(cmd->nsub * dsworklen); dsdata2 = gen_fvect(cmd->nsub * dsworklen); currentdsdata = dsdata1; lastdsdata = dsdata2; } else { currentdsdata = data1; lastdsdata = data2; } } while (1) { if (RAWDATA || insubs) { for (ii = 0; ii < blocksperread; ii++) { if (RAWDATA) numread = read_subbands(currentdata + ii * blocksize, idispdts, cmd->nsub, s, 0, &tmppad, maskchans, &nummasked, obsmask); else if (insubs) numread = read_PRESTO_subbands(s->files, s->num_files, currentdata + ii * blocksize, blockdt, maskchans, &nummasked, obsmask, cmd->clip, s->padvals); if (!firsttime) totnumread += numread; if (numread != s->spectra_per_subint) { for (jj = ii * blocksize; jj < (ii + 1) * blocksize; jj++) currentdata[jj] = 0.0; } if (tmppad) *padding = 1; } } /* Downsample the subband data if needed */ if (cmd->downsamp > 1) { int kk, index; float ftmp; for (ii = 0; ii < dsworklen; ii++) { const int dsoffset = ii * cmd->nsub; const int offset = dsoffset * cmd->downsamp; for (jj = 0; jj < cmd->nsub; jj++) { const int dsindex = dsoffset + jj; index = offset + jj; currentdsdata[dsindex] = ftmp = 0.0; for (kk = 0; kk < cmd->downsamp; kk++) { ftmp += currentdata[index]; index += cmd->nsub; } currentdsdata[dsindex] += ftmp / cmd->downsamp; } } } if (firsttime) { SWAP(currentdata, lastdata); SWAP(currentdsdata, lastdsdata); firsttime = 0; } else break; } if (!cmd->subP) { for (ii = 0; ii < cmd->numdms; ii++) float_dedisp(currentdsdata, lastdsdata, dsworklen, cmd->nsub, offsets[ii], 0.0, outdata[ii]); } else { /* Input format is sub1[0], sub2[0], sub3[0], ..., sub1[1], sub2[1], sub3[1], ... */ float infloat; for (ii = 0; ii < cmd->nsub; ii++) { for (jj = 0; jj < dsworklen; jj++) { infloat = lastdsdata[ii + (cmd->nsub * jj)]; subsdata[ii][jj] = (short) (infloat + 0.5); //if ((float) subsdata[ii][jj] != infloat) // printf // ("Warning: We are incorrectly converting subband data! float = %f short = %d\n", // infloat, subsdata[ii][jj]); } } } SWAP(currentdata, lastdata); SWAP(currentdsdata, lastdsdata); if (totnumread != worklen) { if (cmd->maskfileP) vect_free(maskchans); vect_free(data1); vect_free(data2); if (cmd->downsamp > 1) { vect_free(dsdata1); vect_free(dsdata2); } } return totnumread; }