/***********************************************************************//** * @brief Read GTIs from HDU. * * @param[in] hdu GTI table. * * Reads the Good Time Intervals from the GTI extension. Since the Fermi * LAT Science Tools do not set corrently the time reference for source * maps, the method automatically adds this missing information so that * the time reference is set correctly. The time reference that is assumed * for Fermi LAT is * * MJDREFI 51910 * MJDREFF 0.00074287037037037 * ***************************************************************************/ void GLATEventCube::read_gti(const GFitsTable& hdu) { // Work on a local copy of the HDU to make the kluge work GFitsTable* hdu_local = hdu.clone(); // Kluge: modify HDU table in case that the MJDREF header keyword is // blank. This happens for Fermi LAT source maps since the Science // Tools do not properly write out the time reference. We hard-code // here the Fermi LAT time reference to circumvent the problem. if (hdu.has_card("MJDREF")) { if (gammalib::strip_whitespace(hdu.string("MJDREF")).empty()) { hdu_local->header().remove("MJDREF"); hdu_local->card("MJDREFI", 51910, "Integer part of MJD reference"); hdu_local->card("MJDREFF", 0.00074287037037037, "Fractional part of MJD reference"); } } // Read Good Time Intervals m_gti.read(*hdu_local); // Set time set_times(); // Return return; }
/***********************************************************************//** * @brief Constructor * * @param[in] map Sky map. * @param[in] weights Event cube weights. * @param[in] ebds Energy boundaries. * @param[in] gti Good Time intervals. * * Constructs instance of events cube from a sky map, a map of weights, * energy boundaries and Good Time Intervals. ***************************************************************************/ GCTAEventCube::GCTAEventCube(const GSkyMap& map, const GSkyMap& weights, const GEbounds& ebds, const GGti& gti) : GEventCube() { // Initialise members init_members(); // Set sky map, energy boundaries and GTI m_map = map; this->ebounds(ebds); this->gti(gti); // Set weight map m_weights = weights; // Set sky directions set_directions(); // Set energies set_energies(); // Set times set_times(); // Return return; }
/***********************************************************************//** * @brief Read GTIs from HDU. * * @param[in] hdu GTI table. * * Reads the Good Time Intervals from the HDU. ***************************************************************************/ void GCTAEventCube::read_gti(const GFitsTable& hdu) { // Read Good Time Intervals m_gti.read(hdu); // Set times set_times(); // Return return; }
/***********************************************************************//** * @brief Read GTIs from HDU. * * @param[in] hdu Pointer to GTI table. * * Reads the Good Time Intervals from the GTI extension. * * @todo GTI read method should take const GFitsTable* as argument ***************************************************************************/ void GCTAEventCube::read_gti(const GFitsTable* hdu) { // Continue only if HDU is valid if (hdu != NULL) { // Read Good Time Intervals m_gti.read(const_cast<GFitsTable*>(hdu)); // Set times set_times(); } // endif: HDU was valid // Return return; }
void dpsx(SRC_NODE *node) { int retVal; start_node = node; close_fds(); if (start_node == NULL) return; set_times(); retVal = outputSeq(); close_fds(); if (retVal) { write_info(); sprintf(tmpStr, "%s/.dpsViewInfo", curexpdir); unixPathToWin(tmpStr, tmpPath, MAXPATH); writelineToVnmrJ("dps scopewindow ", tmpPath); } }
void Job_Touch(GNode *gn) { if (gn->type & (OP_JOIN|OP_USE|OP_EXEC|OP_OPTIONAL|OP_PHONY)) { /* * .JOIN, .USE, and .OPTIONAL targets are "virtual" targets * and, as such, shouldn't really be created. * Likewise, .PHONY targets are not really files */ return; } if (!(gn->type & OP_SILENT)) { (void)fprintf(stdout, "touch %s\n", gn->name); (void)fflush(stdout); } if (noExecute) { return; } if (gn->type & OP_ARCHV) { Arch_Touch(gn); } else if (gn->type & OP_LIB) { Arch_TouchLib(gn); } else { const char *file = gn->path != NULL ? gn->path : gn->name; if (set_times(file) == -1) { if (rewrite_time(file) == -1) { (void)fprintf(stdout, "*** couldn't touch %s: %s", file, strerror(errno)); (void)fflush(stdout); } } } }
int smart_rename (const char *from, const char *to, int preserve_dates ATTRIBUTE_UNUSED) { bfd_boolean exists; struct stat s; int ret = 0; exists = lstat (to, &s) == 0; #if 1 /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but fail instead. Also, chown is not present. */ if (exists) remove (to); ret = rename (from, to); if (ret != 0) { /* We have to clean up here. */ non_fatal (_("unable to rename '%s'; reason: %s"), to, strerror (errno)); unlink (from); } #else /* Use rename only if TO is not a symbolic link and has only one hard link, and we have permission to write to it. */ if (! exists || (!S_ISLNK (s.st_mode) && S_ISREG (s.st_mode) && (s.st_mode & S_IWUSR) && s.st_nlink == 1) ) { ret = rename (from, to); if (ret == 0) { if (exists) { /* Try to preserve the permission bits and ownership of TO. First get the mode right except for the setuid bit. Then change the ownership. Then fix the setuid bit. We do the chmod before the chown because if the chown succeeds, and we are a normal user, we won't be able to do the chmod afterward. We don't bother to fix the setuid bit first because that might introduce a fleeting security problem, and because the chown will clear the setuid bit anyhow. We only fix the setuid bit if the chown succeeds, because we don't want to introduce an unexpected setuid file owned by the user running objcopy. */ // chmod (to, s.st_mode & 0777); // if (chown (to, s.st_uid, s.st_gid) >= 0) // chmod (to, s.st_mode & 07777); } } else { /* We have to clean up here. */ non_fatal (_("unable to rename '%s'; reason: %s"), to, strerror (errno)); unlink (from); } } else { ret = simple_copy (from, to); if (ret != 0) non_fatal (_("unable to copy file '%s'; reason: %s"), to, strerror (errno)); if (preserve_dates) set_times (to, &s); unlink (from); } #endif /* _WIN32 && !__CYGWIN32__ */ return ret; }
/* Log the string given by the last two parameters. * Use the given generator. * Return 0 on success and -1 on failure. */ static int lprintfgen(LFILE *mf, char *gen, char *fmt, va_list ap) { int blen; /* size of data buffer */ char buf[LOGGING_BUFSIZE]; char buftemp[LOGGING_BUFSIZE]; char genbuf[LOGGING_GENMAX]; int ret; unsigned long sec; char timebuf[13]; char *timep; char timesbuf[20]; /* holds seconds and microseconds */ unsigned long usec; int written; if (mf==NULL) { if (ldebug_flag) fprintf(stderr, "lprintf called with NULL first parameter\n"); return -1; } if ( (mf->tmode) || (strstr(fmt, "%t") != NULL) ) if (set_times(&sec, &usec) != 0) { if (ldebug_flag) fprintf(stderr, "Error getting current time\n"); return -1; } if (mf->tmode) sprintf(timesbuf, "%lu;%lu;", sec, usec); else timesbuf[0] = 0; timep = strstr(fmt, "%t"); if (timep != NULL) { if (make_time_string(timebuf, sec, usec) != 0) { if (ldebug_flag) fprintf(stderr, "Error making time string in lprintf\n"); return -1; } if (strlen(fmt) + 13 >= LOGGING_BUFSIZE) { fprintf(stderr, "Format string is too long\n"); return -1; } sprintf(buf, "%.*s%s%s", (int)(timep-fmt), fmt, timebuf, timep+2); ret = vsnprintf(buftemp, LOGGING_BUFSIZE, buf, ap); } else ret = vsnprintf(buftemp, LOGGING_BUFSIZE, fmt, ap); if ((ret < 0) || (ret >= LOGGING_BUFSIZE)) { if (ldebug_flag) fprintf(stderr, "Error in lprintf format string\n"); return -1; } if (expand_gen(gen, genbuf, LOGGING_GENMAX) != 0) { if (ldebug_flag) fprintf(stderr, "Generator info does not fit\n"); } blen = strlen(buftemp) + strlen(genbuf) + strlen(timesbuf); ret = snprintf(buf, LOGGING_BUFSIZE, "%d:%s%s;%s", blen+1, timesbuf, genbuf, buftemp); if (ret >= LOGGING_BUFSIZE) { if (ldebug_flag) fprintf(stderr, "Error in lprintf: size too large to fit\n"); return -1; } while (written = write(mf->fd, buf, ret), written == -1 && errno == EINTR) ; if (written != ret) { if (ldebug_flag) fprintf(stderr, "lprintf error writing to pipe\n"); return -1; } return 0; }
JNIEXPORT void JNIFn(zebra, ZebraEngine, zePlay)(JNIEnv *env, jobject thiz, jint providedMoveCount, jbyteArray providedMoves) { EvaluationType eval_info; const char *black_name; const char *white_name; const char *opening_name; const char *op; double move_start, move_stop; int i; int side_to_move; int curr_move; int timed_search; int black_hash1, black_hash2, white_hash1, white_hash2; ui_event_t evt; int provided_move_count; int provided_move_index; int provided_move[65]; int silent = FALSE; int use_book = s_use_book; DROIDZEBRA_JNI_SETUP; force_exit = 0; if (skill[BLACKSQ] < 0 || skill[WHITESQ] < 0) { fatal_error("Set Player Info first"); } /* copy provided moves */ provided_move_index = 0; provided_move_count = 0; if (providedMoveCount > 0 && providedMoves) { jbyte *providedMovesJNI; provided_move_count = providedMoveCount; i = (*env)->GetArrayLength(env, providedMoves); if (provided_move_count > i) fatal_error("Provided move count is greater than array size %d>%d", provided_move_count, i); if (provided_move_count > 64) fatal_error("Provided move count is greater that 64: %d", provided_move_count); providedMovesJNI = (*env)->GetByteArrayElements(env, providedMoves, 0); if (!providedMovesJNI) fatal_error("failed to get provide moves (jni)"); for (i = 0; i < provided_move_count; i++) { provided_move[i] = providedMovesJNI[i]; } (*env)->ReleaseByteArrayElements(env, providedMoves, providedMovesJNI, 0); } /* Set up the position and the search engine */ game_init(NULL, &side_to_move); setup_hash(TRUE); clear_stored_game(); set_slack(floor(s_slack * 128.0)); set_perturbation(floor(s_perturbation * 128.0)); toggle_human_openings(s_human_opening); set_forced_opening(s_forced_opening_seq); opening_name = NULL; reset_book_search(); set_deviation_value(0, 0, 0.0); if (skill[BLACKSQ] == 0) black_name = "Player"; else black_name = "Zebra"; if (skill[WHITESQ] == 0) white_name = "Player"; else white_name = "Zebra"; set_names(black_name, white_name); set_move_list(black_moves, white_moves, score_sheet_row); set_evals(0.0, 0.0); for (i = 0; i < 60; i++) { black_moves[i] = PASS; white_moves[i] = PASS; } black_hash1 = my_random(); black_hash2 = my_random(); white_hash1 = my_random(); white_hash2 = my_random(); droidzebra_msg_game_start(); AGAIN: curr_move = PASS; while (game_in_progress() && !force_exit) { force_return = 0; silent = (provided_move_index < provided_move_count); droidzebra_enable_messaging(!silent); droidzebra_msg_move_start(side_to_move); remove_coeffs(disks_played); clear_evaluated(); if (SEPARATE_TABLES) { /* Computer players won't share hash tables */ if (side_to_move == BLACKSQ) { hash1 ^= black_hash1; hash2 ^= black_hash2; } else { hash1 ^= white_hash1; hash2 ^= white_hash2; } } generate_all(side_to_move); if (side_to_move == BLACKSQ) score_sheet_row++; // echo droidzebra_msg_candidate_moves(); set_move_list(black_moves, white_moves, score_sheet_row); set_times(floor(player_time[BLACKSQ]), floor(player_time[WHITESQ])); op = find_opening_name(); if (op != NULL && (!opening_name || strcmp(op, opening_name))) { opening_name = op; } droidzebra_msg_opening_name(opening_name); droidzebra_msg_last_move(disks_played > 0 ? get_stored_move(disks_played - 1) : PASS); display_board(stdout, board, side_to_move, TRUE, TRUE, TRUE); // echo if (move_count[disks_played] != 0) { move_start = get_real_timer(); clear_panic_abort(); if (provided_move_index >= provided_move_count) { if (skill[side_to_move] == 0) { curr_move = -1; if (auto_make_forced_moves && move_count[disks_played] == 1) { curr_move = move_list[disks_played][0]; } else { // compute evaluations if (s_practice_mode) { _droidzebra_compute_evals(side_to_move); if (force_exit) break; if (force_return) force_return = 0; // interrupted by user input } // wait for user event droidzebra_msg_get_user_input(side_to_move, &evt); if (evt.type == UI_EVENT_EXIT) { force_exit = 1; break; } else if (evt.type == UI_EVENT_MOVE) { curr_move = evt.evt_move.move; _droidzebra_undo_stack_clear(); // once player makes the move undo info is stale } else if (evt.type == UI_EVENT_UNDO) { _droidzebra_undo_turn(&side_to_move); // adjust for increment at the beginning of the game loop if (side_to_move == BLACKSQ) score_sheet_row--; continue; } else if (evt.type == UI_EVENT_REDO) { _droidzebra_redo_turn(&side_to_move); // adjust for increment at the beginning of the game loop if (side_to_move == BLACKSQ) score_sheet_row--; continue; } else if (evt.type == UI_EVENT_SETTINGS_CHANGE) { _droidzebra_on_settings_change(); // repeat move on settings change if (side_to_move == BLACKSQ) score_sheet_row--; // adjust for increment at the beginning of the game loop continue; } else { fatal_error("Unsupported UI event: %d", evt.type); } } assert(curr_move >= 0); } else { start_move(player_time[side_to_move], player_increment[side_to_move], disks_played + 4); determine_move_time(player_time[side_to_move], player_increment[side_to_move], disks_played + 4); timed_search = (skill[side_to_move] >= 60); toggle_experimental(FALSE); curr_move = compute_move(side_to_move, TRUE, player_time[side_to_move], player_increment[side_to_move], timed_search, use_book, skill[side_to_move], exact_skill[side_to_move], wld_skill[side_to_move], FALSE, &eval_info); if (side_to_move == BLACKSQ) set_evals(produce_compact_eval(eval_info), 0.0); else set_evals(0.0, produce_compact_eval(eval_info)); } } else { curr_move = provided_move[provided_move_index]; if (!valid_move(curr_move, side_to_move)) fatal_error("Invalid move %c%c in move sequence", TO_SQUARE(curr_move)); } move_stop = get_real_timer(); if (player_time[side_to_move] != INFINIT_TIME) player_time[side_to_move] -= (move_stop - move_start); store_move(disks_played, curr_move); (void) make_move(side_to_move, curr_move, TRUE); if (side_to_move == BLACKSQ) black_moves[score_sheet_row] = curr_move; else { white_moves[score_sheet_row] = curr_move; } } else { // this is where we pass if (side_to_move == BLACKSQ) black_moves[score_sheet_row] = PASS; else white_moves[score_sheet_row] = PASS; if (!auto_make_forced_moves && skill[side_to_move] == 0) { droidzebra_msg_pass(); } } droidzebra_msg_move_end(side_to_move); side_to_move = OPP(side_to_move); provided_move_index++; } droidzebra_enable_messaging(TRUE); if (side_to_move == BLACKSQ) score_sheet_row++; set_move_list(black_moves, white_moves, score_sheet_row); set_times(floor(player_time[BLACKSQ]), floor(player_time[WHITESQ])); droidzebra_msg_opening_name(opening_name); display_board(stdout, board, side_to_move, TRUE, TRUE, TRUE); /* double node_val, eval_val; adjust_counter( &total_nodes ); node_val = counter_value( &total_nodes ); adjust_counter( &total_evaluations ); eval_val = counter_value( &total_evaluations ); printf( "\nBlack: %d White: %d\n", disc_count( BLACKSQ ), disc_count( WHITESQ ) ); printf( "Nodes searched: %-10.0f\n", node_val ); printf( "Positions evaluated: %-10.0f\n", eval_val ); printf( "Total time: %.1f s\n", total_time ); */ if (!force_exit) droidzebra_msg_game_over(); // loop here until we are told to exit so the user has a chance to undo while (!force_exit) { droidzebra_msg_get_user_input(side_to_move, &evt); if (evt.type == UI_EVENT_EXIT) { force_exit = 1; break; } else if (evt.type == UI_EVENT_UNDO) { _droidzebra_undo_turn(&side_to_move); // adjust for increment at the beginning of the game loop if (side_to_move == BLACKSQ) score_sheet_row--; goto AGAIN; } else if (evt.type == UI_EVENT_SETTINGS_CHANGE) { _droidzebra_on_settings_change(); } } DROIDZEBRA_JNI_CLEAN; }
int smart_rename (const char *from, const char *to, int preserve_dates) { bfd_boolean exists; struct stat s; int ret = 0; exists = lstat (to, &s) == 0; #if defined (_WIN32) && !defined (__CYGWIN32__) /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but fail instead. Also, chown is not present. */ if (exists) remove (to); ret = rename (from, to); if (ret != 0) { /* We have to clean up here. */ non_fatal (_("unable to rename '%s' reason: %s"), to, strerror (errno)); unlink (from); } #else /* Use rename only if TO is not a symbolic link and has only one hard link, and we have permission to write to it. */ if (! exists || (!S_ISLNK (s.st_mode) && S_ISREG (s.st_mode) && (s.st_mode & S_IWUSR) && s.st_nlink == 1) ) { ret = rename (from, to); if (ret == 0) { if (exists) { /* Try to preserve the permission bits of TO. Don't * restore special bits. */ chmod (to, s.st_mode & 0777); } } else { /* We have to clean up here. */ non_fatal (_("unable to rename '%s' reason: %s"), to, strerror (errno)); unlink (from); } } else { ret = simple_copy (from, to); if (ret != 0) non_fatal (_("unable to copy file '%s' reason: %s"), to, strerror (errno)); if (preserve_dates) set_times (to, &s); unlink (from); } #endif /* _WIN32 && !__CYGWIN32__ */ return ret; }