[66] | 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 |
---|
[115] | 11 | * Copyright (c) 2004-2005 Purdue Research Foundation |
---|
| 12 | * |
---|
| 13 | * See the file "license.terms" for information on usage and |
---|
| 14 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
[66] | 15 | * ====================================================================== |
---|
| 16 | */ |
---|
| 17 | #include <stdlib.h> |
---|
| 18 | #include <time.h> |
---|
[1018] | 19 | #include <RpLibrary.h> |
---|
| 20 | #include <errno.h> |
---|
[66] | 21 | |
---|
| 22 | void |
---|
[1018] | 23 | rpResult(RpLibrary* lib) |
---|
| 24 | { |
---|
[66] | 25 | char outputFile[100]; |
---|
[1018] | 26 | std::string xtext; |
---|
[66] | 27 | FILE* fp; |
---|
| 28 | time_t t; |
---|
| 29 | |
---|
[1018] | 30 | xtext = lib->xml(); |
---|
[66] | 31 | |
---|
| 32 | // create output filename |
---|
| 33 | snprintf(outputFile, 50, "run%d.xml", (int)time(&t)); |
---|
| 34 | |
---|
| 35 | // write out the result file |
---|
| 36 | fp = fopen(outputFile, "w"); |
---|
| 37 | if(!fp) { |
---|
| 38 | fprintf(stderr,"can't save results (err=%d)\n", errno); |
---|
| 39 | return; |
---|
| 40 | } |
---|
[1018] | 41 | int fsize = fwrite(xtext.c_str(), xtext.length(), sizeof(char), fp); |
---|
| 42 | if (fsize != (int)xtext.length()) { |
---|
| 43 | fprintf(stderr, "short write: can't save results (err=%d)\n", errno); |
---|
| 44 | fclose(fp); |
---|
| 45 | return; |
---|
| 46 | } |
---|
[66] | 47 | fclose(fp); |
---|
| 48 | // tell Rappture the file name |
---|
| 49 | printf("=RAPPTURE-RUN=>%s\n", outputFile); |
---|
| 50 | } |
---|