Пример #1
0
void CCalendarCtrl::Goto(const COleDateTime& dtDate, bool bSelect)
{
	if( (dtDate < m_BoundUp) && 
		(dtDate > m_BoundDown) )
	{
		m_DateCurrent = dtDate;		
		if(m_nFirstWeekDay<1 || m_nFirstWeekDay>7)
			m_nFirstWeekDay = 1;

		COleDateTime dtIte(m_DateCurrent.GetYear(), m_DateCurrent.GetMonth(), m_DateCurrent.GetDay(),0,0,0);
		int narr[7];
		for (int d=0; d<7; d++)	
			narr[((m_nFirstWeekDay-1)+d)%7] = d;
		int nCellStart = narr[dtIte.GetDayOfWeek()-1];
		for(int i=0; i<nCellStart; i++)	
			dtIte -= COleDateTimeSpan(1,0,0,0);

		for(i=0; i<CALENDAR_ROWS ; i++)
		{
			for(int u=0; u<CALENDAR_COLUMNS; u++)
			{
				// Init the cell
				m_dayCells[i][u].date = dtIte;
				m_dayCells[i][u].bPartial = false;
				m_dayCells[i][u].bMark = false;
				m_dayCells[i][u].csaLines.RemoveAll();

				if(m_pfnDataCallback)
					m_pfnDataCallback(this, DateToSeconds(m_dayCells[i][u].date));
				dtIte += COleDateTimeSpan(1,0,0,0);
			}
		}

		if(bSelect)
		{
			m_RandomSelection.RemoveAll();
			m_SelectionRange[2] = 0;
			m_SelectionRange[1] = DateToSeconds(COleDateTime(m_DateCurrent.GetYear(), m_DateCurrent.GetMonth(), m_DateCurrent.GetDay(),0,0,0));
			m_SelectionRange[0] = m_SelectionRange[1];

			// Scrolling pos
			COleDateTime today(time(NULL));
			m_nVscrollPos = (m_nVscrollMax/2) + (m_DateCurrent-today).GetDays()/7;
			SetScrollPos(SB_VERT, m_nVscrollPos, TRUE);
		}
	}

	Invalidate(true);
}
Пример #2
0
Seconds RetrieveTime(DialogPtr dialog, short monthItem)
{
	DateTimeRec time;
	Seconds seconds;
	
	time.month = EditText2Long(dialog, monthItem);
	time.day = EditText2Long(dialog, monthItem + 1);
	time.year = EditText2Long(dialog, monthItem + 2);
	time.hour = EditText2Long(dialog, monthItem + 3);
	time.minute = EditText2Long(dialog, monthItem + 4);
	time.second = 0;
	if (time.year < 1900)						// two digit date, so fix it
	{
		if (time.year >= 40 && time.year <= 99)	// JLM
			time.year += 1900;
		else
			time.year += 2000;					// correct for year 2000 (00 to 40)
	}

	if (time.month && time.day && time.year)
		DateToSeconds (&time, &seconds);
	else
		seconds = 0;

	return seconds;
}
Пример #3
0
void CCalendarCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	bool bHold = (GetKeyState(VK_SHIFT)>>8 == -1)?true:false;
	bool bCtrl = (GetKeyState(VK_CONTROL)>>8 == -1)?true:false;
	if(bHold) bCtrl = false; // allow one combination

	int nRow, nCol;
	if(GetGridCellFromPoint(point, nRow, nCol) && !bCtrl)
	{
		if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
			(m_dayCells[nRow][nCol].date > m_BoundDown) )
		{
			m_RandomSelection.RemoveAll();
			m_SelectionRange[2] = 0;
			m_bSelectionStarted = true;
			m_SelectionRange[0] = DateToSeconds(m_dayCells[nRow][nCol].date);
			m_SelectionRange[1] = m_SelectionRange[0];
			SetCapture();
			Invalidate(true);
		}
	}	
	
	SetFocus();
	CWnd::OnLButtonDown(nFlags, point);
}
Пример #4
0
void CCalendarCtrl::GetLastSelectedGridCell(int &nRow, int &nCol)
{
	nRow = 0; nCol = 0;
	for(int i=0; i<CALENDAR_ROWS ; i++)
	{
		for(int u=0; u<CALENDAR_COLUMNS ; u++)
		{
			if(m_SelectionRange[1] == DateToSeconds(m_dayCells[i][u].date)){
				nRow = i; nCol = u;
				return;
			}
		}
	}
}
Пример #5
0
//----------------------------------------------------------------------
// Sets the Real-Time clock alarm (RTCA) time on the 1-Wire 
// device to the PC's clock with an offset in seconds. Also included 
// is an option to enable or disable the alarm.
//
// Parameters:
//  portnum        The port number of the port being used for the
//                 1-Wire network.
//  SNum           The 1-Wire address of the device to communicate.
//  PCOffset       The number of seconds from the PC's time/date to 
//                 to set the RTCA.
//  AlarmEnable    Enables/Disables the Real-Time clock alarm.  TRUE will 
//                 enable the alarm and FALSE will disable the alarm. 
//
// Returns:        TRUE  if the write worked.
//                 FALSE if there was an error in writing to the part.
//
SMALLINT setRTCAFromPCOffset(int portnum, uchar * SNum, ulong PCOffset, SMALLINT AlarmEnable)
{
   ulong timelong = 0;
   timedate td;

   // get seconds since Jan 1, 1970
   getPCTime(&td); // first, get timedate
   timelong = DateToSeconds(&td); // convert timedate to seconds since Jan 1, 1970
   // write 4 bytes to 1-Wire clock device (memory bank 2) 
   // starting at address 0x11.
   if (setRTCA(portnum, SNum, (timelong + PCOffset), AlarmEnable) != TRUE)
   {
	   return FALSE;
   }
   return TRUE;
}
Пример #6
0
static void MacintoshInitializeTime(void)
{
    uint64					upTime;
    unsigned long			currentLocalTimeSeconds,
	   startupTimeSeconds;
    uint64				startupTimeMicroSeconds;
    uint32				upTimeSeconds;
    uint64				oneMillion, upTimeSecondsLong, microSecondsToSeconds;
    DateTimeRec				firstSecondOfUnixTime;

    /*
     * Figure out in local time what time the machine started up. This information can be added to
     * upTime to figure out the current local time as well as GMT.
     */

    Microseconds((UnsignedWide*)&upTime);

    GetDateTime(&currentLocalTimeSeconds);

    JSLL_I2L(microSecondsToSeconds, PRMJ_USEC_PER_SEC);
    JSLL_DIV(upTimeSecondsLong, upTime, microSecondsToSeconds);
    JSLL_L2I(upTimeSeconds, upTimeSecondsLong);

    startupTimeSeconds = currentLocalTimeSeconds - upTimeSeconds;

    /*  Make sure that we normalize the macintosh base seconds to the unix base of January 1, 1970.
     */

    firstSecondOfUnixTime.year = 1970;
    firstSecondOfUnixTime.month = 1;
    firstSecondOfUnixTime.day = 1;
    firstSecondOfUnixTime.hour = 0;
    firstSecondOfUnixTime.minute = 0;
    firstSecondOfUnixTime.second = 0;
    firstSecondOfUnixTime.dayOfWeek = 0;

    DateToSeconds(&firstSecondOfUnixTime, &gJanuaryFirst1970Seconds);

    startupTimeSeconds -= gJanuaryFirst1970Seconds;

    /*  Now convert the startup time into a wide so that we can figure out GMT and DST.
     */

    JSLL_I2L(startupTimeMicroSeconds, startupTimeSeconds);
    JSLL_I2L(oneMillion, PRMJ_USEC_PER_SEC);
    JSLL_MUL(dstLocalBaseMicroseconds, oneMillion, startupTimeMicroSeconds);
}
Пример #7
0
void CCalendarCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
	if(m_bSelectionStarted)
	{
		int nRow, nCol;
		if(GetGridCellFromPoint(point, nRow, nCol))
		{
			if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
				(m_dayCells[nRow][nCol].date > m_BoundDown) )	
			{
				m_RandomSelection.RemoveAll();
				m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
				AdjustSelection();
				Invalidate(true);
			}
		}
	}	
	CWnd::OnMouseMove(nFlags, point);
}
Пример #8
0
void CCalendarCtrl::Reset()
{
	COleDateTime today(time(NULL));
	COleDateTime dtFirstDay(today.GetYear(), today.GetMonth(), 1,0,0,0); 
	
	if(dtFirstDay > m_BoundUp) 
		dtFirstDay = m_BoundUp;
	else if(dtFirstDay < m_BoundDown)	
		dtFirstDay = m_BoundDown;

	if (dtFirstDay.GetMonth()%2) 
		m_bMonthIsOdd = true;

	Goto(dtFirstDay);

	// Reset selection
	m_SelectionRange[1] = DateToSeconds(COleDateTime(today.GetYear(), today.GetMonth(), today.GetDay(),0,0,0));
	m_SelectionRange[0] = m_SelectionRange[1];

	// Reset scroll pos
	m_nVscrollPos = m_nVscrollMax/2;
	SetScrollPos(SB_VERT, m_nVscrollPos, TRUE);
}
Пример #9
0
static time_t tm2time(struct tm *tp)
{
time_t intMacTime;
DateTimeRec  dtr;

 normalize(&tp->tm_sec, &tp->tm_min, 60);
 normalize(&tp->tm_min, &tp->tm_hour,60);
 normalize(&tp->tm_hour,&tp->tm_mday,24);
 normalize(&tp->tm_mon, &tp->tm_year,12);

 dtr.year    = tp->tm_year + 1900;  /* years since 1900 */
 dtr.month   = tp->tm_mon  +    1;  /* month, 0 = January and 11 = December */
 dtr.day     = tp->tm_mday;         /* day of the month, from 1 to 31 */
 dtr.hour    = tp->tm_hour;         /* hour, from 0 to 23 */
 dtr.minute  = tp->tm_min;          /* minute, from 0 to 59 */
 dtr.second  = tp->tm_sec;          /* second, from 0 to 59 */

 DateToSeconds(&dtr, &intMacTime);

 MACOS_TO_UNIX(intMacTime);

 return intMacTime;
}
Пример #10
0
OSErr NetCDFWindMoverCurv::TextRead(char *path, TMap **newMap, char *topFilePath) // don't want a map  
{
	// this code is for curvilinear grids
	OSErr err = 0;
	long i,j, numScanned, indexOfStart = 0;
	int status, ncid, latIndexid, lonIndexid, latid, lonid, recid, timeid, numdims;
	size_t latLength, lonLength, recs, t_len, t_len2;
	float timeVal;
	char recname[NC_MAX_NAME], *timeUnits=0, month[10];	
	char dimname[NC_MAX_NAME], s[256], topPath[256];
	WORLDPOINTFH vertexPtsH=0;
	float *lat_vals=0,*lon_vals=0,yearShift=0.;
	static size_t timeIndex,ptIndex[2]={0,0};
	static size_t pt_count[2];
	Seconds startTime, startTime2;
	double timeConversion = 1.;
	char errmsg[256] = "",className[256]="";
	char fileName[64],*modelTypeStr=0;
	Point where;
	OSType typeList[] = { 'NULL', 'NULL', 'NULL', 'NULL' };
	MySFReply reply;
	Boolean bTopFile = false, fIsNavy = false;	// for now keep code around but probably don't need Navy curvilinear wind
	//VelocityFH velocityH = 0;
	char outPath[256];
	
	if (!path || !path[0]) return 0;
	strcpy(fPathName,path);
	
	strcpy(s,path);
	SplitPathFile (s, fileName);
	strcpy(fFileName, fileName); // maybe use a name from the file
	status = nc_open(path, NC_NOWRITE, &ncid);
	//if (status != NC_NOERR) {err = -1; goto done;}
	if (status != NC_NOERR) 
	{
#if TARGET_API_MAC_CARBON
		err = ConvertTraditionalPathToUnixPath((const char *) path, outPath, kMaxNameLen) ;
		status = nc_open(outPath, NC_NOWRITE, &ncid);
#endif
		if (status != NC_NOERR) {err = -1; goto done;}
	}
	// check number of dimensions - 2D or 3D
	status = nc_inq_ndims(ncid, &numdims);
	if (status != NC_NOERR) {err = -1; goto done;}
	
	status = nc_inq_attlen(ncid,NC_GLOBAL,"generating_model",&t_len2);
	if (status != NC_NOERR) {fIsNavy = false; /*goto done;*/}	
	else 
	{
		fIsNavy = true;
		// may only need to see keyword is there, since already checked grid type
		modelTypeStr = new char[t_len2+1];
		status = nc_get_att_text(ncid, NC_GLOBAL, "generating_model", modelTypeStr);
		if (status != NC_NOERR) {fIsNavy = false; goto done;}	
		modelTypeStr[t_len2] = '\0';
		
		strcpy(fFileName, modelTypeStr); 
	}
	GetClassName(className);
	if (!strcmp("NetCDF Wind",className))
		SetClassName(fFileName); //first check that name is now the default and not set by command file ("NetCDF Wind")
	
	//if (fIsNavy)
	{
		status = nc_inq_dimid(ncid, "time", &recid); //Navy
		//if (status != NC_NOERR) {err = -1; goto done;}
		if (status != NC_NOERR) 
		{	status = nc_inq_unlimdim(ncid, &recid);	// issue of time not being unlimited dimension
			if (status != NC_NOERR) {err = -1; goto done;}
		}			
	}
	/*else
	 {
	 status = nc_inq_unlimdim(ncid, &recid);	// issue of time not being unlimited dimension
	 if (status != NC_NOERR) {err = -1; goto done;}
	 }*/
	
	//if (fIsNavy)
	status = nc_inq_varid(ncid, "time", &timeid); 
	if (status != NC_NOERR) 
	{	
		status = nc_inq_varid(ncid, "ProjectionHr", &timeid); 
		if (status != NC_NOERR) {err = -1; goto done;}
	}			
	//	if (status != NC_NOERR) {/*err = -1; goto done;*/timeid=recid;} 
	
	//if (!fIsNavy)
	//status = nc_inq_attlen(ncid, recid, "units", &t_len);	// recid is the dimension id not the variable id
	//else	// LAS has them in order, and time is unlimited, but variable/dimension names keep changing so leave this way for now
	status = nc_inq_attlen(ncid, timeid, "units", &t_len);
	if (status != NC_NOERR) 
	{
		timeUnits = 0;	// files should always have this info
		timeConversion = 3600.;		// default is hours
		startTime2 = model->GetStartTime();	// default to model start time
		//err = -1; goto done;
	}
	else
	{
		DateTimeRec time;
		char unitStr[24], junk[10];
		
		timeUnits = new char[t_len+1];
		//if (!fIsNavy)
		//status = nc_get_att_text(ncid, recid, "units", timeUnits);	// recid is the dimension id not the variable id
		//else
		status = nc_get_att_text(ncid, timeid, "units", timeUnits);
		if (status != NC_NOERR) {err = -1; goto done;} 
		timeUnits[t_len] = '\0'; // moved this statement before StringSubstitute, JLM 5/2/10
		StringSubstitute(timeUnits, ':', ' ');
		StringSubstitute(timeUnits, '-', ' ');
		StringSubstitute(timeUnits, 'T', ' ');
		StringSubstitute(timeUnits, 'Z', ' ');
		
		numScanned=sscanf(timeUnits, "%s %s %hd %hd %hd %hd %hd %hd",
						  unitStr, junk, &time.year, &time.month, &time.day,
						  &time.hour, &time.minute, &time.second) ;
		if (numScanned==5)	
		{time.hour = 0; time.minute = 0; time.second = 0; }
		else if (numScanned==7) // has two extra time entries ??	
			time.second = 0;
		else if (numScanned<8)	
		//else if (numScanned!=8)	
		{ 
			//timeUnits = 0;	// files should always have this info
			//timeConversion = 3600.;		// default is hours
			//startTime2 = model->GetStartTime();	// default to model start time
			err = -1; TechError("NetCDFWindMoverCurv::TextRead()", "sscanf() == 8", 0); goto done;
		}
		else
		{
			// code goes here, trouble with the DAYS since 1900 format, since converts to seconds since 1904
			if (time.year ==1900) {time.year += 40; time.day += 1; /*for the 1900 non-leap yr issue*/ yearShift = 40.;}
			DateToSeconds (&time, &startTime2);	// code goes here, which start Time to use ??
			if (!strcmpnocase(unitStr,"HOURS") || !strcmpnocase(unitStr,"HOUR"))
				timeConversion = 3600.;
			else if (!strcmpnocase(unitStr,"MINUTES") || !strcmpnocase(unitStr,"MINUTE"))
				timeConversion = 60.;
			else if (!strcmpnocase(unitStr,"SECONDS") || !strcmpnocase(unitStr,"SECOND"))
				timeConversion = 1.;
			else if (!strcmpnocase(unitStr,"DAYS") || !strcmpnocase(unitStr,"DAY"))
				timeConversion = 24.*3600.;
		}
	} 
	
	if (fIsNavy)
	{
		status = nc_inq_dimid(ncid, "gridy", &latIndexid); //Navy
		if (status != NC_NOERR) {err = -1; goto done;}
		status = nc_inq_dimlen(ncid, latIndexid, &latLength);
		if (status != NC_NOERR) {err = -1; goto done;}
		status = nc_inq_dimid(ncid, "gridx", &lonIndexid);	//Navy
		if (status != NC_NOERR) {err = -1; goto done;}
		status = nc_inq_dimlen(ncid, lonIndexid, &lonLength);
		if (status != NC_NOERR) {err = -1; goto done;}
		// option to use index values?
		status = nc_inq_varid(ncid, "grid_lat", &latid);
		if (status != NC_NOERR) {err = -1; goto done;}
		status = nc_inq_varid(ncid, "grid_lon", &lonid);
		if (status != NC_NOERR) {err = -1; goto done;}
	}
	else
	{
		for (i=0;i<numdims;i++)
		{
			if (i == recid) continue;
			status = nc_inq_dimname(ncid,i,dimname);
			if (status != NC_NOERR) {err = -1; goto done;}
			if (!strncmpnocase(dimname,"X",1) || !strncmpnocase(dimname,"LON",3) || !strncmpnocase(dimname,"nx",2))
			{
				lonIndexid = i;
			}
			if (!strncmpnocase(dimname,"Y",1) || !strncmpnocase(dimname,"LAT",3) || !strncmpnocase(dimname,"ny",2))
			{
				latIndexid = i;
			}
		}
		
		status = nc_inq_dimlen(ncid, latIndexid, &latLength);
		if (status != NC_NOERR) {err = -1; goto done;}
		status = nc_inq_dimlen(ncid, lonIndexid, &lonLength);
		if (status != NC_NOERR) {err = -1; goto done;}
		
		status = nc_inq_varid(ncid, "LATITUDE", &latid);
		if (status != NC_NOERR) 
		{
			status = nc_inq_varid(ncid, "lat", &latid);
			if (status != NC_NOERR) 
			{
				status = nc_inq_varid(ncid, "latitude", &latid);
				if (status != NC_NOERR) {err = -1; goto done;}
			}
		}
		status = nc_inq_varid(ncid, "LONGITUDE", &lonid);
		if (status != NC_NOERR) 
		{
			status = nc_inq_varid(ncid, "lon", &lonid);
			if (status != NC_NOERR) 
			{
				status = nc_inq_varid(ncid, "longitude", &lonid);
				if (status != NC_NOERR) {err = -1; goto done;}
			}
		}
	}
	
	pt_count[0] = latLength;
	pt_count[1] = lonLength;
	vertexPtsH = (WorldPointF**)_NewHandleClear(latLength*lonLength*sizeof(WorldPointF));
	if (!vertexPtsH) {err = memFullErr; goto done;}
	lat_vals = new float[latLength*lonLength]; 
	lon_vals = new float[latLength*lonLength]; 
	if (!lat_vals || !lon_vals) {err = memFullErr; goto done;}
	status = nc_get_vara_float(ncid, latid, ptIndex, pt_count, lat_vals);
	if (status != NC_NOERR) {err = -1; goto done;}
	status = nc_get_vara_float(ncid, lonid, ptIndex, pt_count, lon_vals);
	if (status != NC_NOERR) {err = -1; goto done;}
	for (i=0;i<latLength;i++)
	{
		for (j=0;j<lonLength;j++)
		{
			//if (lat_vals[(latLength-i-1)*lonLength+j]==fill_value)	// this would be an error
			//lat_vals[(latLength-i-1)*lonLength+j]=0.;
			//if (lon_vals[(latLength-i-1)*lonLength+j]==fill_value)
			//lon_vals[(latLength-i-1)*lonLength+j]=0.;
			INDEXH(vertexPtsH,i*lonLength+j).pLat = lat_vals[(latLength-i-1)*lonLength+j];	
			INDEXH(vertexPtsH,i*lonLength+j).pLong = lon_vals[(latLength-i-1)*lonLength+j];
		}
	}
	fVertexPtsH	 = vertexPtsH;
	
	status = nc_inq_dim(ncid, recid, recname, &recs);
	if (status != NC_NOERR) {err = -1; goto done;}
	if (recs<=0) {strcpy(errmsg,"No times in file. Error opening NetCDF wind file"); err =  -1; goto done;}
	
	fTimeHdl = (Seconds**)_NewHandleClear(recs*sizeof(Seconds));
	if (!fTimeHdl) {err = memFullErr; goto done;}
	for (i=0;i<recs;i++)
	{
		Seconds newTime;
		// possible units are, HOURS, MINUTES, SECONDS,...
		timeIndex = i;
		//if (!fIsNavy)
		//status = nc_get_var1_float(ncid, recid, &timeIndex, &timeVal);	// recid is the dimension id not the variable id
		//else
		status = nc_get_var1_float(ncid, timeid, &timeIndex, &timeVal);
		if (status != NC_NOERR) {err = -1; goto done;}
		newTime = RoundDateSeconds(round(startTime2+timeVal*timeConversion));
		//INDEXH(fTimeHdl,i) = startTime2+(long)(timeVal*timeConversion -yearShift*3600.*24.*365.25);	// which start time where?
		//if (i==0) startTime = startTime2+(long)(timeVal*timeConversion -yearShift*3600.*24.*365.25);
		INDEXH(fTimeHdl,i) = newTime-yearShift*3600.*24.*365.25;	// which start time where?
		if (i==0) startTime = newTime-yearShift*3600.*24.*365.25;
	}
	if (model->GetStartTime() != startTime || model->GetModelTime()!=model->GetStartTime())
	{
		if (true)	// maybe use NOAA.ver here?
		{
			short buttonSelected;
			//buttonSelected  = MULTICHOICEALERT(1688,"Do you want to reset the model start time to the first time in the file?",FALSE);
			if(!gCommandFileRun)	// also may want to skip for location files...
				buttonSelected  = MULTICHOICEALERT(1688,"Do you want to reset the model start time to the first time in the file?",FALSE);
			else buttonSelected = 1;	// TAP user doesn't want to see any dialogs, always reset (or maybe never reset? or send message to errorlog?)
			switch(buttonSelected){
				case 1: // reset model start time
					//bTopFile = true;
					model->SetModelTime(startTime);
					model->SetStartTime(startTime);
					model->NewDirtNotification(DIRTY_RUNBAR); // must reset the runbar
					break;  
				case 3: // don't reset model start time
					//bTopFile = false;
					break;
				case 4: // cancel
					err=-1;// user cancel
					goto done;
			}
		}
		//model->SetModelTime(startTime);
		//model->SetStartTime(startTime);
		//model->NewDirtNotification(DIRTY_RUNBAR); // must reset the runbar
	}
	
	fNumRows = latLength;
	fNumCols = lonLength;
	
	status = nc_close(ncid);
	if (status != NC_NOERR) {err = -1; goto done;}
	
	//err = this -> SetInterval(errmsg);
	//if(err) goto done;
	
	// look for topology in the file
	// for now ask for an ascii file, output from Topology save option
	// need dialog to ask for file
	//if (fIsNavy)	// for now don't allow for wind files
	{if (topFilePath[0]) {err = ReadTopology(topFilePath,newMap); goto done;}}
	if (!gCommandFileRun)
	{
		short buttonSelected;
		buttonSelected  = MULTICHOICEALERT(1688,"Do you have an extended topology file to load?",FALSE);
		switch(buttonSelected){
			case 1: // there is an extended top file
				bTopFile = true;
				break;  
			case 3: // no extended top file
				bTopFile = false;
				break;
			case 4: // cancel
				err=-1;// stay at this dialog
				goto done;
		}
	}
	if(bTopFile)
	{
#if TARGET_API_MAC_CARBON
		mysfpgetfile(&where, "", -1, typeList,
					 (MyDlgHookUPP)0, &reply, M38c, MakeModalFilterUPP(STDFilter));
		if (!reply.good)/* return USERCANCEL;*/
		{
			/*if (recs>0)
				err = this -> ReadTimeData(indexOfStart,&velocityH,errmsg);
			else {strcpy(errmsg,"No times in file. Error opening NetCDF file"); err =  -1;}
			if(err) goto done;*/
			err = dynamic_cast<NetCDFWindMoverCurv *>(this)->ReorderPoints(newMap,errmsg);	
			//err = ReorderPoints(fStartData.dataHdl,newMap,errmsg);	// if u, v input separately only do this once?
	 		goto done;
		}
		else
			strcpy(topPath, reply.fullPath);
		
#else
		where = CenteredDialogUpLeft(M38c);
		sfpgetfile(&where, "",
				   (FileFilterUPP)0,
				   -1, typeList,
				   (DlgHookUPP)0,
				   &reply, M38c,
				   (ModalFilterUPP)MakeUPP((ProcPtr)STDFilter, uppModalFilterProcInfo));
		if (!reply.good) 
		{
			/*if (recs>0)
				err = this -> ReadTimeData(indexOfStart,&velocityH,errmsg);
			else {strcpy(errmsg,"No times in file. Error opening NetCDF file"); err =  -1;}
			if(err) goto done;*/
			err = dynamic_cast<NetCDFWindMoverCurv *>(this)->ReorderPoints(newMap,errmsg);	
			//err = ReorderPoints(fStartData.dataHdl,newMap,errmsg);	
	 		/*if (err)*/ goto done;
		}
		
		my_p2cstr(reply.fName);
		
#ifdef MAC
		GetFullPath(reply.vRefNum, 0, (char *)reply.fName, topPath);
#else
		strcpy(topPath, reply.fName);
#endif
#endif		
		strcpy (s, topPath);
		err = ReadTopology(topPath,newMap);	
		goto done;
	}
	
	/*if (recs>0)
		err = this -> ReadTimeData(indexOfStart,&velocityH,errmsg);
	else {strcpy(errmsg,"No times in file. Error opening NetCDF wind file"); err =  -1;}
	if(err) goto done;*/
	err = dynamic_cast<NetCDFWindMoverCurv *>(this)->ReorderPoints(newMap,errmsg);	
	//err = ReorderPoints(fStartData.dataHdl,newMap,errmsg);	
	
done:
	if (err)
	{
		printNote("Error opening NetCDF wind file");
		if(fGrid)
		{
			fGrid ->Dispose();
			delete fGrid;
			fGrid = 0;
		}
		if(vertexPtsH) {DisposeHandle((Handle)vertexPtsH); vertexPtsH = 0;	fVertexPtsH	 = 0;}
	}
	
	if (timeUnits) delete [] timeUnits;
	if (lat_vals) delete [] lat_vals;
	if (lon_vals) delete [] lon_vals;
	if (modelTypeStr) delete [] modelTypeStr;
	//if (velocityH) {DisposeHandle((Handle)velocityH); velocityH = 0;}
	return err;
}
Пример #11
0
BOOL CCalendarCtrl::PreTranslateMessage(MSG* pMsg) 
{		
	if( pMsg->message == WM_KEYDOWN )
	{
		COleDateTime newDate = m_DateCurrent;
		bool bHold = (GetKeyState(VK_SHIFT)>>8 == -1)?true:false;
		bool bCtrl = (GetKeyState(VK_CONTROL)>>8 == -1)?true:false;
		if(bHold) bCtrl = false; // allow one combination

		switch(pMsg->wParam)
		{
		case VK_SPACE:
			{
				if(bCtrl)
				{
					int nRow, nCol;
					GetLastSelectedGridCell(nRow, nCol);
					if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
						(m_dayCells[nRow][nCol].date > m_BoundDown) )	
					{
						void*p; time_t t = DateToSeconds(m_dayCells[nRow][nCol].date);
						if(m_RandomSelection.Lookup((void*)t ,p))
							m_RandomSelection.RemoveKey((void*)t);
						else{
							if(m_RandomSelection.GetCount() < m_nMaxSel)
								m_RandomSelection.SetAt((void*)t, 0);
						}
						Invalidate(true);
						return TRUE;
					}
				}
				break;
			}
		case VK_UP:
			{
				int nRow, nCol;
				GetLastSelectedGridCell(nRow, nCol);
				if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
					(m_dayCells[nRow][nCol].date > m_BoundDown) )	
				{
					if(!bCtrl){
						m_RandomSelection.RemoveAll();
						m_SelectionRange[2] = 0;
					}
					else{
						if(m_RandomSelection.GetCount() == 0)
							m_RandomSelection.SetAt((void*)m_SelectionRange[0], 0);
					}

					if(nRow == 0){
						newDate -= COleDateTimeSpan(7,0,0,0);
						if((m_BoundUp > newDate) && (newDate > m_BoundDown))
						{
							m_nVscrollPos--;
							SetScrollPos(SB_VERT, m_nVscrollPos, TRUE);
							Goto(newDate);
						}
					}
					else
						nRow--;	
					
					if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
						(m_dayCells[nRow][nCol].date > m_BoundDown) )	
					{
						m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
						if(bCtrl)
							m_SelectionRange[2] = m_SelectionRange[1];

						if(!bHold)
							m_SelectionRange[0] = m_SelectionRange[1];

						AdjustSelection();
						Invalidate(true);
					}
				}
				return TRUE;
			}
		case VK_DOWN:
			{
				int nRow, nCol;
				GetLastSelectedGridCell(nRow, nCol);
				if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
					(m_dayCells[nRow][nCol].date > m_BoundDown) )	
				{
					if(!bCtrl){
						m_RandomSelection.RemoveAll();
						m_SelectionRange[2] = 0;
					}
					else{
						if(m_RandomSelection.GetCount() == 0)
							m_RandomSelection.SetAt((void*)m_SelectionRange[0], 0);
					}

					if(nRow == CALENDAR_ROWS-1){
						newDate += COleDateTimeSpan(7,0,0,0);
						if((m_BoundUp > newDate) && (newDate > m_BoundDown))
						{
							m_nVscrollPos++;
							SetScrollPos(SB_VERT, m_nVscrollPos, TRUE);
							Goto(newDate);
						}
					}
					else
						nRow++;

					if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
						(m_dayCells[nRow][nCol].date > m_BoundDown) )	
					{	
						m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
						if(bCtrl)
							m_SelectionRange[2] = m_SelectionRange[1];

						if(!bHold)
							m_SelectionRange[0] = m_SelectionRange[1];

						AdjustSelection();
						Invalidate(true);
					}
				}
				return TRUE;
			}
		case VK_LEFT:
			{
				int nRow, nCol;
				GetLastSelectedGridCell(nRow, nCol);
				if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
					(m_dayCells[nRow][nCol].date > m_BoundDown) )	
				{
					if(!bCtrl){
						m_RandomSelection.RemoveAll();
						m_SelectionRange[2] = 0;
					}
					else{
						if(m_RandomSelection.GetCount() == 0)
							m_RandomSelection.SetAt((void*)m_SelectionRange[0], 0);
					}
					if(nCol > 0) nCol--;
					else
					{
						nCol = CALENDAR_COLUMNS-1;
						if(nRow == 0){
							newDate -= COleDateTimeSpan(7,0,0,0);
							if((m_BoundUp > newDate) && (newDate > m_BoundDown))
							{
								m_nVscrollPos--;
								SetScrollPos(SB_VERT, m_nVscrollPos, TRUE);
								Goto(newDate);
							}
							else
								nCol = 0;
						}
						else
							nRow--;
					}

					if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
						(m_dayCells[nRow][nCol].date > m_BoundDown) )	
					{					
						m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
						if(bCtrl)
							m_SelectionRange[2] = m_SelectionRange[1];

						if(!bHold)
							m_SelectionRange[0] = m_SelectionRange[1];

						AdjustSelection();
						Invalidate(true);
					}
				}
				return TRUE;
			}
		case VK_RIGHT:
			{
				int nRow, nCol;
				GetLastSelectedGridCell(nRow, nCol);
				if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
					(m_dayCells[nRow][nCol].date > m_BoundDown) )	
				{
					if(!bCtrl){
						m_RandomSelection.RemoveAll();
						m_SelectionRange[2] = 0;
					}
					else{
						if(m_RandomSelection.GetCount() == 0)
							m_RandomSelection.SetAt((void*)m_SelectionRange[0], 0);
					}
					if(nCol < CALENDAR_COLUMNS-1)	nCol++;
					else
					{
						nCol = 0;
						if(nRow == CALENDAR_ROWS-1){
							newDate += COleDateTimeSpan(7,0,0,0);
							if((m_BoundUp > newDate) && (newDate > m_BoundDown))
							{
								m_nVscrollPos++;
								SetScrollPos(SB_VERT, m_nVscrollPos, TRUE);
								Goto(newDate);
							}
							else
								nCol = CALENDAR_COLUMNS-1;
						}
						else
							nRow++;
					}
					
					if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
						(m_dayCells[nRow][nCol].date > m_BoundDown) )	
					{
						m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
						if(bCtrl)
							m_SelectionRange[2] = m_SelectionRange[1];

						if(!bHold)
							m_SelectionRange[0] = m_SelectionRange[1];

						AdjustSelection();
						Invalidate(true);
					}
				}
				return TRUE;
			}
		}
	}
Пример #12
0
void CCalendarCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	bool bHold = (GetKeyState(VK_SHIFT)>>8 == -1)?true:false;
	bool bCtrl = (GetKeyState(VK_CONTROL)>>8 == -1)?true:false;
	if(bHold) bCtrl = false; // allow one combination
	if(m_bSelectionStarted && !bCtrl)
	{
		m_RandomSelection.RemoveAll();
		m_bSelectionStarted = false;

		int nRow, nCol;
		if(GetGridCellFromPoint(point, nRow, nCol))
		{
			if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
				(m_dayCells[nRow][nCol].date > m_BoundDown) )			
				m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
			else
				m_SelectionRange[1]=m_SelectionRange[0];
		}
		else
			m_SelectionRange[1]=m_SelectionRange[0];		
		ReleaseCapture();
		AdjustSelection();
		Invalidate(true);
	}

	if(bCtrl){
		int nRow, nCol;
		if(GetGridCellFromPoint(point, nRow, nCol))
		{
			if( (m_dayCells[nRow][nCol].date < m_BoundUp) && 
				(m_dayCells[nRow][nCol].date > m_BoundDown) )	
			{
				if(m_SelectionRange[2])
				{				
						m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
						m_SelectionRange[0] = m_SelectionRange[1];

						void*p;
						if(m_RandomSelection.Lookup((void*)m_SelectionRange[1], p))
							m_RandomSelection.RemoveKey((void*)m_SelectionRange[1]);
						else{
							if(m_RandomSelection.GetCount() < m_nMaxSel)
								m_RandomSelection.SetAt((void*)m_SelectionRange[1], 0);
						}
						m_SelectionRange[2] = m_SelectionRange[1];
				}
				else{
					if(m_RandomSelection.GetCount() < m_nMaxSel)
						m_RandomSelection.SetAt((void*)m_SelectionRange[1], 0);
					m_SelectionRange[1] = DateToSeconds(m_dayCells[nRow][nCol].date);
					m_SelectionRange[0] = m_SelectionRange[1];
					if(m_RandomSelection.GetCount() < m_nMaxSel)
						m_RandomSelection.SetAt((void*)m_SelectionRange[1], 0);
					m_SelectionRange[2] = m_SelectionRange[1];
				}			
				Invalidate(true);
			}
		}
	}
	else{
		m_RandomSelection.RemoveAll();
		m_SelectionRange[2] = 0;
		Invalidate(true);
	}
	CWnd::OnLButtonUp(nFlags, point);
}
Пример #13
0
void CCalendarCtrl::DrawCells(CDC* pDC)
{
	CRect rc;
	GetClientRect(&rc);
	int ncHeight = (rc.Height()-CALENDAR_HEADER_HEIGHT)/CALENDAR_ROWS;
	int ncWidth = rc.Width()/CALENDAR_COLUMNS;

	CPen whitePen(PS_SOLID, 1, RGB(255,255,255));
	CPen blackPen(PS_SOLID, 1, RGB(0,0,0));

	CFont* pOldFont = pDC->SelectObject(&m_DefaultFont);
	CPen* pOldPen = pDC->SelectObject(&blackPen);

	for(int i=0; i<CALENDAR_ROWS ; i++)
	{
		for(int u=0; u<CALENDAR_COLUMNS ; u++)
		{
			CRect rect;
			if(GetRectFromCell(i, u, rect))
			{
				if(u == CALENDAR_COLUMNS-1) rect.right = rc.right;
				if(i == CALENDAR_ROWS-1) rect.bottom = rc.bottom;

				if((m_bMonthIsOdd &&  !(m_dayCells[i][u].date.GetMonth()%2))
					|| (!m_bMonthIsOdd && (m_dayCells[i][u].date.GetMonth()%2)))
				{
					CBrush br;
					br.CreateSolidBrush(CALENDAR_LIGHTGREY);
					pDC->FillRect(&rect ,&br);
				}

				COleDateTime today(time(NULL));
				bool btoday = false;
				if(today.GetDay() == m_dayCells[i][u].date.GetDay()	&& today.GetMonth() == m_dayCells[i][u].date.GetMonth()	&& today.GetYear() == m_dayCells[i][u].date.GetYear())
				{
					// Draw the frame 
					CRect rcLine(rect);
					rcLine.bottom = rcLine.top+15;
					rcLine.top = rcLine.bottom-1;
					for(int c=0; c<15; c++)
					{
						pDC->FillSolidRect(rcLine, GetFadedBlue(c*6));
						rcLine.bottom--;
						rcLine.top = rcLine.bottom-1;
					}
					btoday = true;
				}

				// Draw the selection
				bool bSelected = false;
				time_t tmax = max(m_SelectionRange[0], m_SelectionRange[1]);
				time_t tmin = min(m_SelectionRange[0], m_SelectionRange[1]);			
				time_t tcur = DateToSeconds(m_dayCells[i][u].date);				
				if(m_RandomSelection.GetCount())
				{	
					POSITION pos = m_RandomSelection.GetStartPosition();	 
					while (pos){
						void* p; DWORD date;
						m_RandomSelection.GetNextAssoc(pos, (void*&)date, p);
						if(date == (DWORD)tcur)
						{							
							CBrush br;
							br.CreateSolidBrush(GetFadedBlue(70));
							CRect selRect(rect);
							if(btoday)	selRect.top += 15;
							pDC->FillRect(&selRect, &br);
							bSelected = true;
						}
					}

					if(m_SelectionRange[2] == tcur)
					{
						rect.left+=2;	rect.right -=1;
						rect.top+=2;	rect.bottom -=1;
						pDC->DrawFocusRect(rect);
					}
				}
				else if((tmax >= tcur) && (tcur >= tmin))
				{						
					CRect selRect(rect);
					CBrush br;
					br.CreateSolidBrush(GetFadedBlue(70));
					if(btoday)	selRect.top += 15;
					pDC->FillRect(&selRect, &br);
					bSelected = true;
				}

				// Out of range
				if( (m_dayCells[i][u].date >= m_BoundUp) || 
					(m_dayCells[i][u].date <= m_BoundDown) )	
				{
					CRect selRect(rect);
					CBrush br;
					br.CreateSolidBrush(RGB(255,225,225));
					pDC->FillRect(&selRect, &br);
				}

				if(m_dayCells[i][u].bMark)
				{
					CBrush br;
					br.CreateSolidBrush(RGB(255,104,4));
					CRect rcMark(rect);
					rcMark.DeflateRect(3,3);
					rcMark.right = rcMark.left +6;
					rcMark.bottom = rcMark.top +6;
					pDC->FillRect(&rcMark, &br);
				}

				// draw inside...
				rect.DeflateRect(1,1);		
				CString csDay;
				int nDay = m_dayCells[i][u].date.GetDay();
				if(nDay == 1 || (i==0 && u==0))
				{
					csDay.Format(_T("%s %d"), m_dayCells[i][u].date.Format(_T("%B")), nDay);
					CSize dtSize(pDC->GetTextExtent(csDay));
					if(dtSize.cx>rect.Width())
						csDay.Format(_T("%s %d"), m_dayCells[i][u].date.Format(_T("%b")), nDay);
				}
				else
					csDay.Format(_T("%d"), nDay);

				unsigned long nColor;
				if(bSelected && !btoday)
					nColor = pDC->SetTextColor(RGB(255,104,4));
				else
					nColor = pDC->SetTextColor(RGB(0,0,0));
				pDC->DrawText(csDay, rect, DT_RIGHT|DT_TOP);
				pDC->SetTextColor(nColor);

				// Draw the cell content if possible
				if(rect.Width() >= 15)
				{
					for (int j=0; j<m_dayCells[i][u].csaLines.GetSize(); j++)
					{
						CRect txtRect(rect);
						CRect dotRect(rect);

						txtRect.left += 9; //CALENDAR_LINE_HEIGHT;
						txtRect.right-= 2;
						txtRect.top += (j+1)*CALENDAR_LINE_HEIGHT; 

						dotRect.top += (j+1)*CALENDAR_LINE_HEIGHT+(CALENDAR_LINE_HEIGHT/2-1); 
						dotRect.bottom = dotRect.top + 3;
						dotRect.left += 3;
						dotRect.right = dotRect.left +3;

						m_dayCells[i][u].bPartial = false;
						if(!m_dayCells[i][u].csaLines[j].IsEmpty() && txtRect.Height() > CALENDAR_LINE_HEIGHT)
						{
							pDC->SetTextColor(RGB(0,0,0));
							pDC->DrawText(m_dayCells[i][u].csaLines[j], txtRect, DT_LEFT|DT_TOP);								
							CBrush br;
							br.CreateSolidBrush(RGB(125,175,255));
							pDC->FillRect(&dotRect, &br);
						}
						else if(!m_dayCells[i][u].csaLines[j].IsEmpty())
						{
							CPen dotPen(PS_SOLID, 1, RGB(170,170,170));
							pDC->SelectObject(&dotPen);
							// Draw a little arrow
							static int t[2][7] = {5,5,8,8,8,5,5,4,3,2,1,2,3,4};
							int n = 0;
							for(int r=7; r>0; r--){
								pDC->MoveTo(rect.right-9+r, rect.bottom-t[0][n]);
								pDC->LineTo(rect.right-9+r, rect.bottom-t[1][n]);
								n++;
							}
							m_dayCells[i][u].bPartial = true;
							break;
						}
					}
				}
			}
		}
	}

	pDC->SelectObject(pOldFont);
	pDC->SelectObject(pOldPen);
}
Пример #14
0
Seconds RetrievePopTime(DialogPtr dialog, short monthItem,OSErr * err)
{
	DateTimeRec time;
	Seconds seconds = 0;
	short minDay = 1, maxDay;
	char msg[256] = "";
	
	*err = 0;
	
	time.month = GetPopSelection (dialog, monthItem);
	time.year = (FirstYearInPopup()  - 1) + GetPopSelection(dialog, monthItem + 2);

	// retrieve the day
	time.day = EditText2Long(dialog, monthItem + 1);
	switch(time.month)
	{
		case 1: case 3: case 5: case 7: case 8: case 10: case 12: maxDay = 31; break;
		case 2: //feb 
			if( (time.year % 4 == 0 && time.year % 100 != 0) || time.year % 400 == 0)  maxDay=29;
			else maxDay = 28;
			break;
		default: maxDay = 30; break;
	}
	if(time.day < minDay) strcpy(msg,"Your day value must be greater than 0.");
	else if (time.day > maxDay )
	{
		char *format = "Your day value cannot exceed %d."; 
		sprintf(msg,format,maxDay);
	}
	if(msg[0])
	{
		*err = 1;
		printError(msg);
		MySelectDialogItemText(dialog, monthItem + 1, 0, 100);
		return 0;
	}
	
	
	time.hour = EditText2Long(dialog, monthItem + 3);
	if(time.hour >= 24)
	{
		*err = 1;
		printError("Your hour value must be less than 24.");
		MySelectDialogItemText(dialog, monthItem + 3, 0, 100);
		return 0;
	}
	
	time.minute = EditText2Long(dialog, monthItem + 4);
	if(time.hour >= 60)
	{
		*err = 1;
		printError("Your minute value must be less than 60.");
		MySelectDialogItemText(dialog, monthItem + 4, 0, 100);
		return 0;
	}

	time.second = 0;

	if (time.month && time.day && time.year)
		DateToSeconds (&time, &seconds);
	else
		seconds = 0;

	return seconds;
}
Пример #15
0
OSErr TriCurMover_c::ReadTimeData(long index,VelocityFH *velocityH, char* errmsg) 
{
	char s[256], path[256]; 
	long i,j,line = 0;
	long offset,lengthToRead;
	CHARH h = 0;
	char *sectionOfFile = 0;
	char *strToMatch = 0;
	long len,numScanned;
	VelocityFH velH = 0;
	long totalNumberOfVels = 0;
	
	LongPointHdl ptsHdl = 0;
	//TopologyHdl topoH = GetTopologyHdl();
	//TTriGridVel* triGrid = (TTriGridVel*)fGrid;
	
	OSErr err = 0;
	DateTimeRec time;
	Seconds timeSeconds;
	//long numPoints, numDepths; 
	long numTris;
	errmsg[0]=0;
	
	strcpy(path,fVar.pathName);
	if (!path || !path[0]) return -1;
	
	lengthToRead = (*fTimeDataHdl)[index].lengthOfData;
	offset = (*fTimeDataHdl)[index].fileOffsetToStartOfData;
	
	if (fDepthDataInfo)
		numTris = _GetHandleSize((Handle)fDepthDataInfo)/sizeof(**fDepthDataInfo);
	//if(topoH)
	//numTris = _GetHandleSize((Handle)topoH)/sizeof(**topoH);
	else 
	{err=-1; goto done;} // no data
	
	h = (CHARH)_NewHandle(lengthToRead+1);
	if(!h){TechError("TriCurMover::ReadTimeData()", "_NewHandle()", 0); err = memFullErr; goto done;}
	
	_HLock((Handle)h);
	sectionOfFile = *h;			
	
	err = ReadSectionOfFile(0,0,path,offset,lengthToRead,sectionOfFile,0);
	if(err || !h) 
	{
		char firstPartOfLine[128];
		sprintf(errmsg,"Unable to open data file:%s",NEWLINESTRING);
		strncpy(firstPartOfLine,path,120);
		strcpy(firstPartOfLine+120,"...");
		strcat(errmsg,firstPartOfLine);
		goto done;
	}
	sectionOfFile[lengthToRead] = 0; // make it a C string
	
	//numDepths = fVar.maxNumDepths;
	// for now we will always have a full set of velocities
	totalNumberOfVels = (*fDepthDataInfo)[numTris-1].indexToDepthData+(*fDepthDataInfo)[numTris-1].numDepths;
	//totalNumberOfVels = numTris*numDepths;
	if(totalNumberOfVels<numTris) {err=-1; goto done;} // must have at least full set of 2D velocity data
	velH = (VelocityFH)_NewHandleClear(sizeof(**velH)*totalNumberOfVels);
	if(!velH){TechError("TriCurMover::ReadTimeData()", "_NewHandle()", 0); err = memFullErr; goto done;}
	
	strToMatch = "[TIME]";
	len = strlen(strToMatch);
	NthLineInTextOptimized (sectionOfFile, line = 0, s, 256);
	if(!strncmp(s,strToMatch,len)) 
	{
		numScanned=sscanf(s+len, "%hd %hd %hd %hd %hd",
						  &time.day, &time.month, &time.year,
						  &time.hour, &time.minute) ;
		if (numScanned!= 5)
		{ err = -1; TechError("TriCurMover::ReadTimeData()", "sscanf() == 5", 0); goto done; }
		// check for constant current
		if (time.day == -1 && time.month == -1 && time.year == -1 && time.hour == -1 && time.minute == -1)
			//if (time.year == time.month == time.day == time.hour == time.minute == -1) 
		{
			timeSeconds = CONSTANTCURRENT;
		}
		else // time varying current
		{
			if (time.year < 1900)					// two digit date, so fix it
			{
				if (time.year >= 40 && time.year <= 99)	
					time.year += 1900;
				else
					time.year += 2000;					// correct for year 2000 (00 to 40)
			}
			
			time.second = 0;
			DateToSeconds (&time, &timeSeconds);
		}
		
		// check time is correct
		if (timeSeconds!=(*fTimeDataHdl)[index].time)
		{ err = -1;  strcpy(errmsg,"Can't read data - times in the file have changed."); goto done; }
		line++;
	}
	
	
	for(i=0;i<numTris;i++) // interior points
	{
		VelocityRec vel;
		char *startScan;
		long scanLength,stringIndex=0;
		long numDepths = (*fDepthDataInfo)[i].numDepths;	// allow for variable depths/velocites
		//long numDepths = fVar.maxNumDepths;
		
		char *s1 = new char[numDepths*64];
		if(!s1) {TechError("TriCurMover::ReadTimeData()", "new[]", 0); err = memFullErr; goto done;}
		
		NthLineInTextOptimized (sectionOfFile, line, s1, numDepths*64);
		//might want to check that the number of lines matches the number of triangles (ie there is data at every triangle)
		startScan = &s1[stringIndex];
		
		for(j=0;j<numDepths;j++) 
		{
			err = ScanVelocity(startScan,&vel,&scanLength); 
			// ScanVelocity is faster than scanf, but doesn't handle scientific notation. Try a scanf on error.
			if (err)
			{
				if(err!=-2 || sscanf(&s1[stringIndex],lfFix("%lf%lf"),&vel.u,&vel.v) < 2)
				{
					char firstPartOfLine[128];
					sprintf(errmsg,"Unable to read velocity data from line %ld:%s",line,NEWLINESTRING);
					strncpy(firstPartOfLine,s1,120);
					strcpy(firstPartOfLine+120,"...");
					strcat(errmsg,firstPartOfLine);
					delete[] s1; s1=0;
					goto done;
				}
				err = 0;
			}
			(*velH)[(*fDepthDataInfo)[i].indexToDepthData+j].u = vel.u; 
			(*velH)[(*fDepthDataInfo)[i].indexToDepthData+j].v = vel.v; 
			//(*velH)[i*numDepths+j].u = vel.u; 
			//(*velH)[i*numDepths+j].v = vel.v; 
			stringIndex += scanLength;
			startScan = &s1[stringIndex];
		}
		line++;
		delete[] s1; s1=0;
	}
	*velocityH = velH;
	
done:
	
	if(h) {
		_HUnlock((Handle)h); 
		DisposeHandle((Handle)h); 
		h = 0;
	}
	
	
	if(err)
	{
		if(!errmsg[0])
			strcpy(errmsg,"An error occurred in TriCurMover::ReadTimeData");
		//printError(errmsg); // This alert causes a freeze up...
		// We don't want to put up an error message here because it can lead to an infinite loop of messages.
		if(velH) {DisposeHandle((Handle)velH); velH = 0;}
	}
	return err;
	
}