如何自动修正VIC流向

大概800行代码,供各位参考。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flowgen.h"

BOOLEAN Verbose = FALSE;        /* flag for optional verbose */
char FlowChar[] = {' ', '|', '/', '-', '\\', '|', '/', '-', '\\'};
/*char FlowChar[] = {' ', '1', '2', '3', '4', '5', '6', '7', '8'};*/

int main(int argc, char **argv)
{
  BOOLEAN HasFraction = FALSE;  /* flag for whether fraction is provided */
  BOOLEAN HasMask = FALSE;      /* flag for optional mask */
  BOOLEAN HasUserDefOutsideValue = FALSE;
				/* flag whether a user defined value is given
				   to indicate values outside the basin */
  BOOLEAN **MaskMatrix;         /* matrix with mask */
  char AccFilename[BUFSIZE+1];  /* filename for accumulation file */
  char MaskFilename[BUFSIZE+1]; /* filename for mask file */
  char OutFilename[BUFSIZE+1];  /* filename for output file */
  char *EndPtr = NULL;
  FILE *AccFile = NULL;         /* accumulation file */
  FILE *MaskFile = NULL;        /* optional mask file */
  FILE *OutFile = NULL;         /* output  */
  float Fraction;               /* fraction of border through which flow 
                                   exits perpendicular */
  int i;                        /* counter */
  int j;                        /* counter */
  int m;                        /* counter */
  int n;                        /* counter */
  int AccCols;                  /* number of columns in accumulation file */
  int AccRows;                  /* number of rows in accumulation file */
  int CellCols;                 /* number of columns per cell */
  int CellRows;                 /* number of rows per cell */
  int Col;
  int CornerCols;
  int CornerRows;
  int ExtraCols;                /* superfluous columns in accumulation file */
  int ExtraRows;                /* superfluous rows in accumulation file */
  int MiddleCols;
  int MiddleRows;
  int OutCols;                  /* number of columns in output file */
  int OutRows;                  /* number of rows in output file */
  int Row;
  int *FlowDirection;           /* array with flow directions */
  int **FlowMatrix;             /* matrix with flow directions */
  size_t NRead;			/* number of records read */
  long *Border;			/* cells on the border */
  long **AccMatrix;		/* matrix with accumulation totals */
  long **CellMatrix;		/* matrix with accumulation totals for a single 
				   cell */
  long **MaxAccMatrix;		/* matrix with maximum accumulation total */
  long OutletAccumulation;	/* largest accumulation value in 
				   AccMatrix */
  long UserDefOutsideValue;	/* User defined value indicating which values
				   are outside the basin */
  CORNER_INFO Corner[4];
  CORNER_NODE **CornerMatrix;
  
  /****************************************************************************/
  /* read the command-line options                                            */
  /****************************************************************************/
  
  /* Echo the function call to the screen */

  printf("\n\n");
  for (i = 0; i < argc; i++)
    printf("%s ", argv[i]);
  printf("\n\n");

  /* Get command-line options */

  if (argc < 7) {
    fprintf(stderr, "Usage: %s %s\n\n", argv[0], Usage);
    exit(EXIT_FAILURE);
  }

  /* Read information about accumulation file */

  strcpy(AccFilename, *++argv);
  --argc;
  AccRows = (int) strtol(*++argv, &EndPtr, 0);
  --argc;
  if ((EndPtr != NULL && EndPtr[0] != '\0') || AccRows < 0) {
    fprintf(stderr, "%s: Not a valid number of rows\n\n", *argv);
    exit(EXIT_FAILURE);      
  }
  AccCols = (int) strtol(*++argv, &EndPtr, 0);
  --argc;
  if ((EndPtr != NULL && EndPtr[0] != '\0') || AccCols < 0) {
    fprintf(stderr, "%s: Not a valid number of columns\n\n", *argv);
    exit(EXIT_FAILURE);      
  }

  /* Read information about output file */

  strcpy(OutFilename, *++argv);
  --argc;
  CellRows = (int) strtol(*++argv, &EndPtr, 0);
  --argc;
  if ((EndPtr != NULL && EndPtr[0] != '\0') || CellRows < 0) {
    fprintf(stderr, "%s: Not a valid number of rows\n\n", *argv);
    exit(EXIT_FAILURE);      
  }
  if (CellRows < 2) {
    fprintf(stderr, 
            "%s: Number of rows per cell must be at least 2\n",
            *argv);
    exit(EXIT_FAILURE);      
  }

  CellCols = (int) strtol(*++argv, &EndPtr, 0);
  --argc;
  if ((EndPtr != NULL && EndPtr[0] != '\0') || CellCols < 0) {
    fprintf(stderr, "%s: Not a valid number of columns\n\n", *argv);
    exit(EXIT_FAILURE);      
  }
  if (CellCols < 2) {
    fprintf(stderr, 
            "%s: Number of columns per cell must be at least 2\n",
            *argv);
    exit(EXIT_FAILURE);      
  }

  OutRows = AccRows/CellRows;
  ExtraRows = AccRows % CellRows;
  if (ExtraRows != 0) {
    fprintf(stderr, 
            "Warning: The number of output rows is not an integer\n");
    fprintf(stderr,
            "multiple of the number of rows in the accumulation file.\n");
    fprintf(stderr, 
            "The last %d rows in the accumulation file will not be \n", 
            ExtraRows);
    fprintf(stderr, 
            "taken into account\n\n");
    AccRows -= ExtraRows;
  }
  OutCols = AccCols/CellCols;
  ExtraCols = AccCols % CellCols;
  if (ExtraCols != 0) {
    fprintf(stderr, 
            "Warning: The number of output columns is not an integer\n");
    fprintf(stderr,
            "multiple of the number of columns in the accumulation file.\n");
    fprintf(stderr, 
            "The last %d columns in the accumulation file will not be \n", 
            ExtraCols);
    fprintf(stderr, 
            "taken into account\n\n");
    AccCols -= ExtraCols;
  }
    
  /*
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hydromonkey

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值