NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
arallocc.c
Go to the documentation of this file.
1 
5 #include "bufrlib.h"
6 #define IN_ARALLOCC
7 #include "cread.h"
8 #include "mstabs.h"
9 
34 void arallocc( void )
35 {
36 
37 #ifdef DYNAMIC_ALLOCATION
38 
39  char brtstr[50] = "BUFRLIB: ARALLOCC FAILED ALLOCATING ";
40 
41  f77int nfiles;
42 
43  f77int mxmtbb;
44  f77int mxmtbd;
45  f77int maxcd;
46 
47 /*
48 ** cread arrays
49 */
50 
51  nfiles = igetprm( "NFILES", 6 );
52 
53  if ( ( pb = malloc( (nfiles+1) * sizeof(FILE *) ) ) == NULL ) {
54  strcat( brtstr, "PB" );
55  bort( brtstr, ( f77int ) strlen( brtstr ) );
56  }
57 
58  if ( ( lstpos = malloc( (nfiles+1) * sizeof(fpos_t) ) ) == NULL ) {
59  strcat( brtstr, "LSTPOS" );
60  bort( brtstr, ( f77int ) strlen( brtstr ) );
61  }
62 
63 /*
64 ** mstabs arrays
65 */
66 
67  mxmtbb = igetprm( "MXMTBB", 6 );
68  mxmtbd = igetprm( "MXMTBD", 6 );
69  maxcd = igetprm( "MAXCD", 5 );
70 
71  if ( ( MSTABS_BASE(ibfxyn) = malloc( mxmtbb * sizeof(f77int) ) ) == NULL ) {
72  strcat( brtstr, "IBFXYN" );
73  bort( brtstr, ( f77int ) strlen( brtstr ) );
74  }
75 
76  if ( ( MSTABS_BASE(cbscl) = malloc( mxmtbb * 4 * sizeof(char) ) ) == NULL ) {
77  strcat( brtstr, "CBSCL" );
78  bort( brtstr, ( f77int ) strlen( brtstr ) );
79  }
80 
81  if ( ( MSTABS_BASE(cbsref) = malloc( mxmtbb * 12 * sizeof(char) ) ) == NULL ) {
82  strcat( brtstr, "CBSREF" );
83  bort( brtstr, ( f77int ) strlen( brtstr ) );
84  }
85 
86  if ( ( MSTABS_BASE(cbbw) = malloc( mxmtbb * 4 * sizeof(char) ) ) == NULL ) {
87  strcat( brtstr, "CBBW" );
88  bort( brtstr, ( f77int ) strlen( brtstr ) );
89  }
90 
91  if ( ( MSTABS_BASE(cbunit) = malloc( mxmtbb * 14 * sizeof(char) ) ) == NULL ) {
92  strcat( brtstr, "CBUNIT" );
93  bort( brtstr, ( f77int ) strlen( brtstr ) );
94  }
95 
96  if ( ( MSTABS_BASE(cbmnem) = malloc( mxmtbb * 8 * sizeof(char) ) ) == NULL ) {
97  strcat( brtstr, "CBMNEM" );
98  bort( brtstr, ( f77int ) strlen( brtstr ) );
99  }
100 
101  if ( ( MSTABS_BASE(cbelem) = malloc( mxmtbb * 120 * sizeof(char) ) ) == NULL ) {
102  strcat( brtstr, "CBELEM" );
103  bort( brtstr, ( f77int ) strlen( brtstr ) );
104  }
105 
106  if ( ( MSTABS_BASE(idfxyn) = malloc( mxmtbd * sizeof(f77int) ) ) == NULL ) {
107  strcat( brtstr, "IDFXYN" );
108  bort( brtstr, ( f77int ) strlen( brtstr ) );
109  }
110 
111  if ( ( MSTABS_BASE(cdseq) = malloc( mxmtbd * 120 * sizeof(char) ) ) == NULL ) {
112  strcat( brtstr, "CDSEQ" );
113  bort( brtstr, ( f77int ) strlen( brtstr ) );
114  }
115 
116  if ( ( MSTABS_BASE(cdmnem) = malloc( mxmtbd * 8 * sizeof(char) ) ) == NULL ) {
117  strcat( brtstr, "CDMNEM" );
118  bort( brtstr, ( f77int ) strlen( brtstr ) );
119  }
120 
121  if ( ( MSTABS_BASE(ndelem) = malloc( mxmtbd * sizeof(f77int) ) ) == NULL ) {
122  strcat( brtstr, "NDELEM" );
123  bort( brtstr, ( f77int ) strlen( brtstr ) );
124  }
125 
126  if ( ( MSTABS_BASE(idefxy) = malloc( mxmtbd * maxcd * sizeof(f77int) ) ) == NULL ) {
127  strcat( brtstr, "IDEFXY" );
128  bort( brtstr, ( f77int ) strlen( brtstr ) );
129  }
130 
131 #endif
132 
133 }
Define signatures to enable a number of BUFRLIB subprograms to be called directly from C application ...
void arallocc(void)
For dynamic allocation builds of the library, this subroutine is called internally during the first c...
Definition: arallocc.c:34
INTEGER function igetprm(CPRMNM)
This function returns the current value of a parameter used for allocating one or more internal array...
Definition: igetprm.f:81
FILE * pb[NFILES+1]
File pointers.
Definition: cread.h:58
fpos_t lstpos[NFILES+1]
Byte positions of last successful reads from files corresponding to pb, for files that were opened fo...
Definition: cread.h:59
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
Define signatures and declare variables for reading or writing BUFR messages via a C language interfa...
Define signatures and declare variables for internal storage of master Table B and Table D entries...