Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Patricia Estrada
- // Assignment 1
- // CS780
- //
- // This is a simple disk simulator which accepts a set of basic
- // parameters and prints them. computes some derived parameters,
- // and repeatedly accept transfer requests, calculating things about
- // each set and outputting them.
- #include <stdio.h>
- #include <math.h>
- void outputBasic(double value, char* label, char* unit);
- void calculateDerivedParameters();
- void outputDerivedParameters();
- //basic parameters//////////////////
- double sectorSize = 0;
- double sectorsPerTrack = 0;
- double tracksPerCylinder = 0;
- double cylindersPerDisk = 0;
- double spindleSpeed = 0;
- float averageSeekTime = 0;
- float singleHeadSwitchTime = 0;
- float singleCylinderSwitchTime = 0;
- //derived parameters////////////
- double trackSize = 0;
- double cylinderSize = 0;
- double diskSize = 0;
- double diskSizeGig = 0;
- double sectorsPerCylinder = 0;
- double sectorsPerDisk = 0;
- double fullLatencyTime = 0;
- double averageLatencyTime = 0;
- double effectiveDataTransferRate = 0;
- double singleByteTransferTime = 0;
- double sectorTransferTime = 0;
- double headSkew = 0;
- double cylinderSkew = 0;
- int main ( int argc, char *argv[] )
- {
- char label[50];
- char unit[10];
- if ( argc != 2 )
- {
- printf( "usage: %s filename", argv[0] );
- }
- else
- {
- FILE *file = fopen( argv[1], "r" );
- if ( file == 0 )
- {
- printf( "Failure in opening file\n" );
- }
- else
- {
- int tempSize = 0;
- fscanf(file, "%d %s %s", &tempSize, label, unit);
- outputBasic(sectorSize, label, unit);
- sectorSize = tempSize;
- fscanf(file, "%d %s %s", &tempSize, label, unit);
- outputBasic(sectorsPerTrack, label, unit);
- sectorsPerTrack = tempSize;
- fscanf(file, "%d %s %s", &tracksPerCylinder, label, unit);
- outputBasic(tracksPerCylinder, label, unit);
- fscanf(file, "%d %s %s", &cylindersPerDisk, label, unit);
- outputBasic(cylindersPerDisk, label, unit);
- fscanf(file, "%d %s %s", &spindleSpeed, label, unit);
- outputBasic(spindleSpeed, label, unit);
- fscanf(file, "%f %s %s", &averageSeekTime, label, unit);
- fprintf(stdout, "%s in %s: %f\n", label, unit, averageSeekTime);
- fscanf(file, "%f %s %s", &singleHeadSwitchTime, label, unit);
- fprintf(stdout, "%s in %s: %f\n", label, unit, singleHeadSwitchTime);
- fscanf(file, "%f %s %s", &singleCylinderSwitchTime, label, unit);
- fprintf(stdout, "%s in %s: %f\n", label, unit, singleCylinderSwitchTime);
- trackSize = sectorSize * sectorsPerTrack;
- fprintf(stdout, "\ntemp2: %d\n", trackSize);
- calculateDerivedParameters();
- outputDerivedParameters();
- fclose( file );
- }
- }
- }
- void outputBasic(double value, char* label, char* unit)
- {
- fprintf(stdout, "%s in %s: %d\n", label, unit, value);
- }
- void calculateDerivedParameters()
- {
- trackSize = sectorSize * sectorsPerTrack;
- fprintf(stdout, "\ntemp: %d\n", sectorSize);
- fprintf(stdout, "\ntemp: %d\n", sectorsPerTrack);
- fprintf(stdout, "\ntemp2: %f\n", trackSize);
- fprintf(stdout, "\ntemp2: %d\n", trackSize);
- double temp = sectorSize;
- double temp2 = sectorsPerTrack;
- trackSize = temp * temp2;
- fprintf(stdout, "\ntemp3: %f\n", trackSize);
- cylinderSize = trackSize * tracksPerCylinder;
- diskSize = cylinderSize * cylindersPerDisk;
- diskSizeGig = diskSize/1000000000;
- sectorsPerCylinder = sectorsPerTrack * tracksPerCylinder;
- sectorsPerDisk = sectorsPerCylinder * cylindersPerDisk;
- fullLatencyTime = 1/spindleSpeed * 60;
- averageLatencyTime = fullLatencyTime/2;
- effectiveDataTransferRate = trackSize/fullLatencyTime;
- singleByteTransferTime = 1/effectiveDataTransferRate;
- sectorTransferTime = sectorSize/effectiveDataTransferRate;
- ceil(singleHeadSwitchTime/sectorTransferTime);
- ceil(singleCylinderSwitchTime/sectorTransferTime);
- }
- void outputDerivedParameters()
- {
- fprintf(stdout, "\nDerived Parameters\n");
- fprintf(stdout, "%s in %s: %f\n", "track_size", "bytes", trackSize);
- fprintf(stdout, "%s in %s: %d\n", "cylinder_size", "bytes", cylinderSize);
- fprintf(stdout, "%s in %s: %d\n", "disk_size", "bytes", diskSize);
- fprintf(stdout, "%s in %s: %d\n", "disk_size", "gigabytes", diskSizeGig);
- fprintf(stdout, "%s in %s: %d\n", "sectors_per_cylinder", "sectors", sectorsPerCylinder);
- fprintf(stdout, "%s in %s: %d\n", "sectors_per_disk", "sectors", sectorsPerDisk);
- fprintf(stdout, "%s in %s: %d\n", "full_latency_time", "msec", fullLatencyTime);
- fprintf(stdout, "%s in %s: %d\n", "average_latency_time", "msec", averageLatencyTime);
- fprintf(stdout, "%s in %s: %d\n", "effective_data_transfer_rate", "megabytes per second", effectiveDataTransferRate);
- fprintf(stdout, "%s in %s: %d\n", "single_byte_transfer_time", "msec", singleByteTransferTime);
- fprintf(stdout, "%s in %s: %d\n", "sector_transfer_time", "msec", sectorTransferTime);
- fprintf(stdout, "%s in %s: %d\n", "head_skew", "sectors", headSkew);
- fprintf(stdout, "%s in %s: %d\n", "cylinder_skew", "sectors", cylinderSkew);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement