NCEPLIBS-bufr  11.6.0
 All Data Structures Files Functions Variables Pages
cread.c
Go to the documentation of this file.
1 
16 #include "bufrlib.h"
17 #include "cread.h"
18 
34 void openrb (nfile,ufile) f77int *nfile; char *ufile; { pb[*nfile] = fopen( ufile , "rb " ); }
35 
51 void openwb (nfile,ufile) f77int *nfile; char *ufile; { pb[*nfile] = fopen( ufile , "wb " ); }
52 
68 void openab (nfile,ufile) f77int *nfile; char *ufile; { pb[*nfile] = fopen( ufile , "a+b" ); }
69 
84 void backbufr (nfile ) f77int *nfile; { fsetpos(pb[*nfile],&lstpos[*nfile]);}
85 
100 void cewind (nfile ) f77int *nfile; { rewind(pb[*nfile]); }
101 
116 void closfb (nfile ) f77int *nfile; { fclose(pb[*nfile]); }
117 
140 f77int crdbufr (nfile,bufr,mxbyt)
141 f77int *nfile; f77int *mxbyt; char *bufr;
142 { f77int nbyt; f77int nb; f77int wkint[2]; fpos_t nxtpos;
143  fgetpos(pb[*nfile],&lstpos[*nfile]);
144  nb = sizeof(*bufr); bufr[0]=bufr[1];
145  while ( strncmp(bufr,"BUFR",4)!=0)
146  { memmove(bufr,&bufr[1],3);
147  if(fread(bufr+3,nb,1,pb[*nfile])!=1) return -1;
148  }
149  fgetpos(pb[*nfile],&nxtpos); if(fread(bufr+4,nb,4,pb[*nfile])!=4) return -1;
150  memcpy(wkint,bufr,8); nbyt=iupbs01(wkint,"LENM",4)-8;
151  if(nbyt+8>*mxbyt) {fsetpos(pb[*nfile],&nxtpos);return -3;};
152  if(fread(bufr+8,nb,nbyt,pb[*nfile])!=nbyt) {fsetpos(pb[*nfile],&nxtpos);return -2;};
153  if(strncmp(bufr+nbyt+4,"7777",4)!=0) {fsetpos(pb[*nfile],&nxtpos);return -2;};
154  return 0;
155 }
156 
173 void cwrbufr (nfile,bufr,nwrd)
174 f77int *nfile; f77int *nwrd; f77int *bufr;
175 { f77int nb; nb = sizeof(*bufr);
176  fwrite(bufr,nb,*nwrd,pb[*nfile]);
177 }
Define signatures to enable a number of BUFRLIB subprograms to be called directly from C application ...
void closfb(f77int *nfile)
This subroutine closes a previously opened BUFR file.
Definition: cread.c:116
void backbufr(f77int *nfile)
This subroutine backspaces a BUFR file by one BUFR message.
Definition: cread.c:84
f77int crdbufr(f77int *nfile, char *bufr, f77int *mxbyt)
This function reads the next message from a BUFR file that was previously opened for reading...
Definition: cread.c:140
void cwrbufr(f77int *nfile, f77int *bufr, f77int *nwrd)
This subroutine writes a BUFR message into a file that was previously opened for writing.
Definition: cread.c:173
void openab(f77int *nfile, char *ufile)
This subroutine opens a new system file for appending BUFR messages.
Definition: cread.c:68
fpos_t * lstpos
Byte positions of last successful reads from files corresponding to pb, for files that were opened fo...
void cewind(f77int *nfile)
This subroutine rewinds a BUFR file back to its beginning.
Definition: cread.c:100
void openwb(f77int *nfile, char *ufile)
This subroutine opens a new system file for writing BUFR messages.
Definition: cread.c:51
Define signatures and declare variables for reading or writing BUFR messages via a C language interfa...
FILE ** pb
File pointers.
function iupbs01(MBAY, S01MNEM)
This function returns a specified value from within Section 0 or Section 1 of a BUFR message...
Definition: iupbs01.f:73
void openrb(f77int *nfile, char *ufile)
This subroutine opens a new system file for reading BUFR messages.
Definition: cread.c:34