3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996, 1997
6 Space Applications Corporation
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this library; if not, write to the Free
21 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifdef HAVE_LIBTSDISTK
27 /******************************************************************
29 Memory management functions used for the dynamic allocation/
30 deallocation of TSDIS Toolkit GV_Level_1 structures, created when
31 reading/writing to an HDF file.
33 Functions herein are called by RSL_radar_to_hdf() and RSL_hdf_to_radar().
35 *******************************************************************/
37 /* TSDIS toolkit function and structure definitions. */
41 /* ------ Functions defined in this file. ------- */
43 void TKfreeGVL1(L1B_1C_GV *gvl1);
44 int8 ***TKnewParmData1byte(int nsweep, int nray, int ncell);
45 int16 ***TKnewParmData2byte(int nsweep, int nray, int ncell);
46 PARAMETER *TKnewGVL1parm(void);
47 L1B_1C_GV *TKnewGVL1(void);
50 /*************************************************************/
54 /*************************************************************/
55 void TKfreeGVL1(L1B_1C_GV *gvl1)
57 /* Frees all memory which was (dynamically) allocated to the toolkit
58 'L1B_1C_GV' structure, and associated substructures.
62 for (pindex=0; pindex<MAX_PARM; pindex++)
64 if (gvl1->sensor.parm[pindex] != NULL)
66 if (gvl1->sensor.parm[pindex]->parmData1byte != NULL)
68 free(gvl1->sensor.parm[pindex]->parmData1byte[0][0]);
69 free(gvl1->sensor.parm[pindex]->parmData1byte[0]);
70 free(gvl1->sensor.parm[pindex]->parmData1byte);
71 } /* end if (gvl1->sensor.parm[pindex]->parmData1byte != NULL) */
72 else if (gvl1->sensor.parm[pindex]->parmData2byte != NULL)
74 free(gvl1->sensor.parm[pindex]->parmData2byte[0][0]);
75 free(gvl1->sensor.parm[pindex]->parmData2byte[0]);
76 free(gvl1->sensor.parm[pindex]->parmData2byte);
77 } /* end if (gvl1->sensor.parm[pindex]->parmData1byte != NULL) */
78 free(gvl1->sensor.parm[pindex]);
79 } /* end if (gvl1->sensor.parm[pindex] != NULL)*/
80 } /* end for (pindex=0;*/
85 /*************************************************************/
87 /* TKnewParmData1byte */
89 /*************************************************************/
90 int8 ***TKnewParmData1byte(int nsweep, int nray, int ncell)
92 /* Allocates memory for indexed storage of a 3_dimensional array
93 of 1_byte mask values associated with one parameter of the
94 toolkit 'L1B_1C_GV' structure.
96 int8 ***parmData1byte;
101 /* Vector for 'nsweep' sweep pointers. */
102 parmData1byte = (int8 ***)calloc(nsweep, sizeof(int8 **));
103 /* 2D array for 'nsweep*nray' ray pointers. */
104 ray = (int8 **)calloc(nsweep*nray, sizeof(int8 *));
105 /* 3D array for data. */
106 data = (int8 *)calloc(nsweep*nray*ncell, sizeof(int8));
108 /* Fill all the sweep and ray pointer slots created above. */
109 for (sindex=0; sindex<nsweep; sindex++)
111 parmData1byte[sindex] = (int8 **)(ray + sindex*nray);
112 for (rindex=0; rindex<nray; rindex++)
113 parmData1byte[sindex][rindex] = (int8 *)(data + sindex*nray*ncell +
117 return(parmData1byte);
120 /*************************************************************/
122 /* TKnewParmData2byte */
124 /*************************************************************/
125 int16 ***TKnewParmData2byte(int nsweep, int nray, int ncell)
127 /* Allocates memory for storage of a 3_dimensional array of 2_byte
128 data values associated with one parameter of the toolkit
129 'L1B_1C_GV' structure.
131 int16 ***parmData2byte;
136 /* Vector for 'nsweep' sweep pointers. */
137 parmData2byte = (int16 ***)calloc(nsweep, sizeof(int16 **));
138 /* 2D array for 'nsweep*nray' ray pointers. */
139 ray = (int16 **)calloc(nsweep*nray, sizeof(int16 *));
140 /* 3D array for data. */
141 data = (int16 *)calloc(nsweep*nray*ncell, sizeof(int16));
143 /* Fill all the sweep and ray pointer slots created above. */
144 for (sindex=0; sindex<nsweep; sindex++)
146 parmData2byte[sindex] = (int16 **)(ray + sindex*nray);
147 for (rindex=0; rindex<nray; rindex++)
148 parmData2byte[sindex][rindex] = (int16 *)(data + sindex*nray*ncell +
152 return(parmData2byte);
155 /*************************************************************/
159 /*************************************************************/
160 PARAMETER *TKnewGVL1parm(void)
162 /* Allocates memory for a 'PARAMETER' structure. */
165 parm = (PARAMETER *)calloc(1, sizeof(PARAMETER));
166 parm->parmData1byte = (int8 ***)NULL;
167 parm->parmData2byte = (int16 ***)NULL;
171 /*************************************************************/
175 /*************************************************************/
176 L1B_1C_GV *TKnewGVL1(void)
178 /* Allocates memory for a 'L1B_1C_GV' structure. */
182 gvl1 = (L1B_1C_GV *)calloc(1, sizeof(L1B_1C_GV));
183 for (pindex=0; pindex<MAX_PARM; pindex++)
184 gvl1->sensor.parm[pindex] = (PARAMETER *)NULL;