Ejemplo n.º 1
0
void VisionConductor::Load(string pathfile)
{
  // $IT_DATA environmet variable, NULL if not set
  const char *it_data = getenv("IT_DATA");
  string std_it_data;
  if (it_data!=NULL) {
    std_it_data = ConvertPathToStandard(it_data);
  } else {
    std_it_data = "";
  }

  // substitute $IT_DATA environment variable, if requested
  string::size_type pos = pathfile.find("$IT_DATA");
  if (pos!=string::npos) {
    if (it_data==NULL) {
      throw HVEFile(pathfile, "The filename requests the environment variable "
        "$IT_DATA to be set.");
    }
    // substitute "$IT_DATA" for the value of that environment variable
    ReplaceAll(pathfile, "$IT_DATA", std_it_data);
  }

  // all paths in the VisionConductor file "filename" are relative
  // to the path of "filename".  so, let's cd to that directory, load
  // all cascades etc., and in the end restore the previous cwd.
  string old_cwd = GetCWD();
  string vc_path, fname;
  SplitPathFile(pathfile, vc_path, fname);
  VERBOSE1(5, "HandVu: loading supplemental conductor files from path %s",
    vc_path.c_str());
  if (old_cwd!=vc_path) {
    SetCWD(vc_path);
  }

  m_masks.clear();
  m_orig_areas.clear();

  try {
    // the actual parsing function
    ParseFromFile(fname);
  } catch (HVException& hve) {
    if (old_cwd!=vc_path) {
      SetCWD(old_cwd);
    }
    throw HVException(hve.GetMessage() + "\n" +
      "note: paths in VisionConductor files are relative;\n"
      "in this case to " + vc_path);
  }

  if (old_cwd!=vc_path) {
    SetCWD(old_cwd);
  }

  SanityCheckMasks();

  m_is_loaded = true;
}
Ejemplo n.º 2
0
TOSSMTimeValue* LoadTOSSMTimeValue(TMover *theOwner, short unitsIfKnownInAdvance)
{
	char path[256],shortFileName[256];
	char tempStr[256];
	Point where = CenteredDialogUpLeft(M38d);
	WorldPoint p;
	OSType typeList[] = { 'NULL', 'NULL', 'NULL', 'NULL' };
	MySFReply reply;
	OSErr err = 0;
	
#if TARGET_API_MAC_CARBON
	mysfpgetfile(&where, "", -1, typeList,
				 (MyDlgHookUPP)0, &reply, M38d, MakeModalFilterUPP(STDFilter));
	if (!reply.good) return 0;
	strcpy(path, reply.fullPath);
	strcpy(tempStr,path);
	SplitPathFile(tempStr,shortFileName);
#else
	sfpgetfile(&where, "",
			   (FileFilterUPP)0,
			   -1, typeList,
			   (DlgHookUPP)0,
			   &reply, M38d,
			   (ModalFilterUPP)MakeUPP((ProcPtr)STDFilter, uppModalFilterProcInfo));
	
	if (!reply.good) return nil; // user canceled
	
	my_p2cstr(reply.fName);
#ifdef MAC
	GetFullPath(reply.vRefNum, 0, (char *)reply.fName, path);
	strcpy(shortFileName,(char*) reply.fName);
#else
	strcpy(path, reply.fName);
	strcpy(tempStr,path);
	SplitPathFile(tempStr,shortFileName);
#endif
#endif	
	
	//	return  CreateTOSSMTimeValue(theOwner,path,shortFileName,kUndefined);	// ask user for units 
	return  CreateTOSSMTimeValue(theOwner,path,shortFileName,unitsIfKnownInAdvance);	// ask user for units 
}
Ejemplo n.º 3
0
Map3D* CreateAndInitMap3D(char *path, WorldRect bounds)
{
	char 		nameStr[256];
	OSErr		err = noErr;
	Map3D 	*map = nil;
	char fileName[256],s[256];
	
	if (path[0])
	{
		strcpy(s,path);
		SplitPathFile (s, fileName);
		strcpy (nameStr, "BathymetryMap: ");
		strcat (nameStr, fileName);
	}
	else
		strcpy(nameStr,"Bathymetry Map");
	map = new Map3D(nameStr, bounds);
	if (!map)
	{ TechError("AddMap3D()", "new Map3D()", 0); return nil; }
	
	if (err = map->InitMap()) { delete map; return nil; }
	
	return map;
}
Ejemplo n.º 4
0
ADCPTimeValue*	ADCPMover_c::AddADCP(OSErr *err)
{	// might send in path for first adcp
	*err = 0;
	char tempStr[128], shortFileName[64], givenPath[256], givenFileName[64], s[256], fileName[64], path[256];
	short unitsIfKnownInAdvance = 0;
	Boolean askForFile = true;
	ADCPTimeValue *timeValObj = 0;
	
	Point where = CenteredDialogUpLeft(M38c);;
	OSType typeList[] = { 'NULL', 'NULL', 'NULL', 'NULL' };
	MySFReply reply;
	
	//if(askForFile || !givenPath || !givenFileName)
	{
#if TARGET_API_MAC_CARBON
		mysfpgetfile(&where, "", -1, typeList,
					 (MyDlgHookUPP)0, &reply, M38c, MakeModalFilterUPP(STDFilter));
		if (!reply.good) return 0;
		strcpy(path, reply.fullPath);
#else
		sfpgetfile(&where, "",
				   (FileFilterUPP)0,
				   -1, typeList,
				   (DlgHookUPP)0,
				   &reply, M38c,
				   (ModalFilterUPP)MakeUPP((ProcPtr)STDFilter, uppModalFilterProcInfo));
		if (!reply.good) return 0;
		
		my_p2cstr(reply.fName);
#ifdef MAC
		GetFullPath(reply.vRefNum, 0, (char *)reply.fName, path);
#else
		strcpy(path, reply.fName);
#endif
#endif		
		strcpy (s, path);
		SplitPathFile (s, fileName);
	}
	/*else
	 {	// don't ask user, we were provided with the path
	 strcpy(path,givenPath);
	 strcpy(fileName,givenFileName);
	 }*/
	
	if (IsADCPFile(path))
	{
		timeValObj = new ADCPTimeValue(dynamic_cast<ADCPMover *>(this));
		//timeDep = new ADCPTimeValue(this);
		
		if (!timeValObj)
		{ TechError("TextRead()", "new ADCPTimeValue()", 0); return nil; }
		
		*err = timeValObj->InitTimeFunc();
		if(*err) {delete timeValObj; timeValObj = nil; return nil;}  
		
		*err = timeValObj->ReadTimeValues (path, M19REALREAL, unitsIfKnownInAdvance);
		if(*err) { delete timeValObj; timeValObj = nil; return nil;}
		timeValObj->SetTimeFileName(fileName);
		//return timeValObj;
		//AddTimeDep(timeValObj,0);
	}	
	// code goes here, add code for OSSMHeightFiles, need scale factor to calculate derivative
	else
	{
		sprintf(tempStr,"File %s is not a recognizable ADCP time file.",shortFileName);
		printError(tempStr);
	}
	return timeValObj;
}
Ejemplo n.º 5
0
OSErr AddMapsDialog2()
{
	char 		path[256], nameStr [256], shortFileName[256], tempStr[256];
	OSErr		err = noErr;
	long 		n;
	Point 		where = CenteredDialogUpLeft(M38b);
	TVectorMap	*vMap;
	TOSSMMap 	*oMap;
	Map3D 		*gMap;
	GridMap_c *gridMap = 0;
	OSType 	typeList[] = { 'NULL', 'NULL', 'NULL', 'NULL' };
	MySFReply 	reply;
	WorldRect	theRect = emptyWorldRect;
	short 		gridType;
	Boolean		isESI = false;
	float arrowDepth = 0;

#if TARGET_API_MAC_CARBON
		mysfpgetfile(&where, "", -1, typeList,
				   (MyDlgHookUPP)0, &reply, M38b, MakeModalFilterUPP(STDFilter));
		if (!reply.good) return USERCANCEL;
		strcpy(path, reply.fullPath);
		strcpy(tempStr,path);
		SplitPathFile(tempStr,shortFileName);
#else
	sfpgetfile(&where, "",
			   (FileFilterUPP)0,
			   -1, typeList,
			   (DlgHookUPP)0,
			   &reply, M38b,
			   (ModalFilterUPP)MakeUPP((ProcPtr)STDFilter, uppModalFilterProcInfo));
	if (!reply.good) return USERCANCEL;

	my_p2cstr(reply.fName);
	#ifdef MAC
		GetFullPath(reply.vRefNum, 0, (char *)reply.fName, path);
		strcpy(shortFileName,(char*) reply.fName);
	#else
		strcpy(path, reply.fName);
		strcpy(tempStr,path);
		SplitPathFile(tempStr,shortFileName);
	#endif
#endif	
	if (IsVectorMap (path, &isESI))
	{
		if (isESI) {printNote("File is ESI segments not map polygons");err=-1; return err;}
		strcpy (nameStr, "Vector Map: ");
		strcat (nameStr, shortFileName);
	
		vMap = (TVectorMap*) new TVectorMap (nameStr, theRect);
		if (!vMap)
			{ TechError("AddMapsDialog()", "new TVectorMap()", 0); return -1; }

		if (err = vMap -> InitMap(path)) { delete vMap; return err; }
	
		if (err = model->AddMap(vMap, 0))
		{
			vMap -> Dispose ();
			delete vMap;
			err = -1;
		}
	}
	else if (IsGridMap (path))
	{
		strcpy (nameStr, "Grid Map: ");
		strcat (nameStr, shortFileName);

		oMap = new TOSSMMap(nameStr, voidWorldRect);
		if (!oMap)
			{ TechError("AddMapsDialog()", "new TOSSMMap()", 0); return -1; }
	
		if (err = ((TOSSMMap*) oMap) -> InitMap(path)) { delete oMap; return err; }
	
		if (err = model->AddMap(oMap, 0))
		{
			oMap -> Dispose ();
			delete oMap;
			err = -1;
		}
	}
	else if (IsPtCurFile (path))
	{
		TMap *newMap = 0;
		TCurrentMover *newMover = CreateAndInitCurrentsMover (model->uMap,false,path,"ptcurfile",&newMap);	// already have path
		
		if (newMover)
		{
			PtCurMover *ptCurMover = dynamic_cast<PtCurMover*>(newMover);
			err = ptCurMover -> SettingsDialog();
			if(err)	
			{ 
				newMover->Dispose(); delete newMover; newMover = 0;
				if (newMap) {newMap->Dispose(); delete newMap; newMap = 0;} 
			}
	
			if(newMover && !err)
			{
				Boolean timeFileChanged = false;
				if (!newMap) 
				{
					err = AddMoverToMap (model->uMap, timeFileChanged, newMover);
				}
				else
				{
					err = model -> AddMap(newMap, 0);
					if (!err) err = AddMoverToMap(newMap, timeFileChanged, newMover);
					//if(!err) err = ((PtCurMap*)newMap)->MakeBitmaps();
					if (!err) newMover->SetMoverMap(newMap);
					if (model->ThereIsA3DMover(&arrowDepth)) InitAnalysisMenu();	// want to have it come and go?
					else 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
				}
			}
		}
	}
	else if (IsNetCDFFile (path, &gridType))
	{
		TMap *newMap = 0;
		
		char s[256],fileName[256], outPath[256];
		WorldRect bounds = theWorld;

		strcpy(s,path);
		SplitPathFile (s, fileName);
		strcat (nameStr, fileName);
		gMap = CreateAndInitMap3D (path,bounds);	// need to fix bounds afterwards
		
		if (gMap && gridType!=REGULAR && gridType!=REGULAR_SWAFS)
		{
			FLOATH depthPtsH = 0;
			WORLDPOINTFH vertexPtsH=0;
			long numRows=0, numCols=0, numNodes=0, numTri=0, numBoundaryPts=0;
			char errmsg[256];
			gridMap = new GridMap_c();
			
#if TARGET_API_MAC_CARBON
			err = ConvertTraditionalPathToUnixPath((const char *) path, outPath, kMaxNameLen) ;
			//if (!err) strcpy(path,outPath);
#else
			strcpy(outPath,path);
#endif

			if (gridType == CURVILINEAR)
			{
				DOUBLEH maskH = 0;
				//err = gMap->GetPointsAndMask(path,&maskH,&vertexPtsH,&depthPtsH,&numRows, &numCols);	//Text read	
				//if (!err) err = gMap->SetUpCurvilinearGrid(maskH,numRows,numCols,vertexPtsH,depthPtsH,errmsg);	//Reorder points
				err = gridMap->GetPointsAndMask(outPath,&maskH,&vertexPtsH,&depthPtsH,&numRows, &numCols);	//Text read	
				if (!err) err = gridMap->SetUpCurvilinearGrid(maskH,numRows,numCols,vertexPtsH,depthPtsH,errmsg);	//Reorder points
				if(maskH) {DisposeHandle((Handle)maskH); maskH = 0;}
			}
			else if (gridType == TRIANGULAR)
			{	// check if topology is included
				LONGPTR bndry_indices=0, bndry_nums=0, bndry_type=0, tri_verts=0, tri_neighbors=0;
				//err = gMap->GetPointsAndBoundary(path,&vertexPtsH,&depthPtsH, &numNodes, &bndry_indices, &bndry_nums, &bndry_type, &numBoundaryPts, &tri_verts, &tri_neighbors, &numTri);	//Text read	
				err = gridMap->GetPointsAndBoundary(outPath,&vertexPtsH,&depthPtsH, &numNodes, &bndry_indices, &bndry_nums, &bndry_type, &numBoundaryPts, &tri_verts, &tri_neighbors, &numTri);	//Text read	
				if (!err) 
				{	// separate points and boundary
					if (numTri == 0)
						//err = gMap->SetUpTriangleGrid(numNodes,numTri,vertexPtsH,depthPtsH, bndry_indices, bndry_nums, bndry_type, numBoundaryPts);	//Reorder points
						err = gridMap->SetUpTriangleGrid(numNodes,numTri,vertexPtsH,depthPtsH, bndry_indices, bndry_nums, bndry_type, numBoundaryPts);	//Reorder points
					else
						//err = gMap->SetUpTriangleGrid2(numNodes,numTri,vertexPtsH,depthPtsH, bndry_indices, bndry_nums, bndry_type, numBoundaryPts,tri_verts, tri_neighbors);	//Reorder points
						err = gridMap->SetUpTriangleGrid2(numNodes,numTri,vertexPtsH,depthPtsH, bndry_indices, bndry_nums, bndry_type, numBoundaryPts,tri_verts, tri_neighbors);	//Reorder points
				
				}
				if (bndry_indices) delete [] bndry_indices;
				if (bndry_nums) delete [] bndry_nums;
				if (bndry_type) delete [] bndry_type;
				if (tri_verts) delete [] tri_verts;
				if (tri_neighbors) delete [] tri_neighbors;
			}
			if(vertexPtsH) {DisposeHandle((Handle)vertexPtsH); vertexPtsH = 0;}
			if(depthPtsH) {DisposeHandle((Handle)depthPtsH); depthPtsH = 0;}
			if( !err) 
			{
				gMap->SetBoundarySegs(gridMap->GetBoundarySegs());
				gMap->SetWaterBoundaries(gridMap->GetWaterBoundaries());
				gMap->SetBoundaryPoints(gridMap->GetBoundaryPoints());
				gMap->SetGrid(gridMap->GetGrid());
				gMap->SetMapBounds(gridMap->GetMapBounds());
				err = gMap->MakeBitmaps();
			}
			if (!err) err = model->AddMap(gMap, 0);
			if (err)
			{
				gMap -> Dispose ();
				delete gMap;
				err = -1;
			}
		}
		else
		{
			err = true;
			sprintf(tempStr,"File %s is a current file and should be input as a universal mover.",shortFileName);
			printNote(tempStr);
		}
	}
	else if (IsTriCurFile (path))
	{
		TMap *newMap = 0;
		TCurrentMover *newMover = CreateAndInitCurrentsMover (model->uMap,false,path,"TriCurFile",&newMap);	// already have path
		
		if (newMover)
		{
			TriCurMover *triCurMover = dynamic_cast<TriCurMover *>(newMover);
			err = triCurMover -> SettingsDialog();
			if(err)	
			{ 
				newMover->Dispose(); delete newMover; newMover = 0;
				if (newMap) {newMap->Dispose(); delete newMap; newMap = 0;} 
			}
	
			if(newMover && !err)
			{
				Boolean timeFileChanged = false;
				if (!newMap) 
				{
					err = AddMoverToMap (model->uMap, timeFileChanged, newMover);
				}
				else
				{
					err = model -> AddMap(newMap, 0);
					if (err) 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
					err = AddMoverToMap(newMap, timeFileChanged, newMover);
					if(err) 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
					/*err = ((PtCurMap*)newMap)->MakeBitmaps();
					if(err) 
					{
						newMap->Dispose(); delete newMap; newMap = 0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}*/
					newMover->SetMoverMap(newMap);
					if (model->ThereIsA3DMover(&arrowDepth)) InitAnalysisMenu();	// want to have it come and go?
				}
			}
		}
		else
		{
			err = true;
			sprintf(tempStr,"File %s is a current file and should be input as a universal mover.",shortFileName);
			printNote(tempStr);
		}
	}
	else if (IsCATS3DFile (path))	// for any CATS?
	{
		char s[256],fileName[256];
		WorldRect bounds = theWorld;

		strcpy(s,path);
		SplitPathFile (s, fileName);
		strcat (nameStr, fileName);
		gMap = CreateAndInitMap3D (path,bounds);	// need to fix bounds afterwards
		
		if (gMap)
		{
			gridMap = new GridMap_c();
			if (!gridMap) {err = gMap->ReadCATSMap(path);/*err = -1;*/}
			else
				//err = gMap->ReadCATSMap(path);
				err = gridMap->ReadCATSMap(path);	
			if(!err) 
			{	
				if (gridMap)
				{
					gMap->SetBoundarySegs(gridMap->GetBoundarySegs());
					gMap->SetWaterBoundaries(gridMap->GetWaterBoundaries());
					gMap->SetBoundaryPoints(gridMap->GetBoundaryPoints());
					gMap->SetGrid(gridMap->GetGrid());
					gMap->SetMapBounds(gridMap->GetMapBounds());
				}
				err = gMap->MakeBitmaps();
			}

			if (err = model->AddMap(gMap, 0))
			{
				gMap -> Dispose ();
				delete gMap;
				err = -1;
			}
		}
	}
	else
	{
		WorldRect bounds = theWorld;
		gMap = CreateAndInitMap3D (path,bounds);	// need to fix bounds afterwards
		if (gMap)
		{
			gridMap = new GridMap_c();
			if (!gridMap) {err = gMap -> ReadTopology(path);/*err = -1;*/}
			else 
				//err = gMap -> ReadTopology(path);
				err = gridMap -> ReadTopology(path);
			if(!err) 
			{
				if (gridMap)
				{
					gMap->SetBoundarySegs(gridMap->GetBoundarySegs());
					gMap->SetWaterBoundaries(gridMap->GetWaterBoundaries());
					gMap->SetBoundaryPoints(gridMap->GetBoundaryPoints());
					gMap->SetGrid(gridMap->GetGrid());
					gMap->SetMapBounds(gridMap->GetMapBounds());
				}
				err = gMap->MakeBitmaps();
			}
			if (err = model->AddMap(gMap, 0))
			{
				gMap -> Dispose ();
				delete gMap;
				err = -1;
			}
		}
		//err = true;
		if (err)
		{sprintf(tempStr,"File %s is not a recognizable map file.",shortFileName);
		printError(tempStr);}
	}

	if (!err)
	{
		model->NewDirtNotification();
	}

	return err;
}
Ejemplo n.º 6
0
OSErr AddMapsDialog()
{
	char 		path[256], nameStr [256], shortFileName[256], tempStr[256];
	OSErr		err = noErr;
	long 		n;
	Point 		where = CenteredDialogUpLeft(M38b);
	TVectorMap	*vMap;
	TOSSMMap 	*oMap;
	OSType 	typeList[] = { 'NULL', 'NULL', 'NULL', 'NULL' };
	MySFReply 	reply;
	WorldRect	theRect = emptyWorldRect;
	short 		gridType;
	Boolean		isESI = false;
	float arrowDepth = 0;

#if TARGET_API_MAC_CARBON
		mysfpgetfile(&where, "", -1, typeList,
				   (MyDlgHookUPP)0, &reply, M38b, MakeModalFilterUPP(STDFilter));
		if (!reply.good) return USERCANCEL;
		strcpy(path, reply.fullPath);
		strcpy(tempStr,path);
		SplitPathFile(tempStr,shortFileName);
#else
	sfpgetfile(&where, "",
			   (FileFilterUPP)0,
			   -1, typeList,
			   (DlgHookUPP)0,
			   &reply, M38b,
			   (ModalFilterUPP)MakeUPP((ProcPtr)STDFilter, uppModalFilterProcInfo));
	if (!reply.good) return USERCANCEL;

	my_p2cstr(reply.fName);
	#ifdef MAC
		GetFullPath(reply.vRefNum, 0, (char *)reply.fName, path);
		strcpy(shortFileName,(char*) reply.fName);
	#else
		strcpy(path, reply.fName);
		strcpy(tempStr,path);
		SplitPathFile(tempStr,shortFileName);
	#endif
#endif	
	if (IsVectorMap (path, &isESI))
	{
		if (isESI) {printNote("File is ESI segments not map polygons");err=-1; return err;}
		strcpy (nameStr, "Vector Map: ");
		strcat (nameStr, shortFileName);
	
		vMap = (TVectorMap*) new TVectorMap (nameStr, theRect);
		if (!vMap)
			{ TechError("AddMapsDialog()", "new TVectorMap()", 0); return -1; }

		if (err = vMap -> InitMap(path)) { delete vMap; return err; }
	
		if (err = model->AddMap(vMap, 0))
		{
			vMap -> Dispose ();
			delete vMap;
			err = -1;
		}
	}
	else if (IsGridMap (path))
	{
		strcpy (nameStr, "Grid Map: ");
		strcat (nameStr, shortFileName);

		oMap = new TOSSMMap(nameStr, voidWorldRect);
		if (!oMap)
			{ TechError("AddMapsDialog()", "new TOSSMMap()", 0); return -1; }
	
		if (err = ((TOSSMMap*) oMap) -> InitMap(path)) { delete oMap; return err; }
	
		if (err = model->AddMap(oMap, 0))
		{
			oMap -> Dispose ();
			delete oMap;
			err = -1;
		}
	}
	else if (IsPtCurFile (path))
	{
		TMap *newMap = 0;
		TCurrentMover *newMover = CreateAndInitCurrentsMover (model->uMap,false,path,"ptcurfile",&newMap);	// already have path
		
		if (newMover)
		{
			PtCurMover *ptCurMover = dynamic_cast<PtCurMover*>(newMover);
			err = ptCurMover -> SettingsDialog();
			if(err)	
			{ 
				newMover->Dispose(); delete newMover; newMover = 0;
				if (newMap) {newMap->Dispose(); delete newMap; newMap = 0;} 
			}
	
			if(newMover && !err)
			{
				Boolean timeFileChanged = false;
				if (!newMap) 
				{
					err = AddMoverToMap (model->uMap, timeFileChanged, newMover);
				}
				else
				{
					err = model -> AddMap(newMap, 0);
					if (!err) err = AddMoverToMap(newMap, timeFileChanged, newMover);
					//if(!err) err = ((PtCurMap*)newMap)->MakeBitmaps();
					if (!err) newMover->SetMoverMap(newMap);
					if (model->ThereIsA3DMover(&arrowDepth)) InitAnalysisMenu();	// want to have it come and go?
					else 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
				}
			}
		}
	}
	else if (IsNetCDFFile (path, &gridType))
	{
		TMap *newMap = 0;
		TCurrentMover *newMover = CreateAndInitCurrentsMover (model->uMap,false,path,"NetCDFfile",&newMap);	// already have path
		
		if (newMover && gridType!=REGULAR && gridType!=REGULAR_SWAFS)	// should probably get rid of the SWAFS grid type and generalize a regular navy
		{
			NetCDFMover *netCDFMover = dynamic_cast<NetCDFMover *>(newMover);
			err = netCDFMover -> SettingsDialog();
			if(err)	
			{ 
				newMover->Dispose(); delete newMover; newMover = 0;
				if (newMap) {newMap->Dispose(); delete newMap; newMap = 0;} 
			}
	
			if(newMover && !err)
			{
				Boolean timeFileChanged = false;
				if (!newMap) 
				{
					err = AddMoverToMap (model->uMap, timeFileChanged, newMover);
				}
				else
				{
					err = model -> AddMap(newMap, 0);
					if (!err) err = AddMoverToMap(newMap, timeFileChanged, newMover);
					// if (!err) err = ((PtCurMap*)newMap)->MakeBitmaps();
					if (!err) newMover->SetMoverMap(newMap);
					if (model->ThereIsA3DMover(&arrowDepth)) InitAnalysisMenu();	// want to have it come and go?
					else 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
				}
			}
		}
		else
		{
			err = true;
			sprintf(tempStr,"File %s is a current file and should be input as a universal mover.",shortFileName);
			printNote(tempStr);
		}
	}
	else if (IsTriCurFile (path))
	{
		TMap *newMap = 0;
		TCurrentMover *newMover = CreateAndInitCurrentsMover (model->uMap,false,path,"TriCurFile",&newMap);	// already have path
		
		if (newMover)
		{
			TriCurMover *triCurMover = dynamic_cast<TriCurMover *>(newMover);
			err = triCurMover -> SettingsDialog();
			if(err)	
			{ 
				newMover->Dispose(); delete newMover; newMover = 0;
				if (newMap) {newMap->Dispose(); delete newMap; newMap = 0;} 
			}
	
			if(newMover && !err)
			{
				Boolean timeFileChanged = false;
				if (!newMap) 
				{
					err = AddMoverToMap (model->uMap, timeFileChanged, newMover);
				}
				else
				{
					err = model -> AddMap(newMap, 0);
					if (err) 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
					err = AddMoverToMap(newMap, timeFileChanged, newMover);
					if(err) 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
					/*err = ((PtCurMap*)newMap)->MakeBitmaps();
					if(err) 
					{
						newMap->Dispose(); delete newMap; newMap = 0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}*/
					newMover->SetMoverMap(newMap);
					if (model->ThereIsA3DMover(&arrowDepth)) InitAnalysisMenu();	// want to have it come and go?
				}
			}
		}
		else
		{
			err = true;
			sprintf(tempStr,"File %s is a current file and should be input as a universal mover.",shortFileName);
			printNote(tempStr);
		}
	}
	else if (IsCATS3DFile (path))
	{
		TMap *newMap = 0;
		char s[256],fileName[256];
		TCurrentMover *newMover = 0;
		Boolean	timeFileChanged = false;

		strcpy(s,path);
		SplitPathFile (s, fileName);
		strcat (nameStr, fileName);
		newMover = CreateAndInitCurrentsMover (model->uMap,false,path,fileName,&newMap);	// already have path
		
		if (newMover)
		{
			TCATSMover3D *catsMover3D = dynamic_cast<TCATSMover3D *>(newMover);
			err = CATSSettingsDialog (dynamic_cast<TCATSMover *>(newMover), model->uMap, &timeFileChanged);
			if(err)	
			{ 
				newMover->Dispose(); delete newMover; newMover = 0;
				if (newMap) {newMap->Dispose(); delete newMap; newMap = 0;} 
			}
	
			if(newMover && !err)
			{
				Boolean timeFileChanged = false;
				if (!newMap) 
				{
					err = AddMoverToMap (model->uMap, timeFileChanged, newMover);
				}
				else
				{
					err = model -> AddMap(newMap, 0);
					if (err) 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
					err = AddMoverToMap(newMap, timeFileChanged, newMover);
					if(err) 
					{
						newMap->Dispose(); delete newMap; newMap =0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}
					/*err = ((PtCurMap*)newMap)->MakeBitmaps();
					if(err) 
					{
						newMap->Dispose(); delete newMap; newMap = 0; 
						newMover->Dispose(); delete newMover; newMover = 0;
						return -1; 
					}*/
					newMover->SetMoverMap(newMap);
					if (model->ThereIsA3DMover(&arrowDepth)) InitAnalysisMenu();	// want to have it come and go?
				}
			}
		}
	}
	else
	{
		err = true;
		sprintf(tempStr,"File %s is not a recognizable map file.",shortFileName);
		printError(tempStr);
	}

	if (!err)
	{
		model->NewDirtNotification();
	}

	return err;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
OSErr TShioTimeValue::ReadTimeValues (char *path, short format, short unitsIfKnownInAdvance)
{
	// code goes here, use unitsIfKnownInAdvance to tell if we're coming from a location file, 
	// if not and it's a heights file ask if progressive or standing wave (add new field or track as 'P')
	//#pragma unused(unitsIfKnownInAdvance)	
	char strLine[kMaxKeyedLineLength];
	long i,numValues;
	double value1, value2, magnitude, degrees;
	CHARH f = 0;
	DateTimeRec time;
	TimeValuePair pair;
	OSErr	err = noErr,scanErr;
	long lineNum = 0;
	char *p;
	long numScanned;
	double value, stationLat, stationLon;
	CONTROLVAR  DatumControls;
	
	if (err = OSSMTimeValue_c::InitTimeFunc()) return err;
	
	timeValues = 0;
	fileName[0] = 0;
	
	if (!path) return -1;
	
	strcpy(strLine, path);
	SplitPathFile(strLine, this->fileName);
	
	err = ReadFileContents(TERMINATED, 0, 0, path, 0, 0, &f);
	if(err)	{ TechError("TShioTimeValue::ReadTimeValues()", "ReadFileContents()", 0); return -1; }
	
	lineNum = 0;
	// first line
	if(!(p = GetKeyedLine(f, "[StationInfo]",lineNum++,strLine)))  goto readError;
	// 2nd line
	if(!(p = GetKeyedLine(f, "Type=",lineNum++,strLine)))  goto readError;
	switch(p[0])
	{
			//case 'c': case 'C': this->fStationType = 'C'; break;
			//case 'h': case 'H': this->fStationType = 'H'; break;
			//case 'p': case 'P': this->fStationType = 'P';	// for now assume progressive waves selected in file, maybe change to user input
		case 'c': case 'C': 
			this->fStationType = 'C'; break;
		case 'h': case 'H': 
			this->fStationType = 'H'; 
		{
			// if not a location file, Ask user if this is a progressive or standing wave
			// also ask for scale factor here
			/*if (unitsIfKnownInAdvance==kFudgeFlag)
			 {
			 short buttonSelected;
			 buttonSelected  = MULTICHOICEALERT(1690,"The file you selected is a shio heights file. Are you sure you want to treat it as a progressive wave?",TRUE);
			 switch(buttonSelected){
			 case 1:// continue, treat as progressive wave
			 this->fStationType = 'P';
			 break;  
			 case 3: // cancel
			 //return 0;// leave as standing wave?
			 return -1;
			 break;
			 }
			 //printNote("The shio heights file will be treated as a progressive wave file");
			 //this->fStationType = 'P';
			 }*/
			if (unitsIfKnownInAdvance!=-2)	// not a location file
			{
				Boolean bStandingWave = true;
				float scaleFactor = fScaleFactor;
				err = ShioHtsDialog(&bStandingWave,&scaleFactor,mapWindow);
				if (!err)
				{
					if (!bStandingWave) this->fStationType = 'P';
					//this->fScaleFactor = scaleFactor;
				}
			}
		}
			break;
		case 'p': case 'P': 
			this->fStationType = 'P';	// for now assume progressive waves selected in file, maybe change to user input
			
			//printError("You have selected a SHIO heights file.  Only SHIO current files can be used in GNOME.");
			//return -1;
			break;	// Allow heights files to be read in 9/18/00
		default:	goto readError; 	
	}
	// 3nd line
	if(!(p = GetKeyedLine(f, "Name=",lineNum++,strLine)))  goto readError;
	strncpy(this->fStationName,p,MAXSTATIONNAMELEN);
	this->fStationName[MAXSTATIONNAMELEN-1] = 0;
	// 
	if(err = this->GetKeyedValue(f,"Latitude=",lineNum++,strLine,&stationLat))  goto readError;
	if(err = this->GetKeyedValue(f,"Longitude=",lineNum++,strLine,&stationLon))  goto readError;

	this->fStationPosition.p.pLat = stationLat * 1000000;
	this->fStationPosition.p.pLong = stationLon * 1000000;
	
	//
	if(!(p = GetKeyedLine(f, "[Constituents]",lineNum++,strLine)))  goto readError;
	// code goes here in version 1.2.7 these lines won't be required for height files, but should still allow old format
	//if(err = this->GetKeyedValue(f,"DatumControls.datum=",lineNum++,strLine,&this->fConstituent.DatumControls.datum))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.datum=",lineNum++,strLine,&this->fConstituent.DatumControls.datum))  
	{
		if(this->fStationType=='h' || this->fStationType=='H')
		{
			lineNum--;	// possibly new Shio output which eliminated the unused datumcontrols for height files
			goto skipDatumControls;
		}
		else
		{
			goto readError;
		}
	}
	if(err = this->GetKeyedValue(f,"DatumControls.FDir=",lineNum++,strLine,&this->fConstituent.DatumControls.FDir))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.EDir=",lineNum++,strLine,&this->fConstituent.DatumControls.EDir))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.L2Flag=",lineNum++,strLine,&this->fConstituent.DatumControls.L2Flag))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.HFlag=",lineNum++,strLine,&this->fConstituent.DatumControls.HFlag))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.RotFlag=",lineNum++,strLine,&this->fConstituent.DatumControls.RotFlag))  goto readError;
	
skipDatumControls:
	if(err = this->GetKeyedValue(f,"H=",lineNum++,strLine,&this->fConstituent.H))  goto readError;
	if(err = this->GetKeyedValue(f,"kPrime=",lineNum++,strLine,&this->fConstituent.kPrime))  goto readError;
	
	if(!(p = GetKeyedLine(f, "[Offset]",lineNum++,strLine)))  goto readError;
	
	switch(this->fStationType)
	{
		case 'c': case 'C': 
			if(err = this->GetKeyedValue(f,"MinBefFloodTime=",lineNum++,strLine,&this->fCurrentOffset.MinBefFloodTime))  goto readError;
			if(err = this->GetKeyedValue(f,"FloodTime=",lineNum++,strLine,&this->fCurrentOffset.FloodTime))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBefEbbTime=",lineNum++,strLine,&this->fCurrentOffset.MinBefEbbTime))  goto readError;
			if(err = this->GetKeyedValue(f,"EbbTime=",lineNum++,strLine,&this->fCurrentOffset.EbbTime))  goto readError;
			if(err = this->GetKeyedValue(f,"FloodSpdRatio=",lineNum++,strLine,&this->fCurrentOffset.FloodSpdRatio))  goto readError;
			if(err = this->GetKeyedValue(f,"EbbSpdRatio=",lineNum++,strLine,&this->fCurrentOffset.EbbSpdRatio))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBFloodSpd=",lineNum++,strLine,&this->fCurrentOffset.MinBFloodSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBFloodDir=",lineNum++,strLine,&this->fCurrentOffset.MinBFloodDir))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxFloodSpd=",lineNum++,strLine,&this->fCurrentOffset.MaxFloodSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxFloodDir=",lineNum++,strLine,&this->fCurrentOffset.MaxFloodDir))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBEbbSpd=",lineNum++,strLine,&this->fCurrentOffset.MinBEbbSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBEbbDir=",lineNum++,strLine,&this->fCurrentOffset.MinBEbbDir))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxEbbSpd=",lineNum++,strLine,&this->fCurrentOffset.MaxEbbSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxEbbDir=",lineNum++,strLine,&this->fCurrentOffset.MaxEbbDir))  goto readError;
			SetFileType(SHIOCURRENTSFILE);
			break;
		case 'h': case 'H': 
			if(err = this->GetKeyedValue(f,"HighTime=",lineNum++,strLine,&this->fHeightOffset.HighTime))  goto readError;
			if(err = this->GetKeyedValue(f,"LowTime=",lineNum++,strLine,&this->fHeightOffset.LowTime))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Add=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Add))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Add=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Add))  goto readError;
			SetFileType(SHIOHEIGHTSFILE);
			break;
		case 'p': case 'P': 
			if(err = this->GetKeyedValue(f,"HighTime=",lineNum++,strLine,&this->fHeightOffset.HighTime))  goto readError;
			if(err = this->GetKeyedValue(f,"LowTime=",lineNum++,strLine,&this->fHeightOffset.LowTime))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Add=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Add))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Add=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Add))  goto readError;
			SetFileType(PROGRESSIVETIDEFILE);
			break;
	}
	
	
	if(f) DisposeHandle((Handle)f); f = nil;
	return 0;
	
readError:
	if(f) DisposeHandle((Handle)f); f = nil;
	sprintf(strLine,"Error reading SHIO time file %s on line %ld",this->fileName,lineNum);
	printError(strLine);
	this->Dispose();
	return -1;
	
Error:
	if(f) DisposeHandle((Handle)f); f = nil;
	return -1;
	
}
Ejemplo n.º 9
0
//=================================================================
// Methods for DumpModelTEP
//
int DumpModelTEP::callback(INode *pnode)
{
	Object*	pobj;
	int	fHasMat = TRUE;

	// clear physique export parameters
	m_mcExport = NULL;
	m_phyExport = NULL;
    m_phyMod = NULL;

	ASSERT_MBOX(!(pnode)->IsRootNode(), "Encountered a root node!");

	if (::FNodeMarkedToSkip(pnode))
		return TREE_CONTINUE;
	
	int iNode = ::GetIndexOfINode(pnode);
	TSTR strNodeName(pnode->GetName());
	
	// The Footsteps node apparently MUST have a dummy mesh attached!  Ignore it explicitly.
	if (FStrEq((char*)strNodeName, "Bip01 Footsteps"))
		return TREE_CONTINUE;

	// Helper nodes don't have meshes
	pobj = pnode->GetObjectRef();
	if (pobj->SuperClassID() == HELPER_CLASS_ID)
		return TREE_CONTINUE;

	// The model's root is a child of the real "scene root"
	INode *pnodeParent = pnode->GetParentNode();
	BOOL fNodeIsRoot = pnodeParent->IsRootNode( );

	// Get node's material: should be a multi/sub (if it has a material at all)
	Mtl *pmtlNode = pnode->GetMtl();
	if (pmtlNode == NULL)
	{
		return TREE_CONTINUE;
		fHasMat = FALSE;
	}
	else if (!(pmtlNode->ClassID() == Class_ID(MULTI_CLASS_ID, 0) && pmtlNode->IsMultiMtl()))
	{
		// sprintf(st_szDBG, "ERROR--Material on node %s isn't a Multi/Sub-Object", (char*)strNodeName);
		// ASSERT_AND_ABORT(FALSE, st_szDBG);
		fHasMat = FALSE;
	}
	
	// Get Node's object, convert to a triangle-mesh object, so I can access the Faces
	ObjectState os = pnode->EvalWorldState(m_tvToDump);
	pobj = os.obj;
	TriObject *ptriobj;
	BOOL fConvertedToTriObject = 
		pobj->CanConvertToType(triObjectClassID) &&
		(ptriobj = (TriObject*)pobj->ConvertToType(m_tvToDump, triObjectClassID)) != NULL;
	if (!fConvertedToTriObject)
		return TREE_CONTINUE;
	Mesh *pmesh = &ptriobj->mesh;

	// Shouldn't have gotten this far if it's a helper object
	if (pobj->SuperClassID() == HELPER_CLASS_ID)
	{
		sprintf(st_szDBG, "ERROR--Helper node %s has an attached mesh, and it shouldn't.", (char*)strNodeName);
		ASSERT_AND_ABORT(FALSE, st_szDBG);
	}

	// Ensure that the vertex normals are up-to-date
	pmesh->buildNormals();

	// We want the vertex coordinates in World-space, not object-space
	Matrix3 mat3ObjectTM = pnode->GetObjectTM(m_tvToDump);


	// initialize physique export parameters
    m_phyMod = FindPhysiqueModifier(pnode);
    if (m_phyMod)
	{
		// Physique Modifier exists for given Node
	    m_phyExport = (IPhysiqueExport *)m_phyMod->GetInterface(I_PHYINTERFACE);

        if (m_phyExport)
        {
            // create a ModContext Export Interface for the specific node of the Physique Modifier
           m_mcExport = (IPhyContextExport *)m_phyExport->GetContextInterface(pnode);

		   if (m_mcExport)
		   {
		       // convert all vertices to Rigid 
                m_mcExport->ConvertToRigid(TRUE);
		   }
		}
	}

	// Dump the triangle face info
	int cFaces = pmesh->getNumFaces();
	for (int iFace = 0; iFace < cFaces; iFace++)
	{
		Face*	pface		= &pmesh->faces[iFace];
		TVFace*	ptvface		= &pmesh->tvFace[iFace];
		DWORD	smGroupFace	= pface->getSmGroup();

		// Get face's 3 indexes into the Mesh's vertex array(s).
		DWORD iVertex0 = pface->getVert(0);
		DWORD iVertex1 = pface->getVert(1);
		DWORD iVertex2 = pface->getVert(2);
		ASSERT_AND_ABORT((int)iVertex0 < pmesh->getNumVerts(), "Bogus Vertex 0 index");
		ASSERT_AND_ABORT((int)iVertex1 < pmesh->getNumVerts(), "Bogus Vertex 1 index");
		ASSERT_AND_ABORT((int)iVertex2 < pmesh->getNumVerts(), "Bogus Vertex 2 index");
		
		// Get the 3 Vertex's for this face
		Point3 pt3Vertex0 = pmesh->getVert(iVertex0);
		Point3 pt3Vertex1 = pmesh->getVert(iVertex1);
		Point3 pt3Vertex2 = pmesh->getVert(iVertex2);

		// Get the 3 RVertex's for this face
		// NOTE: I'm using getRVertPtr instead of getRVert to work around a 3DSMax bug
		RVertex *prvertex0 = pmesh->getRVertPtr(iVertex0);
		RVertex *prvertex1 = pmesh->getRVertPtr(iVertex1);
		RVertex *prvertex2 = pmesh->getRVertPtr(iVertex2);
		
		// Find appropriate normals for each RVertex
		// A vertex can be part of multiple faces, so the "smoothing group"
		// is used to locate the normal for this face's use of the vertex.
		Point3 pt3Vertex0Normal;
		Point3 pt3Vertex1Normal;
		Point3 pt3Vertex2Normal;
		if (smGroupFace) 
		{
			pt3Vertex0Normal = Pt3GetRVertexNormal(prvertex0, smGroupFace);
			pt3Vertex1Normal = Pt3GetRVertexNormal(prvertex1, smGroupFace);
			pt3Vertex2Normal = Pt3GetRVertexNormal(prvertex2, smGroupFace);
		}
		else 
		{
			pt3Vertex0Normal = pmesh->getFaceNormal( iFace );
			pt3Vertex1Normal = pmesh->getFaceNormal( iFace );
			pt3Vertex2Normal = pmesh->getFaceNormal( iFace );
		}
		ASSERT_AND_ABORT( Length( pt3Vertex0Normal ) <= 1.1, "bogus orig normal 0" );
		ASSERT_AND_ABORT( Length( pt3Vertex1Normal ) <= 1.1, "bogus orig normal 1" );
		ASSERT_AND_ABORT( Length( pt3Vertex2Normal ) <= 1.1, "bogus orig normal 2" );
	
		// Get Face's sub-material from node's material, to get the bitmap name.
		// And no, there isn't a simpler way to get the bitmap name, you have to
		// dig down through all these levels.
		TCHAR szBitmapName[256] = "null.bmp";
		if (fHasMat)
		{
			MtlID mtlidFace = pface->getMatID();
			if (mtlidFace >= pmtlNode->NumSubMtls())
			{
				sprintf(st_szDBG, "ERROR--Bogus sub-material index %d in node %s; highest valid index is %d",
					mtlidFace, (char*)strNodeName, pmtlNode->NumSubMtls()-1);
				// ASSERT_AND_ABORT(FALSE, st_szDBG);
				mtlidFace = 0;
			}
			Mtl *pmtlFace = pmtlNode->GetSubMtl(mtlidFace);
			ASSERT_AND_ABORT(pmtlFace != NULL, "NULL Sub-material returned");
 
			if ((pmtlFace->ClassID() == Class_ID(MULTI_CLASS_ID, 0) && pmtlFace->IsMultiMtl()))
			{
				// it's a sub-sub material.  Gads.
				pmtlFace = pmtlFace->GetSubMtl(mtlidFace);			
				ASSERT_AND_ABORT(pmtlFace != NULL, "NULL Sub-material returned");
			}

			if (!(pmtlFace->ClassID() == Class_ID(DMTL_CLASS_ID, 0)))
			{

				sprintf(st_szDBG,
					"ERROR--Sub-material with index %d (used in node %s) isn't a 'default/standard' material [%x].",
					mtlidFace, (char*)strNodeName, pmtlFace->ClassID());
				ASSERT_AND_ABORT(FALSE, st_szDBG);
			}
			StdMat *pstdmtlFace = (StdMat*)pmtlFace;
			Texmap *ptexmap = pstdmtlFace->GetSubTexmap(ID_DI);
			// ASSERT_AND_ABORT(ptexmap != NULL, "NULL diffuse texture")
			if (ptexmap != NULL) 
			{
				if (!(ptexmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0)))
				{
					sprintf(st_szDBG,
						"ERROR--Sub-material with index %d (used in node %s) doesn't have a bitmap as its diffuse texture.",
						mtlidFace, (char*)strNodeName);
					ASSERT_AND_ABORT(FALSE, st_szDBG);
				}
				BitmapTex *pbmptex = (BitmapTex*)ptexmap;
				strcpy(szBitmapName, pbmptex->GetMapName());
				TSTR strPath, strFile;
				SplitPathFile(TSTR(szBitmapName), &strPath, &strFile);
				strcpy(szBitmapName,strFile);
			}
		}

		UVVert UVvertex0( 0, 0, 0 );
		UVVert UVvertex1( 1, 0, 0 );
		UVVert UVvertex2( 0, 1, 0 );
		
		// All faces must have textures assigned to them
		if (pface->flags & HAS_TVERTS)
		{
			// Get TVface's 3 indexes into the Mesh's TVertex array(s).
			DWORD iTVertex0 = ptvface->getTVert(0);
			DWORD iTVertex1 = ptvface->getTVert(1);
			DWORD iTVertex2 = ptvface->getTVert(2);
			ASSERT_AND_ABORT((int)iTVertex0 < pmesh->getNumTVerts(), "Bogus TVertex 0 index");
			ASSERT_AND_ABORT((int)iTVertex1 < pmesh->getNumTVerts(), "Bogus TVertex 1 index");
			ASSERT_AND_ABORT((int)iTVertex2 < pmesh->getNumTVerts(), "Bogus TVertex 2 index");

			// Get the 3 TVertex's for this TVFace
			// NOTE: I'm using getRVertPtr instead of getRVert to work around a 3DSMax bug
			UVvertex0 = pmesh->getTVert(iTVertex0);
			UVvertex1 = pmesh->getTVert(iTVertex1);
			UVvertex2 = pmesh->getTVert(iTVertex2);
		}
		else 
		{
			//sprintf(st_szDBG, "ERROR--Node %s has a textureless face.  All faces must have an applied texture.", (char*)strNodeName);
			//ASSERT_AND_ABORT(FALSE, st_szDBG);
		}
		
		/*
		const char *szExpectedExtension = ".bmp";
		if (stricmp(szBitmapName+strlen(szBitmapName)-strlen(szExpectedExtension), szExpectedExtension) != 0)
			{
			sprintf(st_szDBG, "Node %s uses %s, which is not a %s file", (char*)strNodeName, szBitmapName, szExpectedExtension);
			ASSERT_AND_ABORT(FALSE, st_szDBG);
			}
		*/

		// Determine owning bones for the vertices.
		int iNodeV0, iNodeV1, iNodeV2;
		if (m_mcExport)
		{
			// The Physique add-in allows vertices to be assigned to bones arbitrarily
			iNodeV0 = InodeOfPhyVectex( iVertex0 );
			iNodeV1 = InodeOfPhyVectex( iVertex1 );
			iNodeV2 = InodeOfPhyVectex( iVertex2 );
		}
		else
		{
			// Simple 3dsMax model: the vertices are owned by the object, and hence the node
			iNodeV0 = iNode;
			iNodeV1 = iNode;
			iNodeV2 = iNode;
		}
		
		// Rotate the face vertices out of object-space, and into world-space space
		Point3 v0 = pt3Vertex0 * mat3ObjectTM;
		Point3 v1 = pt3Vertex1 * mat3ObjectTM;
		Point3 v2 = pt3Vertex2 * mat3ObjectTM;


		Matrix3 mat3ObjectNTM = mat3ObjectTM;
		mat3ObjectNTM.NoScale( );
		ASSERT_AND_ABORT( Length( pt3Vertex0Normal ) <= 1.1, "bogus pre normal 0" );
		pt3Vertex0Normal = VectorTransform(mat3ObjectNTM, pt3Vertex0Normal);
		ASSERT_AND_ABORT( Length( pt3Vertex0Normal ) <= 1.1, "bogus post normal 0" );
		ASSERT_AND_ABORT( Length( pt3Vertex1Normal ) <= 1.1, "bogus pre normal 1" );
		pt3Vertex1Normal = VectorTransform(mat3ObjectNTM, pt3Vertex1Normal);
		ASSERT_AND_ABORT( Length( pt3Vertex1Normal ) <= 1.1, "bogus post normal 1" );
		ASSERT_AND_ABORT( Length( pt3Vertex2Normal ) <= 1.1, "bogus pre normal 2" );
		pt3Vertex2Normal = VectorTransform(mat3ObjectNTM, pt3Vertex2Normal);
		ASSERT_AND_ABORT( Length( pt3Vertex2Normal ) <= 1.1, "bogus post normal 2" );

		// Finally dump the bitmap name and 3 lines of face info
		fprintf(m_pfile, "%s\n", szBitmapName);
		fprintf(m_pfile, "%3d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f\n",
				iNodeV0, v0.x, v0.y, v0.z,
				pt3Vertex0Normal.x, pt3Vertex0Normal.y, pt3Vertex0Normal.z,
				UVvertex0.x, UVvertex0.y);
		fprintf(m_pfile, "%3d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f\n",
				iNodeV1, v1.x, v1.y, v1.z,
				pt3Vertex1Normal.x, pt3Vertex1Normal.y, pt3Vertex1Normal.z,
				UVvertex1.x, UVvertex1.y);
		fprintf(m_pfile, "%3d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f\n",
				iNodeV2, v2.x, v2.y, v2.z,
				pt3Vertex2Normal.x, pt3Vertex2Normal.y, pt3Vertex2Normal.z,
				UVvertex2.x, UVvertex2.y);
	}

	cleanup( );	
	return TREE_CONTINUE;
}
Ejemplo n.º 10
0
PAVISTREAM GetAudioStream(TSTR name,TCHAR *dir)
	{
	HRESULT		hr;
	PAVIFILE	pfile;
	PAVISTREAM	pstream = NULL;
	BOOL res = TRUE;

#ifndef INTERIM_64_BIT	// CCJ

	// RB 5/10/99: Reworked this a bit. Added the current scene dir as a possible search location.
	// Also now using SplitPathFile() instead of doing it by hand.

 	hr = AVIFileOpen(&pfile,name,OF_READ,NULL);
	if (hr) {
		TSTR fileName, tryName;
		SplitPathFile(name, NULL, &fileName);

		// Try the given directory (which is the sound dir)
		tryName = TSTR(dir) + TSTR(_T("\\")) + fileName;
		hr = AVIFileOpen(&pfile,tryName,OF_READ,NULL);
		
		if (hr) {
			// Try the scene directory
			TSTR sceneName = GetCOREInterface()->GetCurFilePath();
			TSTR scenePath;
			SplitPathFile(sceneName, &scenePath, NULL);
			tryName = scenePath + TSTR(_T("\\")) + fileName;
			hr = AVIFileOpen(&pfile,tryName,OF_READ,NULL);
			}

#if 0
		// Try the file in the given directory
		int i = name.Length()-1;
		while (i>0) {
			if (name[i]=='\\' ||
				name[i]==':' ||
				name[i]=='/') {
				i++;
				break;
				}	
			i--;
			}
		if (name.Length()-i>0) {
			TSTR newname = TSTR(dir) + TSTR(_T("\\")) + name.Substr(i,name.Length()-i);
			hr = AVIFileOpen(&pfile,newname,OF_READ,NULL);
			}
#endif
		}
	if (hr) return NULL;

	AVIFileGetStream(pfile,&pstream,streamtypeAUDIO,0);
	AVIFileRelease(pfile);

	if (!pstream) return NULL;

	// Verify it's PCM
	PCMWAVEFORMAT wf;
	LONG l = sizeof(wf);
    AVIStreamReadFormat(pstream,0,&wf,&l);
    if (!l)	{
        AVIStreamRelease(pstream);
		return NULL;
		}
	if (wf.wf.wFormatTag != WAVE_FORMAT_PCM) {
		AVIStreamRelease(pstream);
		return NULL;
		}

#endif	// INTERIM_64_BIT
	return pstream;
	}