#include #include #include "fifth.h" /* asume grid is a valid grid with its 2D array allocated. set the value of grid.data[i][j] to val*/ void set(Grid * g, int i, int j, float val) { } /* assume grid is a valid grid with data allocated. return the value in the grid at position i,j */ float get(Grid g, int i, int j) { } /* f is a file that has just been opened. read and initialize the header of g from file f */ void readHeader(FILE* f, Grid * g) { char foo[100]; fscanf(f, "%s", foo); fscanf(f, "%d", &(g->ncols)); fscanf(f, "%s", foo); fscanf(f, "%d", &(g->nrows)); fscanf(f, "%s", foo); fscanf(f, "%s", foo); fscanf(f, "%s", foo); fscanf(f, "%s", foo); fscanf(f, "%s", foo); fscanf(f, "%s", foo); fscanf(f, "%s", foo); fscanf(f, "%s", foo); } void printInfo(Grid g) { printf("ncols=%d, nrows=%d\n", g.ncols, g.nrows); } int main (int argc, char** args) { /* printf("argc=%d\n", argc); int i; for (i=0; i < argc; i++) printf("%s\n", args[i]); */ int i, j; if (argc != 3) { printf("usage: %s \n", args[0]); exit(1); } char *elevfname, *flowfname; elevfname= args[1]; flowfname=args[2]; Grid elevgrid; FILE *f; f = fopen(elevfname, "r"); if (f == NULL) { printf("cannot open file %s\n", elevfname); exit(1); } readHeader(f, &elevgrid); //allocate the elevgrid data elevgrid.data = (float**) malloc(elevgrid.nrows*sizeof(float*)); if (elevgrid.data == NULL) {} for (i=0; i