37 rbytes(
char *bmg,
int mxmb,
int isloc,
int newbytes)
41 if ((isloc + newbytes) > mxmb) {
44 else if (fread(&bmg[isloc], 1, newbytes,
pbf[0]) != newbytes) {
45 iret = (feof(
pbf[0]) ? -1 : -2);
126 char foparg[3] =
" b";
143 for (i = 0; (! isspace(bfl[i]) && ! iscntrl(bfl[i])); i++) {
145 sprintf(errstr,
"BUFRLIB: COBFL - INPUT FILENAME CONTAINS"
146 " MORE THAN %hu CHARACTERS", (
unsigned short)
MXFNLEN);
154 if ((foparg[0] = (
char) tolower(lio)) ==
'r') {
157 else if (foparg[0] ==
'w') {
161 sprintf(errstr,
"BUFRLIB: COBFL - SECOND ARGUMENT WAS (%c),"
162 " WHICH IS AN ILLEGAL VALUE", lio);
169 if (
pbf[j] != NULL) fclose(
pbf[j]);
174 if ((
pbf[j] = fopen(lbf, foparg)) == NULL) {
175 sprintf(errstr,
"BUFRLIB: COBFL - COULD NOT OPEN FILE %s", lbf);
203 crbmg(
char *bmg,
int mxmb,
int *nmb,
int *iret)
208 char blanks[5] =
" ";
222 if (
pbf[0] == NULL) {
223 sprintf(errstr,
"BUFRLIB: CRBMG - NO FILE IS OPEN FOR READING");
239 while (strncmp(
BMOSTR, bmg, 4) != 0) {
240 memmove(bmg, &bmg[1], 3);
241 if ((*iret =
rbytes(bmg, mxmb, 3, 1)) != 0)
return;
247 if ((*iret =
rbytes(bmg, mxmb, 4, 4)) != 0)
return;
248 memcpy(wkint, bmg, 8);
254 if ((*iret =
rbytes(bmg, mxmb, 8, *nmb-8)) != 0)
return;
259 *iret = ((strncmp(
BMCSTR, &bmg[*nmb-4], 4) == 0) ? 0 : 2);
280 cwbmg(
const char *bmg,
int nmb,
int *iret)
296 if (
pbf[1] == NULL) {
297 sprintf(errstr,
"BUFRLIB: CWBMG - NO FILE IS OPEN FOR WRITING");
304 *iret = ((fwrite(bmg, 1, nmb,
pbf[1]) == nmb) ? 0 : -1);
320 for (i = 0; i < 2; i++) {
321 if (
pbf[i] != NULL) fclose(
pbf[i]);
void catch_bort_crbmg(char *bmg, int mxmb, int *nmb, int *iret)
Catch any bort error inside of function crbmg().
void catch_bort_cwbmg(const char *bmg, int nmb, int *iret)
Catch any bort error inside of function cwbmg().
void catch_bort_cobfl(const char *bfl, char io)
Catch any bort error inside of function cobfl().
int iupbs01_f(int *bufr, const char *mnemonic)
Read a data value from Section 0 or Section 1 of a BUFR message.
Enable a number of NCEPLIBS-bufr subprograms to be called from within the C part of the library.
#define BMCSTR
Closing string of a BUFR message.
void bort_target_unset_f(void)
Clear any existing bort target.
void bort_f(const char *errstr)
Log one error message and abort application program.
int bort_target_set_f(void)
Sets a new bort target, if bort catching is enabled and such a target doesn't already exist.
#define BMOSTR
Opening string of a BUFR message.
void cobfl(const char *bfl, char io)
Open a new file for reading or writing BUFR messages via a C language interface.
void cwbmg(const char *bmg, int nmb, int *iret)
Write a BUFR message to the file that was opened via the most recent call to function cobfl() with io...
int rbytes(char *bmg, int mxmb, int isloc, int newbytes)
Read a specified number of bytes from the file that was opened via the most recent call to function c...
void crbmg(char *bmg, int mxmb, int *nmb, int *iret)
Read the next BUFR message from the file that was opened via the most recent call to function cobfl()...
void ccbfl(void)
Close all files that were opened via previous calls to function cobfl().
#define MXFNLEN
Maximum length of a filename, including any directory prefixes or other local filesystem notation.
FILE * pbf[2]
File pointers; each element will automatically initialize to NULL.