Changeset 1073
- Timestamp:
- Oct 17, 2013, 4:19:26 PM (11 years ago)
- Location:
- trunk/LMDZ.MARS/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/concatnc.F90
r632 r1073 18 18 ! + handle absence of ap() and bp() if aps and bps are available 19 19 ! (case of stats file) FF, November 2011 20 ! + read and write controle field, if available. TN, October 2013 20 21 ! ******************************************************** 21 22 … … 54 55 ! memolonlen: # of elements of lon(), read from the first input file 55 56 ! memoaltlen: # of elements of alt(), read from the first input file 56 real, dimension(:), allocatable:: lat,lon,alt, time57 real, dimension(:), allocatable:: lat,lon,alt,ctl,time 57 58 ! lat(): array, stores latitude coordinates 58 59 ! lon(): array, stores longitude coordinates 59 60 ! alt(): array, stores altitude coordinates 61 ! ctl(): array, stores controle coordinates 60 62 ! time(): array, stores time coordinates 61 63 integer :: nbvar,nbfile,nbvarfile,ndim … … 64 66 ! nbvarfile: total # of variables in an input file 65 67 ! ndim: [netcdf] # (3 or 4) of dimensions (for variables) 66 integer :: latdim,londim,altdim, timedim68 integer :: latdim,londim,altdim,ctldim,timedim 67 69 ! latdim: [netcdf] "latitude" dim ID 68 70 ! londim: [netcdf] "longitude" dim ID 69 71 ! altdim: [netcdf] "altdim" dim ID 72 ! ctldim: [netcdf] "ctldim" dim ID 70 73 ! timedim: [netcdf] "timedim" dim ID 71 74 integer :: gcmlayerdim ! NetCDF dimension ID for # of layers in GCM 72 integer :: latvar,lonvar,altvar, timevar75 integer :: latvar,lonvar,altvar,ctlvar,timevar 73 76 ! latvar: [netcdf] ID of "latitude" variable 74 77 ! lonvar: [netcdf] ID of "longitude" variable 75 78 ! altvar: [netcdf] ID of "altitude" variable 79 ! ctlvar: [netcdf] ID of "controle" variable 76 80 ! timevar: [netcdf] ID of "Time" variable 77 integer :: latlen,lonlen,altlen, timelen81 integer :: latlen,lonlen,altlen,ctllen,timelen 78 82 ! latlen: # of elements of lat() array 79 83 ! lonlen: # of elements of lon() array 80 ! altvar: # of elements of alt() array 84 ! altlen: # of elements of alt() array 85 ! ctllen: # of elements of ctl() array 81 86 ! timelen: # of elemnets of time() array 82 87 integer :: GCM_layers ! number of GCM atmospheric layers (may not be … … 141 146 !write(*,*) "Beginning day of the first specified file?" 142 147 write(*,*) "Starting day of the run stored in the first input file?" 148 write(*,*) " (Obsolete if the controle field is present, answer any number)" 143 149 write(*,*) "(e.g.: 100 if that run started at time=100 sols)" 144 150 read(*,*) memotime … … 320 326 ! write(*,*) "altlen: ",altlen 321 327 328 ierr=NF_INQ_DIMID(nid,"index",ctldim) 329 ierr=NF_INQ_VARID(nid,"controle",ctlvar) 330 if (ierr.NE.NF_NOERR) then 331 write(*,*) 'Field <controle> is missing in file'//file 332 ctllen=0 333 !stop "" 334 else 335 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen) 336 endif 337 ! write(*,*) "controle: ",controle 338 322 339 ! load size of aps() or sigma() (in case it is not altlen) 323 340 ! default is that GCM_layers=altlen … … 345 362 allocate(lon(lonlen)) 346 363 allocate(alt(altlen)) 364 allocate(ctl(ctllen)) 347 365 #ifdef NC_DOUBLE 348 366 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat) 349 367 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon) 350 368 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt) 369 if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl) 351 370 #else 352 371 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 353 372 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 354 373 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 355 #endif 374 if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 375 #endif 376 if (ctllen .ne. -1) then 377 if (modulo(int(memotime),669)/=modulo(int(ctl(4)),669)) then 378 write(*,'(2(A,I4),A)') "WARNING: Starting day of the run is not ",& 379 modulo(int(memotime),669)," but ",modulo(int(ctl(4)),669),"!!" 380 write(*,*) "Starting day of the run has been corrected." 381 memotime=float(modulo(int(ctl(4)),669)) 382 endif 383 endif 356 384 ! Initialize output file's lat,lon,alt and time dimensions 357 call initiate (filename,lat,lon,alt, GCM_layers,nout,&385 call initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,& 358 386 latdimout,londimout,altdimout,timedimout,& 359 387 layerdimout,interlayerdimout,timevarout) … … 570 598 571 599 !****************************************************************************** 572 subroutine initiate (filename,lat,lon,alt, GCM_layers,nout,&600 subroutine initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,& 573 601 latdimout,londimout,altdimout,timedimout,& 574 602 layerdimout,interlayerdimout,timevarout) … … 596 624 real, dimension(:), intent(in):: alt 597 625 ! alt(): altitude 626 real, dimension(:), intent(in):: ctl 627 ! ctl(): controle 598 628 integer,intent(in) :: GCM_layers ! number of GCM layers 599 629 integer, intent(out):: nout … … 619 649 !integer :: latdim,londim,altdim,timedim 620 650 integer :: nvarid,ierr 651 integer :: ctldimout 621 652 ! nvarid: [netcdf] ID of a variable 622 653 ! ierr: [netcdf] return error code (from called subroutines) … … 640 671 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout) 641 672 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout) 673 if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout) 642 674 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout) 643 675 ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout) … … 681 713 682 714 !============================================================================== 683 ! 4. Write "altitude" (data and attributes)715 ! 5. Write "altitude" (data and attributes) 684 716 !============================================================================== 685 717 … … 704 736 #else 705 737 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 706 #endif 738 #endif 739 740 !============================================================================== 741 ! 6. Write "controle" (data and attributes) 742 !============================================================================== 743 744 if (size(ctl).ne.0) then 745 ! Switch to netcdf define mode 746 ierr = NF_REDEF (nout) 747 748 #ifdef NC_DOUBLE 749 ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid) 750 #else 751 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 752 #endif 753 754 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 755 756 ! End netcdf define mode 757 ierr = NF_ENDDEF(nout) 758 759 #ifdef NC_DOUBLE 760 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl) 761 #else 762 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 763 #endif 764 endif 707 765 708 766 end Subroutine initiate … … 1162 1220 do i=1,timelen-1 1163 1221 if ((ls(i+1)-ls(i)) > 350) then 1164 write(*,*) "+ 360 °Ls jump solved:", ls(i), ls(i+1), "at timestep", i1222 write(*,*) "+ 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i 1165 1223 ls(i+1) = ls(i+1) - 360 1166 1224 write(*,*) " corrected to now be:", ls(i), ls(i+1) 1167 1225 else if ((ls(i)-ls(i+1)) > 350) then 1168 write(*,*) "- 360 °Ls jump solved:", ls(i), ls(i+1), "at timestep", i1226 write(*,*) "- 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i 1169 1227 ls(i+1) = ls(i+1) + 360 1170 1228 write(*,*) " corrected to now be:", ls(i), ls(i+1) -
trunk/LMDZ.MARS/util/localtime.F90
r410 r1073 35 35 integer :: varid 36 36 ! varid: [netcdf] variable ID # 37 real, dimension(:), allocatable:: lat,lon,alt, time37 real, dimension(:), allocatable:: lat,lon,alt,ctl,time 38 38 ! lat(): array, stores latitude coordinates 39 39 ! lon(): array, stores longitude coordinates 40 40 ! alt(): array, stores altitude coordinates 41 ! ctl(): array, stores controle array 41 42 ! time(): array, stores time coordinates 42 43 integer :: nbvar,nbvarfile,ndim … … 45 46 ! nbvarfile: total # of variables in an input file 46 47 ! ndim: [netcdf] # (3 or 4) of dimensions (for variables) 47 integer :: latdim,londim,altdim, timedim48 integer :: latdim,londim,altdim,ctldim,timedim 48 49 ! latdim: [netcdf] "latitude" dim ID 49 50 ! londim: [netcdf] "longitude" dim ID 50 51 ! altdim: [netcdf] "altdim" dim ID 52 ! ctldim: [netcdf] "controle" dim ID 51 53 ! timedim: [netcdf] "timedim" dim ID 52 integer :: latvar,lonvar,altvar, timevar54 integer :: latvar,lonvar,altvar,ctlvar,timevar 53 55 ! latvar: [netcdf] ID of "latitude" variable 54 56 ! lonvar: [netcdf] ID of "longitude" variable 55 57 ! altvar: [netcdf] ID of "altitude" variable 58 ! ctlvar: [netcdf] ID of "controle" variable 56 59 ! timevar: [netcdf] ID of "Time" variable 57 integer :: latlen,lonlen,altlen, timelen,timelen_lt,timelen_tot60 integer :: latlen,lonlen,altlen,ctllen,timelen,timelen_lt,timelen_tot 58 61 integer :: ilat,ilon,ialt,it 59 62 ! latlen: # of elements of lat() array 60 63 ! lonlen: # of elements of lon() array 61 64 ! altvar: # of elements of alt() array 65 ! ctlvar: # of elements of ctl() array 62 66 ! timelen: # of elemnets of time() array 63 67 ! timelen_tot:# =timelen or timelen+1 (if 1 more time to interpolate needed) … … 246 250 ! write(*,*) "altlen: ",altlen 247 251 252 ierr=NF_INQ_DIMID(nid,"index",ctldim) 253 ierr=NF_INQ_VARID(nid,"controle",ctlvar) 254 if (ierr.NE.NF_NOERR) then 255 write(*,*) 'Field <controle> is missing in file'//file 256 ctllen=0 257 !stop "" 258 else 259 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen) 260 endif 261 ! write(*,*) "controle: ",controle 262 248 263 !============================================================================== 249 264 ! 2.3. Read (and check compatibility of) dimensions of … … 255 270 allocate(lon(lonlen)) 256 271 allocate(alt(altlen)) 272 allocate(ctl(ctllen)) 257 273 #ifdef NC_DOUBLE 258 274 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat) 259 275 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon) 260 276 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt) 277 if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl) 261 278 #else 262 279 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 263 280 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 264 281 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 282 if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 265 283 #endif 266 284 !============================================================================== … … 351 369 352 370 ! Initialize output file's lat,lon,alt and time dimensions 353 call initiate (filename,lat,lon,alt, nout,&371 call initiate (filename,lat,lon,alt,ctl,nout,& 354 372 latdimout,londimout,altdimout,timedimout,timevarout) 355 373 ! Initialize output file's aps,bps and phisinit variables … … 561 579 562 580 !****************************************************************************** 563 Subroutine initiate (filename,lat,lon,alt, &581 Subroutine initiate (filename,lat,lon,alt,ctl,& 564 582 nout,latdimout,londimout,altdimout,timedimout,timevarout) 565 583 !============================================================================== … … 586 604 real, dimension(:), intent(in):: alt 587 605 ! alt(): altitude 606 real, dimension(:), intent(in):: ctl 607 ! ctl(): controle 588 608 integer, intent(out):: nout 589 609 ! nout: [netcdf] file ID … … 604 624 !integer :: latdim,londim,altdim,timedim 605 625 integer :: nvarid,ierr 626 integer :: ctldimout 606 627 ! nvarid: [netcdf] ID of a variable 607 628 ! ierr: [netcdf] return error code (from called subroutines) … … 625 646 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout) 626 647 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout) 648 if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout) 627 649 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout) 628 650 … … 664 686 665 687 !============================================================================== 666 ! 4. Write "altitude" (data and attributes)688 ! 5. Write "altitude" (data and attributes) 667 689 !============================================================================== 668 690 … … 688 710 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 689 711 #endif 712 713 !============================================================================== 714 ! 6. Write "controle" (data and attributes) 715 !============================================================================== 716 717 if (size(ctl).ne.0) then 718 ! Switch to netcdf define mode 719 ierr = NF_REDEF (nout) 720 721 #ifdef NC_DOUBLE 722 ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid) 723 #else 724 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 725 #endif 726 727 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 728 729 ! End netcdf define mode 730 ierr = NF_ENDDEF(nout) 731 732 #ifdef NC_DOUBLE 733 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl) 734 #else 735 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 736 #endif 737 endif 690 738 691 739 end Subroutine initiate -
trunk/LMDZ.MARS/util/lslin.F90
r410 r1073 10 10 ! Modified by Ehouarn Millour 10/2007 (changed evaluation of 'start_var' 11 11 ! from hard-coded values to a computed value) 12 ! Read controle field, if available TN, October 2013 13 12 14 13 15 implicit none … … 109 111 read(*,'(a50)') infile 110 112 111 write(*,*) "Is it a concatnc file? (y/n)?" 113 !write(*,*) "Is it a concatnc file? (y/n)?" 114 write(*,*) "Do you want to specify the beginning day of the file" 115 write(*,*) "in case the controle field is not present ? (y/n)?" 112 116 read(*,*) answer 113 117 if ((answer=="y").or.(answer=="Y")) then 114 write(*,*) "Beginning day of the concatncfile?"118 write(*,*) "Beginning day of the file?" 115 119 read(*,*) reptime 116 120 ! start_var=8 ! 'concatnc' type of file … … 311 315 endif 312 316 313 day_ini = tab_cntrl(4) 317 day_ini = tab_cntrl(4) 318 day_ini = modulo(day_ini,669) 314 319 write(*,*) 'day_ini', day_ini 315 320 else -
trunk/LMDZ.MARS/util/zrecast.F90
r909 r1073 60 60 ! constants (radius, R, etc.) are now read from file 61 61 ! TN 01/2013 : Adapted for large output files with at least 2 variables > 2 GiB 62 ! TN 10/2013 : Read and write controle field, if available 62 63 ! 63 64 implicit none … … 80 81 integer nbvar4dinfile ! # of 4D (lon,lat,alt,time) variables in input file 81 82 integer outfid ! NetCDF output file ID 82 integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs83 integer lon_varid,lat_varid,alt_varid,time_varid 83 integer lon_dimid,lat_dimid,alt_dimid,time_dimid,ctl_dimid ! NetCDF dimension IDs 84 integer lon_varid,lat_varid,alt_varid,time_varid,ctl_varid 84 85 integer gcm_layers_dimid ! NetCDF dimension ID for # of layers in GCM 85 86 integer sigma_varid,aps_varid,bps_varid … … 103 104 integer latlength ! # of grid points along latitude 104 105 integer altlength ! # of grid point along altitude (of input datasets) 106 real,dimension(:),allocatable :: ctl ! controle 107 integer ctllength ! # of grid points along controle 105 108 real,dimension(:),allocatable :: time ! time 106 109 integer timelength ! # of points along time … … 439 442 if (ierr.ne.NF_NOERR) then 440 443 stop "Error: Failed to get altitude length" 444 endif 445 endif 446 447 ! controle 448 ierr=NF_INQ_DIMID(infid,"index",tmpdimid) 449 if (ierr.ne.NF_NOERR) then 450 write(*,*) "Could not get controle dimension ID" 451 ctllength = 0 452 else 453 ierr=NF_INQ_VARID(infid,"controle",tmpvarid) 454 if (ierr.ne.NF_NOERR) then 455 stop "Error: Failed to get controle ID" 456 else 457 ierr=NF_INQ_DIMLEN(infid,tmpdimid,ctllength) 458 if (ierr.ne.NF_NOERR) then 459 stop "Error: Failed to get controle length" 460 else 461 allocate(ctl(ctllength),stat=ierr) 462 if (ierr.ne.0) then 463 write(*,*) "Error: Failed to allocate ctl(ctllength)" 464 write(*,*) " ctllength=",ctllength 465 stop 466 endif 467 ierr=NF_GET_VAR_REAL(infid,tmpvarid,ctl) 468 if (ierr.ne.NF_NOERR) then 469 stop "Error: Failed reading controle" 470 endif 471 endif 441 472 endif 442 473 endif … … 1030 1061 endif 1031 1062 1063 ! controle 1064 if (ctllength .ne. 0) then 1065 ierr=NF_DEF_DIM(outfid,"index",ctllength,ctl_dimid) 1066 if (ierr.ne.NF_NOERR) then 1067 write(*,*) "Error: Could not define controle dimension" 1068 write(*,*) NF_STRERROR(ierr) 1069 stop 1070 endif 1071 endif 1072 1032 1073 ! GCM layers (for sigma or aps and bps) 1033 1074 ierr=NF_DEF_DIM(outfid,"GCM_layers",altlength,gcm_layers_dimid) … … 1162 1203 endif 1163 1204 endif ! of if (have_sigma) 1205 1206 ! controle 1207 if (ctllength .ne. 0) then 1208 ierr=NF_DEF_VAR(outfid,"controle",NF_REAL,1,ctl_dimid,ctl_varid) 1209 if (ierr.ne.NF_NOERR) then 1210 write(*,*) "Error: Could not define controle variable" 1211 write(*,*) NF_STRERROR(ierr) 1212 stop 1213 endif 1214 1215 ! controle attributes 1216 text='Control parameters' 1217 ierr=NF_PUT_ATT_TEXT(outfid,ctl_varid,'title',len_trim(text),text) 1218 if (ierr.ne.NF_NOERR) then 1219 stop "Error: Problem writing title for controle" 1220 endif 1221 endif 1164 1222 1165 1223 ! GCM_layers … … 1509 1567 endif 1510 1568 1569 ! Write controle 1570 if (ctllength .ne. 0) then 1571 ierr=NF_PUT_VAR_REAL(outfid,ctl_varid,ctl) 1572 if (ierr.ne.NF_NOERR) then 1573 write(*,*) "Error: Could not write controle data to output file" 1574 write(*,*) NF_STRERROR(ierr) 1575 stop 1576 endif 1577 endif 1578 1511 1579 ! Write time 1512 1580 ierr=NF_PUT_VARA_REAL(outfid,time_varid,1,timelength,time) … … 1771 1839 subroutine init_planet_const(infid) 1772 1840 ! initialize planetary constants using the "controle" array in the file 1773 ! if "co introle" array not found in file, look for it in "diagfi.nc"1841 ! if "controle" array not found in file, look for it in "diagfi.nc" 1774 1842 use planet_const 1775 1843 use netcdf
Note: See TracChangeset
for help on using the changeset viewer.