source: trunk/src/core/RpResult.cc @ 1731

Last change on this file since 1731 was 1382, checked in by gah, 16 years ago

fixed encoding problems

File size: 1.5 KB
Line 
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  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.
15 * ======================================================================
16 */
17#include <stdlib.h>
18#include <time.h>
19#include <RpLibrary.h>
20#include <errno.h>
21
22void
23rpResult(RpLibrary* lib)
24{
25    char outputFile[100];
26    std::string xtext;
27    FILE* fp;
28    time_t t;
29
30    xtext = lib->xml();
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: %s\n", strerror(errno));
39        return;
40    }
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: %s\n",
44                strerror(errno));
45        fclose(fp);
46        return;
47    }
48    fclose(fp);
49    // tell Rappture the file name
50    printf("=RAPPTURE-RUN=>%s\n", outputFile);
51}
Note: See TracBrowser for help on using the repository browser.