25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.4 Gestione dei file ad accesso diretto 439<br />

DO i=1,number_of_reads<br />

CALL RANDOM_NUMBER(values)<br />

irec = (max_records-1)*value+1<br />

READ(11,REC=irec) values<br />

END DO<br />

CALL CPU_TIME(time_end)<br />

time_unf = time_end-time_begin<br />

! Processing dei record formattati<br />

CALL CPU_TIME(time_begin)<br />

DO i = 1, number_of_reads<br />

CALL RANDOM_NUMBER(value)<br />

irec = INT((max_records-1)*value)+1<br />

READ(12,"(4ES20.14)",REC=irec) values<br />

END DO<br />

CALL CPU_TIME(time_end)<br />

time_fmt = time_end-time_begin<br />

! Output dei risultati<br />

WRITE(*,*)<br />

WRITE(*,"(A,F6.2)") "Tempo speso sul file non formattato: ", time_unf<br />

WRITE(*,"(A,F6.2)") "Tempo speso sul file formattato: ", time_fmt<br />

STOP<br />

END PROGRAM accesso_diretto<br />

Compilato con l’Intel <strong>Fortran</strong> Compiler 5.0 ed eseguito su un PC Pentium III, il precedente<br />

programma produce questo output:<br />

Lunghezza dei record non formattati: 32<br />

Lunghezza dei record non formattati: 80<br />

Tempo speso sul file non formattato: 0.94<br />

Tempo speso sul file formattato: 1.97<br />

Come si può notare le operazioni svolte sui file non formattate sono state notevolmente più<br />

rapide. Non solo; se infatti si vanno ad analizzare i file prodotti in uscita si nota subito un’altra<br />

importante caratteristica: i file non formattati occupano anche meno spazio su disco. Infatti<br />

questo è il contenuto della directory di uscita dopo l’esecuzione del file:<br />

C:\MYPROG\OUT>dir<br />

<strong>Il</strong> volume nell’unità C non ha etichetta.<br />

Numero di serie del volume: E85E-5D71<br />

Directory di C:\MYPROG\OUT<br />

16/12/2001 18.27 .<br />

16/12/2001 18.27 ..

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!