int Traj_GmxTrX::ReadTrxHeader() { int version = 0; // Read past magic byte if (file_.Read(&version, 4) != 4) return 1; // Read version for TRR if (format_ != TRJ) read_int( version ); //mprintf("DEBUG: TRX Version= %i\n", version); // Read in title string SetTitle( read_string() ); // Read in size data if ( read_int( ir_size_ ) ) return 1; if ( read_int( e_size_ ) ) return 1; if ( read_int( box_size_ ) ) return 1; if ( read_int( vir_size_ ) ) return 1; if ( read_int( pres_size_ ) ) return 1; if ( read_int( top_size_ ) ) return 1; if ( read_int( sym_size_ ) ) return 1; if ( read_int( x_size_ ) ) return 1; if ( read_int( v_size_ ) ) return 1; if ( read_int( f_size_ ) ) return 1; if ( read_int( natoms_ ) ) return 1; if (natoms_ < 1) { mprinterr("Error: No atoms detected in TRX trajectory.\n"); return 1; } natom3_ = natoms_ * 3; if ( read_int( step_ ) ) return 1; if ( read_int( nre_ ) ) return 1; // Determine precision if (x_size_ > 0) precision_ = x_size_ / natom3_; else if (v_size_ > 0) precision_ = v_size_ / natom3_; else if (f_size_ > 0) precision_ = f_size_ / natom3_; else { mprinterr("Error: X/V/F sizes are 0 in TRX trajectory.\n"); return 1; } if ( precision_ != sizeof(float) && precision_ != sizeof(double) ) { mprinterr("Error: TRX precision %i not recognized.\n", precision_); return 1; } // Read timestep and lambda if ( read_real( dt_ ) ) return 1; if ( read_real( lambda_ ) ) return 1; return 0; }
Chunk *read_chunk(FILE *fp) { Chunk *chunk = malloc(sizeof *chunk); if (!chunk) { fatal("Out of memory."); } chunk->numtemps = read_int(fp); chunk->numconstants = read_int(fp); chunk->numinstructions = read_int(fp); chunk->numchildren = read_int(fp); chunk->numlocals = read_int(fp); chunk->numupvars = read_int(fp); chunk->numparams = read_int(fp); Constant **constants = malloc(chunk->numconstants * sizeof **constants); int *instructions = malloc(chunk->numinstructions * sizeof *instructions); Chunk **children = malloc(chunk->numchildren * sizeof **children); if (!constants || !instructions || !children) { fatal("Out of memory."); } chunk->constants = constants; chunk->instructions = instructions; chunk->children = children; int i; for (i = 0; i < chunk->numinstructions; i++) { chunk->instructions[i] = read_int(fp); } for (i = 0; i < chunk->numconstants; i++) { int type = read_int(fp); Constant *c = malloc(sizeof *c); if (!c) { fatal("Out of memory."); } c->type = type; switch (type) { case CONST_INT: case CONST_BOOL: c->value.i = read_int(fp); break; case CONST_REAL: c->value.d = read_real(fp); break; case CONST_NULL: break; case CONST_STRING: { c->value.s = read_string(fp); } break; } chunk->constants[i] = c; } for (i = 0; i < chunk->numchildren; i++) { chunk->children[i] = read_chunk(fp); } return chunk; }
void input_schema(Pschema s, char *attr_name, int spaces, int pretty, FILE *in_file){ // reads a schema and puts it on the top op tstack if(attr_name!=NULL && pretty){ print_spaces(spaces, stdout); fprintf(stdout, "Input record attribute \"%s\"\n",attr_name); } if(pretty){ print_spaces(spaces, stdout); } if(s->type == TY_RECORD || s->type == TY_ARRAY || s->type == TY_ATTR){ int size = get_schema_size(s); int nfields = 0; switch(s->type){ case TY_RECORD:{ if(pretty){ fprintf(stdout,"Input for a record\n"); } Pschema temp = s->child; while(temp){ input_schema(temp->child, temp->id, spaces+1, pretty, in_file); nfields++; temp = temp->brother; } break; } case TY_ARRAY:{ int i; if(pretty){ fprintf(stdout, "Input for an array\n"); } nfields = s->size; for(i=0; i<nfields; i++){ input_schema(s->child, NULL, spaces+1, pretty, in_file); } break; } default: print_schema(s,0); machine_error("TY_ATTR cannot be used in input_schema()."); break; } exec_cat(nfields,size); } else{ switch(s->type){ case TY_INT: { int in = read_int(stdout, in_file, "Insert an integer: ", pretty); push_int(in); break; } case TY_CHAR: { char in = read_char(stdout, in_file, "Insert a char: ", pretty); push_char(in); break; } case TY_REAL: { float in = read_real(stdout, in_file, "Insert a number of type real: ", pretty); push_real(in); break; } case TY_STRING: { char *in = read_string(stdout, in_file, "Insert a string: ", pretty); char *strig_to_store = stringtable_store(in, stringtable); freemem(in, strlen(in) + 1); push_string(strig_to_store); break; } case TY_BOOL: { char in = read_char(stdout, in_file, "Insert a boolean (0 or 1): ", pretty); push_bool(in == '1'); break; } default: {machine_error("Unknown type of schema in input_schema()."); break;} } } }
void read_basis (const char *filename, wfa_t *wfa) /* * Read WFA initial basis 'filename' and fill 'wfa' struct. * * No return value. * * Side effects: * wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states * wfa->domain_type wfa->wfainfo->basis_name, are filled with the * values of the WFA basis. */ { FILE *input; /* ASCII WFA initial basis file */ assert (filename && wfa); if (!wfa->wfainfo->basis_name || !streq (wfa->wfainfo->basis_name, filename)) { if (wfa->wfainfo->basis_name) Free (wfa->wfainfo->basis_name); wfa->wfainfo->basis_name = strdup (filename); } if (get_linked_basis (filename, wfa)) return; /* basis is linked with excecutable */ /* * Check whether 'wfa_name' is a regular ASCII WFA initial basis file */ { char magic [MAXSTRLEN]; /* WFA magic number */ if (!(input = open_file (filename, "FIASCO_DATA", READ_ACCESS))) file_error(filename); if (fscanf (input, MAXSTRLEN_SCANF, magic) != 1) error ("Format error: ASCII FIASCO initial basis file %s", filename); else if (strneq (FIASCO_BASIS_MAGIC, magic)) error ("Input file %s is not an ASCII FIASCO initial basis!", filename); } /* * WFA ASCII format: * * Note: State 0 is assumed to be the constant function f(x, y) = 128. * Don't define any transitions of state 0 in an initial basis. * * Header: * type |description * ----------------+----------- * string |MAGIC Number "Wfa" * int |Number of basis states 'N' * bool_t-array[N] |use vector in linear combinations, * |0: don't use vector (auxilliary state) * |1: use vector in linear combinations * float-array[N] |final distribution of every state * * Transitions: * * <state 1> current state * <label> <into> <weight> transition 1 of current state * <label> <into> <weight> transition 2 of current state * ... * <-1> last transition marker * <state 2> * ... * <-1> last transition marker * <state N> * ... * * <-1> last transition marker * <-1> last state marker */ { unsigned state; if (fscanf (input ,"%u", &wfa->basis_states) != 1) error ("Format error: ASCII FIASCO initial basis file %s", filename); /* * State 0 is assumed to be the constant function f(x, y) = 128. */ wfa->domain_type [0] = USE_DOMAIN_MASK; wfa->final_distribution [0] = 128; wfa->states = wfa->basis_states; wfa->basis_states++; append_edge (0, 0, 1.0, 0, wfa); append_edge (0, 0, 1.0, 1, wfa); for (state = 1; state < wfa->basis_states; state++) wfa->domain_type [state] = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK; for (state = 1; state < wfa->basis_states; state++) wfa->final_distribution[state] = read_real (input); /* * Read transitions */ for (state = 1; state < wfa->basis_states; state++) { unsigned domain; int label; real_t weight; if (read_int (input) != (int) state) error ("Format error: ASCII FIASCO initial basis file %s", filename); while((label = read_int (input)) != -1) { domain = read_int (input); weight = read_real (input); append_edge (state, domain, weight, label, wfa); } } } fclose (input); }