Example #1
0
//-----------------------------------------------------------------------------
//BOP
// !IROUTINE:  ESMC_Initialize - Initialize the ESMF Framework
//
// !INTERFACE:
  int ESMC_Initialize(
//
// !RETURN VALUE:
//  int return code
//
// !ARGUMENTS:
    int *rc,        // return code
    ...){           // optional arguments
//  
// !DESCRIPTION:
//
//EOP

    int localrc;
    ESMCI_ArgList   argPtr;
    ESMCI_ArgID     argID;
    char *defaultConfigFilename;

    // check the optional argument list
    ESMCI_ArgStart(argPtr, rc);
    while ( (argID=ESMCI_ArgGetID(argPtr)) != ESMCI_ArgLastID ) {
      switch ( argID ) {
        case ESMCI_InitArgDefaultConfigFilenameID:
          ESMCI_ArgGetString(argPtr);
          break;
        default:
          printf("ESMC_Initialize: Improperly specified optional argument list\n");
          return ESMC_RC_OPTARG_BAD;
      }
    }

    // parse the optional argument list
    ESMCI_ArgStart(argPtr, rc);
    while ( (argID=ESMCI_ArgGetID(argPtr)) != ESMCI_ArgLastID ) {
      switch ( argID ) {
        case ESMCI_InitArgDefaultConfigFilenameID:
          defaultConfigFilename = ESMCI_ArgGetString(argPtr);
          break;
        default:
          printf("ESMC_Initialize: Improperly specified optional argument list\n");
          return ESMC_RC_OPTARG_BAD;
      }
    }
    
    // todo: it may be better to go directly into F90 instead of using C++
    // todo: if this was implemented right it were to use the defaultConfigFile.
    localrc = ESMCI_Initialize();
    
    // todo: use LogErr to do error handling for localrc

    return localrc;

  } // end ESMC_Initialize
Example #2
0
//-----------------------------------------------------------------------------
//BOP
// !IROUTINE:  ESMCI::TestStart() - Initialize the framework, print a standard msg
//
// !INTERFACE:   
int TestStart(
//
// !RETURN VALUE:
//    ESMF_SUCCESS or ESMF_FAILURE
//
// !ARGUMENTS:
  const char *file, // in - test filename
  int line,         // in - test line number in test filename
  int only) {       // in - if set to 0, print on stderr also
// 
// !DESCRIPTION:
//    Initializes the framework, prints out the standard messages needed
//    by the testing scripts.
//    If {\tt only} is zero, also print same message to stderr as well
//    as the normal output on stdout.  The default for {\tt only} is 1.
//
//EOP
//-----------------------------------------------------------------------------
  int rc;
  ESMCI::VM *globalVM;
  char msgbuf[ESMF_MAXSTR], failMsg[ESMF_MAXSTR];
  int numPETs;
  ESMCI::LogErr *whichLog;

  // TODO: this should be settable by the user
  whichLog = &ESMC_LogDefault;

  if (file == NULL) {
    sprintf(msgbuf, "FAIL %s, line %d, null filename passed to "
      "ESMCI::TestStart()\n", __FILE__, __LINE__);
    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);
    return(ESMF_FAILURE);
  }

  char logFileName[160];
  const char *underScore = strchr(file, '_');
  if (underScore == NULL) underScore = file-1;
  const char *period = strrchr(file, '.');
  int numChars = period - underScore;
  strncpy(logFileName, underScore+1, numChars);
  strcpy(logFileName+numChars, "Log\0");

  rc = ESMCI_Initialize((char *)"", ESMC_CAL_NOCALENDAR, logFileName,
    ESMC_LOG_MULTI);
  if (rc != ESMF_SUCCESS) {
    sprintf(msgbuf, "FAIL  rc=%d, %s, line %d, Unable to initialize ESMF\n", rc,
      file, line);
    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);
    return(rc);
  }

  globalVM = ESMCI::VM::getGlobal(&rc);
  if ((globalVM == NULL) || (rc != ESMF_SUCCESS)) {
    sprintf(msgbuf, "FAIL  rc=%d, %s, line %d, Unable to get GlobalVM\n", rc,
      file, line);

    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);

    return (false);
  }

  numPETs = globalVM->getPetCount();

  sprintf(msgbuf, "Beginning Test, file %s, line %d\n", file, line);
  whichLog->Write(msgbuf, ESMC_LOG_INFO);
  if (!only)
    fprintf(stderr, "%s", msgbuf);

  sprintf(msgbuf, "NUMBER_OF_PROCESSORS %d\n", numPETs);
  whichLog->Write(msgbuf, ESMC_LOG_INFO);
  if (!only)
    fprintf(stderr, "%s", msgbuf);
 
  return(ESMF_SUCCESS);

} // end ESMC_TestStart