1 | PROGRAM testrest |
---|
2 | !- |
---|
3 | !$Id$ |
---|
4 | !--------------------------------------------------------------------- |
---|
5 | !- This program provide a an example of the basic usage of REST. |
---|
6 | !- Here the test the time sampling and averaging. Thus a long |
---|
7 | !- time-series is produced and sampled in different ways. |
---|
8 | !--------------------------------------------------------------------- |
---|
9 | USE ioipsl |
---|
10 | ! |
---|
11 | IMPLICIT NONE |
---|
12 | ! |
---|
13 | INTEGER :: iim,jjm,llm |
---|
14 | PARAMETER (iim=12,jjm=10,llm=2) |
---|
15 | ! |
---|
16 | REAL :: champ1(iim,jjm,llm),champ2(iim,jjm,llm+1),champ3(iim,jjm,llm) |
---|
17 | REAL :: champ4(iim,jjm) |
---|
18 | REAL :: champ_read(iim,jjm,llm) |
---|
19 | REAL :: lon(iim,jjm),lat(iim,jjm),lev(llm) |
---|
20 | ! |
---|
21 | INTEGER :: i,j,l,fid |
---|
22 | INTEGER :: day=1,month=1,year=1997,itau=1 |
---|
23 | ! |
---|
24 | REAL :: julday,un_mois,un_an |
---|
25 | REAL :: deltat=86400,dt_wrt,dt_op,dt_wrt2,dt_op2 |
---|
26 | CHARACTER*20 :: fnamein,fnameout |
---|
27 | ! |
---|
28 | REAL :: pi=3.1415 |
---|
29 | !--------------------------------------------------------------------- |
---|
30 | !- |
---|
31 | ! 0.0 Choose a gregorian calendar |
---|
32 | !- |
---|
33 | CALL ioconf_calendar ('gregorian') |
---|
34 | !- |
---|
35 | ! 1.0 Define a few variables we will need. |
---|
36 | ! These are the coordinates the file name and the date. |
---|
37 | !- |
---|
38 | DO i=1,iim |
---|
39 | DO j=1,jjm |
---|
40 | lon(i,j) = & |
---|
41 | & ((float(iim/2)+0.5)-float(i))*pi/float(iim/2)*(-1.)*180./pi |
---|
42 | lat(i,j) = & |
---|
43 | & (180./pi)*ASIN(((float(jjm/2)+0.5)-float(j))/float(jjm/2)) |
---|
44 | ENDDO |
---|
45 | ENDDO |
---|
46 | !- |
---|
47 | DO l=1,llm |
---|
48 | lev(l) = float(l)/llm |
---|
49 | ENDDO |
---|
50 | !- |
---|
51 | ! 1.1 The chosen date is 15 Feb. 1997 as stated above. It has to be |
---|
52 | ! transformed into julian days using the calendar provided by |
---|
53 | ! IOIPSL. |
---|
54 | !- |
---|
55 | CALL ymds2ju (year,month,day,0.,julday) |
---|
56 | CALL ioget_calendar (un_an) |
---|
57 | un_mois = un_an/12. |
---|
58 | dt_wrt = un_mois*deltat |
---|
59 | dt_op = deltat |
---|
60 | dt_wrt2 = -1. |
---|
61 | dt_op2 = deltat |
---|
62 | !- |
---|
63 | fnamein = 'NONE' |
---|
64 | fnameout = 'restfile' |
---|
65 | !- |
---|
66 | ! 2.0 Create a restart file from nothing ! |
---|
67 | !- |
---|
68 | CALL restini (fnamein,iim,jjm,lon,lat,llm,lev,fnameout, & |
---|
69 | & itau,julday,deltat,fid) |
---|
70 | !- |
---|
71 | champ1(:,:,:) = ASIN(1.0) |
---|
72 | champ2(:,:,:) = EXP(ASIN(1.0)) |
---|
73 | !- |
---|
74 | CALL ioconf_setatt ('units','1') |
---|
75 | CALL ioconf_setatt ('long_name','Tests 1 for a real variable') |
---|
76 | CALL restput (fid,'test1',iim,jjm,llm,itau,champ1) |
---|
77 | !- |
---|
78 | CALL ioconf_setatt ('units','1') |
---|
79 | CALL ioconf_setatt ('long_name','Tests 2 for a real variable') |
---|
80 | CALL restput (fid,'test2',iim,jjm,llm+1,itau,champ2) |
---|
81 | !- |
---|
82 | CALL restclo () |
---|
83 | !- |
---|
84 | WRITE(*,*) '============== FIRST FILE CLOSED ==============' |
---|
85 | !- |
---|
86 | ! 3.0 Reopen the restart file and check that the values read are correct |
---|
87 | !- |
---|
88 | fnamein = 'restfile' |
---|
89 | fnameout = 'restfilebis' |
---|
90 | !- |
---|
91 | CALL restini (fnamein,iim,jjm,lon,lat,llm,lev,fnameout, & |
---|
92 | & itau,julday,deltat,fid) |
---|
93 | !- |
---|
94 | CALL restget (fid,'test1',iim,jjm,llm,itau,.FALSE.,champ_read) |
---|
95 | !- |
---|
96 | itau = itau+10 |
---|
97 | CALL restput (fid,'test1',iim,jjm,llm,itau,champ_read) |
---|
98 | CALL restput (fid,'test2',iim,jjm,llm+1,itau,champ2) |
---|
99 | !- |
---|
100 | itau = itau+10 |
---|
101 | champ3(:,:,:) = champ_read(:,:,:)+champ2(:,:,1:llm) |
---|
102 | CALL restput (fid,'test1',iim,jjm,llm,itau,champ3) |
---|
103 | !- |
---|
104 | CALL restclo () |
---|
105 | !- |
---|
106 | WRITE(*,'(a25,e36.30)') 'The input data : ',champ1(1,1,1) |
---|
107 | WRITE(*,'(a25,e36.30)') 'The restart data : ',champ_read(1,1,1) |
---|
108 | !- |
---|
109 | ! 4.0 Reopen the restart file and add another time step |
---|
110 | !- |
---|
111 | fnamein = 'restfilebis' |
---|
112 | fnameout = 'restfilebis' |
---|
113 | !- |
---|
114 | CALL restini (fnamein,iim,jjm,lon,lat,llm,lev,fnameout, & |
---|
115 | & itau,julday,deltat,fid) |
---|
116 | !- |
---|
117 | itau = itau+10 |
---|
118 | CALL restput (fid,'test1',iim,jjm,llm,itau,champ1) |
---|
119 | CALL ioconf_setatt ('units','1') |
---|
120 | CALL ioconf_setatt ('long_name', & |
---|
121 | & 'Test a variable with another dimension') |
---|
122 | CALL restput (fid,'test4',iim,jjm,0,itau,champ4) |
---|
123 | !- |
---|
124 | CALL restclo () |
---|
125 | !------------------- |
---|
126 | END PROGRAM testrest |
---|