test.pl 1.1 KB

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