Remote Matlab API and Examples


This page describes the remote Matlab API, and gives an example of using this API. This API and example have been tested on both Windows and Linux, and require only access to the internet and Matlab 5 or greater to run. It is available for download here.

Remote Matlab methods

   ***********************************************************
       
    getMadrigalCgiUrl  	parse the main madrigal page to get the cgi url  
    
     The calling syntax is:
   
   		[cgiurl] = getMadrigalCgiUrl(url)
		
     where url is the url of the Madrigal home page.  For example,  
     getMadrigalCgiUrl('http://www.haystack.mit.edu/madrigal/') would
     return 'http://www.haystack.mit.edu/cgi-bin/madrigal/'
     
     
   ***********************************************************
     
   isprintWeb  	Create an isprint-like 3D array of doubles via
                a command similar to the isprint command-line
                application, but access data via the web
   
   The calling syntax is:
   
   		[records] = isprintWeb(cgiurl, file, parms, filters, [missing, [assumed, [knownbad] ] ])
   
    where 
 
      cgiurl (string) to Madrigal site cgi directory that has that
       filename.
         (Example: 'http://www.haystack.mit.edu/cgi-bin/madrigal/') 
          Note that method getMadrigalCgiUrl converts homepage url into cgiurl.
   
      file is path to file
          (example = '/home/brideout/data/mlh980120g.001')
   
      parms is the desired parameters in the form of a comma-delimited
          string of Madrigal mnemonics (example = 'gdlat,ti,dti')
   
      filters is the filters requested in exactly the form given in isprint
          command line (example = 'time1=15:00:00 date1=01/20/1998 
                        time2=15:30:00 date2=01/20/1998 filter=ti,500,1000')
          See:  http://www.haystack.mit.edu/madrigal/isprint.html for details
 
      missing is an optional double to represent missing values.  Defaults to NaN
 
      assumed is an optional double to represent assumed values.  Defaults to NaN
 
      knownbad is an optional double to represent knownbad values.  Defaults to NaN
 
      The returned records is a three dimensional array of double with the dimensions:
 
          [Number of rows, number of parameters requested, number of records]
 
      If error or no data returned, will return error explanation string instead.
      
      
   ***********************************************************   
 
   getInstrumentsWeb  	returns an array of instrument structs of instruments found on remote Madrigal server.
 
   inputs:  cgiurl (string) to Madrigal site cgi directory 
       (Example: 'http://www.haystack.mit.edu/cgi-bin/madrigal/') 
       Note that method getMadrigalCgiUrl converts homepage url into cgiurl. 
 
   output:
      instArray - array of instrument structs found
 
        instrument struct has the fields:
 
      instrument.name (string) Example: 'Millstone Hill Incoherent Scatter Radar'
      instrument.code (int) Example: 30
      instrument.mnemonic (3 char string) Example: 'mlh'
      instrument.latitude (double) Example: 45.0
      instrument.longitude (double) Example: 110.0
      instrument.altitude (double)  Example: 0.015 (km) 
 
   Raises error if unable to return instrument array.
   
   
   ***********************************************************
   
   getExperimentsWeb  	returns an array of experiment structs given input filter arguments from a remote Madrigal server.
 
   Inputs:
 
       1. cgiurl (string) to Madrigal site cgi directory 
         (Example: 'http://www.haystack.mit.edu/cgi-bin/madrigal/') 
          Note that method getMadrigalCgiUrl converts homepage url into cgiurl. 
  
       2. instCodeArray - a 1 X N array of ints containing selected instrument codes.  Special value of 0 selects all instruments.
  
       3. starttime - Matlab datenum double (must be UTC)
  
       4. endtime - Matlab datenum double (must be UTC)
 
       5. localFlag - 1 if local experiments only, 0 if all experiments 
 
    Return array of Experiment struct (May be empty):
    
    experiment.id (int) Example: 10000111
    experiment.url (string) Example: 'http://www.haystack.edu/cgi-bin/madtoc/1997/mlh/03dec97'
    experiment.name (string) Example: 'Wide Latitude Substorm Study'
    experiment.siteid (int) Example: 1
    experiment.sitename (string) Example: 'Millstone Hill Observatory'
    experiment.instcode (int) Code of instrument. Example: 30
    experiment.instname (string) Instrument name. Example: 'Millstone Hill Incoherent Scatter Radar'
    experiment.starttime (double) Matlab datenum of experiment start
    experiment.endtime (double) Matlab datenum of experiment end
    experiment.isLocal (int) 1 if local, 0 if not 
 
   Raises error if unable to return experiment array
   
   
   *********************************************************** 
   
   getCgiurlForExperiment  	returns cgiurl of experiment struct as returned by getExperimentsWeb or getExperiments.
 
   inputs:  experiment struct as returned by getExperimentsWeb or getExperiments.
 
 
   output:
      cgiurl of experiment
 
   Simply truncates experiment.url to remove /madtoc/<YYYY>/<inst>/<date>
  
   

   ***********************************************************
   
   getExperimentFilesWeb  	returns an array of experiment file structs given experiment id from a remote Madrigal server.
 
   Note that it is assumed that experiment is local to cgiurl.  If not,
   empty list will be returned.
 
   Inputs:
 
       1. cgiurl (string) to Madrigal site cgi directory that has that
       experiment.
         (Example: 'http://www.haystack.mit.edu/cgi-bin/madrigal/') 
          Note that method getCgiurlForExperiment returns cgiurl for a given experiment struct. 
  
       2. experiment id (int) as returned by getExperiments or
          getExperimentsWeb
 
    Return array of Experiment File struct (May be empty):
    
    file.name (string) Example '/opt/mdarigal/blah/mlh980120g.001'
    file.kindat (int) Kindat code.  Example: 3001
    file.kindatdesc (string) Kindat description: Example 'Basic Derived Parameters'
    file.category (int) (1=default, 2=variant, 3=history, 4=real-time)
    file.status (string)('preliminary', 'final', or any other description)
    file.permission (int)  0 for public, 1 for private 
 
   Raises error if unable to return experiment file array
   
   
   ***********************************************************
   
   getParametersWeb  	returns an array of parameter structs given filename from a remote Madrigal server.
 
   Note that it is assumed that filename is local to cgiurl.  If not,
   empty list will be returned.
 
   Inputs:
 
       1. cgiurl (string) to Madrigal site cgi directory that has that
       filename.
         (Example: 'http://www.haystack.mit.edu/cgi-bin/madrigal/') 
          Note that method getMadrigalCgiUrl converts homepage url into cgiurl. 
  
       2. filename (string) as returned by getExperimentFiles or
          getExperimentFilesWeb
 
    Return array of Parameter struct:
    
        parameter.mnemonic (string) Example 'dti'
        parameter.description (string) Example:
           "F10.7 Multiday average observed (Ott) - Units: W/m2/Hz"
        parameter.isError (int) 1 if error parameter, 0 if not
        parameter.units (string) Example "W/m2/Hz"
        parameter.isMeasured (int) 1 if measured, 0 if derivable
        parameter.category (string) Example: "Time Related Parameter" 
        parameter.isSure (int) 1 if can be found for all records, 0 if only
            for some records (implies not all records have same measured
            parameters)
 
   Raises error if unable to return parameter array
   
   

   ***********************************************************
   
   
   madCalculatorWeb  	Create a matrix of doubles via a the Madrigal derivation engine for a time and range of lat, long, and alt
   
   The calling syntax is:
   
   		[record] = madCalculatorWeb(cgiurl, time, startLat, endLat, stepLat, startLong, endLong, stepLong, 
                                    startAlt, endAlt, stepAlt, parms)
   
    where 
 
      cgiurl (string) to Madrigal site cgi directory that has that
       filename.
         (Example: 'http://www.haystack.mit.edu/cgi-bin/madrigal/') 
          Note that method getMadrigalCgiUrl converts homepage url into cgiurl.
   
      time - Matlab datenum double (must be UTC)	7. startLat - Starting geodetic latitude, -90 to 90 (required)
      
      endLat - Ending geodetic latitude, -90 to 90 (required)
      
      stepLat - Latitude step (0.1 to 90) (required)
      
      startLong - Starting geodetic longitude, -180 to 180 (required)
      
      endLong - Ending geodetic longitude, -180 to 180 (required)
      
      stepLong - Longitude step (0.1 to 180) (required)
      
      startAlt - Starting geodetic altitude, >= 0 (required)
      
      endAlt - Ending geodetic altitude, > 0 (required)
      
      stepAlt - Altitude step (>= 0.1) (required)
   
      parms is the desired parameters in the form of a comma-delimited
          string of Madrigal mnemonics (example = 'gdlat,ti,dti')
   
 
      The returned record is a matrix of doubles with the dimensions:
 
          [(num lat steps * num long steps * num alt steps), 3 + num of parms]
 
      The first three columns will always be lat, long, and alt, so there are three
      additional columns to the number of parameters requested via the parms argument.
 
      If error or no data returned, will return error explanation string instead.
 
      Example: result = madCalculatorWeb('http:/grail.haystack.mit.edu/cgi-bin/madrigal', ...
                                          now,45,55,5,45,55,5,200,300,50,'bmag,bn');
   
   
   ***********************************************************
   
   getUrl returns the text given by url as a string
   
   ***********************************************************
   

Simple Example

This simple example Matlab script uses most of the methods discussed above.

 
% demo program of madmatlab running on a pc or linux

% first, get url of installation to test
madurl = input('Enter the url of the home page of the Madrigal site to test:', 's');

cgiurl = getMadrigalCgiUrl(madurl)

'List all instruments, and their latitudes and longitudes:'
instArray = getInstrumentsWeb(cgiurl);
for i = 1:length(instArray)
    [s,errmsg] = sprintf('Instrument: %s, at lat %f and long %f', ...
            instArray(i).name, ...
            instArray(i).latitude, ...
            instArray(i).longitude);
     s
end
% now list all experiments from local Madrigal site with mlh (code 30) in
% 1998 - should be data if default files installed...
startdate = datenum('01/01/1998');
enddate = datenum('12/31/1998');
expArray = getExperimentsWeb(cgiurl, 30, startdate, enddate, 1);
for i = 1:length(expArray)
    [s,errmsg] = sprintf('Experiment name: %s, at url %s', ...
            expArray(i).name, ...
            expArray(i).url);
     s
end

% now list all files in the first experiment
expFileArray = getExperimentFilesWeb(cgiurl, expArray(1).id);
for i = 1:length(expFileArray)
    [s,errmsg] = sprintf('File name: %s, with kindat %i', ...
            expFileArray(i).name, ...
            expFileArray(i).kindat);
     s
end
% now first 2 parameters in the last file
parmArray = getParametersWeb(cgiurl, expFileArray(end).name)
for i = 1:10
    [s,errmsg] = sprintf('Parameter mnemonic: %s, description "%s" -- isMeasured = %i', ...
            parmArray(i).mnemonic, ...
            parmArray(i).description, ...
            parmArray(i).isMeasured);
     s
end
% finally, run isprint for that file for first two parameters
parmStr = sprintf('%s,%s', parmArray(1).mnemonic, parmArray(2).mnemonic);
data = isprintWeb(cgiurl, expFileArray(1).name, parmStr, '');
% print first 10 records
data(:,:,1:10)


Revised: March 9, 2004