DHSVM Subdailiy to Daily streamflow

Update 2016/11/30

今天我又重新写了subdaily to monthly的程序,现在放在这里一并和大家分享。

截个图:

DHSVM_stream.rar

DHSVM模型流域出口的河川径流的格式(3小时为例):

现在要将Subdaily的streamflow转化为daily,我写了一个C的程序来实现,先贴结果.

源代码如下:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define MaxLine 1024

int main(int argc, char *argv[])

{

FILE *InputFid, *OutputFid;

int TempStrComp, CountForDay;

long offset;

char strline01[MaxLine];

char StartLine[MaxLine];

double TempDischarge, ReadDischarge, MeanDailyDischarge;

char StrDate01[11],TempStrDate[11];

const char  *input_name = “Streamflow.Only”;

const char  *Output_name = “Streamflow_daily.Only”;

char *TempStrDischarge;

if ((InputFid=fopen(input_name,”r”))==NULL){

printf(“Open %s Failed”, input_name);

return;

}

if ((OutputFid=fopen(Output_name,”w+”))==NULL){

printf(“Open %s Failed”, Output_name);

return;

}

/* Write header, DATE OUTLET */

fgets(strline01,MaxLine,InputFid);

fprintf(OutputFid,”%s  %s\n”, “DATE”, “Discharge(m^3/timestep)”);

/* Provide StartLine */

fgets(strline01,MaxLine,InputFid);

strncpy(TempStrDate, strline01, 10);

TempStrDate[10]=’\0′; /* it is important */

/* No value in the second line */

TempDischarge=0.0;

CountForDay=0;

while (!feof(InputFid))

{

/* read lines sequentially */

fgets(strline01,MaxLine,InputFid);

/* get the Date */

strncpy(StrDate01, strline01,10);

StrDate01[10]=’\0′;

if (strcmp(TempStrDate,StrDate01)==0)

{

/* find the location of two spaces */

TempStrDischarge=strchr(strline01,’  ‘);

/* convert float to double */

ReadDischarge=strtod(TempStrDischarge, NULL);

TempDischarge += ReadDischarge;

CountForDay += 1;

}

else

{

MeanDailyDischarge = TempDischarge/CountForDay;

fprintf(OutputFid,”%s  %.4f\n”,TempStrDate, MeanDailyDischarge);

/*——— initiate in new day—————- */

/* find the location of two spaces */

TempStrDischarge=strchr(strline01,’  ‘);

/* convert float to double */

ReadDischarge=strtod(TempStrDischarge, NULL);

strncpy(TempStrDate, strline01, 10);

TempDischarge=ReadDischarge;

CountForDay=1;

}

/* Initiate each line at each step */

strcpy(strline01,” “);

}

fclose(InputFid);

fclose(OutputFid);

return 0;

}

 

Updated: 2016-11-30 — pm8:49

Leave a Reply

  Subscribe  
Notify of