source: branches/1.7/src/core/RpResult.cc @ 6705

Last change on this file since 6705 was 6705, checked in by clarksm, 4 years ago

Enable "ionhelper" to execute jobs and immediately put results in cache.
This includes reporting run.xml location with absolute path.

  • Property svn:eol-style set to native
File size: 1.8 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-2012  HUBzero Foundation, LLC
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#include <limits.h>
22#include <unistd.h>
23
24void
25rpResult(RpLibrary* lib)
26{
27    char outputFile[100];
28    char currentWorkingDirectory[PATH_MAX+1];
29    char *cwd;
30    std::string xtext;
31    FILE* fp;
32    time_t t;
33
34    xtext = lib->xml();
35
36    // get current working directory
37    cwd = getcwd(currentWorkingDirectory,PATH_MAX);
38
39    // create output filename
40    snprintf(outputFile, 50, "run%d.xml", (int)time(&t));
41
42    // write out the result file
43    fp = fopen(outputFile, "w");
44    if(!fp) {
45        fprintf(stderr,"can't save results: %s\n", strerror(errno));
46        return;
47    }
48    int fsize = fwrite(xtext.c_str(), xtext.length(), sizeof(char), fp);
49    if (fsize != (int)xtext.length()) {
50        fprintf(stderr, "short write: can't save results: %s\n",
51        strerror(errno));
52        fclose(fp);
53        return;
54    }
55    fclose(fp);
56    // tell Rappture the file name
57    if (cwd != NULL) {
58        printf("=RAPPTURE-RUN=>%s/%s\n", currentWorkingDirectory, outputFile);
59    } else {
60        printf("=RAPPTURE-RUN=>%s\n", outputFile);
61    }
62}
Note: See TracBrowser for help on using the repository browser.