# ---------------------------------------------------------------------- # LANGUAGE: C Language API # ====================================================================== # AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2012 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== language "C Language" { extension ".c" # use the convention with "c" on the end of the program name # so we can tell that this is a C language program, not fortran command {@tool/@@FILEROOT@@c @driver} main {/* * ---------------------------------------------------------------------- * MAIN PROGRAM - generated by the Rappture Builder * ---------------------------------------------------------------------- */ #include "rappture.h" #include #include #include #include #include int main(int argc, char * argv[]) { /* stuff needed for Rappture library */ RpLibrary* io; const char* data; char line[255]; int err; @@DECLARATIONS@@ /* open the XML file containing the run parameters */ io = rpLibrary(argv[1]); if (io == NULL) { /* cannot open file or out of memory */ printf("FAILED loading Rappture data\n"); exit(1); } /* ********************************************************* * Get input values from Rappture ********************************************************* */ @@INPUTS@@ /* ********************************************************* * Add your code here for the main body of your program ********************************************************* */ /* spit out progress messages as you go along... */ rpUtilsProgress(0, "Starting..."); rpUtilsProgress(5, "Loading data..."); rpUtilsProgress(50, "Half-way there"); rpUtilsProgress(100, "Done"); /* ********************************************************* * Save output values back to Rappture ********************************************************* */ @@OUTPUTS@@ rpResult(io); exit(0); }} input boolean { decl "int $id; /* for $path */" code "\n/* get input value for $path */" code "rpGetString(io,\"$path.current\", &data);" code "$id = (strcmp(data,\"yes\") == 0);" } input image { code "\n/* get input value for $path */" code "/* returns base64-encoded image data */" code "rpGetString(io,\"$path.current\", &data);" } input integer { decl "int $id; /* for $path */" code "\n/* get input value for $path */" code "rpGetString(io,\"$path.current\", &data);" code "$id = atoi(data);" } input number { set units [attr get units] if {$units ne ""} { decl "double $id; /* for $path */" code "\n/* get input value for $path and convert to $units */" code "rpGetString(io,\"$path.current\", &data);" code "$id = rpConvertDbl(data, \"$units\", &err);" code "if (err) {" code " printf(\"Error while retrieving $path.current\n\");" code " exit(1);" code "}" } else { decl "double $id; /* for $path */" code "\n/* get input value for $path */" code "rpGetString(io,\"$path.current\", &data);" code "$id = atof(data);" } } input string { decl "const char* $id; /* for $path */" code "\n/* get input value for $path */" code "rpGetString(io,\"$path.current\", &$id);" } input * { code "\n/* get input value for $path */" code "rpGetString(io,\"$path.current\", &data);" } output boolean { decl "int $id; /* for $path */" code "\n/* save output value for $path */" code "rpPutString(io, \"$path.current\", ($id) ? \"yes\" : \"no\");" } output curve { code "\n/* save output value for $path */" code "/* this shows just one (x,y) point -- modify as needed */" code "sprintf(line, \"%g %g\\n\", x, y);" code "rpPutString(io,\"$path.component.xy\", line, RPLIB_APPEND);" } output histogram { code "\n/* save output value for $path */" code "/* this shows just one point -- modify as needed */" code "/* (x,h,w) = x-coord, height of bar, and width of bar (optional) */" code "sprintf(line, \"%g %g %g\\n\", x, h, w);" code "rpPutString(io,\"$path.component.xhw\", line, RPLIB_APPEND);" } output image { code "\n/* save output value for $path */" code "/* data should be base64-encoded image data */" code "rpPutString(io, \"$path.current\", imdata, RPLIB_OVERWRITE);" } output integer { decl "int $id; /* for $path */" code "\n/* save output value for $path */" code "sprintf(line, \"%d\\n\", $id);" code "rpPutString(io, \"$path.current\", line, RPLIB_OVERWRITE);" } output number { decl "double $id; /* for $path */" code "\n/* save output value for $path */" code "sprintf(line, \"%g\\n\", $id);" code "rpPutString(io, \"$path.current\", line, RPLIB_OVERWRITE);" } output string { decl "char $id\[1024\]; /* for $path */" code "\n/* save output value for $path */" code "rpPutString(io, \"$path.current\", $id, RPLIB_OVERWRITE);" } output * { code "\n/* save output value for $path */" code "rpPutString(io, \"$path.current\", $id, RPLIB_OVERWRITE);" } makefile {# simple makefile for a Rappture-based program CC = gcc CFLAGS = -g -Wall RAPPTURE_DIR = @@RAPPTUREDIR@@ INCLUDES = -I$(RAPPTURE_DIR)/include LIBS = -L$(RAPPTURE_DIR)/lib -lrappture -lm all: @@FILEROOT@@c @@FILEROOT@@c: @@FILENAME@@ $(CC) $(CFLAGS) $(INCLUDES) $< -o $@ $(LIBS) install: clean: $(RM) @@FILEROOT@@c run*.xml } }