[OpenMadrigal-developers] madExperiment instead of madDataBrowse
Angela Li
angela.li at sri.com
Thu Oct 16 13:18:07 EDT 2003
Hi all,
sorry it's madExeriment.cgi, not madDataBrowse. Attached.
Angela Li wrote:
> Hi all,
>
> I don't know if anyone has had this problem with madDataBrowse: When one tries to apply private filters, the public filters "directory:name" are parsed, even if there are no
> public filters saved. That generates a string.split error, which I got around with a few lines of code change.
>
> Attached is the madDatBrowse with the changes. It happens around line 1992 in the original file.
>
> I'm not sure if this change will bring errors, but it seems to work in the moment. If someone has already fixed the problem more completely, please let me know.
>
> regards,
> Angela
>
> _______________________________________________
> OpenMadrigal-developers mailing list
> OpenMadrigal-developers at openmadrigal.org
> http://www.openmadrigal.org/mailman/listinfo/openmadrigal-developers
-------------- next part --------------
#!/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+"$@"}
# $Id: madExperiment.cgi,v 1.26 2003/06/05 19:24:28 brideout Exp $
lappend auto_path /opt/madrigal/madtcllib
package require cgi
package require mtl
# usage: madExperiment.cgi exp expTitle displayLevel
# madExperiment.cgi is a simple Madrigal experiment access program.
# madExperiment.cgi reads the metadata files in that experiment directory
# and the full Instrument and Data Type metadata files and then generates
# a page with links to:
# CEDAR files in the experiment directory
# Html files in the experiment directory
# Files named index.html in any subdirectory of the experiment directory.
# madExperiment.cgi also checks for the existence of a plots/$filename/records directory
# in the experiment directory. If found, it adds a note next to the File Summary link.
# Links to plots for individual records show up in summarizeCedarFile.cgi
# If this script is called from a trusted host (see trustedIPs in the Madrigal
# root directory) all data sets are displayed together with an option to
# toggle the status of individual data sets between public and private.
# For all other hosts, only data sets marked public will be displayed and links to
# the index.html files in any subdirectories whose titles include the string
# "rivate" (matching Private and private) will be surpressed.
########################
# Start Execution Here #
########################
# Use cgi_input with arguments when running from command line
cgi_input "exp=1998/mlh/20jan98&expTitle=TestExpTitle&displayLevel=1"
cgi_import exp
# catch requests from older MADRIGAL installations which dont send the experiment title
if { [ catch { cgi_import expTitle } ] } {
set expTitle ""
}
cgi_import displayLevel
madExperiment experiment
set madroot [experiment cget -madroot]
set madserver [experiment cget -madserver]
set madservercgi [experiment cget -madservercgi]
set madserverroot [experiment cget -madserverroot]
set htmlstyle [experiment cget -htmlstyle]
set htmlstyle [string trimleft [set htmlstyle] "<"]
set htmlstyle [string trimright [set htmlstyle] ">"]
regsub -nocase BODY $htmlstyle "" htmlstyle
set metadataDir [file join $madroot metadata]
set expPath [file join $madroot experiments $exp]
set cgiPath http://[file join $madserver $madservercgi]
set linkPath http://[file join $madserver $madserverroot experiments $exp]
set recpath $expPath/plots
# Determine if this access is from an internal site
set remoteAddress "public"
if { [ info exists env(REMOTE_ADDR) ] } {
if { ![ catch { set allowedIPs [ open "$madroot/trustedIPs.txt" "r"] } ] } {
while { [ gets $allowedIPs nextIP ] > 0 && $remoteAddress == "public" } {
if { [ string match "[ string trimright $nextIP]*" $env(REMOTE_ADDR) ] } {
set remoteAddress "internal"
}
}
close $allowedIPs
}
}
experiment configure -expName $exp
if {[ catch { experiment read } ]} { }
set displayTypes(1) 1
set displayTypes(2) 1
set displayTypes(3) 1
set displayTypes(4) 1
if {$displayLevel == 0} {
set displayTypes(3) 0
set displayTypes(4) 0
}
# Get instrument table
madInstrument instruments
instruments read
instruments getEntries instrumentMnemonic instrumentName \
instrumentLatitude instrumentLongitude \
instrumentAltitude contactName contactAddress1 \
contactAddress2 contactAddress3 \
contactCity contactState contactPostalCode \
contactCountry contactTelephone contactEmail
foreach code [array names instrumentMnemonic] {
#puts "$code $instrumentMnemonic($code) $instrumentName($code)"
}
# Get data type table
madDataType dataTypes
dataTypes read
dataTypes getEntries dataTypeDescription
foreach code [array names dataTypeDescription] {
#puts "$code $dataTypeDescription($code)"
}
# See if we should show comment about plots/records
set hasRecordDir 0
if {[file isdirectory $recpath] == 1} {
set hasRecordDir 1
}
# Get experiment
set files [experiment cget -files]
experiment getFileEntries experimentID fileDataType category spare1 spare2 \
spare3 analysisDate analysisTime statusDesc privateBit
set fileNames {}
foreach dataFile [array names experimentID] {
set fileNames [lappend fileName $dataFile]
#puts [format "%14s %10.10d %4.4d %1.1d %8s %8s %6s %8s %6s %1.1d %1.1d" \
$dataFile $experimentID($dataFile) $fileDataType($dataFile) \
$category($dataFile) $spare1($dataFile) $spare2($dataFile) \
$spare3($dataFile) $analysisDate($dataFile) \
$analysisTime($dataFile) $statusDesc($dataFile) $privateBit($dataFile)]
}
#puts "fileNames = $fileNames"
set data [experiment cget -data]
#puts $data
experiment getDataEntries dataExperimentID dataDataType
set days {}
foreach day [array names dataExperimentID] {
set days [lappend days $day]
#puts [format "%14s %10.10d %4.4d" \
$day $dataExperimentID($day) $dataDataType($day)]
}
#puts "days = $days"
# Get the data type description for each Cedar file (n.b.:fileDataType=kindat)
foreach fileName $fileNames {
set fileDataTypeDescription($fileName) "Unknown data type"
catch {set fileDataTypeDescription($fileName) \
$dataTypeDescription($fileDataType($fileName))}
# puts "$fileName $fileDataType($fileName) $fileDataTypeDescription($fileName)"
}
# Get the file category description and statusDescription for each Cedar file
set categoryDescriptions(1) "default file"
set categoryDescriptions(2) "variant file"
set categoryDescriptions(3) "history file"
set categoryDescriptions(4) "real-time file"
foreach fileName $fileNames {
set fileCategoryDescription($fileName) \
$categoryDescriptions($category($fileName))
if {[string length $statusDesc($fileName)] < 2} {
set statusDescList($fileName) final
} else {
set statusDescList($fileName) $statusDesc($fileName)
}
# puts "$fileName $category($fileName) $fileCategoryDescription($fileName)"
}
# Read the experiment table
set id [experiment cget -id]
set url [experiment cget -url]
set name [experiment cget -name]
set siteID [experiment cget -siteID]
set startDate [experiment cget -startDate]
set startTime [experiment cget -startTime]
set endDate [experiment cget -endDate]
set endTime [experiment cget -endTime]
set instrumentCode [experiment cget -instrumentCode]
set expSecurityCode [experiment cget -securityCode]
#regsub madtoc $expURL madExperiment expURL
regsub madtoc $url madExperiment url
# Process experiment table information
set expInstrumentName "Unknown Instrument - Instrument code = $instrumentCode"
foreach code [array names instrumentMnemonic] {
if {$code == $instrumentCode} {
set expInstrumentName $instrumentName($code)
break
}
}
set year [string range $startDate 0 3]
set month [string range $startDate 4 5]
set day [string range $startDate 6 7]
set startDate $month/$day/$year
set hour [string range $startTime 0 1]
set minute [string range $startTime 2 3]
set second [string range $startTime 4 5]
set startTime $hour:$minute:$second
set year [string range $endDate 0 3]
set month [string range $endDate 4 5]
set day [string range $endDate 6 7]
set endDate $month/$day/$year
set hour [string range $endTime 0 1]
set minute [string range $endTime 2 3]
set second [string range $endTime 4 5]
set endTime $hour:$minute:$second
# Build the Experiment Web Page
# -----------------------------
cgi_eval {
#cgi_debug -on
cgi_http_head
cgi_html {
cgi_head {
cgi_title "Madrigal Experiment $expPath"
}
cgi_body $htmlstyle {
cgi_center {
cgi_h1 $expInstrumentName
cgi_h2 $expTitle
}
# Add Start, end date to page
cgi_hr
cgi_table cellpadding=5 {
cgi_table_row {
cgi_th "Start Time: $startDate $startTime"
cgi_th "End Time: $endDate $endTime"
}
}
cgi_hr
# Add Madrigal files to page
cgi_p [cgi_bold "CEDAR Format Datasets:"]
cgi_bullet_list {
# Sort by category
for {set j 1} {$j <= 4} {incr j} {
foreach fileName $fileNames {
if {$category($fileName) == $j && $displayTypes($j) == 1 && ( $privateBit($fileName) == 0 || $remoteAddress == "internal" ) } {
cgi_li "$fileName - $fileCategoryDescription($fileName) for $fileDataTypeDescription($fileName) - status: $statusDescList($fileName)"
cgi_bullet_list {
set qp1 [cgi_cgi_set expName $exp]
set qp2 [cgi_cgi_set fileName $fileName]
set query "?$qp1&$qp2"
set cmd $cgiPath/summarizeCedarFile.cgi$query
# See if we should show comment about plots/records
set hasRecordDir 0
if {[file isdirectory $recpath/$fileName/records] == 1} {
set hasRecordDir 1
}
# change comment if plots/$filename/records exists
if { $hasRecordDir == 0 } {
set des "Record summary, list of parameters in file, etc."
} else {
set des "Record summary, list of parameters in file, <i>individual record plots available</i>"
}
cgi_li "[cgi_url "File Summary" $cmd] - $des"
regsub -all " " $expTitle "+" cgiExpName
set des "Flat-file listing of a user-selected portion of the file"
set query "?fileName=[file join $expPath $fileName]&expName=$cgiExpName"
set madDataScript "madDataBrowse"
set cmd $cgiPath/$madDataScript$query
cgi_li "[cgi_url "Data Browser (isprint - updated Feb. 2003)" $cmd] - $des"
set query "?fileName=[file join $expPath $fileName]"
set cmd $cgiPath/getMadfile.cgi$query
set des "Download $fileName in selected format"
cgi_li "[cgi_url "Download file" $cmd] - $des"
if { ![ catch { set writableFileTab [ open "$expPath/fileTab.txt" "a"] } ] } {
#cgi_p [cgi_bold "Opened fileTab.txt"]
close $writableFileTab
if { $remoteAddress == "internal" } {
#cgi_p [cgi_bold "Address is interrnal:"]
set query "?expPath=$expPath&fileName=$fileName"
if { $privateBit($fileName) != 0 } {
cgi_li "[cgi_bold "Unpublished"] [cgi_url "(Click to make data set visible on the public web site)" $cgiPath/madPublish.cgi$query]"
} else {
cgi_li "Published [cgi_url "(Click to hide data set from the public web site)" $cgiPath/madPublish.cgi$query]"
}
}
}
}
cgi_br
}
}
}
}
# Add links to html files to page
cgi_hr
cgi_p [cgi_bold "Additional information:"]
# Extract titles from html files in experiment directory
set htmlFiles1 {}
catch { [set htmlFiles1 [glob $expPath/*.html]] }
set i 0
foreach htmlFile $htmlFiles1 {
set htmlFiles1 [lreplace $htmlFiles1 $i $i [file tail $htmlFile]]
incr i
}
# Extract titles from index.html files in experiment subdirectories
set htmlFiles2 {}
catch { [set htmlFiles2 [glob $expPath/*/index.html]] }
set i 0
foreach htmlFile $htmlFiles2 {
set fileTail ""
set fileSplit [file split $htmlFile]
set nSplit [llength $fileSplit]
set fileTail2 [lindex $fileSplit [expr $nSplit-2]]
set fileTail1 [lappend fileTail [lindex $fileSplit [expr $nSplit-1]]]
set fileTail [file join $fileTail2 $fileTail1]
set htmlFiles2 [lreplace $htmlFiles2 $i $i $fileTail]
incr i
}
set htmlFiles [concat $htmlFiles1 $htmlFiles2]
set i 0
foreach htmlFile $htmlFiles {
set fp [open $expPath/$htmlFile r]
set htmlTitle($htmlFile) "No Title"
while {[gets $fp line] >= 0} {
if {[string match "*<TITLE>*" $line]} {
regsub -nocase <TITLE> $line "" line
regsub -nocase </TITLE> $line "" line
set htmlTitle($htmlFile) $line
}
}
close $fp
incr i
}
# List html files by title
cgi_bullet_list {
foreach htmlFile $htmlFiles {
if { $remoteAddress == "internal" || [ string first "rivate" $htmlTitle($htmlFile) ] == "-1" } {
cgi_li [cgi_url $htmlTitle($htmlFile) $linkPath/$htmlFile target=viewWindow]
}
}
}
# Temporary section to handle public/private control of additional data
if { ![catch { exec /bin/cat $madroot/local_rules_of_the_road.txt } returnMessage ] } {
cgi_p $returnMessage
}
# List graphics files
set gifList {}; set jpegList {}; set psList {}; set numberColumns 0
catch { [set gifList [lsort [glob $expPath/*.gif]]] }
catch { [set jpegList [lsort [glob $expPath/*.jpeg]]] }
catch { [lappend jpegList [lsort [glob $expPath/*.jpg]]] }
catch { [set psList [lsort [glob $expPath/*.ps.gz]]] }
catch { [lappend psList [lsort [glob $expPath/*.ps]]] }
if { [ llength $gifList ] } { incr numberColumns }
if { [ llength $jpegList ] } { incr numberColumns }
if { [ llength $psList ] && $remoteAddress == "internal" } { incr numberColumns }
if { $numberColumns > 0 } {
cgi_table border align=center {
cgi_table_row {
th colspan=$numberColumns align=center "IMAGES"
}
cgi_table_row {
if { [ llength $gifList ] } { th align=center "GIF files" }
if { [ llength $jpegList ] } { th align=center "JPEG files" }
if { [ llength $psList ] && $remoteAddress == "internal" } { th align=center "PostScript files" }
}
if { [ llength $gifList ] } {
cgi_table_data {
cgi_bullet_list {
foreach fileEntry $gifList {
put [cgi_url [ file tail $fileEntry ] $linkPath/[ file tail $fileEntry ] ]
cgi_br
}
}
}
}
if { [ llength $jpegList ] } {
cgi_table_data {
cgi_bullet_list {
foreach fileEntry $jpegList {
put [cgi_url [ file tail $fileEntry ] $linkPath/[ file tail $fileEntry ] ]
cgi_br
}
}
}
}
if { [ llength $psList ] && $remoteAddress == "internal" } {
cgi_table_data {
cgi_bullet_list {
foreach fileEntry $psList {
put [cgi_url [ file tail $fileEntry ] $linkPath/[ file tail $fileEntry ] ]
cgi_br
}
}
}
}
}
}
if { $remoteAddress == "internal" } {
# List original datasets
set dataList {}
catch { [set dataList [glob $expPath/*sigma.gz]] }
if { [ llength $dataList ] } {
cgi_p [cgi_bold "Original fitted data files"]
cgi_bullet_list {
foreach fileEntry $dataList {
cgi_li [cgi_url "[ file tail $fileEntry ] (gzipped file)" $linkPath/[ file tail $fileEntry ] ]
}
}
}
}
# add notes section (if writable notes.txt exists in this experiment)
if { ![ catch { set writableNotes [ open "$expPath/notes.txt" "a"] } ] } {
close $writableNotes
cgi_p [cgi_bold "Notes"]
if { ![catch { exec /bin/cat $expPath/notes.txt } returnMessage ] } {
cgi_p $returnMessage
}
set query "?expPath=$expPath&author=&messageContent=&http_referer="
cgi_p [cgi_url "Add to these notes" $cgiPath/madNotes.cgi$query]
}
cgi_hr
}
}
}
More information about the OpenMadrigal-developers
mailing list