NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 17, 2017, 05:05:47 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
The softest thing overcomes the hardest thing in the universe. ...Lao Tzu (570-490 BC)
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: External data  (Read 8564 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Mus
Newbie
*
Offline Offline

Posts: 4

«
Embed this message
on: October 22, 2008, 01:49:17 pm » posted from:Adelaide,South Australia,Australia

Dear Prof. Fu-Kwun Hwang,

I would like to create a viewer for my experiment data. Could you please help me to design an applet?

I have two files that will be used as an an input, one is "mydata.dat" and the other one is "myconfig.cfg" which will stayed in the same folder /combo box. Please find in the attachment three files: mydata.dat, mydata.cfg and information about the files.
I would like to create an interface in applet that will display the graphs or waveforms of mydata.dat values. The information will be displayed according to the myconfig.cfg file. It means that when user select another *.cfg file from the combo box, the waveforms will be displayed the *.dat file of the selected file name.

The graph or the waveforms that will be displayed in the applet such as:

graph 1 :
X axis = time
Y1 axis = Va
Y2 axis = Vb
Y3 axis = Vc

graph 2 :
X axis = time
Y1 axis = Ia
Y2 axis = Ib
Y3 axis = Ic

In addition, if its detect there is value 1 in Tra, Trb or Trc from mydata.dat, it will display the vertical line in the graph 1 and 2.

Thank you very much.

Kind regards,
Mus
-





*** There are 3 more attached files. You need to login to acces it!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: October 22, 2008, 05:18:03 pm » posted from:Taipei,T'ai-pei,Taiwan

You can use EJS to display your data easily.
It is not difficult to read data from files.
However, the difficult part is how to interpret data in the file.
You can either write your own code or find some java library from the web if you want to implemented with java.

The way I will do is: I will set up a web interface and enter those data with web page(as a form).
And send data back to server to create applet page and use php code to generate javascript code to send data to java applet and display it.
It is much easy to read/interpret data with php code.
Logged
Mus
Newbie
*
Offline Offline

Posts: 4

«
Embed this message
Reply #2 on: October 23, 2008, 11:23:47 am » posted from:Adelaide,South Australia,Australia

Thank you for your suggestions.

Yes, I agree with you that it is difficult to interpret data in the file.
The reasons why I choose EJS because the graph will be more interactive, for example, we can zoom the graph that we interested in, and the data can be analyzed using  formula/functions before we displayed the results in the applet.

Do you have any example code, procedures or the references about how the data can be displayed as a graph in applet by using EJS, javascript and php ?

Thank you,

Mus
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #3 on: October 23, 2008, 03:28:12 pm » posted from:Taipei,T'ai-pei,Taiwan

I am assuming that you are familiar with EJS/HTML code and Javascript code.
You can define variables in EJS Model/Variables Tab pages.
All the variable defined are global variables and can be accessed or modified with javascript.
For example: Supposed  you have defined  x=0.5 and dt=0.05 in the ejs
And create an EJS source code as myejs.xml
So the applet tags created will be similar to the following lines: width,height,codebase might be different
Quote
<applet code="xtvt2psametime.xtvt2psametimeApplet.class" codebase="./" archive="_library/ejsBasic.jar,myejs.jar" name="myejs" id="myejs" width="600" height="500" mayscript="true"></applet>
You can found the above html code at created myejs_Simulations.html file.
You can add the following javascript code to access or modify ejs variables:
Quote
x=document.myejs._model.x; // x will be equal to 0.5
document.myejs._model.dt=0.2; // this will change dt variable in the applet to be 0.2 instead of 0.05
Normally, I will define a new variable
Quote
ejsm=document.myejs._model;
x=ejsm.x;
ejsm.dt=0.2;
the above 3 lines will have the same result.
Your data format is
Quote
0000000001,0000000000,-00181,-00805,000983,000691,000007,000142,-00148,000001,0,0,0
0000000002,0000000400,-00044,-00886,000918,000905,-00018,000153,-00135,000001,0,0,0
0000000003,0000000800,000089,-00953,000843,001098,-00042,000164,-00123,000001,0,0,0
0000000004,0000001200,000212,-01008,000760,001272,-00063,000176,-00113,000001,0,0,0
0000000005,0000001600,000331,-01047,000668,001426,-00083,000183,-00099,000002,0,0,0
0000000006,0000002000,000447,-01066,000565,001556,-00103,000184,-00079,000001,0,0,0
0000000007,0000002400,000558,-01065,000453,001659,-00121,000177,-00055,000001,0,0,0
0000000008,0000002800,000662,-01042,000327,001733,-00137,000171,-00032,000001,0,0,0
0000000009,0000003200,000758,-00999,000191,001779,-00153,000161,-00007,000001,0,0,0
0000000010,0000003600,000844,-00940,000052,001801,-00166,000149,000018,000000,0,0,0
0000000011,0000004000,000921,-00872,-00085,001804,-00177,000137,000040,000000,0,0,0
0000000012,0000004400,000986,-00798,-00213,001788,-00187,000128,000058,000001,0,0,0
0000000013,0000004800,001035,-00717,-00332,001747,-00191,000116,000073,000001,0,0,0
0000000014,0000005200,001066,-00621,-00447,001671,-00190,000098,000090,000001,0,0,0
0000000015,0000005600,001074,-00512,-00556,001558,-00184,000074,000107,000001,0,0,0
0000000016,0000006000,001058,-00389,-00657,001404,-00174,000046,000124,000000,0,0,0
0000000017,0000006400,001019,-00253,-00751,001223,-00164,000022,000138,000000,0,0,0
0000000018,0000006800,000964,-00112,-00837,001020,-00152,-00004,000152,-00002,0,0,0
0000000019,0000007200,000898,000026,-00914,000816,-00143,-00026,000164,-00002,0,0,0
0000000020,0000007600,000827,000154,-00980,000616,-00135,-00047,000174,-00003,0,0,0
 
Assume you have defined variables time[20],Va[20] to stored time and Va values.


You can create a form for user to enter the above data
For example:
Quote
<form>
<textarea name=mydata rows=10 cols=10></textarea>
<input type=button value="confirm" onClick="processit(this.form)">
</form>
The above code will create a form for user to enter data. And when user click the button labeled as "confirm", javascript code processit(this.form) will be called.

The javascript code might look like the following lines:
Quote
function processit(mform){// mform will be the form object
 ejsm=document.myejs._model;// get ejs model object
 data=mform.mydata.value;// get the user data
 datalines=data.split("\n"); // assume lines are separated by line break
 for(line in datalines){// process data line by line
  ds=line.split(",");// your data are separated by ","
  id=parseInt(ds[0])-1;// get the integer index value
  ejsm.time[id]=parseFloat(ds[1]);// set the time value
 ...
 }
}
You can set up all necessary parameters/variables with the above java script code.
And EJS will be ready to display your data from user's input.
You do not need php code, if you have fixed data format.
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #4 on: October 23, 2008, 03:39:23 pm » posted from:Taipei,T'ai-pei,Taiwan

The above examples assume data enter by user are all correct format.
The javascript code will be much more complicated if error checking is required.
Please check out Quiz: Do you know when two particles have the same horizontal speed?
PHP code and javascript code are combined to save user data back to server and displayed in the html page. Javascript code are used to calculate/compare user data with the simulation data.
Logged
Mus
Newbie
*
Offline Offline

Posts: 4

«
Embed this message
Reply #5 on: October 24, 2008, 05:09:53 am »


I just wondering if it is possible to make EJS or javascript read the data and interpret directly from the files in the users specified folder rather than entering the data in the form?. Its because the real data is about thousand lines, so it will be difficult for the user to enter the data into the form. It does not have the same total number of line between one data to another as well.

What you have shown in  "Quiz: Do you know when two particles have the same horizontal speed?"  is quite similar with what I want, especially it can calculate and display the information about time. The different with my simulation is user don't need to enter the time but the time is taken directly from coulmn 2 of the data (time in micro-second) and the variable x is taken from column 3 of data.
The information that need to be calculated and displayed in the interface is the time duration between the first time and the last time the value 1 appear in the data in coulmn 11.


Thank you very much.
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #6 on: October 24, 2008, 09:21:15 am » posted from:Taipei,T'ai-pei,Taiwan

For security reason, normal java applet or javascript can not read your computer file.
Java application can have full access to the computer running the program.
I would suggest to read and interprete with java code directly if there are thousand lines of data and you need to repeat similar task many times.
If you just need to use it for a few times, may be combine with php/javascript/ejs will be easier(but will need more computer ram on local and server).
I believe you can find some java library from the web which can read configuration file and interpret data.
(I have done similar search several years ago, and I did find some library. But I did not keep those records. May be I can do similar search again when I have free time. Please try it first by yourself.)
The library will allow you to read data in different format.
Since ejs is a java code generator, you can import java library and use ejs to display interpreted data.


If your data are always with the same format. You can try to write the code by yourself.
There are simple example distributed with EJS distribution.
Please check out EJS/Simulations/_examples/TechnicalExamples/_WriteAndReading.xml
and EJS/Simulations/_examples/TechnicalExamples/_WriteAndReadingASCII.xml
You will also find UsingYourOwnLibraries sub-directory at the same folder.
Check out files in that folder to find out how to add libraries you found.
Logged
Pages: [1]   Go Up
  Print  
The softest thing overcomes the hardest thing in the universe. ...Lao Tzu (570-490 BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Two blocks connected with spring with external force push
Dynamics
Fu-Kwun Hwang 0 10828 Last post February 26, 2007, 04:59:41 pm
by Fu-Kwun Hwang
Plot Panel with Data Anaylsis Tools such as Linear Regression
Collaborative Community of EJS
lookang 1 6375 Last post August 03, 2009, 02:19:03 pm
by lookang
Data images in project MetalicConductor
Questions related to EJS
ahmedelshfie 4 4015 Last post July 03, 2010, 10:21:35 am
by ahmedelshfie
how to make Ejs Data collect over a series of runs of experiments
Questions related to EJS
lookang 6 5508 Last post September 22, 2010, 10:29:43 am
by lookang
can data builder do dflux / dt ?
Questions related to EJS
lookang 6 6337 Last post February 27, 2011, 11:04:52 am
by Fu-Kwun Hwang
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.058 seconds with 22 queries.since 2011/06/15