next up previous contents
Next: BASE ROUTINES AND FILES Up: specifications Previous: QUICK REFERENCE

Subsections


EXAMPLES

C Language

This chapter contains and example of components of a C language code which a typical user might write to integrate with an existing application or to form the basis for a new one. We will walk through this code.

[frame=single]
#include <stdlib.h>

#include <stdio.h>
#include <string.h>

// include GROWL header
#include "growl.h"

int main(int argc, char **argv) { 
  char *sessionId;
  char *response;
  int res;

// start at GROWL session with a Grid proxy credential
  {
    printf("***** Testing old session key *****\n");
    char uid[]="myusername";
    char passPhrase[]="mypasswd";
    int ttl=2; 
    char oldId[]="f6a6d3fe-1b36-4131-8dbe-dd29a5c483c5";
    res = growl_testDelegation(oldId, &sessionId);
    printf("Got new session key %s\n", sessionId);
    if(strcmp(oldId,sessionId)) {
      strcpy(oldId, sessionId);
      printf("***** Need to renew session *****\n");
      res = growl_getDelegation(uid, passPhrase, ttl, oldId, &sessionId);
    } else 
      printf("***** Existing session still OK *****\n");
  }

// transfer a file
  {
    char *source="grid2.rl.ac.uk";
    char *sname="/home/rja/GROWL/Test/data/myinput.dat";
    char *target="tyne.dl.ac.uk";
    char *tname="/tmp/input.dat";

    printf("***** Transfering a file *****\n");
    res = growl_gridFTP(sessionId, source, sname, target, tname,
			&response);
    printf("Service returned: %s\n", response);
  }

// submit a remote Grid job
  {
    char *target="tyne.dl.ac.uk";
    char *directory="/tmp";
    char *environment="";
    char *executable="/bin/ls";
    char *arguments="input.dat";

    printf("***** Running a remote job *****\n");
    res = growl_runClient(sessionId, target, directory, environment, 
			  executable, arguments, &response);
    printf("Service returned: %s\n", response);
  }

// tidy up
  free(sessionId); free(response);
  return 0;
}

A very simple makefile for such a program is as follows:

[frame=single]
LDIR = -L $(GROWL)/lib
LIBS = -lgrowl
INCL = -I $(GROWl)/include

all:	TEST

TEST: test.c
        gcc -c test.c $(INCL)
	gcc -o TEST -dynamic test.o $(LDIR) $(LIBS)

The code illustrates a very simple-to-use interface to the GROWL library and eventual Grid resources.

Fortran

[frame=single]
Fortran example

R language

[frame=single]
library(GROWL)
restore.session()
string=''help.search('packages')''
rCommand(string,'a','b')
etc()
save.session()
q()



Rob Allan
2006-02-10