#This awk program is the first part of a system to translate
#files in the DIMACS .min format to ones readable by Helgassen 
#and Kennington's NETFLO program.  
#It does no error checking. 

$1 == "c" { #ignore comment lines 
	}

$1 == "p"  {prob = $2;  nodes = $3; arcs = $4;
	    print "a", nodes  
	}

$1 == "n"  {name = $2; demand = $3;
	    print "b", name, demand 
	}

$1 == "a"  {from = $2; to =$3; low=$4; cap=$5; cost=$6; 
	    acount++;

	    if (cap == -1) cap = 0;
            else if (cap == 0) cap = -1;

            print "e", acount, from, to, cost, cap, low;  
	
		incident[to]++;
	}	

END     { for (i = 1; i <= nodes; i++) {
		if (1== (i % 8) ) printf("d ");    #start new line 
		printf("%10d",incident[i]);
		if (0== (i % 8) ) printf("\n");    #terminate line
	   } 
          #finish last line 
          while (0 != (i % 8)) {printf("%10d", 0); i++;}
	  printf("\n");
	  
 	  # add zero lines
	  print "c\n"; 
          print "f\n" ; 
	}
	 
	   
