Skip to content

Instantly share code, notes, and snippets.

@rmcgibbo
Created May 12, 2015 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmcgibbo/ed7be1fff89e3467f1bc to your computer and use it in GitHub Desktop.
Save rmcgibbo/ed7be1fff89e3467f1bc to your computer and use it in GitHub Desktop.
diff xdrfile-1.1.4/src/xdrfile.c src/xdrfile.c
1,4d0
< /* -*- mode: c; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
< *
< * $Id$
< *
635c631
< fprintf(stderr,"major breakdown in encodeints - num %u doesn't "
---
> fprintf(stderr,"(xdrfile error) major breakdown in encodeints - num %u doesn't "
795a792
> const float* ptrstart = ptr;
801c798,799
< if(xfp==NULL || ptr==NULL)
---
> if(xfp==NULL || ptr==NULL) {
> fprintf(stderr, "(xdrfile error) Null pointer issue\n");
802a801
> }
804c803,804
< if(tmp==0)
---
> if(tmp==0) {
> fprintf(stderr, "(xdrfile error) Size could not be read\n");
805a806
> }
808c809
< fprintf(stderr, "Requested to decompress %d coords, file contains %d\n",
---
> fprintf(stderr, "(xdrfile error) Requested to decompress %d coords, file contains %d\n",
818c819
< fprintf(stderr,"Cannot allocate memory for decompressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for decompressing coordinates.\n");
825c826
< fprintf(stderr,"Cannot allocate memory for decompressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for decompressing coordinates.\n");
863c864,865
< if (xdrfile_read_int(&smallidx,1,xfp) == 0)
---
> if (xdrfile_read_int(&smallidx,1,xfp) == 0) {
> fprintf(stderr,"(xdrfile error) Undocumented error 1");
864a867
> }
877,879c880,881
< if (xdrfile_read_int(buf2,1,xfp) == 0)
< return 0;
< if (xdrfile_read_opaque((char *)&(buf2[3]),(unsigned int)buf2[0],xfp) == 0)
---
> if (xdrfile_read_int(buf2,1,xfp) == 0) {
> fprintf(stderr, "(xdrfile error) Undocumented error 2");
880a883,887
> }
> if (xdrfile_read_opaque((char *)&(buf2[3]),(unsigned int)buf2[0],xfp) == 0) {
> fprintf(stderr, "(xdrfile error) Undocumented error 3");
> return 0;
> }
920a928,932
> if ((lfp-ptrstart)+run > size3)
> {
> fprintf(stderr, "(xdrfile error) Buffer overrun during decompression.\n");
> return 0;
> }
979c991,996
< sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx] ;
---
> sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
> if (sizesmall[0]==0 || sizesmall[1]==0 || sizesmall[2]==0)
> {
> fprintf(stderr, "(xdrfile error) Undefined error.\n");
> return 0;
> }
1014c1031
< fprintf(stderr,"Cannot allocate memory for compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for compressing coordinates.\n");
1021c1038
< fprintf(stderr,"Cannot allocate memory for compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for compressing coordinates.\n");
1059c1076
< fprintf(stderr,"Internal overflow compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Internal overflow compressing coordinates.\n");
1074c1091
< fprintf(stderr,"Internal overflow compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Internal overflow compressing coordinates.\n");
1111c1128
< fprintf(stderr,"Internal overflow compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Internal overflow compressing coordinates.\n");
1305c1322
< fprintf(stderr, "Requested to decompress %d coords, file contains %d\n",
---
> fprintf(stderr, "(xdrfile error) Requested to decompress %d coords, file contains %d\n",
1315c1332
< fprintf(stderr,"Cannot allocate memory for decompression coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for decompression coordinates.\n");
1322c1339
< fprintf(stderr,"Cannot allocate memory for decompressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for decompressing coordinates.\n");
1504c1521
< fprintf(stderr,"Cannot allocate memory for compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for compressing coordinates.\n");
1510c1527
< fprintf(stderr,"Cannot allocate memory for compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Cannot allocate memory for compressing coordinates.\n");
1548c1565
< fprintf(stderr,"Internal overflow compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Internal overflow compressing coordinates.\n");
1562c1579
< fprintf(stderr,"Internal overflow compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Internal overflow compressing coordinates.\n");
1598c1615
< fprintf(stderr,"Internal overflow compressing coordinates.\n");
---
> fprintf(stderr, "(xdrfile error) Internal overflow compressing coordinates.\n");
diff xdrfile-1.1.4/src/xdrfile_trr.c src/xdrfile_trr.c
1,4d0
< /* -*- mode: c; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
< *
< * $Id$
< *
101,103c97,106
< if (xdrfile_read_int(&magic,1,xd) != 1)
< return exdrINT;
<
---
> if (xdrfile_read_int(&magic,1,xd) != 1) {
> /* modification by RTM to return the right EOF code
> this is what's happening in the XTC code */
> if (bRead)
> return exdrENDOFFILE;
> else
> return exdrINT;
> }
> if (magic != GROMACS_MAGIC)
> return exdrMAGIC;
449a453
>
486a491,519
> int read_trr_nframes(char *fn, unsigned long *nframes) {
> XDRFILE *xd;
> int result, step;
> float time, lambda;
> int natoms;
> matrix box;
> rvec *x;
> *nframes = 0;
>
> read_trr_natoms(fn, &natoms);
> x = malloc(natoms * sizeof(*x));
>
> xd = xdrfile_open(fn, "r");
> if (NULL == xd)
> return exdrFILENOTFOUND;
>
> do {
> result = read_trr(xd, natoms, &step, &time, &lambda,
> box, x, NULL, NULL);
> if (exdrENDOFFILE != result) {
> (*nframes)++;
> }
> } while (result == exdrOK);
>
> xdrfile_close(xd);
> free(x);
> return exdrOK;
> }
>
diff xdrfile-1.1.4/src/xdrfile_xtc.c src/xdrfile_xtc.c
104a105,133
> int read_xtc_nframes(char* fn, unsigned long *nframes) {
> XDRFILE *xd;
> int result, step;
> float time;
> int natoms;
> matrix box;
> rvec *x;
> float prec;
> *nframes = 0;
>
> read_xtc_natoms(fn, &natoms);
> x = malloc(natoms * sizeof(*x));
>
> xd = xdrfile_open(fn, "r");
> if (NULL == xd)
> return exdrFILENOTFOUND;
>
> do {
> result = read_xtc(xd, natoms, &step, &time, box, x, &prec);
> if (exdrENDOFFILE != result) {
> (*nframes)++;
> }
> } while (result == exdrOK);
>
> xdrfile_close(xd);
> free(x);
> return exdrOK;
> }
>
117c146
<
---
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment