examples/4_cells_model/loop.c
void readInput() {
  static unsigned char count = 0;
  /* The check here is very expensive! */
  // Initialisation
  if(0 == count) {
    fi1 = fopen(IFILE1, "r");
    if (fi1 == NULL){
      perror(IFILE1);
      exit(1);
    }
    fi2 = fopen(IFILE2, "r");
    if (fi2 == NULL){
      perror(IFILE2);
      exit(1);
    }
    fi3 = fopen(IFILE3, "r");
    if (fi3 == NULL){
      perror(IFILE3);
    }
    ++count;
  }
  
  /* Reading x1, x2, x */
  

  char in1[256], in2[256], in3[256];

    while (fgets(in1,255,fi1) == NULL ){
      perror("No input 1");
      waitFor();
    }
    while (fgets(in2,255,fi2) == NULL ){
      perror("No input 2");
      waitFor();
    }
    while (fgets(in3,255,fi3) == NULL ){
      perror("No input 3");
      waitFor();
    }
  
    char *ret1 = NULL, *v1 = NULL;
    ret1 = strtok(in1, ",");
    if(ret1 == NULL){
      /* This means nothing found! */
      /* Set all events to false */
      exit(1);
    }
    while(ret1 != NULL) {
      v1 = strtok(NULL, ",");
      if (v1 != NULL) {
        if (strcmp(ret1, "x1") == 0){
          x1 = atof(v1);
    }
      }
      else {
        perror("NULL while scanning input 1");
        exit(1);
      }

      /* Read the next one! */
      ret1 = strtok(NULL, ",");
    }
  
    // input 2
    char *ret2 = NULL, *v2 = NULL;
    ret2 = strtok(in2, ",");
    if(ret2 == NULL){
      /* This means nothing found! */
      exit(1);
    }
    while(ret2 != NULL) {
      v2 = strtok(NULL, ",");
      if (v2 != NULL) {
        if (strcmp(ret2, "x2") == 0){
          x2 = atof(v2);
        }
      }
      else {
        perror("NULL while scanning input 2");
        exit(1);
      }

      /* Read the next one! */
      ret2 = strtok(NULL, ",");
    }

    // input 3
    char *ret3 = NULL, *v3 = NULL;
    ret3 = strtok(in3, ",");
    if(ret3 == NULL){
      /* This means nothing found! */
      exit(1);
    }
    while(ret3 != NULL) {
      v3 = strtok(NULL, ",");
      if (v3 != NULL) {
        if (strcmp(ret3, "x") == 0){
          x = atof(v3);
        }
      }
      else {
        perror("NULL while scanning input 3");
        exit(1);
      }

      /* Read the next one! */
      ret3 = strtok(NULL, ",");
    }
  
  
  
  
  fprintf(stdout, "%s:%f %s:%f %s:%f tick:%ld\n", "x1", x1,
    "x2", x2, "x", x, tick);
  fflush(stdout);
}
/* Read input x1, x2, x from files */
Read input x1, x2, x from files
Read input x1 x2 x from files
void readInput() {
  static unsigned char count = 0;
  if(0 == count) {
    fi1 = fopen(IFILE1, "r");
    if (fi1 == NULL){
      perror(IFILE1);
      exit(1);
    }
    fi2 = fopen(IFILE2, "r");
    if (fi2 == NULL){
      perror(IFILE2);
      exit(1);
    }
    fi3 = fopen(IFILE3, "r");
    if (fi3 == NULL){
      perror(IFILE3);
    }
    ++count;
  }
  char in1[256], in2[256], in3[256];
    while (fgets(in1,255,fi1) == NULL ){
      perror("No input 1");
      waitFor();
    }
    while (fgets(in2,255,fi2) == NULL ){
      perror("No input 2");
      waitFor();
    }
    while (fgets(in3,255,fi3) == NULL ){
      perror("No input 3");
      waitFor();
    }
    char *ret1 = NULL, *v1 = NULL;
    ret1 = strtok(in1, ",");
    if(ret1 == NULL){
      exit(1);
    }
    while(ret1 != NULL) {
      v1 = strtok(NULL, ",");
      if (v1 != NULL) {
        if (strcmp(ret1, "x1") == 0){
          x1 = atof(v1);
    }
      }
      else {
        perror("NULL while scanning input 1");
        exit(1);
      }
      ret1 = strtok(NULL, ",");
    }
    char *ret2 = NULL, *v2 = NULL;
    ret2 = strtok(in2, ",");
    if(ret2 == NULL){
      exit(1);
    }
    while(ret2 != NULL) {
      v2 = strtok(NULL, ",");
      if (v2 != NULL) {
        if (strcmp(ret2, "x2") == 0){
          x2 = atof(v2);
        }
      }
      else {
        perror("NULL while scanning input 2");
        exit(1);
      }
      ret2 = strtok(NULL, ",");
    }
    char *ret3 = NULL, *v3 = NULL;
    ret3 = strtok(in3, ",");
    if(ret3 == NULL){
      exit(1);
    }
    while(ret3 != NULL) {
      v3 = strtok(NULL, ",");
      if (v3 != NULL) {
        if (strcmp(ret3, "x") == 0){
          x = atof(v3);
        }
      }
      else {
        perror("NULL while scanning input 3");
        exit(1);
      }
      ret3 = strtok(NULL, ",");
    }
  fprintf(stdout, "%s:%f %s:%f %s:%f tick:%ld\n", "x1", x1,
    "x2", x2, "x", x, tick);
  fflush(stdout);
}
void readInput ( ) { static unsigned char count = 0 ; if ( 0 == count ) { fi1 = fopen ( IFILE1 , " " ) ; if ( fi1 == NULL ) { perror ( IFILE1 ) ; exit ( 1 ) ; } fi2 = fopen ( IFILE2 , " " ) ; if ( fi2 == NULL ) { perror ( IFILE2 ) ; exit ( 1 ) ; } fi3 = fopen ( IFILE3 , " " ) ; if ( fi3 == NULL ) { perror ( IFILE3 ) ; } ++ count ; } char in1 [ 256 ] , in2 [ 256 ] , in3 [ 256 ] ; while ( fgets ( in1 , 255 , fi1 ) == NULL ) { perror ( " " ) ; waitFor ( ) ; } while ( fgets ( in2 , 255 , fi2 ) == NULL ) { perror ( " " ) ; waitFor ( ) ; } while ( fgets ( in3 , 255 , fi3 ) == NULL ) { perror ( " " ) ; waitFor ( ) ; } char * ret1 = NULL , * v1 = NULL ; ret1 = strtok ( in1 , " " ) ; if ( ret1 == NULL ) { exit ( 1 ) ; } while ( ret1 != NULL ) { v1 = strtok ( NULL , " " ) ; if ( v1 != NULL ) { if ( strcmp ( ret1 , " " ) == 0 ) { x1 = atof ( v1 ) ; } } else { perror ( " " ) ; exit ( 1 ) ; } ret1 = strtok ( NULL , " " ) ; } char * ret2 = NULL , * v2 = NULL ; ret2 = strtok ( in2 , " " ) ; if ( ret2 == NULL ) { exit ( 1 ) ; } while ( ret2 != NULL ) { v2 = strtok ( NULL , " " ) ; if ( v2 != NULL ) { if ( strcmp ( ret2 , " " ) == 0 ) { x2 = atof ( v2 ) ; } } else { perror ( " " ) ; exit ( 1 ) ; } ret2 = strtok ( NULL , " " ) ; } char * ret3 = NULL , * v3 = NULL ; ret3 = strtok ( in3 , " " ) ; if ( ret3 == NULL ) { exit ( 1 ) ; } while ( ret3 != NULL ) { v3 = strtok ( NULL , " " ) ; if ( v3 != NULL ) { if ( strcmp ( ret3 , " " ) == 0 ) { x = atof ( v3 ) ; } } else { perror ( " " ) ; exit ( 1 ) ; } ret3 = strtok ( NULL , " " ) ; } fprintf ( stdout , " \n " , " " , x1 , " " , x2 , " " , x , tick ) ; fflush ( stdout ) ; }
Read input x1, x2, x from files
Read input x1 x2 x from files
/* The check here is very expensive! */ // Initialisation /* Reading x1, x2, x */ /* This means nothing found! */ /* Set all events to false */ /* Read the next one! */ // input 2 /* This means nothing found! */ /* Read the next one! */ // input 3 /* This means nothing found! */ /* Read the next one! */