int main(void) { FILE *f; Akind *a = 0; int Ldef = 0; unsigned int nanbits[2]; fpinit_ASL(); #ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */ f = fopen("arith.h", "w"); if (!f) { printf("Cannot open arith.h\n"); return 1; } #else f = stdout; #endif if (sizeof(double) == 2*sizeof(long)) a = Lcheck(); else if (sizeof(double) == 2*sizeof(int)) { Ldef = 1; a = icheck(); } else if (sizeof(double) == sizeof(long)) a = ccheck(); if (a) { fprintf(f, "#define %s\n#define Arith_Kind_ASL %d\n", a->name, a->kind); if (Ldef) fprintf(f, "#define Long int\n#define Intcast (int)(long)\n"); if (dalign) fprintf(f, "#define Double_Align\n"); if (sizeof(char*) == 8) fprintf(f, "#define X64_bit_pointers\n"); #ifndef NO_LONG_LONG if (sizeof(long long) > sizeof(long) && sizeof(long long) == sizeof(void*)) fprintf(f, "#define LONG_LONG_POINTERS\n"); if (sizeof(long long) < 8) #endif fprintf(f, "#define NO_LONG_LONG\n"); if (a->kind <= 2) { if (fzcheck()) fprintf(f, "#define Sudden_Underflow\n"); t_nan = -a->kind; if (need_nancheck()) fprintf(f, "#define NANCHECK\n"); if (sizeof(double) == 2*sizeof(unsigned int)) { get_nanbits(nanbits, a->kind); fprintf(f, "#define QNaN0 0x%x\n", nanbits[0]); fprintf(f, "#define QNaN1 0x%x\n", nanbits[1]); } } return 0; } fprintf(f, "/* Unknown arithmetic */\n"); return 1; }
static int _main(int argc, char* argv[], MPI_Comm *pcomm, void *exc) { static bool initialized = false; if (!initialized) { #ifdef HAVE_AMPL // Switch to 53-bit rounding if appropriate, to eliminate some // cross-platform differences. fpinit_ASL(); #endif // Tie signals to Dakota's abort_handler. Dakota::register_signal_handlers(); // Have abort_handler() throw an exception rather than aborting the process. Dakota::abort_mode = Dakota::ABORT_THROWS; initialized = true; } // Parse input and construct Dakota LibraryEnvironment, performing // input data checks. Assumes comm rank 0. Dakota::ProgramOptions opts(argc, argv, 0); Dakota::LibraryEnvironment* env = 0; if (pcomm) { MPI_Comm comm = *pcomm; env = new Dakota::LibraryEnvironment(comm, opts); } else { env = new Dakota::LibraryEnvironment(opts); } // Execute the environment. int retval = 0; try { env->execute(); } catch (boost::system::system_error& se) { retval = se.code().value(); if (PyErr_Occurred()) { PyObject *type = NULL, *value = NULL, *traceback = NULL; PyErr_Fetch(&type, &value, &traceback); bp::object *tmp = (bp::object *)exc; PyObject_SetAttrString(tmp->ptr(), "type", type); PyObject_SetAttrString(tmp->ptr(), "value", value); PyObject_SetAttrString(tmp->ptr(), "traceback", traceback); } } delete env; return retval; }
jac0dim_ASL(ASL *asl, char *stub, ftnlen stub_len) #endif { FILE *nl; int i, k, nlv; char *s, *se; const char *opfmt; EdRead ER, *R; if (!asl) badasl_ASL(asl,0,"jac0dim"); fpinit_ASL(); /* get IEEE arithmetic, if possible */ if (stub_len <= 0) for(i = 0; stub[i]; i++); else for(i = stub_len; stub[i-1] == ' ' && i > 0; --i); filename = (char *)M1alloc(i + 5); s = stub_end = filename + i; strncpy(filename, stub, i); strcpy(s, ".nl"); nl = fopen(filename, "rb"); if (!nl && i > 3 && !strncmp(s-3, ".nl", 3)) { *s = 0; stub_end = s - 3; nl = fopen(filename, "rb"); } if (!nl) { if (return_nofile) return 0; fflush(stdout); what_prog(); fprintf(Stderr, "can't open %s\n", filename); exit(1); } R = EdReadInit_ASL(&ER, asl, nl, 0); R->Line = 0; s = read_line(R); binary_nl = 0; opfmt = "%d"; switch(*s) { #ifdef DEPRECATED case 'E': /* deprecated "-oe" format */ {int ncsi = 0; k = Sscanf(s, "E%d %d %d %d %d %d", &n_var, &n_con, &n_obj, &maxrownamelen, &maxcolnamelen, &ncsi); if (k < 5) badints(R, k, 5); if (ncsi) { if (ncsi != 6) { badread(R); fprintf(Stderr, "expected 6th integer to be 0 or 6, not %d\n", ncsi); exit(1); } s = read_line(R); k = Sscanf(s, " %d %d %d %d %d %d", &comb, &comc, &como, &comc1, &como1, &nfunc); if (k != 6) badints(R, k, 6); } } break; #endif case 'z': case 'Z': opfmt = "%hd"; case 'B': case 'b': binary_nl = 1; xscanf = bscanf; goto have_xscanf; case 'h': case 'H': opfmt = "%hd"; binary_nl = 1; xscanf = hscanf; goto have_xscanf; case 'G': case 'g': xscanf = ascanf; have_xscanf: if ((k = ampl_options[0] = strtol(++s, &se, 10))) { if (k > 9) { fprintf(Stderr, "ampl_options = %d is too large\n", k); exit(1); } for(i = 1; i <= k && se > s; i++) ampl_options[i] = strtol(s = se,&se,10); if (ampl_options[2] == 3) ampl_vbtol = strtod(s = se, &se); } s = read_line(R); n_eqn = -1; k = Sscanf(s, " %d %d %d %d %d %d", &n_var, &n_con, &n_obj, &nranges, &n_eqn, &n_lcon); if (k < 3) badints(R,k,3); nclcon = n_con + n_lcon; /* formerly read2(R, &nlc, &nlo); */ s = read_line(R); n_cc = nlcc = ndcc = nzlb = 0; k = Sscanf(s, " %d %d %d %d %d %d", &nlc, &nlo, &n_cc, &nlcc, &ndcc, &nzlb); if (k < 2) badints(R,k,2); if ((n_cc += nlcc) > 0 && k < 6) ndcc = -1; /* indicate unknown */ read2(R, &nlnc, &lnc); nlvb = -1; s = read_line(R); k = Sscanf(s, " %d %d %d", &nlvc, &nlvo, &nlvb); if (k < 2) badints(R,k,2); /* read2(R, &nwv, &nfunc); */ s = read_line(R); asl->i.flags = 0; k = Sscanf(s, " %d %d %d %d", &nwv, &nfunc, &i, &asl->i.flags); if (k < 2) badints(R,k,2); else if (k >= 3 && i != Arith_Kind_ASL && i) { #ifdef Want_bswap if (i > 0 && i + Arith_Kind_ASL == 3) { asl->i.iadjfcn = asl->i.dadjfcn = bswap_ASL; binary_nl = i << 1; } else #endif badfmt(R); } if (nlvb < 0) /* ampl versions < 19930630 */ read2(R, &nbv, &niv); else { s = read_line(R); k = Sscanf(s, " %d %d %d %d %d", &nbv, &niv, &nlvbi, &nlvci, &nlvoi); if (k != 5) badints(R,k,5); } /* formerly read2(R, &nzc, &nzo); */ s = read_line(R); k = Sscanf(s, " %D %D", &nZc, &nZo); if (k != 2) badints(R, k, 2); nzc = nZc; nzo = nZo; read2(R, &maxrownamelen, &maxcolnamelen); s = read_line(R); k = Sscanf(s, " %d %d %d %d %d", &comb, &comc, &como, &comc1, &como1); if (k != 5) badints(R,k,5); } student_check_ASL(asl); if (n_con < 0 || n_var <= 0 || n_obj < 0) { what_prog(); fprintf(Stderr, "jacdim: got M = %d, N = %d, NO = %d\n", n_con, n_var, n_obj); exit(1); } asl->i.opfmt = opfmt; asl->i.n_var0 = asl->i.n_var1 = n_var; asl->i.n_con0 = asl->i.n_con1 = n_con; if ((nlv = nlvc) < nlvo) nlv = nlvo; if (nlv <= 0) nlv = 1; x0len = nlv * sizeof(real); x0kind = ASL_first_x; n_conjac[0] = 0; n_conjac[1] = n_con; c_vars = o_vars = n_var; /* confusion arises otherwise */ return nl; }