1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * FUNCTION: rpResult |
---|
4 | * |
---|
5 | * Clients call this function at the end of their simulation, to |
---|
6 | * pass the simulation result back to the Rappture GUI. It writes |
---|
7 | * out the given XML object to a runXXX.xml file, and then writes |
---|
8 | * out the name of that file to stdout. |
---|
9 | * ====================================================================== |
---|
10 | * AUTHOR: Michael McLennan, Purdue University |
---|
11 | * Copyright (c) 2004-2005 |
---|
12 | * Purdue Research Foundation, West Lafayette, IN |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | #include <stdlib.h> |
---|
16 | #include <time.h> |
---|
17 | |
---|
18 | void |
---|
19 | rpResult(PyObject* lib) { |
---|
20 | char outputFile[100]; |
---|
21 | char* xtext; |
---|
22 | FILE* fp; |
---|
23 | time_t t; |
---|
24 | |
---|
25 | xtext = rpXml(lib); |
---|
26 | |
---|
27 | // create output filename |
---|
28 | snprintf(outputFile, 50, "run%d.xml", (int)time(&t)); |
---|
29 | |
---|
30 | // write out the result file |
---|
31 | fp = fopen(outputFile, "w"); |
---|
32 | if(!fp) { |
---|
33 | fprintf(stderr,"can't save results (err=%d)\n", errno); |
---|
34 | return; |
---|
35 | } |
---|
36 | int fsize = fwrite(xtext, strlen(xtext), sizeof(char), fp); |
---|
37 | fclose(fp); |
---|
38 | |
---|
39 | // tell Rappture the file name |
---|
40 | printf("=RAPPTURE-RUN=>%s\n", outputFile); |
---|
41 | } |
---|