File: testobj.c

package info (click to toggle)
ncbi-tools6 6.1.20120620-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 241,628 kB
  • ctags: 101,236
  • sloc: ansic: 1,431,713; cpp: 6,248; pascal: 3,949; xml: 3,390; sh: 3,090; perl: 1,077; csh: 488; makefile: 449; ruby: 93; lisp: 81
file content (81 lines) | stat: -rw-r--r-- 2,168 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

/*****************************************************************************
*
*   testobj.c
*       test program for object loaders
*
*****************************************************************************/
#include <objmedli.h>
#include <objsset.h>

Int2 Main(void)
{
	AsnIoPtr aip, aipout, aipnull;
    MedlineEntryPtr mep;
    BioseqSetPtr bsp;
	DatePtr tmp;

    if (! MedlineAsnLoad())
    {
        Message(MSG_ERROR, "MedlineLoad failed");
        return 1;
    }

	if ((aip = AsnIoOpen("medline.ent", "r")) == NULL)
		return 1;

    mep = MedlineEntryAsnRead(aip, NULL);
	if (mep == NULL) ErrShow();

      /**** this is a demonstration of error checking using a null device
		    before actually writing the object **************************/

	aipnull = AsnIoNullOpen();     /* open a NULL device for testing */
	aipout = AsnIoOpen("medline.out", "w");   /* open a real output stream */

	ErrSetOpts(ERR_CONTINUE, 0);   /* set to continue on an error */

	tmp = mep->em;           /* Entry Month is required for Medline Entry */
	mep->em = NULL;          /* so we create an error */
							 
	                         /* this will fail, and ErrPost() */
	if (! MedlineEntryAsnWrite(mep, aipnull, NULL))
		ErrShow();

	mep->em = tmp;           /* put it back */
	AsnIoReset(aipnull);     /* reset the null device */

							 /* now check it again */
							 /* normally this is all the code you need */

    if (! MedlineEntryAsnWrite(mep, aipnull, NULL))     /* if not ok  */
		ErrShow();               						/*    show error */
	else if (! MedlineEntryAsnWrite(mep, aipout, NULL))	/* else write it */
		ErrShow();										/*  with fail-safe */

							 /* that's all  */

    MedlineEntryFree(mep);

	aip = AsnIoClose(aip);
    aipout = AsnIoClose(aipout);

    if (! SeqSetAsnLoad())
    {
        Message(MSG_ERROR, "SeqSetLoad failed");
        return 1;
    }

	if ((aip = AsnIoOpen("bioseq.set", "r")) == NULL)
		return 1;

	aipout = AsnIoOpen("seqset.out", "w");
    bsp = BioseqSetAsnRead(aip, NULL);
    BioseqSetAsnWrite(bsp, aipout, NULL);
    BioseqSetFree(bsp);
	aip = AsnIoClose(aip);
    aipout = AsnIoClose(aipout);

	return 0;
}