void OpenFileDlg::LoadWfdiscRecords(LPSTR lpFileName)
	{
	int nRecord=0;
	CListCtrl	m_list;
	char cChan[32],cSpS[32],cSta[32],cTimeBeg[32],cTimeEnd[32];
	LV_ITEM lvi;
	static char line[WFDISC_SIZE+2];
	static wfdisc wfd;
	struct wfdisc *pwfdisc;
	pwfdisc=&wfd;

	m_list.Attach(GetDlgItem(IDC_LIST)->m_hWnd);

	m_list.DeleteAllItems();


	int result;
	struct _stat buffer;
	result = _stat(lpFileName, &buffer);
	if( result == 0 )
		{
		int file_type=_S_IFREG;
		int dir_type=_S_IFDIR ;
		
		if( (buffer.st_mode & _S_IFMT) == _S_IFMT)
			{
			m_list.Detach();
			return;
			}
		}
	else
		{
		m_list.Detach();
		return;
		}




	FILE *fp=fopen(lpFileName,"rt");

	if(fp==NULL)
		{
		m_list.Detach();
		return;
		}

	_fpreset();
	while(1)
		{
		if (fgets(line, WFDISC_SIZE+1, fp) == NULL) break;
		if (lstrlen(line) == WFDISC_SIZE) 
			{
//        sscanf(line, WFDISC_SCS, WFDISC_RVL(pwfdisc));

			ScanWfdLine(pwfdisc, line);
            WFDISC_TRM(pwfdisc);

			lstrcpy(cSta,	pwfdisc->sta);
			lstrcpy(cChan,	pwfdisc->chan);
			sprintf(cSpS,"%.3f", pwfdisc->smprate);
			sprintf(cTimeBeg,"%s",dttostr(pwfdisc->time, 1));
			sprintf(cTimeEnd,"%s",dttostr(pwfdisc->endtime, 1));


			memset(&lvi,0,sizeof(lvi));
			lvi.iItem=nRecord;
			lvi.iSubItem=0;
			lvi.mask=LVIF_TEXT;
			lvi.iImage=0;
			lvi.cchTextMax=sizeof(cSta);
			lvi.pszText=cSta;

			m_list.InsertItem(&lvi);
			m_list.SetItemText(nRecord,1,cChan);
			m_list.SetItemText(nRecord,2,cSpS);
			m_list.SetItemText(nRecord,3,cTimeBeg);
			m_list.SetItemText(nRecord,4,cTimeEnd);
			++nRecord;
			}
		}
	fclose(fp);
	m_list.Detach();
	}
/*
* Routine: void EvalDateExpr(expr_t *pExpr, StringBuffer_t *pBuf)
* Purpose: set the values to be used to replace a given tag for this query generation
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: 
*/
int
EvalDateExpr(expr_t *pExpr, Expr_Val_t *pBuf, Expr_Val_t *pParams, int bIsParam)
{
	date_t dBegin,
		dEnd,
		dResult;
	int nDay,
		nDay2,
		nDistributionType,
		nModifierArg,
		i,
		*pPermute = NULL,
		nTotal = 0,
		nDirection;
	
	/* pull the parameters from pParams */
	strtodt(&dBegin, GetBuffer(pParams->pBuf));
	strtodt(&dEnd, GetBuffer(pParams[1].pBuf));
	nDistributionType = pParams[2].nValue;
	
	/* and then check to see if more are required */
	switch (pExpr->nFlags & (EXPR_FL_LIST | EXPR_FL_RANGE))
	{
	case EXPR_FL_LIST:	/* return a set of values */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = pParams[3].nValue;
		i = dBegin.julian - dBegin.julian;
		if (nModifierArg > i)
		{
			nModifierArg = i;
			ReportError(QERR_RANGE_OVERRUN, NULL, 0);
			pPermute = makePermutation(pPermute, i, 0);
		}
		for (i=0; i < nModifierArg; i++)
		{
			jtodt(&dResult, dBegin.julian + getPermutationEntry(pPermute, i + 1) - 1);
			AddBuffer(pBuf[i].pBuf, dttostr(&dBegin));
		}
		free(pPermute);
		break;
	case EXPR_FL_RANGE:	/* return end points of a range */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = pParams[3].nValue;
		
		for (i=dBegin.julian; i < dEnd.julian; i++)
			nTotal += getDateWeightFromJulian(i, nDistributionType);
		nTotal *= nModifierArg;
		nTotal /= 100;
		
		genrand_date(&dResult, nDistributionType, &dBegin, &dEnd, NULL, 0);
		nDay = dResult.julian;
		nDay2 = nDay;
		
		nDirection = 1;
		while (nTotal > 0)
		{
			if (nDirection == 1)
			{
				nDay2 += 1;
				nTotal -= getDateWeightFromJulian(nDay2, nDistributionType);
				if (nDay2 == dEnd.julian)
					nDirection = -1;
			}
			else
			{
				nDay -= 1;
				nTotal -= getDateWeightFromJulian(nDay, nDistributionType);
			}
		}
		
		jtodt(&dResult, nDay);
		AddBuffer(pBuf->pBuf, dttostr(&dResult));
		jtodt(&dResult, nDay2);
		AddBuffer(pBuf[1].pBuf , dttostr(&dResult));
		break;
	case EXPR_FL_RANGE|EXPR_FL_LIST:	/* cannot use them both */
		ReportError(QERR_RANGE_LIST, NULL, 1);
		break;
	default:
		/* just do "normal" random date with a single return value */
		genrand_date(&dResult, nDistributionType, &dBegin, &dEnd, NULL, 0);
		AddBuffer(pBuf->pBuf, dttostr(&dResult));
		pBuf->bUseInt = 0;
		break;
	}
	
	
	return(DT_DATE);
}
void CDBPickView::DrawTimePanel(CDC *pDC)
	{

	char cBuff[64];
    CPen WhitePen(PS_SOLID,1,RGB(255,255,255));
	CPen DarkPen(PS_SOLID,1,RGB(0,0,0));
	CPen RedPen(PS_SOLID,1,RGB(255,0,0));
	
	int xw1=WindowInfoXsize+3;
	int xw2=MaxX-1;
	int yw1=1;
	int yw2=TimeBarYsize-1;
	int x, x_old;


	CPen   *oldPen=pDC->GetCurrentPen();
	pDC->SelectObject(&WhitePen);


	pDC->MoveTo(xw1,MaxY-yw2);		
	pDC->LineTo(xw2,MaxY-yw2);

	pDC->MoveTo(xw1,MaxY-yw2);		
	pDC->LineTo(xw1,MaxY-yw1);

	pDC->SelectObject(&DarkPen);

	pDC->MoveTo(xw2,MaxY-yw1);		
	pDC->LineTo(xw2,MaxY-yw2);

	pDC->MoveTo(xw2,MaxY-yw1);		
	pDC->LineTo(xw1,MaxY-yw1);

	x_old=-1;

	int imode;

	x=(int)((xw2-xw1)/(t2-t1));

	if(x<3)
		{
		x=(int)(60*(xw2-xw1)/(t2-t1));
		if(x==0)
			{
			imode=2;
			}
		else
			{
			imode=1;
			}
		}
	else
		{
		imode=0;
		}
	nLastMarkRightPos=-100;
	for(long tt=(long)t1; tt<t2; ++tt)
		{
		x=(int)((tt-t1)*(xw2-xw1)/(t2-t1)+xw1);

		if(tt%3600==0)
			{
			pDC->SelectObject(&WhitePen);
			pDC->MoveTo(x,MaxY-yw2);		
			pDC->LineTo(x,MaxY-(yw2-12));
			pDC->SelectObject(&DarkPen);
			pDC->MoveTo(x+1,MaxY-yw2);		
			pDC->LineTo(x+1,MaxY-(yw2-12));
			x_old=x;


			lstrcpy(cBuff, dttostr(tt, 1));
			RECT rcc;
			GetTextRectangle(cBuff,rcc);
			int nWtd=(rcc.right-rcc.left)/2+1;
			rcc.left=x-nWtd;
			rcc.right=x+nWtd;
			rcc.bottom=(MaxY-yw1);
			rcc.top=(MaxY-yw2);
			if(nLastMarkRightPos<rcc.left)
				{
				pDC->DrawText(cBuff,&rcc,DT_LEFT|DT_SINGLELINE|DT_BOTTOM);
				nLastMarkRightPos=rcc.right;
				}

			continue;
			}


		
		if(imode<2)
		if(tt%60==0)
			{
			pDC->SelectObject(&WhitePen);
			pDC->MoveTo(x,MaxY-yw2);		
			pDC->LineTo(x,MaxY-(yw2-8));
			pDC->SelectObject(&DarkPen);
			pDC->MoveTo(x+1,MaxY-yw2);		
			pDC->LineTo(x+1,MaxY-(yw2-8));
			x_old=x;

			pDC->SetTextColor(RGB(255,255,255));

			lstrcpy(cBuff, dttostr(tt, 1));
			RECT rcc;
			GetTextRectangle(cBuff,rcc);
			int nWtd=(rcc.right-rcc.left)/2+1;
			rcc.left=x-nWtd;
			rcc.right=x+nWtd;
			rcc.bottom=(MaxY-yw1);
			rcc.top=(MaxY-yw2);
			if(nLastMarkRightPos<rcc.left)
				{
				pDC->DrawText(cBuff,&rcc,DT_LEFT|DT_SINGLELINE|DT_BOTTOM);
				nLastMarkRightPos=rcc.right;
				}
			continue;
			}

		if(imode==0)
			{
			pDC->SelectObject(&WhitePen);
			pDC->MoveTo(x,MaxY-yw2);		
			pDC->LineTo(x,MaxY-(yw2-4));
			pDC->SelectObject(&DarkPen);
			pDC->MoveTo(x+1,MaxY-yw2);		
			pDC->LineTo(x+1,MaxY-(yw2-4));
			x_old=x;
			}

		}

/*	pDC->SetTextColor(RGB(255,255,255));

	lstrcpy(cBuff, dttostr(t1, 1));
	CRect *rcc=new CRect(xw1,(MaxY-yw2),xw2, (MaxY-yw1));
	pDC->DrawText(cBuff,rcc,DT_LEFT|DT_SINGLELINE|DT_BOTTOM);
	delete rcc;

	lstrcpy(cBuff, dttostr(t2, 1));
	rcc=new CRect(xw1,(MaxY-yw2),xw2, (MaxY-yw1));
	pDC->DrawText(cBuff,rcc,DT_RIGHT|DT_SINGLELINE|DT_BOTTOM);
	delete rcc;*/

    pDC->SelectObject(oldPen);

	}