Code Red > AutoLISP (Vanilla / Visual)

[Help Me]How to deal with these data?

(1/5) > >>

myloveflyer:
Because the job needs, wrote a modification of data files, don't know why output data format is not right after, each data corresponding position change, how to write can do and the original data format exactly the same?
Please help me,Thank!

--- Code: ---(defun c:test()
(arxload "geomcal.arx")
(setq date_list nil)
(princ (if (setq f (open "d:/old.DAT" "r")) "Data file open success!\n" "Data files can't open!\n"))
(while  (setq str_line (read-line f))
(setq str_line (strcat "(" str_line ")"))
(setq list_line (read str_line))
(if (= (length list_line) 10)
(setq list_line (append (list (nth 0 list_line) (nth 1 list_line) "  ") (cddr list_line)))
)
(setq date_list (append date_list (list list_line)))
)
(close f)
(setq n (length date_list))
(setq wt_list (nth (- n 1) date_list))
(setq old_wt (nth 2 wt_list))
(setq new_wt (* old_wt 1.05))
(setq wt old_wt)
(setq min_wt (* old_wt 0.001))
(setq i 1)
(while (> (abs (- wt new_wt)) min_wt)
(setq minus_list (nth i date_list))
(setq minus_n (nth 5 minus_list))
(if (> minus_n 1)
(progn
(setq add_list (nth (+ i 1) date_list))
(setq minus_wt (nth 9 minus_list))
(setq add_wt (nth 9 add_list))
(setq wt (cal "wt - minus_wt + add_wt"))
(setq minus_list
(list
(nth 0 minus_list)
(nth 1 minus_list)
(nth 2 minus_list)
(nth 3 minus_list)
(nth 4 minus_list)
(- minus_n 1)
(nth 6 minus_list)
(nth 7 minus_list)
(nth 8 minus_list)
minus_wt
(- (nth 10 minus_list) minus_wt)
)
)
(setq date_list (subst minus_list (nth i date_list) date_list))
(setq add_list
(list
(nth 0 add_list)
(nth 1 add_list)
(nth 2 add_list)
(nth 3 add_list)
(nth 4 add_list)
(+ (nth 5 add_list) 1)
(nth 6 add_list)
(nth 7 add_list)
(nth 8 add_list)
add_wt
(+ (nth 10 add_list) add_wt)
)
)
(setq date_list (subst add_list (nth (+ i 1) date_list) date_list))
)
)
(setq i (+ i 1))
(if (= i (- n 2))
(setq i 1)
)
)
(setq date_list (subst (subst wt old_wt wt_list) wt_list date_list))
(princ (if (setq f (open "d:/new.DAT" "w")) "Data file open success!\n" "Data files can't open!\n"))
(foreach line date_list
(progn
(foreach num line
(progn
(princ num f)
(princ "\t" f)
)
)
(princ "\n" f)
)
)
(close f)
(princ)
)


--- End code ---

myloveflyer:
My aim is to make the output file ( new.dat ) format and the original document ( old.dat ) format is the same as。

Keith™:
The problem you have is that the original file ( old.dat ) has spaces between the columns and the new file ( new.dat ) has tabs. Also, the original data is mixed justification. some columns are right justified, while others are left justified.

The old.dat file contains eleven fields. Each field is separated by two spaces and the data in the field is padded with spaces depending upon justification.

Characters per field (in order): 4-4-12-4-4-4-3-5-10-6-7

The record is 83 characters long.

Justification per field (in order): r-r-l-l-l-r-l-l-r-r-r

So, when you output each field to the new file, do this:

Pad spaces on the left for right aligned text and pad spaces on the right for left aligned text, then put an additional two spaces between each output.

This is a simple padding function to make the text align and fit the field as needed. I am sure it could be tweaked, but it works as advertised. ;-)


--- Code: ---;;;By: K. Blackie 02/05/2012
;;;Function: Pad
;;;Notes:     Pad text with specified character(s) until the text is as long as the passed length.
;;;              Justification is handled by the alignment parameter. acAlignmentLeft, acAlignmentRight
;;;              and acAlignmentMiddle are the options, otherwise the function returns the passed value
;;;              unchanged. The bit parameter is used only for middle justification. If T then the first
;;;              padded character is appended, if nil the first character is prepended.
;;;
;;;Usage:    (pad "text" integer "character" alignment nil)
;;;Examples:
;;;              (pad "73.453" 8 "0" acAlignmentLeft nil) returns "0073.453"
;;;              (pad "73.453" 8 "0" acAlignmentRight nil) returns "73.45300"
;;;              (pad "73.453" 8 "0" acAlignmentMiddle nil) returns "073.4530"


(defun pad (value len char alignment bit)
  (if (< (strlen value) len)
    (cond
      ((= alignment acAlignmentLeft)
       (setq value (pad (strcat char value) len char alignment nil))
      )
      ((= alignment acAlignmentRight)
       (setq value (pad (strcat value char) len char alignment nil))
      )
      ((= alignment acAlignmentMiddle)
       (if (= bit t)
(setq value (pad (strcat value char) len char alignment nil))
(setq value (pad (strcat char value) len char alignment t))
       )
      )
    )
  )
  value
)
--- End code ---

BlackBox:
Building on Keith's post, I would test for the ARX application being found in (arx) prior to subsequent Arxloads, which is not necessary, and may cause issues.

myloveflyer:
Keith, thank you, can you help me to revise my program?
Due to the presence of large amounts of data file is to be processed, so the trouble you help me deal or help me to arrange a program to complete the data processing.

Navigation

[0] Message Index

[#] Next page

Go to full version