program count c Prints out a chronological list for each week of what backups are c kept in what folders. In particular, the age in weeks will be c listed for the backups in folders 1/, 2/, 3/, ... c If you do daily "backup auto" backups, instead of say "backup 7" c ones, and parameter n1 is at the default value Z, then replace c "week" above and below with "month". c Usage: Set the n-values, taken from the backup script, in the data c statement below, using 0 for n1 and -1 for the final n-values that c are left blank in the script. Compile and run the program using a c fortran compiler, like maybe gfortran: c gfortran -o count count.f c ./count c The output will show the full backup kept in each folder 1/, 2/, c 3/, ... Backups are numbered consecutively, so the backup number c gives the time that the backup was made in terms of weeks since c backups started. The output will also show the current age of the c backup in weeks. c n values integer n(9) c n(1) must be 0, values cannot exceed 9 in this program, -1 for none data n/0,0,1,2,3,4,5,-1,-1/ c backup IDs, being variable base numbers character*9 cnum(9),cnumnw c number of nonblank n-values (number of folders) (digits in the backup ID) integer imax c directory for which to drop the backup to make room for the new one integer idrop c output line count for paging integer lct c number of lines in a typical terminal integer lctmax parameter (lctmax=22) c generic indices integer i,i2 c number of weeks since backups started (the number of the backup in 1/) integer ict c answer character*1 ans c evaluation function integer eval external eval c initialize the backup IDs and the number of folders imax=0 do 10 i=1,9 cnum(i)=' ' cnum(1)(10-i:10-i)='0' if(n(i).lt.0)goto 10 if(imax.ne.i-1)then print*,'*** nonblank n value cannot follow a blank one' stop endif imax=i 10 continue c print the first header print1960,' Folder:',(i,i=1,imax) print1970,' used n:',' ',('n',i,n(i),i=2,imax) print1980,('-',i=1,8+10*imax) lct=3 c loop over the weeks since backups started 1000 continue c increment the ID cnum(1) to get the ID cnumnw for the new backup cnumnw=cnum(1) do 1100 i=1,imax i2=10-i if(ichar(cnumnw(i2:i2))-48.lt.n(i))then cnumnw(i2:i2)=char(ichar(cnumnw(i2:i2))+1) goto 1110 endif cnumnw(i2:i2)='0' 1100 continue c increment an invisible leading digit to avoid number wrap over to zero i2=i2-1 if(i2.lt.1)stop if(cnumnw(i2:i2).ge.'9')stop cnumnw(i2:i2)=char(ichar(cnumnw(i2:i2))+1) 1110 continue c find a folder for which to drop the backup to make space for the new one do 1200 i=1,imax-1 i2=10-i-1 if(cnum(i)(i2:i2).eq.'0')goto 1200 idrop=i goto 1210 1200 continue idrop=imax 1210 continue c move the backups, dropping the one in folder idrop/ do 1300 i=idrop-1,1,-1 cnum(i+1)=cnum(i) 1300 continue c put the new backup in folder 1/ cnum(1)=cnumnw c find out how many folders are not empty do 1905 i=imax,1,-1 i2=i if(cnum(i).ne.' ')goto 1906 1905 continue 1906 continue c print out the contents of the folders print1910,'File ID:',(cnum(i)(10-imax:9),i=1,i2) 1910 format(a8,9a10) print1920,' number:',(eval(cnum(i),n),i=1,i2) 1920 format(a8,9i10) ict=eval(cnum(1),n) print1920,' age:',(ict-eval(cnum(i),n),i=1,i2) lct=lct+3 c ask user to press Enter before printing the next screen if(lct+4.gt.lctmax)then print1930 1930 format('Press Enter to continue: ',$) read1940,ans 1940 format(a1) if(ans.eq.'q')stop if(ans.eq.'e')stop lct=lct+1 do 1950 i=1,lctmax-lct print1920 1950 continue print1960,' Folder:',(i,i=1,imax) 1960 format(a8,i7,'/',i9,'/',i9,'/',i9,'/',i9,'/', & i9,'/',i9,'/',i9,'/',i9,'/') print1970,' used n:',' ',('n',i,n(i),i=2,imax) 1970 format(a8,a9,a7,i1,'=',i1,a7,i1,'=',i1,a7,i1,'=',i1, & a7,i1,'=',i1,a7,i1,'=',i1,a7,i1,'=',i1,a7,i1,'=',i1, & a7,i1,'=',i1) print1980,('-',i=1,8+10*imax) 1980 format(100a1) lct=3 endif c go print out the next week goto 1000 stop end integer function eval(cnum,n) c evaluate a variable base number implicit none c variable base number as string character*9 cnum c limits, n(1) must be 0, values cannot exceed 9 at this time. integer n(9) c index integer i c multiplier integer mul eval=0 mul=1 do 100 i=1,9 if(cnum(10-i:10-i).eq.' ')return eval=eval+(ichar(cnum(10-i:10-i))-48)*mul if(n(i).lt.0)return mul=mul*(n(i)+1) 100 continue return end