1 | MODULE nb_time_step_PCM_mod |
---|
2 | |
---|
3 | use netcdf, only: nf90_open, NF90_NOWRITE, nf90_noerr, nf90_strerror, & |
---|
4 | nf90_get_var, nf90_inq_varid, nf90_inq_dimid, & |
---|
5 | nf90_inquire_dimension, nf90_close |
---|
6 | |
---|
7 | implicit none |
---|
8 | |
---|
9 | character(256) :: msg, var, modname |
---|
10 | |
---|
11 | !======================================================================= |
---|
12 | contains |
---|
13 | !======================================================================= |
---|
14 | |
---|
15 | SUBROUTINE nb_time_step_PCM(fichnom,timelen) |
---|
16 | |
---|
17 | implicit none |
---|
18 | |
---|
19 | !======================================================================= |
---|
20 | ! |
---|
21 | ! Purpose: Read in the data_PCM_Y*.nc the number of time steps |
---|
22 | ! |
---|
23 | ! Author: RV |
---|
24 | !======================================================================= |
---|
25 | |
---|
26 | include "dimensions.h" |
---|
27 | |
---|
28 | !======================================================================= |
---|
29 | ! Arguments: |
---|
30 | character(len = *), intent(in) :: fichnom !--- FILE NAME |
---|
31 | !======================================================================= |
---|
32 | ! Local Variables |
---|
33 | integer :: fID, vID, ierr |
---|
34 | integer :: timelen ! number of times stored in the file |
---|
35 | !----------------------------------------------------------------------- |
---|
36 | modname = "nb_time_step_PCM" |
---|
37 | |
---|
38 | ! Open initial state NetCDF file |
---|
39 | var = fichnom |
---|
40 | call error_msg(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var) |
---|
41 | |
---|
42 | ierr = nf90_inq_varid (fID, "temps", vID) |
---|
43 | if (ierr /= nf90_noerr) then |
---|
44 | write(*,*)"read_data_PCM: Le champ <temps> est absent" |
---|
45 | write(*,*)"read_data_PCM: J essaie <time_counter>" |
---|
46 | ierr = nf90_inq_varid (fID, "time_counter", vID) |
---|
47 | if (ierr /= nf90_noerr) then |
---|
48 | write(*,*)"read_data_PCM: Le champ <time_counter> est absent" |
---|
49 | write(*,*)"read_data_PCM: J essaie <Time>" |
---|
50 | ierr = nf90_inq_varid (fID, "Time", vID) |
---|
51 | if (ierr /= nf90_noerr) then |
---|
52 | write(*,*)"read_data_PCM: Le champ <Time> est absent" |
---|
53 | write(*,*)trim(nf90_strerror(ierr)) |
---|
54 | call abort_gcm("nb_time_step_PCM", "", 1) |
---|
55 | endif |
---|
56 | ! Get the length of the "Time" dimension |
---|
57 | ierr = nf90_inq_dimid(fID,"Time",vID) |
---|
58 | ierr = nf90_inquire_dimension(fID,vID,len = timelen) |
---|
59 | else |
---|
60 | ! Get the length of the "time_counter" dimension |
---|
61 | ierr = nf90_inq_dimid(fID,"time_counter",vID) |
---|
62 | ierr = nf90_inquire_dimension(fID,vID,len = timelen) |
---|
63 | endif |
---|
64 | else |
---|
65 | ! Get the length of the "temps" dimension |
---|
66 | ierr = nf90_inq_dimid(fID,"temps",vID) |
---|
67 | ierr = nf90_inquire_dimension(fID,vID,len = timelen) |
---|
68 | endif |
---|
69 | |
---|
70 | call error_msg(NF90_CLOSE(fID),"close",fichnom) |
---|
71 | |
---|
72 | write(*,*) "The number of timestep of the PCM run data=", timelen |
---|
73 | |
---|
74 | END SUBROUTINE nb_time_step_PCM |
---|
75 | |
---|
76 | !======================================================================= |
---|
77 | |
---|
78 | SUBROUTINE error_msg(ierr,typ,nam) |
---|
79 | |
---|
80 | implicit none |
---|
81 | |
---|
82 | integer, intent(in) :: ierr !--- NetCDF ERROR CODE |
---|
83 | character(len = *), intent(in) :: typ !--- TYPE OF OPERATION |
---|
84 | character(len = *), intent(in) :: nam !--- FIELD/FILE NAME |
---|
85 | |
---|
86 | if (ierr == nf90_noerr) return |
---|
87 | select case(typ) |
---|
88 | case('inq'); msg = "Field <"//trim(nam)//"> is missing" |
---|
89 | case('get'); msg = "Reading failed for <"//trim(nam)//">" |
---|
90 | case('open'); msg = "File opening failed for <"//trim(nam)//">" |
---|
91 | case('close'); msg = "File closing failed for <"//trim(nam)//">" |
---|
92 | case default |
---|
93 | write(*,*) 'There is no message for this error.' |
---|
94 | error stop |
---|
95 | end select |
---|
96 | call abort_gcm(trim(modname),trim(msg),ierr) |
---|
97 | |
---|
98 | END SUBROUTINE error_msg |
---|
99 | |
---|
100 | END MODULE nb_time_step_PCM_mod |
---|