I have created a package of Java classes which give access to the geomag data. For background information on the geomag data see CGIAccessToGeomagData. The javadoc documentation for these is here: http:\\www.geomag.bgs.ac.uk\workshop\GeomagJavaDoc

The rest of this page gives some examples of using the classes.

Using properties to tell the software how to find the data.

Before running any of the code, you need to set a couple of properties. These tell the software where to find files. The GIN data will be shared as a Samba share \\mhlf\e_gin - the following examples assume q: is mapped to \\mhlf\e_gin. The first property is "GIN_DATA_DIR" which should be set to the base directory for the data files, something like this:

    java.util.Properties sys_props = System.getProperties();
    sys_props.setProperty("GIN_DATA_DIR", "q:\\data");

The second is "GIN_SYS_TAB_DIR" which points to a directory containing the system configuration files, something like this:

    java.util.Properties sys_props = System.getProperties();
    sys_props.setProperty("GIN_SYS_TAB_DIR", "q:\\data\\system_tables");

Of course the properties can be set with the -D command line option to the Java command.

Getting a list of stations

The first thing an application would probably want to do is list the available stations:

        int count;
        StationDetails sd;
        StationDetails.StationDetailsFields sd_fields;
        
        sd = new StationDetails (StationDetails.ORDER_BY_STATION_CODE);
        for (count = 0; count << sd.getNRows (); count++)
        {
            sd_fields = sd.getRow (count);
            System.out.print (Integer.toString (count +1));
            System.out.print (" " + sd_fields.station_code));
            System.out.println (" [" + station_details_fields.station_name + "]");
        }

Finding out how much data is available

Having chosen a station (for the examples we will use Eskdalemuir which has a station code "esk"), an application might then want to check how much data is available. The next piece of code lists the number of data points available for station esk, 1 line per day, from the first available day to the last (for minute data there should be 1440 data points per day):

        int count;
        GINUtils.AvailableDataDetails av_data_details;
        
        av_data_details = GINUtils.getAvailableData("esk", "adj-or-rep", null, null);
        System.out.println (av_data_details.start_date.toString());
        for (count = 0; count << av_data_details.day_counts.length; count ++)
            System.out.println (av_data_details.day_counts[count]);

Retrieving data

Finally we want to get some data. This example retrieves 10 minutes of data for station "esk" starting at 00:00:00 on 1st Jan 2006 (there is some a-priori knowledge of epoch dates to save space) and prints each of the 4 components in each of the 10 samples:

        int count;
        MinuteData minute_data;
        Date date;
        
        System.out.println ("Data:");
        date = new Date (1136073600000l);   // 1st Jan 2006        
        minute_data = new MinuteData ("esk", date, 10, "adj-or-rep", true);
        for (count = 0; count << minute_data.getDataLength(); count ++)
        {
            System.out.println (Integer.toString (count) + " " +
                                minute_data.getData(0, count) + " " +
                                minute_data.getData(1, count) + " " +
                                minute_data.getData(2, count) + " " +
                                minute_data.getData(3, count));
        }

-- SimonFlower - 13 Nov 2006

Topic revision: r2 - 13 Nov 2006 - 21:03:13 - SimonFlower
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback