本文整理汇总了C++中DataSource::DataSourceUngetc方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSource::DataSourceUngetc方法的具体用法?C++ DataSource::DataSourceUngetc怎么用?C++ DataSource::DataSourceUngetc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSource
的用法示例。
在下文中一共展示了DataSource::DataSourceUngetc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindGRIBMsg
/*****************************************************************************
* FindGRIBMsg() -- Review 12/2002
*
* Arthur Taylor / MDL
*
* PURPOSE
* Jumps through a GRIB2 file looking for a specific message. Currently
* that message is determined by msgNum which is in the range of 1..n.
* In the future we may be searching based on projection or date.
*
* ARGUMENTS
* fp = The current GRIB2 file to look through. (Input)
* msgNum = Which message to look for. (Input)
* offset = Where in the file the message starts (this is before the
* wmo ASCII part if there is one.) (Output)
* curMsg = The current # of messages we have looked through. (In/Out)
*
* FILES/DATABASES:
* An already opened "GRIB2" File
*
* RETURNS: int (could use errSprintf())
* 0 = OK
* -1 = Problems reading Section 0.
* -2 = Ran out of file.
*
* HISTORY
* 11/2002 Arthur Taylor (MDL/RSIS): Created.
* 12/2002 (TK,AC,TB,&MS): Code Review.
* 6/2003 Matthew T. Kallio ([email protected]):
* "wmo" dimension increased to WMO_HEADER_LEN + 1 (for '\0' char)
* 8/2003 AAT: Removed dependence on offset and fileLen.
*
* NOTES
*****************************************************************************
*/
int FindGRIBMsg (DataSource &fp, int msgNum, sInt4 *offset, int *curMsg)
{
int cnt; /* The current message we are looking at. */
char *buff; /* Holds the info between records. */
uInt4 buffLen; /* Length of info between records. */
sInt4 sect0[SECT0LEN_WORD]; /* Holds the current Section 0. */
uInt4 gribLen; /* Length of the current GRIB message. */
int version; /* Which version of GRIB is in this message. */
int c; /* Determine if end of the file without fileLen. */
sInt4 jump; /* How far to jump to get to past GRIB message. */
cnt = *curMsg + 1;
buff = NULL;
buffLen = 0;
while ((c = fp.DataSourceFgetc()) != EOF) {
fp.DataSourceUngetc(c);
if (cnt >= msgNum) {
/* 12/1/2004 version 1.63 forgot to free buff */
free (buff);
*curMsg = cnt;
return 0;
}
/* Read section 0 to find gribLen and wmoLen. */
if (ReadSECT0 (fp, &buff, &buffLen, GRIB_LIMIT, sect0, &gribLen,
&version) < 0) {
preErrSprintf ("Inside FindGRIBMsg\n");
free (buff);
return -1;
}
myAssert ((version == 1) || (version == 2) || (version == -1));
/* Continue on to the next grib message. */
if ((version == 1) || (version == -1)) {
jump = gribLen - 8;
} else {
jump = gribLen - 16;
}
fp.DataSourceFseek(jump, SEEK_CUR);
*offset = *offset + gribLen + buffLen;
cnt++;
}
free (buff);
*curMsg = cnt - 1;
/* Return -2 since we reached the end of file. This may not be an error
* (multiple file option). */
return -2;
/*
errSprintf ("ERROR: Ran out of file looking for msgNum %d.\n", msgNum);
errSprintf (" Current msgNum %d\n", cnt);
*/
}
示例2: errSprintf
/*****************************************************************************
* GRIB2SectJump() --
*
* Arthur Taylor / MDL
*
* PURPOSE
* To jump past a GRIB2 section. Reads in secLen and checks that the
* section is valid.
*
* ARGUMENTS
* fp = Opened file pointing to the section in question. (Input/Output)
* gribLen = The total length of the grib message. (Input)
* sect = Which section we think we are reading.
* If it is -1, then set it to the section the file says we are
* reading (useful for optional sect 2)) (Input/Output).
* secLen = The length of this section (Output)
*
* FILES/DATABASES:
* An already opened GRIB2 file pointer, already at section in question.
*
* RETURNS: int (could use errSprintf())
* 0 = Ok.
* -1 = Ran out of file.
* -2 = Section was miss-labeled.
*
* HISTORY
* 3/2003 Arthur Taylor (MDL/RSIS): Created.
* 8/2003 AAT: Removed dependence on curTot, which was used to compute if
* the file should be large enough for the fseek, but didn't check
* if it actually was.
*
* NOTES
* May want to put this in degrib2.c
*****************************************************************************
*/
static int GRIB2SectJump (DataSource &fp,
CPL_UNUSED sInt4 gribLen, sChar *sect, uInt4 *secLen)
{
char sectNum; /* Validates that we are on the correct section. */
int c; /* Check that the fseek is still inside the file. */
if (FREAD_BIG (secLen, sizeof (sInt4), 1, fp) != 1) {
if (*sect != -1) {
errSprintf ("ERROR: Ran out of file in Section %d\n", *sect);
} else {
errSprintf ("ERROR: Ran out of file in GRIB2SectSkip\n");
}
return -1;
}
if (fp.DataSourceFread (§Num, sizeof (char), 1) != 1) {
if (*sect != -1) {
errSprintf ("ERROR: Ran out of file in Section %d\n", *sect);
} else {
errSprintf ("ERROR: Ran out of file in GRIB2SectSkip\n");
}
return -1;
}
if (*sect == -1) {
*sect = sectNum;
} else if (sectNum != *sect) {
errSprintf ("ERROR: Section %d mislabeled\n", *sect);
return -2;
}
/* Since fseek does not give an error if we jump outside the file, we test
* it by using fgetc / ungetc. */
fp.DataSourceFseek (*secLen - 5, SEEK_CUR);
if ((c = fp.DataSourceFgetc()) == EOF) {
errSprintf ("ERROR: Ran out of file in Section %d\n", *sect);
return -1;
} else {
fp.DataSourceUngetc(c);
}
return 0;
}
示例3: GRIB2Inventory
//.........这里部分代码省略.........
uChar prodType; /* Which GRIB2 type of product, 0 is meteo, 1 is
* hydro, 2 is land, 3 is space, 10 is oceanographic.
*/
int grib_limit; /* How many bytes to look for before the first "GRIB"
* in the file. If not found, is not a GRIB file. */
int c; /* Determine if end of the file without fileLen. */
sInt4 fileLen; /* Length of the GRIB2 file. */
unsigned short int center, subcenter; /* Who produced it. */
// char *ptr; /* used to find the file extension. */
grib_limit = GRIB_LIMIT;
/*
if (filename != NULL) {
//if ((fp = fopen (filename, "rb")) == NULL) {
// errSprintf ("ERROR: Problems opening %s for read.", filename);
// return -1;
//}
//fp = FileDataSource(filename);
ptr = strrchr (filename, '.');
if (ptr != NULL) {
if (strcmp (ptr, ".tar") == 0) {
grib_limit = 5000;
}
}
} else {
//fp = stdin; // TODO!!
}
*/
msgNum = *MsgNum;
buff = NULL;
buffLen = 0;
while ((c = fp.DataSourceFgetc()) != EOF) {
fp.DataSourceUngetc(c);
// ungetc (c, fp);
/* msgNum++ done first so any error messages range from 1..n, instead
* of 0.. n-1. Note msgNum should end up as n not (n-1) */
msgNum++;
/* Used when testing inventory of large TDLPack files. */
/*
#ifdef DEBUG
myAssert (msgNum < 32500L);
if (msgNum % 10 == 0) {
printf ("%ld :: %f\n", msgNum, clock () / (double) CLOCKS_PER_SEC);
}
#endif
*/
/* Make it so the second, third, etc messages have no limit to finding
* the "GRIB" keyword. */
if (msgNum > 1) {
grib_limit = -1;
}
/* Read in the wmo header and sect0. */
if (ReadSECT0 (fp, &buff, &buffLen, grib_limit, sect0, &gribLen,
&version) < 0) {
if (msgNum == 1) {
/* Handle case where we couldn't find 'GRIB' in the message. */
preErrSprintf ("Inside GRIB2Inventory, Message # %d\n", msgNum);
free (buffer);
free (buff);
//fclose (fp);
return -2;
} else {
/* Handle case where there are trailing bytes. */
msg = errSprintf (NULL);
printf ("Warning: Inside GRIB2Inventory, Message # %d\n",