diff options
author | tradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350> | 2001-12-13 12:08:36 +0000 |
---|---|---|
committer | tradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350> | 2001-12-13 12:08:36 +0000 |
commit | 81cb04034072d59583194d75af79491a7674d1de (patch) | |
tree | 7b7bb1a4f28969a64de167706c54a87a514c5ac6 /src | |
parent | b5ab373e2c442017fe284f9531a91cb9a5eed6ac (diff) |
Put in Erik's patch to get 2D ASCII output for 2D variables.
Closes PR CactusBase-IOASCII/478.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@86 94b1c47f-dcfd-45ef-a468-0854c0e9e350
Diffstat (limited to 'src')
-rw-r--r-- | src/ChooseOutput.c | 4 | ||||
-rw-r--r-- | src/Output2D.c | 12 | ||||
-rw-r--r-- | src/Write2D.c | 162 |
3 files changed, 96 insertions, 82 deletions
diff --git a/src/ChooseOutput.c b/src/ChooseOutput.c index bc7cabc..ca6a739 100644 --- a/src/ChooseOutput.c +++ b/src/ChooseOutput.c @@ -144,9 +144,9 @@ void IOASCII_Choose2D (cGH *GH) CCTK_REAL origin_phys[3]; /* Specify output planes by coordinates */ - GET_SLICE (out2D_yzplane_x, out_yzplane_x, origin_index[0], origin_phys[0]); + GET_SLICE (out2D_xyplane_z, out_xyplane_z, origin_index[0], origin_phys[0]); GET_SLICE (out2D_xzplane_y, out_xzplane_y, origin_index[1], origin_phys[1]); - GET_SLICE (out2D_xyplane_z, out_xyplane_z, origin_index[2], origin_phys[2]); + GET_SLICE (out2D_yzplane_x, out_yzplane_x, origin_index[2], origin_phys[2]); myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); diff --git a/src/Output2D.c b/src/Output2D.c index 3353a1c..94a4f20 100644 --- a/src/Output2D.c +++ b/src/Output2D.c @@ -26,10 +26,6 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Output2D_c) /* prototypes of routines defined in this source file */ -int IOASCII_TriggerOutput2D (const cGH *GH, int vindex); -int IOASCII_Output2DVarAs (const cGH *GH, const char *fullname, const char *alias); -int IOASCII_TimeFor2D (const cGH *GH, int vindex); -int IOASCII_Output2DGH (const cGH *GH); static int CheckOutputVar (int vindex); static void CheckSteerableParameters (asciiioGH *myGH); static void SetOutputFlag (int vindex, const char *optstring, void *arg); @@ -347,15 +343,15 @@ static int CheckOutputVar (int vindex) const char *errormsg; - /* get the variable group indormation */ + /* get the variable group information */ groupindex = CCTK_GroupIndexFromVarI (vindex); CCTK_GroupData (groupindex, &groupinfo); - /* check if variable is of dimension 3 and is a GF or array type */ + /* check if variable is grid array type with either 2 or 3 dimensions */ errormsg = NULL; - if (groupinfo.dim != 3) + if (groupinfo.dim < 2 || groupinfo.dim > 3) { - errormsg = "No IOASCII 2D output for '%s' (dim != 3)"; + errormsg = "No IOASCII 2D output for '%s' (dim != [2,3])"; } else if (groupinfo.grouptype != CCTK_GF && groupinfo.grouptype != CCTK_ARRAY) { diff --git a/src/Write2D.c b/src/Write2D.c index 12e9107..df930cc 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -28,9 +28,9 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) /* macro to output a time slice as typed data */ -#define OUTPUT_TYPED_DATA(coord_hsizes, coord_i, coord_j, stagger_offset_i, \ - stagger_offset_j, data_hsizes, cctk_type, c_type, \ - data, have_coords, is_cmplx_type, fmt_string, file) \ +#define OUTPUT_TYPED_DATA(coord_i, coord_j, stagger_offset_i,stagger_offset_j,\ + cctk_type, c_type, data, hsize, is_cmplx_type, \ + have_coords, fmt_string, file) \ { \ int i, j; \ const cctk_type *typed_data = (const cctk_type *) (data); \ @@ -39,9 +39,9 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) /* output coordinates if available otherwise just the indices */ \ if (have_coords) \ { \ - for (j = 0; j < data_hsizes[1]; j++) \ + for (j = 0; j < hsize[1]; j++) \ { \ - for (i = 0; i < data_hsizes[0]; i++) \ + for (i = 0; i < hsize[0]; i++) \ { \ fprintf (file, fmt_string, \ (double) (*coord_i++ + stagger_offset_i), \ @@ -55,17 +55,15 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) fprintf (file, "\n"); \ } \ fprintf (file, "\n"); \ - coord_i += coord_hsizes[0] - data_hsizes[0]; \ - coord_j += coord_hsizes[0] - data_hsizes[0]; \ } \ - coord_i -= coord_hsizes[0] * data_hsizes[1]; \ - coord_j -= coord_hsizes[0] * data_hsizes[1]; \ + coord_i -= hsize[0] * hsize[1]; \ + coord_j -= hsize[0] * hsize[1]; \ } \ else \ { \ - for (j = 0; j < data_hsizes[1]; j++) \ + for (j = 0; j < hsize[1]; j++) \ { \ - for (i = 0; i < data_hsizes[0]; i++) \ + for (i = 0; i < hsize[0]; i++) \ { \ fprintf (file, fmt_string, \ (double) i, \ @@ -122,7 +120,7 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) char time_fmt_string[30]; /* time format string */ char data_fmt_string_int[30]; /* data format string for int types */ char data_fmt_string_real[30]; /* data format string for real types */ - int dir; + int dir, maxdir; int groupindex; int have_coords; cGroup groupinfo; @@ -137,13 +135,13 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) char slicename[20]; ioAdvertisedFileDesc advertised_file; char buffer[128]; - static char *extensions[3] = {"yz", "xz", "xy"}; + static char *extensions[] = {"xy", "xz", "yz"}; /* to make the compiler happy */ fdset_2D = NULL; - /* get the variable group indormation */ + /* get the variable group information */ groupindex = CCTK_GroupIndexFromVarI (vindex); CCTK_GroupData (groupindex, &groupinfo); @@ -160,9 +158,13 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) /* Get the handle for IOASCII extensions */ myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); + /* get the number of slices to output */ + /* in general: maxdir = groupinfo.dim * (groupinfo.dim - 1) / 2; */ + maxdir = groupinfo.dim == 2 ? 1 : 3; + /* set header and data format strings */ sprintf (header_fmt_string, "\n\n#Time = %%%s\n", out_format); - sprintf (zlabel_fmt_string, "#z-label %%s (%%c = %%%s), ", out_format); + sprintf (zlabel_fmt_string, " (%%c = %%%s),", out_format); sprintf (out_real_format, "%%%s", out_format); dir = 0; if (CCTK_Equals (out2D_style, "gnuplot f(t,x,y)")) @@ -221,15 +223,22 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) fullname = CCTK_FullName (vindex); /* Open/Create files */ - for (dir = 0; dir < 3; dir++) + for (dir = 0; dir < maxdir; dir++) { /* FIXME: this can go when we permanently switch the the new filename scheme */ if (new_filename_scheme) { - /* give the slice origin as range [1 .. n] */ - sprintf (slicename, "%s_[%d]", extensions[dir], - myGH->sp2xyz[groupinfo.dim - 1][dir]); + if (groupinfo.dim == 2) + { + strcpy (slicename, "2D"); + } + else + { + /* give the slice origin as range [1 .. n] */ + sprintf (slicename, "%s_[%d]", extensions[dir], + myGH->sp2xyz[groupinfo.dim - 1][dir]); + } /* skip pathname if output goes into current directory */ if (strcmp (myGH->outdir2D, ".")) @@ -246,12 +255,26 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) /* skip pathname if output goes into current directory */ if (strcmp (myGH->outdir2D, ".")) { - sprintf (filename, "%s/%s_2d_%s.gnuplot", myGH->outdir2D, alias, - extensions[dir]); + if (groupinfo.dim == 2) + { + sprintf (filename, "%s/%s_2D.gnuplot", myGH->outdir2D, alias); + } + else + { + sprintf (filename, "%s/%s_2d_%s.gnuplot", myGH->outdir2D, alias, + extensions[dir]); + } } else { - sprintf (filename, "%s_2d_%s.gnuplot", alias, extensions[dir]); + if (groupinfo.dim == 2) + { + sprintf (filename, "%s_2D.gnuplot", alias); + } + else + { + sprintf (filename, "%s_2d_%s.gnuplot", alias, extensions[dir]); + } } } @@ -307,15 +330,19 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) { fprintf (fdset_2D[dir], "#x-label %c\n", extensions[dir][0]); fprintf (fdset_2D[dir], "#y-label %c\n", extensions[dir][1]); - if (have_coords) + fprintf (fdset_2D[dir], "#z-label %s", advertised_file.varname); + if (groupinfo.dim != 2) { - fprintf (fdset_2D[dir], zlabel_fmt_string, - advertised_file.varname, 'x' + dir, - coord_lower[dir] + GH->cctk_delta_space[dir] * - myGH->sp2xyz[groupinfo.dim-1][dir]); + if (have_coords) + { + fprintf (fdset_2D[dir], zlabel_fmt_string, 'x' + dir, + coord_lower[dir] + GH->cctk_delta_space[dir] * + myGH->sp2xyz[groupinfo.dim-1][dir]); + } + fprintf (fdset_2D[dir], " (%ci = %d)", + 'x' + dir, myGH->sp2xyz[groupinfo.dim-1][dir]); } - fprintf (fdset_2D[dir], "(%ci = %d)\n", - 'x' + dir, myGH->sp2xyz[groupinfo.dim-1][dir]); + fputc ('\n', fdset_2D[dir]); } } @@ -327,20 +354,20 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) } } - for (dir = 0; dir < 3; dir++) + for (dir = 0; dir < maxdir; dir++) { int dir_i, dir_j; int directions[3]; const int lengths[2] = {-1, -1}; const int downsamples[2] = {1, 1}; - int coord_hsizes[2], data_hsizes[2]; + int hsize[2]; CCTK_REAL *coord_data_i, *coord_data_j; void *data; /* get the directions to span the hyperslab */ if (dir == 0) { - dir_i = 1; dir_j = 2; /* yz */ + dir_i = 0; dir_j = 1; /* xy */ } else if (dir == 1) { @@ -348,7 +375,7 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) } else { - dir_i = 0; dir_j = 1; /* xy */ + dir_i = 1; dir_j = 2; /* yz */ } /* set the origin using the slice center from IOUtil */ @@ -365,7 +392,7 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) /* get the i-coordinate slice */ if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_i], 0, 2, origin, directions, lengths, downsamples, - (void **) &coord_data_i, coord_hsizes) < 0) + (void **) &coord_data_i, hsize) < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to extract 2D hyperslab for %c-coordinate", @@ -376,7 +403,7 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) /* get the j-coordinate slice */ if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_j], 0, 2, origin, directions, lengths, downsamples, - (void **) &coord_data_j, coord_hsizes) < 0) + (void **) &coord_data_j, hsize) < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to extract 2D hyperslab for %c-coordinate", @@ -394,7 +421,7 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) /* get the variable slice */ if (Hyperslab_GetHyperslab (GH, 0, vindex, 0, 2, origin, directions, - lengths, downsamples, &data, data_hsizes) < 0) + lengths, downsamples, &data, hsize) < 0) { fullname = CCTK_FullName (vindex); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, @@ -429,85 +456,76 @@ void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) switch (groupinfo.vartype) { case CCTK_VARIABLE_CHAR: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_BYTE, int, data, have_coords, - 0, data_fmt_string_int, fdset_2D[dir]); + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_BYTE, int, data, hsize, + 0, have_coords, data_fmt_string_int,fdset_2D[dir]); break; case CCTK_VARIABLE_INT: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_INT, int, data, have_coords, - 0, data_fmt_string_int, fdset_2D[dir]); + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_INT, int, data, hsize, + 0, have_coords, data_fmt_string_int,fdset_2D[dir]); break; case CCTK_VARIABLE_REAL: case CCTK_VARIABLE_COMPLEX: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_REAL, double, data, have_coords, + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_REAL, double, data, hsize, groupinfo.vartype == CCTK_VARIABLE_COMPLEX, - data_fmt_string_real, fdset_2D[dir]); + have_coords, data_fmt_string_real, fdset_2D[dir]); break; #ifdef CCTK_INT2 case CCTK_VARIABLE_INT2: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_INT2, int, data, have_coords, - 0, data_fmt_string_int, fdset_2D[dir]); + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_INT2, int, data, hsize, + 0, have_coords, data_fmt_string_int,fdset_2D[dir]); break; #endif #ifdef CCTK_INT4 case CCTK_VARIABLE_INT4: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_INT4, int, data, have_coords, - 0, data_fmt_string_int, fdset_2D[dir]); + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_INT4, int, data, hsize, + 0, have_coords, data_fmt_string_int,fdset_2D[dir]); break; #endif #ifdef CCTK_INT8 case CCTK_VARIABLE_INT8: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_INT8, int, data, have_coords, - 0, data_fmt_string_int, fdset_2D[dir]); + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_INT8, int, data, hsize, + 0, have_coords, data_fmt_string_int,fdset_2D[dir]); break; #endif #ifdef CCTK_REAL4 case CCTK_VARIABLE_REAL4: case CCTK_VARIABLE_COMPLEX8: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_REAL4, double, data, have_coords, + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_REAL4, double, data, hsize, groupinfo.vartype == CCTK_VARIABLE_COMPLEX8, - data_fmt_string_real, fdset_2D[dir]); + have_coords, data_fmt_string_real, fdset_2D[dir]); break; #endif #ifdef CCTK_REAL8 case CCTK_VARIABLE_REAL8: case CCTK_VARIABLE_COMPLEX16: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_REAL8, double, data, have_coords, + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_REAL8, double, data, hsize, groupinfo.vartype == CCTK_VARIABLE_COMPLEX16, - data_fmt_string_real, fdset_2D[dir]); + have_coords, data_fmt_string_real, fdset_2D[dir]); break; #endif #ifdef CCTK_REAL16 case CCTK_VARIABLE_REAL16: case CCTK_VARIABLE_COMPLEX32: - OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, - stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_REAL16, double, data,have_coords, + OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, + stagger_offset_j, CCTK_REAL16, double, data, hsize, groupinfo.vartype == CCTK_VARIABLE_COMPLEX32, - data_fmt_string_real, fdset_2D[dir]); + have_coords, data_fmt_string_real, fdset_2D[dir]); break; #endif |