38 rbytes(
char *bmg,
int mxmb,
int isloc,
int newbytes)
42 if ((isloc + newbytes) > mxmb) {
45 else if (fread(&bmg[isloc], 1, newbytes,
pbf[0]) != newbytes) {
46 iret = (feof(
pbf[0]) ? -1 : -2);
127 char foparg[3] =
" b";
135 for (i = 0; (! isspace(bfl[i]) && ! iscntrl(bfl[i])); i++) {
137 sprintf(errstr,
"BUFRLIB: COBFL - INPUT FILENAME CONTAINS"
138 " MORE THAN %hu CHARACTERS", (
unsigned short)
MXFNLEN);
146 if ((foparg[0] = (
char) tolower(lio)) ==
'r') {
149 else if (foparg[0] ==
'w') {
153 sprintf(errstr,
"BUFRLIB: COBFL - SECOND ARGUMENT WAS (%c),"
154 " WHICH IS AN ILLEGAL VALUE", lio);
161 if (
pbf[j] != NULL) fclose(
pbf[j]);
166 if ((
pbf[j] = fopen(lbf, foparg)) == NULL) {
167 sprintf(errstr,
"BUFRLIB: COBFL - COULD NOT OPEN FILE %s", lbf);
201 crbmg(
char *bmg,
int mxmb,
int *nmb,
int *iret)
206 char blanks[5] =
" ";
211 if (
pbf[0] == NULL) {
212 sprintf(errstr,
"BUFRLIB: CRBMG - NO FILE IS OPEN FOR READING");
228 while (strncmp(
"BUFR", bmg, 4) != 0) {
229 memmove(bmg, &bmg[1], 3);
230 if ((*iret =
rbytes(bmg, mxmb, 3, 1)) != 0)
return;
236 if ((*iret =
rbytes(bmg, mxmb, 4, 4)) != 0)
return;
237 memcpy(wkint, bmg, 8);
243 if ((*iret =
rbytes(bmg, mxmb, 8, *nmb-8)) != 0)
return;
248 *iret = ((strncmp(
"7777", &bmg[*nmb-4], 4) == 0) ? 0 : 2);
269 cwbmg(
char *bmg,
int nmb,
int *iret)
276 if (
pbf[1] == NULL) {
277 sprintf(errstr,
"BUFRLIB: CWBMG - NO FILE IS OPEN FOR WRITING");
284 *iret = ((fwrite(bmg, 1, nmb,
pbf[1]) == nmb) ? 0 : -1);
300 for (i = 0; i < 2; i++) {
301 if (
pbf[i] != NULL) fclose(
pbf[i]);
int iupbs01_f(int *bufr, 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.
void wrdlen_f(void)
Determine important information about the local machine.
void bort_f(char *errstr)
Log one error message and abort application program.
void cobfl(char *bfl, char io)
Open a new file for reading or writing BUFR messages via a C language interface.
void cwbmg(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.