Author Topic: FIX issue  (Read 1277 times)

0 Members and 1 Guest are viewing this topic.

BIGAL

  • Swamp Rat
  • Posts: 699
  • 30 + years of using Autocad
Re: FIX issue
« Reply #30 on: April 24, 2021, 11:07:11 PM »
Just a ps degs max 360, Minutes max 60, seconds max 60, can not have 67.
A man who never made a mistake never made anything

domenicomaria

  • Bull Frog
  • Posts: 255
Re: FIX issue
« Reply #31 on: April 25, 2021, 01:48:14 AM »
Just a ps degs max 360, Minutes max 60, seconds max 60, can not have 67.
yes
you are right !


I have not taken this number from the txt file of the surveying instrument.

I used this number to give an example (wrong)
. . . if you notice, the digits of this number are increasing digits
1 2 3 4 5 6 7. . .

I only used it to give an example and didn't consider that I couldn't use 67 for the seconds!



domenicomaria

  • Bull Frog
  • Posts: 255
Re: FIX issue
« Reply #32 on: April 25, 2021, 02:10:26 AM »
does this work?
Code: [Select]
(defun sgf_convert (n / )
  (+ (atoi (substr n 1 (vl-string-search "." n)))
     (/ (atoi (substr n (+ 2 (vl-string-search "." n)) 2)) 60.0)
     (/ (atoi (substr n (+ 4 (vl-string-search "." n)) 2)) 3600.0)
  )
)
(defun dtr (a)(* pi (/ a 180.0)))

(sgf_convert "123.4567") -> 123.768611111111
(dtr (sgf_convert "123.4567")) -> 2.16016977450933

assumes always 4 digits after decimal, and since you are reading from a file you are starting with a string

Yes

It works well.
I prefer to not use strings.

But it works.
Bravo !

domenicomaria

  • Bull Frog
  • Posts: 255
Re: FIX issue
« Reply #33 on: April 25, 2021, 05:26:02 AM »
does this work?
Code: [Select]
(defun sgf_convert (n / )
  (+ (atoi (substr n 1 (vl-string-search "." n)))
     (/ (atoi (substr n (+ 2 (vl-string-search "." n)) 2)) 60.0)
     (/ (atoi (substr n (+ 4 (vl-string-search "." n)) 2)) 3600.0)
  )
)
(defun dtr (a)(* pi (/ a 180.0)))

(sgf_convert "123.4567") -> 123.768611111111
(dtr (sgf_convert "123.4567")) -> 2.16016977450933

assumes always 4 digits after decimal, and since you are reading from a file you are starting with a string

DanAllen your code with some little modifications . . .

Code - Auto/Visual Lisp: [Select]
  1. (defun DDMMGG>RAD (ang / ang-str dot-pos)
  2.         (setvar "dimzin" 0)
  3.         (if(numberp ang) (setq ang-str (rtos ang 2 4) ) (setq ang-str ang) )
  4.         (setq dot-pos (vl-string-search "." ang-str))
  5.         (* pi
  6.                 (/
  7.                         (+      (atoi (substr ang-str 1 dot-pos))
  8.                                 (/ (atoi (substr ang-str (+ 2 dot-pos) 2)) 60.0)
  9.                                 (/ (atoi (substr ang-str (+ 4 dot-pos) 2)) 3600.0)
  10.                         )
  11.                         180.0
  12.                 )
  13.         )
  14. )
  15.  

(rtos (DDMMGG>RAD 222.3344) 2 15)
3.884443568333069

danAllen

  • Mosquito
  • Posts: 16
Re: FIX issue
« Reply #34 on: April 25, 2021, 11:04:55 AM »
I prefer to not use strings.

But it works.
Bravo !

Thank you. I'm glad I could help.

A minor quibble - you said the data was stored in an ascii file, a simple txt file. I'm pretty sure that means when it is read from file, the original format is a string. It is a string representing three numbers, the first is from 1 to 3 digits (or does it encode "001.2345"?) , a "." separator, then two numbers from 0 to 59, encoded with leading 0 (ex "01" or "59") - and no separator.
To convert it to decimal then back again with the DDMMGG>RAD function seems like an extra step and led to some of the confusion about what you needed to accomplish.

domenicomaria

  • Bull Frog
  • Posts: 255
Re: FIX issue
« Reply #35 on: April 25, 2021, 11:59:24 AM »
danAllen,
I read a TXT file, and get a LIST of STRINGS.

Every string contains 7 information, separated from comma (",")
So I split every string in its 7 sub-strings
and then I READ every item.

2 of this seven items are the horizontal angle and the vertical angle.

They rappresent angles in SEXAGESIMAL FORMAT.

But they are formatted as DECIMAL DEGREES.

So I need to get the number before the dot
and after,
i have to get the first 2 numbers and the second 2 numbers
(after the dot)
that rappresent the minutes and the seconds.

You know the rest.

That's all.

Ciao