1 /**************************************************************************
2 * mesh.c -- data structures and routines for processing terrain meshes
4 * Written by Curtis Olson, started May 1997.
7 * (Log is kept at end of this file)
8 **************************************************************************/
13 #include <stdlib.h> /* atof(), atoi() */
20 /* return a pointer to a new mesh structure (no data array allocated yet) */
21 struct mesh *(new_mesh)() {
22 struct mesh *mesh_ptr;
24 mesh_ptr = (struct mesh *)malloc(sizeof(struct mesh));
26 if ( mesh_ptr == 0 ) {
27 printf("Virtual memory exceeded\n");
31 mesh_ptr->cur_row = 0;
32 mesh_ptr->cur_col = 0;
38 /* return a pointer to a dynamically allocated array */
39 float *(new_mesh_data)(int nrows, int ncols) {
42 mesh_data_ptr = (float *)malloc(nrows * ncols * sizeof(float));
44 if ( mesh_data_ptr == 0 ) {
45 printf("Virtual memory exceeded\n");
49 printf("Allocated float(%d, %d)\n", nrows, ncols);
51 return(mesh_data_ptr);
55 /* set the option name in the mesh data structure */
56 void mesh_set_option_name(struct mesh *m, char *name) {
57 if ( strlen(name) < MAX_IDENT_LEN ) {
58 strcpy(m->option_name, name);
60 strncpy(m->option_name, name, MAX_IDENT_LEN - 1);
61 m->option_name[MAX_IDENT_LEN - 1] = '\0';
65 /* set an option value in the mesh data structure */
66 void mesh_set_option_value(struct mesh *m, char *value) {
67 printf("Setting %s to %s\n", m->option_name, value);
69 if ( strcmp(m->option_name, "origin_lat") == 0 ) {
70 m->originx = atof(value);
71 } else if ( strcmp(m->option_name, "origin_lon") == 0 ) {
72 m->originy = atof(value);
73 } else if ( strcmp(m->option_name, "rows") == 0 ) {
74 m->rows = atoi(value);
75 } else if ( strcmp(m->option_name, "cols") == 0 ) {
76 m->cols = atoi(value);
77 } else if ( strcmp(m->option_name, "row_step") == 0 ) {
78 m->row_step = atof(value);
79 } else if ( strcmp(m->option_name, "col_step") == 0 ) {
80 m->col_step = atof(value);
82 printf("Unknown option %s with value %s, ignoring ...\n",
83 m->option_name, value);
89 /* Revision 1.2 1997/05/19 18:20:50 curt
90 /* Slight change to origin key words.
92 * Revision 1.1 1997/05/16 16:07:04 curt