C Copyright(c) 1999, Space Science and Engineering Center, UW-Madison C Refer to "McIDAS Software Acquisition and Distribution Policies" C in the file mcidas/data/license.txt C *** $Id: smpnav.f,v 1.0 1999/09/28 14:38:32 russd Tst $ *** C ? SMPNAV - McIDAS navigation sample program C ? SMPNAV FNAV FRAME convert frame to lat/lon by clicking frame C ? SMPNAV FNAV EARTH convert lat/lon to TV for given lat/lon C ? SMPNAV INAV dataset convert lat/lon line/elem using C ? image nav C ? Parameters: C ? dataset | source dataset name (group/descriptor.pos) C ? EARTH | display Earth coordinates C ? FNAV | demonstrate frame navigation C ? FRAME | display frame coordinates C ? INAV | demonstrate image navigation C ? Keywords: C ? LATlon=lat lon | convert lat/lon to line/ele C ? LINele=line ele I | convert image line/ele to lat/lon C ? TIMe=time1..timeN | list of times C ? Remarks: C ? McIDAS sample program. C ? C ? This program demonstrates the principles of McIDAS frame and C ? image navigation. C ? C ? If option is INAV, then navigation is obtained from the image C ? specified by dataset. If LATLON is given, then that lat/lon is C ? converted to image line/elem for that image. If LINELE is given, C ? then the line/elem for that image is converted to lat/lon C ? Functions demonstrated include: C ? NVPREP, NV1INI, NV1SEA, NV1EAS C ? C ? If option is FNAV, then convert between frame and earth coord- C ? inates. If optarg is FRAME, then conversion are done from frame C ? to earth coordinates interactively by clicking the mouse. C ? ---------- subroutine main0 implicit none c --- external functions integer mccmdstr ! character string parameter c --- internal functions integer image_nav ! image navigation integer frame_nav ! frame navigation integer grid_nav ! grid navigation c --- internal variables character*12 option ! program option string integer status ! function status c **************** Program Body ************** c --- set initial program status to FAILED call MCCODESET( -1 ) c --- fetch the command option status = MCCMDSTR( ' ', 1, ' ', option ) if( status.lt.0 ) return c --- Force the contents of the option string to upper case call MCUPCASE( option ) c --- Image navigation if (option .eq. 'INAV') then status = image_nav( ) if( status.lt.0 ) then call edest ('Error with image navigation', 0) return endif endif if (option .eq. 'FNAV') then status = frame_nav( ) if( status.lt.0 ) then call edest ('Error with frame navigation', 0) return endif endif if (option .eq. 'GNAV') then endif call sdest ('Done...', 0) c --- set the program status to SUCCESS call mccodeset( 0 ) return end c ---------------------------------------------------------------------- c integer function frame_nav c c Frame navigation example c COMMAND FNAV FRAME c click navigated frame to get lat/lon c c COMMAND FNAV EARTH LATLON=lat lon c get TV line/element for LATLON on navigated frame c ---------------------------------------------------------------------- integer function frame_nav( ) implicit none c --- internal constants c --- external functions integer mcgetimageframenumber ! get the current frame integer mccmddll ! get command line double integer mccmdstr ! get command line string integer mccmdnum ! get number of command args integer mcmoubtn ! get pointing device status integer ITVLL ! convert TV to lat/lon lin/ele integer ILLTV ! convert lat/lon to TV and linele c --- internal functions c --- external functions c --- internal variables character*12 frame_opt ! options for frame nav character*160 cline ! line of text output integer status ! function return status integer button1 ! mouse button 1 status integer button2 ! mouse button 2 status integer tvline ! line in TV coordinate integer tvelem ! element in TV coordinate integer current_frame ! current frame integer iline ! image line integer ielem ! image element real rlat ! latitude as real real rlon ! longitude as real double precision dlat ! latitude as double double precision dlon ! longitude as double frame_nav = -1 current_frame = mcgetimageframenumber () status = mccmdstr (' ', 2, 'FRAME', frame_opt) if (status .lt. 0) then call edest ('Error getting frame navigation option', 0) return endif frame_nav = -2 if (frame_opt(1:3) .eq. 'FRA') then call sdest ('Position mouse and repeatedly press the ',0) call sdest ('middle mouse button to get lat/lon and ', 0) call sdest ('lin/ele of point', 0) goto 100 else goto 200 endif c ------------------------------------------------------ c --- convert the TV line/element to lat/lon and c --- image lin/ele c ------------------------------------------------------ 100 continue c --- Get information about the status of the pointer status = mcmoubtn (1, button1, button2, tvline, tvelem) c --- pressed if (status .eq. 1 .or. button2 .gt. 0 ) then frame_nav = 0 return endif c --- check button status from pointing device if (status .eq. 0 .or. status .eq. 2 .and. & (button1 .gt. 0)) then status = ITVLL (current_frame, tvline, tvelem, & iline, ielem, rlon, rlat, 0) if (status .lt. 0) then call edest ('Unable to navigate point', 0) call edest ('No navigation on frame', 0) return endif write (cline, 40) tvline, tvelem, rlat, rlon, & iline, ielem 40 format ('TV Line/Elem: ', 2I5, ' Lat/Lon: ', 2F7.2, & ' Image Lin/Ele: ', 2I7) call sdest (cline, 0) c --- get next point goto 100 c --- endif c ------------------------------------------------------ c --- convert the lat/lon to TV line/element and c --- image lin/ele c ------------------------------------------------------ 200 continue frame_nav = -3 c --- Get the specified lat/lon from the command line if (mccmdnum ('LAT.LON') .lt. 2) then call edest ('Must specify a LAT/LON with LATLON=', 0) return endif frame_nav = -4 status = mccmddll ('LAT.LON', 1, 'Latitude', 0.0, 0.0, 90.0, & dlat) if (status .lt. 0) then call edest ('Failed picking up LATLON', 0) return endif status = mccmddll ('LAT.LON', 2, 'Longitude', 0.0, -180.0, 180.0, & dlon) if (status .lt. 0) then call edest ('Failed picking up LATLON', 0) return endif frame_nav = -5 c --- convert the lat/lon on the frame to TV line/element rlat = dlat rlon = dlon status = ILLTV (current_frame, 0, rlat, rlon, iline, ielem, & tvline, tvelem) if (status .lt. 0) then call edest ('Unable to navigate point', 0) call edest ('No navigation on frame', 0) return endif write (cline, 42) rlat, rlon, tvline, tvelem, iline, ielem 42 format ('Lat/Lon: ', 2F7.2, ' TV Line/Elem: ', 2I5, & ' Image Lin/Ele: ', 2I7) call sdest (cline, 0) frame_nav = 0 return end c ---------------------------------------------------------------------- c integer function image_nav c c Image navigation example c COMMAND INAV imagedataset LATLON=lat lon c convert lat/lon to image line/elem for image specified c in dataset imagedataset c c COMMAND INAV imagedataset LINELE=iline ielem c convert image line/elem to lat/lon for image specified c in dataset imagedataset c ---------------------------------------------------------------------- integer function image_nav( ) implicit none c --- internal constants integer mccmdstr ! return command line string integer mccmdint ! return command line int integer mccmddll ! return command line double integer mccmdnum ! return command line number integer nv1sae ! convert satellite to earth integer nv1eas ! convert earth to satellite c --- internal functions integer image_nav_init ! initialize image navigation c --- internal variables character*80 cline ! output line character*80 dataset ! dataset name double precision dlat ! input latitude double precision dlon ! input longitude real rlat ! input latitude real rlon ! input longitude real rline ! image line as real real relem ! image elem as real real dz ! distance above ground integer line ! image line integer elem ! image elem integer status ! return status variable image_nav = -1 c --- get the dataset name status = mccmdstr (' ', 2, ' ', dataset) if (status .le. 0) then call edest ('Error getting image dataset name', 0) return endif image_nav = -2 c --- Initialize the navigation from a dataset image. Request c --- latitude/longitude transformations. Initialize as slot 1 status = image_nav_init (1, dataset, 'LL ') if (status .ne. 0) then call sdest ('Failed to initialize navigation', 0) return endif c ------------------------------------------------------------- c --- Perform navigation transformations. c ------------------------------------------------------------- dz = 0.0 c --- If LATLON is provided, then convert to LINELE if (mccmdnum ('LAT.LON') .eq. 2) then status = mccmddll ('LAT.LON', 1, 'Lat/Lon', 0.0, & 0.0, 90.0, dlat) if (status .lt. 0) then call edest ('Failure obtaining Latitude', 0) return endif status = mccmddll ('LAT.LON', 2, 'Lat/Lon', 0.0, & 0.0, 90.0, dlon) if (status .lt. 0) then call edest ('Failure obtaining Longitude', 0) return endif rlat = dlat rlon = dlon status = NV1EAS (rlat, rlon, dz, rline, relem, dz) if (status .lt. 0) then call edest ('Failure converting LAT/LON to LIN/ELE', 0) return endif line = rline elem = relem write (cline, 30) dlat, dlon, line, elem 30 format ('Lat/Lon ', 2F7.2, ' Converts to ', 2I7) call sdest (cline, 0) endif c --- If LINELE is provided, then convert to LATLON. The LINELE must c --- be entered in image coordinate, because the default used by c --- mcasort () is File. For the purpose of this excercise, we are c --- converting from Satellite to Earth coordinate and visa versa if (mccmdnum ('LIN.ELE') .eq. 2) then call edest ('Must specify image coordinate with', 0) call edest ('LINELE option. ie. LINELE 1234 23423 I', 0) return endif if (mccmdnum ('LIN.ELE') .eq. 3) then status = mccmdint ('LIN.ELE', 1, 'Line/Elem', 1, & 2, 1, line) if (status .lt. 0) then call edest ('Failure obtaining Latitude', 0) return endif status = mccmdint ('LIN.ELE', 2, 'Line/Elem', 1, & 2, 1, elem) if (status .lt. 0) then call edest ('Failure obtaining Longitude', 0) return endif rline = real (line) relem = real (elem) status = NV1SAE (rline, relem, dz, rlat, rlon, dz) if (status .lt. 0) then call edest ('Failure converting LAT/LON to LIN/ELE', 0) return endif write (cline, 32) line, elem, rlat, rlon 32 format ('Line/Elem ', 2I7, 'Converts to ', 2F7.2) call sdest (cline, 0) endif image_nav = 0 return end c ---------------------------------------------------------------------- c integer function image_nav_init (int slot, char sdataset, char ctrans) c c Initialize the navigation subsystem with navigation obtained from c an image c c slot navigation slot number to initialize c sdataset Dataset name of image to obtain nav from c ctrans 'LL ' for lat/lon 'XYZ ' for spherical c ---------------------------------------------------------------------- integer function image_nav_init (slot, sdataset, ctrans) implicit none c --- internal constants integer MAXSORTS parameter (MAXSORTS = 24) ! maximum sort clause strings integer DIRSIZE parameter (DIRSIZE = 64) ! size of image directory block integer NAVSIZE parameter (NAVSIZE = 1024) ! max size of navigation block integer MAXBYTES parameter (MAXBYTES = 4000) ! max number of bytes return by server integer MAXLINES parameter (MAXlINES = 480) ! max number of lines return by server c --- external functions character*12 cfi ! integer to character integer lit ! char*4 to int integer m0dsnnam ! parse dataset integer mcasort ! generate aget sort clauses integer mcaget ! open connection for image data integer mcanav ! read image navigation integer mcafree ! close connection for image data integer nvprep ! prepare navigation module integer nv1ini ! initialize navigation module c --- internal functions c --- internal variables character*12 form ! form of bytes to return character*12 calunit ! calibration units to request character*12 cpos ! dataset position as character character*12 ctmp ! temporary variable character*12 cval1 ! temporary variable character*12 cval2 ! temporary variable character*60 sname ! source dataset name character*60 sdataset ! source dataset name character*80 sorts(MAXSORTS) ! source sort clauses character*4 ctrans ! transformation type ! ('LL ', or 'XYZ ') integer nsorts ! number of sort clauses integer directory(DIRSIZE) ! image directory integer nav_block(NAVSIZE) ! image nav block integer bandpos ! position in the BAND= to ! select the band number from integer handle ! handle to image request integer slot ! navigation slot number integer status ! return status integer itrans ! navigation output options integer num_line ! number of lines to retrieve integer num_ele ! number of elements to retrieve integer errorflag ! error flag to mcaget image_nav_init = -1 status = m0dsnnam (sdataset, sname, cpos, ctmp, 0) if (status .lt. 0) then call edest ('Failed to parse dataset name '//sdataset, 0) return endif image_nav_init = -2 c --- get select conditions from the command line c --- c --- the mcasort function builds select strings from the following c --- keywords c --- BAND = band image bands c --- DAY = bday image day c --- LATLON = lat lon lat/lon location c --- LINELE = line ele sys image lin/ele location c --- MAG = lmag emag line and element magnification c --- PLACE = loc sets whether the location c --- is to be centered, upperleft, c --- etc c --- RTIME = bmin emin set the bmin and emin of the c --- current hour in the TIME select c --- STATION= stn set the location to the lat/lon c --- of the station stn c --- TIME = btime etime image time range c --- select only the first band specified in BAND= keyword c --- if you wanted the ability to select all bands, then you would c --- do the following c --- c --- call movcw ('ALL ', bandpos) bandpos = 1 status = mcasort (nsorts, sorts, bandpos) if (status .lt. 0) return image_nav_init = -3 c --- Because the only way to obtain the navigation block is to c --- open a connection to the image server, we must ask for c --- some data. Since we are really only interested in the c --- navigation block, then we will ask for the minimum amount c --- of data - 1 line by 4 elements c --- Build the 'SIZE = line ele' select clause c num_line = 3 c num_ele = 8 num_line = 1 num_ele = 4 nsorts = nsorts + 1 cval1 = cfi (num_line) cval2 = cfi (num_ele) sorts(nsorts) = 'SIZE '//cval1//' '//cval2 c --- Add the POS sort condition to the clauses nsorts = nsorts + 1 sorts (nsorts) = 'POS '//cpos c --- request raw data calunit = 'RAW' c --- request 4-byte data c --- options are: c --- I1 1-byte elements c --- I2 2-byte elements c --- I4 4-byte elements form = 'I4' errorflag = 1 c --- open a connection to the server status = mcaget (sname, nsorts, sorts, calunit, form, & MAXBYTES, errorflag, directory, handle) if (status .lt. 0) then call edest ('Call to MCAGET failed; returned ', status) return endif c --- now we have made a connection to the server and there is data c --- waiting for us to fetch. image_nav_init = -4 c --- fetch the navigation block - can be read at any time after a c --- successful call to MCAGET status = mcanav (handle, nav_block) if (status .lt. 0) then call edest ('Failed to retrieve navigation block', 0) return endif c --- were done fetching data we need from the server. Free things up status = mcafree (handle) image_nav_init = -5 c --- load the navigation into slot 1 status = NVPREP (slot, nav_block (1)) if (status .lt. 0) then call edest ('Failed to prep navigation slot 1', 0) return endif image_nav_init = -6 c --- initialize the navigation for output in lat/lon coordinates itrans = lit (ctrans(1:4)) status = NV1INI (2, itrans) if (status .lt. 0) then call edest ('Failed to initialize output options slot 1', 0) return endif image_nav_init = 0 return end