/*--------------------------------------------------------------------------- put_into_subcubes(begin,end,a1,a2,b1,b2) put the data in Vert_ary into subcubes. ----------------------------------------------------------------------------*/ void put_into_subcubes(int begin, int end, double a1, double a2, double b1, double b2) { int i,j,dir,begin1,end1; double midval; if ( (a2 - a1 <= Det_large[0]) && (b2 - b1 <= Det_large[1])) { int temp; i = (int)((a1 - Bound_box[0][0])/Det[0] + 0.5); j = (int)((b1 - Bound_box[1][0])/Det[1] + 0.5); temp=(j*CUBE_PER_DIM + i)<<1; Matrix[temp] = begin; Matrix[temp + 1] = end; return; } /* partition direction */ if (a2 - a1 >= Det_large[0] ) dir = 0; else if (b2 - b1 >= Det_large[1] ) dir = 1; /* subdivide the set of vertice in x-direction */ if (dir == 0) { midval=(a1+a2)/2.0; ReorderData(begin,end,0,midval,&end1,&begin1); put_into_subcubes(begin,end1,a1,midval,b1,b2); put_into_subcubes(begin1,end,midval,a2,b1,b2); } else if (dir == 1) { /* subdivide the set of vertice in y-direction */ midval=(b1+b2)/2.0; ReorderData(begin,end,1,midval,&end1,&begin1); put_into_subcubes(begin,end1,a1,a2,b1,midval); put_into_subcubes(begin1,end,a1,a2,midval,b2); } }
//--------------------------------------------------------------------------- int THQGetData::GetData(TPriceListDyn *DataBuf, char *Code, int Count, bool Mode) { try { if(!DirectoryExists(FFilePath)) return -1; char cFileNameH[HQ_FILE_PATH_LEN + 5]; strcpy(cFileNameH, FFilePath); if(FFilePath[strlen(cFileNameH) - 1] != '\\') strcat(cFileNameH, "\\"); if(Code[0] == 'H' || Code [0] == 'h') strcat(cFileNameH, "Sh"); else if(Code[0] == 'S' || Code [0] == 's') strcat(cFileNameH, "Sz"); else return -2; SYSTEMTIME stCurTime; GetLocalTime(&stCurTime); SYSTEMTIME ORIGINAL_DATE = {2004, 8, 4, 5, 0, 0, 0, 0}; int iLastDate = GetDate(stCurTime, 1); char cCurFileName[HQ_FILE_NAME_LEN] = {0x0, }; int iCount = 0; THQBackFileHead FHead; THQBackPackHead PackHead; char *buffer = NULL; int SecuNo = 0; //int iFileHandle = -1; FILE *pFileHandle = NULL; while (iCount < Count) { if(pFileHandle != NULL) { fclose(pFileHandle); pFileHandle = NULL; } iLastDate = GetDate(stCurTime, -1); if( DateCmp(stCurTime, ORIGINAL_DATE) < 0) break; char cDate[10] = {0x0, }; sprintf(cDate, "%d", iLastDate); strcpy(cCurFileName, cFileNameH); strcat(cCurFileName, cDate); strcat(cCurFileName, ".dat"); char cMsg[100] = "正在获取"; strcat(cMsg, cDate); strcat(cMsg, "历史数据……"); FCallBack(cMsg, iCount); pFileHandle = fopen(cCurFileName, "rb"); if(pFileHandle == NULL) continue; if(fseek(pFileHandle, 0, 0) == -1) continue; if( fread(&FHead, sizeof(THQBackFileHead), 1, pFileHandle) <= 0) continue; if(FHead.stock_num <= 0) continue; //Read static stock info; if( fread(&PackHead, sizeof(THQBackPackHead), 1, pFileHandle) <= 0) continue; if(buffer != NULL) { delete [] buffer; buffer = NULL; } //buffer = new char[PackHead.length]; buffer = new char[ sizeof(TUDPPackage) + sizeof(TUDPPriceList)*FHead.stock_num ]; if( fread((void*)buffer, PackHead.length, 1, pFileHandle) <= 0 ) continue; SecuNo = GetSecuNo(Code, buffer); if(SecuNo < 0) continue; int iCurCount = 0; int iLastCount = iCount; while(true) { FCallBack(cMsg, iCount); if( fread(&PackHead, sizeof(THQBackPackHead), 1, pFileHandle) <= 0) break; if(fread(buffer, PackHead.length, 1, pFileHandle) <= 0) break; if(AddFreshData(buffer, DataBuf, iLastCount, iCount, SecuNo, Count)) { if( iCount < Count) { iCount++; iCurCount++; } } } ReorderData(DataBuf, iCurCount, iCount); } if(pFileHandle != NULL) { fclose(pFileHandle); pFileHandle = NULL; } if(buffer != NULL) { delete [] buffer; buffer = NULL; } FCallBack("", iCount); return iCount; } catch(...) { return -1; } }