📄 unit1.cpp
字号:
int mm;
// return;
if(Column<=0||Row<=0) return;
if (SaveDialog1->Execute())
{
if (FileExists(SaveDialog1->FileName))
{
fnsplit(SaveDialog1->FileName.c_str(), 0, 0, szFileName, 0);
strcat(szFileName, ".BAK");
RenameFile(SaveDialog1->FileName, szFileName);
}
WFileHandle = FileCreate(SaveDialog1->FileName);
/* sprintf(MYMSG,"Year Month Date Hour TIMESTAMP RECORD WDir Fc_irga LE_irga Hs tau u_star cv_Uz_Uz_1 cv_Uz_Ux_1 cv_Uz_Uy_1 cv_Uz_co2_1 cv_Uz_h2o_1 cv_Uz_Ts_1 cv_Ux_Ux_1 cv_Ux_Uy_1 cv_Ux_co2_1 cv_Ux_h2o_1 cv_Ux_Ts_1 cv_Uy_Uy_1 cv_Uy_co2_1 cv_Uy_h2o_1 cv_Uy_Ts_1 cv_co2_co2_1 cv_h2o_h2o_1 cv_Ts_Ts_1 Ux_1_Avg Uy_1_Avg Uz_1_Avg co2_1_Avg h2o_1_Avg Ts_1_Avg press_1_Avg tc_ref_Avg wnd_dir_comp_1 wnd_dir_csat3_1 wnd_spd_1 rslt_wnd_spd_1 batt_volt_Avg std_wnd_dir_1 NetRad%c%c",CH1,CH2);
FileWrite(WFileHandle, MYMSG, strlen(MYMSG));
sprintf(MYMSG,"Year Month Date Hour TS RN Degree mg/(m^2 s) W/m^2 W/m^2 kg m/s^2 m/s (m/s)^2 (m/s)^2 (m/s)^2 mg/(m^2 s) g/(m^2 s) m C/s (m/s)^2 (m/s)^2 mg/(m^2 s) g/(m^2 s) m C/s (m/s)^2 mg/(m^2 s) g/(m^2 s) m C/s (mg/m^3)^2 (g/m^3)^2 C^2 m/s m/s m/s mg/(m^3) g/(m^3) C kPa C degrees_1 degrees m/s m/s V degrees W/m^2%c%c",CH1,CH2);
FileWrite(WFileHandle, MYMSG, strlen(MYMSG));
// sprintf(MYMSG,"Year Month Date Hour minute Record Record Fc_irga LE_irga Hs tau u_star cv_Uz_Uz_1 cv_Uz_Ux_1 cv_Uz_Uy_1 cv_Uz_co2_1 cv_Uz_h2o_1 cv_Uz_Ts_1 cv_Ux_Ux_1 cv_Ux_Uy_1 cv_Ux_co2_1 cv_Ux_h2o_1 cv_Ux_Ts_1 cv_Uy_Uy_1 cv_Uy_co2_1 cv_Uy_h2o_1 cv_Uy_Ts_1 cv_co2_co2_1 cv_h2o_h2o_1 cv_Ts_Ts_1 Ux_1_Avg Uy_1_Avg Uz_1_Avg co2_1_Avg h2o_1_Avg Ts_1_Avg press_1_Avg tc_ref_Avg wnd_dir_comp_1 wnd_dir_csat3_1 wnd_spd_1 rslt_wnd_spd_1 batt_volt_Avg std_wnd_dir_1 n_Tot csat_warning_Tot irga_warning_Tot del_T_f_1_Tot track_f_1_Tot amp_h_f_1_Tot amp_l_f_1_Tot chopper_f_1_Tot detector_f_1_Tot pll_f_1_Tot sync_f_1_Tot agc_1_Avg%c%c",CH1,CH2);
// FileWrite(WFileHandle, MYMSG, strlen(MYMSG));
*/
sprintf(MYMSG,"Hour Hs LE CO2%c%c",CH1,CH2);
FileWrite(WFileHandle, MYMSG, strlen(MYMSG));
for(ii=0;ii<24;ii++)
{
sprintf(MYMSG,"%g", ii*1.0);
sprintf(tempMSG," %g",DiurnalAvg_T[ii]); //
strcat(MYMSG,tempMSG);
sprintf(tempMSG," %g",DiurnalAvg_H[ii]); //
strcat(MYMSG,tempMSG);
sprintf(tempMSG," %g",DiurnalAvg_C[ii]); //
strcat(MYMSG,tempMSG);
sprintf(tempMSG,"%c%c",CH1,CH2);
strcat(MYMSG,tempMSG);
FileWrite(WFileHandle, MYMSG, strlen(MYMSG));
}
Label5->Caption="Results have been saved into file: "+SaveDialog1->FileName;
// sprintf(MYMSG,"\nnum=%d,m=%d,var=%g,s=%g\n",Row,m,var,s*fa/m);
Label6->Caption=MYMSG;
FileClose(WFileHandle);
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int __fastcall TForm1::CharToDouble (char string[],double data[],unsigned int nn)
{
unsigned int ii,jj,dd,mm; //ii for index of character which can be transfered by AnsiString.ToDouble(),dd for index of data array
char MYMSG[255],TMSG[200]; //TMSG is the character hich can be transfered by AnsiString.ToDouble()
unsigned int EndRD; //when EndRD=1, the current datum has been read over because meeting undatum character.
int FlagE,FlagD; //for e(or E) and Dot respectively
dd=0;
FlagE=0; FlagD=0; EndRD=0;ii=0; //
ii=0;TMSG[0]='0';
for(jj=0;jj<strlen(string);jj++)
{
if(string[jj]=='-'||string[jj]=='+'||string[jj]=='.'||string[jj]=='e'||string[jj]=='E'||(string[jj]<=57&&string[jj]>=48))
{
switch(string[jj])
{
case '+':
case '-':
if(ii==0) {TMSG[ii]=string[jj]; ii++; } //+- only presents at the first
else
if(TMSG[ii-1]=='e'||TMSG[ii-1]=='E') //similar 1e+4
{TMSG[ii]=string[jj]; ii++; }
else EndRD=1;
break;
case '.':
if(FlagE==1||FlagD==1){EndRD=1;break; }
TMSG[ii]=string[jj];
ii++;
FlagD=1;
break;
case 'e':
case 'E':
if(FlagE==1){EndRD=1;break; }
if((TMSG[ii-1]<=57&&TMSG[ii-1]>=48)||TMSG[ii-1]=='.')
{TMSG[ii]=string[jj];ii++; FlagE=1;}
else EndRD=1;
break;
default:
TMSG[ii]=string[jj];
ii++;
break;
}
}
else
{
EndRD=1;
FlagE=0; FlagD=0;
}
if(EndRD==1)
{
if(ii>0)
{
TMSG[ii]='\0';
if(!(strlen(TMSG)==1&&(TMSG[0]=='+'||TMSG[0]=='-'||TMSG[0]=='.'||TMSG[0]=='e'||TMSG[0]=='E')) )
{
data[dd]=AnsiString(TMSG).ToDouble();
dd++;
}
ii=0;
if(string[jj]=='+'||string[jj]=='-')
{
TMSG[0]=string[jj];
ii++;
}
if(string[jj]=='.')
{
TMSG[0]=string[jj];
FlagD=1;
ii++;
}
}
FlagE=0; FlagD=0; EndRD=0;
}
}
if(ii>0)
{
TMSG[ii]='\0';
if(!(strlen(TMSG)==1&&(TMSG[0]=='+'||TMSG[0]=='-'||TMSG[0]=='.'||TMSG[0]=='e'||TMSG[0]=='E')) )
{
data[dd]=AnsiString(TMSG).ToDouble();
dd++;
}
}
return dd;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int __fastcall TForm1::NumTime( int ii)
{
int jj;
int day,num;
// char MYMSG[255];
int MONTH[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int MONTH1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
if(ii<0) return -1;
if(*(Data[ii]+1)<0) *(Data[ii]+1)*=-1;
if(*(Data[ii]+2)<0) *(Data[ii]+2)*=-1;
if(*(Data_Flag+ii)!=Column) return -1;
if(!((*(Data[ii]+4)>29.5&&*(Data[ii]+4)<30.5)||(*(Data[ii]+4)>-.5&&*(Data[ii]+4)<0.5))) return -1;
num=0;day=0;
if((int)(*(Data[ii]+0)+0.5)==2004)
{
for(jj=0;jj<(int)(*(Data[ii]+1)+0.5)-1;jj++)
day+=MONTH1[jj];
}
else
{
for(jj=0;jj<(int)(*(Data[ii]+1)+0.5)-1;jj++)
day+=MONTH[jj];
}
day+=(int)(*(Data[ii]+2)+0.5)-1;
num=day*48+(int)(*(Data[ii]+3)+0.5)*2;
if(*(Data[ii]+4)>29.5&&*(Data[ii]+4)<30.5) num+=1;
if(num>=18000||num<0) return -1;
return num;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::Btn_CalculateClick(TObject *Sender)
{
int ii,jj;
bool Error_Flag;
int num_T[24],num_H[24],num_C[24];
int NN_Tstart,NN_Hstart,NN_Cstart;
char MYMSG[255];
NN_Tstart=6;NN_Hstart=7;NN_Cstart=8;
for(ii=0;ii<24;ii++)
{
DiurnalAvg_T[ii]=0;
DiurnalAvg_H[ii]=0;
DiurnalAvg_C[ii]=0;
num_T[ii]=0;
num_H[ii]=0;
num_C[ii]=0;
}
for(ii=0;ii<Row;ii++)
{
Error_Flag=true;
if(*(Data_Flag+ii)!=Column) Error_Flag=false;
for(jj=0;jj<Column;jj++)
if(*(Data[ii]+jj)<-4000) Error_Flag=false;
if(*(Data[ii]+NN_Tstart)<-3000||*(Data[ii]+NN_Tstart)>3000) Error_Flag=false; //temperature
if(*(Data[ii]+NN_Hstart)<-3000 ||*(Data[ii]+NN_Hstart)>3000) Error_Flag=false; //H2O
if(*(Data[ii]+NN_Cstart)<-3000||*(Data[ii]+NN_Cstart)>3000) Error_Flag=false; //CO2
if(!Error_Flag) continue;
// sprintf(MYMSG,"(int)(*(Data[ii]+3)+0.45)=%d,num_T[(int)(*(Data[ii]+3)+0.45)][jj]=%d!",(int)(*(Data[ii]+3)+0.45),num_T[(int)(*(Data[ii]+3)+0.45)][jj]);
// Application->MessageBox(MYMSG,"Error Message!",MB_OK);
DiurnalAvg_T[(int)(*(Data[ii]+3)+0.45)]=DiurnalAvg_T[(int)(*(Data[ii]+3)+0.45)]*num_T[(int)(*(Data[ii]+3)+0.45)]/(num_T[(int)(*(Data[ii]+3)+0.45)]+1.0)+*(Data[ii]+NN_Tstart)/(num_T[(int)(*(Data[ii]+3)+0.45)]+1.0);//Temperature
num_T[(int)(*(Data[ii]+3)+0.45)]++;
DiurnalAvg_H[(int)(*(Data[ii]+3)+0.45)]=DiurnalAvg_H[(int)(*(Data[ii]+3)+0.45)]*num_H[(int)(*(Data[ii]+3)+0.45)]/(num_H[(int)(*(Data[ii]+3)+0.45)]+1.0)+*(Data[ii]+NN_Hstart)/(num_H[(int)(*(Data[ii]+3)+0.45)]+1.0);//H2O
num_H[(int)(*(Data[ii]+3)+0.45)]++;
DiurnalAvg_C[(int)(*(Data[ii]+3)+0.45)]=DiurnalAvg_C[(int)(*(Data[ii]+3)+0.45)]*num_C[(int)(*(Data[ii]+3)+0.45)]/(num_C[(int)(*(Data[ii]+3)+0.45)]+1.0)+*(Data[ii]+NN_Cstart)/(num_C[(int)(*(Data[ii]+3)+0.45)]+1.0);//CO2
num_C[(int)(*(Data[ii]+3)+0.45)]++;
}
Btn_Calculate->Enabled=false;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -