5#include <polarvolume.h>
8#include <fmi_radar_image.h>
13is_hdf_file(
char *filename)
17 fp = fopen(filename,
"r");
20 fread(header,
sizeof(
char), 4, fp);
25 return (strcmp(header+1,
"HDF") == 0);
33read_scan(RaveCoreObject *rave_pvol,
FmiImage *pscan,
int index)
35 RaveCoreObject *rave_scan;
38 rave_scan=(RaveCoreObject *)PolarVolume_getScan((PolarVolume_t *)rave_pvol, index);
40 pscan->width=PolarScan_getNbins((PolarScan_t *)rave_scan);
41 pscan->height=PolarScan_getNrays((PolarScan_t *)rave_scan);
42 pscan->bin_depth=PolarScan_getRscale((PolarScan_t *)rave_scan);
43 pscan->elevation_angle=PolarScan_getElangle((PolarScan_t *)rave_scan);
46 initialize_image(pscan);
49 for (j=0;j<pscan->height;j++)
50 for (i=0;i<pscan->width;i++)
52 PolarScan_getValue((PolarScan_t *)rave_scan, i, j, &value);
53 put_pixel(pscan, i, j, 0, (Byte)(value+0.5));
62rave2ropo(PolarVolume_t *rave_pvol,
FmiImage **pvol)
66 sweep_count=PolarVolume_getNumberOfScans(rave_pvol);
67 PolarVolume_sortByElevations(rave_pvol, 1);
70 for (i=0;i<sweep_count;i++)
72 read_scan((RaveCoreObject *)rave_pvol,¤t_pvol[1+i],i);
82PolarVolume_t * read_h5_radar_data(
char *pvol_file,
FmiImage **target){
83 PolarVolume_t *result = (PolarVolume_t *)RaveIO_getObject(RaveIO_open(pvol_file, 0, NULL));
84 rave2ropo(result, target);
89PolarScan_t * create_scan(
FmiImage *input,
int index){
90 PolarScan_t* result = NULL;
91 PolarScan_t* scan = NULL;
92 PolarScanParam_t* parameter = NULL;
95 FmiImage *current_input = &input[index + 1];
96 scan = RAVE_OBJECT_NEW(&PolarScan_TYPE);
101 parameter = RAVE_OBJECT_NEW(&PolarScanParam_TYPE);
102 if (parameter == NULL) {
105 PolarScan_setElangle(scan, fmi_radar_sweep_angles[index]);
106 PolarScan_setRscale(scan, input->bin_depth);
107 PolarScan_setRstart(scan, 0.0);
109 if (!PolarScanParam_createData(parameter,
110 current_input->width,
111 current_input->height,
112 RaveDataType_UCHAR)) {
116 PolarScan_addParameter(scan, parameter);
118 for (ray = 0; ray < current_input->height; ray++) {
119 for (bin = 0; bin < current_input->width; bin++) {
120 PolarScan_setValue(scan, bin, ray, get_pixel(current_input, bin, ray, 0));
123 result = RAVE_OBJECT_COPY(scan);
125 RAVE_OBJECT_RELEASE(parameter);
126 RAVE_OBJECT_RELEASE(scan);
131fill_scan(
FmiImage *input, PolarVolume_t *output,
int index)
133 PolarScan_t *scan = PolarVolume_getScan(output, index);
135 FmiImage *current_input = &input[index + 1];
137 PolarScan_setElangle(scan, fmi_radar_sweep_angles[index]/180.0 * M_PI);
138 PolarScan_setRscale(scan, input->bin_depth);
139 PolarScan_setRstart(scan, 0.0);
140 for (ray = 0; ray < current_input->height; ray++)
142 for (bin = 0; bin < current_input->width; bin++)
144 PolarScan_setValue(scan, bin, ray, get_pixel(current_input, bin, ray, 0));
153ropo2rave(
FmiImage *input, PolarVolume_t *output)
157 PolarVolume_sortByElevations(output, 1);
159 for(i=0; i < input->sweep_count; i++) {
160 fill_scan(input, output, i);
169write_h5_radar_data(
FmiImage *pvol,
char *pvol_file, PolarVolume_t *
template)
171 RaveIO_t * raveio = NULL;
172 raveio = RAVE_OBJECT_NEW(&RaveIO_TYPE);
174 assert(raveio != NULL);
175 ropo2rave(pvol,
template);
176 RaveIO_setObject(raveio, (RaveCoreObject*)
template);
177 RaveIO_save(raveio, pvol_file);