static inline uns find_match(uns record_id, struct hash_record *hash_rec, const byte *string, const byte *string_end, byte **best_ptr, uns head) /* hash_tab[hash] == record_id points to the head of the double-linked * link-list of strings with the same hash. The records are statically * stored in circular array hash_rec (with the 1st entry unused), and the * pointers are just 16-bit indices. The strings in every collision chain * are ordered by age. */ { uns count = CHAIN_MAX_TESTS; uns best_len = 0; while (record_id && count-- > 0) { byte *record_string = locate_string(string, record_id, head); byte *cmp = record_string; if (cmp[0] == string[0] && cmp[2] == string[2]) /* implies cmp[1] == string[1] */ { if (cmp[3] == string[3]) { cmp += 4; if (*cmp++ == string[4] && *cmp++ == string[5] && *cmp++ == string[6] && *cmp++ == string[7]) { const byte *str = string + 8; while (str <= string_end && *cmp++ == *str++); } } else cmp += 4; uns len = cmp - record_string - 1; /* cmp points 2 characters after the last match */ if (len > best_len) { best_len = len; *best_ptr = record_string; if (best_len >= CHAIN_GOOD_MATCH) /* optimization */ break; } } record_id = hash_rec[record_id].next; } return best_len; }
int read_atom_data(int *p_ichar, int *p_num_atoms, int at_end, int num_of_chars, int *p_next_mol, atom *p_atom, int *p_mol_number) { int is_end,idummy,place,itsanum,iloop,ndigi,sign; int idum[10], igroup; char *p_key; /* check for end of molecule or file */ p_key= "end"; is_end= locate_string( p_key, p_ichar, num_of_chars); if (is_end && !at_end ) { /* first end encountered for a while, just end of molecule */ (*p_next_mol)++; return 1; } else if (is_end && at_end ) { /* the end of the atom list */ return 2; } else { /* a normal atom data line */ /* copy over atom name */ copy_int( p_ichar, &idum[0], 0, 3); int_to_string(&idum[0], &(p_atom->label[0]), 4); /* get x,y,z co-ordinates */ place= 1; place= next_space (p_ichar, place, num_of_chars ); p_atom->x = get_doub(p_ichar, num_of_chars, &place, &itsanum); p_atom->y = get_doub(p_ichar, num_of_chars, &place, &itsanum); p_atom->z = get_doub(p_ichar, num_of_chars, &place, &itsanum); /* get group label */ place= next_none_space( p_ichar, place, num_of_chars ); if (place == -1 ) { printf("Read error whilst trying to get the group from car file line:"); put_string(stdout, p_ichar,200); return -1; } copy_int( p_ichar, &idum[0], place, place+3); int_to_string(&idum[0],&(p_atom->group[0]), 4); place= next_space (p_ichar, place, num_of_chars ); /******* Get the group number, which can contain a string!! ***********/ place++; if (place == -1 ) { printf("Read error whilst trying to get the group number from car file line:"); put_string(stdout, p_ichar,200); return -1; } copy_int( p_ichar, &idum[0], place, place+3); int_to_string(&idum[0],&(p_atom->group_no[0]), 4); place= next_space (p_ichar, place, num_of_chars ); /* get potential type */ place= next_none_space( p_ichar, place, num_of_chars ); if (place == -1 ) { printf("Read error whilst trying to get the potential type from car file line:"); put_string(stdout, p_ichar,200); return -1; } copy_int( p_ichar, &idum[0], place, place+2); int_to_string( &idum[0], &(p_atom->pot[0]), 2); place= next_space (p_ichar, place, num_of_chars ); /* get element type */ place= next_none_space( p_ichar, place, num_of_chars ); if (place == -1 ) { printf("Read error whilst trying to get the element type from car file line:"); put_string(stdout,p_ichar,200); return -1; } copy_int( p_ichar, &idum[0], place, place+1); int_to_string( &idum[0], &(p_atom->elem[0]), 2); if (p_atom->elem[1] == ' ') p_atom->elem[1] = '\0'; place= next_space (p_ichar, place, num_of_chars ); /* get partial charge */ p_atom->part_chge= get_doub(p_ichar, num_of_chars, &place, &itsanum); if (!itsanum) { printf("Failed to find partial charge on car file line: \n"); put_string(stdout, p_ichar,200); } /* sort out molecule number and increment atom counter */ *p_mol_number= *p_next_mol; (*p_num_atoms)++; return 0; } }