SEGMENTH CombinePolygonPieces(SEGMENTH *A1, SEGMENTH *B1, Boolean keepAinB, Boolean keepAnotinB, Boolean keepBinA, Boolean keepBnotinA) { long i, j, err, numSegsA, numSegsB, numSegsC = 0; WorldPoint m; SEGMENTH C = 0, A2 = 0, B2 = 0, *A = 0, *B = 0; err = 0; numSegsA = _GetHandleSize((Handle)*A1) / sizeof(Segment); numSegsB = _GetHandleSize((Handle)*B1) / sizeof(Segment); A2 = (SEGMENTH)_NewHandle(numSegsA * sizeof(Segment)); if (_MemError()) { TechError("CombinePolygonPieces()", "_NewHandle()", 0); goto done; } for (i = 0 ; i < numSegsA ; i++) INDEXH(A2, i) = INDEXH(*A1, i); A = &A2; B2 = (SEGMENTH)_NewHandle(numSegsB * sizeof(Segment)); if (_MemError()) { TechError("CombinePolygonPieces()", "_NewHandle()", 0); goto done; } for (i = 0 ; i < numSegsB ; i++) INDEXH(B2, i) = INDEXH(*B1, i); B = &B2; for (i = 0 ; i < numSegsA ; i++) for (j = 0 ; j < numSegsB ; j++) if (SegmentTouchesSegment(INDEXH(*A, i), INDEXH(*B, j)) && !SameSegmentEndPoints(INDEXH(*A, i), INDEXH(*B, j))) { m = PointOfIntersection(INDEXH(*A, i), INDEXH(*B, j)); if (err = InsertSegment(A, &numSegsA, i, m)) goto done; if (err = InsertSegment(B, &numSegsB, j, m)) goto done; } C = (SEGMENTH)_NewHandle(0); if (_MemError()) { TechError("CombinePolygonPieces()", "_NewHandle()", 0); goto done; } for (i = 0 ; i < numSegsA ; i++) { m = Midpoint(INDEXH(*A, i)); if ((keepAinB && PointInPolygon(m, *B, numSegsB, TRUE)) || (keepAnotinB && !PointInPolygon(m, *B, numSegsB, TRUE))) if (err = AddSegment(&C, &numSegsC, INDEXH(*A, i))) goto done; } for (j = 0 ; j < numSegsB ; j++) { m = Midpoint(INDEXH(*B, j)); if ((keepBinA && PointInPolygon(m, *A, numSegsA, TRUE)) || (keepBnotinA && !PointInPolygon(m, *A, numSegsA, TRUE))) if (err = AddSegment(&C, &numSegsC, INDEXH(*B, j))) goto done; } SortSegments(C, numSegsC); done: if (A2) DisposeHandle((Handle)A2); if (B2) DisposeHandle((Handle)B2); if (err && C) DisposeHandle((Handle)C); return err ? 0 : C; }
OSErr ReadTopology(BFPB *bfpb,TopologyHdl *topH,VelocityFH *velocityH, char *errmsg) { long numRecs, i; Topology thisTop; VelocityFRec thisVelF; OSErr err = noErr; char haveVelocityHdl; *topH = 0; *velocityH = 0; if (err = ReadMacValue(bfpb, &numRecs)) goto done; if(numRecs <= 0) {err = TRUE; goto done;} *topH = (TopologyHdl)_NewHandle(sizeof(***topH)*(numRecs)); for(i=0;i<numRecs;i++) { memset(&thisTop,0,sizeof(thisTop)); if (err = ReadMacValue(bfpb, &thisTop.vertex1)) goto done; if (err = ReadMacValue(bfpb, &thisTop.vertex2)) goto done; if (err = ReadMacValue(bfpb, &thisTop.vertex3)) goto done; if (err = ReadMacValue(bfpb, &thisTop.adjTri1)) goto done; if (err = ReadMacValue(bfpb, &thisTop.adjTri2)) goto done; if (err = ReadMacValue(bfpb, &thisTop.adjTri3)) goto done; (**topH)[i] = thisTop; } /// if (err = ReadMacValue(bfpb, &haveVelocityHdl)) goto done; if(haveVelocityHdl) { *velocityH = (VelocityFH)_NewHandle(sizeof(***velocityH)*(numRecs)); for(i=0;i<numRecs;i++) { memset(&thisVelF,0,sizeof(thisVelF)); if (err = ReadMacValue(bfpb, &thisVelF.u)) goto done; if (err = ReadMacValue(bfpb, &thisVelF.v)) goto done; (**velocityH)[i] = thisVelF; } } done: if (err) { strcpy (errmsg, "Error while reading topology file."); if(*topH) {DisposeHandle((Handle)*topH); *topH = 0;} if(*velocityH) {DisposeHandle((Handle)*velocityH); *velocityH = 0;} } return err; }
SEGMENTH WPointsToSegments(WORLDPOINTH wPoints, long numPoints, long *numSegs) { long i, j; SEGMENTH segments; if (EqualWPoints(INDEXH(wPoints, 0), INDEXH(wPoints, numPoints - 1))) (*numSegs) = numPoints - 1; else (*numSegs) = numPoints; segments = (SEGMENTH)_NewHandle((*numSegs) * sizeof(Segment)); if (_MemError()) { TechError("WPointsToSegments()", "_NewHandle()", 0); return 0; } for (i = 0 ; i < (*numSegs) ; i++) { INDEXH(segments, i).fromLong = INDEXH(wPoints, i).pLong; INDEXH(segments, i).fromLat = INDEXH(wPoints, i).pLat; if ((*numSegs) == numPoints && i == numPoints - 1) j = 0; else j = i + 1; INDEXH(segments, i).toLong = INDEXH(wPoints, j).pLong; INDEXH(segments, i).toLat = INDEXH(wPoints, j).pLat; } return segments; }
OSErr ReadIndexedDagTree(BFPB *bfpb,DAGHdl *treeH,char* errmsg) { OSErr err = noErr; long i; long numRecs; DAG thisDag; if (err = ReadMacValue(bfpb, &numRecs)) goto done; *treeH = (DAGHdl)_NewHandle(sizeof(DAG)*(numRecs)); for(i=0;i<numRecs;i++) { if (err = ReadMacValue(bfpb, &thisDag.topoIndex)) goto done; if (err = ReadMacValue(bfpb, &thisDag.branchLeft)) goto done; if (err = ReadMacValue(bfpb, &thisDag.branchRight)) goto done; (**treeH)[i] = thisDag; } done: if (err) { strcpy (errmsg, "Error while writing topology to file."); } return err; }
/**************************************************************** DefineMenu() reads the menu's 'MDAT' resource into memory and fills in the fields. It creates the resource if it doesn't exist. ****************************************************************/ void DefineMenu(int menuID, short cellHeight, short menuWidth, Boolean bFixedWidth, short numColumns, //JLM ProcPtr drawProc, //JLM ProcPtr invertProc, //JLM ProcPtr disableProc) SAMenuActionProcPtr drawProc, SAMenuActionProcPtr invertProc, SAMenuActionProcPtr disableProc) { MenuDataRec **menuDataHandle; char message[100]; menuDataHandle = (MenuDataRec **)GetResource('MDAT', menuID); if (menuDataHandle == nil) { // try to create the resource menuDataHandle = (MenuDataRec **)_NewHandle(sizeof (MenuDataRec)); if (menuDataHandle == nil) { sprintf(message, "Could not create info structure for menu ID %d.", menuID); // debugstr(message); SysBeep(1); return; } AddResource((Handle)menuDataHandle, 'MDAT', menuID, "\p"); if (ResError() != 0) { sprintf(message, "Could not add 'MDAT' resource for menu ID %d.", menuID); // debugstr(message); SysBeep(1); return; }
OSErr ReadVertices(BFPB *bfpb, LongPointHdl *ptsH, char *errmsg) { long numPoints, i; LongPoint thisLPoint; OSErr err = noErr; if (err = ReadMacValue(bfpb, &numPoints)) goto done; *ptsH = (LongPointHdl)_NewHandle(sizeof(LongPoint)*(numPoints)); if (!*ptsH) { err = memFullErr; goto done; } for(i=0;i<numPoints;i++) { if (err = ReadMacValue(bfpb, &thisLPoint.h)) goto done; if (err = ReadMacValue(bfpb, &thisLPoint.v)) goto done; (**ptsH)[i].h = thisLPoint.h; (**ptsH)[i].v = thisLPoint.v; } done: if(err) { strcpy (errmsg, "Error while reading vertices to file."); } return err; }
void DrawMapBoundsPoly (CMap* theMap, PolyObjectHdl MapPolyHdl, DrawSpecRecPtr drawSettings, Boolean erasePolygon) { long numPts = (**MapPolyHdl).pointCount; POINT **pointsH = (POINT**)_NewHandle(numPts *sizeof(POINT)); POINT *pointsPtr = (POINT*)_NewPtr(numPts *sizeof(POINT)); LongPoint** thisPointsHdl=nil; Point pt; LongPoint wPt; long i; Boolean offQuickDrawPlane = false; RGBColor saveColor; // JLM ?? wouldn't compile without this if(!pointsH || !pointsPtr) {SysBeep(5); return;} thisPointsHdl = (LongPoint**) (**MapPolyHdl).objectDataHdl; for(i = 0; i< numPts;i++) { wPt = INDEXH(thisPointsHdl,i); pt = GetQuickDrawPt(wPt.h,wPt.v,&gRect,&offQuickDrawPlane); INDEXH(pointsH,i) = MakePOINT(pt.h,pt.v); (pointsPtr)[i] = MakePOINT(pt.h,pt.v); // code goes here, make sure this point does not equal previous point JLM } GetForeColor (&saveColor); /* save original forecolor */ if (erasePolygon) { RgnHandle newClip=0; HBRUSH whiteBrush; newClip = CreatePolygonRgn((const POINT*)pointsPtr,numPts,ALTERNATE); whiteBrush = (HBRUSH)GetStockObject(WHITE_BRUSH); //err = SelectClipRgn(currentHDC,savedClip); FillRgn(currentHDC, newClip, whiteBrush); //DeleteObject(newClip); DisposeRgn(newClip); //SelectClipRgn(currentHDC,0); } else { POINT p[2]; p[0] = INDEXH(pointsH,numPts-1); p[1] = INDEXH(pointsH,0); RGBForeColor(&colors[BLACK]); if(numPts >= 2) { Polyline(currentHDC,*pointsH,numPts); Polyline(currentHDC,p,2); // close the polygon } } RGBForeColor (&saveColor); DisposeHandle((Handle)pointsH); if(pointsPtr) {_DisposePtr((Ptr)pointsPtr); pointsPtr = 0;} }
static NavTypeListHandle MyCreateNavTypeListHandle(OSType applicationSignature, short numTypes, OSType typeList[]) { NavTypeListHandle hdl = NULL; if ( numTypes > 0 ) { hdl = (NavTypeListHandle) _NewHandle(sizeof(NavTypeList) + numTypes * sizeof(OSType)); if ( hdl != NULL ){ (*hdl)->componentSignature = applicationSignature; (*hdl)->osTypeCount = numTypes; BlockMoveData(typeList, (*hdl)->osType, numTypes * sizeof(OSType)); } } return hdl; }
OSErr TShioTimeValue::Read(BFPB *bfpb) { long i, n, version; ClassID id; TimeValuePair pair; float f; OSErr err = 0; if (err = TOSSMTimeValue::Read(bfpb)) return err; StartReadWriteSequence("TShioTimeValue::Read()"); if (err = ReadMacValue(bfpb,&id)) return err; if (id != GetClassID ()) { TechError("TShioTimeValue::Read()", "id != TYPE_SHIOMOVER", 0); return -1; } if (err = ReadMacValue(bfpb,&version)) return err; //if (version != TShioMoverREADWRITEVERSION) { printSaveFileVersionError(); return -1; } if (version > TShioMoverREADWRITEVERSION) { printSaveFileVersionError(); return -1; } ///////////////////////////////// if (err = ReadMacValue(bfpb, fStationName, MAXSTATIONNAMELEN)) return err; // don't swap !! if (err = ReadMacValue(bfpb,&fStationType)) return err; //if (version == 1) { double fLatitude, fLongitude; // now the station info is is TOSSMTimeValue... if (err = ReadMacValue(bfpb,&fLatitude)) return err; if (err = ReadMacValue(bfpb,&fLongitude)) return err; // should set the station position fStationPosition.p.pLat = fLatitude * 1.e6; fStationPosition.p.pLong = fLongitude * 1.e6; } if (err = ReadMacValue(bfpb,&fConstituent.DatumControls.datum)) return err; if (err = ReadMacValue(bfpb,&fConstituent.DatumControls.FDir)) return err; if (err = ReadMacValue(bfpb,&fConstituent.DatumControls.EDir)) return err; if (err = ReadMacValue(bfpb,&fConstituent.DatumControls.L2Flag)) return err; if (err = ReadMacValue(bfpb,&fConstituent.DatumControls.HFlag)) return err; if (err = ReadMacValue(bfpb,&fConstituent.DatumControls.RotFlag)) return err; // read the number of elements in the handle, then the handle values if (err = ReadMacValue(bfpb,&n)) return err; if(n > 0) { if(sizeof(f) != sizeof(**fConstituent.H)) { printError("fConstituent.H size mismatch"); return -1; } fConstituent.H = (float**)_NewHandle(n*sizeof(**fConstituent.H)); if(!fConstituent.H) {TechError("TLEList::Read()", "_NewHandle()", 0); return -1; } for(i = 0; i<n;i++) { if (err = ReadMacValue(bfpb,&f)) return err; INDEXH(fConstituent.H,i) = f; } } // read the number of elements in the handle, then the handle values if (err = ReadMacValue(bfpb,&n)) return err; if(n > 0) { if(sizeof(f) != sizeof(**fConstituent.kPrime)) { printError("fConstituent.kPrime size mismatch"); return -1; } fConstituent.kPrime = (float**)_NewHandle(n*sizeof(**fConstituent.kPrime)); if(!fConstituent.kPrime) {TechError("TLEList::Read()", "_NewHandle()", 0); return -1; } for(i = 0; i<n;i++) { if (err = ReadMacValue(bfpb,&f)) return err; INDEXH(fConstituent.kPrime,i) = f; } } if (err = ReadMacValue(bfpb,&fHeightOffset.HighTime.val)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.HighTime.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.LowTime.val)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.LowTime.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.HighHeight_Mult.val)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.HighHeight_Mult.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.HighHeight_Add.val)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.HighHeight_Add.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.LowHeight_Mult.val)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.LowHeight_Mult.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.LowHeight_Add.val)) return err; if (err = ReadMacValue(bfpb,&fHeightOffset.LowHeight_Add.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBefFloodTime.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBefFloodTime.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.FloodTime.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.FloodTime.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBefEbbTime.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBefEbbTime.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.EbbTime.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.EbbTime.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.FloodSpdRatio.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.FloodSpdRatio.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.EbbSpdRatio.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.EbbSpdRatio.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBFloodSpd.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBFloodSpd.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBFloodDir.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBFloodDir.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxFloodSpd.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxFloodSpd.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxFloodDir.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxFloodDir.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBEbbSpd.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBEbbSpd.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBEbbDir.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MinBEbbDir.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxEbbSpd.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxEbbSpd.dataAvailFlag)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxEbbDir.val)) return err; if (err = ReadMacValue(bfpb,&fCurrentOffset.MaxEbbDir.dataAvailFlag)) return err; // ///////////////////////////////////////////////// if (fStationType == 'C') // values to show on list for tidal currents { long i,numEbbFloods; EbbFloodData ebbFloodData; if (err = ReadMacValue(bfpb,&numEbbFloods)) return err; fEbbFloodDataHdl = (EbbFloodDataH)_NewHandleClear(sizeof(EbbFloodData)*numEbbFloods); if(!fEbbFloodDataHdl) {TechError("TShioTimeValue::Read()", "_NewHandleClear()", 0); err = memFullErr; return err;} for (i=0;i<numEbbFloods;i++) { if (err = ReadMacValue(bfpb,&(ebbFloodData.time))) return err; if (err = ReadMacValue(bfpb,&(ebbFloodData.speedInKnots))) return err; if (err = ReadMacValue(bfpb,&(ebbFloodData.type))) return err; INDEXH(fEbbFloodDataHdl,i) = ebbFloodData; } } if (fStationType == 'H') // values to show on list for tidal heights { long i,numHighLows; HighLowData highLowData; if (err = ReadMacValue(bfpb,&numHighLows)) return err; fHighLowDataHdl = (HighLowDataH)_NewHandleClear(sizeof(HighLowData)*numHighLows); if(!fHighLowDataHdl) {TechError("TShioTimeValue::Read()", "_NewHandleClear()", 0); err = memFullErr; return err;} for (i=0;i<numHighLows;i++) { if (err = ReadMacValue(bfpb,&(highLowData.time))) return err; if (err = ReadMacValue(bfpb,&(highLowData.height))) return err; if (err = ReadMacValue(bfpb,&(highLowData.type))) return err; INDEXH(fHighLowDataHdl,i) = highLowData; } if (err = ReadMacValue(bfpb,&fHighLowValuesOpen)) return err; if (err = ReadMacValue(bfpb,&fEbbFloodValuesOpen)) return err; } if (fStationType == 'P') // values to show on list for tidal heights { long i,numHighLows; HighLowData highLowData; if (err = ReadMacValue(bfpb,&numHighLows)) return err; fHighLowDataHdl = (HighLowDataH)_NewHandleClear(sizeof(HighLowData)*numHighLows); if(!fHighLowDataHdl) {TechError("TShioTimeValue::Read()", "_NewHandleClear()", 0); err = memFullErr; return err;} for (i=0;i<numHighLows;i++) { if (err = ReadMacValue(bfpb,&(highLowData.time))) return err; if (err = ReadMacValue(bfpb,&(highLowData.height))) return err; if (err = ReadMacValue(bfpb,&(highLowData.type))) return err; INDEXH(fHighLowDataHdl,i) = highLowData; } if (err = ReadMacValue(bfpb,&fHighLowValuesOpen)) return err; //if (err = ReadMacValue(bfpb,&fEbbFloodValuesOpen)) return err; } return err; }
// will need to read from text file instead YEARDATAHDL GetYearData(short year) { // IMPORTANT: The calling function should NOT dispose the handle it gets YEARDATAHDL yrHdl=nil; short yearMinus1990 = year-1990; long i,n,resSize=0; if(0<= yearMinus1990 && yearMinus1990 <kMAXNUMSAVEDYEARS) { if(gYearDataHdl1990Plus[yearMinus1990]) return gYearDataHdl1990Plus[yearMinus1990]; } #ifdef MAC Handle r = nil; r=GetResource('YEAR',(long)year); #ifdef SWAP_BINARY resSize = GetMaxResourceSize(r); if(resSize > 0 && r) { yrHdl = (YEARDATAHDL)_NewHandle(resSize); if(yrHdl) { _HLock(r); // so it can't be purged !!! YEARDATAHDL rHdl = (YEARDATAHDL)_NewHandle(resSize); DetachResource(r); rHdl = (YEARDATAHDL) r; // copy and swap the bytes n = resSize/sizeof(YEARDATA); for(i = 0; i< n; i++) { YEARDATA yrd = (YEARDATA)INDEXH(rHdl,i); SwapFloat(&yrd.XODE); SwapFloat(&yrd.VPU); INDEXH(yrHdl,i) = yrd; } // I don't think we free something gotten from a resource } ReleaseResource(r);// don't dispose of a resource handle !!! r = 0; } #else if(r) { DetachResource(r); yrHdl = (YEARDATAHDL) r; } #endif #else char numStr[32]; HRSRC hResInfo =0; HGLOBAL r = 0; sprintf(numStr,"#%ld",year); hResInfo = FindResource(hInst,numStr,"YEAR"); if(hResInfo) { // copy the handle so we can be // just like the mac // //also we need to swap the bytes // // be careful r is a HGLOBAL, not one of our special fake handles resSize = SizeofResource(hInst,hResInfo); if(resSize > 0) r = LoadResource(hInst,hResInfo); if(resSize > 0 && r) { yrHdl = (YEARDATAHDL)_NewHandle(resSize); if(yrHdl) { YEARDATAPTR rPtr = (YEARDATAPTR) LockResource(r); // copy and swap the bytes n = resSize/sizeof(YEARDATA); for(i = 0; i< n; i++) { YEARDATA yrd = rPtr[i]; SwapFloat(&yrd.XODE); SwapFloat(&yrd.VPU); INDEXH(yrHdl,i) = yrd; } // WIN32 applications do not have to unlock resources locked by LockResource // I don't think we free something gotten from a resource } } } #endif if(yrHdl && 0<= yearMinus1990 && yearMinus1990 <kMAXNUMSAVEDYEARS) { gYearDataHdl1990Plus[yearMinus1990] = yrHdl; } return(yrHdl); }
void DrawMapPoly (CMap* theMap, PolyObjectHdl MapPolyHdl, DrawSpecRecPtr drawSettings) { RGBColor saveColor; drawSettings -> bClosed = IsPolyClosed (MapPolyHdl); #ifdef MAC long PointCount; //drawSettings -> bClosed = IsPolyClosed (MapPolyHdl); GetForeColor (&saveColor); /* save original forecolor */ if (drawSettings -> bClosed) { if (drawSettings -> mode == kPictMode) { DrawSectPoly (theMap, MapPolyHdl, drawSettings); /* changed 11/21/95 due to postscript errors */ // DrawNoSectPoly (theMap, MapPolyHdl, drawSettings); /* changed back on 3/28/96 } else { //PointCount = GetPolyPointCount (MapPolyHdl); //if (PointCount > 7000) //{ // /* draw polygon interior without any frame */ // drawSettings -> frameCode = kNoFrameCode; // DrawNoSectPoly (theMap, MapPolyHdl, drawSettings); // /* then draw polygon outline without using poly-routines */ // drawSettings -> frameCode = kPaintFrameCode; // drawSettings -> fillCode = kNoFillCode; // DrawNoSectPoly (theMap, MapPolyHdl, drawSettings); //} //else DrawNoSectPoly (theMap, MapPolyHdl, drawSettings); } } else /* hollow polygon, no fill of any kind */ { DrawNoSectPoly (theMap, MapPolyHdl, drawSettings); } RGBForeColor (&saveColor); return; #else long numPts = (**MapPolyHdl).pointCount; POINT **pointsH = (POINT**)_NewHandle(numPts *sizeof(POINT)); LongPoint** thisPointsHdl=nil; Point pt; LongPoint wPt; long i, esiCode; long penWidth = 2, halfPenWidth = 0; Boolean bDrawBlackAndWhite = (sharedPrinting && settings.printMode != COLORMODE); Boolean offQuickDrawPlane = false, drawingESILayer = false; if(!pointsH) {SysBeep(5); return;} thisPointsHdl = (LongPoint**) (**MapPolyHdl).objectDataHdl; GetObjectESICode ((ObjectRecHdl) MapPolyHdl,&esiCode); if (esiCode>0) // -500 is the default { //halfPenWidth = penWidth/2; PenStyle(BLACK,penWidth); drawingESILayer = true; } for(i = 0; i< numPts;i++) { wPt = INDEXH(thisPointsHdl,i); //pt.h = SameDifferenceX(wPt.h); //pt.v = (gRect.bottom + gRect.top) - SameDifferenceY(wPt.v); pt = GetQuickDrawPt(wPt.h,wPt.v,&gRect,&offQuickDrawPlane); //pt.h += drawSettings -> offsetDx; //pt.v += drawSettings -> offsetDy; INDEXH(pointsH,i) = MakePOINT(pt.h-halfPenWidth,pt.v-halfPenWidth); // code goes here, make sure this point does not equal previous point JLM } GetForeColor (&saveColor); /* save original forecolor */ //Our_PmForeColor (bDrawBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);//JLM // make sure the blackandwhite bitmaps come out right Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);//JLM if (drawSettings -> fillCode == kNoFillCode && drawSettings->backColorInd == kWaterColorInd) Our_PmForeColor (drawSettings -> foreColorInd); else { if(bDrawBlackAndWhite) { //SetPenPat(UPSTRIPES); // we want solid outline and a patterned inside FillPat(UPSTRIPES); PenStyle(BLACK,1); } } //if(numPts > 2) Polygon(currentHDC,*pointsH,numPts); // 6/11/03 PC wasn't recognizing the flag for not filling a land polygon if (drawSettings -> bClosed) { if(numPts > 2) Polygon(currentHDC,*pointsH,numPts); } else { //POINT p[2]; //p[0] = INDEXH(pointsH,numPts-1); //p[1] = INDEXH(pointsH,0); //RGBForeColor(&colors[BLACK]); if(numPts >= 2) { Polyline(currentHDC,*pointsH,numPts); //if (!drawingESILayer) //Polyline(currentHDC,p,2); // close the polygon } } if(bDrawBlackAndWhite) SetPenPat(BLACK); RGBForeColor (&saveColor); DisposeHandle((Handle)pointsH); #endif }
short EditProfilesClick(DialogPtr dialog, short itemNum, long lParam, VOIDPTR data) { Point pos,mp,clippedPos; Rect r; double speed, direction; long curSelection; long dir,i,n; unsigned long incr; char s[30]; OSErr err=0,settingsErr = 0; CProfilesList *tlist; DepthValuesSet dvals; //if (AddRecordRowIsSelected2()) if (VLAddRecordRowIsSelected(&sgObjects)) { //Last row is selected //Disable delete button MyEnableControl(dialog,EPDELETEROWS_BTN,FALSE); // And change title in replace dialog to "Add new record" MySetControlTitle(dialog, EPREPLACE, "Add New Record"); } else { MySetControlTitle(dialog, EPREPLACE, "Replace Selected"); MyEnableControl(dialog,EPDELETEROWS_BTN,TRUE); } switch(itemNum) { case EPOK: { // don't retrieve increment here // Just use the value from the last time they incremented. // Why bother them if we are not going to use the value. //if(ShowAutoIncrement2()) err = RetrieveIncrementDepth(dialog); //if(err) break; //sgSpeedUnits = GetPopSelection(dialog, EPSPEEDPOPUP); if(sgDepthVals) { DepthValuesSetH dvalsh = sgDepthValuesH; n = sgDepthVals->GetItemCount(); if(n == 0) { // no items are entered, tell the user char msg[512],buttonName[64]; GetWizButtonTitle_Cancel(buttonName); sprintf(msg,"You have not entered any data values. Either enter data values and use the 'Add New Record' button, or use the '%s' button to exit the dialog.",buttonName); printError(msg); break; } // check that all the values are in range - if there is some range // or may allow the user to change units for(i=0; i<n; i++) { char errStr[256] = ""; err=sgDepthVals->GetListItem((Ptr)&dvals,i); if(err) { SysBeep(5); // this shouldn't ever happen break; } /*UV2RTheta(dvals.value.u,dvals.value.v,&r,&theta); err = CheckWindSpeedLimit(r,sgSpeedUnits,errStr); if(err) { strcat(errStr," Check your units and each of the records you entered."); printError(errStr); return 0; // stay in the dialog }*/ } //sCellLength = EditText2Float(dialog,EPDXDY); // use map size instead and calculate km from that //sNumCells = EditText2Float(dialog,EPNUMCELLS); // will want to check that spill is inside of the grid, and grid is not super small ///////////// // point of no return ////////////// if(dvalsh == 0) { dvalsh = (DepthValuesSetH)_NewHandle(n*sizeof(DepthValuesSet)); if(!dvalsh) { TechError("EditProfilesClick:OKAY", "_NewHandle()", 0); //return EPCANCEL; break; // make them cancel so that code gets executed } sgDepthValuesH = dvalsh; } else { _SetHandleSize((Handle)dvalsh,n*sizeof(DepthValuesSet)); if(_MemError()) { TechError("EditProfilesClick:OKAY", "_NewHandle()", 0); //return EPCANCEL; break; // make them cancel, so that code gets executed } } for(i=0; i<n; i++) { if(err=sgDepthVals->GetListItem((Ptr)&dvals,i))return EPOK; (*dvalsh)[i]=dvals; } } ///////////////////////////// DisposeEPStuff(); return EPOK; } case EPCANCEL: //SetEPDialogNonPtrFields(sgWindMover,&sharedEPDialogNonPtrFields); DisposeEPStuff(); return EPCANCEL; break; case EPINCREMENT: case EPDEPTH: case EPTEMP: case EPSAL: //case EPDXDY: CheckNumberTextItem(dialog, itemNum, TRUE); // allow decimals break; case EPU: case EPV: //case EPDXDY: CheckNumberTextItemAllowingNegative(dialog, itemNum, TRUE); // allow decimals break; //case EPNUMCELLS: //CheckNumberTextItem(dialog, itemNum, FALSE); // don't allow decimals //break; case EPDELETEALL: sgDepthVals->ClearList(); VLReset(&sgObjects,1); UpdateDisplayWithCurSelection(dialog); break; case EPDELETEROWS_BTN: if (VLGetSelect(&curSelection, &sgObjects)) { sgDepthVals->DeleteItem(curSelection); VLDeleteItem(curSelection,&sgObjects); if(sgObjects.numItems == 0) { VLAddItem(1,&sgObjects); VLSetSelect(0,&sgObjects); } --curSelection; if(curSelection >-1) { VLSetSelect(curSelection,&sgObjects); } VLUpdate(&sgObjects); } UpdateDisplayWithCurSelection(dialog); break; //case EPSPEEDPOPUP: //{ //PopClick(dialog, itemNum, &sgSpeedUnits); //} //break; case EPREPLACE: err = RetrieveIncrementDepth(dialog); if(err) break; if (VLGetSelect(&curSelection, &sgObjects)) { err=GetDepthVals(dialog,&dvals); if(err) break; if(curSelection==sgDepthVals->GetItemCount()) { // replacing blank record err = AddReplaceRecord(dialog,INCREMENT_DEPTH,!REPLACE,dvals); SelectNthRow(dialog, curSelection+1 ); } else // replacing existing record { VLGetSelect(&curSelection,&sgObjects); sgDepthVals->DeleteItem(curSelection); VLDeleteItem(curSelection,&sgObjects); err = AddReplaceRecord(dialog,!INCREMENT_DEPTH,REPLACE,dvals); } } break; case EPLIST: // retrieve every time they click on the list // because clicking can cause the increment to be hidden // and we need to verify it before it gets hidden err = RetrieveIncrementDepth(dialog); if(err) break; /////////// pos=GetMouseLocal(GetDialogWindow(dialog)); VLClick(pos, &sgObjects); VLUpdate(&sgObjects); VLGetSelect(&curSelection,&sgObjects); if(curSelection == -1 ) { curSelection = sgObjects.numItems-1; VLSetSelect(curSelection,&sgObjects); VLUpdate(&sgObjects); } //ShowHideAutoIncrement(dialog,curSelection); // moved into UpdateDisplayWithCurSelection() //if (AddRecordRowIsSelected2()) if (VLAddRecordRowIsSelected(&sgObjects)) { DepthValuesSet dvals; sgDepthVals->GetListItem((Ptr)&dvals,sgDepthVals->GetItemCount()-1); err = RetrieveIncrementDepth(dialog); if(err) break; IncrementDepth(dialog,dvals.depth); } UpdateDisplayWithCurSelection(dialog); break; } return 0; }
// simplify for wind data - no map needed, no mask OSErr NetCDFWindMoverCurv_c::ReorderPoints(TMap **newMap, char* errmsg) { long i, j, n, ntri, numVerdatPts=0; long fNumRows_ext = fNumRows+1, fNumCols_ext = fNumCols+1; long nv = fNumRows * fNumCols, nv_ext = fNumRows_ext*fNumCols_ext; long iIndex, jIndex, index; long triIndex1, triIndex2, waterCellNum=0; long ptIndex = 0, cellNum = 0; long indexOfStart = 0; OSErr err = 0; LONGH landWaterInfo = (LONGH)_NewHandleClear(fNumRows * fNumCols * sizeof(long)); LONGH maskH2 = (LONGH)_NewHandleClear(nv_ext * sizeof(long)); LONGH ptIndexHdl = (LONGH)_NewHandleClear(nv_ext * sizeof(**ptIndexHdl)); LONGH verdatPtsH = (LONGH)_NewHandleClear(nv_ext * sizeof(**verdatPtsH)); GridCellInfoHdl gridCellInfo = (GridCellInfoHdl)_NewHandleClear(nv * sizeof(**gridCellInfo)); TopologyHdl topo=0; LongPointHdl pts=0; VelocityFH velH = 0; DAGTreeStruct tree; WorldRect triBounds; TTriGridVel *triGrid = nil; tree.treeHdl = 0; TDagTree *dagTree = 0; VelocityFH velocityH = 0; if (!landWaterInfo || !ptIndexHdl || !gridCellInfo || !verdatPtsH || !maskH2) {err = memFullErr; goto done;} err = ReadTimeData(indexOfStart,&velocityH,errmsg); // try to use velocities to set grid for (i=0;i<fNumRows;i++) { for (j=0;j<fNumCols;j++) { // eventually will need to have a land mask, for now assume fillValue represents land //if (INDEXH(velocityH,i*fNumCols+j).u==0 && INDEXH(velocityH,i*fNumCols+j).v==0) // land point if (INDEXH(velocityH,i*fNumCols+j).u==fFillValue && INDEXH(velocityH,i*fNumCols+j).v==fFillValue) // land point { INDEXH(landWaterInfo,i*fNumCols+j) = -1; // may want to mark each separate island with a unique number } else { INDEXH(landWaterInfo,i*fNumCols+j) = 1; INDEXH(ptIndexHdl,i*fNumCols_ext+j) = -2; // water box INDEXH(ptIndexHdl,i*fNumCols_ext+j+1) = -2; INDEXH(ptIndexHdl,(i+1)*fNumCols_ext+j) = -2; INDEXH(ptIndexHdl,(i+1)*fNumCols_ext+j+1) = -2; } } } for (i=0;i<fNumRows_ext;i++) { for (j=0;j<fNumCols_ext;j++) { if (INDEXH(ptIndexHdl,i*fNumCols_ext+j) == -2) { INDEXH(ptIndexHdl,i*fNumCols_ext+j) = ptIndex; // count up grid points ptIndex++; } else INDEXH(ptIndexHdl,i*fNumCols_ext+j) = -1; } } for (i=0;i<fNumRows;i++) { for (j=0;j<fNumCols;j++) { if (INDEXH(landWaterInfo,i*fNumCols+j)>0) { INDEXH(gridCellInfo,i*fNumCols+j).cellNum = cellNum; cellNum++; INDEXH(gridCellInfo,i*fNumCols+j).topLeft = INDEXH(ptIndexHdl,i*fNumCols_ext+j); INDEXH(gridCellInfo,i*fNumCols+j).topRight = INDEXH(ptIndexHdl,i*fNumCols_ext+j+1); INDEXH(gridCellInfo,i*fNumCols+j).bottomLeft = INDEXH(ptIndexHdl,(i+1)*fNumCols_ext+j); INDEXH(gridCellInfo,i*fNumCols+j).bottomRight = INDEXH(ptIndexHdl,(i+1)*fNumCols_ext+j+1); } else INDEXH(gridCellInfo,i*fNumCols+j).cellNum = -1; } } ntri = cellNum*2; // each water cell is split into two triangles if(!(topo = (TopologyHdl)_NewHandleClear(ntri * sizeof(Topology)))){err = memFullErr; goto done;} for (i=0;i<nv_ext;i++) { if (INDEXH(ptIndexHdl,i) != -1) { INDEXH(verdatPtsH,numVerdatPts) = i; //INDEXH(verdatPtsH,INDEXH(ptIndexHdl,i)) = i; numVerdatPts++; } } _SetHandleSize((Handle)verdatPtsH,numVerdatPts*sizeof(**verdatPtsH)); pts = (LongPointHdl)_NewHandle(sizeof(LongPoint)*(numVerdatPts)); if(pts == nil) { strcpy(errmsg,"Not enough memory to triangulate data."); return -1; } for (i=0; i<=numVerdatPts; i++) // make a list of grid points that will be used for triangles { float fLong, fLat, fDepth, dLon, dLat, dLon1, dLon2, dLat1, dLat2; //double val, u=0., v=0.; LongPoint vertex; if(i < numVerdatPts) { // since velocities are defined at the lower left corner of each grid cell // need to add an extra row/col at the top/right of the grid // set lat/lon based on distance between previous two points // these are just for boundary/drawing purposes, velocities are set to zero index = i+1; n = INDEXH(verdatPtsH,i); iIndex = n/fNumCols_ext; jIndex = n%fNumCols_ext; if (iIndex==0) { if (jIndex<fNumCols) { dLat = INDEXH(fVertexPtsH,fNumCols+jIndex).pLat - INDEXH(fVertexPtsH,jIndex).pLat; fLat = INDEXH(fVertexPtsH,jIndex).pLat - dLat; dLon = INDEXH(fVertexPtsH,fNumCols+jIndex).pLong - INDEXH(fVertexPtsH,jIndex).pLong; fLong = INDEXH(fVertexPtsH,jIndex).pLong - dLon; } else { dLat1 = (INDEXH(fVertexPtsH,jIndex-1).pLat - INDEXH(fVertexPtsH,jIndex-2).pLat); dLat2 = INDEXH(fVertexPtsH,fNumCols+jIndex-1).pLat - INDEXH(fVertexPtsH,fNumCols+jIndex-2).pLat; fLat = 2*(INDEXH(fVertexPtsH,jIndex-1).pLat + dLat1)-(INDEXH(fVertexPtsH,fNumCols+jIndex-1).pLat+dLat2); dLon1 = INDEXH(fVertexPtsH,fNumCols+jIndex-1).pLong - INDEXH(fVertexPtsH,jIndex-1).pLong; dLon2 = (INDEXH(fVertexPtsH,fNumCols+jIndex-2).pLong - INDEXH(fVertexPtsH,jIndex-2).pLong); fLong = 2*(INDEXH(fVertexPtsH,jIndex-1).pLong-dLon1)-(INDEXH(fVertexPtsH,jIndex-2).pLong-dLon2); } } else { if (jIndex<fNumCols) { fLat = INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex).pLat; fLong = INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex).pLong; //u = INDEXH(velocityH,(iIndex-1)*fNumCols+jIndex).u; //v = INDEXH(velocityH,(iIndex-1)*fNumCols+jIndex).v; } else { dLat = INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex-1).pLat - INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex-2).pLat; fLat = INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex-1).pLat + dLat; dLon = INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex-1).pLong - INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex-2).pLong; fLong = INDEXH(fVertexPtsH,(iIndex-1)*fNumCols+jIndex-1).pLong + dLon; } } vertex.v = (long)(fLat*1e6); vertex.h = (long)(fLong*1e6); fDepth = 1.; INDEXH(pts,i) = vertex; } else { // for outputting a verdat the last line should be all zeros index = 0; fLong = fLat = fDepth = 0.0; } ///////////////////////////////////////////////// } // figure out the bounds triBounds = voidWorldRect; if(pts) { LongPoint thisLPoint; if(numVerdatPts > 0) { WorldPoint wp; for(i=0;i<numVerdatPts;i++) { thisLPoint = INDEXH(pts,i); wp.pLat = thisLPoint.v; wp.pLong = thisLPoint.h; AddWPointToWRect(wp.pLat, wp.pLong, &triBounds); } } } DisplayMessage("NEXTMESSAGETEMP"); DisplayMessage("Making Triangles"); ///////////////////////////////////////////////// for (i=0;i<fNumRows;i++) { for (j=0;j<fNumCols;j++) { if (INDEXH(landWaterInfo,i*fNumCols+j)==-1) continue; waterCellNum = INDEXH(gridCellInfo,i*fNumCols+j).cellNum; // split each cell into 2 triangles triIndex1 = 2*waterCellNum; triIndex2 = 2*waterCellNum+1; // top/left tri in rect (*topo)[triIndex1].vertex1 = INDEXH(gridCellInfo,i*fNumCols+j).topRight; (*topo)[triIndex1].vertex2 = INDEXH(gridCellInfo,i*fNumCols+j).topLeft; (*topo)[triIndex1].vertex3 = INDEXH(gridCellInfo,i*fNumCols+j).bottomLeft; if (j==0 || INDEXH(gridCellInfo,i*fNumCols+j-1).cellNum == -1) (*topo)[triIndex1].adjTri1 = -1; else { (*topo)[triIndex1].adjTri1 = INDEXH(gridCellInfo,i*fNumCols+j-1).cellNum * 2 + 1; } (*topo)[triIndex1].adjTri2 = triIndex2; if (i==0 || INDEXH(gridCellInfo,(i-1)*fNumCols+j).cellNum==-1) (*topo)[triIndex1].adjTri3 = -1; else { (*topo)[triIndex1].adjTri3 = INDEXH(gridCellInfo,(i-1)*fNumCols+j).cellNum * 2 + 1; } // bottom/right tri in rect (*topo)[triIndex2].vertex1 = INDEXH(gridCellInfo,i*fNumCols+j).bottomLeft; (*topo)[triIndex2].vertex2 = INDEXH(gridCellInfo,i*fNumCols+j).bottomRight; (*topo)[triIndex2].vertex3 = INDEXH(gridCellInfo,i*fNumCols+j).topRight; if (j==fNumCols-1 || INDEXH(gridCellInfo,i*fNumCols+j+1).cellNum == -1) (*topo)[triIndex2].adjTri1 = -1; else { (*topo)[triIndex2].adjTri1 = INDEXH(gridCellInfo,i*fNumCols+j+1).cellNum * 2; } (*topo)[triIndex2].adjTri2 = triIndex1; if (i==fNumRows-1 || INDEXH(gridCellInfo,(i+1)*fNumCols+j).cellNum == -1) (*topo)[triIndex2].adjTri3 = -1; else { (*topo)[triIndex2].adjTri3 = INDEXH(gridCellInfo,(i+1)*fNumCols+j).cellNum * 2; } } } DisplayMessage("NEXTMESSAGETEMP"); DisplayMessage("Making Dag Tree"); MySpinCursor(); // JLM 8/4/99 tree = MakeDagTree(topo, (LongPoint**)pts, errmsg); MySpinCursor(); // JLM 8/4/99 if (errmsg[0]) {err = -1; goto done;} // sethandle size of the fTreeH to be tree.fNumBranches, the rest are zeros _SetHandleSize((Handle)tree.treeHdl,tree.numBranches*sizeof(DAG)); ///////////////////////////////////////////////// fVerdatToNetCDFH = verdatPtsH; ///////////////////////////////////////////////// triGrid = new TTriGridVel; if (!triGrid) { err = true; TechError("Error in NetCDFWindMoverCurv::ReorderPoints()","new TTriGridVel",err); goto done; } fGrid = (TTriGridVel*)triGrid; triGrid -> SetBounds(triBounds); dagTree = new TDagTree(pts,topo,tree.treeHdl,velH,tree.numBranches); if(!dagTree) { err = -1; printError("Unable to create dag tree."); goto done; } triGrid -> SetDagTree(dagTree); //triGrid -> SetDepths(totalDepthH); // used by PtCurMap to check vertical movement pts = 0; // because fGrid is now responsible for it topo = 0; // because fGrid is now responsible for it velH = 0; // because fGrid is now responsible for it tree.treeHdl = 0; // because fGrid is now responsible for it velH = 0; // because fGrid is now responsible for it ///////////////////////////////////////////////// done: if (landWaterInfo) {DisposeHandle((Handle)landWaterInfo); landWaterInfo=0;} if (ptIndexHdl) {DisposeHandle((Handle)ptIndexHdl); ptIndexHdl = 0;} if (gridCellInfo) {DisposeHandle((Handle)gridCellInfo); gridCellInfo = 0;} if(err) { if(!errmsg[0]) strcpy(errmsg,"An error occurred in NetCDFWindMoverCurv::ReorderPoints"); printError(errmsg); if(pts) {DisposeHandle((Handle)pts); pts=0;} if(topo) {DisposeHandle((Handle)topo); topo=0;} if(velH) {DisposeHandle((Handle)velH); velH=0;} if(tree.treeHdl) {DisposeHandle((Handle)tree.treeHdl); tree.treeHdl=0;} if(fGrid) { fGrid ->Dispose(); delete fGrid; fGrid = 0; } if (verdatPtsH) {DisposeHandle((Handle)verdatPtsH); verdatPtsH = 0;} if (maskH2) {DisposeHandle((Handle)maskH2); maskH2 = 0;} } if (velocityH) {DisposeHandle((Handle)velocityH); velocityH = 0;} return err; }
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; }
OSErr TriCurMover_c::CalculateVerticalGrid(LongPointHdl ptsH, FLOATH totalDepthH, TopologyHdl topH, long numTri, FLOATH sigmaLevelsH, long numSigmaLevels) { long i,j,index=0,numDepths; long ptIndex1,ptIndex2,ptIndex3; float depth1,depth2,depth3; double depthAtPoint; FLOATH depthsH = 0; DepthDataInfoH depthDataInfo = 0; OSErr err = 0; if (fVar.gridType == TWO_D) // may want an option to handle 2D here { if (numSigmaLevels != 0) {printError("2D grid can't have sigma levels"); return -1;} } if (!totalDepthH || !topH) return -1; numTri = _GetHandleSize((Handle)topH)/sizeof(**topH); if (fVar.gridType != TWO_D) { if (!sigmaLevelsH) return -1; depthsH = (FLOATH)_NewHandle(sizeof(float)*numSigmaLevels*numTri); if(!depthsH) {TechError("TriCurMover::CalculateVerticalGrid()", "_NewHandle()", 0); err = memFullErr; goto done;} } depthDataInfo = (DepthDataInfoH)_NewHandle(sizeof(**depthDataInfo)*numTri); if(!depthDataInfo){TechError("TriCurMover::CalculateVerticalGrid()", "_NewHandle()", 0); err = memFullErr; goto done;} numDepths = numSigmaLevels; if (numDepths==0) numDepths = 1; for (i=0;i<numTri;i++) { // get the index into the pts handle for each vertex ptIndex1 = (*topH)[i].vertex1; ptIndex2 = (*topH)[i].vertex2; ptIndex3 = (*topH)[i].vertex3; depth1 = (*totalDepthH)[ptIndex1]; depth2 = (*totalDepthH)[ptIndex2]; depth3 = (*totalDepthH)[ptIndex3]; depthAtPoint = (depth1 + depth2 + depth3) / 3.; (*depthDataInfo)[i].totalDepth = depthAtPoint; (*depthDataInfo)[i].indexToDepthData = index; (*depthDataInfo)[i].numDepths = numDepths; for (j=0;j<numSigmaLevels;j++) { (*depthsH)[index+j] = (*sigmaLevelsH)[j] * depthAtPoint; } index+=numDepths; } fDepthsH = depthsH; fDepthDataInfo = depthDataInfo; done: if(err) { if(depthDataInfo) {DisposeHandle((Handle)depthDataInfo); depthDataInfo = 0;} if(depthsH) {DisposeHandle((Handle)depthsH); depthsH = 0;} } return err; }