Initializing help system before first use

Interrupting a running model using Ctrl-C


Type: Programming
Rating: 2 (easy-medium)
Description: Demonstrates how to interrupt a running model with Ctrl-C.
The C program requires the mos file to be pre-compiled.
File(s): mmexctc.c
Data file(s): toolong.mos


mmexctc.c
/********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexctc.c                                      */
/*  ``````````````                                      */
/*  Example for the use of the Mosel libraries          */
/*  (Interrupting a running model)                      */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: Y. Colombani, 2001                      */
/********************************************************/

#include <stdio.h>
#include <signal.h>
#include "xprm_rt.h"

XPRMmodel mod;

void stop_mod(int sig)
{
 if(XPRMisrunmod(mod))            /* If the model `mod' is currently running */
  XPRMstoprunmod(mod);            /* Stop it */
}

int main()
{
 int rts_run,result,i;

 i=XPRMinit();
 if((i!=0)&&(i!=32))              /* Initialize Mosel */
  return 1;

 if((mod=XPRMloadmod("Models/toolong.bim",NULL))==NULL)   /* Load a BIM file */
  return 2;

 signal(SIGINT,stop_mod);         /* Redirect the Ctrl-C signal */

 printf("Running a long loop... Press Ctrl-C to stop it!\n");
 rts_run=XPRMrunmod(mod,&result,NULL);    /* Run the model */

 if(rts_run==0)
  printf("Normal termination.\n");
 else
  if(rts_run&XPRM_RT_STOP)
   printf("Interrupted.\n");
  else
   printf("Error when running.\n");
 
 return 0;
}


© 2001-2023 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.