I am workring on a program that can simulate an array of disks and from an event list, record their mean time to failure (mttf), mean time to repair(mttr) and stop the program when it encounters dataloss. so we would also need to record the mean time to data loss (mttdl).

I wrote the following code by converting a perl code into c with help from a friend. in the bottom part of the code you would see ************** beyond that we have all perl code. needs to be done in C. Need to work on the nextevent() function. In the perl code, it is asking for three values- my $thistime, my $thistype, my $thisdisk. I think if we make 2 variables global, we can get $disk. Rest 2 variables are already in the global category. Please note that 'keys' and 'shift' are perl functions working on associative arrays, We have to find a way around those too.All $ variables are perl so it means that code is untouched.

#include <stdio.h>
#include <string.h>
// #include <system.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <sys\timeb.h>


float clock = 0.0; //time
float evtype[10][10]; 
float evdisk[10][10]; 
int duration = 1000000000; //10^9
int status[100]; // array

int losscount = 0;
char type = 'E'; // error code

main()
{
int disk;
float lambda;
float mu, mttdl;
int mttf, mttr;
status[0]=1;
status[1]=1;
// int disk;
printf("Enter disk MTTF (hours): ");
scanf("%d", &mttf);
printf("Enter disk MTTR (hours): ");
scanf("%d", &mttr);

lambda = 1/mttf;
mu = 1/mttr;

printf("Disk failure rate : %f \n", lambda);
printf("Disk repair rate : %f \n", mu);
printf("Simulation duration: %d \n", duration);
/* 
schedule(duration, "X", 2);

schedule(exponential(lambda), "F", 0);

do {
(clock, type, disk) = &nextevent; //needs looking into 
if (type == "F") {
// disk failure
failure(disk);
} elsif (type == "R") {
// disk repair
repair(disk)
} # if-else
} while (type != "X"); // do-while

*/
//closing
printf("SIMULATION RESULTS:\n");
printf("Number of data losses is %d \n", losscount);
mttdl = duration/losscount;
printf("Rough estimate of MTTF is %f \n", mttdl); // end of simulation

// }




failure(failed)
int failed;
{
// extract disk ID
status[failed] = 0;
printf("Disk %d failed at time %f.\n", failed, clock);
// check for data loss
if (status[1 - failed] == 0) {
losscount++;
print("Data loss at time %f.\n", clock);
} // if
schedule(clock + exponential(mu), "R", failed);
} // failure 


\\*************************************************************************


repair(repaired)
int repaired;
{
//(my $repaired) = @_; // extract disk ID
status[repaired] = 1;
printf("Disk %d was repaired at time %d.\n", repaired, clock);
schedule(clock + exponential(lambda), "F", repaired);
} // repair

/*schedule(thistime, thistype, thisdisk)
float thistime;
char thistype;
int thisdisk;
{
//extract three parameters
//(my $thistime, my $thistype, my $thisdisk) = @_;
$evtype{$thistime} = $thistype; //pascal associative array
$evdisk{$thistime} = $thisdisk; //pascal associative array
} // schedule

nextevent() {
int skeys[];
int thattime, thattype, thatdisk;
my @skeys =
sort{$a <=> $b} (keys %evtype);
my $thattime = shift(@skeys);
my $thattype = $evtype{$thattime};
my $thatdisk = $evdisk{$thattime};
delete($evtype{$thattime});
delete($evdisk{$thattime});
($thattime, $thattype, $thatdisk);
} nextevent

exponential() {
(my $rate) = @_;
- log(rand(1))/$rate;
} // exponential

*/

Sure, figuring out how to use code tags would be high on your list.
You were a lot closer than most people manage, but you still didn't make it.

But do you think there is a way I can manage to get what I actually need? Or is there a better way of doing it? Looking forward for some help to finish this off.. thanks!

Probably, but I really couldn't care less until either you or a mod fixes the post so that I can read it without going blind in the process.

I am sorry I dint understand about the 'fixing' part. And if I can, how should I go about fixing it?
thanks again!

Use "[/code]" at the bottom, what is perl code doing ?

Edited 3 Years Ago by Dani: Fixed formatting

Ok. Let me tell you what the whole program intends to do. There is an event list that contains events that would occur at predefined intervals. The events are - disk mean time to failure (m t t f), and disk mean time to repair(m t t r). We should also take care in our program that the repairs should be carried within a specified period of time interval, else it would be a data loss, which we do not want too early to happen in our program. We continue to run these events by taking inputs from the event list for these two events. We intend to run the loop for a possibly large number of iterations i.e failures and repairs, until we encounter disk data loos - i.e we reach a point comes when the disk was not repaired within the specified time and that would indicate a data loss i.e mean time to data loss(m t t d l). And run the program again to simulate using another set of values. The C code posted above might give you an idea as to what we were trying to accomplish.

a) Does the PERL program actually work ?

b) Post your latest C code as it currently stands. Don't forget to use the

tags which everyone mentions, and don't forget to click on "preview post" or "go advanced" to make sure your code looks like this

int main ( ) {
    printf("Hello world\n" );
}

and not like this, like you originally posted.
int main ( ) {
printf("Hello world\n" );
}

c) Post your reference PERL code "as is". That is, without all your attempts to mix in various bits of commented out C, or what have you.

This article has been dead for over six months. Start a new discussion instead.