File merging based on different counter loop

hello,

File 1

main Group            sub group
    MIT               VAR_1D_DATA_TYPE      23-03-2012
    MIT               VAR_1D_DATA_TYPE      22-03-2012

   MIT              VAR_10D_DATA_TYPE      23-03-2012
   MIT              VAR_10D_DATA_TYPE      22-03-2012

   MIT      STRESSED_VAR_1D_DATA_TYPE      23-03-2012
   MIT      STRESSED_VAR_1D_DATA_TYPE      22-03-2012

   MIT     STRESSED_VAR_10D_DATA_TYPE      23-03-2012
   MIT     STRESSED_VAR_10D_DATA_TYPE      22-03-2012

   ISS               CB_VAR_DATA_TYPE      23-03-2012
   ISS               CB_VAR_DATA_TYPE      22-03-2012

file 2

index		value
0		42379
1		1349
2		234
3		789
4		456
5		7634
6		879
7		5890
8		3210
9		87540
10		65430
11		879
12		2156
13    	658
14		87985
15		896
16		542
17		635

op file

main Group            sub group				index
    MIT               1D_DATA_TYPE      23-03-2012	3
    MIT               1D_DATA_TYPE      22-03-2012	4

   MIT              10D_DATA_TYPE      23-03-2012	6
   MIT              10D_DATA_TYPE      22-03-2012	7

   MIT      STRESSED_1D_DATA_TYPE      23-03-2012	9
   MIT      STRESSED_1D_DATA_TYPE      22-03-2012	10

   MIT     STRESSED_10D_DATA_TYPE      23-03-2012	12
   MIT     STRESSED_10D_DATA_TYPE      22-03-2012	13

   ISS               CB_DATA_TYPE      23-03-2012	16
   ISS               CB_DATA_TYPE      22-03-2012	17

It's a strange requirement ,
first of all, main role are played by individual main groups and sub groups.
here in this example it's 2
and then how many sub groups are there under each main group
here e.g. for MIT there are 4 sub groups are present 1D_DATA_TYPE,10D_DATA_TYPE, STRESSED_1D_DATA_TYPE,STRESSED_10D_DATA_TYPE
similarly for ISS only one sub group is present i.e. CB_DATA_TYPE

so it will now check file 2 for values, I have mentioned index number for more readbility.
index counter always begin from nr.3 then it will check next sub-group, if it is same sub group as well as main group then it increase the index counter next one +1.

if it's new subgroup, then it will check the main group, if it's same then then index counter will increase by +2 from the previous one, and then it will again check for the next subgroup and taking consideration of previous main and sub group.

let say next sub group is a new sub group as well as a new main group then counter will increase by +3 from the previous one. same loop goes thru all over file 1 and corresponding index value will be printed.

e.g. STRESSED_10D_DATA_TYPE index counter is 13 ,
now checks for next sub group found that it's new sub group as well as new main group so the index counter increased to 16. (+3)
let say it found another same STRESSED_10D_DATA_TYPE sub group with same main group then next index would be 14 (+1)
then it encounters CB_DATA_TYPE index for ISS , index would be 17(+3) as previous one was 14.

let say it found another new sub group but main group reamins same, then index counter for that new sub group 15 (+2)
then it encounters CB_DATA_TYPE index for ISS , index would be 18(+3) as previous one was 15.

This rule applied for the whole file1 after the first line indexed.
how can I achieve this one???

have a look on different o/p on different scenario

Scenario 1 o/p

main Group            sub group				index
    MIT               1D_DATA_TYPE      23-03-2012	3
    MIT               1D_DATA_TYPE      22-03-2012	4

   MIT              10D_DATA_TYPE      23-03-2012	6
   MIT              10D_DATA_TYPE      22-03-2012	7

   MIT      STRESSED_1D_DATA_TYPE      23-03-2012	9
   MIT      STRESSED_1D_DATA_TYPE      22-03-2012	10

   MIT     STRESSED_10D_DATA_TYPE      23-03-2012	12
   MIT     STRESSED_10D_DATA_TYPE      22-03-2012	13
   MIT     STRESSED_10D_DATA_TYPE      12-03-2012	14

   ISS               CB_DATA_TYPE      23-03-2012	17
   ISS               CB_DATA_TYPE      22-03-2012	18

scenario 2 o/p

main Group            sub group				index
    MIT               1D_DATA_TYPE      23-03-2012	3
    MIT               1D_DATA_TYPE      22-03-2012	4

   MIT              10D_DATA_TYPE      23-03-2012	6
   MIT              10D_DATA_TYPE      22-03-2012	7

   MIT      STRESSED_1D_DATA_TYPE      23-03-2012	9
   MIT      STRESSED_1D_DATA_TYPE      22-03-2012	10

   MIT     STRESSED_10D_DATA_TYPE      23-03-2012	12
   MIT     STRESSED_10D_DATA_TYPE      22-03-2012	13

   MIT     	    ED_10D_DATA_TYPE      12-03-2012	15

   ISS               CB_DATA_TYPE      23-03-2012	18
   ISS               CB_DATA_TYPE      22-03-2012	19