Next / Previous / Contents / TCC Help System / NM Tech homepage

10.41. HistArgs._checkLatLon(): Check one lat-lon argument

hist.cgi
# - - -   H i s t A r g s . _ c h e c k L a t L o n

    LAT_GROUP = 'lat'
    LON_GROUP = 'lon'
    LAT_LON_PAT = re.compile(
        r'(?P<%s>'      # Start LAT_GROUP
            r'[0-9]{2}'     # Matches degrees of latitude
            r'[0-5][0-9]'   # Matches minutes of latitude
        r')'            # End LAT_GROUP
        r'\-'           # Matches the hyphen
        r'(?P<%s>'      # Start LON_GROUP
            r'[01]'         # Matches hundreds digit of deg. lon.
            r'[0-9]{2}'     # Matches tens, units digits
            r'[0-5][0-9]'   # Matches minutes of longitude
        r')'            # End LON_GROUP
        r'$'            # Insure that all characters match
        % (LAT_GROUP, LON_GROUP))

    def _checkLatLon(self, rawLatLon):
        '''Validate one circle center form argument.

          [ rawLatLon is a string ->
              if rawLatLon is a valid circle center in the form
              "ddmm-DDDMM" ->
                return that center as a ("ddmm", "DDDMM") tuple
              else -> raise ScriptError ]
        '''
        #-- 1
        # [ if self.LAT_LON_PAT matches rawLatLon ->
        #     lat  :=  the part of rawLatLon that matches LAT_GROUP
        #     lon  :=  the part of rawLatLon that matches LON_GROUP
        #   else -> raise ScriptError ]
        m = self.LAT_LON_PAT.match(rawLatLon)
        if m is None:
            raise lib.ScriptError("Lat-lon group '%s' does not have "
                "the proper 'ddmm-DDDMM' format." % rawLatLon)
        lat = m.group(self.LAT_GROUP)
        lon = m.group(self.LON_GROUP)

        #-- 2
        return (lat, lon)