test.pl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/perl -w
  2. use strict;
  3. # g.parser demo script
  4. #%Module
  5. #% description: g.parser test script (perl)
  6. #% keywords: keyword1, keyword2
  7. #%End
  8. #%flag
  9. #% key: f
  10. #% description: A flag
  11. #%end
  12. #%option
  13. #% key: raster
  14. #% type: string
  15. #% gisprompt: old,cell,raster
  16. #% description: Raster input map
  17. #% required : yes
  18. #%end
  19. #%option
  20. #% key: vector
  21. #% type: string
  22. #% gisprompt: old,vector,vector
  23. #% description: Vector input map
  24. #% required : yes
  25. #%end
  26. #%option
  27. #% key: option1
  28. #% type: string
  29. #% description: An option
  30. #% required : yes
  31. #%end
  32. if ( !$ENV{'GISBASE'} ) {
  33. printf(STDERR "You must be in GRASS GIS to run this program.\n");
  34. exit 1;
  35. }
  36. if( $ARGV[0] ne '@ARGS_PARSED@' ){
  37. my $arg = "";
  38. for (my $i=0; $i < @ARGV;$i++) {
  39. $arg .= " $ARGV[$i] ";
  40. }
  41. system("$ENV{GISBASE}/bin/g.parser $0 $arg");
  42. exit;
  43. }
  44. #add your code here
  45. print "\n";
  46. if ( $ENV{'GIS_FLAG_F'} eq "1" ){
  47. print "Flag -f set\n"
  48. }
  49. else {
  50. print "Flag -f not set\n"
  51. }
  52. printf ("Value of GIS_OPT_option1: '%s'\n", $ENV{'GIS_OPT_OPTION1'});
  53. printf ("Value of GIS_OPT_raster: '%s'\n", $ENV{'GIS_OPT_RASTER'});
  54. printf ("Value of GIS_OPT_vect: '%s'\n", $ENV{'GIS_OPT_VECTOR'});
  55. #end of your code