Madrigal Tcl API | Doc home | Madrigal home |
The first two commands create new tcl objects which can be used to manipulate Cedar files (mad) and Cedar metacode information (cedarCode). The remaining commands determine the Madrigal key given a time and date (getKey) and provide basic geometry and geographic coordinate functions (isr_point, isr_look, isr_geodetic2geocentric, isr_geocentric2geodetic and isr_dircos).
The script shown below, summarizeCedarFile, illustrates the use of madtclsh. It begins by creating a new madrec object (mad madin). More than one madrec object can be created. For example, a script to translate a Cedar file from Madrigal to Cedar Ascii format would require two. The mad command creates a new tcl command - $madin in the example. Typically the first thing done with the new command is to associate it with a Cedar file ($madin open 1 $infile). The file can then be read using the getNextRecord subcommand ($madin getNextRecord). Once a record has read, numerous subcommands are available to extract information from the record (e.g. $madin get startTime). When the file is no longer needed, it can be disassociated from the madrec object ($madin close). Finally, when the madrec object is no longer needed, it can be destroyed ($madin destroy).
#!/bin/sh # The madtclsh path is longer than 32 characters. So, we take advantage # of the fact that a backslash continues a comment line in tcl \ exec /opt/madrigal/bin/madtclsh "$0" ${1+"$@"} # summarizeCedarFile prints a one line per record summary of a CEDAR # file. The file may be any of the 5 supported CEDAR formats (Madrigal, # Blocked Binary, Cbf, Unblocked Binary or ASCII"), and may include any # mixture of prologue, header and data records. The format of the file is # determined automatically. # Usage: printCedarRecords filename firstRecord lastRecord # Get parameter codes cedarCode cedarCode # Get number of parameters set nargs $argc if {$nargs != 1} { puts {Usage: summarizeCedarFile filename} exit } # Get file name from the argument list set infile [lindex $argv 0] # Create madrec object for the input file. Specify file type 1 for automatic # determination of the CEDAR file type mad madin catch [$madin open 1 $infile] # Print a one line per record summary of the file puts " rec Start Time End Time kinst krec kindat" set rec 0 while {[set status [$madin getNextRecord]] == 0} { incr rec set recno [format %4d $rec] set startTime [$madin get startTime] set yr1 [lindex $startTime 0] set mo1 [lindex $startTime 1] set dy1 [lindex $startTime 2] set hr1 [lindex $startTime 3] set mn1 [lindex $startTime 4] set sc1 [lindex $startTime 5] set zero 0 if {[string length $hr1] == 1} { set hr1 $zero$hr1 } if {[string length $mn1] == 1} { set mn1 $zero$mn1 } if {[string length $sc1] == 1} { set sc1 $zero$sc1 } set endTime [$madin get endTime] set yr2 [lindex $endTime 0] set mo2 [lindex $endTime 1] set dy2 [lindex $endTime 2] set hr2 [lindex $endTime 3] set mn2 [lindex $endTime 4] set sc2 [lindex $endTime 5] set zero 0 if {[string length $hr2] == 1} { set hr2 $zero$hr2 } if {[string length $mn2] == 1} { set mn2 $zero$mn2 } if {[string length $sc2] == 1} { set sc2 $zero$sc2 } puts "$recno $mo1/$dy1/$yr1 $hr1:$mn1:$sc1 $mo2/$dy2/$yr2 $hr2:$mn2:$sc2 \ [$madin get kinst] \ [$madin get krec] \ [$madin get kindat]" } # Close file and delete madrec object $madin close $madin destroy
Further details of the Madrigal Tcl are found by examining the tcl source code from OpenMadrigal.
Madrigal Tcl API | Doc home | Madrigal home |