OSErr GridCurrentMover::Read(BFPB *bfpb) { long version; ClassID id; OSErr err = 0; if (err = TCurrentMover::Read(bfpb)) return err; StartReadWriteSequence("GridCurrentMover::Read()"); if (err = ReadMacValue(bfpb,&id)) return err; if (id != GetClassID ()) { TechError("GridCurrentMover::Read()", "id != TYPE_GRIDCURRENTMOVER", 0); return -1; } if (err = ReadMacValue(bfpb,&version)) return err; if (version > GridCurrentMoverREADWRITEVERSION) { printSaveFileVersionError(); return -1; } //// // read the type of grid used for the GridCurrent mover if (err = ReadMacValue(bfpb,&id)) return err; switch(id) { case TYPE_TIMEGRIDVELRECT: timeGrid = new TimeGridVelRect; break; //case TYPE_TIMEGRIDVEL: timeGrid = new TimeGridVel; break; case TYPE_TIMEGRIDVELCURV: timeGrid = new TimeGridVelCurv; break; case TYPE_TIMEGRIDVELTRI: timeGrid = new TimeGridVelTri; break; case TYPE_TIMEGRIDCURRECT: timeGrid = new TimeGridCurRect; break; case TYPE_TIMEGRIDCURTRI: timeGrid = new TimeGridCurTri; break; default: printError("Unrecognized Grid type in GridCurrentMover::Read()."); return -1; } // code goes here, should also have a name/path done: if(err) { TechError("GridCurrentMover::Read(char* path)", " ", 0); } return err; }
OSErr ComponentMover_c::TextRead(char *cats_path1, char *cats_path2) { OSErr err = 0; TTriGridVel *triGrid = 0; TCATSMover *newCATSMover1 = 0; TCATSMover *newCATSMover2 = 0; if (!cats_path1[0]) return -1; newCATSMover1 = new TCATSMover; if (!newCATSMover1) { TechError("CreateAndInitCurrentsMover()", "new TCATSMover()", 0); return -1; } err = newCATSMover1->TextRead(cats_path1); if (!err) pattern1 = newCATSMover1; if (cats_path2[0]) { newCATSMover2 = new TCATSMover; if (!newCATSMover2) { TechError("CreateAndInitCurrentsMover()", "new TCATSMover()", 0); return -1; } err = newCATSMover2->TextRead(cats_path2); if (!err) pattern2 = newCATSMover2; } return err; }
OSErr TimeGridWindRect::Read(BFPB *bfpb) { char c, msg[256], fileName[256], newFileName[64]; long i, version, numTimes, numPoints; ClassID id; float val; Seconds time; Boolean bPathIsValid = true; OSErr err = 0; if (err = TimeGridVel::Read(bfpb)) return err; StartReadWriteSequence("TimeGridWindRect::Read()"); if (err = ReadMacValue(bfpb, &id)) return err; if (id != GetClassID ()) { TechError("TimeGridWindRect::Read()", "id != TYPE_TIMEGRIDWINDRECT", 0); return -1; } if (err = ReadMacValue(bfpb, &version)) return err; if (version > TimeGridWindRectREADWRITEVERSION) { printSaveFileVersionError(); return -1; } // anything here? done: if(err) { TechError("TimeGridWindRect::Read(char* path)", " ", 0); if(fTimeHdl) {DisposeHandle((Handle)fTimeHdl); fTimeHdl=0;} } return err; }
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; }
short ChooseWindMoverDialog(char* classNameOfSelectedGrid) //JLM added param { short dialogItem = 0; long i, j, m, n; TMap *map; TMover *mover; OSErr err = 0; strcpy(sharedFileName,classNameOfSelectedGrid);//JLM 8/14/98 sharedMoverList = new CMyList(sizeof(TMover *)); if (!sharedMoverList) { TechError("ChooseWindMoverDialog()", "new CMyList()", 0); return -1; } if (err = sharedMoverList->IList()) { TechError("ChooseWindMoverDialog()", "IList()", 0); return -1; } for (j = 0, m = model->mapList->GetItemCount() ; j < m ; j++) { model->mapList->GetListItem((Ptr)&map, j); for (i = 0, n = map->moverList->GetItemCount() ; i < n ; i++) { map->moverList->GetListItem((Ptr)&mover, i); if (mover->GetClassID() != TYPE_WINDMOVER) continue; if (err = sharedMoverList->AppendItem((Ptr)&mover)) { TechError("ChooseWindMoverDialog()", "AppendItem()", err); return -1; } } } // append any wind movers belonging to the universal map, STH map = model -> uMap; for (i = 0, n = map->moverList->GetItemCount() ; i < n ; i++) { map->moverList->GetListItem((Ptr)&mover, i); if (mover->GetClassID() != TYPE_WINDMOVER) continue; if (err = sharedMoverList->AppendItem((Ptr)&mover)) { TechError("ChooseWindMoverDialog()", "AppendItem()", err); return -1; } } if (sharedMoverList->GetItemCount() == 0) { printError("There are no wind movers loaded."); dialogItem = M17CANCEL; } else SelectFromVListDialog(M17, M17LIST, sharedMoverList->GetItemCount(), M17Init, 0, 0, M17Draw, M17Click, FALSE, &dialogItem); sharedMoverList->Dispose(); delete sharedMoverList; strcpy(classNameOfSelectedGrid,sharedFileName);//JLM 8/14/98 return name through parameter return dialogItem; }
OSErr Random3DSettingsDialog(TRandom3D *mover, TMap *owner) { short item; TRandom3D *newMover = 0; OSErr err = 0; if (!mover) { newMover = new TRandom3D(owner, "3D Diffusion"); if (!newMover) { TechError("RandomSettingsDialog()", "new TRandom3D()", 0); return -1; } if (err = newMover->InitMover()) { delete newMover; return err; } sharedRMover3D = newMover; } else sharedRMover3D = mover; item = MyModalDialog(M28b, mapWindow, 0, M28bInit, M28bClick); if (item == M28bOK) model->NewDirtNotification(); if (newMover) { if (item == M28bOK) { if (err = owner->AddMover(newMover, 0)) { newMover->Dispose(); delete newMover; return -1; } } else { newMover->Dispose(); delete newMover; } } return 0; }
OSErr TRandom3D::Read(BFPB *bfpb) { long version; ClassID id; OSErr err = 0; if (err = TMover::Read(bfpb)) return err; StartReadWriteSequence("TRandom3D::Read()"); if (err = ReadMacValue(bfpb, &id)) return err; if (id != GetClassID ()) { TechError("TRandom3D::Read()", "id != GetClassID", 0); return -1; } if (err = ReadMacValue(bfpb, &version)) return err; if (version > TRandom3D_FileVersion) { printSaveFileVersionError(); return -1; } if (err = ReadMacValue(bfpb, &fDiffusionCoefficient)) return err; if (err = ReadMacValue(bfpb, &fUncertaintyFactor)) return err; if (gMearnsVersion || version > 1) { if (err = ReadMacValue(bfpb, &fVerticalDiffusionCoefficient)) return err; if (err = ReadMacValue(bfpb, &fHorizontalDiffusionCoefficient)) return err; //if (err = ReadMacValue(bfpb, &fVerticalDiffusionCoefficient)) return err; } if (version>1) if (err = ReadMacValue(bfpb, &bUseDepthDependentDiffusion)) return err; return 0; }
long AddUniquelySorted(DOUBLEH h, double value) { long curSize = _GetHandleSize((Handle)h); long i,index,nElements = GetNumDoubleHdlItems(h); double diff,epsilon=1e-6; for(i=0; i<nElements; i++) { diff = value - (*h)[i]; if(diff < 0) break; if(diff >= -epsilon && diff <= epsilon) { return 0; // already in list } } index = i; _SetHandleSize((Handle)h,curSize + sizeof(double)); if (_MemError()) { TechError("Out of memory", "_SetHandleSize()", 0); SysBeep(5); return -1; } if(nElements > 0) { for(i= nElements - 1; i >= index; i--) { (*h)[i+1] = (*h)[i]; } } (*h)[index] = value; return index; }
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 InsertSegment(SEGMENTH *segments, long *numSegs, long index, WorldPoint m) { long i; if ((m.pLong == INDEXH(*segments, index).toLong && m.pLat == INDEXH(*segments, index).toLat) || (m.pLong == INDEXH(*segments, index).fromLong && m.pLat == INDEXH(*segments, index).fromLat)) return 0; _SetHandleSize((Handle)*segments, ((*numSegs) + 1) * sizeof(Segment)); if (_MemError()) { TechError("AddSegment()", "_SetHandleSize()", 0); return -1; } // old way: insert at end //INDEXH(*segments, *numSegs) = INDEXH(*segments, index); //INDEXH(*segments, index).toLong = m.pLong; //INDEXH(*segments, index).toLat = m.pLat; //INDEXH(*segments, *numSegs).fromLong = m.pLong; //INDEXH(*segments, *numSegs).fromLat = m.pLat; (*numSegs)++; // new way: insert as next segment for (i = (*numSegs) - 1 ; i > index ; i--) INDEXH(*segments, i) = INDEXH(*segments, i - 1); INDEXH(*segments, index).toLong = m.pLong; INDEXH(*segments, index).toLat = m.pLat; INDEXH(*segments, index + 1).fromLong = m.pLong; INDEXH(*segments, index + 1).fromLat = m.pLat; return 0; }
OSErr NetCDFWindMoverCurv::Read(BFPB *bfpb) { long i, version, index, numPoints; ClassID id; WorldPointF vertex; OSErr err = 0; if (err = NetCDFWindMover::Read(bfpb)) return err; StartReadWriteSequence("NetCDFWindMoverCurv::Read()"); if (err = ReadMacValue(bfpb,&id)) return err; if (id != GetClassID ()) { TechError("NetCDFWindMoverCurv::Read()", "id != TYPE_NETCDFWINDMOVERCURV", 0); return -1; } if (err = ReadMacValue(bfpb,&version)) return err; if (version != NetCDFWindMoverCurvREADWRITEVERSION) { printSaveFileVersionError(); return -1; } //// if (err = ReadMacValue(bfpb, &numPoints)) goto done; if (numPoints > 0) { fVerdatToNetCDFH = (LONGH)_NewHandleClear(sizeof(long)*numPoints); // for curvilinear if(!fVerdatToNetCDFH) {TechError("NetCDFWindMoverCurv::Read()", "_NewHandle()", 0); err = memFullErr; goto done;} for (i = 0 ; i < numPoints ; i++) { if (err = ReadMacValue(bfpb, &index)) goto done; INDEXH(fVerdatToNetCDFH, i) = index; } } if (err = ReadMacValue(bfpb, &numPoints)) goto done; fVertexPtsH = (WORLDPOINTFH)_NewHandleClear(sizeof(WorldPointF)*numPoints); // for curvilinear if(!fVertexPtsH) {TechError("NetCDFWindMoverCurv::Read()", "_NewHandle()", 0); err = memFullErr; goto done;} for (i = 0 ; i < numPoints ; i++) { if (err = ReadMacValue(bfpb, &vertex.pLat)) goto done; if (err = ReadMacValue(bfpb, &vertex.pLong)) goto done; INDEXH(fVertexPtsH, i) = vertex; } done: if(err) { TechError("NetCDFWindMoverCurv::Read(char* path)", " ", 0); if(fVerdatToNetCDFH) {DisposeHandle((Handle)fVerdatToNetCDFH); fVerdatToNetCDFH=0;} if(fVertexPtsH) {DisposeHandle((Handle)fVertexPtsH); fVertexPtsH=0;} } return err; }
OSErr GridWindMover::Read(BFPB *bfpb) { char c, msg[256], fileName[256], newFileName[64]; long i, version, numTimes, numPoints; ClassID id; float val; Seconds time; Boolean bPathIsValid = true; OSErr err = 0; if (err = TWindMover::Read(bfpb)) return err; StartReadWriteSequence("GridWindMover::Read()"); if (err = ReadMacValue(bfpb, &id)) return err; if (id != GetClassID ()) { TechError("GridWindMover::Read()", "id != TYPE_GRIDWINDMOVER", 0); return -1; } if (err = ReadMacValue(bfpb, &version)) return err; if (version > GridWindMoverREADWRITEVERSION) { printSaveFileVersionError(); return -1; } // read the type of grid used for the GridWind mover if (err = ReadMacValue(bfpb,&id)) return err; switch(id) { case TYPE_TIMEGRIDWINDRECT: timeGrid = new TimeGridVelRect; break; //case TYPE_TIMEGRIDVEL: timeGrid = new TimeGridVel; break; case TYPE_TIMEGRIDWINDCURV: timeGrid = new TimeGridVelCurv; break; default: printError("Unrecognized Grid type in GridWindMover::Read()."); return -1; } // if (err = ReadMacValue(bfpb, &bShowGrid)) return err; if (err = ReadMacValue(bfpb, &bShowArrows)) return err; if (err = ReadMacValue(bfpb, &fUserUnits)) return err; if (err = ReadMacValue(bfpb, &fArrowScale)) return err; if (err = ReadMacValue(bfpb, &fWindScale)) return err; ///////////////// done: if(err) { TechError("GridWindMover::Read(char* path)", " ", 0); } return err; }
short ChooseOtherGridDialog(TCATSMover *connectingCMover,char* classNameOfSelectedGrid) //JLM added param { short dialogItem = 0; long i, j, m, n; TMap *map; TMover *mover; OSErr err = 0; strcpy(sharedFileName,classNameOfSelectedGrid);//JLM 8/14/98 sharedMoverList = new CMyList(sizeof(TMover *)); if (!sharedMoverList) { TechError("ChooseOtherGridDialog()", "new CMyList()", 0); return -1; } if (err = sharedMoverList->IList()) { TechError("ChooseOtherGridDialog()", "IList()", 0); return -1; } for (j = 0, m = model->mapList->GetItemCount() ; j < m ; j++) { model->mapList->GetListItem((Ptr)&map, j); for (i = 0, n = map->moverList->GetItemCount() ; i < n ; i++) { map->moverList->GetListItem((Ptr)&mover, i); if (mover->GetClassID() != TYPE_CATSMOVER) continue; if (!strcmp(mover->className, connectingCMover->className)) continue;// i.e. don't let it chooose one with the same name if (err = sharedMoverList->AppendItem((Ptr)&mover)) { TechError("ChooseOtherGridDialog()", "AppendItem()", err); return -1; } } } if (sharedMoverList->GetItemCount() == 0) { printError("There are no other current grids loaded."); dialogItem = M17CANCEL; } else SelectFromVListDialog(M17, M17LIST, sharedMoverList->GetItemCount(), M17Init, 0, 0, M17Draw, M17Click, FALSE, &dialogItem); sharedMoverList->Dispose(); delete sharedMoverList; strcpy(classNameOfSelectedGrid,sharedFileName);//JLM 8/14/98 return name through parameter return dialogItem; }
OSErr ADCPMover_c::AddTimeDep(ADCPTimeValue *theTimeDep, short where) { OSErr err = 0; if (err = timeDepList->AppendItem((Ptr)&theTimeDep)) { TechError("ADCPMover::AddTimeDep()", "AppendItem()", err); return err; } SelectListItemOfOwner(theTimeDep); return 0; }
OSErr AddSegment(SEGMENTH *segments, long *numSegs, Segment s) { _SetHandleSize((Handle)*segments, ((*numSegs) + 1) * sizeof(Segment)); if (_MemError()) { TechError("AddSegment()", "_SetHandleSize()", 0); return -1; } INDEXH(*segments, *numSegs) = s; (*numSegs)++; return 0; }
OSErr ADCPMover_c::DropTimeDep(ADCPTimeValue *theTimeDep) { long i; OSErr err = 0; if (timeDepList->IsItemInList((Ptr)&theTimeDep, &i)) if (err = timeDepList->DeleteItem(i)) { TechError("ADCPMover::DropTimeDep()", "DeleteItem()", err); return err; } return 0; }
TOSSMTimeValue* CreateTOSSMTimeValue(TMover *theOwner,char* path, char* shortFileName, short unitsIfKnownInAdvance) { char tempStr[256]; OSErr err = 0; if(IsShioFile(path)) { TShioTimeValue *timeValObj = new TShioTimeValue(theOwner); if (!timeValObj) { TechError("LoadTOSSMTimeValue()", "new TShioTimeValue()", 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;} return timeValObj; } else if (IsTimeFile(path) || IsHydrologyFile(path) || IsOSSMTimeFile(path, &unitsIfKnownInAdvance)) { TOSSMTimeValue *timeValObj = new TOSSMTimeValue(theOwner); if (!timeValObj) { TechError("LoadTOSSMTimeValue()", "new TOSSMTimeValue()", 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;} return timeValObj; } // code goes here, add code for OSSMHeightFiles, need scale factor to calculate derivative else { sprintf(tempStr,"File %s is not a recognizable time file.",shortFileName); printError(tempStr); } return nil; }
OSErr TriCurMover_c::AddUncertainty(long setIndex, long leIndex,VelocityRec *velocity,double timeStep,Boolean useEddyUncertainty) { LEUncertainRec unrec; double u,v,lengthS,alpha,beta,v0; OSErr err = 0; //err = this -> UpdateUncertainty(); if(err) return err; if(!fUncertaintyListH || !fLESetSizesH) return 0; // this is our clue to not add uncertainty if(fUncertaintyListH && fLESetSizesH) { unrec=(*fUncertaintyListH)[(*fLESetSizesH)[setIndex]+leIndex]; lengthS = sqrt(velocity->u*velocity->u + velocity->v * velocity->v); u = velocity->u; v = velocity->v; if(lengthS < fVar.uncertMinimumInMPS) { // use a diffusion ?? printError("nonzero UNCERTMIN is unimplemented"); //err = -1; } else { // normal case, just use cross and down stuff alpha = unrec.downStream; beta = unrec.crossStream; velocity->u = u*(1+alpha)+v*beta; velocity->v = v*(1+alpha)-u*beta; } } else { TechError("TriCurMover::AddUncertainty()", "fUncertaintyListH==nil", 0); err = -1; velocity->u=velocity->v=0; } return err; }
OSErr TimeGridWindRect::Write(BFPB *bfpb) { long i, version = TimeGridWindRectREADWRITEVERSION; ClassID id = GetClassID (); Seconds time; OSErr err = 0; if (err = TimeGridVel::Write(bfpb)) return err; StartReadWriteSequence("TimeGridWindRect::Write()"); if (err = WriteMacValue(bfpb, id)) return err; if (err = WriteMacValue(bfpb, version)) return err; // anything here? done: if(err) TechError("TimeGridWindRect::Write(char* path)", " ", 0); return err; }
OSErr TClassID::Read(BFPB *bfpb) { long version; ClassID id; OSErr err = noErr; StartReadWriteSequence("TClassID::::Read()"); if (err = ReadMacValue(bfpb, &id)) return err; if (id != GetClassID ()) { TechError("TClassID::Read()", "id != GetClassID", 0); return -1; } if (err = ReadMacValue(bfpb, &version)) return err; if (version != TClassID_FileVersion) { printSaveFileVersionError(); return -1; } bDirty = false; // we are reading if (err = ReadMacValue(bfpb, &bOpen)) return err; if (err = ReadMacValue(bfpb, &bActive)) return err; if (err = ReadMacValue(bfpb, className, kMaxNameLen)) return err; if (err = ReadMacValue(bfpb, &fUniqueID.ticksAtCreation)) return err; if (err = ReadMacValue(bfpb, &fUniqueID.counter)) return err; return err; }
OSErr ComponentMover_c::AddUncertainty(long setIndex, long leIndex,VelocityRec *patVelocity,double timeStep) { double u,v,lengthS,alpha,beta; LEUncertainRec unrec; OSErr err = 0; //err = this -> UpdateUncertainty(); //if(err) return err; if(!fUncertaintyListH || !fLESetSizesH) return 0; // this is our clue to not add uncertainty if(fUncertaintyListH && fLESetSizesH) { unrec=(*fUncertaintyListH)[(*fLESetSizesH)[setIndex]+leIndex]; lengthS = sqrt(patVelocity->u*patVelocity->u + patVelocity->v * patVelocity->v); u = patVelocity->u; v = patVelocity->v; if(lengthS>1e-6) // so we don't divide by zero { alpha = unrec.downStream; beta = unrec.crossStream; patVelocity->u = u*(1+alpha)+v*beta; patVelocity->v = v*(1+alpha)-u*beta; } } else { TechError("TComponentMover::AddUncertainty()", "fUncertaintyListH==nil", 0); patVelocity->u=patVelocity->v=0; } return err; }
OSErr TimeGridWindCurv::Write (BFPB *bfpb) { long i, version = TimeGridWindCurvREADWRITEVERSION; //JLM ClassID id = GetClassID (); long numPoints, index; WorldPointF vertex; OSErr err = 0; if (err = TimeGridWindRect::Write (bfpb)) return err; StartReadWriteSequence("TimeGridWindCurv::Write()"); if (err = WriteMacValue(bfpb, id)) return err; if (err = WriteMacValue(bfpb, version)) return err; //// numPoints = _GetHandleSize((Handle)fVerdatToNetCDFH)/sizeof(**fVerdatToNetCDFH); if (err = WriteMacValue(bfpb, numPoints)) goto done; for (i=0;i<numPoints;i++) { index = INDEXH(fVerdatToNetCDFH,i); if (err = WriteMacValue(bfpb, index)) goto done; } numPoints = _GetHandleSize((Handle)fVertexPtsH)/sizeof(**fVertexPtsH); if (err = WriteMacValue(bfpb, numPoints)) goto done; for (i=0;i<numPoints;i++) { vertex = INDEXH(fVertexPtsH,i); if (err = WriteMacValue(bfpb, vertex.pLat)) goto done; if (err = WriteMacValue(bfpb, vertex.pLong)) goto done; } done: if(err) TechError("TimeGridWindCurv::Write(char* path)", " ", 0); return err; }
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; }
OSErr GridWindMover::Write(BFPB *bfpb) { long i, version = GridWindMoverREADWRITEVERSION; ClassID id = GetClassID (); long numTimes = timeGrid->GetNumTimesInFile(); Seconds time; OSErr err = 0; if (err = TWindMover::Write(bfpb)) return err; StartReadWriteSequence("GridWindMover::Write()"); if (err = WriteMacValue(bfpb, id)) return err; if (err = WriteMacValue(bfpb, version)) return err; //// id = timeGrid -> GetClassID (); if (err = WriteMacValue(bfpb, id)) return err; if (err = timeGrid -> Write (bfpb)) goto done; //if (err = WriteMacValue(bfpb, fPathName, kMaxNameLen)) goto done; //if (err = WriteMacValue(bfpb, fFileName, kPtCurUserNameLen)) return err; if (err = WriteMacValue(bfpb, bShowGrid)) return err; if (err = WriteMacValue(bfpb, bShowArrows)) return err; if (err = WriteMacValue(bfpb, fUserUnits)) return err; if (err = WriteMacValue(bfpb, fArrowScale)) return err; if (err = WriteMacValue(bfpb, fWindScale)) return err; //////////////// done: if(err) TechError("GridWindMover::Write(char* path)", " ", 0); return err; }
OSErr GridCurrentMover::Write (BFPB *bfpb) { long version = GridCurrentMoverREADWRITEVERSION; //JLM ClassID id = GetClassID (); OSErr err = 0; if (err = TCurrentMover::Write (bfpb)) return err; StartReadWriteSequence("GridCurrentMover::Write()"); if (err = WriteMacValue(bfpb, id)) return err; if (err = WriteMacValue(bfpb, version)) return err; //// id = timeGrid -> GetClassID (); if (err = WriteMacValue(bfpb, id)) return err; if (err = timeGrid -> Write (bfpb)) goto done; // code goes here, may want to add a name/path done: if(err) TechError("GridCurrentMover::Write(char* path)", " ", 0); return err; }
//OSErr NetCDFWindMoverCurv::ReadTopology(char* path, TMap **newMap) OSErr NetCDFWindMoverCurv::ReadTopology(vector<string> &linesInFile, TMap **newMap) { // import NetCDF curvilinear info so don't have to regenerate char s[1024], errmsg[256]/*, s[256], topPath[256]*/; long i, numPoints, numTopoPoints, line = 0, numPts; string currentLine; //CHARH f = 0; OSErr err = 0; TopologyHdl topo=0; LongPointHdl pts=0; FLOATH depths=0; VelocityFH velH = 0; DAGTreeStruct tree; WorldRect bounds = voidWorldRect; TTriGridVel *triGrid = nil; tree.treeHdl = 0; TDagTree *dagTree = 0; long numWaterBoundaries, numBoundaryPts, numBoundarySegs; LONGH boundarySegs=0, waterBoundaries=0, boundaryPts=0; errmsg[0]=0; /*if (!path || !path[0]) return 0; if (err = ReadFileContents(TERMINATED,0, 0, path, 0, 0, &f)) { TechError("NetCDFWindMover::ReadTopology()", "ReadFileContents()", err); goto done; } _HLock((Handle)f); // JLM 8/4/99 */ // No header // start with transformation array and vertices MySpinCursor(); // JLM 8/4/99 //NthLineInTextOptimized(*f, (line)++, s, 1024); currentLine = linesInFile[line++]; //if(IsTransposeArrayHeaderLine(s,&numPts)) // if(IsTransposeArrayHeaderLine(currentLine,numPts)) // { //if (err = ReadTransposeArray(f,&line,&fVerdatToNetCDFH,numPts,errmsg)) if (err = ReadTransposeArray(linesInFile,&line,&fVerdatToNetCDFH,numPts,errmsg)) {strcpy(errmsg,"Error in ReadTransposeArray"); goto done;} } else {err=-1; strcpy(errmsg,"Error in Transpose header line"); goto done;} //if(err = ReadTVertices(f,&line,&pts,&depths,errmsg)) goto done; if(err = ReadTVertices(linesInFile,&line,&pts,&depths,errmsg)) goto done; if(pts) { LongPoint thisLPoint; numPts = _GetHandleSize((Handle)pts)/sizeof(LongPoint); if(numPts > 0) { WorldPoint wp; for(i=0;i<numPts;i++) { thisLPoint = INDEXH(pts,i); wp.pLat = thisLPoint.v; wp.pLong = thisLPoint.h; AddWPointToWRect(wp.pLat, wp.pLong, &bounds); } } } MySpinCursor(); currentLine = linesInFile[line++]; //NthLineInTextOptimized(*f, (line)++, s, 1024); //code goes here, boundary points //if(IsBoundarySegmentHeaderLine(s,&numBoundarySegs)) // Boundary data from CATs if(IsBoundarySegmentHeaderLine(currentLine,numBoundarySegs)) // Boundary data from CATs { MySpinCursor(); if (numBoundarySegs>0) //err = ReadBoundarySegs(f,&line,&boundarySegs,numBoundarySegs,errmsg); err = ReadBoundarySegs(linesInFile,&line,&boundarySegs,numBoundarySegs,errmsg); if(err) goto done; //NthLineInTextOptimized(*f, (line)++, s, 1024); currentLine = linesInFile[line++]; } else { //err = -1; //strcpy(errmsg,"Error in Boundary segment header line"); //goto done; // not needed for 2D files, but we require for now } MySpinCursor(); // JLM 8/4/99 //if(IsWaterBoundaryHeaderLine(s,&numWaterBoundaries,&numBoundaryPts)) // Boundary types from CATs if(IsWaterBoundaryHeaderLine(currentLine,numWaterBoundaries,numBoundaryPts)) // Boundary types from CATs { MySpinCursor(); if (numBoundaryPts>0) //err = ReadWaterBoundaries(f,&line,&waterBoundaries,numWaterBoundaries,numBoundaryPts,errmsg); err = ReadWaterBoundaries(linesInFile,&line,&waterBoundaries,numWaterBoundaries,numBoundaryPts,errmsg); if(err) goto done; //NthLineInTextOptimized(*f, (line)++, s, 1024); currentLine = linesInFile[line++]; } else { //err = -1; //strcpy(errmsg,"Error in Water boundaries header line"); //goto done; // not needed for 2D files, but we require for now } MySpinCursor(); // JLM 8/4/99 //NthLineInTextOptimized(*f, (line)++, s, 1024); //if(IsBoundaryPointsHeaderLine(s,&numBoundaryPts)) // Boundary data from CATs if(IsBoundaryPointsHeaderLine(currentLine,numBoundaryPts)) // Boundary data from CATs { MySpinCursor(); if (numBoundaryPts>0) //err = ReadBoundaryPts(f,&line,&boundaryPts,numBoundaryPts,errmsg); err = ReadBoundaryPts(linesInFile,&line,&boundaryPts,numBoundaryPts,errmsg); if(err) goto done; //NthLineInTextOptimized(*f, (line)++, s, 1024); currentLine = linesInFile[line++]; } else { //err = -1; //strcpy(errmsg,"Error in Boundary segment header line"); //goto done; // not always needed ? probably always needed for curvilinear } MySpinCursor(); // JLM 8/4/99 //if(IsTTopologyHeaderLine(s,&numTopoPoints)) // Topology from CATs if(IsTTopologyHeaderLine(currentLine,numTopoPoints)) // Topology from CATs { MySpinCursor(); //err = ReadTTopologyBody(f,&line,&topo,&velH,errmsg,numTopoPoints,FALSE); err = ReadTTopologyBody(linesInFile,&line,&topo,&velH,errmsg,numTopoPoints,FALSE); if(err) goto done; //NthLineInTextOptimized(*f, (line)++, s, 1024); currentLine = linesInFile[line++]; } else { err = -1; // for now we require TTopology strcpy(errmsg,"Error in topology header line"); if(err) goto done; } MySpinCursor(); // JLM 8/4/99 //NthLineInTextOptimized(*f, (line)++, s, 1024); //if(IsTIndexedDagTreeHeaderLine(s,&numPoints)) // DagTree from CATs if(IsTIndexedDagTreeHeaderLine(currentLine,numPoints)) // DagTree from CATs { MySpinCursor(); //err = ReadTIndexedDagTreeBody(f,&line,&tree,errmsg,numPoints); err = ReadTIndexedDagTreeBody(linesInFile,&line,&tree,errmsg,numPoints); if(err) goto done; } else { err = -1; // for now we require TIndexedDagTree strcpy(errmsg,"Error in dag tree header line"); if(err) goto done; } MySpinCursor(); // JLM 8/4/99 ///////////////////////////////////////////////// // if the boundary information is in the file we'll need to create a bathymetry map (required for 3D) /*if (waterBoundaries && (this -> moverMap == model -> uMap)) { //PtCurMap *map = CreateAndInitPtCurMap(fVar.userName,bounds); // the map bounds are the same as the grid bounds PtCurMap *map = CreateAndInitPtCurMap("Extended Topology",bounds); // the map bounds are the same as the grid bounds if (!map) {strcpy(errmsg,"Error creating ptcur map"); goto done;} // maybe move up and have the map read in the boundary information map->SetBoundarySegs(boundarySegs); map->SetWaterBoundaries(waterBoundaries); *newMap = map; }*/ { // wind will always be on another map if (waterBoundaries) {DisposeHandle((Handle)waterBoundaries); waterBoundaries=0;} if (boundarySegs) {DisposeHandle((Handle)boundarySegs); boundarySegs=0;} if (boundaryPts) {DisposeHandle((Handle)boundaryPts); boundaryPts=0;} } /*if (!(this -> moverMap == model -> uMap)) // maybe assume rectangle grids will have map? { if (waterBoundaries) {DisposeHandle((Handle)waterBoundaries); waterBoundaries=0;} if (boundarySegs) {DisposeHandle((Handle)boundarySegs); boundarySegs=0;} }*/ ///////////////////////////////////////////////// triGrid = new TTriGridVel; if (!triGrid) { err = true; TechError("Error in NetCDFWindMover::ReadTopology()","new TTriGridVel" ,err); goto done; } fGrid = (TTriGridVel*)triGrid; triGrid -> SetBounds(bounds); //triGrid -> SetDepths(depths); dagTree = new TDagTree(pts,topo,tree.treeHdl,velH,tree.numBranches); if(!dagTree) { err = -1; printError("Unable to read Extended Topology file."); goto done; } triGrid -> SetDagTree(dagTree); pts = 0; // because fGrid is now responsible for it topo = 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 //depths = 0; done: if(depths) {DisposeHandle((Handle)depths); depths=0;} /*if(f) { _HUnlock((Handle)f); DisposeHandle((Handle)f); f = 0; }*/ if(err) { if(!errmsg[0]) strcpy(errmsg,"An error occurred in NetCDFWindMoverCurv::ReadTopology"); printError(errmsg); if(pts) {DisposeHandle((Handle)pts); pts=0;} if(topo) {DisposeHandle((Handle)topo); topo=0;} if(velH) {DisposeHandle((Handle)velH); velH=0;} if(depths) {DisposeHandle((Handle)depths); depths=0;} if(tree.treeHdl) {DisposeHandle((Handle)tree.treeHdl); tree.treeHdl=0;} if(fGrid) { fGrid ->Dispose(); delete fGrid; fGrid = 0; } if (*newMap) { (*newMap)->Dispose(); delete *newMap; *newMap=0; } if (waterBoundaries) {DisposeHandle((Handle)waterBoundaries); waterBoundaries=0;} if (boundarySegs) {DisposeHandle((Handle)boundarySegs); boundarySegs = 0;} if (boundaryPts) {DisposeHandle((Handle)boundaryPts); boundaryPts = 0;} } return err; }
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; }
OSErr ADCPMover_c::AddUncertainty(long setIndex, long leIndex,VelocityRec *patVelocity,double timeStep,Boolean useEddyUncertainty) { /// 5/12/99 only add the eddy uncertainty when told to double u,v,lengthS,alpha,beta,v0,gammaScale; LEUncertainRec unrec; float rand1,rand2; OSErr err = 0; //err = this -> UpdateUncertainty(); //if(err) return err; if(!fUncertaintyListH || !fLESetSizesH) return 0; // this is our clue to not add uncertainty if(useEddyUncertainty) { if(this -> fOptimize.isFirstStep) { GetRandomVectorInUnitCircle(&rand1,&rand2); } else { rand1 = GetRandomFloat(-1.0, 1.0); rand2 = GetRandomFloat(-1.0, 1.0); } } else { // no need to calculate these when useEddyUncertainty is false rand1 = 0; rand2 = 0; } if(fUncertaintyListH && fLESetSizesH) { unrec=(*fUncertaintyListH)[(*fLESetSizesH)[setIndex]+leIndex]; lengthS = sqrt(patVelocity->u*patVelocity->u + patVelocity->v * patVelocity->v); u = patVelocity->u; v = patVelocity->v; if(!this -> fOptimize.isOptimizedForStep) this -> fOptimize.value = sqrt(6*(fEddyDiffusion/10000)/timeStep); // in m/s, note: DIVIDED by timestep because this is later multiplied by the timestep v0 = this -> fEddyV0; //meters /second if(lengthS>1e-6) // so we don't divide by zero { if(useEddyUncertainty) gammaScale = this -> fOptimize.value * v0 /(lengthS * (v0+lengthS)); else gammaScale = 0.0; alpha = unrec.downStream + gammaScale * rand1; beta = unrec.crossStream + gammaScale * rand2; patVelocity->u = u*(1+alpha)+v*beta; patVelocity->v = v*(1+alpha)-u*beta; } else { // when lengthS is too small, ignore the downstream and cross stream and only use diffusion uncertainty if(useEddyUncertainty) { // provided we are supposed to patVelocity->u = this -> fOptimize.value * rand1; patVelocity->v = this -> fOptimize.value * rand2; } } } else { TechError("ADCPMover::AddUncertainty()", "fUncertaintyListH==nil", 0); patVelocity->u=patVelocity->v=0; } return err; }
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; }
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; }