static int print_human_version(void) {
  char xver[256], xdate[256], xfdate[256], xcommit[256];
  time_t xdate_t; struct tm *xdate_tm;
  if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1;
  xdate_t=(time_t)atoi(xdate);
  if (!(xdate_tm=gmtime(&xdate_t))) return 1;
  strftime(xfdate,sizeof(xfdate),"%a, %d %b %Y %H:%M:%S Z",xdate_tm);
  if ((sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD")))
    return 1;
  snprintf(xver,sizeof(xver),"; git at commit %s on %s",xcommit,xfdate);
  if (show_unclean && (sys(NULL,0,"git diff-index --quiet HEAD"))) {
    char buf[256], now[256]; time_t now_t=time(NULL); struct tm *now_tm;
    if (!(now_tm=gmtime(&now_t))) return 1;
    strftime(now,sizeof(now),"%a, %d %b %Y %H:%M:%S Z",now_tm);
    snprintf(buf,sizeof(buf),"%s; unclean git build on %s",xver,now);
    strncpy(xver,buf,sizeof(xver));
  }
  printf("%s\n",xver);
  return 0;
}
Example #2
0
File: sysjs.c Project: jelaas/sysjs
int main(int argc, char *argv[]) {
	int i, rc;
	
	prg.argc = argc;
	prg.argv = argv;
	prg.name = argv[1];

	duk_context *ctx = duk_create_heap_default();

	duk_push_global_object(ctx);
	duk_push_object(ctx);  /* -> [ ... global obj ] */
	sys1(ctx);

	for(i=1;i<argc;i++) {
		duk_push_string(ctx, argv[i]);
		duk_put_prop_index(ctx, -2, i-1);
	}
	duk_push_number(ctx, argc-1);
	duk_put_prop_string(ctx, -2, "argc");

	duk_put_prop_string(ctx, -2, "Sys1");  /* -> [ ... global ] */

	duk_push_object(ctx);  /* -> [ ... global obj ] */
	prg1(ctx);
	duk_put_prop_string(ctx, -2, "Prg1");  /* -> [ ... global ] */

	prg_push_modsearch(ctx);
	
	duk_pop(ctx);

	prg_parse_appfile(&prg);
	
	// push file
	duk_push_lstring(ctx, prg.main->buf, prg.main->size);
	duk_push_string(ctx, argv[1]);
	
	// execute file (compile + call)
	prg_register(&prg);
	rc = duk_safe_call(ctx, prg_wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
	if (rc != DUK_EXEC_SUCCESS) {
		print_error(ctx, stderr);
		exit(2);
	}
	duk_pop(ctx);  /* pop eval result */
	
	duk_destroy_heap(ctx);

	return prg.status;
}
Example #3
0
  void Newton<_Type>::arclength_solve(DenseVector<_Type>& x) {
#ifdef PARANOID
    if(!this -> INITIALISED) {
      std::string problem;
      problem = "The Newton.arclength_solve method has been called, but \n";
      problem += " you haven't called the arc_init method first. This means \n";
      problem += " that a starting solution & derivatives thereof are unknown. \n";
      problem += " Please initialise things appropriately! ";
      throw ExceptionRuntime(problem);
    }
#endif
#ifdef DEBUG
    std::cout.precision(6);
    std::cout << "[ DEBUG ] : Entering arclength_solve of the Newton class with\n";
    std::cout << "[ DEBUG ] : a parameter of " << *(this -> p_PARAM) << "\n";
#endif
    // backup the state/system in case we fail
    DenseVector<_Type> backup_state(x);
    _Type backup_parameter(*(this -> p_PARAM));

    int det_sign(1);
    // init some local vars
    bool step_succeeded(false);
    unsigned itn(0);
    // make a guess at the next solution
    *(this -> p_PARAM) = this -> LAST_PARAM + this -> PARAM_DERIV_S * this -> DS;
    x = this -> LAST_X + this -> X_DERIV_S * this -> DS;

    // the order of the system
    unsigned N = this -> p_RESIDUAL -> get_order();
    DenseMatrix<_Type> J(N, N, 0.0);
    DenseVector<_Type> R1(N, 0.0);
    DenseVector<_Type> R2(N, 0.0);
    DenseVector<_Type> dR_dp(N, 0.0);
    //
    do {
      // update the residual object to the current guess
      this -> p_RESIDUAL -> update(x);
      // get the Jacobian of the system
      J = this -> p_RESIDUAL -> jacobian();
      R1 = this -> p_RESIDUAL -> residual();
      // get the residual of the EXTRA arclength residual
      double E1 = this -> arclength_residual(x);
      // compute derivatives w.r.t the parameter
      *(this -> p_PARAM) += this -> DELTA;
      this -> p_RESIDUAL -> residual_fn(x, R2);
      double E2 = this -> arclength_residual(x);
      *(this -> p_PARAM)  -= this -> DELTA;
      dR_dp = (R2 - R1) / this -> DELTA;
      _Type dE_dp = (E2 - E1) / this -> DELTA;
      // bordering algorithm
      DenseVector<_Type> y(-R1);
      DenseVector<_Type> z(-dR_dp);
#ifdef LAPACK
      DenseLinearSystem<_Type> sys1(&J, &y, "lapack");
#else
      DenseLinearSystem<_Type> sys1(&J, &y, "native");
#endif
      sys1.set_monitor_det(MONITOR_DET);
      try {
        sys1.solve();
        det_sign = sys1.get_det_sign();
      } catch ( const ExceptionExternal &error ) {
        break;
      }
      // the solve will have overwritten the LHS, so we need to replace it
      J = this -> p_RESIDUAL -> jacobian();
#ifdef LAPACK
      DenseLinearSystem<_Type> sys2(&J, &z, "lapack");
#else
      DenseLinearSystem<_Type> sys2(&J, &z, "native");
#endif
      try {
        sys2.solve();
      } catch( const ExceptionExternal &error ) {
        break;
      }
      DenseVector<_Type> JacE(this -> Jac_arclength_residual(x));
      _Type delta_p = - (E1 + Utility::dot(JacE, y)) /
                      (dE_dp + Utility::dot(JacE, z));
      DenseVector<_Type> delta_x = y + z * delta_p;
      double max_correction = std::max(delta_x.inf_norm(), std::abs(delta_p));
      if(max_correction < this -> TOL) {
        step_succeeded = true;
        break;
      }
      // add the corrections to the state variables
      x += delta_x;
      *(this -> p_PARAM) += delta_p;
      ++itn;
      if(itn > MAX_STEPS) {
        step_succeeded = false;
        break;
      }
    } while(true);

    // is this a successful step?
    if(!step_succeeded) {
#ifdef DEBUG
      std::cout << "[ DEBUG ] : REJECTING STEP \n";
#endif
      // if not a successful step then restore things
      x = backup_state;
      *(this -> p_PARAM) = backup_parameter;
      // restore the residual object to its initial state
      this -> p_RESIDUAL -> update(x);
      // reduce our step length
      this -> DS /= this -> ARCSTEP_MULTIPLIER;
    } else {
      // update the variables needed for arc-length continuation
      this -> update(x);
      if(LAST_DET_SIGN * det_sign < 0) {
        LAST_DET_SIGN = det_sign;
        std::string problem;
        problem = "[ INFO ] : Determinant monitor has changed signs in the Newton class.\n";
        problem += "[ INFO ] : Bifurcation detected.\n";
        throw ExceptionBifurcation(problem);
      } else {
        LAST_DET_SIGN = det_sign;
      }
#ifdef DEBUG
      std::cout << "[ DEBUG ] : Number of iterations = " << itn << "\n";
      std::cout << "[ DEBUG ] : Parameter p = " << *(this -> p_PARAM)
                << "; arclength DS = " << this -> DS << "\n";
#endif
      if(itn >= 7) {
        // converging too slowly, so decrease DS
        this -> DS /= this -> ARCSTEP_MULTIPLIER;
#ifdef DEBUG
        std::cout << "[ DEBUG ] : I decreased DS to " << this -> DS << "\n";
#endif
      }
      if(itn <= 2) {
        if(std::abs(this -> DS * this -> ARCSTEP_MULTIPLIER) < this -> MAX_DS) {
          // converging too quickly, so increase DS
          this -> DS *= this -> ARCSTEP_MULTIPLIER;
#ifdef DEBUG
          std::cout << "[ DEBUG ] : I increased DS to " << this -> DS << "\n";
#endif
        }
      }
    }
  }