标准化降水指数(SPI)计算程序

本文介绍如何根据洪兴骏等人的研究,用C++实现标准化降水指数(SPI)计算。代码中涉及积分和gamma函数的实现,通过输入每年降水量调用getSPI(int year)函数获取SPI值。程序假设输入数据合理,不合理数据可能导致意外结果。
摘要由CSDN通过智能技术生成

之前遇到的一个客户需求就是计算标准化降水指数(SPI)。

主要参考的论文为:洪兴骏,等 “标准化降水指数SPI分布函数的适用性研究”。原文可以很容易搜索到。

论文将计算方法其实写的比较清楚了,本文主要提供其C++实现。


头文件

//SPI_Calculator.h
#include<iostream>
#include<vector>
#include<utility>
#include<fstream>
#include<cmath>


using namespace std;

#ifndef SPICALCULATOR_H
#define SPICALCULATOR_H



class SPI_Calculator{
public:
	/**
	path is the file that provides the data of rain fall
	file format:
	year	amount of precipitation
	year	amount of precipitation
	.
	.
	.
	*/
	SPI_Calculator(char* path);

	/**
	parameter is the year to get the SPI
	return SPI
	*/
	double getSPI(int year);

	double f_probabilityDensity(double x);
	double f_gamma(double z, unsigned Ntermsx);
	double integral(double a,double b);

	void printYears();
	void printSPI();

	void test();

private:

	bool readData(char* path);
	void calculateParameter();
	
	vect
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值