-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmwdtrc.c
134 lines (123 loc) · 6.47 KB
/
dmwdtrc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "geminc.h"
#include "gemprm.h"
static int *_ksGrid;
/************************************************************************
* dm_wdtrc *
* *
* This module contains two functions in support of the DM library *
* function DM_WDTR. It is written in 'C' to allow dynamic allocation *
* of a temporary buffer. *
* The first function, dm_pkgdc, packs the data into an integer array *
* (the temp buffer). The buffer, local global variable '_ksGrid', is *
* allocated in this function. *
* The second function, dm_wpkgc, writes the data to the file. The *
* buffer, local global variable '_ksGrid', is freed at the end of this *
* function. *
************************************************************************/
void dm_pkgdc_ ( float *rdata, int *nword, int *kword, int *ipktyp,
int *nbits, int *misflg, int *kxky, int *kx,
float *ref, float *scale, float *difmin, int *iret )
/************************************************************************
* dm_pkgdc *
* *
* This is a subfunction to the DM library function DM_WDTR. *
* It packs the data into an integer array stored locally until it *
* is written by the sister routine 'dm_wpkgc'. *
* This functionality has been isolated and written in 'C' *
* to allow for the dynamic allocation of buffer memory. *
* *
* dm_pkgdc ( rdata, kword, ipktyp, nbits, misflg, kxky, kx, *
* ref, scale, difmin, iret ) *
* *
* Input parameters: *
* *rdata float Grid data *
* *nword int Number of words of gridded data *
* *
* Output parameters: *
* *kword int Number of words to write *
* *ipktyp int Packing type *
* *nbits int Number of bits *
* *miss int Missing data flag *
* *kxky int Number of grid points *
* *kx int Number of points in x direction *
* *ref float Reference minimum value of grid *
* *scale float Scaling factor *
* *difmin float Minimum value of differences *
* *iret int Return code *
* = 0 - normal *
* = -31 - unknown packing type *
* = -35 - problems w/ mem alloc *
** *
* Log: *
* D.W.Plummer/NCEP 9/06 Created *
************************************************************************/
{
/*---------------------------------------------------------------------*/
*iret = 0;
if ( _ksGrid == (int *)NULL ) {
G_MALLOC ( _ksGrid, int, *nword,
"Error allocating _ksGrid in dm_wdtrc" );
}
else {
G_REALLOC ( _ksGrid, int, *nword,
"Error re-allocating _ksGrid in dm_wdtrc" );
}
if ( _ksGrid == (int *)NULL ) {
*iret = -35;
}
else {
dm_pkgd_ ( rdata, _ksGrid, kword, ipktyp, nbits, misflg, kxky,
kx, ref, scale, difmin, iret );
}
}
void dm_wpkgc_ ( int *iflno, float *rdata, int *isword, int *kword,
int *ipktyp, int *nbits, int *misflg, int *kxky, int *kx,
float *ref, float *scale, float *difmin, int *iret )
/************************************************************************
* dm_wpkgc *
* *
* This is a subfunction to the DM library function DM_WDTR. *
* It writes the packed grid stored locally in the variable '_ksGrid' *
* by sister routine 'dm_pkgdc'. *
* This functionality has been isolated and written in 'C' *
* to allow for the dynamic allocation of buffer memory. *
* *
* dm_wpkgc ( iflno, rdata, isword, kword, ipktyp, nbits, misflg, kxky, *
* kx, ref, scale, difmin, iret ) *
* *
* *
* Input parameters: *
* *iflno int File number (from FORTRAN) *
* *rdata float Grid data *
* *isword int Starting word *
* *kword int Number of words to write *
* *ipktyp int Packing type *
* *nbits int Number of bits *
* *miss int Missing data flag *
* *kxky int Number of grid points *
* *kx int Number of points in x direction *
* *ref float Reference minimum value of grid *
* *scale float Scaling factor *
* *difmin float Minimum value of differences *
* *
* Output parameters: *
* *iret int Return code *
* = 0 - normal *
* = -31 - unknown packing type *
* = -35 - problems w/ mem alloc *
** *
* Log: *
* D.W.Plummer/NCEP 9/06 Created *
************************************************************************/
{
/*---------------------------------------------------------------------*/
*iret = 0;
if ( _ksGrid == (int *)NULL ) {
*iret = -35;
}
else {
dm_wpkg_ ( iflno, rdata, _ksGrid, isword, kword, ipktyp, nbits,
misflg, kxky, kx, ref, scale, difmin, iret );
G_FREE ( _ksGrid, int );
}
}