diff options
author | tradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880> | 2001-03-19 23:28:53 +0000 |
---|---|---|
committer | tradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880> | 2001-03-19 23:28:53 +0000 |
commit | 8e915effdbd2b082fc2fbd100f9c0d9219ea2b37 (patch) | |
tree | be1f69523230492ec115a062550f0b1fffeac09d /src | |
parent | 41ff08ada1a4e9bbfc561fc4d34f759ec68291da (diff) |
Added the parameter filename, the creation date, and the axis labels
as comments at the top of the output files.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@83 b589c3ab-70e8-4b4d-a09f-cba2dd200880
Diffstat (limited to 'src')
-rw-r--r-- | src/Write.c | 46 | ||||
-rw-r--r-- | src/WriteGF.c | 44 |
2 files changed, 48 insertions, 42 deletions
diff --git a/src/Write.c b/src/Write.c index 388a37f..18abe0e 100644 --- a/src/Write.c +++ b/src/Write.c @@ -26,15 +26,15 @@ #include "iobasicGH.h" -void IOBasic_Write (cGH *GH, int index, const char *alias) +void IOBasic_Write (cGH *GH, int vindex, const char *alias) { DECLARE_CCTK_PARAMETERS char *openmode; FILE *file; void *data; - char *fname; + char *fname, buffer[128]; iobasicGH *myGH; - char *format_str_real, *format_str_int; + char format_str_real[15], format_str_int[15]; struct stat fileinfo; @@ -45,11 +45,11 @@ void IOBasic_Write (cGH *GH, int index, const char *alias) } /* first, check if variable has storage assigned */ - if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) + if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) { char *fullname; - fullname = CCTK_FullName (index); + fullname = CCTK_FullName (vindex); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "IOBasic_Write: No scalar output for '%s' (no storage)", fullname); @@ -58,16 +58,8 @@ void IOBasic_Write (cGH *GH, int index, const char *alias) } /* set the output format string for the desired notation */ - if (CCTK_Equals (out_format, "f")) - { - format_str_real = "%f %25.13f\n"; - format_str_int = "%f %d\n"; - } - else - { - format_str_real = "%e %25.13e\n"; - format_str_int = "%e %d\n"; - } + sprintf (format_str_real, "%%%s\t%%%s\n", out_format, out_format); + sprintf (format_str_int, "%%%s\t%%d\n", out_format); /* get the GH extensions for IOBasic */ myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")]; @@ -103,41 +95,47 @@ void IOBasic_Write (cGH *GH, int index, const char *alias) if (*openmode == 'w') { - char title_start_char; + char comment_char; ioAdvertisedFileDesc advertised_file; if (CCTK_Equals (outScalar_style, "gnuplot")) { - title_start_char = '#'; + comment_char = '#'; advertised_file.mimetype = "application/gnuplot"; } else { - title_start_char = 34; /* this is for xgraph */ + comment_char = '"'; /* this is for xgraph */ advertised_file.mimetype = "application/x-graph"; } - /* write the header */ - fprintf (file, "%c%s v time\n", title_start_char, alias); - /* just store a non-NULL pointer in database */ StoreNamedData (&myGH->filenameListScalar, fname, (void *) 1); /* advertise the file for downloading */ advertised_file.slice = "tl"; advertised_file.thorn = CCTK_THORNSTRING; - advertised_file.varname = CCTK_FullName (index); + advertised_file.varname = CCTK_FullName (vindex); advertised_file.description = "Scalar value"; IOUtil_AdvertiseFile (GH, fname, &advertised_file); + /* write the file info and the header */ + CCTK_ParameterFilename (sizeof (buffer), buffer); + fprintf (file, "%cParameter file %s\n", comment_char, buffer); + Util_CurrentTime (sizeof (buffer), buffer); + fprintf (file, "%cCreated %s\n", comment_char, buffer); + fprintf (file, "%cx-label time\n", comment_char); + fprintf (file, "%cy-label %s\n", comment_char, advertised_file.varname); + fprintf (file, "%c%s v time\n", comment_char, alias); + free (advertised_file.varname); } /* get the data pointer */ - data = CCTK_VarDataPtrI (GH, 0, index); + data = CCTK_VarDataPtrI (GH, 0, vindex); - switch (CCTK_VarTypeI (index)) + switch (CCTK_VarTypeI (vindex)) { case CCTK_VARIABLE_REAL: fprintf (file, format_str_real, GH->cctk_time, diff --git a/src/WriteGF.c b/src/WriteGF.c index 946d593..45c0a29 100644 --- a/src/WriteGF.c +++ b/src/WriteGF.c @@ -48,7 +48,7 @@ CCTK_FILEVERSION(CactusBase_IOBasic_WriteGF_c) @vtype cGH * @vio in @endvar - @var index + @var vindex @vdesc CCTK index of the variable to output @vtype int @vio in @@ -60,7 +60,7 @@ CCTK_FILEVERSION(CactusBase_IOBasic_WriteGF_c) @endvar @@*/ void IOBasic_WriteGF (cGH *GH, - int index, + int vindex, const char *alias) { DECLARE_CCTK_PARAMETERS @@ -73,10 +73,10 @@ void IOBasic_WriteGF (cGH *GH, char *reduction_op; char *string_start; char *string_end; - char title_start_char; - char *format_str; + char comment_char; + char format_str[15]; const char *file_extension; - char *fullname; + char *fullname, buffer[128]; struct stat fileinfo; ioAdvertisedFileDesc advertised_file; CCTK_REAL reduction_value; @@ -87,9 +87,9 @@ void IOBasic_WriteGF (cGH *GH, /* first, check if variable has storage assigned */ - if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) + if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) { - fullname = CCTK_FullName (index); + fullname = CCTK_FullName (vindex); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "IOBasic_WriteGF: No scalar output for '%s' (no storage)", fullname); @@ -97,19 +97,19 @@ void IOBasic_WriteGF (cGH *GH, return; } - /* check if decimal or exponential format desired */ - format_str = CCTK_Equals (out_format, "f") ? "%f %25.13f\n" : "%e %25.13e\n"; + /* set output format */ + sprintf (format_str, "%%%s\t%%%s\n", out_format, out_format); /* set the output file extension and the output style */ if (CCTK_Equals (outScalar_style, "gnuplot")) { file_extension = ".asc"; - title_start_char = '#'; + comment_char = '#'; } else { file_extension = ".xg"; - title_start_char = 34; + comment_char = '"'; } /* get the GH extension handle for IOBasic */ @@ -159,7 +159,7 @@ void IOBasic_WriteGF (cGH *GH, /* do the reduction (all processors) */ ierr = CCTK_Reduce (GH, 0, reduction_handle, 1, CCTK_VARIABLE_REAL, - &reduction_value, 1, index); + &reduction_value, 1, vindex); /* dump the reduction value to file by processor 0 */ if (ierr == 0 && CCTK_MyProc (GH) == 0) @@ -226,23 +226,31 @@ void IOBasic_WriteGF (cGH *GH, continue; } - /* when creating the file, write the header, - advertise the file, and save the filename in the database */ + /* when creating the file, advertise it for downloading, + write the header and the file info, + and save the filename in the database */ if (*openmode == 'w') { - fprintf (file, "%c%s %s v time\n", title_start_char, alias, - reduction_op); - /* advertise the file for downloading */ advertised_file.slice = reduction_op; advertised_file.thorn = CCTK_THORNSTRING; - advertised_file.varname = CCTK_FullName (index); + advertised_file.varname = CCTK_FullName (vindex); advertised_file.description = "Reduction on Grid Functions"; advertised_file.mimetype = CCTK_Equals (outScalar_style, "gnuplot") ? "application/gnuplot" : "application/x-graph"; IOUtil_AdvertiseFile (GH, filename, &advertised_file); + CCTK_ParameterFilename (sizeof (buffer), buffer); + fprintf (file, "%cParameter file %s\n", comment_char, buffer); + Util_CurrentTime (sizeof (buffer), buffer); + fprintf (file, "%cCreated %s\n", comment_char, buffer); + fprintf (file, "%cx-label time\n", comment_char); + fprintf (file, "%cy-label %s\n", + comment_char, advertised_file.varname); + fprintf (file, "%c%s %s v time\n", comment_char, alias, + reduction_op); + free (advertised_file.varname); /* just store a non-NULL pointer in database */ |