Well I could not figure it out last night, fatigue I guess.
The problem is when size is less that than 12 which is easily
overcome by adding code *0 to the list. I did the same for the other
end by adding *1000, but could not connect the dots last night.
Here is the revised code & data file:
***** test file (gage,stock,slips) *****
*** 0 to 11.9 use 26.0,96.0,0.5
*0
26.0,96.0,0.5
*** 12 to 30.9 use 24.0,60.0,1.75
*12
24.0,60.0,1.75
*31
22.0,60.0,1.75
*54
20.0,30.0,1.75
*72
18.0,30.0,1.75
*100
18.0,30.0,1.75
Results:
10.0 = (26.0 96.0 0.5)
12.0 = (24.0 60.0 1.75)
30.0 = (24.0 60.0 1.75)
31.0 = (22.0 60.0 1.75)
32.0 = (22.0 60.0 1.75)
53.0 = (22.0 60.0 1.75)
54.0 = (20.0 30.0 1.75)
55.0 = (20.0 30.0 1.75)
120.0 = (18.0 30.0 1.75)
(defun shop_spec (size / char fn fp line lst nsize)
;; if the file is found proceed
(cond ((setq fn (findfile "specs.dat"))
(setq fp (open fn "r")) ; open file read only
;; read all line in a loop
(while (setq line (read-line fp)) ; line is a string data type
;; get the first char of the line
(setq char (substr line 1 1))
(cond ((= char ";")) ; do nothing character
((= char "*") ; flag character
;; 1st two lines need to be true to do the third
(and (numberp ; verify we got a number
(setq nsize (read ; convert to number if it is one
(substr line 2); get all but 1 char
)))
(>= size nsize); test for size match
;; if line 1 & 2 are true,
;; get lst if test size < code size
(setq lst (read-line fp))
)
) ; end flag
) ; end cond stmt
) ; end while
(close fp)
) ; end file found
) ; end cond stmt
lst ; return the list, changed from (reverse lst)
) ; end defun
;; from a string & delimiter char return the numbers
(defun str2nums (aStr delim / strList pos)
(while (setq pos (vl-string-search delim aStr 0))
(setq strList (cons (substr aStr 1 POS) strList)
aStr (substr aStr (+ pos 2))
)
)
(mapcar 'atof (reverse (cons aStr strList)))
)
(defun c:test ()
;;(setq msize (max g:wid1 g:dep1 g:wid2 g:dep2)) yes WB this will work
(foreach msize '(10 12 30 31 32 53 54 55 120) ; for test
;; return a list of numbers
(setq dlist (car
(mapcar ; repeat the function foreach item in the list
(function (lambda (n) (str2nums n ",")))
(list ; added this to make it a list
(shop_spec msize) ; this returns the data string
)
)
)
)
(princ (strcat "\n" (rtos msize 2 1) " = " ))
(princ dlist)
)
(print)
(mapcar 'set '(gage stock slips) dlist)
)
;|
***** test file (gage,stock,slips) *****
*** 0 to 11.9 use 26.0,96.0,0.5
*0
26.0,96.0,0.5
*** 12 to 30.9 use 24.0,60.0,1.75
*12
24.0,60.0,1.75
*31
22.0,60.0,1.75
*54
20.0,30.0,1.75
*72
18.0,30.0,1.75
*100
18.0,30.0,1.75
|;