/* This example shows the expected result when grid data contains a wrong parameter */ #include #include #include #include #include int main(int argc, char **argv) { int32 gridfile1; int32 grid1; int32 grid1_xdim; int32 grid1_ydim; float64 grid1_upleft[2]; float64 grid1_lowright[2]; int32 grid1_projcode; int32 grid1_zone; int32 grid1_sphere; float64 grid1_params[16]; int32 grid1_pixreg; int32 grid1_origin; int32 *grid1_row; int32 *grid1_col; float64 *grid1_lon; float64 *grid1_lat; int32 i, j, k; /* Open 'MISR_AM1_CGAS_MAR_01_2006_SITE_INTEXB_F06_0021.hdf' using grid API */ if ((gridfile1 = GDopen("MISR_AM1_CGAS_MAR_01_2006_SITE_INTEXB_F06_0021.hdf", DFACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open grid 'MISR_AM1_CGAS_MAR_01_2006_SITE_INTEXB_F06_0021.hdf'\n"); return -1; } /* Open a grid named 'AerosolParameterAverage' */ if ((grid1 = GDattach(gridfile1, "AerosolParameterAverage")) == -1) { fprintf(stderr, "error: cannot attach to 'AerosolParameterAverage'\n"); return -1; } /* Retrieve dimensions and X-Y coordinates of corners from 'AerosolParameterAverage' */ if ((GDgridinfo(grid1, &grid1_xdim, &grid1_ydim, grid1_upleft, grid1_lowright)) == -1) { fprintf(stderr, "error: cannot get grid information from 'AerosolParameterAverage'\n"); return -1; } /* Retrieve all GCTP projection information from 'AerosolParameterAverage' */ if ((GDprojinfo(grid1, &grid1_projcode, &grid1_zone, &grid1_sphere, grid1_params)) == -1) { fprintf(stderr, "error: cannot get projection information from 'AerosolParameterAverage'\n"); return -1; } /* Retrieve pixel registration information from 'AerosolParameterAverage' */ if ((GDpixreginfo(grid1, &grid1_pixreg)) == -1) { fprintf(stderr, "error: cannot get pixel registration information from 'AerosolParameterAverage'\n"); return -1; } /* Retrieve grid pixel origin from 'AerosolParameterAverage' */ if ((GDorigininfo(grid1, &grid1_origin)) == -1) { fprintf(stderr, "error: cannot get pixel origin information from 'AerosolParameterAverage'\n"); return -1; } /* GDij2ll() will fail because there is a wrong parameter in grid data. */ /* Allocate buffer for row */ if ((grid1_row = malloc(sizeof(int32) * grid1_xdim * grid1_ydim)) == NULL) { fprintf(stderr, "error: cannot allocate memory for row\n"); return -1; } /* Allocate buffer for column */ if ((grid1_col = malloc(sizeof(int32) * grid1_xdim * grid1_ydim)) == NULL) { fprintf(stderr, "error: cannot allocate memory for column\n"); return -1; } /* Fill two arguments, rows and columns */ for (k = j = 0; j < grid1_xdim; ++j) { for (i = 0; i < grid1_ydim; ++i) { grid1_row[k] = i; grid1_col[k] = j; ++k; } } /* Allocate buffer for longitude */ if ((grid1_lon = malloc(sizeof(float64) * grid1_xdim * grid1_ydim)) == NULL) { fprintf(stderr, "error: cannot allocate memory for longitude\n"); return -1; } /* Allocate buffer for latitude */ if ((grid1_lat = malloc(sizeof(float64) * grid1_xdim * grid1_ydim)) == NULL) { fprintf(stderr, "error: cannot allocate memory for latitude\n"); return -1; } /* Retrieve lon/lat values for 'AerosolParameterAverage' */ if ((GDij2ll(grid1_projcode, grid1_zone, grid1_params, grid1_sphere, grid1_xdim, grid1_ydim, grid1_upleft, grid1_lowright, grid1_xdim * grid1_ydim, grid1_row, grid1_col, grid1_lon, grid1_lat, grid1_pixreg, grid1_origin)) == -1) { fprintf(stderr, "error: cannot retrieve lon/lat values for 'AerosolParameterAverage'\n"); return -1; } /* Release buffer for row */ free(grid1_row); /* Release buffer for column */ free(grid1_col); /* Release buffer for longitude */ free(grid1_lon); /* Release buffer for latitude */ free(grid1_lat); /* Close the grid named 'AerosolParameterAverage' */ if ((GDdetach(grid1)) == -1) { fprintf(stderr, "error: cannot detach from 'AerosolParameterAverage'\n"); return -1; } /* Close 'MISR_AM1_CGAS_MAR_01_2006_SITE_INTEXB_F06_0021.hdf' */ if ((GDclose(gridfile1)) == -1) { fprintf(stderr, "error: cannot close grid 'MISR_AM1_CGAS_MAR_01_2006_SITE_INTEXB_F06_0021.hdf'\n"); return -1; } return 0; }