⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 natgrid_linear.c

📁 C语言编写的
💻 C
字号:
#include <stdio.h>/* Function prototype for c_natgrids */extern float *c_natgrids(int, float [], float [], float [],                          int, int, float [], float [], int *);/* Specify number of input data points and the size of the output grid */#define NUMIN   80732 #define NUMXOUT 600#define NUMYOUT 200/* Specify the range of the input, or type NULL to have the program calculate it */#define XMAX 167  #define XMIN 161 #define YMAX 74#define YMIN 72main(int argc, char *argv[]){  FILE *in;  int i, j, k, ier, count=0, nitems, temp;  float *out, xo[NUMXOUT], yo[NUMYOUT], xc, yc;  float x[NUMIN], y[NUMIN], z[NUMIN];  float x_max, x_min, y_max, y_min;  /* Check if the file argument is present */  if (!argv[1]) {     printf( "\nNo input file specified\n" );     exit(0);  }  /* Check if the file exists */  in=fopen(argv[1],"r");  if (in == NULL) {      printf( "\nUnable to open file\n" );      exit(0);  }     /* Read in longitude, latitude, and elevation from file */  while(1)  {    nitems = fscanf(in, "%f\t%f\t%f\n", &x[count], &y[count], &z[count]);    if (nitems == EOF)      break;    count++;  }    /* Find the x and y range of input */  if ((XMAX == NULL) || (XMIN == NULL) || (YMAX == NULL) || (YMIN == NULL)) {    x_max = x[0];    x_min = x[0];    y_max = y[0];    y_min = y[0];    for (temp=0; temp < count; temp++)  {      if (x[temp] > x_max) { x_max = x[temp]; }      if (x[temp] < x_min) { x_min = x[temp]; }      if (y[temp] > y_max) { y_max = y[temp]; }      if (y[temp] < y_min) { y_min = y[temp]; }    }  }  if (XMAX != NULL) { x_max = XMAX; }  if (XMIN != NULL) { x_min = XMIN; }  if (YMAX != NULL) { y_max = YMAX; }  if (YMIN != NULL) { y_min = YMIN; }   /* Calculate the x coordinates of the output grid */  xc = (x_max-x_min)/(NUMXOUT-1);    for (i = 0 ; i < NUMXOUT ; i++) {    xo[i] = i * xc + x_min;  }  /* Calculate the y coordinates of the output grid */  yc = (y_max-y_min)/(NUMYOUT-1);   for (j = 0 ; j < NUMYOUT ; j++) {    yo[j] = j * yc + y_min;  }    /* Run the natural neighbor function */  out = c_natgrids(NUMIN, x, y, z, NUMXOUT, NUMYOUT, xo, yo, &ier);   /* Check if any errors were encountered by c_natgrids */   if (ier != 0) {     printf (" Error return from c_natgrids = %d\n",ier);  }    /* Output the results */   for (k = 0; k < NUMXOUT*NUMYOUT; k++) {     printf ("%f\n", out[k]);   }     fclose(in); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -