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.

1.5 Istruzioni di assegnazione ed espressioni 41<br />

ans1: "Donald*Duck"<br />

ans2: "Duffy*Duck*"<br />

ans3: "DuckDuckDuc"<br />

in cui, come in precedenza, con il simbolo ”*” si è voluto indicare graficamente uno spazio<br />

vuoto.<br />

<strong>Il</strong> seguente programma fornisce un esempio un pò più completo delle possibili applicazioni<br />

degli strumenti di manipolazione delle stringhe di caratteri:<br />

PROGRAM DateTime<br />

IMPLICIT NONE<br />

CHARACTER(LEN=8) :: date ! ccyymmdd<br />

CHARACTER(LEN=4) :: anno<br />

CHARACTER(LEN=2) :: mese, giorno<br />

CHARACTER(LEN=10) :: time ! hhmmss.sss<br />

CHARACTER(LEN=12) :: orario<br />

CHARACTER(LEN=2) :: ore, minuti<br />

CHARACTER(LEN=6) :: secondi<br />

CALL DATE_AND_TIME(date,time)<br />

! decompone la variabile "date" in anno, mese e giorno<br />

! date ha forma ’ccyymmdd’, dove cc = secolo, yy = anno<br />

! mm = mese e dd = giorno<br />

anno = date(1:4)<br />

mese = date(5:6)<br />

giorno = date(7:8)<br />

WRITE(*,*) ’ Data attuale -> ’, date<br />

WRITE(*,*) ’ Anno -> ’, anno<br />

WRITE(*,*) ’ Mese -> ’, mese<br />

WRITE(*,*) ’ Giorno -> ’, giorno<br />

! decompone la variabile "time" in ore, minuti e secondi<br />

! time ha forma ’hhmmss.sss’, dove h = ore, m = minuti<br />

! ed s = secondi<br />

ore = time(1:2)<br />

minuti = time(3:4)<br />

secondi = time(5:10)<br />

orario = ore // ’:’ // minuti // ’:’ // secondi<br />

WRITE(*,*)<br />

WRITE(*,*) ’ Orario attuale -> ’, time<br />

WRITE(*,*) ’ Ore -> ’, ore<br />

WRITE(*,*) ’ Minuti -> ’, minuti<br />

WRITE(*,*) ’ Secondi -> ’, secondi<br />

WRITE(*,*) ’ Orario -> ’, orario<br />

END PROGRAM DateTime<br />

Un possibile output di questo programma potrebbe essere:

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

Saved successfully!

Ooh no, something went wrong!