/*********************************************************************** * * Name : process_jnl_field_trim() * * Description: Processes the JNL_FEED_LAYOUT.jnl_field_trim values. * It calls the trim library function in jnl_aux.c * Inputs : None * Outputs : None * Returns : None * **********************************************************************/ int process_jnl_field_trim(tiny command, char *string, tiny size) { switch(command) { case FIELD_TRIM_TRIM_RIGHT: return(trim_string(TRIM_RIGHT, string, size)); case FIELD_TRIM_TRIM_LEFT: return(trim_string(TRIM_LEFT, string, size)); case FIELD_TRIM_FILL_RIGHT: return(fill_string(FILL_RIGHT, string, size, ' ')); case FIELD_TRIM_FILL_LEFT: return(fill_string(FILL_LEFT, string, size, ' ')); case FIELD_TRIM_FILL_ZERO_RIGHT: return(fill_string(FILL_RIGHT, string, size, '0')); case FIELD_TRIM_FILL_ZERO_LEFT: return(fill_string(FILL_LEFT, string, size, '0')); case FIELD_TRIM_CENTER: return(center_string(string, size)); case FIELD_TRIM_NO_TRIM: break; default: break; } return(FAILURE); }
static void write_val_with_err(FILE * outfile, double val, double err, int numerr, int width) { int retval; char tmpstr[30], ctrstr[30]; if (numerr == 1) retval = nice_output_1(tmpstr, val, err, 0); else if (numerr == 2) retval = nice_output_2(tmpstr, val, err, 0); else printf("\numerr = %d is out-of-range (1-2) in write_val_with_err()\n", numerr); center_string(ctrstr, tmpstr, width); fprintf(outfile, "%s ", ctrstr); }
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); }
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); }
/** * Display a "tomb-stone" */ static void print_tomb(void) { cptr p; int offset = 12; char tmp[160]; char buf[1024]; ang_file *fp; #ifdef _WIN32_WCE time_t ct = fake_time((time_t) 0); #else time_t ct = time((time_t) 0); #endif bool boat = ((p_ptr->total_winner) && (player_has(PF_ELVEN))); bool tree = ((p_ptr->total_winner) && (player_has(PF_WOODEN) || player_has(PF_DIVINE))); /* Clear screen */ Term_clear(); /* Build the filename */ if (tree) path_build(buf, 1024, ANGBAND_DIR_FILE, "tree.txt"); else if (boat) path_build(buf, 1024, ANGBAND_DIR_FILE, "boat.txt"); else path_build(buf, 1024, ANGBAND_DIR_FILE, "dead.txt"); /* Open the News file */ fp = file_open(buf, MODE_READ, FTYPE_TEXT); /* Dump */ if (fp) { int i, y, x; byte a = 0; char c = ' '; bool okay = TRUE; int len; /* Load the screen */ for (y = 0; okay; y++) { /* Get a line of data */ if (!file_getl(fp, buf, 1024)) okay = FALSE; /* Stop on blank line */ if (!buf[0]) break; /* Get the width */ len = strlen(buf); /* XXX Restrict to current screen size */ if (len >= Term->wid) len = Term->wid; /* Show each row */ for (x = 0; x < len; x++) { /* Put the attr/char */ Term_draw(x, y, TERM_WHITE, buf[x]); } } /* Get the blank line */ /* if (my_fgets(fp, buf, 1024)) okay = FALSE; */ /* Load the screen */ for (y = 0; okay; y++) { /* Get a line of data */ if (!file_getl(fp, buf, 1024)) okay = FALSE; /* Stop on blank line */ if (!buf[0]) break; /* Get the width */ len = strlen(buf); /* XXX Restrict to current screen size */ if (len >= Term->wid) len = Term->wid; /* Show each row */ for (x = 0; x < len; x++) { /* Get the attr/char */ (void) (Term_what(x, y, &a, &c)); /* Look up the attr */ for (i = 0; i < 16; i++) { /* Use attr matches */ if (hack[i] == buf[x]) a = i; } /* Put the attr/char */ Term_draw(x, y, a, c); } /* Place the cursor */ Term_gotoxy(x, y); } /* Get the blank line */ /* if (my_fgets(fp, buf, 1024)) okay = FALSE; */ /* Close it */ file_close(fp); } /* King or Queen */ if (p_ptr->total_winner || (p_ptr->lev > PY_MAX_LEVEL)) { p = "Magnificent"; } /* Normal */ else { p = cp_ptr->title[(p_ptr->lev - 1) / 5]; } /* Set offset */ offset = 11; center_string(buf, op_ptr->full_name); put_str(buf, 6, offset); center_string(buf, "the"); put_str(buf, 7, offset); center_string(buf, p); put_str(buf, 8, offset); center_string(buf, cp_ptr->name); put_str(buf, 10, offset); sprintf(tmp, "Level: %d", (int) p_ptr->lev); center_string(buf, tmp); put_str(buf, 11, offset); sprintf(tmp, "Exp: %ld", (long) p_ptr->exp); center_string(buf, tmp); put_str(buf, 12, offset); sprintf(tmp, "AU: %ld", (long) p_ptr->au); center_string(buf, tmp); put_str(buf, 13, offset); if (p_ptr->depth) sprintf(tmp, "Killed in %s level %d", locality_name[stage_map[p_ptr->stage][LOCALITY]], p_ptr->depth); else if (boat) sprintf(tmp, "Sailed victorious to Aman."); else if (tree) sprintf(tmp, "Retired to Fangorn Forest."); else sprintf(tmp, "Killed in %s town", locality_name[stage_map[p_ptr->stage][LOCALITY]]); center_string(buf, tmp); put_str(buf, 14, offset); if (!(boat || tree)) { sprintf(tmp, "by %s.", p_ptr->died_from); center_string(buf, tmp); put_str(buf, 15, offset); } #ifdef _WIN32_WCE { char *fake_ctime(const unsigned long *fake_time_t); sprintf(tmp, "%-.24s", fake_ctime(&ct)); } #else sprintf(tmp, "%-.24s", ctime(&ct)); #endif center_string(buf, tmp); put_str(buf, 17, offset); }