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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*****************************************************************************
*
* getpub.c
* does an indexed lookup for medline entries by medline uid
*
*****************************************************************************/
#include "allpub.h"
#define NUMARGS 5
Args myargs[NUMARGS] = {
{ "Input binary data", "medline.val", "Pub-set", NULL, FALSE, 'i', ARG_DATA_IN, 0.0,0,NULL},
{ "Medline UID to find", "88055872", NULL,NULL,FALSE,'u', ARG_INT, 0.0, 0, NULL },
{ "Input index table", "medline.idx", NULL,NULL,FALSE,'t', ARG_FILE_IN, 0.0,0,NULL },
{ "Output data", "stdout", "Medline-entry",NULL,FALSE,'o',ARG_DATA_OUT, 0.0,0,NULL},
{ "Output data is binary", "F", NULL, NULL, FALSE , 'b', ARG_BOOLEAN, 0.0,0,NULL}};
Int2 Main(void)
{
AsnIoPtr aip, aipout;
AsnTypePtr atp;
DataVal value;
Int4 seekptr, uid, uid_to_find;
static CharPtr outtypes[2] = { "w", "wb" };
Int2 outtype;
FILE *fp;
Boolean done, first;
int retval;
if (! AsnLoad())
Message(MSG_FATAL, "Unable to load allpub parse tree.");
if (! GetArgs("GetPub 1.0", NUMARGS, myargs))
return 1;
if (myargs[4].intvalue) /* binary output is TRUE */
outtype = 1;
else
outtype = 0;
if ((aip = AsnIoOpen(myargs[0].strvalue, "rb")) == NULL)
{
Message(MSG_ERROR, "Couldn't open %s", myargs[0].strvalue);
return 1;
}
if ((aipout = AsnIoOpen(myargs[3].strvalue, outtypes[outtype])) == NULL)
{
Message(MSG_ERROR, "Couldn't open %s", myargs[3].strvalue);
return 1;
}
if ((fp = FileOpen(myargs[2].strvalue, "r")) == NULL)
{
Message(MSG_ERROR, "Couldn't open %s", myargs[2].strvalue);
return 1;
}
uid_to_find = myargs[1].intvalue;
done = FALSE;
first = TRUE;
while (! done)
{
retval = fscanf(fp, "%d %d", &uid, &seekptr);
if (retval == EOF)
{
Message(MSG_ERROR, "UID %ld not found", uid_to_find);
return 1;
}
if (uid == uid_to_find)
done = TRUE;
}
FileClose(fp);
atp = MEDLINE_ENTRY;
AsnIoSeek(aip, seekptr);
done = FALSE;
while (! done)
{
atp = AsnReadId(aip, amp, atp);
AsnReadVal(aip, atp, &value);
AsnWrite(aipout, atp, &value);
AsnKillValue(atp, &value);
if (! first)
{
if (atp == MEDLINE_ENTRY)
done = TRUE;
}
else
first = FALSE;
}
AsnIoClose(aip);
AsnIoClose(aipout);
return 0;
}
|