NamedScript void UpdateShopAutoList() { ArrayCreate(&Player.AutoSellList, "Auto-Sell", 128, sizeof(ItemInfoPtr)); ArrayCreate(&Player.AutoStoreList, "Auto-Store", 128, sizeof(ItemInfoPtr)); for (int i = 0; i < ItemCategories; i++) { for (int j = 0; j < ItemMax[i]; j++) { if (Player.AutoSellList.Position == Player.AutoSellList.Size) ArrayResize(&Player.AutoSellList); if (Player.AutoStoreList.Position == Player.AutoStoreList.Size) ArrayResize(&Player.AutoStoreList); if (Player.ItemAutoMode[i][j] == AT_SELL) { ItemInfoPtr Item = &ItemData[i][j]; LogMessage(StrParam("Sell List Position: %i Sell List Size: %i", Player.AutoSellList.Position, Player.AutoSellList.Size), LOG_DEBUG); LogMessage(StrParam("Adding %S to auto-sell @ %p", ItemData[i][j].Name, Item), LOG_DEBUG); ((ItemInfoPtr *)Player.AutoSellList.Data)[Player.AutoSellList.Position++] = Item; } else if (Player.ItemAutoMode[i][j] == AT_STORE) { ItemInfoPtr Item = &ItemData[i][j]; LogMessage(StrParam("Store List Position: %i Store List Size: %i", Player.AutoStoreList.Position, Player.AutoStoreList.Size), LOG_DEBUG); LogMessage(StrParam("Adding %S to auto-store @ %p", ItemData[i][j].Name, Item), LOG_DEBUG); ((ItemInfoPtr *)Player.AutoStoreList.Data)[Player.AutoStoreList.Position++] = Item; } // LogMessage(StrParam("Completed Item #%i, %S", j, ItemData[i][j].Name), LOG_DEBUG); } } LogMessage("Completed AutoUpdateShopList", LOG_DEBUG); }
PetscErrorCode FluidFieldCreate(MPI_Comm comm, FluidField *fluid) { FluidField f; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscNew(struct _FluidField, &f); CHKERRQ(ierr); // Default values f->comm = comm; f->mu = 1e-3; // pN s / um^2 ierr = PetscOptionsGetReal(0,"-fluid_viscosity",&f->mu,0); CHKERRQ(ierr); int nmax = 3; f->lens.x = 7; f->lens.y = 7; f->lens.z = 0; ierr = PetscOptionsGetRealArray(0,"-fluid_lens", &f->lens.x, &nmax, 0); CHKERRQ(ierr); f->is3D = (nmax == 3); PetscReal dx = 1; ierr = PetscOptionsGetReal(0,"-fluid_dx",&dx,0); CHKERRQ(ierr); f->dh.x = dx; f->dh.y = dx; f->dh.z = dx; nmax = 3; f->dims.x = f->lens.x / f->dh.x; f->dims.y = f->lens.y / f->dh.y; f->dims.z = f->lens.z / f->dh.z; ierr = PetscOptionsGetIntArray(0,"-fluid_dims", &f->dims.x, &nmax, 0); CHKERRQ(ierr); if( !f->is3D ) { f->lens.z = 0; f->dims.z = 0; f->dh.z = 0; } // Create BC index set ierr = ArrayCreate("dirichletBC",sizeof(MatStencil),&f->dirichletBC); CHKERRQ(ierr); ierr = FluidFieldRegisterEvents(); CHKERRQ(ierr); *fluid = f; PetscFunctionReturn(0); }
GDB *g_open_database_(char *fns[], GCardinal Nfns, int read_only) /* * Open a database with a given file name */ { GDB *gdb; GCardinal i; /* check arguments */ if (fns==NULL) { (void) gerr_set(GERR_INVALID_ARGUMENTS); return NULL; } if (NULL == (gdb = g_new_gdb())) return NULL; /* * initialise data structs for clients */ gdb->Nclient = G_MAX_CLIENTS; if ( (gdb->client = ArrayCreate(sizeof(Client),gdb->Nclient)) == NULL ) { g_free_gdb(gdb); (void)gerr_set(GERR_OUT_OF_MEMORY); return NULL; } (void)ArrayRef(gdb->client,gdb->Nclient-1); for (i=0;i<gdb->Nclient;i++) arr(Client,gdb->client,i).id = -1; /* * Open the file (now only 1 file allowed, we ignore the rest) */ gdb->gfile = g_open_file(fns[0], read_only); if (NULL == gdb->gfile) { g_free_gdb(gdb); /* g_open_file sets gerrnum */ return NULL; } /* * allocate views - assume using Gap4, which locks all records. * FIXME: Changed to have max 1000 views at startup. It's reallocated * as we go anyway. */ gdb->Nview = 1000 < gdb->gfile->header.num_records ? 1000 : gdb->gfile->header.num_records; if ( (gdb->view = ArrayCreate(sizeof(View),gdb->Nview)) == NULL ) { g_free_gdb(gdb); (void)gerr_set(GERR_OUT_OF_MEMORY); return NULL; } (void)ArrayRef(gdb->view,gdb->Nview-1); /* initialise views */ for(i=0;i<gdb->Nview;i++) { arr(View,gdb->view,i).next = (i-1); arr(View,gdb->view,i).flags = G_VIEW_NEW; } gdb->free_view = gdb->Nview-1; return gdb; }
int shuffle_contigs_io(GapIO *io, int ncontigs, contig_list_t *contigs, int band, int flush) { int i; //, start; Array indels; set_malign_lookup(5); /* set_alignment_matrix("/tmp/nuc_matrix", "ACGTURYMWSKDHVB-*"); */ indels = ArrayCreate(sizeof(con_indel_t), 0); for (i = 0; i < ncontigs; i++) { tg_rec cnum = contigs[i].contig; int64_t old_score, new_score, tot_score, orig_score; //for (start = 0; start < 1000000; start += 1000) { // MALIGN *malign = build_malign(io, cnum, start, start + 1000); MALIGN *malign; int c_start, c_shift; vmessage("Shuffling pads for contig %s\n", get_contig_name(io, cnum)); /* * The shuffle pads code (malign) comes from gap4 and has lots of * assumptions that the contig goes from base 1 to base N. * Fixing these assumptions is a lot of work, so for now we will take * the cheat route of moving the contig to ensure the assumption * is valid. */ if (-1 == consensus_valid_range(io, cnum, &c_start, NULL)) { verror(ERR_WARN, "shuffle_contigs_io", "Failure in consensus_valid_range()"); return -1; } //printf("Contig starts at base %d\n", c_start); c_shift = 1-c_start; if (c_shift != 0) { if (move_contig(io, cnum, c_shift) != 0) return -1; } //printf("Shuffle #%"PRIrec" from %d..%d, shift %d\n", // contigs[i].contig, contigs[i].start, contigs[i].end, c_shift); malign = build_malign(io, cnum, contigs[i].start + c_shift, contigs[i].end + c_shift); resort_contigl(malign); malign_add_region(malign, contigs[i].start + c_shift, contigs[i].end + c_shift); ArrayMax(indels) = 0; orig_score = new_score = malign_diffs(malign, &tot_score); vmessage("Initial score %.2f%% mismatches (%"PRId64" mismatches)\n", (100.0 * orig_score)/tot_score, orig_score/128); if (flush) UpdateTextOutput(); //print_malign(malign); do { old_score = new_score; malign = realign_seqs(cnum, malign, band, indels); //print_malign(malign); new_score = malign_diffs(malign, &tot_score); vmessage(" Consensus difference score: %"PRId64"\n", new_score); if (flush) UpdateTextOutput(); } while (new_score < old_score); if (new_score < orig_score) { //print_malign(malign); update_io(io, cnum, malign, indels); /* * It's possible the contig ends could move if a sequence that * was previously the end of a contig has been moved such that * it's no longer the contig end. This can lead to tags off the * end of the contig, so trim them (reusing break_contig * code). */ contig_visible_start(io, cnum, CITER_CSTART); contig_visible_end(io, cnum, CITER_CEND); } else { vmessage("Could not reduce number of consensus differences.\n"); } /* Remove pad columns */ //printf("New score=%d, orig_score=%d\n", new_score, orig_score); if (new_score < orig_score) { contigs[i].start += c_shift; contigs[i].end += c_shift; remove_pad_columns(io, 1, &contigs[i], 100, 1); //contig_t *c; //c = cache_search(io, GT_Contig, cnum); //cache_incr(io, c); //remove_pads(io, malign, c, contigs[i].start, contigs[i].end); //cache_decr(io, c); } destroy_malign(malign, 1); vmessage("Final score %.2f%% mismatches\n", (100.0 * new_score)/tot_score); /* * Sequences like * AGCT**GATGC * TGGATCGA * can end up causing holes. We break the contig in this case to * avoid minor database inconsistencies. */ // remove_contig_holes(io, cnum); /* reassign_confidence_values(io, cnum); */ //} /* Shift contig back */ if (c_shift != 0) { if (move_contig(io, cnum, -c_shift) != 0) return -1; } if (flush) cache_flush(io); } ArrayDestroy(indels); return 0; }
/* * A recursive break contig function. * bin_num The current bin being moved or split. * pos The contig break point. * offset The absolute positional offset of this bin in original contig * pleft The parent bin/contig record num in the left new contig * pright The parent bin/contig record num in the right new contig * child_no 0 or 1 - whether this bin is the left/right child of its parent */ static int break_contig_recurse(GapIO *io, HacheTable *h, contig_t *cl, contig_t *cr, tg_rec bin_num, int pos, int offset, int level, tg_rec pleft, tg_rec pright, int child_no, int complement) { int i, j, f_a, f_b; tg_rec rbin; bin_index_t *bin = get_bin(io, bin_num), *bin_dup ; //int bin_min, bin_max; int nseqs; tg_rec opright; /* old pright, needed if we revert back */ cache_incr(io, bin); if (bin->flags & BIN_COMPLEMENTED) { complement ^= 1; } if (complement) { f_a = -1; f_b = offset + bin->size-1; } else { f_a = +1; f_b = offset; } printf("%*sBreak offset %d pos %d => test bin %"PRIrec": %d..%d\n", level*4, "", offset, pos, bin->rec, NMIN(bin->start_used, bin->end_used), NMAX(bin->start_used, bin->end_used)); bin = cache_rw(io, bin); nseqs = bin->nseqs; bin->nseqs = 0; /* Invalidate any cached data */ bin_invalidate_track(io, bin, TRACK_ALL); if (bin->flags & BIN_CONS_VALID) { bin->flags |= BIN_BIN_UPDATED; bin->flags &= ~BIN_CONS_VALID; } //bin_min = bin->rng ? NMIN(bin->start_used, bin->end_used) : offset; //bin_max = bin->rng ? NMAX(bin->start_used, bin->end_used) : offset; /* * Add to right parent if this bin is to the right of pos, * or if the used portion is to the right and we have no left child. * * FIXME: Not a valid assumption! * The used portion of a bin is not a placeholder for the used portion * of all the the children beneath it. Therefore if the used portion of * this bin is > pos (and we have no left child) it still doesn't mean * that the absolute positions of the used portion of the right child * won't be < pos. */ if (offset >= pos /*|| (bin_min >= pos && !bin->child[0])*/) { printf("%*sADD_TO_RIGHT pl=%"PRIrec" pr=%"PRIrec"\n", level*4, "", pleft, pright); if (0 != break_contig_move_bin(io, bin, cl, pleft, cr, pright, child_no)) return -1; bin_incr_nseq(io, bin, nseqs); cache_decr(io, bin); return 0; } /* * Add to left parent if this bin is entirely to the left of pos, * or if the used portion is to the left and we have no right child. */ if (offset + bin->size < pos /*|| (bin_max < pos && !bin->child[1])*/) { printf("%*sADD_TO_LEFT\n", level*4, ""); //if (0 != break_contig_move_bin(io, bin, cr, pright, cl, pleft, child_no)) //return -1; bin_incr_nseq(io, bin, nseqs); cache_decr(io, bin); return 0; } /* * Nominally the bin overlaps both left and right and so needs duplicating. * There are cases though at the roots of our trees where duplicating is * unnecessary as it leads to empty bins at the root. In this case * we skip creating a duplicate for the right, or alternatively steal * the left root bin and use that instead. * * Similarly the range_t array will either be left where it is, moved to * the right contig, or split in half (creating a new one for the right). * * FIXED: always need this. Eg: * * |-------------empty--------------| * |----------------|---------------| * |--------|-------|--------|------| * ^ * | * break here * * In this case we need to duplicate the parent as it overlaps the left * bin, which may (or may not) have data that needs to end up in the right * hand contig. Just duplicate for now and free later on if needed. */ if (1 /* always! */ || pright != cr->rec || (bin->rng && NMAX(bin->start_used, bin->end_used) >= pos)) { //printf("NMAX=%d >= %d\n", NMAX(bin->start_used, bin->end_used), pos); rbin = 0; /* Possibly steal left contig's bin */ if (pleft == cl->rec && NMIN(bin->start_used, bin->end_used) >= pos) { #if 0 /* Currently this doesn't always work */ if (bin->child[1]) { bin_index_t *ch = get_bin(io, bin->child[1]); if (NMIN(ch->pos, ch->pos + ch->size-1) >= pos) { rbin = cl->bin; cl->bin = bin->child[0]; } } #else pleft = bin->rec; #endif } else { pleft = bin->rec; } /* Create new bin, or use root of contig if it's unused so far */ if (!rbin && pright == cr->rec) { rbin = cr->bin; } /* Otherwise we genuingly need a duplicate */ if (!rbin) rbin = bin_new(io, 0, 0, 0, GT_Bin); /* Initialise with duplicate values from left bin */ bin_dup = get_bin(io, rbin); bin_dup = cache_rw(io, bin_dup); bin_dup->size = bin->size; bin_dup->pos = bin->pos; bin_dup->parent = pright; bin_dup->parent_type = (pright == cr->rec ? GT_Contig : GT_Bin); bin_dup->flags = bin->flags | BIN_BIN_UPDATED; bin_dup->start_used = bin->start_used; bin_dup->end_used = bin->end_used; /* * Shift bin to offset if it's the contig root. * It'll be shifted back by the correct amount later. */ if (pright == cr->rec) { printf("moving root bin to offset=%d comp=%d\n", offset, complement); bin_dup->pos = offset; } printf("%*sCreated dup for right, rec %"PRIrec"\n", level*4,"", bin_dup->rec); break_contig_move_bin(io, bin_dup, cl, 0, cr, pright, child_no); opright = pright; pright = bin_dup->rec; } else { bin_dup = NULL; pleft = bin->rec; } if (!bin->rng) { /* Empty bin */ printf("%*sEMPTY range\n", level*4, ""); bin->start_used = bin->end_used = 0; bin->flags |= BIN_BIN_UPDATED; if (bin_dup) { bin_dup->start_used = bin_dup->end_used = 0; bin_dup->flags |= BIN_BIN_UPDATED; } } else if (NMIN(bin->start_used, bin->end_used) >= pos) { /* Move range to right contig */ printf("%*sDUP %"PRIrec", MOVE Array to right\n", level*4, "", bin_dup->rec); bin_dup->rng = bin->rng; bin_dup->rng_rec = bin->rng_rec; bin_dup->rng_free = bin->rng_free; if (bin_dup->rng_rec) bin_dup->flags |= BIN_RANGE_UPDATED; if (bin->rec != bin_dup->rec) { bin->rng = NULL; bin->rng_rec = 0; bin->rng_free = -1; bin->flags |= BIN_BIN_UPDATED; } bin->start_used = bin->end_used = 0; break_contig_reparent_seqs(io, bin_dup); if (bin_dup->rng) { int n = ArrayMax(bin_dup->rng); for (i = j = 0; i < n; i++) { range_t *r = arrp(range_t, bin_dup->rng, i), *r2; if (r->flags & GRANGE_FLAG_UNUSED) continue; if ((r->flags & GRANGE_FLAG_ISMASK) != GRANGE_FLAG_ISANNO) { HacheData hd; hd.i = 1; HacheTableAdd(h, (char *)&r->rec, sizeof(r->rec), hd,NULL); j++; } } bin_incr_nseq(io, bin_dup, j); } } else if (NMAX(bin->start_used, bin->end_used) < pos) { /* Range array already in left contig, so do nothing */ printf("%*sMOVE Array to left\n", level*4, ""); if (bin_dup) bin_dup->start_used = bin_dup->end_used = 0; if (bin->rng) { int n = ArrayMax(bin->rng); for (i = j = 0; i < n; i++) { range_t *r = arrp(range_t, bin->rng, i); if (r->flags & GRANGE_FLAG_UNUSED) continue; if ((r->flags & GRANGE_FLAG_ISMASK) != GRANGE_FLAG_ISANNO) { HacheData hd; hd.i = 0; HacheTableAdd(h, (char *)&r->rec, sizeof(r->rec), hd,NULL); j++; } } bin_incr_nseq(io, bin, j); } } else { /* Range array covers pos, so split in two */ int n, nl = 0, nr = 0; int lmin = bin->size, lmax = 0, rmin = bin->size, rmax = 0; printf("%*sDUP %"PRIrec", SPLIT array\n", level*4, "", bin_dup->rec); bin->flags |= BIN_RANGE_UPDATED; bin_dup->flags |= BIN_RANGE_UPDATED; bin_dup->rng = ArrayCreate(sizeof(range_t), 0); bin_dup->rng_free = -1; /* Pass 1 - hash sequences */ n = ArrayMax(bin->rng); for (i = 0; i < n; i++) { range_t *r = arrp(range_t, bin->rng, i); int cstart; /* clipped sequence positions */ seq_t *s; if (r->flags & GRANGE_FLAG_UNUSED) continue; if ((r->flags & GRANGE_FLAG_ISMASK) == GRANGE_FLAG_ISANNO) continue; s = (seq_t *)cache_search(io, GT_Seq, r->rec); if ((s->len < 0) ^ complement) { cstart = NMAX(r->start, r->end) - (s->right-1); } else { cstart = NMIN(r->start, r->end) + s->left-1; } if (cstart >= pos) { HacheData hd; hd.i = 1; HacheTableAdd(h, (char *)&r->rec, sizeof(r->rec), hd, NULL); } else { HacheData hd; hd.i = 0; HacheTableAdd(h, (char *)&r->rec, sizeof(r->rec), hd, NULL); } } /* Pass 2 - do the moving of anno/seqs */ n = ArrayMax(bin->rng); for (i = j = 0; i < n; i++) { range_t *r = arrp(range_t, bin->rng, i), *r2; int cstart; /* clipped sequence positions */ if (r->flags & GRANGE_FLAG_UNUSED) continue; if ((r->flags & GRANGE_FLAG_ISMASK) == GRANGE_FLAG_ISANNO) { cstart = NMAX(r->start, r->end); } else { seq_t *s = (seq_t *)cache_search(io, GT_Seq, r->rec); if ((s->len < 0) ^ complement) { cstart = NMAX(r->start, r->end) - (s->right-1); } else { cstart = NMIN(r->start, r->end) + s->left-1; } } if (cstart >= pos && ((r->flags & GRANGE_FLAG_ISMASK) == GRANGE_FLAG_ISANNO)) { anno_ele_t *a = (anno_ele_t *)cache_search(io, GT_AnnoEle, r->rec); /* If it's an annotation on a sequence < pos then we * still don't move. * * FIXME: we have no guarantee that the sequence being * annotated is in the same bin as this annotation, as * they may be different sizes and end up in different * bins. (Should we enforce anno always in same bin as seq? * If so, consensus annos fit anywhere?) */ if (a->obj_type == GT_Seq) { HacheItem *hi = HacheTableSearch(h, (char *)&r->pair_rec, sizeof(r->pair_rec)); if (hi) { if (hi->data.i == 0) cstart = pos-1; } else { puts("FIXME: annotation for seq in unknown place - " "work out correct location and move if needed."); } } } if (cstart >= pos) { r2 = (range_t *)ArrayRef(bin_dup->rng, ArrayMax(bin_dup->rng)); *r2 = *r; if (rmin > r->start) rmin = r->start; if (rmin > r->end) rmin = r->end; if (rmax < r->start) rmax = r->start; if (rmax < r->end) rmax = r->end; if ((r->flags & GRANGE_FLAG_ISMASK) == GRANGE_FLAG_ISSEQ) nr++; } else { if (lmin > r->start) lmin = r->start; if (lmin > r->end) lmin = r->end; if (lmax < r->start) lmax = r->start; if (lmax < r->end) lmax = r->end; if (j != i) { r2 = arrp(range_t, bin->rng, j); *r2 = *r; } j++; if ((r->flags & GRANGE_FLAG_ISMASK) == GRANGE_FLAG_ISSEQ) nl++; } } bin_incr_nseq(io, bin, nl); bin_incr_nseq(io, bin_dup, nr); ArrayMax(bin->rng) = j; #if 0 /* * Right now this causes problems, but I'm not sure why. Try again * after we've fixed the bin->nseqs issues and other deallocation * woes. */ if (ArrayMax(bin_dup->rng) == 0 && bin_dup->parent_type == GT_Bin) { /* We didn't need it afterall! Odd. */ bin_index_t *pb; printf("Purging bin %d that we didn't need afterall\n", bin_dup->rec); cache_rec_deallocate(io, GT_Bin, bin_dup->rec); pb = cache_search(io, GT_Bin, bin_dup->parent); if (pb->child[0] == bin_dup->rec) pb->child[0] = 0; if (pb->child[1] == bin_dup->rec) pb->child[1] = 0; bin_dup = NULL; pright = opright; } #endif if (bin_dup) break_contig_reparent_seqs(io, bin_dup); if (lmin < lmax) { bin->start_used = lmin; bin->end_used = lmax; } else { /* No data left in bin */ bin->start_used = 0; bin->end_used = 0; } printf("%*sLeft=>%d..%d right=>%d..%d\n", level*4, "", lmin, lmax, rmin, rmax); if (bin_dup) { if (rmin < rmax) { bin_dup->start_used = rmin; bin_dup->end_used = rmax; } else { /* No data moved in bin */ bin_dup->start_used = 0; bin_dup->end_used = 0; } } } /* Recurse */ for (i = 0; i < 2; i++) { bin_index_t *ch; if (!bin->child[i]) continue; ch = get_bin(io, bin->child[i]); if (0 != break_contig_recurse(io, h, cl, cr, bin->child[i], pos, NMIN(ch->pos, ch->pos + ch->size-1), level+1, pleft, pright, i, complement)) return -1; } cache_decr(io, bin); // if (bin_dup) // cache_decr(io, bin_dup); return 0; }
/* * Dumps a G database in an ASCII readable form. Modelled around the start * of the g_open_file() routine. */ void g_dump_file(char *fn) { GFile *gfile = NULL; char fnaux[1024]; AuxIndex aux_ind; int i; #define ABORT(E)\ {\ g_free_gfile(gfile); \ gfile = NULL; \ (void)gerr_set(E); \ perror("ABORT"); \ return; \ } /* check file name isn't too long */ if (strlen(fn) + strlen(G_AUX_SUFFIX) >= sizeof(fnaux)) ABORT(GERR_NAME_TOO_LONG); strcpy(fnaux, fn); strcat(fnaux, G_AUX_SUFFIX); /* allocate new data structure - GFile */ gfile = g_new_gfile(); if (gfile == NULL) ABORT(GERR_OUT_OF_MEMORY); /* set file name */ if ((gfile->fname = (char *)xmalloc(strlen(fn)+1)) != NULL) strcpy(gfile->fname, fn); /* open file and its aux */ /* LOW LEVEL IO HERE */ if ((gfile->fd = open(fn, O_RDONLY)) == -1) ABORT(GERR_OPENING_FILE); /* LOW LEVEL IO HERE */ if ((gfile->fdaux = open(fnaux, O_RDONLY)) == -1) ABORT(GERR_OPENING_FILE); /* LOW LEVEL IO HERE */ if (-1 == lseek(gfile->fdaux, 0, 0)) ABORT(GERR_SEEK_ERROR); if (g_read_aux_header(gfile->fdaux, &gfile->header)) ABORT(GERR_READ_ERROR); printf("** \n"); printf("** Opening file %s\n",fn); printf("** file_size = %"PRIGImage"\n", gfile->header.file_size); printf("** block_size = %"PRIGCardinal"\n", gfile->header.block_size); printf("** num_records = %"PRIGCardinal"\n", gfile->header.num_records); printf("** max_records = %"PRIGCardinal"\n", gfile->header.max_records); printf("** last_time = %"PRIGCardinal"\n", gfile->header.last_time); printf("** flags = %"PRIGHFlags"\n", gfile->header.flags); printf("** \n"); /* allocate index */ gfile->Nidx = gfile->header.num_records; if ((gfile->idx = ArrayCreate(sizeof(Index), gfile->Nidx)) == NULL ) ABORT(GERR_OUT_OF_MEMORY); (void) ArrayRef(gfile->idx, gfile->Nidx-1); for(i = 0; i < gfile->Nidx; i++) arr(Index, gfile->idx, i).flags = G_INDEX_NEW; /* read aux index and initialise */ /* LOW LEVEL IO HERE */ if (-1 == lseek(gfile->fdaux, sizeof(AuxHeader), 0)) ABORT(GERR_SEEK_ERROR); /* force Array.max field to be updated */ (void)ArrayRef(gfile->idx, gfile->header.num_records-1); printf("global_time %08x\n", gfile->header.last_time); for (i = 0; i < gfile->header.num_records; i++) { char buf[MAX_BUF]; int toggle, len, len_r; /* Load index for this record */ if (g_read_aux_index(gfile->fdaux, &aux_ind)) ABORT(GERR_READ_ERROR); /* Compute toggle */ toggle = g_toggle_state(gfile->header.last_time, &aux_ind); /* LOW LEVEL IO HERE */ if (-1 == lseek(gfile->fd, aux_ind.image[toggle], 0)) ABORT(GERR_SEEK_ERROR); len = MIN(aux_ind.used[toggle], MAX_BUF); /* LOW LEVEL IO HERE */ if (-1 == (len_r = read(gfile->fd, buf, len))) ABORT(GERR_READ_ERROR); if (len_r != len) { fprintf(stderr, "WARNING: Read too short. Requested %d, got %d\n", len, len_r); } printf("record %05d pos %020"PRIGImage" len %08d : %08x", i, aux_ind.image[toggle], aux_ind.used[toggle], (((((buf[0] << 8) + buf[1]) << 8) + buf[2]) << 8) + buf[3]); if (len > 4) printf(" %c%c%c%c%c%c%c%c\n", isprint(buf[4])?buf[4]:'.', isprint(buf[5])?buf[5]:'.', isprint(buf[6])?buf[6]:'.', isprint(buf[7])?buf[7]:'.', isprint(buf[8])?buf[8]:'.', isprint(buf[9])?buf[9]:'.', isprint(buf[10])?buf[10]:'.', isprint(buf[11])?buf[11]:'.'); else putchar('\n'); } #undef ABORT g_free_gfile(gfile); return; }