File mttroot/mtt/bin/trans/name2index artifact f7933c91d6 part of check-in ba3f371abd


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: name2index

# Converts names to array index

# Copyright (c) P.J.Gawthrop, 1997.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.5  2000/11/27 18:06:33  peterg
## *** empty log message ***
##
## Revision 1.4  1997/12/04 22:10:18  peterg
## Handles argument list - variable names.
##
## Revision 1.3  1997/05/22 09:42:48  peterg
## Returns 0 if no names.
##
## Revision 1.2  1997/05/22 09:28:22  peterg
## Removed trailing , in output.
##
## Revision 1.1  1997/05/22 08:48:21  peterg
## Initial revision
##
###############################################################

gawk '
{
  name_index[$4]=$2;
}
END{
  M=split(names,xynames,":");
  if (M==0)
    printf("0\n")
  else
    {
    if (M==1) 
      printf("1,");
    else {  
        printf("%i,",name_index[xynames[1]]+1);
        names=xynames[2]
       }

    N=split(names,Names,",");
    for (i=1; i<N; i++)
      printf("%i,",name_index[Names[i]]+1);
  printf("%i\n",name_index[Names[N]]+1);
  }
}'  names=$2 < $1_struc.txt

  


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]