aboutsummaryrefslogtreecommitdiff
path: root/noao/obsutil/src/doc/cgiparse.hlp
blob: f054ca4e3f9c72f8454272f73acdc7db239f7873 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
.help cgiparse Mar03 noao.obsutil
.ih
NAME
cgiparse -- parse STRING_QUERY environment var. into parameters
.ih
SYNOPSIS
CGIPARSE parses the STRING_QUERY environment varabile and sets parameters.
The string format is a list of task.param=value pairs which includes the
standard QUERY string special characters '&', '+', and '%'.  This is
intended to parse a query from a CGI script.
.ih
USAGE
cgiparse
.ih
PARAMETERS
There are no parameters.  The input is the value of the QUERY_STRING
environment variable.
.ih
DESCRIPTION
CGIPARSE parses the STRING_QUERY environment varabile and sets parameters.
The string format is a list of task.param=value pairs which includes the
standard QUERY string special characters '&', '+', and '%'.  This is
intended to parse a query from a CGI script.

The only input is the STRING_QUERY variable.  If it is undefined the
task simply does nothing.  The string will normally use the standard
parameters for this type of string.  The data fields are task.param=value
strings.  As each is parsed the values will be set for the task.  This
assumes the tasks are defined.  Theere is no error checking for
undefined tasks or parameters.
.ih
EXAMPLES
1.  A CGI script calls a CL script with the STRING_QUERY string set.
The string has "imheader.longheader=yes".  CGIPARSE is called and
when it completes the parameter value is set.

.nf
    cl> lpar imhead
    cl> lpar imheader
           images =                 image names
          (imlist = "*.imh,*.fits,*.pl,*.qp,*.hhh") default image ...
      (longheader = no)             print header in multi-line format
      (userfields = yes)            print the user fields ...
            (mode = "ql")           
    cl> cgiparse
    cl> lpar imheader
           images =                 image names
          (imlist = "*.imh,*.fits,*.pl,*.qp,*.hhh") default image ...
      (longheader = yes)            print header in multi-line format
      (userfields = yes)            print the user fields ...
            (mode = "ql")           
.fi

Note that when running this in a "#!cl" script where the "login.cl" is
not used that you must be careful to have all tasks referenced by the
query string defined.

2.  Below is a "#!cl" type script that uses CGIPARSE.  It is used for
a spectral exposure time calculator based on OBSUTIL.SPTIME though many
aspects are fairly generic for this type of application.

.nf
#!/iraf/iraf/bin.freebsd/cl.e -f

file	urldir

# The following must be set for different hosts.
# The home directory and the urldir are the same but in different syntax.
# The home directory must have a world writable tmp subdirectory.

set arch = ".freebsd"
set (home = osfn ("/www/htdocs/noao/staff/brooke/gsmt/"))
urldir = "/noao/staff/brooke/gsmt/"

# The uparm is a unique temporary directory.
s1 = mktemp ("uparm") // "/"
set (uparm = "home$/tmp/" // s1)
mkdir uparm$
cd uparm
printf ("!/bin/chmod a+rw %s\n", osfn("uparm$")) | cl

# The URL directory is the same as uparm.
urldir = urldir // "tmp/" // s1

# A private graphcap is required to give an path for sgidispatch.
set graphcap = home$graphcap

# Load packages.
dataio
proto
noao
onedspec
spectime
gsmt

# Parse the CGI string and set parameters.
cgiparse

# Create the output.

# Start HTML.
printf ("Content-Type: text/html\n\n")
printf ("<html><head><title>Test</title></head>\n")
printf ("<body>\n")
if (cl.line == "...")
    printf ("<center><h2>SPECTIME</h2></center>\n", cl.line)
else
    printf ("<center><h2>%s</h2></center>\n", cl.line)
printf ("<pre>\n")

# Execute task(s).
#show QUERY_STRING

setup interactive=no mode=h
printf ("</pre>\n")
printf ("<A Href='http://www.noao.edu/noao/staff/brooke/gsmt/gsmt.php?stage=1'>Back to form</A>")
printf ("<pre>\n")

sptime output="counts,snr" graphics="g-gif" interactive=no mode=h

printf ("</pre>\n")
printf ("<A Href='http://www.noao.edu/noao/staff/brooke/gsmt/gsmt.php?stage=1'>Back to form</A>\n")

printf ("<pre>\n")

# Add any gifs created.  We have to wait for them to be created.

gflush

i = 0; j = 1
while (i != j) {
    sleep 2
    j = i
    files *.gif | count STDIN | scan (i)
}


if (i > 0) {
    printf ("<br><p><em>Note: DN and S/N are per-pixel</em><br>\n")
	
    files *.gif > gifs
    list = "gifs"
    while (fscan (list, s1) != EOF) {
	if (access (s1))
		printf ("<img src=\"%s%s\">\n", urldir, s1)
    }
    list = ""
    ## delete ("uparm$gifs", verify-)
}

printf ("</pre>\n")

# Finish HTML.

printf ("<A Href='http://www.noao.edu/noao/staff/brooke/gsmt/gsmt.php?stage=1'>Back to form</A>")

printf ("</body></html>\n")

# Clean up.
## delete ("*[^g][^i][^f]", verify-)

logout
.fi
.ih
SEE ALSO
.endhelp