NCEPLIBS-bufr  12.0.0
crwbmg.c File Reference

C language interface for reading or writing BUFR messages. More...

#include "bufrlib.h"

Go to the source code of this file.

Macros

#define MXFNLEN   200
 Maximum length of a filename, including any directory prefixes or other local filesystem notation. More...
 

Functions

void ccbfl (void)
 Close all files that were opened via previous calls to function cobfl(). More...
 
void cobfl (char *bfl, char io)
 Open a new file for reading or writing BUFR messages via a C language interface. More...
 
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() with io = 'r'. More...
 
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 = 'w'. More...
 
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 cobfl() with io = 'r'. More...
 

Variables

FILE * pbf [2]
 File pointers; each element will automatically initialize to NULL. More...
 

Detailed Description

C language interface for reading or writing BUFR messages.

Author
J. Ator
Date
2005-11-29

Definition in file crwbmg.c.

Macro Definition Documentation

◆ MXFNLEN

#define MXFNLEN   200

Maximum length of a filename, including any directory prefixes or other local filesystem notation.

Definition at line 10 of file crwbmg.c.

Function Documentation

◆ ccbfl()

void ccbfl ( void  )

Close all files that were opened via previous calls to function cobfl().

Author
J. Ator
Date
2005-11-29

Definition at line 296 of file crwbmg.c.

References pbf.

Referenced by main().

◆ cobfl()

void cobfl ( char *  bfl,
char  io 
)

Open a new file for reading or writing BUFR messages via a C language interface.

This function is designed to be easily callable from application program written in either C or Fortran. It is functionally equivalent to subroutine openbf(); however, there are some important differences:

  • When using openbf(), the underlying file must already be associated with a Fortran logical unit number on the local system, typicially via a prior Fortran "OPEN" statement. This is not required when using this function.
  • When using this function, it is only possible to have at most one input (io = 'r') file and one output (io = 'w') file open at a time. If a successive call to this function is made in either case where a file of that type is already open, then the function will automatically close the previous file of that type before opening the new one.
  • When opening a file for input/reading using openbf(), the user can make subsequent calls to any of the NCEPLIBS-bufr message-reading subroutines to read individual BUFR messages from that file into internal arrays, followed by subsequent calls to any of the NCEPLIBS-bufr subset-reading subroutines") to read individual data subsets from each such message. However, when opening a file for input/reading using this function, the user must instead make subsequent calls to crbmg() to read individual BUFR messages from that file, and each such message will be returned directly to the user within an allocated memory array. The user may then, if desired, make subsequent calls to readerme() to store each such message into the same internal arrays, followed by subsequent calls to any of the NCEPLIBS-bufr subset-reading subroutines" to read individual data subsets from each such message.
  • When opening a file for output/writing using openbf(), the user can make subsequent successive calls to writsb() to pack each completed data subset into the BUFR message that is currently open within the internal arrays, for eventual output to that file. However, when opening a file for output/writing using this function, the user can instead, if desired, make subsequent successive calls to writsa() to pack each completed data subset into the BUFR message that is currently open within the internal arrays. The use of writsa() will cause each completed BUFR message to be returned directly to the user within an allocated memory array, which in turn can then be written directly to the file via a subsequent call to cwbmg().

Any errors encountered when using this function are automatically logged to standard output, or to an alternate location previously specified via a call to subroutine errwrt().

Parameters
bfl- System file to be opened. Inclusion of directory prefixes or other local filesystem notation is allowed, up to 200 total characters.
io- Flag indicating how bfl is to be opened:
  • 'r' input (for reading BUFR messages)
  • 'w' output (for writing BUFR messages)
Author
J. Ator
Date
2005-11-29

Definition at line 120 of file crwbmg.c.

References bort_f(), MXFNLEN, pbf, and wrdlen_f().

Referenced by main().

◆ crbmg()

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() with io = 'r'.

This function is designed to be easily callable from application program written in either C or Fortran.

Parameters
bmg- BUFR message
mxmb- Number of elements in bmg array;; used by the function to ensure that it doesn't overflow the array.
nmb- Size (in bytes) of BUFR message in bmg.
iret- return code:
  • 0 normal return.
  • 1 overflow of bmg array.
  • 2 "7777" indicator not found in expected location.
  • -1 end-of-file encountered while reading.
  • -2 I/O error encountered while reading.
Author
J. Ator
Date
2005-11-29

Definition at line 201 of file crwbmg.c.

References bort_f(), iupbs01_f(), pbf, and rbytes().

◆ cwbmg()

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 = 'w'.

This function is designed to be easily callable from application program written in either C or Fortran.

Parameters
bmg- BUFR message
nmb- Size (in bytes) of BUFR message in bmg
iret- return code:
  • 0 normal return.
  • -1 I/O error encountered while writing.
Author
J. Ator
Date
2005-11-29

Definition at line 269 of file crwbmg.c.

References bort_f(), and pbf.

◆ rbytes()

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 cobfl() with io = 'r'.

Parameters
bmg- Array containing the newbytes bytes that were read, beginning at byte number isloc.
mxmb- Number of elements in bmg array; used by the function to ensure that it doesn't overflow the array.
isloc- Starting byte within bmg into which to read the next newbytes bytes
newbytes- Number of bytes to read from file most recently opened for input/reading via function cobfl()
Returns
  • 0 normal return
  • 1 overflow of bmg array
  • -1 end-of-file encountered while reading
  • -2 I/O error encountered while reading
Author
J. Ator
Date
2005-11-29

Definition at line 38 of file crwbmg.c.

References pbf.

Referenced by crbmg().

Variable Documentation

◆ pbf

FILE* pbf[2]

File pointers; each element will automatically initialize to NULL.

Definition at line 14 of file crwbmg.c.

Referenced by ccbfl(), cobfl(), crbmg(), cwbmg(), and rbytes().