@@ -0,0 +1,3517 @@
+/*%0ACopyright (c) 2014, Colorado State University%0AAll rights reserved.%0A%0ARedistribution and use in source and binary forms, with or without modification,%0Aare permitted provided that the following conditions are met:%0A%0A1. Redistributions of source code must retain the above copyright notice, this%0A   list of conditions and the following disclaimer.%0A2. Redistributions in binary form must reproduce the above copyright notice,%0A   this list of conditions and the following disclaimer in the documentation%0A   and/or other materials provided with the distribution.%0A%0AThis software is provided by the copyright holders and contributors %22as is%22 and%0Aany express or implied warranties, including, but not limited to, the implied%0Awarranties of merchantability and fitness for a particular purpose are%0Adisclaimed. In no event shall the copyright holder or contributors be liable for%0Aany direct, indirect, incidental, special, exemplary, or consequential damages%0A(including, but not limited to, procurement of substitute goods or services;%0Aloss of use, data, or profits; or business interruption) however caused and on%0Aany theory of liability, whether in contract, strict liability, or tort%0A(including negligence or otherwise) arising in any way out of the use of this%0Asoftware, even if advised of the possibility of such damage.%0A*/%0A%0Apackage galileo.samples;%0A%0Aimport java.util.Map;%0A%0Aimport galileo.dataset.Coordinates;%0Aimport galileo.dataset.Metadata;%0Aimport galileo.dataset.SpatialProperties;%0Aimport galileo.dataset.feature.Feature;%0A%0A/**%0A * A simple demo showing the conversion of a Metadata instance to a custom%0A * JSON format.  Future work will include an automatic serialization to JSON.%0A *%0A * @author malensek%0A */%0Apublic class MetadataToJSON %7B%0A%0A    private static int counter = 0;%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        if (args.length %3C 1) %7B%0A            System.out.println(%0A                    %22Usage: galileo.samples.MetadataToJSON %3Cfilename%3E%22);%0A            return;%0A        %7D%0A%0A        String fileName = args%5B0%5D;%0A        Map%3CString, Metadata%3E metas = ConvertNetCDF.readFile(fileName);%0A        for (Metadata meta : metas.values()) %7B%0A            MetadataToJSON.convert(meta);%0A        %7D%0A    %7D%0A%0A    public static void convert(Metadata meta) %7B%0A        System.out.println(%22%7B%22);%0A        printValue(%22_id%22, counter++ + %22%22);%0A        printQuoted(%22name%22, meta.getName());%0A        printValue(%22hasSpatialProperties%22, meta.hasSpatialProperties());%0A        if (meta.hasSpatialProperties()) %7B%0A            SpatialProperties sp = meta.getSpatialProperties();%0A            if (sp.hasCoordinates()) %7B%0A                Coordinates c = sp.getCoordinates();%0A                String coords = %22%5B%22 + c.getLongitude() + %22, %22%0A                    + c.getLatitude() + %22%5D%22;%0A                printValue(%22spatialProperties%22, coords);%0A            %7D else if (sp.hasRange()) %7B%0A                //TODO range conversion?%0A%0A            %7D%0A        %7D%0A        printValue(%22hasTemporalProperties%22, meta.hasTemporalProperties());%0A%0A        for (Feature f : meta.getAttributes()) %7B%0A            printValue(f.getName(), f.getString());%0A        %7D%0A%0A        //TODO features%0A        System.out.println(%22%7D%22);%0A    %7D%0A%0A    private static void printQuoted(String a, String b) %7B%0A        final char quote = '%22';%0A        System.out.println(quote + a + quote + %22 : %22 + quote + b + quote + %22,%22);%0A    %7D%0A%0A    private static void printValue(String a, Object b) %7B%0A        final char quote = '%22';%0A        System.out.println(quote + a + quote + %22 : %22 + b + %22,%22);%0A    %7D%0A%7D%0A

Add Metadata-JSON conversion sample