1Format_duplicate_item = class 2 Menuaction "_Duplicate" "take a copy of an object" { 3 action x = map_unary copy x; 4} 5 6#separator 7 8Format_list_to_group_item = class 9 Menuaction "_List to Group" "turn a list of objects into a group" { 10 action x = to_group x; 11} 12 13Format_group_to_list_item = class 14 Menuaction "_Group to List" "turn a group into a list of objects" { 15 action x = to_list x; 16} 17 18#separator 19 20Format_break_item = class 21 Menuaction "_Break Up Object" 22 "break an object into a list of components" { 23 action x 24 = map_unary break x 25 { 26 break x 27 = bandsplit x, is_Image x 28 = map Vector x.value, is_Matrix x 29 = x.value, is_Vector x || is_Real x 30 = error "Breakup: not Image/Matrix/Vector/Real"; 31 } 32} 33 34Format_assemble_item = class 35 Menuaction "_Assemble Objects" 36 "assemble a list (or group) of objects into a single object" { 37 action x 38 = map_unary ass x 39 { 40 ass x 41 = [], x == [] 42 = Vector x, is_real_list x 43 = Matrix x, is_matrix x 44 = bandjoin x, is_listof is_Image x 45 = Vector (map get_value x), is_listof is_Real x 46 = Matrix (map get_value x), is_listof is_Vector x 47 = error "Assemble: not list of Image/Vector/Real/image/real"; 48 } 49} 50 51#separator 52 53Format_csv_import_item = class 54 Menuaction "_CSV Import" "read a file of comma-separated values" { 55 action = class 56 _result { 57 _vislevel = 3; 58 59 path = Pathname "File to load" "empty"; 60 start_line = Expression "Start at line" 1; 61 rows = Expression "Lines to read (-1 for whole file)" (-1); 62 whitespace = String "Whitespace characters" " \""; 63 separator = String "Separator characters" ",;\t"; 64 65 _result 66 = Image blank, path.value == "empty" 67 = Image (im_csv2vips filename) 68 { 69 filename = search (expand path.value) ++ ":" ++ 70 "skip:" ++ print (start_line.expr - 1) ++ "," ++ 71 "whi:" ++ escape whitespace.value ++ "," ++ 72 "sep:" ++ escape separator.value ++ "," ++ 73 "line:" ++ print rows.expr; 74 75 // prefix any ',' with a '\' in the separators line 76 escape x 77 = foldr prefix [] x 78 { 79 prefix x l 80 = '\\' : x : l, x == ',' 81 = x : l; 82 } 83 84 blank = image_new 1 1 1 85 Image_format.DOUBLE Image_coding.NOCODING Image_type.B_W 86 0 0 0; 87 } 88 } 89} 90 91// interpret Analyze header for layout and calibration 92Interpret_header_item = class 93 Menuaction "_Interpret Analyze 7 Header" 94 "examine the Analyze header and set layout and value" { 95 action x 96 = x''' 97 { 98 // read bits of header 99 dim n = get_header ("dsr-image_dimension.dim[" ++ print n ++ "]"); 100 dim0 = dim 0 x; 101 dim1 = dim 1 x; 102 dim2 = dim 2 x; 103 dim3 = dim 3 x; 104 dim4 = dim 4 x; 105 dim5 = dim 5 x; 106 dim6 = dim 6 x; 107 dim7 = dim 7 x; 108 glmax = get_header "dsr-image_dimension.glmax" x; 109 cal_max = get_header "dsr-image_dimension.cal_max" x; 110 111 // oops, now a nop 112 x' = x; 113 114 // lay out higher dimensions width-ways 115 x'' 116 = grid dim2 dim3 1 x', dim0 == 3 117 = grid dim2 dim3 dim4 x', dim0 == 4 118 = grid (dim2 * dim4) dim5 1 (grid dim2 dim3 dim4) x', dim0 == 5 119 = grid (dim2 * dim4) dim5 dim6 (grid dim2 dim3 dim4) x', dim0 == 6 120 = grid (dim2 * dim4 * dim6) dim7 1 121 (grid (dim2 * dim4) dim5 dim6 (grid dim2 dim3 dim4)) x', 122 dim0 == 7 123 = error (_ "unsupported dimension " ++ dim0); 124 125 // multiply by scale factor to get kBeq 126 x''' = x'' * (cal_max / glmax); 127 } 128} 129