source: branches/1.7/builder/scripts/templates/clang.tl @ 6307

Last change on this file since 6307 was 6307, checked in by ldelgass, 6 years ago

merge r6291 from 1.6 branch

File size: 5.7 KB
Line 
1# ----------------------------------------------------------------------
2#  LANGUAGE:  C Language API
3# ======================================================================
4#  AUTHOR:  Michael McLennan, Purdue University
5#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
6#
7#  See the file "license.terms" for information on usage and
8#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9# ======================================================================
10language "C Language" {
11  extension ".c"
12
13  # use the convention with "c" on the end of the program name
14  # so we can tell that this is a C language program, not fortran
15  command {@tool/@@FILEROOT@@c @driver}
16
17  main {/*
18 * ----------------------------------------------------------------------
19 *  MAIN PROGRAM - generated by the Rappture Builder
20 * ----------------------------------------------------------------------
21 */
22#include "rappture.h"
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <math.h>
28#include <unistd.h>
29
30int main(int argc, char * argv[]) {
31    /* stuff needed for Rappture library */
32    RpLibrary* io;
33    const char* data; char line[255];
34    int err;
35
36    @@DECLARATIONS@@
37
38    /* open the XML file containing the run parameters */
39    io = rpLibrary(argv[1]);
40
41    if (io == NULL) {
42        /* cannot open file or out of memory */
43        printf("FAILED loading Rappture data\n");
44        exit(1);
45    }
46
47    /*
48     *********************************************************
49     * Get input values from Rappture
50     *********************************************************
51     */
52    @@INPUTS@@
53
54    /*
55     *********************************************************
56     *  Add your code here for the main body of your program
57     *********************************************************
58     */
59
60    /* spit out progress messages as you go along... */
61    rpUtilsProgress(0, "Starting...");
62    rpUtilsProgress(5, "Loading data...");
63    rpUtilsProgress(50, "Half-way there");
64    rpUtilsProgress(100, "Done");
65
66    /*
67     *********************************************************
68     * Save output values back to Rappture
69     *********************************************************
70     */
71    @@OUTPUTS@@
72
73    rpResult(io);
74    exit(0);
75}}
76
77  input boolean {
78    decl "int $id;  /* for $path */"
79    code "\n/* get input value for $path */"
80    code "rpGetString(io,\"$path.current\", &data);"
81    code "$id = (strcmp(data,\"yes\") == 0);"
82  }
83  input image {
84    code "\n/* get input value for $path */"
85    code "/* returns base64-encoded image data */"
86    code "rpGetString(io,\"$path.current\", &data);"
87  }
88  input integer {
89    decl "int $id;  /* for $path */"
90    code "\n/* get input value for $path */"
91    code "rpGetString(io,\"$path.current\", &data);"
92    code "$id = atoi(data);"
93  }
94  input number {
95    set units [attr get units]
96    if {$units ne ""} {
97      decl "double $id;  /* for $path */"
98      code "\n/* get input value for $path and convert to $units */"
99      code "rpGetString(io,\"$path.current\", &data);"
100      code "$id = rpConvertDbl(data, \"$units\", &err);"
101      code "if (err) {"
102      code "    printf(\"Error while retrieving $path.current\n\");"
103      code "    exit(1);"
104      code "}"
105    } else {
106      decl "double $id;  /* for $path */"
107      code "\n/* get input value for $path */"
108      code "rpGetString(io,\"$path.current\", &data);"
109      code "$id = atof(data);"
110    }
111  }
112  input string {
113    decl "const char* $id;  /* for $path */"
114    code "\n/* get input value for $path */"
115    code "rpGetString(io,\"$path.current\", &$id);"
116  }
117  input * {
118    code "\n/* get input value for $path */"
119    code "rpGetString(io,\"$path.current\", &data);"
120  }
121
122  output boolean {
123    decl "int $id;  /* for $path */"
124    code "\n/* save output value for $path */"
125    code "rpPutString(io, \"$path.current\", ($id) ? \"yes\" : \"no\");"
126  }
127  output curve {
128    code "\n/* save output value for $path */"
129    code "/* this shows just one (x,y) point -- modify as needed */"
130    code "sprintf(line, \"%g %g\\n\", x, y);"
131    code "rpPutString(io,\"$path.component.xy\", line, RPLIB_APPEND);"
132  }
133  output histogram {
134    code "\n/* save output value for $path */"
135    code "/* this shows just one point -- modify as needed */"
136    code "/* (x,h,w) = x-coord, height of bar, and width of bar (optional) */"
137    code "sprintf(line, \"%g %g %g\\n\", x, h, w);"
138    code "rpPutString(io,\"$path.component.xhw\", line, RPLIB_APPEND);"
139  }
140  output image {
141    code "\n/* save output value for $path */"
142    code "/* data should be base64-encoded image data */"
143    code "rpPutString(io, \"$path.current\", imdata, RPLIB_OVERWRITE);"
144  }
145  output integer {
146    decl "int $id;  /* for $path */"
147    code "\n/* save output value for $path */"
148    code "sprintf(line, \"%d\\n\", $id);"
149    code "rpPutString(io, \"$path.current\", line, RPLIB_OVERWRITE);"
150  }
151  output number {
152    decl "double $id;  /* for $path */"
153    code "\n/* save output value for $path */"
154    code "sprintf(line, \"%g\\n\", $id);"
155    code "rpPutString(io, \"$path.current\", line, RPLIB_OVERWRITE);"
156  }
157  output string {
158    decl "char $id\[1024\];  /* for $path */"
159    code "\n/* save output value for $path */"
160    code "rpPutString(io, \"$path.current\", $id, RPLIB_OVERWRITE);"
161  }
162  output * {
163    code "\n/* save output value for $path */"
164    code "rpPutString(io, \"$path.current\", $id, RPLIB_OVERWRITE);"
165  }
166
167  makefile {# simple makefile for a Rappture-based program
168
169CC              = gcc
170CFLAGS          = -g -Wall
171
172RAPPTURE_DIR    = @@RAPPTUREDIR@@
173INCLUDES        = -I$(RAPPTURE_DIR)/include
174LIBS            = -L$(RAPPTURE_DIR)/lib -lrappture -lm
175
176
177all: @@FILEROOT@@c
178
179@@FILEROOT@@c: @@FILENAME@@
180        $(CC) $(CFLAGS) $(INCLUDES) $< -o $@ $(LIBS)
181
182install:
183
184clean:
185        $(RM) @@FILEROOT@@c run*.xml
186}
187}
Note: See TracBrowser for help on using the repository browser.