[LON-CAPA-users] How to realize a randomly generated downloadable data set?

Peter Riegler lon-capa-users@mail.lon-capa.org
Thu, 21 Jun 2007 16:55:14 +0200


Here is an example which Gerd has provided to me. However, it does not 
open a "save as"-window on all browsers

<problem>
<script type="loncapa/perl">$omega=2*$pi/&random(30,60,1);
$phi=&random(1,2,0.1);
$amp=&random(3,10,1);
for ($t=0;$t<=600;$t++) {
      $func=$amp*(sin($omega*$t+$phi)+&random(-0.2,0.2,0.01));
      $data.="$t,$func\\n";
}</script>
<startouttext />
<script type="text/javascript">
function datawindow() {
     csvwindow=window.open("","datafile","");
     csvwindow.document.mimeType="text/csv";
     csvwindow.document.clear();
     csvwindow.document.write("<pre>$data</pre>");
     csvwindow.document.close();
}
</script>
Copy the data file and perform a Fourier analysis.<br />
<a href="javascript:datawindow();">Data File</a><br />
What is the angular frequency of the data?<endouttext />
<numericalresponse unit="rad/s" format="3s" answer="$omega">
     <responseparam type="tolerance" default="5%" name="tol" 
description="Numerical Tolerance" />

     <textline readonly="no" />

</numericalresponse>
</problem>


Jay Sullivan wrote:

> Gerd,
> 
> Trying to figure out what you mean here. Do you mean javascript that 
> would allow the user to download the data?
> Is that possible with javascript security? If you have an example of 
> that, I would love to use it in several of my problems.
> 
> Jay
> 
> On 5/7/07, *Gerd Kortemeyer* <korte@lite.msu.edu 
> <mailto:korte@lite.msu.edu>> wrote:
> 
> 
>     If yes, then the problem below might do the trick. Alternatively, one
>     could put a piece of JavaScript around the data which provides a "file."
> 
> 

-- 
Peter Riegler
Fachhochschule Braunschweig/Wolfenbüttel
Salzdahlumer Str. 46/48, 38302 Wolfenbüttel
Tel. +49 5331 939 6314, Fax. +49 5331 939 6002
email: p.riegler@fh-wolfenbuettel.de
http://public.rz.fh-wolfenbuettel.de/~riegler