Subject How to decide when a new secondary file is required

I am attempting the following.
I want to create a database as haveing secondary file. The secondary file is used after first file reaches 2GB.
Once second file is used to store data then I want to add a third secondary file automatically. So user never has to worry there are always enough files to hold all the data.

So every time the last secondary file is used. I want to increase the number of secondary files by one..

How to detect whether Firebird is using only the first file. Or is it using the second, third fourth secondary files etc.

I tried TIBDatabaseInfo from IBServices and retrieved page size and allocation. But there is no clear pattern in what is being retrieved.
As long as it is only one file the page size and allocation which are retrieved and be used to find out the database size.

Once there are more than one file allocation returns some really strange values.

For e.g.
If there is only on file and the actual file size is 1470 KB
Then the number of allocated pages is 736 and the page size is 2048
So 736*(2048 / 1024) gives us total database file size as 1472 KB

This results in ~ correct figure

Suppose there are two files First file size 1026 Kb and second file is 448 for a total of 1026 + 448 = 1474 KB
Then the number of allocated pages is 739 and the page size is 2048
Then total database file size become 1478 KB (739*2049/1024)

These results are also ~ correct

Suppose there are three files. Only the main file and first secondary file has any data. The second secondary file is not used.

That is the file sizes are 1026 KB, 448 KB and 4 KB for a total of 1026 +448 + 4 = 1478 KB
But number of allocated pages is 1026 and the page size is 2048 Hence database size should be 2053 KB
i.e. 1026 *2048/1024

These are crazy results

Any help would be much appreciated

S. Govindkrishna