aboutsummaryrefslogtreecommitdiff
path: root/src/patch/patch.cc
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-17 17:13:47 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-17 17:13:47 +0000
commit30801866f7ecdaca9f718025372ad5f85b041da3 (patch)
tree06cdd8875eaea4089a7fa26a5b78dd8504109488 /src/patch/patch.cc
parent5dfff7277b864a32e79527ad50b0985f37fabad7 (diff)
merge common code in print nominal/ghosted routines into new
print_unknown_gridfn() routines, both in patch:: and patch_system:: also new patch:: read routines also declarations (but no code yet) for patch_system:: read routines git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@534 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/patch/patch.cc')
-rw-r--r--src/patch/patch.cc139
1 files changed, 103 insertions, 36 deletions
diff --git a/src/patch/patch.cc b/src/patch/patch.cc
index a56a6e3..5465be9 100644
--- a/src/patch/patch.cc
+++ b/src/patch/patch.cc
@@ -18,8 +18,7 @@
// patch::edge_adjacent_to_patch
// patch::assert_all_ghost_zones_fully_setup
//
-// patch::print_gridfn
-// patch::print_ghosted_gridfn
+// patch::print_unknown_gridfn
//
// patch_info::grid_array_pars
// patch_info::grid_pars
@@ -422,24 +421,37 @@ max_sigma_ghost_zone().assert_fully_setup();
//******************************************************************************
//
-// This function prints a nominal-grid gridfn in ASCII format to an
+// This function prints an unknown-grid gridfn in ASCII format to an
// already-open stdio stream. The output format is suitable for a
// gnuplot 'splot' command. Individual patches may be selected with
// the select.patch program (perl script).
//
-void patch::print_gridfn(int gfn, FILE *output_fp = stdout)
+void patch::print_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ FILE *output_fp = stdout,
+ bool want_ghost_zones = true)
const
{
+if (want_ghost_zones && !ghosted_flag)
+ then error_exit(PANIC_EXIT,
+"***** patch::print_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" can't have want_ghost_zones && !ghosted_flag !\n"
+,
+ name(), unknown_gfn); /*NOTREACHED*/
+
fprintf(output_fp, "### %s patch\n", name());
-fprintf(output_fp, "# gfn=%d\n", gfn);
+fprintf(output_fp, "# %s_gfn=%d\n",
+ (ghosted_flag ? "ghosted" : "nominal"), unknown_gfn);
fprintf(output_fp, "# dpx = %s\n", name_of_dpx());
fprintf(output_fp, "# dpy = %s\n", name_of_dpy());
fprintf(output_fp, "#\n");
-fprintf(output_fp, "# dpx\tdpy\tgridfn\tirho\tisigma\n");
- for (int irho = min_irho() ; irho <= max_irho() ; ++irho)
+fprintf(output_fp, "# dpx\tdpy\tgridfn\n");
+
+ for (int irho = effective_min_irho(want_ghost_zones) ;
+ irho <= effective_max_irho(want_ghost_zones) ;
+ ++irho)
{
- for (int isigma = min_isigma() ;
- isigma <= max_isigma() ;
+ for (int isigma = effective_min_isigma(want_ghost_zones) ;
+ isigma <= effective_max_isigma(want_ghost_zones) ;
++isigma)
{
const fp rho = rho_of_irho(irho);
@@ -448,49 +460,104 @@ fprintf(output_fp, "# dpx\tdpy\tgridfn\tirho\tisigma\n");
const fp dpy = dpy_of_rho_sigma(rho, sigma);
fprintf(output_fp,
"%g\t%g\t%.15g\n",
- dpx, dpy, gridfn(gfn,irho,isigma));
+ dpx, dpy,
+ (ghosted_flag ? ghosted_gridfn(unknown_gfn, irho,isigma)
+ : gridfn(unknown_gfn, irho,isigma)));
}
fprintf(output_fp, "\n");
}
}
//******************************************************************************
+//******************************************************************************
+//******************************************************************************
//
-// This function prints a ghosted-grid gridfn in ASCII format to an
-// already-open stdio stream. The output format is suitable for a
-// gnuplot 'splot' command. Individual patches may be selected with
-// the select.patch program (perl script).
+// This function reads an unknown-grid gridfn in ASCII format from an
+// already-open stdio stream. Comments ('#' in column 1) and blank lines
+// are ignored, otherwise the input format matches that written by
+// print_unknown_gridfn().
//
-void patch::print_ghosted_gridfn(int ghosted_gfn,
- FILE *output_fp = stdout,
- bool want_ghost_zones = true)
- const
+// Line numbers (1-origin) are used only for error messages.
+// The function return value is the next line number to be read.
+//
+int patch::read_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ int starting_line_number = 1,
+ FILE *input_fp = stdin,
+ bool want_ghost_zones = true)
{
-fprintf(output_fp, "### %s patch\n", name());
-fprintf(output_fp, "# ghosted_gfn=%d\n", ghosted_gfn);
-fprintf(output_fp, "# dpx = %s\n", name_of_dpx());
-fprintf(output_fp, "# dpy = %s\n", name_of_dpy());
-fprintf(output_fp, "#\n");
-fprintf(output_fp, "# dpx\tdpy\tgridfn\tirho\tisigma\n");
+if (want_ghost_zones && !ghosted_flag)
+ then error_exit(PANIC_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" can't have want_ghost_zones && !ghosted_flag !\n"
+,
+ name(), unknown_gfn); /*NOTREACHED*/
+
+int line_number = starting_line_number;
for (int irho = effective_min_irho(want_ghost_zones) ;
irho <= effective_max_irho(want_ghost_zones) ;
++irho)
{
- for (int isigma = effective_min_isigma(want_ghost_zones) ;
- isigma <= effective_max_isigma(want_ghost_zones) ;
- ++isigma)
+ for (int isigma = effective_min_isigma(want_ghost_zones) ;
+ isigma <= effective_max_isigma(want_ghost_zones) ;
+ ++isigma)
+ {
+ const fp rho = rho_of_irho(irho);
+ const fp sigma = sigma_of_isigma(isigma);
+ const fp dpx = dpx_of_rho_sigma(rho, sigma);
+ const fp dpy = dpy_of_rho_sigma(rho, sigma);
+
+ const int N_buffer = 100;
+ char buffer[N_buffer];
+ // read/discard comments and blank lines
+ do
{
- const fp rho = rho_of_irho(irho);
- const fp sigma = sigma_of_isigma(isigma);
- const fp dpx = dpx_of_rho_sigma(rho, sigma);
- const fp dpy = dpy_of_rho_sigma(rho, sigma);
- fprintf(output_fp,
- "%g\t%g\t%.15g\n",
- dpx, dpy, ghosted_gridfn(ghosted_gfn,irho,isigma));
- }
- fprintf(output_fp, "\n");
+ if (fgets(buffer, N_buffer, input_fp) == NULL)
+ then error_exit(ERROR_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" I/O error or unexpected end-of-file on input!\n"
+" at irho=%d of [%d,%d], isigma=%d of [%d,%d]\n"
+" dpx=%g dpy=%g\n"
+,
+ name(), unknown_gfn,
+ irho, effective_min_irho(want_ghost_zones),
+ effective_max_irho(want_ghost_zones),
+ isigma,
+ effective_min_isigma(want_ghost_zones),
+ effective_max_isigma(want_ghost_zones),
+ dpx, dpy); /*NOTREACHED*/
+ ++line_number;
+ } while ((buffer[0] == '#') || (buffer[0] == '\n'));
+
+ double read_dpx, read_dpy, read_gridfn_value;
+ if (sscanf(buffer, "%lf %lf %lf",
+ &read_dpx, &read_dpy, &read_gridfn_value) != 3)
+ then error_exit(ERROR_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" bad input data at input line %d!\n"
+,
+ name(), unknown_gfn,
+ line_number); /*NOTREACHED*/
+ if (! ( jtutil::fuzzy<fp>::EQ(read_dpx,dpx)
+ && jtutil::fuzzy<fp>::EQ(read_dpy,dpy) ) )
+ then error_exit(ERROR_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" wrong (dpx,dpy) at input line %d!\n"
+" expected (%g,%g)\n"
+" read (%g,%g)\n"
+,
+ name(), unknown_gfn,
+ line_number,
+ dpx, dpy,
+ read_dpx, read_dpy); /*NOTREACHED*/
+
+ if (ghosted_flag)
+ then ghosted_gridfn(unknown_gfn, irho,isigma) = read_gridfn_value;
+ else gridfn(unknown_gfn, irho,isigma) = read_gridfn_value;
}
+ }
+
+return line_number;
}
//******************************************************************************