[Thread Prev][Thread Next][Index]

Re: [las_users] LAS V7 : Unable to make intermediate netCDF file.



Hi Efren,

Serra, Mr. Efren, Contractor, Code 7542 wrote:

Roland,

 

I was wondering if you ever received my last email where I included Java code to access and display the BLOB values.  Thanks.

Yes, I did receive the code.  Thanks.  Sorry I fell silent on this issue.

Once I have the code it moves from a process of answering a email to actually writing and testing code and thus it has to be fit in among the other priorities for new development and bug fixes.  I don't know of any other groups storing data this way so I'm afraid I've put it down a couple of notches on the priority list.

If you are able I would encourage you to try to tackle the additions to the InteremediateNetcdfFile class yourself and contribute the change back to us for others to use.  I can coach you over email.  Otherwise, I've got a note in our bug tracking system that this is enhancement has be requested.

Roland

 

Efren A. Serra (Contractor)
DeVine Consulting, Inc.
Naval Research Laboratory
Marine Meteorology Division
7 Grace Hopper Ave., STOP 2
Monterey, CA 93943
Code 7542
Office: 831-656-4650


From: Roland Schweitzer [mailto:Roland.Schweitzer@xxxxxxxx]
Sent: Tuesday, November 10, 2009 12:55 PM
To: Serra, Mr. Efren, Contractor, Code 7542
Cc: oar.pmel.las_users@xxxxxxxx
Subject: Re: [las_users] LAS V7 : Unable to make intermediate netCDF file.

 

Efren,

Maybe somebody else on the list is an expert on using mySQL blobs in Java and can figure out how to make it work in Java, but I probably wont' be able to help in that regard.  One way to get this to work it to implement your own database backend in Python.  Others have created LAS backends using Python.  In this case it would receive a SOAP message containing the XML that specifies the query that needs to be made.  Your code would be responsible for interpreting the XML, making the query and creating the netCDF file that LAS needs to make the plots.

It's a shame to have to reinvent the wheel, but it's an approach that would certainly work. 

Roland

Serra, Mr. Efren, Contractor, Code 7542 wrote:

Roland,

 

This one is as bad as it gets, eh?  The data is being written using Python’s struct.pack.  I’m able to read using it Python’s MySQLdb and struct modules; however, Java’s DataInputStream returns garbage.  Included are the two test scripts/Java code.

 

Python code:

 

import MySQLdb

import struct

 

conn = MySQLdb.connect("localhost", "user", "passwd", "argo2")

cursor = conn.cursor(MySQLdb.cursors.DictCursor)

sql = "SELECT profile_id,t,x,y,pres,pres_qc,psal,psal_qc,temp,temp_qc FROM profiles WHERE (temp<99999.0 OR temp>99999.0) AND ((x>=-180.0) AND (x <=179.0)) AND ((y>=-90) AND (y<=89)) AND ((pres>=0) AND (pres<=5000)) AND ((t>=349069.0) AND (t<=349069.0));"

cursor.execute(sql)

result_set = cursor.fetchall()

for row in result_set:

  col = row["pres"]

  print col

  i=0

  j=4

  length = col.buffer_info()[1] * col.itemsize

  while (length):

    print struct.unpack('=f', col[i:j].tostring())

    i +=4

    j +=4

    length -=4

 

print "Number of rows returned: %d" % cursor.rowcount

 

cursor.close()

conn.close()

 

Java code:

 

import java.io.*;

 

public class argo2_test {

 

  public static void main (String args[]) throws Exception

  {

    java.sql.Connection conn;

    java.sql.ResultSetMetaData meta;

    java.sql.Statement stmt;

    java.sql.ResultSet result;

    int i;

 

    System.out.println("JDBC sample application starts...");

    System.out.println("Application tries to register the driver.");

 

    // this is the recommended way for registering Drivers

    java.sql.Driver d =

       (java.sql.Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();

 

    System.out.println("Driver succesfully registered.");

 

    // the user is asked for a connect string

    System.out.println(

        "Now sample application needs a connectstring in format:\n"

        );

    System.out.println(

        "jdbc:mysql://<host>:<port>/<database>?<user name>=value&<password>=value\n"

        );

    System.out.print("\nPlease enter the connect string >");

    //BufferedReader reader =

    //    new BufferedReader(new InputStreamReader(System.in));

    //String sCon = reader.readLine();

    String sCon = "jdbc:mysql://localhost:3306/argo2?user=user&password=passwd";

 

    // next, the connection is attempted

    System.out.println("Attempting to connect :" + sCon);

    conn = java.sql.DriverManager.getConnection(sCon);

 

    System.out.println("Driver succesfully connected.");

 

    String sQuery = "SELECT profile_id,t,x,y,pres,pres_qc,psal,psal_qc,temp,temp_qc FROM profiles WHERE (temp<99999.0 OR temp>99999.0) AND ((x>=-180.0) AND (x <=179.0)) AND ((y>=-90) AND (y<=89)) AND ((pres>=0) AND (pres<=5000)) AND ((t>=349069.0) AND (t<=349069.0));";

 

    stmt= conn.createStatement();

 

    result = stmt.executeQuery(sQuery);

    System.out.println("Query executed and result set obtained.");

 

    // we get a metadataobject containing information about the

    // obtained result set

    System.out.println("Obtaining metadata information.");

    meta = result.getMetaData();

    int cols = meta.getColumnCount();

 

    System.out.println("Metadata information for columns is as follows:");

    // we dump the column information about the result set

    for (i=1; i <= cols; i++)

    {

        System.out.println("Column i:"+i+"  "+meta.getColumnName(i)+ "," +

             meta.getColumnType(i) + "," + meta.getColumnTypeName(i) + "," +

             meta.getColumnDisplaySize(i));

    }

 

    // and finally, we dump the result set

    System.out.println("Starting to dump result set.");

    int cnt = 1;

    while(result.next())

    {

        System.out.print("\nRow "+cnt+" : ");

        for (i=1; i <= cols; i++) {

          switch (i) {

            case 5:

              try

              {

              java.sql.Blob blob = result.getBlob(i);

              long blen = blob.length();

              DataInputStream distream = new DataInputStream(result.getBinaryStream(i));

              System.out.println("Blob length: "+blen);

              while (blen>0) {

                float presVal = distream.readFloat();

                System.out.println("pres value: "+presVal);

                blen -= 4;

              }

              } catch (Exception ex) { ex.printStackTrace();}

              break;

          }

          System.out.print(result.getString(i)+"\t");

        }

        cnt++;

    }

 

    stmt.close();

 

    conn.close();

    // and not it is all over

    System.out.println("\nResult set dumped. Sample application finishes.");

  }

}

Efren A. Serra (Contractor)
DeVine Consulting, Inc.
Naval Research Laboratory
Marine Meteorology Division
7 Grace Hopper Ave., STOP 2
Monterey, CA 93943
Code 7542
Office: 831-656-4650


 



[Thread Prev][Thread Next][Index]


Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement