Example #1
0
int read_subbands(float *fdata, int *delays, int numsubbands,
                  struct spectra_info *s, int transpose, int *padding,
                  int *maskchans, int *nummasked, mask * obsmask)
// This routine reads a spectral block/subint from the input raw data
// files. The routine uses dispersion delays in 'delays' to
// de-disperse the data into 'numsubbands' subbands.  It stores the
// resulting data in vector 'fdata' of length 'numsubbands' *
// 's->spectra_per_subint'.  The low freq subband is stored first,
// then the next highest subband etc, with 's->spectra_per_subint'
// floating points per subband.  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 which 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.
// If 'transpose'==0, the data will be kept in time order instead of
// arranged by subband as above.
{
   static int firsttime = 1;
   static float *frawdata;

   if (firsttime) {
       // Needs to be twice as large for buffering if adding observations together
       frawdata = gen_fvect(2 * s->num_channels * s->spectra_per_subint);
       if (!s->get_rawblock(frawdata, s, padding)) {
           fprintf(stderr, "Error: problem reading the raw data file in read_subbands()\n");
           return 0;
       }
       if (0 != prep_subbands(fdata, frawdata, delays, numsubbands, s,
                              transpose, maskchans, nummasked, obsmask)) {
           fprintf(stderr, "Error: problem initializing prep_subbands() in read_subbands()\n");
           return 0;
       }
       firsttime = 0;
   }
   if (!s->get_rawblock(frawdata, s, padding)) {
       return 0;
   }
   if (prep_subbands(fdata, frawdata, delays, numsubbands, s, transpose,
                     maskchans, nummasked, obsmask)==s->spectra_per_subint) {
       currentspectra += s->spectra_per_subint;
       return s->spectra_per_subint;
   } else {
       return 0;
   }
}
Example #2
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;
}