source: branches/1.3/src/core/RpResult.cc @ 5734

Last change on this file since 5734 was 5675, checked in by ldelgass, 9 years ago

merge r5673 from trunk (eol-style)

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[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
[3177]11 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
[115]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
22void
[1018]23rpResult(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) {
[1382]38        fprintf(stderr,"can't save results: %s\n", strerror(errno));
[66]39        return;
40    }
[1018]41    int fsize = fwrite(xtext.c_str(), xtext.length(), sizeof(char), fp);
42    if (fsize != (int)xtext.length()) {
[1382]43        fprintf(stderr, "short write: can't save results: %s\n",
44                strerror(errno));
[1018]45        fclose(fp);
46        return;
47    }
[66]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.