#!/usr/bin/perl

  if(! defined($ENV{NETCDF_INC})){
    print"Error: environment variable NETCDF_INC not defined. \n";
    exit(0);
  }
  if(! defined($ENV{NETCDF_LIB})){
    print"Error: environment variable NETCDF_LIB not defined. \n";
    exit(0);
  }
  if(-e macros) {system (rm -f macros);}
  if(-e Makefile) {system "rm -f Makefile" ;}

  system("cp arc/Makefile ."); 

#  if((! (-d "Main")) && (-d "HRLDAS") ) {system "cp -r HRLDAS_cpl Main";}

  if($#ARGV == 0) {
     $response = shift(@ARGV) ;
     print("Configure hydro: $response \n");
  }else {
     print "Please select from following supported options. \n\n";

     print "   1. Linux PGI compiler sequential \n";
     print "   2. Linux PGI compiler mpp \n";
     print "   3. IBM AIX compiler sequential, xlf90_r\n";
     print "   4. IBM AIX compiler mpp \n";
     print "   5. Linux gfort compiler sequential \n";
     print "   0. exit only \n";

     printf "\nEnter selection [%d-%d] : ",1,5 ;

     $response = <STDIN> ;
     chop($response);
  }

  use Switch;
  switch ($response) {
     case 1 { 
              # sequential linux 
              system "cp arc/macros.seq.linux macros"; 
              system "cp arc/Makefile.seq Makefile.comm"; 
            }

     case 2 {
              # mpp linux 
              system "cp arc/macros.mpp.linux macros"; 
              system "cp arc/Makefile.mpp Makefile.comm"; 
            }

     case 3 {
              # sequential IBM AIX
              system "cp arc/macros.seq.IBM.xlf90_r macros"; 
              system "cp arc/Makefile.seq Makefile.comm"; 
            }

     case 4 {
              # mpp IBM AIX
              system "cp arc/macros.mpp.IBM.xlf90_r macros"; 
              system "cp arc/Makefile.mpp Makefile.comm"; 
            }

     case 5 {
              # GFORTRAN only                         
              system "cp arc/macros.seq.gfort.f90 macros"; 
              system "cp arc/Makefile.seq Makefile.comm"; 
            }

     else   {print "no selection $response\n"; last} 
  }
  if(! (-e lib)) {mkdir lib;}
  if(! (-e mod)) {mkdir mod;}
  if((-d "HRLDAS") ) {system "cat macros HRLDAS/user_build_options.bak  > HRLDAS/user_build_options";}
