[ncl-talk] Problem with plotting station data in DMS-coordinates
Dennis Shea
shea at ucar.edu
Tue Feb 5 13:08:20 MST 2019
The following is fine
dd = dd*(-1.0)
However, the following is preferred
dd = -dd
On Sun, Feb 3, 2019 at 4:27 PM MeteoBB <info at meteo-bb.de> wrote:
> Hi Dennis,
>
> thx. Seems to be work fine except for cases where the lat or lon is in
> western or southern hemisphere.
> I added some code for this and so this is my final function for conversion
> of DMS to DD:
> (if this is incorrect, please tell me)
>
> ;========================================================================
> function dms2dd(dms:string)
> ;========================================================================
>
> local dms_str, degrees, MINUTES, minutes, dd, cminutes
>
> begin
>
> dms_str = str_strip(dms)
> degrees = totype(str_get_field(dms_str, 1, "."), "float")
> cminutes = tochar(str_get_field(dms_str, 2,"."))
> minutes = totype(tostring(cminutes(0:1)), "float") ; 2 places only!
>
> if (any(minutes.ge.60)) then
> print("dms2dd: illegal minutes value >= 60")
> exit
> end if
>
> dd = abs(degrees) + (abs(minutes)/60.0)
> if (any(tofloat(degrees).le.0.0)) then ; degrees in western or
> southern hemisphere
> dd = dd*(-1.0)
> end if
>
> return(dd)
>
> end
> ;========================================================================
>
>
> Am 24.01.2019 um 21:12 schrieb Dennis Shea:
>
>
> Well, of course, NCL [other languages also] would treat the following as
> 'real' numbers
> ===
>
> undef ("dm_to_deg")
> function dm_to_deg(DM:numeric)
> ; DM: latitude or longitude: structure: mantissa.characteristic
> ; Example: 54.41: degrees.minute: mantissa=51, characteristic=41
> local delim, dm_str, mantissa, CHARACTERISTIC, characteristic, deg
>
> begin
> delim = "."
> dm_str = tostring(DM)
> mantissa = totype(str_get_field(dm_str, 1, delim), typeof(DM))
> CHARACTERISTIC = tochar(str_get_field(dm_str, 2, delim))
> characteristic = totype(tostring(CHARACTERISTIC(0:1)),typeof(DM)) ; 2
> places
> if (any(characteristic.ge.60)) then
> print("dm_to_deg: illegal characteristic value >= 60")
> exit
> end if
> deg = mantissa + (characteristic/60.0)
> deg at long_name = "degree coordinates"
> deg at NCL_tag = "dm_to_deg"
> deg at info = "global locations in degrees: derived from dm"
> return(deg)
> end
> ;========================================================================
> ; MAIN: dms ==> degrees_minute_second
> ;========================================================================
>
> lat_dm = 54.41 ; not 'real' number, rather (54° 41')
> lat_deg = dm_to_deg(lat_dm)
> print(lat_deg)
> print("")
> print("===============")
> print("")
> lon_dm = 13.26 ; not 'real' number, rather (13° 26')
> lon_deg = dm_to_deg(lon_dm)
>
>
> On Thu, Jan 24, 2019 at 9:54 AM MeteoBB <info at meteo-bb.de> wrote:
>
>> Hello,
>>
>> i have station data with lat/lon-coordinates in DMS (degree, minutes).
>> I suppose NCL/NCAR always want's decimal coordinates as input? That's why
>> my plotted data points appears at a wrong position.
>>
>> Example (this is my data looks like):
>> lat = 54.41 (54° 41')
>> lon = 13.26 (13° 26')
>>
>> I think I have to transform the coordinates from DMS to decimal, to have:
>> lat = 54.68
>> lon = 13.43
>>
>> Then the location will be placed correctly on map.
>>
>> My question:
>> Just wondering - is there really no built-in procedure/function for the
>> conversion from DMS to decimal coordinates? I found nothing about these
>> stuff in the mailing lists or on the web.
>> Furthermore, I am irritated that the tick labels are DMS in my example
>> program (see at the end), but he expects decimal coordinates.
>> If there is no built-in function, has anyone a funtion to convert DMS to
>> decimal or a workaround?
>>
>> Thanks a lot.
>>
>> Regards,
>> Robert
>>
>>
>> begin
>>
>> wks = gsn_open_wks ("png","test")
>> res = True
>> res at gsnMaximize = True
>> res at gsnFrame = False
>> res at mpGridAndLimbOn = True
>> res at pmTickMarkDisplayMode = "Always"
>> res at mpMinLatF = 54
>> res at mpMaxLatF = 55
>> res at mpMinLonF = 13
>> res at mpMaxLonF = 14
>>
>> res at mpGridSpacingF = 0.25
>> res at mpGridLineThicknessF = 2.0
>> res at mpGridLineColor = "Gray30"
>> res at mpOutlineBoundarySets = "AllBoundaries"
>> res at mpDataBaseVersion = "MediumRes"
>> res at mpDataSetName = "Earth..4"
>> res at mpGridAndLimbOn = True
>>
>> mkres = True
>> mkres at gsMarkerIndex = 16 ; Filled circle
>> mkres at gsMarkerSizeF = 0.008
>>
>> plot = gsn_csm_map(wks,res)
>> gsn_polymarker(wks,plot,13.26,54.41,mkres)
>> frame(wks)
>>
>> end
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190205/0b2a63b5/attachment.html>
More information about the ncl-talk
mailing list