Merge release-4-5-patches into release-4-6
authorRoland Schulz <roland@utk.edu>
Fri, 18 Jan 2013 20:25:05 +0000 (15:25 -0500)
committerRoland Schulz <roland@utk.edu>
Fri, 18 Jan 2013 20:25:05 +0000 (15:25 -0500)
Conflicts:
src/gmxlib/confio.c (whitespace only)

286575f0cd68 commit is not needed and is ignored
by this merge.

Change-Id: I7c4aabd918384aadbf6108501023ca77e019d6c1

1  2 
src/gmxlib/confio.c

index 2c8c2d326f379b1f1eb1abe22cf16066481791f6,c612dee5ab5bcb97e3e0c8cc9176fb7205242d3a..ccb5bf64fb4fc1acf763e59f99337e0ff222d0b9
@@@ -1603,190 -1277,174 +1603,191 @@@ void write_sto_conf_mtop(const char *ou
  
  static int get_xyz_coordnum(const char *infile)
  {
 -  FILE *fp;
 -  int n;
 -  
 -  fp = gmx_fio_fopen(infile,"r");
 -  if (fscanf(fp,"%d",&n) != 1)
 -    gmx_fatal(FARGS,"Can not read number of atoms from %s",infile);
 -  gmx_fio_fclose(fp);
 -  
 -  return n;
 +    FILE *fp;
 +    int   n;
 +
 +    fp = gmx_fio_fopen(infile, "r");
 +    if (fscanf(fp, "%d", &n) != 1)
 +    {
 +        gmx_fatal(FARGS, "Can not read number of atoms from %s", infile);
 +    }
 +    gmx_fio_fclose(fp);
 +
 +    return n;
  }
  
 -static void read_xyz_conf(const char *infile,char *title,
 -                        t_atoms *atoms,rvec *x)
 +static void read_xyz_conf(const char *infile, char *title,
 +                          t_atoms *atoms, rvec *x)
  {
 -  FILE   *fp;
 -  int    i,n;
 -  double xx,yy,zz;
 -  t_symtab *tab;
 -  char atomnm[32],buf[STRLEN];
 -  
 -  snew(tab,1);
 -  fp = gmx_fio_fopen(infile,"r");
 -  fgets2(buf,STRLEN-1,fp);
 -  if (sscanf(buf,"%d",&n) != 1)
 -    gmx_fatal(FARGS,"Can not read number of atoms from %s",infile);
 -  fgets2(buf,STRLEN-1,fp);
 -  strcpy(title,buf);
 -  for(i=0; (i<n); i++) {
 -    fgets2(buf,STRLEN-1,fp);
 -    if (sscanf(buf,"%s%lf%lf%lf",atomnm,&xx,&yy,&zz) != 4)
 -      gmx_fatal(FARGS,"Can not read coordinates from %s",infile);
 -    atoms->atomname[i] = put_symtab(tab,atomnm);
 -    x[i][XX] = xx*0.1;
 -    x[i][YY] = yy*0.1;
 -    x[i][ZZ] = zz*0.1;
 -  }
 -  gmx_fio_fclose(fp);
 +    FILE     *fp;
 +    int       i, n;
 +    double    xx, yy, zz;
 +    t_symtab *tab;
 +    char      atomnm[32], buf[STRLEN];
 +
 +    snew(tab, 1);
 +    fp = gmx_fio_fopen(infile, "r");
 +    fgets2(buf, STRLEN-1, fp);
 +    if (sscanf(buf, "%d", &n) != 1)
 +    {
 +        gmx_fatal(FARGS, "Can not read number of atoms from %s", infile);
 +    }
 +    fgets2(buf, STRLEN-1, fp);
 +    strcpy(title, buf);
 +    for (i = 0; (i < n); i++)
 +    {
 +        fgets2(buf, STRLEN-1, fp);
 +        if (sscanf(buf, "%s%lf%lf%lf", atomnm, &xx, &yy, &zz) != 4)
 +        {
 +            gmx_fatal(FARGS, "Can not read coordinates from %s", infile);
 +        }
 +        atoms->atomname[i] = put_symtab(tab, atomnm);
 +        x[i][XX]           = xx*0.1;
 +        x[i][YY]           = yy*0.1;
 +        x[i][ZZ]           = zz*0.1;
 +    }
 +    gmx_fio_fclose(fp);
  }
  
 -void get_stx_coordnum(const char *infile,int *natoms)
 +void get_stx_coordnum(const char *infile, int *natoms)
  {
 -  FILE *in;
 -  int ftp,tpxver,tpxgen;
 -  t_trxframe fr;
 -  char g96_line[STRLEN+1];
 -
 -  ftp=fn2ftp(infile);
 -  range_check(ftp,0,efNR);
 -  switch (ftp) {
 -  case efGRO:
 -    get_coordnum(infile, natoms);
 -    break;
 -  case efG96:
 -    in=gmx_fio_fopen(infile,"r");
 -    fr.title = NULL;
 -    fr.natoms = -1;
 -    fr.atoms = NULL;
 -    fr.x = NULL;
 -    fr.v = NULL;
 -    fr.f = NULL;
 -    *natoms=read_g96_conf(in,infile,&fr,g96_line);
 -    gmx_fio_fclose(in);
 -    break;
 -  case efXYZ:
 -    *natoms = get_xyz_coordnum(infile);
 -    break;
 -  case efPDB:
 -  case efBRK:
 -  case efENT:
 -    in=gmx_fio_fopen(infile,"r");
 -    get_pdb_coordnum(in, natoms);
 -    gmx_fio_fclose(in);
 -    break;
 -  case efESP:
 -    *natoms = get_espresso_coordnum(infile);
 -    break;
 -  case efTPA:
 -  case efTPB:
 -  case efTPR: {
 -    t_tpxheader tpx;
 -    
 -    read_tpxheader(infile,&tpx,TRUE,&tpxver,&tpxgen);
 -    *natoms = tpx.natoms;
 -    break;
 -  }
 -  default:
 -    gmx_fatal(FARGS,"File type %s not supported in get_stx_coordnum",
 -            ftp2ext(ftp));
 -  }
 +    FILE      *in;
 +    int        ftp, tpxver, tpxgen;
 +    t_trxframe fr;
 +    char       g96_line[STRLEN+1];
 +
 +    ftp = fn2ftp(infile);
 +    range_check(ftp, 0, efNR);
 +    switch (ftp)
 +    {
 +        case efGRO:
 +            get_coordnum(infile, natoms);
 +            break;
 +        case efG96:
 +            in        = gmx_fio_fopen(infile, "r");
 +            fr.title  = NULL;
 +            fr.natoms = -1;
 +            fr.atoms  = NULL;
 +            fr.x      = NULL;
 +            fr.v      = NULL;
 +            fr.f      = NULL;
 +            *natoms   = read_g96_conf(in, infile, &fr, g96_line);
 +            gmx_fio_fclose(in);
 +            break;
 +        case efXYZ:
 +            *natoms = get_xyz_coordnum(infile);
 +            break;
 +        case efPDB:
 +        case efBRK:
 +        case efENT:
 +            in = gmx_fio_fopen(infile, "r");
 +            get_pdb_coordnum(in, natoms);
 +            gmx_fio_fclose(in);
 +            break;
 +        case efESP:
 +            *natoms = get_espresso_coordnum(infile);
 +            break;
 +        case efTPA:
 +        case efTPB:
 +        case efTPR:
 +        {
 +            t_tpxheader tpx;
 +
 +            read_tpxheader(infile, &tpx, TRUE, &tpxver, &tpxgen);
 +            *natoms = tpx.natoms;
 +            break;
 +        }
 +        default:
 +            gmx_fatal(FARGS, "File type %s not supported in get_stx_coordnum",
 +                      ftp2ext(ftp));
 +    }
  }
  
 -void read_stx_conf(const char *infile,char *title,t_atoms *atoms, 
 -                 rvec x[],rvec *v,int *ePBC,matrix box)
 +void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
 +                   rvec x[], rvec *v, int *ePBC, matrix box)
  {
 -  FILE       *in;
 -  char       buf[256];
 -  gmx_mtop_t *mtop;
 -  t_topology top;
 -  t_trxframe fr;
 -  int        i,ftp,natoms;
 -  real       d;
 -  char       g96_line[STRLEN+1];
 -
 -  if (atoms->nr == 0)
 -    fprintf(stderr,"Warning: Number of atoms in %s is 0\n",infile);
 -  else if (atoms->atom == NULL)
 -    gmx_mem("Uninitialized array atom");
 -  
 -  if (ePBC)
 -    *ePBC = -1;
 -
 -  ftp=fn2ftp(infile);
 -  switch (ftp) {
 -  case efGRO:
 -    read_whole_conf(infile, title, atoms, x, v, box);
 -    break;
 -  case efXYZ:
 -    read_xyz_conf(infile,title,atoms,x);
 -    break;
 -  case efG96:
 -    fr.title  = NULL;
 -    fr.natoms = atoms->nr;
 -    fr.atoms = atoms;
 -    fr.x = x;
 -    fr.v = v;
 -    fr.f = NULL;
 -    in = gmx_fio_fopen(infile,"r");
 -    read_g96_conf(in, infile, &fr, g96_line);
 -    gmx_fio_fclose(in);
 -    copy_mat(fr.box,box);
 -    strncpy(title, fr.title, STRLEN);
 -    break;
 -  case efPDB:
 -  case efBRK:
 -  case efENT:
 -    read_pdb_conf(infile, title, atoms, x, ePBC, box, TRUE, NULL);
 -    break;
 -  case efESP:
 -    read_espresso_conf(infile,atoms,x,v,box);
 -    break;
 -  case efTPR:
 -  case efTPB:
 -  case efTPA: 
 -    snew(mtop,1);
 -    i = read_tpx(infile,NULL,box,&natoms,x,v,NULL,mtop);
 +    FILE       *in;
 +    char        buf[256];
 +    gmx_mtop_t *mtop;
 +    t_topology  top;
 +    t_trxframe  fr;
 +    int         i, ftp, natoms;
 +    real        d;
 +    char        g96_line[STRLEN+1];
 +
 +    if (atoms->nr == 0)
 +    {
 +        fprintf(stderr, "Warning: Number of atoms in %s is 0\n", infile);
 +    }
 +    else if (atoms->atom == NULL)
 +    {
 +        gmx_mem("Uninitialized array atom");
 +    }
 +
      if (ePBC)
 -      *ePBC = i;
 -    
 -    strcpy(title,*(mtop->name));
 -    
 -    /* Free possibly allocated memory */
 -    done_atom(atoms);
 -    
 -    *atoms = gmx_mtop_global_atoms(mtop);
 -    top = gmx_mtop_t_to_t_topology(mtop);
 -    tpx_make_chain_identifiers(atoms,&top.mols);
 -              
 -    sfree(mtop);
 -    /* The strings in the symtab are still in use in the returned t_atoms
 -     * structure, so we should not free them. But there is no place to put the
 -     * symbols; the only choice is to leak the memory...
 -     * So we clear the symbol table before freeing the topology structure. */
 -    free_symtab(&top.symtab);
 -    done_top(&top);
 -                
 -    break;
 -  default:
 -    gmx_incons("Not supported in read_stx_conf");
 -  }
 -}
 +    {
 +        *ePBC = -1;
 +    }
  
-             fr.title  = title;
 +    ftp = fn2ftp(infile);
 +    switch (ftp)
 +    {
 +        case efGRO:
 +            read_whole_conf(infile, title, atoms, x, v, box);
 +            break;
 +        case efXYZ:
 +            read_xyz_conf(infile, title, atoms, x);
 +            break;
 +        case efG96:
++            fr.title  = NULL;
 +            fr.natoms = atoms->nr;
 +            fr.atoms  = atoms;
 +            fr.x      = x;
 +            fr.v      = v;
 +            fr.f      = NULL;
 +            in        = gmx_fio_fopen(infile, "r");
 +            read_g96_conf(in, infile, &fr, g96_line);
 +            gmx_fio_fclose(in);
 +            copy_mat(fr.box, box);
++            strncpy(title, fr.title, STRLEN);
 +            break;
 +        case efPDB:
 +        case efBRK:
 +        case efENT:
 +            read_pdb_conf(infile, title, atoms, x, ePBC, box, TRUE, NULL);
 +            break;
 +        case efESP:
 +            read_espresso_conf(infile, atoms, x, v, box);
 +            break;
 +        case efTPR:
 +        case efTPB:
 +        case efTPA:
 +            snew(mtop, 1);
 +            i = read_tpx(infile, NULL, box, &natoms, x, v, NULL, mtop);
 +            if (ePBC)
 +            {
 +                *ePBC = i;
 +            }
 +
 +            strcpy(title, *(mtop->name));
 +
 +            /* Free possibly allocated memory */
 +            done_atom(atoms);
 +
 +            *atoms = gmx_mtop_global_atoms(mtop);
 +            top    = gmx_mtop_t_to_t_topology(mtop);
 +            tpx_make_chain_identifiers(atoms, &top.mols);
 +
 +            sfree(mtop);
 +            /* The strings in the symtab are still in use in the returned t_atoms
 +             * structure, so we should not free them. But there is no place to put the
 +             * symbols; the only choice is to leak the memory...
 +             * So we clear the symbol table before freeing the topology structure. */
 +            free_symtab(&top.symtab);
 +            done_top(&top);
 +
 +            break;
 +        default:
 +            gmx_incons("Not supported in read_stx_conf");
 +    }
 +}