ReefCast
Subject: Signature Generator XML intergration into Website
Prev Next
You are not authorized to post a reply.

Page 2 of 3 << < 123 > >>
AuthorMessages
climatestudios User is Offline
Copepod
Copepod
Posts:12


09/19/2007 8:02 AM  

Hey, thanks Carlos. It's actually your code from a couple posts above, I get (Error on line 27, unexpected ']'). I didn't set up the cron job, just running it from the server until bugs fixed. Here's mine, only parts I changed were my details for sql database. My server has php 5.1.6 if that matters, and I have little (read: very little) knowledge of php which I'm sure certainly matters! I appreciate your help, thanks a ton.

 

php
##This file is to be run via cron job once every 1 minutes
##It takes the AC generated XML file and stores the status
##and values to a SQL database.  
##
## * * * * * /usr/bin/lynx -source http://URLofScript
##
#Opens the database connection
mysql_connect('localhost', 'climates_logan', 'xxx') or die(odbc_error());
mysql_select_db("climates_reeftank");
#Clears the current status table and prepares it for new values
mysql_query("TRUNCATE TABLE tank");
#Opens and stores the xml file into a string
$xml = "";
$f = fopen( 'http://www.rowelab.com/AquaController/climatestudios.xml', 'r' );
while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
fclose( $f );
#Parse items from XML
preg_match_all( "/\<item\>(.*?)\<\/item\>/s", 
$xml, $itemblocks );
foreach( $itemblocksΏ] as $block )
{
preg_match_all( "/\<title\>(.*?)\<\/title\>/", $block, $title );
preg_match_all( "/\<description\>(.*?)\<\/description\>/", $block, $description );
#Stores items in SQL database
mysql_query("INSERT INTO tank (`ID`, `Title`, `Description`, `PubDate`) VALUES ('', '".$titleΏ]Ύ]."', '".$descriptionΏ]Ύ]."', NOW())" [Wink] ;
#A screen print of what was stored
echo( $titleΏ]Ύ]." - ".$descriptionΏ]Ύ]."<br/>\n" );
}
?>
Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


09/19/2007 2:09 PM  

Give this file a try.

I made some changes and made it easier to edit as well.  You will have to open the file and make the necessary changes.

Here is the file. 

xml2sql.zip

HTH,

Carlos

climatestudios User is Offline
Copepod
Copepod
Posts:12


09/19/2007 2:58 PM  
WOW. Worked 'right out of the box'. So I may have been removing some of the "`" or other characters that should be there perhaps. I really appreciate it - edited the info, uploaded, ran it once, and voila - 1st set in database! Thanks so much, Carlos!
Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


09/20/2007 8:03 AM  
Excellent!!!

Glad to hear it worked.

Maybe you can later link us to your website so we can see what you have done!!!

Carlos
climatestudios User is Offline
Copepod
Copepod
Posts:12


09/20/2007 8:37 AM  
Will do for sure! The current php/xml tank status is up at prodibio.climatestudios.com. I plan to use JPGraph with the database to create a main page about the tank with graphs and energy consumption table like on your page, carlos. I love that feature of your site. Thanks for your help!
Ashlar User is Offline
ReefChat Staff
Goby
Goby
Posts:144


09/20/2007 10:39 AM  
I use jpgraph as well for the graphs.. awesome package.

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


09/20/2007 1:41 PM  
I also use JPgraph as well. It is a great package and very easy to use.

You will need to create a new database table and new script. Remember that this script clears out the table before storing data. The new script will have to add to the table and you probably would want to run it every 5 minutes or so.

Carlos
climatestudios User is Offline
Copepod
Copepod
Posts:12


09/21/2007 3:08 PM  

Hi, thanks guys. Yeah, I put a '#' in front of the line that clears the table each time and set up a cron job at every 10 min. So far, fantastic. It's storing in my table every 10 minutes. Found a great tutorial on JPgraph online, so thanks to all that and your help, so far so good. Once I'm able to graph, I'm going to borrow a killawatt and see about measuring all that jazz. but, one step at a time. I'm still playing around though , because i do want to at least have a little understanding of the php involved.  i don't want you to do all my work for me carlos lol

PMolan User is Offline
Copepod
Copepod
Posts:30


12/06/2007 3:16 PM  
Anyone want to take a crack at this?? The site I am working on displays conductivity. What the frig is a conductivity people ask... I know there is a formula to convert conductivity to salinity by using (Conductivity, Pressure, and Temp).. I cant seem to get acurate results with code given to me off another site. Anyone know of a formula that I can convert to javascript?


Ashlar User is Offline
ReefChat Staff
Goby
Goby
Posts:144


12/07/2007 6:45 AM  
A cursory search didn't find a formula that seems to work. (I found the one with the pressure, but it appears to be in different units, and 53.0 / 1.0 / 25.5 doesn't yeild 35ppt.)

LVReefer User is Offline
Copepod
Copepod

Posts:19


12/07/2007 8:33 AM  

Have you seen this?

http://ioc.unesco.org/Oceanteacher/oceanteacher2/01_GlobOcToday/02_CollDta/02_OcDtaFunda/02_OcMeasUnits/SWequationofstatecalculator.htm


admin User is Offline
Site Administrator
Tang
Tang

Posts:255


12/07/2007 2:15 PM  
On Wet Web Media the same question was asked. They wanted the formula to convert conductivity to specific gravity. Of course the good folks there sent him to Randy Holmes-Farely. The formula the guy was thinking was SG = Conductivity * (factor) @ a given temperature (78F). (Needing the factor.)

Anyway Boomer on RC assisted another RC member with a paper and pointed him to http://oceanworld.tamu.edu/resources/ocng_textbook/chapter06/chapter06_01.htm for some of the formulations. Here is the link to the article http://reef.gamma.za.net/home/article_content.dot?inode=1873

Been way too many years since chemistry class. Hope it can help you out.

ReefChat Staff
admin User is Offline
Site Administrator
Tang
Tang

Posts:255


12/07/2007 2:25 PM  

Just so we are clear. The formula for what you are asking is pretty complex. Attached below is the formula that I found. Lot to consider when making that calc.


ReefChat Staff
Ashlar User is Offline
ReefChat Staff
Goby
Goby
Posts:144


12/07/2007 5:41 PM  

Okay, I modified one of them to work with with pressure=0..

http://rowelab.com/fish/sal.html

http://rowelab.com/fish/sal2.html

(first one is for degrees F, second is for degrees C)

 


PMolan User is Offline
Copepod
Copepod
Posts:30


12/07/2007 8:36 PM  
Posted By admin on 12/07/2007 2:25 PM

Just so we are clear. The formula for what you are asking is pretty complex. Attached below is the formula that I found. Lot to consider when making that calc.

Thanks thats what I needed!!  Here's what that looks like in javascript.

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">


Untitled Document
[script removed] function salinity(c,t,p) {
   var R,rt,Rp,Rt,Rt5,t5,dels,A,B,C,sal;

   R = c / 4.29140;
   rt = 0.6766097 + t * ( 0.0200564 + t * ( 1.104259e-04 + t * ( -6.9698e-07 + t * 1.0031e-09 ) ) );

   A = 0.4215 - 0.003107 * t;
   B = 1 + t * ( 0.03426 + t * 0.0004464 );
   C = p * ( 2.07e-5 + p * ( -6.37e-10 + p * 3.989e-15 ) );

   Rp = 1 + C / ( B + A * R );
   Rt = R / rt / Rp;

   Rt5 = Math.sqrt( Rt );
   t15 = t - 15;
   dels = t15 / ( 1 + 0.0162 * t15 );
   sal = ( 14.0941 + dels * -0.0375 ) + Rt5 * ( ( -7.0261 + dels * 0.0636 ) + Rt5 * ( ( 2.7081 + dels * -0.0144 ) ) );
   sal = ( 0.008 + dels * 0.0005 ) + Rt5 * ( ( -0.1692 + dels * -0.0056 ) + Rt5 * ( ( 25.3851 + dels * -0.0066 ) + Rt5 * sal ) );
   return sal;
}
// Compute density from salinity, temperature and pressure
function density(s,t,p) {
   var d0,d,K,E,F,G,H,I,J,M,N,t2,t3,t4,s1p5,pb

   t2 = t * t;
   t3 = t2 * t;
   t4 = t3 * t;

   d0 = density0(s,t);

   E = 19652.21 + 148.4206 * t - 2.327105 * t2 + 1.360477e-2 * t3 - 5.155288e-5 * t4;
   F = 54.6746 - 0.603459 * t + 1.09987e-2 * t2 - 6.1670e-5 * t3;
   G = 7.944e-2 + 1.6483e-2 * t - 5.3009e-4 * t2;
   H = 3.239908 + 1.43713e-3 * t + 1.16092e-4 * t2 - 5.77905e-7 * t3;
   I = 2.2838e-3 - 1.0981e-5 * t - 1.6078e-6 * t2;
   J = 1.91075e-4;
   M = 8.50935e-5 - 6.12293e-6 * t + 5.2787e-8 * t2;
   N = -9.9348e-7 + 2.0816e-8 * t + 9.1697e-10 * t2;

   s1p5 = s * Math.sqrt(s);

   pb = p/10;

   K = (E + F*s + G*s1p5) + (H + I*s + J*s1p5) * pb + (M + N*s) * pb * pb;
   d = d0 / (1 - pb/K);
   d=Math.round(d*10)/10000;
 
  

   return d;
}
// Compute density (kg/m3) at the surface from salinity (psu) and temperature (degC)
function density0(s,t)
    {
        var A,B,C,D,dens0;
       
        A =   1.001685e-04 + t * ( -1.120083e-06 + t * 6.536332e-09 );
        A = 999.842594 + t * (  6.793952e-02 + t * ( -9.095290e-03 + t * A ) );
        B =   7.6438e-05 + t * ( -8.2467e-07 + t * 5.3875e-09 );
        B =   0.824493 + t * ( -4.0899e-03 + t * B );
        C =  -5.72466e-03 + t * ( 1.0227e-04 - t * 1.6546e-06 );
        D = 4.8314e-04;
        dens0 = A + s * (  B + C * Math.sqrt(s) + D * s );
        return dens0;
    }
   

[script removed]


[script removed] var c=50, t=77, p=0, s, d;
//Convert mS/cm to S/m
c=c/10;
//Convert F to C
t=(5/9)*(t-32);

document.write (density(salinity(c,t,0),t,0));
[script removed]

 



PMolan User is Offline
Copepod
Copepod
Posts:30


12/07/2007 8:43 PM  
Seriously though.. Different conversion sites yield different results.. Mathamatically they are close but off by .001 When the swing is 1.021 to 1.026, I cant imagine that conductivity is that accurate.


Ashlar User is Offline
ReefChat Staff
Goby
Goby
Posts:144


12/08/2007 12:45 PM  
*nod* Even the 25 degrees C / 53.0mS/cm / 0bar doesn't yeild 35ppt on any calculator..

Going from conductivity to salinity (ppt) then to density, so that you can get the unitless specific gravity seems to lose precision with each conversion. Especially since it's a curve with fixed points, not a mathematical curve (that's what all those constants are for in the function.)

PMolan User is Offline
Copepod
Copepod
Posts:30


12/11/2007 4:47 AM  

I ended up refering to a chart for the calculations.  Converting conductivity to salinity is a one step calculation.  From that point based on temp and salinity I have it go to the chart for the specific gravity.  Not as accurate as I want it to be, but I guess it will have to do.  Thanks everyone.



PMolan User is Offline
Copepod
Copepod
Posts:30


01/11/2008 7:15 PM  
Still working on the site.. I.ve got most of it where I want it. I wanted to incorporate graphs like aquanotes does. I've seen on multiple sites similar graphs running.
http://effireef.com/graphs.php
http://www.danj.com/reef/graphs.php?params=:Temperature:pH:ORP:tmpg

Just looking for a direction. Thanks.


PMolan User is Offline
Copepod
Copepod
Posts:30


01/14/2008 6:48 PM  
zzzzzzzzzzzzzzzzzzzzzzzzzzz


You are not authorized to post a reply.
Page 2 of 3 << < 123 > >>

Forums > ReefChat Extras > Signature Generator > Signature Generator XML intergration into Website



ActiveForums 3.7
Home|Forums|Links|LFS Map|Photo Galleries|Video Gallery|Sponsors
Copyright 2006 by ReefChat.org - A reef keeping communityTerms Of UsePrivacy Statement