diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2018-05-07 18:33:26 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2018-05-07 18:33:26 (GMT) |
commit | fed8fca93e4662e626d9a5ddaf2796d4c26c3a4f (patch) | |
tree | 16a71401de409e7f5801dbbf970ee5332b248f17 | |
parent | 12e5a42f7ba80ba930a5c3cc2cf29c98651bc590 (diff) | |
download | blt-fed8fca93e4662e626d9a5ddaf2796d4c26c3a4f.zip blt-fed8fca93e4662e626d9a5ddaf2796d4c26c3a4f.tar.gz blt-fed8fca93e4662e626d9a5ddaf2796d4c26c3a4f.tar.bz2 |
add ds9 export parser
-rw-r--r-- | ds9/library/export.tcl | 81 | ||||
-rw-r--r-- | ds9/library/source.tcl | 2 | ||||
-rw-r--r-- | ds9/parsers/exportlex.fcl | 31 | ||||
-rw-r--r-- | ds9/parsers/exportparser.tac | 80 |
4 files changed, 160 insertions, 34 deletions
diff --git a/ds9/library/export.tcl b/ds9/library/export.tcl index 4f8c2fa..eff40ea 100644 --- a/ds9/library/export.tcl +++ b/ds9/library/export.tcl @@ -7,9 +7,7 @@ package provide DS9 1.0 proc ExportDef {} { global export - set export(array,endian) native - set export(nrrd,endian) native - set export(envi,endian) native + set export(endian) native set export(jpeg,quality) 75 set export(tiff,compress) none } @@ -18,10 +16,10 @@ proc Export {fn format fn2} { global export switch $format { - array {ExportArrayFile $fn $export(array,endian)} - rgbarray {ExportRGBArrayFile $fn $export(array,endian)} - nrrd {ExportNRRDFile $fn $export(nrrd,endian)} - envi {ExportENVIFile $fn $fn2 $export(envi,endian)} + array {ExportArrayFile $fn $export(endian)} + rgbarray {ExportRGBArrayFile $fn $export(endian)} + nrrd {ExportNRRDFile $fn $export(endian)} + envi {ExportENVIFile $fn $fn2 $export(endian)} gif {ExportPhotoFile $fn $format {}} tiff {ExportPhotoFile $fn $format $export(tiff,compress)} jpeg {ExportPhotoFile $fn $format $export(jpeg,quality)} @@ -38,6 +36,14 @@ proc ProcessExportCmd {varname iname} { # we need to be realized ProcessRealizeDS9 + global debug + if {$debug(tcl,parser)} { + export::YY_FLUSH_BUFFER + export::yy_scan_string [lrange $var $i end] + export::yyparse + incr i [expr $export::yycnt-1] + } else { + set format {} set fn [lindex $var $i] set fn2 {} @@ -86,18 +92,7 @@ proc ProcessExportCmd {varname iname} { set param [string tolower [lindex $var [expr $i+1]]] switch $format { array - - rgbarray { - switch $param { - native - - big - - bigendian - - little - - littleendian { - set export(array,endian) $param - incr i - } - } - } + rgbarray - nrrd { switch $param { native - @@ -105,7 +100,7 @@ proc ProcessExportCmd {varname iname} { bigendian - little - littleendian { - set export(nrrd,endian) $param + set export(endian) $param incr i } } @@ -119,7 +114,7 @@ proc ProcessExportCmd {varname iname} { little - littleendian { set fn2 "[file rootname $fn].bsq" - set export(envi,endian) $param + set export(endian) $param incr i } default { @@ -135,7 +130,7 @@ proc ProcessExportCmd {varname iname} { bigendian - little - littleendian { - set export(envi,endian) $param + set export(endian) $param incr i } } @@ -164,15 +159,33 @@ proc ProcessExportCmd {varname iname} { png {} } - global arrayfbox - global rgbarrayfbox - global giffbox - global jpegfbox - global tifffbox - global pngfbox - global nrrdfbox - global envifbox - global envi2fbox + switch -- $format { + array {FileLast arrayfbox $fn} + rgbarray {FileLast rgbarrayfbox $fn} + nrrd {FileLast nrrdfbox $fn} + envi { + FileLast envifbox $fn + FileLast envi2fbox $fn2 + } + gif {FileLast giffbox $fn} + jpeg {FileLast jpegfbox $fn} + tiff {FileLast tifffbox $fn} + png {FileLast pngfbox $fn} + } + Export $fn $format $fn2 +} +} + +proc ExportCmdSet {which value {cmd {}}} { + global export + + set export($which) $value + if {$cmd != {}} { + eval $cmd + } +} + +proc ExportCmdSave {format fn {fn2 {}}} { switch -- $format { array {FileLast arrayfbox $fn} rgbarray {FileLast rgbarrayfbox $fn} @@ -218,9 +231,9 @@ proc ExportDialog {format} { if {$fn != {}} { set ok 1 switch -- $format { - array {set ok [ArrayExportDialog export(array,endian)]} + array {set ok [ArrayExportDialog export(endian)]} rgbarray {} - nrrd {set ok [ArrayExportDialog export(nrrd,endian)]} + nrrd {set ok [ArrayExportDialog export(endian)]} envi { set fn2 "[file rootname $fn].bsq" SetFileLast envi2 $fn2 @@ -229,7 +242,7 @@ proc ExportDialog {format} { # set ok 0 # } if {$ok} { - set ok [ArrayExportDialog export(envi,endian)] + set ok [ArrayExportDialog export(endian)] } } gif {} diff --git a/ds9/library/source.tcl b/ds9/library/source.tcl index 222c92f..d7896fb 100644 --- a/ds9/library/source.tcl +++ b/ds9/library/source.tcl @@ -226,6 +226,8 @@ source $ds9(root)/library/dsssaoparser.tcl source $ds9(root)/library/dsssaolex.tcl source $ds9(root)/library/dssstsciparser.tcl source $ds9(root)/library/dssstscilex.tcl +source $ds9(root)/library/exportparser.tcl +source $ds9(root)/library/exportlex.tcl source $ds9(root)/library/gridparser.tcl source $ds9(root)/library/gridlex.tcl source $ds9(root)/library/headerparser.tcl diff --git a/ds9/parsers/exportlex.fcl b/ds9/parsers/exportlex.fcl new file mode 100644 index 0000000..a0991e0 --- /dev/null +++ b/ds9/parsers/exportlex.fcl @@ -0,0 +1,31 @@ +#tab exportparser.tab.tcl + +%{ +%} + +#include defs.fin + +%% + +array {return $ARRAY_} +rgbarray {return $RGBARRAY_} +nrrd {return $NRRD_} +envi {return $ENVI_} + +gif {return $GIF_} +tiff {return $TIFF_} +jpeg {return $JPEG_} +png {return $PNG_} + +big {return $BIG_} +little {return $LITTLE_} +native {return $NATIVE_} + +none {return $NONE_} +packbits {return $PACKBITS_} +deflate {return $DEFLATE_} + +#include numeric.fin +#include string.fin + +%% diff --git a/ds9/parsers/exportparser.tac b/ds9/parsers/exportparser.tac new file mode 100644 index 0000000..5232eab --- /dev/null +++ b/ds9/parsers/exportparser.tac @@ -0,0 +1,80 @@ +%{ +%} + +#include numeric.tin +#include string.tin + +%start command + +%token ARRAY_ +%token RGBARRAY_ +%token NRRD_ +%token ENVI_ + +%token GIF_ +%token TIFF_ +%token JPEG_ +%token PNG_ + +%token BIG_ +%token LITTLE_ +%token NATIVE_ + +%token NONE_ +%token PACKBITS_ +%token DEFLATE_ + +%% + +#include numeric.trl + +command : export + | export {yyclearin; YYACCEPT} STRING_ + ; + +export : STRING_ {ExportCmdSave [ExtToFormat $1] $1} + | STRING_ opts {ExportCmdSave [ExtToFormat $1] $1} + | STRING_ endian {ExportCmdSave [ExtToFormat $1] $1} + + | ext STRING_ {ExportCmdSave $1 $2} + | ext STRING_ opts {ExportCmdSave $1 $2} + + | ext2 STRING_ {ExportCmdSave $1 $2} + | ext2 STRING_ endian {ExportCmdSave $1 $2} + | ENVI_ STRING_ STRING_ {ExportCmdSave envi $2 $3} + | ENVI_ STRING_ STRING_ endian {ExportCmdSave envi $2 $3} + ; + +ext : GIF_ {set _ gif} + | TIFF_ {set _ tiff} + | JPEG_ {set _ jpeg} + | PNG_ {set _ png} + ; + +ext2 : ARRAY_ {set _ array} + | RGBARRAY_ {set _ rgbarray} + | NRRD_ {set _ nrrd} + | ENVI_ {set _ envi} + ; + +opts : NONE_ {ExportCmdSet tiff,compress none} + | JPEG_ {ExportCmdSet tiff,compress jpeg} + | PACKBITS_ {ExportCmdSet tiff,compress packbits} + | DEFLATE_ {ExportCmdSet tiff,compress deflate} + | numeric {ExportCmdSet jpeg,quality $1} + ; + +endian : BIG_ {ExportCmdSet endian big} + | LITTLE_ {ExportCmdSet endian little} + | NATIVE_ {ExportCmdSet endian native} + ; + +%% + +proc export::yyerror {msg} { + variable yycnt + variable yy_current_buffer + variable index_ + + ParserError $msg $yycnt $yy_current_buffer $index_ +} |