aboutsummaryrefslogtreecommitdiff
path: root/Carpet
diff options
context:
space:
mode:
authorschnetter <>2002-07-15 15:10:00 +0000
committerschnetter <>2002-07-15 15:10:00 +0000
commitf90b8854f56a63390c3503cae601da5c79f017c3 (patch)
treef6b0aee8f3acf90332d4353027df152c541eae7b /Carpet
parent621335cf698b9022034ffcbe0d67f2cdfa778b25 (diff)
Added utilities that covert from Carpet's ASCII output to SDF or
Added utilities that covert from Carpet's ASCII output to SDF or xgraph format. These utilities were written by Scott Hawley. darcs-hash:20020715151012-07bb3-57fa8427c46f1626625e08fc79669c3a8650cab1.gz
Diffstat (limited to 'Carpet')
-rw-r--r--Carpet/CarpetIOASCII/src/util/Makefile11
-rw-r--r--Carpet/CarpetIOASCII/src/util/carpet2xgraph.c360
2 files changed, 185 insertions, 186 deletions
diff --git a/Carpet/CarpetIOASCII/src/util/Makefile b/Carpet/CarpetIOASCII/src/util/Makefile
new file mode 100644
index 000000000..14c4981fd
--- /dev/null
+++ b/Carpet/CarpetIOASCII/src/util/Makefile
@@ -0,0 +1,11 @@
+
+all: carpet2sdf carpet2xgraph
+
+.c.o:
+ cc -Wall -g -I$(HOME)/include -c $*.c
+
+carpet2sdf: carpet2sdf.o
+ cc -g carpet2sdf.o -o carpet2sdf -L$(HOME)/lib -lrnpl -lmfhdf -ldf -ljpeg -lz -lvsso -lsv -lm
+
+carpet2xgraph: carpet2xgraph.o
+ cc -g carpet2xgraph.o -o carpet2xgraph
diff --git a/Carpet/CarpetIOASCII/src/util/carpet2xgraph.c b/Carpet/CarpetIOASCII/src/util/carpet2xgraph.c
index 61dfa689b..af56a42c4 100644
--- a/Carpet/CarpetIOASCII/src/util/carpet2xgraph.c
+++ b/Carpet/CarpetIOASCII/src/util/carpet2xgraph.c
@@ -1,186 +1,174 @@
-
-/*******************************************************************
- * Program: carpet2xgraph
- * Description: Converts from Carpet ASCII file format to Xgraph format
- * Author: Scott H. Hawley
- * Date: June 17, 2002
- *
- * This will select the data for ONE REFINEMENT LEVEL (default 0)
- * and send the result to stdout. The "xgraph format" data is
- * not, however, fully annotated and someone may wish to improve
- * this.
- *
- * The [clip_data_at] command-line argument was added for use with
- * 1/r data, to replace the infinities at the origin with whatever
- * value the user specifies.
- *******************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/*******************************************************************
- * Function: read_next_set
- * Supposed to read one time step of data (for one level of refinement)
- *******************************************************************/
-int read_next_set(FILE *infile, int rlev, int *numelems,
- double *time,
- double **coord, double **data, int clip_data, double clip_val)
-{
- char in_line[200];
- int it,tl,rl,c,ml,ix,iy,iz;
- double xval, yval, zval;
- double coordval, dataval;
- int hit_first_non_blank = 0;
- int stop_reading = 0;
- int retval = 0;
- int rc = 0;
-
- *numelems = 0;
- sprintf(in_line," ");
-
- /* reads up to first blank line after non-blank lines, or up to
- * eof */
- while ((fgets(in_line,200,infile) != NULL) && (!stop_reading) ) {
-
- if (in_line[0]=='#') {
- hit_first_non_blank = 1;
-
- } else if ((strncmp("\n",in_line,2)==0) ||
- (in_line[0]==' ')) {
- if (hit_first_non_blank) {
- stop_reading = 1;
- }
-
- } else { /* Assume that we're dealing with a line of numbers */
- hit_first_non_blank = 1;
- retval = sscanf(in_line,"%d %d %d %d %d %d %d %d %lg %lg %lg %lg %lg",
- &it,&tl,&rl,&c,&ml,&ix,&iy,&iz,time,&xval,&yval,&zval,&dataval);
- coordval = xval;
-
- /* Only add input to arrays if it's for the right ref. level */
- if ( (retval == 13) && (rl == rlev)) {
- (*numelems)++;
-
- if (coord==NULL) {
- *coord = (double *)malloc(sizeof(double)* (*numelems));
- *data = (double *)malloc(sizeof(double)* (*numelems));
- } else {
- *coord = (double *)realloc(*coord, sizeof(double)* (*numelems));
- *data = (double *)realloc(*data, sizeof(double)* (*numelems));
- }
- if (coord==NULL) {
- fprintf(stderr,"Error: malloc/realloc returned NULL\n");
- exit(1);
- }
-
- (*coord)[(*numelems)-1] = coordval;
-
- /* If desired, "clip" data above a certain value */
- if (clip_data && (dataval > clip_val)) {
- (*data)[(*numelems)-1] = clip_val;
- } else {
- (*data)[(*numelems)-1] = dataval;
- }
-
- }
-
- }
-
- }
- rc = feof(infile);
-
- return rc;
-}
-
-
-/********************************************************************
- * Main part of program
- ********************************************************************/
-int main(int argc, char **argv)
-{
- char *infilename;
- FILE *infile;
-
- char func_name[200];
- double time;
- int numelems_in_set = 0;
- int rlev = 0;
- double *coord, *data;
- int clip_data = 0;
- double clip_val;
- int i;
-
-
- /*
- * Parse command-line arguments
- */
- if (argc <= 1) {
- fprintf(stderr," input from stdin... invoke carpet2xgraph -h for help\n");
- } else if (strcmp(argv[1],"-h")==0) {
- fprintf(stderr,"usage: cat file | carpet2xgraph [name_tag] [ref_lev] [clip_data_at]\n");
- exit(1);
- }
-
- if (argc >= 2) {
- infilename = argv[1];
- } else {
- infilename = "stdin";
- }
- if (argc >= 3) {
- sscanf(argv[2],"%d",&rlev);
- }
- if (argc >= 4) {
- sscanf(argv[3],"%lf",&clip_val);
- clip_data = 1;
- }
-
- /*
- * Open the input file
- */
- infile = stdin;
-
- /*
- infile = fopen(infilename,"r");
- if (infile == NULL) {
- fprintf(stderr,"Error opening file '%s'.\n",infilename);
- exit(1);
- }
- */
-
-
- time = 0;
- coord = NULL;
- data = NULL;
- sprintf(func_name,"%s_%d",infilename,rlev);
-
- printf("\"x-label x\n");
- printf("\"y-label %s\n\n\n",infilename);
- printf("\"label = %s\n\n\n",infilename);
-
- /*
- * Main loop for reading from input file and writing to output file
- */
- while ( read_next_set(infile,rlev,&numelems_in_set,&time,&coord,&data,
- clip_data, clip_val) == 0 ) {
- if (numelems_in_set > 0) {
-
- /* xgraph format */
- printf("\"Time = %g\n",time);
- for (i=0; i<numelems_in_set; i++) {
- printf("%g %17.14g\n",coord[i],data[i]);
- }
- printf("\n\n");
-
- free(coord);
- free(data);
- coord = NULL;
- data = NULL;
-
- }
- }
-
- return 0;
-}
-
+
+/*******************************************************************
+ * Program: carpet2xgraph
+ * Description: Converts from Carpet ASCII file format to Xgraph format
+ * Author: Scott H. Hawley
+ * Date: June 17, 2002
+ *
+ * This will select the data for ONE REFINEMENT LEVEL (default 0)
+ * and send the result to stdout. The "xgraph format" data is
+ * not, however, fully annotated and someone may wish to improve
+ * this.
+ *
+ * The [clip_data_at] command-line argument was added for use with
+ * 1/r data, to replace the infinities at the origin with whatever
+ * value the user specifies.
+ *******************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/*******************************************************************
+ * Function: read_next_set
+ * Supposed to read one time step of data (for one level of refinement)
+ *******************************************************************/
+int read_next_set(FILE *infile, int rlev, int *numelems,
+ double *time,
+ double **coord, double **data, int clip_data, double clip_val)
+{
+ char in_line[200];
+ int it,tl,rl,c,ml,ix,iy,iz;
+ double xval, yval, zval;
+ double coordval, dataval;
+ int hit_first_non_blank = 0;
+ int stop_reading = 0;
+ int retval = 0;
+ int rc = 0;
+
+ *numelems = 0;
+ sprintf(in_line," ");
+
+ /* reads up to first blank line after non-blank lines, or up to
+ * eof */
+ while ((fgets(in_line,200,infile) != NULL) && (!stop_reading) ) {
+
+ if (in_line[0]=='#') {
+ hit_first_non_blank = 1;
+
+ } else if ((strncmp("\n",in_line,2)==0) ||
+ (in_line[0]==' ')) {
+ if (hit_first_non_blank) {
+ stop_reading = 1;
+ }
+
+ } else { /* Assume that we're dealing with a line of numbers */
+ hit_first_non_blank = 1;
+ retval = sscanf(in_line,"%d %d %d %d %d %d %d %d %lg %lg %lg %lg %lg",
+ &it,&tl,&rl,&c,&ml,&ix,&iy,&iz,time,&xval,&yval,&zval,&dataval);
+ coordval = xval;
+
+ /* Only add input to arrays if it's for the right ref. level */
+ if ( (retval == 13) && (rl == rlev)) {
+ (*numelems)++;
+
+ if (coord==NULL) {
+ *coord = (double *)malloc(sizeof(double)* (*numelems));
+ *data = (double *)malloc(sizeof(double)* (*numelems));
+ } else {
+ *coord = (double *)realloc(*coord, sizeof(double)* (*numelems));
+ *data = (double *)realloc(*data, sizeof(double)* (*numelems));
+ }
+ if (coord==NULL) {
+ fprintf(stderr,"Error: malloc/realloc returned NULL\n");
+ exit(1);
+ }
+
+ (*coord)[(*numelems)-1] = coordval;
+
+ /* If desired, "clip" data above a certain value */
+ if (clip_data && (dataval > clip_val)) {
+ (*data)[(*numelems)-1] = clip_val;
+ } else {
+ (*data)[(*numelems)-1] = dataval;
+ }
+
+ }
+
+ }
+
+ }
+ rc = feof(infile);
+
+ return rc;
+}
+
+
+/********************************************************************
+ * Main part of program
+ ********************************************************************/
+int main(int argc, char **argv)
+{
+ char *infilename;
+ FILE *infile;
+
+ char func_name[200];
+ double time;
+ int numelems_in_set = 0;
+ int rlev = 0;
+ double *coord, *data;
+ int clip_data = 0;
+ double clip_val;
+ int i;
+
+
+ /*
+ * Parse command-line arguments
+ */
+ if (argc <= 1) {
+ fprintf(stderr,"usage: carpet2xgraph <infile> [ref_lev] [clip_data_at]\n");
+ exit(1);
+ }
+ if (argc >= 3) {
+ sscanf(argv[2],"%d",&rlev);
+ }
+ if (argc >= 4) {
+ sscanf(argv[3],"%lf",&clip_val);
+ clip_data = 1;
+ }
+
+ /*
+ * Open the input file
+ */
+ infilename = argv[1];
+ infile = fopen(infilename,"r");
+ if (infile == NULL) {
+ fprintf(stderr,"Error opening file '%s'.\n",infilename);
+ exit(1);
+ }
+
+
+ time = 0;
+ coord = NULL;
+ data = NULL;
+ sprintf(func_name,"%s_%d",infilename,rlev);
+
+ printf("\"x-label x\n");
+ printf("\"y-label %s\n\n\n",infilename);
+
+ /*
+ * Main loop for reading from input file and writing to output file
+ */
+ while ( read_next_set(infile,rlev,&numelems_in_set,&time,&coord,&data,
+ clip_data, clip_val) == 0 ) {
+ if (numelems_in_set > 0) {
+
+ /* xgraph format */
+ printf("\"Time = %g\n",time);
+ for (i=0; i<numelems_in_set; i++) {
+ printf("%g %g\n",coord[i],data[i]);
+ }
+ printf("\n\n");
+
+ free(coord);
+ free(data);
+ coord = NULL;
+ data = NULL;
+
+ }
+ }
+
+ return 0;
+}
+