# source:IOIPSL/trunk/example/testhist1.f90@16

Last change on this file since 16 was 16, checked in by bellier, 17 years ago

• Property svn:keywords set to `Id`
File size: 3.5 KB
Line
1PROGRAM testhist1
2!-
3!\$Id\$
4!---------------------------------------------------------------------
5!- This program provide a an example of the basic usage of HIST.
6!- No secial features are used but just the basics.
7!---------------------------------------------------------------------
8  USE ioipsl
9!
10  IMPLICIT NONE
11!
12  INTEGER,PARAMETER :: iim=96, jjm=96, llm=12, nbreg=200
13!
14  REAL :: champ1(iim,jjm), champ2(iim,jjm,llm), champ3(iim,jjm)
15  REAL :: lon(iim,jjm),lat(iim,jjm), lev(llm)
16  REAL :: lon_test(iim),lat_test(jjm)
17  REAL :: x
18!
19  INTEGER :: i, j, l, id, it, ij, sig_id, hori_id
20  INTEGER :: day=15, month=2, year=1997
21  INTEGER :: itau=0, INDEX(nbreg), start
22!
23  REAL :: julday
24  REAL :: deltat=60., dt_wrt, dt_op
25  CHARACTER(LEN=20) :: histname
26!
27  REAL :: pi=3.1415
28!---------------------------------------------------------------------
29!-
30! 1.0 Define a few variables we will need. These are the coordinates
31!     the file name and the date.
32!-
33  DO i=1,iim
34    DO j=1,jjm
35      lon(i,j) = ((float(iim/2)+0.5)-float(i))*pi/float(iim/2) &
36 &              *(-1.)*180./pi
37      lat(i,j) = 180./pi*ASIN(((float(jjm/2)+0.5)-float(j)) &
38 &              /float(jjm/2))
39    ENDDO
40  ENDDO
41!-
42  lon_test(:) = lon(:,1)
43  lat_test(:) = lat(1,:)
44!-
45  DO l=1,llm
46    lev(l) = REAL(l)/llm
47  ENDDO
48!
49  histname = 'testhist1.nc'
50!-
51! 1.1 The chosen date is 15 Feb. 1997 as stated above.
52!     It has to be transformed into julian days using
53!     the calendar provided by IOIPSL.
54!-
55  CALL ymds2ju(year, month, day, 0.,julday)
56  dt_wrt = 3*deltat
57  dt_op = 3*deltat
58!-
59! 2.0 Do all the declarations for hist. That is define the file,
60!     the vertical coordinate and the variables in the file.
61!-
62  CALL ioconf_modname('testhist1 produced this file')
63!-
64  CALL histbeg (histname,iim,lon_test,jjm,lat_test, &
65 &              1,iim,1,jjm,itau,julday,deltat,hori_id,id)
66!-
67  CALL histvert (id,"sigma","Sigma levels","-",llm,lev,sig_id)
68!-
69  CALL histdef (id,"champ1","Some field","m", &
70 &       iim,jjm,hori_id,1,1,1,-99,32,"inst(scatter(x))",dt_op,dt_wrt)
71!-
72  CALL histdef (id,"champ2","Another field","m", &
73 &       iim,jjm,hori_id,llm,1,llm,sig_id,32,"t_max(max(x,1.0)*2)", &
74 &       deltat,dt_wrt)
75!-
76  CALL histdef (id,"champ3","A field without time","m", &
77 &       iim,jjm,hori_id,1,1,1,-99, 32,"once", &
78 &       deltat,dt_wrt)
79!-
80  CALL histend (id)
81!-
82! 2.1 The filed we are going to write are computes
83!-
84  x = 10.
85  CALL RANDOM_NUMBER(HARVEST=x)
86  CALL RANDOM_NUMBER(champ1)
87  champ3 = champ1
88  DO l=1,llm
89    champ2(:,:,l) = champ1*l
90  ENDDO
91!-
92! 3.0 Start the time steping and write the data as we go along.
93!-
94  start = 1
95!-
96  DO it=1,12
97!---
98!   3.1 In the 2D filed we will have a set of random numbers
99!       which move through the map.
100!---
101    ij = 1
102    DO j=1,nbreg/10
103      DO i=1,10
104        ij = ij+1
105        INDEX(ij) = iim*(j+20)+(i+start)
106      ENDDO
107    ENDDO
108!---
109    IF (start < iim-10) THEN
110      start = start+10
111    ELSE
112      start = 1
113    ENDIF
114!---
115    itau = itau + 1
116!---
117!   3.2 Pass the data to HIST for operation and writing.
118!---
119    CALL histwrite (id,"champ1",itau,champ1,nbreg,index)
120    CALL histwrite (id,"champ2",itau,champ2,iim*jjm*llm,index)
121    CALL histwrite (id,"champ3",itau,champ3,iim*jjm,index)
122    champ1 = champ1+1
123    champ2 = champ2+2
124  ENDDO
125!-
126! 4.0 The HIST routines are ended and netCDF is closed
127!-
128!   CALL histclo
129! This line should work but there seems to be a bug
130! in the optional argument on SUN !
131!-
132  CALL histclo(id)
133!--------------------
134END PROGRAM testhist1
Note: See TracBrowser for help on using the repository browser.