#!/usr/bin/perl -w use strict; # # This converts between SMDA and SMD format. SMDA is a simple ascii format # beginning with the line "SMDA 1". It must have proper line endings for the # system it will run on! I.e. if you run this on linux, it will assume unix # style line endings, if you run it on windows, it will assume DOS. # # Each line after the first has the following form: # # r,g,b; x1,y1,z1; x2,y2,z2; x3,y3,z3; ... # # Semi-colons separate values, and an arbitrary number of coordinates folow # the color which is the first item on the line. Whitespace is ignored. # my $smda_mode = 0; while (<>) { chomp; if($smda_mode) { my(@triple) = split /\s*\;\s*/; print pack ("c4", split(/\s*,\s*/, shift(@triple)), $#triple-1); foreach (@triple) { print pack ("n3", split(/\s*,\s*/)); } } else { if($. == 1) { m/^SMDA\s*(\d+)\s*$/ && $1 == 1 || die "'SMDA 1' header not found, aborting\n"; $smda_mode = $1; print pack ("aaac", 's', 'm', 'd', $smda_mode); } } }