void output_fundamentals(fourierprops * props, GSList * list, accelobs * obs, infodata * idata) { double accel = 0.0, accelerr = 0.0, coherent_pow; int ii, jj, numcols = 12, numcands, *width, *error; int widths[12] = { 4, 5, 6, 8, 4, 16, 15, 15, 15, 11, 15, 20 }; int errors[12] = { 0, 0, 0, 0, 0, 1, 1, 2, 1, 2, 2, 0 }; char tmpstr[30], ctrstr[30], *notes; accelcand *cand; GSList *listptr; rzwerrs errs; static char **title; static char *titles1[] = { "", "", "Summed", "Coherent", "Num", "Period", "Frequency", "FFT 'r'", "Freq Deriv", "FFT 'z'", "Accel", "" }; static char *titles2[] = { "Cand", "Sigma", "Power", "Power", "Harm", "(ms)", "(Hz)", "(bin)", "(Hz/s)", "(bins)", "(m/s^2)", "Notes" }; numcands = g_slist_length(list); listptr = list; /* Close the old work file and open the cand file */ if (!obs->dat_input) fclose(obs->workfile); /* Why is this here? -A */ obs->workfile = chkfopen(obs->accelnm, "w"); /* Set our candidate notes to all spaces */ notes = (char *) malloc(numcands * widths[numcols - 1]); memset(notes, ' ', numcands * widths[numcols - 1]); /* Compare the candidates with the pulsar database */ if (dms2rad(idata->ra_h, idata->ra_m, idata->ra_s) != 0.0 && hms2rad(idata->dec_d, idata->dec_m, idata->dec_s) != 0.0) { for (ii = 0; ii < numcands; ii++) { comp_psr_to_cand(props + ii, idata, notes + ii * 20, 0); } } /* Compare the candidates with themselves */ compare_rzw_cands(props, numcands, notes); /* Print the header */ width = widths; title = titles1; for (ii = 0; ii < numcols - 1; ii++) { center_string(ctrstr, *title++, *width++); fprintf(obs->workfile, "%s ", ctrstr); } center_string(ctrstr, *title++, *width++); fprintf(obs->workfile, "%s\n", ctrstr); width = widths; title = titles2; for (ii = 0; ii < numcols - 1; ii++) { center_string(ctrstr, *title++, *width++); fprintf(obs->workfile, "%s ", ctrstr); } center_string(ctrstr, *title++, *width++); fprintf(obs->workfile, "%s\n", ctrstr); width = widths; for (ii = 0; ii < numcols - 1; ii++) { memset(tmpstr, '-', *width); tmpstr[*width++] = '\0'; fprintf(obs->workfile, "%s--", tmpstr); } memset(tmpstr, '-', *width++); tmpstr[widths[ii]] = '\0'; fprintf(obs->workfile, "%s\n", tmpstr); /* Print the fundamentals */ for (ii = 0; ii < numcands; ii++) { width = widths; error = errors; cand = (accelcand *) (listptr->data); calc_rzwerrs(props + ii, obs->T, &errs); { /* Calculate the coherently summed power */ double coherent_r = 0.0, coherent_i = 0.0; double phs0, phscorr, amp; rderivs harm; /* These phase calculations assume the fundamental is best */ /* Better to irfft them and check the amplitude */ phs0 = cand->derivs[0].phs; for (jj = 0; jj < cand->numharm; jj++) { harm = cand->derivs[jj]; if (obs->nph > 0.0) amp = sqrt(harm.pow / obs->nph); else amp = sqrt(harm.pow / harm.locpow); phscorr = phs0 - fmod((jj + 1.0) * phs0, TWOPI); coherent_r += amp * cos(harm.phs + phscorr); coherent_i += amp * sin(harm.phs + phscorr); } coherent_pow = coherent_r * coherent_r + coherent_i * coherent_i; } sprintf(tmpstr, "%-4d", ii + 1); center_string(ctrstr, tmpstr, *width++); error++; fprintf(obs->workfile, "%s ", ctrstr); sprintf(tmpstr, "%.2f", cand->sigma); center_string(ctrstr, tmpstr, *width++); error++; fprintf(obs->workfile, "%s ", ctrstr); sprintf(tmpstr, "%.2f", cand->power); center_string(ctrstr, tmpstr, *width++); error++; fprintf(obs->workfile, "%s ", ctrstr); sprintf(tmpstr, "%.2f", coherent_pow); center_string(ctrstr, tmpstr, *width++); error++; fprintf(obs->workfile, "%s ", ctrstr); sprintf(tmpstr, "%d", cand->numharm); center_string(ctrstr, tmpstr, *width++); error++; fprintf(obs->workfile, "%s ", ctrstr); write_val_with_err(obs->workfile, errs.p * 1000.0, errs.perr * 1000.0, *error++, *width++); write_val_with_err(obs->workfile, errs.f, errs.ferr, *error++, *width++); write_val_with_err(obs->workfile, props[ii].r, props[ii].rerr, *error++, *width++); write_val_with_err(obs->workfile, errs.fd, errs.fderr, *error++, *width++); write_val_with_err(obs->workfile, props[ii].z, props[ii].zerr, *error++, *width++); accel = props[ii].z * SOL / (obs->T * obs->T * errs.f); accelerr = props[ii].zerr * SOL / (obs->T * obs->T * errs.f); write_val_with_err(obs->workfile, accel, accelerr, *error++, *width++); fprintf(obs->workfile, " %.20s\n", notes + ii * 20); fflush(obs->workfile); listptr = listptr->next; } fprintf(obs->workfile, "\n\n"); free(notes); }
void output_harmonics(GSList * list, accelobs * obs, infodata * idata) { int ii, jj, numcols = 13, numcands; int widths[13] = { 5, 4, 5, 15, 11, 18, 13, 12, 9, 12, 10, 10, 20 }; int errors[13] = { 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 2, 2, 0 }; char tmpstr[30], ctrstr[30], notes[21], *command; accelcand *cand; GSList *listptr; fourierprops props; rzwerrs errs; static char *titles1[] = { "", "", "", "Power /", "Raw", "FFT 'r'", "Pred 'r'", "FFT 'z'", "Pred 'z'", "Phase", "Centroid", "Purity", "" }; static char *titles2[] = { "Cand", "Harm", "Sigma", "Loc Pow", "Power", "(bin)", "(bin)", "(bins)", "(bins)", "(rad)", "(0-1)", "<p> = 1", "Notes" }; numcands = g_slist_length(list); listptr = list; /* Print the header */ for (ii = 0; ii < numcols - 1; ii++) { center_string(ctrstr, titles1[ii], widths[ii]); fprintf(obs->workfile, "%s ", ctrstr); } center_string(ctrstr, titles1[ii], widths[ii]); fprintf(obs->workfile, "%s\n", ctrstr); for (ii = 0; ii < numcols - 1; ii++) { if (obs->nph > 0.0 && ii == 3) /* HAAACK!!! */ center_string(ctrstr, "NumPhot", widths[ii]); else center_string(ctrstr, titles2[ii], widths[ii]); fprintf(obs->workfile, "%s ", ctrstr); } center_string(ctrstr, titles2[ii], widths[ii]); fprintf(obs->workfile, "%s\n", ctrstr); for (ii = 0; ii < numcols - 1; ii++) { memset(tmpstr, '-', widths[ii]); tmpstr[widths[ii]] = '\0'; fprintf(obs->workfile, "%s--", tmpstr); } memset(tmpstr, '-', widths[ii]); tmpstr[widths[ii]] = '\0'; fprintf(obs->workfile, "%s\n", tmpstr); /* Print the fundamentals */ for (ii = 0; ii < numcands; ii++) { cand = (accelcand *) (listptr->data); for (jj = 0; jj < cand->numharm; jj++) { if (obs->nph > 0.0) { double tmp_locpow; tmp_locpow = cand->derivs[jj].locpow; cand->derivs[jj].locpow = obs->nph; calc_props(cand->derivs[jj], cand->hirs[jj], cand->hizs[jj], 0.0, &props); cand->derivs[jj].locpow = tmp_locpow; } else { calc_props(cand->derivs[jj], cand->hirs[jj], cand->hizs[jj], 0.0, &props); } calc_rzwerrs(&props, obs->T, &errs); comp_psr_to_cand(&props, idata, notes, 0); if (jj == 0) sprintf(tmpstr, " %-4d", ii + 1); else sprintf(tmpstr, " "); center_string(ctrstr, tmpstr, widths[0]); fprintf(obs->workfile, "%s ", ctrstr); sprintf(tmpstr, "%-4d", jj + 1); center_string(ctrstr, tmpstr, widths[1]); fprintf(obs->workfile, "%s ", ctrstr); sprintf(tmpstr, "%.2f", candidate_sigma(props.pow, 1, 1)); center_string(ctrstr, tmpstr, widths[2]); fprintf(obs->workfile, "%s ", ctrstr); write_val_with_err(obs->workfile, props.pow, props.powerr, errors[3], widths[3]); sprintf(tmpstr, "%.3g", props.rawpow); center_string(ctrstr, tmpstr, widths[4]); fprintf(obs->workfile, "%s ", ctrstr); write_val_with_err(obs->workfile, props.r, props.rerr, errors[5], widths[5]); sprintf(tmpstr, "%.2f", cand->r * (jj + 1)); center_string(ctrstr, tmpstr, widths[6]); fprintf(obs->workfile, "%s ", ctrstr); write_val_with_err(obs->workfile, props.z, props.zerr, errors[7], widths[7]); sprintf(tmpstr, "%.2f", cand->z * (jj + 1)); center_string(ctrstr, tmpstr, widths[8]); fprintf(obs->workfile, "%s ", ctrstr); write_val_with_err(obs->workfile, props.phs, props.phserr, errors[9], widths[9]); write_val_with_err(obs->workfile, props.cen, props.cenerr, errors[10], widths[10]); write_val_with_err(obs->workfile, props.pur, props.purerr, errors[11], widths[11]); fprintf(obs->workfile, " %.20s\n", notes); fflush(obs->workfile); } listptr = listptr->next; } fprintf(obs->workfile, "\n\n"); fclose(obs->workfile); command = malloc(strlen(obs->rootfilenm) + strlen(obs->accelnm) + 20); sprintf(command, "cat %s.inf >> %s", obs->rootfilenm, obs->accelnm); system(command); free(command); }
int comp_psr_to_cand(fourierprops * cand, infodata * idata, char *output, int full) /* Compares a pulsar candidate defined by its properties found in */ /* *cand, and *idata with all of the pulsars in the pulsar */ /* database. It returns a string (verbose if full==1) describing */ /* the results of the search in *output. */ { int ii, jj; static infodata *old_idata; double theor, theoz, sidedr = 20.0; double r_criteria, z_criteria, rdiff, zdiff, difft = 0; static double T, beam2, ra, dec, epoch; char tmp1[80], tmp2[80], tmp3[80], shortout[30], psrname[20]; rzwerrs rzws; /* Read the database if needed */ if (!have_database) np = read_database(); /* If calling for the first time for a certain data set, */ /* initialize some values. */ if (idata != old_idata) { /* Convert the beam width to radians */ beam2 = 2.0 * ARCSEC2RAD * idata->fov; /* Convert RA and DEC to radians (Use J2000) */ ra = hms2rad(idata->ra_h, idata->ra_m, idata->ra_s); dec = dms2rad(idata->dec_d, idata->dec_m, idata->dec_s); T = idata->N * idata->dt; epoch = (double) idata->mjd_i + idata->mjd_f + T / (2.0 * SECPERDAY); /* Set up old_idata for next time */ old_idata = idata; } /* Calculate the measured r, z, w's and their derivatives */ calc_rzwerrs(cand, T, &rzws); /* Run through RAs in database looking for things close */ /* If find one, check the DEC as well (the angle between */ /* the sources < 2*beam diam). If find one, check its */ /* period. If this matches within 2*perr, return the */ /* number of the pulsar. If no matches, return 0. */ for (ii = 0; ii < np; ii++) { /* See if we're close in RA */ if (fabs(pulsardata[ii].ra2000 - ra) < 5 * beam2) { /* See if we're close in RA and DEC */ if (sphere_ang_diff(pulsardata[ii].ra2000, pulsardata[ii].dec2000, ra, dec) < 5 * beam2) { /* Predict the period of the pulsar at the observation MJD */ difft = SECPERDAY * (epoch - pulsardata[ii].timepoch); theor = T / (pulsardata[ii].p + pulsardata[ii].pd * difft); theoz = -pulsardata[ii].pd * theor * theor; /* Check the predicted period and its harmonics against the */ /* measured period. */ for (jj = 1; jj < 41; jj++) { /* If the psr from the database is in a */ /* binary orbit, loosen the match criteria. */ /* This accounts for Doppler variations in period. */ if (pulsardata[ii].orb.p != 0.0) { r_criteria = 0.001 * theor * jj; /* 0.1% fractional error */ z_criteria = 9999999999.0; /* Always match for binary */ strcpy(tmp1, "?"); if (full) { strcpy(tmp3, "Possibly (large error) "); } } else { r_criteria = 5.0; /* 5 bin error matching... */ z_criteria = 9999999999.0; /* Always match for binary */ /* z_criteria = 2.5 * cand->zerr; */ strcpy(tmp1, ""); if (full) { strcpy(tmp3, "Looks like "); } } if (theor * jj > 1.5 * cand->r) break; rdiff = fabs(theor * jj - cand->r); zdiff = fabs(theoz * jj - cand->z); if (rdiff < r_criteria && zdiff < z_criteria) { if (strlen(pulsardata[ii].bname) == 0) sprintf(psrname, "J%s", pulsardata[ii].jname); else sprintf(psrname, "B%s", pulsardata[ii].bname); if (jj == 1) { if (full) { sprintf(tmp1, "the fundamental of "); sprintf(tmp2, "PSR %s. (predicted p = %11.7f s).\n", psrname, T / theor); sprintf(output, "%s%s\n %s", tmp3, tmp1, tmp2); } else { sprintf(shortout, "PSR %s%s", psrname, tmp1); strncpy(output, shortout, 20); } } else { if (full) { sprintf(tmp1, "the %s harmonic of ", num[jj]); sprintf(tmp2, "PSR %s. (predicted p = %11.7f s).\n", psrname, T / theor); sprintf(output, "%s%s\n %s", tmp3, tmp1, tmp2); } else { sprintf(shortout, "%s H %s%s", num[jj], psrname, tmp1); strncpy(output, shortout, 20); } } return ii + 1; } else if (rdiff < sidedr) { if (strlen(pulsardata[ii].bname) == 0) sprintf(psrname, "J%s", pulsardata[ii].jname); else sprintf(psrname, "B%s", pulsardata[ii].bname); if (full) { sprintf(tmp1, "a sidelobe of the %s harmonic of ", num[jj]); sprintf(tmp2, "PSR %s. (predicted p = %11.7f s).\n", psrname, T / theor); sprintf(output, "%s%s\n %s", tmp3, tmp1, tmp2); } else { sprintf(shortout, "SL H%d %s", jj, psrname); strncpy(output, shortout, 20); } return ii + 1; } } } } } /* Didn't find a match */ if (full) { sprintf(output, "I don't recognize this candidate in the pulsar database.\n"); } else { strncpy(output, " ", 20); } return 0; }