/* * print a clips linked list */ void print_clips_list( CLIPS *clips) { /* * print the clips linked list structure */ while( clips) { print_clips( clips); clips = clips->next; } return; }
int main(int argc, char *argv[]) { Cmdline *cmd; struct psrfits pfi, pfo; // input and output struct subband_info si; int stat=0, padding=0, userN=0; // 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); // Open the input PSRFITs files psrfits_set_files(&pfi, cmd->argc, cmd->argv); // Use the dynamic filename allocation if (pfi.numfiles==0) pfi.filenum = cmd->startfile; pfi.tot_rows = pfi.N = pfi.T = pfi.status = 0; int rv = psrfits_open(&pfi); if (rv) { fits_report_error(stderr, rv); exit(1); } // Read the user weights if requested si.userwgts = NULL; if (cmd->wgtsfileP) { read_weights(cmd->wgtsfile, &userN, &si.userwgts); if (userN != pfi.hdr.nchan) { printf("Error!: Input data has %d channels, but '%s' contains only %d weights!\n", pfi.hdr.nchan, cmd->wgtsfile, userN); exit(0); } printf("Overriding input channel weights with those in '%s'\n", cmd->wgtsfile); } // Initialize the subbanding // (including reading the first row of data and // putting it in si->fbuffer) init_subbanding(&pfi, &pfo, &si, cmd); if (cmd->outputbasenameP) strcpy(pfo.basefilename, cmd->outputbasename); // Loop through the data do { // Put the overlapping parts from the next block into si->buffer float *ptr = pfi.sub.fdata + si.buflen * si.bufwid; if (padding==0) stat = psrfits_read_part_DATA(&pfi, si.max_overlap, si.numunsigned, ptr); if (stat || padding) { // Need to use padding since we ran out of data printf("Adding a missing row (#%d) of padding to the subbands.\n", pfi.tot_rows); // Now fill the last part of si->fbuffer with the chan_avgs so that // it acts like a correctly read block (or row) fill_chans_with_avgs(si.max_overlap, si.bufwid, ptr, si.chan_avgs); } //print_raw_chan_stats(pfi.sub.data, pfi.hdr.nsblk, // pfi.hdr.nchan, pfi.hdr.npol); // if the input data isn't 8 bit, unpack: if (pfi.hdr.nbits == 2) pf_unpack_2bit_to_8bit(&pfi, si.numunsigned); else if (pfi.hdr.nbits == 4) pf_unpack_4bit_to_8bit(&pfi, si.numunsigned); if ((pfo.hdr.ds_time_fact == 1) && (pfo.hdr.ds_freq_fact == 1)) { // No subbanding is needed, so just copy the float buffer // This is useful if we are just changing the number of bits // Could do it without a copy by simply exchanging pointers // to the fdata buffers in pfo and pfi... memcpy(pfo.sub.fdata, pfi.sub.fdata, pfi.hdr.nsblk * pfi.hdr.npol * pfi.hdr.nchan * sizeof(float)); } else { // Now create the subbanded row in the output buffer make_subbands(&pfi, &si); } // Output only Stokes I (in place via floats) if (pfo.hdr.onlyI && pfo.hdr.npol==4) get_stokes_I(&pfo); // Downsample in time (in place via floats) if (pfo.hdr.ds_time_fact > 1) downsample_time(&pfo); // Compute new scales and offsets so that we can pack // into 8-bits reliably if (pfo.rownum == 1) new_scales_and_offsets(&pfo, si.numunsigned, cmd); // Convert the floats back to bytes in the output array un_scale_and_offset_data(&pfo, si.numunsigned); //print_raw_chan_stats(pfo.sub.data, pfo.hdr.nsblk / pfo.hdr.ds_time_fact, // pfo.hdr.nchan / pfo.hdr.ds_freq_fact, pfo.hdr.npol); // pack into 2 or 4 bits if needed if (pfo.hdr.nbits == 2) pf_pack_8bit_to_2bit(&pfo, si.numunsigned); else if (pfo.hdr.nbits == 4) pf_pack_8bit_to_4bit(&pfo, si.numunsigned); // Write the new row to the output file pfo.sub.offs = (pfo.tot_rows+0.5) * pfo.sub.tsubint; psrfits_write_subint(&pfo); // Break out of the loop here if stat is set if (stat) break; // shift the last part of the current row into the "last-row" // part of the data buffer memcpy(si.fbuffer, si.fbuffer + si.buflen * si.bufwid, si.max_overlap * si.bufwid * sizeof(float)); // Read the next row (or padding) padding = get_current_row(&pfi, &si); // Set the new weights properly new_weights(&pfi, &pfo); } while (pfi.status == 0); print_clips(&pfo); rv = psrfits_close(&pfi); if (rv>100) { fits_report_error(stderr, rv); } rv = psrfits_close(&pfo); if (rv>100) { fits_report_error(stderr, rv); } exit(0); }