! ! Subroutines: ! ! LoadBase ! GetBase ! DrawBase ! LineOfNumbers ! ! SUBROUTINE LoadBase !*************************************************************************** !* * !* THIS SUBROUTINE CREATES A DIALOG BOX THAT ALLOWS THE USER TO INPUT THE * !* BASE FILE. THIS ROUTINE USES SIMILAR DIALOG ACCESS AS LOADGRID, * !* AND SAVEGRID. * !* CODES ARE USED REDUNDENTLY IN THREE ROUTINES, WHICH IS SORT OF QUICK- * !* AND-DIRTY WAY. NEW STRUCTURING NEEDED DURING FURTHER MODIFICATION!! * !*************************************************************************** use dflib use dfwin use Global implicit none type (t_openfilename) iofn logical(4) iRet integer(4) ierror character(26*7) allfilters character(60) dlgtitle logical(4) checked ! ! update statusbar ! call setstatusbar(0,'LoadBase'C) call setstatusbar(1,' 'C) ! ALLFILTERS = 'Digitized data files (*.dig)' // char (0) // '*.DIG' // char(0) // char(0) DLGTITLE = 'Input Basemap File Digitized Using DIGITISE'C !iofn%LSTRUCTSIZE = (BIT_SIZE(iofn%LSTRUCTSIZE) + & ! BIT_SIZE(iofn%HWNDOWNER) + & ! BIT_SIZE(iofn%HINSTANCE) + & ! BIT_SIZE(iofn%LPSTRFILTER) + & ! BIT_SIZE(iofn%LPSTRCUSTOMFILTER) + & ! BIT_SIZE(iofn%NMAXCUSTFILTER) + & ! BIT_SIZE(iofn%NFILTERINDEX) + & ! BIT_SIZE(iofn%LPSTRFILE) + & ! BIT_SIZE(iofn%NMAXFILE) + & ! BIT_SIZE(iofn%LPSTRFILETITLE) + & ! BIT_SIZE(iofn%NMAXFILETITLE) + & ! BIT_SIZE(iofn%LPSTRINITIALDIR) + & ! BIT_SIZE(iofn%LPSTRTITLE) + & ! BIT_SIZE(iofn%FLAGS) + & ! BIT_SIZE(iofn%NFILEOFFSET) + & ! BIT_SIZE(iofn%NFILEEXTENSION) + & ! BIT_SIZE(iofn%LPSTRDEFEXT) + & ! BIT_SIZE(iofn%LCUSTDATA) + & ! BIT_SIZE(iofn%LPFNHOOK) + & ! BIT_SIZE(iofn%LPTEMPLATENAME))/8 ! 8 bit = 1 Byte !N.B. When converting this program to the x64 platform, the above code stopped working; ! I found a hint on the web, and replaced it with: iofn%LSTRUCTSIZE = SizeOf(iofn) iofn%HWNDOWNER = GETHWNDQQ(QWIN$FRAMEWINDOW) iofn%HINSTANCE = NULL iofn%LPSTRFILTER = LOC(ALLFILTERS) iofn%LPSTRCUSTOMFILTER = NULL iofn%NMAXCUSTFILTER = NULL iofn%NFILTERINDEX = 1 iofn%LPSTRFILE = LOC(DIG_INP) iofn%NMAXFILE = LEN(DIG_INP) iofn%LPSTRFILETITLE = NULL iofn%NMAXFILETITLE = NULL iofn%LPSTRINITIALDIR = NULL iofn%LPSTRTITLE = LOC(DLGTITLE) iofn%FLAGS = NULL iofn%NFILEOFFSET = NULL iofn%NFILEEXTENSION = NULL iofn%LPSTRDEFEXT = NULL iofn%LCUSTDATA = NULL iofn%LPFNHOOK = NULL iofn%LPTEMPLATENAME = NULL iRet = GETOPENFILENAME(iofn) CALL COMDLGER(ierror) ! CHECK TO SEE IF THE OK BUTTON HAS BEEN PRESSED if(iRet .and. (ierror == 0)) then call GetBase end if if (baseLoaded) then if (gridLoaded) then call CLEARSCREEN($GCLEARSCREEN) call Redraw ! Redraw plots grid and basemap using user-defined zoom and windowPosition. else call DrawGrid ! DrawGrid plots basemap using default zoom and windowPosition, so .dig is visible. end if end if ! update statusbar infor. call setstatusbar(0,'Ready'C) call setstatusbar(1,' 'C) end subroutine LoadBase ! subroutine GetBase ! read into a basemap file. If file does not exist, then display a messagebox use dflib use global implicit none character(len = 512) msg0, msg1 character(len = 150) line integer(4) iRet, ierr, pointCount real(4) lon, lat, alpha, beta, gamma real(8) :: aSum, bSum, gSum logical AreNumbers logical AreNumOrEndmark ! if base already loaded, DEALLOCATE THE POINTS, AND ! DOUBLE-CHECK TO SEE IF THERE IS ANY MEMORY LEAK!! if (baseLoaded) then call ClearLinkList end if msg0 = ' 'C msg1 = ' 'C open(unit = 1, file = DIG_INP, status = 'old', Action = 'read', iostat = ierr) if (ierr /= 0) then msg0 = ' error opening input file ' //DIG_inp//' 'C msg1 = ' error opening file 'C iRet = messageboxqq(msg0, msg1, MB$ICONEXCLAMATION.OR.MB$OK) return endif aSum = 0.0D0; bSum = 0.0D0; gSum = 0.0D0 ! initialize sum of uvecs (for selecting WindowPosition). pointCount = 0 do while(.not.EOF(1)) read(1,'(A150)', iostat=ierr) line call LineofNumbers(line, AreNumbers) if(AreNumbers) then read(line, *, iostat=ierr) lon, lat if (ierr /=0) then msg1 = " Bad file format "C call error1(msg1) return endif lon = lon * .017453293 lat = lat * .017453293 alpha = cos(lat)*cos(lon) beta = cos(lat)*sin(lon) gamma = sin(lat) aSum = aSum + alpha bSum = bSum + beta gSum = gSum + gamma pointCount = pointCount + 1 AreNumOrEndmark = .true. elseif (line(1:3) == '***') then alpha = 99.0 beta = 99.0 gamma = 99.0 AreNumOrEndmark = .true. else AreNumOrEndmark = .false. end if ! store in dynamic data structure if (AreNumOrEndmark) then if (.not.associated(phead)) then allocate(phead, stat = ierr) ptail => phead nullify(ptail%next_point) ptail%alpha = alpha ptail%beta = beta ptail%gamma = gamma else allocate(ptail%next_point, stat = ierr) ptail => ptail%next_point nullify(ptail%next_point) ptail%alpha = alpha ptail%beta = beta ptail%gamma = gamma end if end if end do close(unit=1) ! ! successfully read (option to display confirmation dialog) !msg0 = ' Successfully reading input file ' //DIG_inp//' 'C !msg1 = ' Successfully reading file 'C !iRet = messageboxqq(msg0, msg1, MB$ICONEXCLAMATION.OR.MB$OK) ! ! set global indicator baseLoaded = .true. ! !select a WindowPosition that will show this new dataset: IF (.NOT.gridLoaded) THEN aSum = aSum / DBLE(pointCount) bSum = bSum / DBLE(pointCount) gSum = gSum / DBLE(pointCount) call Unitize(aSum, bSum, gSum) nettempvec(1) = aSum nettempvec(2) = bSum nettempvec(3) = gSum END IF end subroutine GetBase ! After Base map file is loaded, then draw it subroutine DrawBase use dflib use Global real tempvec(3), xBase, yBase logical visible, visiblelast integer colbase, rowbase integer(2) colbase2, rowbase2, status integer count integer(4) iRet type(xycoord) xy type(point), pointer:: tmp ! iRet = SETCOLORRGB(ibasecolor) count = 0 tmp => phead do while(associated(tmp)) tempvec(1) = tmp%Alpha tempvec(2) = tmp%Beta tempvec(3) = tmp%Gamma tmp => tmp%next_point if (tempvec(1) > 1.1) then ! ending marks count = 0 else count = count + 1 call ABG2xy(tempvec, visible, xBase, yBase) if (visible) call pixels(xBase, yBase, colbase, rowbase, visible) if (count == 1) then call moveto(colbase, rowbase, xy) else if (visiblelast) then if(visible) then colbase2 = colbase; rowbase2 = rowbase status = lineto(colbase2, rowbase2) else call moveto(colbase, rowbase, xy) end if else call moveto(colbase,rowbase,xy) end if end if visiblelast = visible ! memory end if end do nullify(tmp) end subroutine DrawBase ! Evaluate one line of a .dig file to decide if it contains a number pair ! Upon return, all preceding and trailing blanks are removed! subroutine LineOfNumbers(msg, AreNumbers) character*(*), intent(in) :: msg logical, intent(out) :: AreNumbers character* 132 :: msg2 integer inum msg2 = trim(adjustl(msg)) inum = ichar(msg2(2:2)) if(((msg2(1:1) == '+').or.(msg2(1:1) == '-')).and.& ((inum > 47).and.(inum < 58))) then AreNumbers = .true. else AreNumbers = .false. end if end subroutine LineOfNumbers