diff options
author | tradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350> | 2001-05-09 15:45:51 +0000 |
---|---|---|
committer | tradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350> | 2001-05-09 15:45:51 +0000 |
commit | 754182350531a19e69cccd7af30df8e2e3e6e676 (patch) | |
tree | 999d5669312661c374f4a8f3403aa28a3e94d506 /src/Write2D.c | |
parent | 2888f65eb55b121ed35e8346fcf7969ccf30c7c7 (diff) |
Added coordinate information to the axis labels.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@58 94b1c47f-dcfd-45ef-a468-0854c0e9e350
Diffstat (limited to 'src/Write2D.c')
-rw-r--r-- | src/Write2D.c | 146 |
1 files changed, 69 insertions, 77 deletions
diff --git a/src/Write2D.c b/src/Write2D.c index beead76..88c2015 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -2,9 +2,9 @@ @file Write2D.c @date Thu May 11 2000 @author Thomas Radke - @desc + @desc Output two-dimensional slices in ASCII gnuplot format. - @enddesc + @enddesc @version $Id$ @@*/ @@ -30,15 +30,14 @@ 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, grouptype, fmt_string, file) \ + data, have_coords, fmt_string, file) \ { \ int i, j; \ cctk_type *typed_data = (cctk_type *) (data); \ \ \ - /* grid functions are output along with their coordinates \ - grid array points are just indexed */ \ - if (grouptype == CCTK_GF) \ + /* output coordinates if available otherwise just the indices */ \ + if (have_coords) \ { \ for (j = 0; j < data_hsizes[1]; j++) \ { \ @@ -106,20 +105,24 @@ void IOASCII_Write2D (cGH *GH, int vindex, const char *alias) int myproc; asciiioGH *myGH; char header_fmt_string[30]; /* header format string */ + char zlabel_fmt_string[30]; /* z-label format string */ char data_fmt_string_int[30]; /* data format string for int types */ char data_fmt_string_real[30]; /* data format string for float types */ int dir; int timelevel; int groupindex; + int have_coords; cGroup groupinfo; FILE **fdset_2D; /* array of output file pointers */ int coord_index[3]; /* variable indices for xyz coordinates */ - int coord_timelevel[3]; /* coordinates' current timelevels */ + CCTK_REAL coord_lower[3]; /* coordinates' minima */ + char coord_system[20]; /* name of the coordinate system */ int origin[3]; /* the slice origin */ + CCTK_REAL dummy; char *filename; char *fullname; char slicename[20]; - ioAdvertisedFileDesc advertised_file; + ioAdvertisedFileDesc advertised_file; char buffer[128]; static char *extensions[3] = {"yz", "xz", "xy"}; @@ -132,7 +135,7 @@ void IOASCII_Write2D (cGH *GH, int vindex, const char *alias) CCTK_GroupData (groupindex, &groupinfo); /* check if variable has storage assigned */ - if (! CCTK_QueryGroupStorageI (GH, groupindex)) + if (! CCTK_QueryGroupStorageI (GH, groupindex)) { fullname = CCTK_FullName (vindex); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, @@ -146,11 +149,37 @@ void IOASCII_Write2D (cGH *GH, int vindex, const char *alias) /* 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)\n", out_format); sprintf (data_fmt_string_int, "%%%s\t\t%%%s\t\t%%d\n", out_format, out_format); sprintf (data_fmt_string_real, "%%%s\t\t%%%s\t\t%%%s\n", out_format, out_format, out_format);; + /* get the coordinate indices if we output a grid function */ + if (groupinfo.grouptype == CCTK_GF) + { + sprintf (coord_system, "cart%dd", groupinfo.dim); + have_coords = 1; + for (dir = 0; dir < groupinfo.dim && dir < 3; dir++) + { + CCTK_CoordRange (GH, &coord_lower[dir], &dummy, dir+1, NULL,coord_system); + coord_index[dir] = CCTK_CoordIndex (dir + 1, NULL, coord_system); + have_coords &= coord_index[dir] >= 0; + } + + if (! have_coords) + { + CCTK_VWarn (8, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOASCII_Write2D: No coordinate ranges found for '%s'", + coord_system); + } + } + else + { + /* CCTK_ARRAY variables never have coordinates associated */ + have_coords = 0; + } + /* What processor are we on? */ myproc = CCTK_MyProc (GH); @@ -160,26 +189,15 @@ void IOASCII_Write2D (cGH *GH, int vindex, const char *alias) /* see if output file for this alias name was already created */ fdset_2D = (FILE **) GetNamedData (myGH->fileList_2D, alias); - if (fdset_2D == NULL) + if (fdset_2D == NULL) { fdset_2D = (FILE **) malloc (3 * sizeof (FILE *)); filename = (char *) malloc (strlen (myGH->outdir2D) + strlen (alias) + - sizeof (slicename) + 20 + -#if 0 -FIXME: get rid of PUGH here - strlen (pughGH->identity_string) + 20); -#else - 0); -#endif - + sizeof (slicename) + 20); + /* Open/Create files */ for (dir = 0; dir < 3; dir++) { -#if 0 - /* FIXME: move identity_string into cGH ?? */ - sprintf (filename, "%s/%s_2d_%s%s.gnuplot", myGH->outdir2D, alias, - extensions[dir], pughGH->identity_string); -#else /* FIXME: this can go when we permanently switch the the new filename scheme */ if (new_filename_scheme) @@ -211,7 +229,6 @@ FIXME: get rid of PUGH here sprintf (filename, "%s_2d_%s.gnuplot", alias, extensions[dir]); } } -#endif /* if restart from recovery, try to open an existing file ... */ fdset_2D[dir] = NULL; @@ -225,7 +242,7 @@ FIXME: get rid of PUGH here { fdset_2D[dir] = fopen (filename, "w"); } - if (! fdset_2D[dir]) + if (! fdset_2D[dir]) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Cannot open 2D output file '%s'", filename); @@ -265,7 +282,19 @@ FIXME: get rid of PUGH here { fprintf (fdset_2D[dir], "#x-label %c\n", extensions[dir][0]); fprintf (fdset_2D[dir], "#y-label %c\n", extensions[dir][1]); - fprintf (fdset_2D[dir], "#z-label %s\n", advertised_file.varname); + if (have_coords) + { + 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]); + } + else + { + fprintf (fdset_2D[dir], "#z-label %s (%c = %d)\n", + advertised_file.varname, 'x' + dir, + myGH->sp2xyz[groupinfo.dim-1][dir]); + } } free (advertised_file.varname); @@ -278,38 +307,10 @@ FIXME: get rid of PUGH here } } - /* get the coordinate indices if we output a grid function */ - if (groupinfo.grouptype == CCTK_GF) - { - switch (groupinfo.dim) - { - case 1: - coord_index[0] = CCTK_CoordIndex (1, NULL, "cart1d"); - break; - case 2: - coord_index[0] = CCTK_CoordIndex (1, NULL, "cart2d"); - coord_index[1] = CCTK_CoordIndex (2, NULL, "cart2d"); - case 3: - coord_index[0] = CCTK_CoordIndex (1, NULL, "cart3d"); - coord_index[1] = CCTK_CoordIndex (2, NULL, "cart3d"); - coord_index[2] = CCTK_CoordIndex (3, NULL, "cart3d"); - break; - default: - CCTK_WARN (4, "Cannot find appropriate coordinate system"); - break; - } - - /* get the coordinate timelevels */ - for (dir = 0; dir < 3; dir++) - { - coord_timelevel[dir] = CCTK_NumTimeLevelsFromVarI (coord_index[dir]) - 1; - } - } - /* get the timelevel for the variable to output */ timelevel = CCTK_NumTimeLevelsFromVarI (vindex) - 1; - for (dir = 0; dir < 3; dir++) + for (dir = 0; dir < 3; dir++) { int dir_i, dir_j; int directions[3]; @@ -343,33 +344,27 @@ FIXME: get rid of PUGH here directions[dir] = 1; /* get the coordinates for grid function output */ - if (groupinfo.grouptype == CCTK_GF) + if (have_coords) { /* get the i-coordinate slice */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_i], - coord_timelevel[dir_i], 2, origin, directions, - lengths, downsamples, + if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_i], 0, 2, + origin, directions, lengths, downsamples, (void **) &coord_data_i, coord_hsizes) < 0) { - fullname = CCTK_FullName (coord_index[dir_i]); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 2D hyperslab for variable '%s'", - fullname); - free (fullname); + "Failed to extract 2D hyperslab for %c-coordinate", + 'x' + dir_i); return; } /* get the j-coordinate slice */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_j], - coord_timelevel[dir_j], 2, origin, directions, - lengths, downsamples, + if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_j], 0, 2, + origin, directions, lengths, downsamples, (void **) &coord_data_j, coord_hsizes) < 0) { - fullname = CCTK_FullName (coord_index[dir_j]); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 2D hyperslab for variable '%s'", - fullname); - free (fullname); + "Failed to extract 2D hyperslab for %c-coordinate", + 'x' + dir_j); free (coord_data_i); return; } @@ -401,7 +396,7 @@ FIXME: get rid of PUGH here } /* proc 0 writes */ - if (myproc == 0) + if (myproc == 0) { CCTK_REAL stagger_offset_i, stagger_offset_j; @@ -420,24 +415,21 @@ FIXME: get rid of PUGH here 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, - groupinfo.grouptype, + data_hsizes, CCTK_BYTE, int, data, 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, - groupinfo.grouptype, + data_hsizes, CCTK_INT, int, data, have_coords, data_fmt_string_int, fdset_2D[dir]); break; case CCTK_VARIABLE_REAL: OUTPUT_TYPED_DATA (coord_hsizes, coord_data_i, coord_data_j, stagger_offset_i, stagger_offset_j, - data_hsizes, CCTK_REAL, double, data, - groupinfo.grouptype, + data_hsizes, CCTK_REAL, double, data, have_coords, data_fmt_string_real, fdset_2D[dir]); break; |