- Timestamp:
- Nov 14, 2020, 3:27:44 PM (4 years ago)
- Location:
- trunk/LMDZ.MARS
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/README
r2429 r2432 3198 3198 distance. 3199 3199 3200 == 14/11/2020 == FF + EM 3201 - Make a single README file (get rid of REAME.exec) and update "compile" 3202 script to (hopefully) better illustrate how to compile utilities 3203 - Update utilities zrecast and lslin: 3204 zrecast.F90: Force the vertical interpolation of any variable starting 3205 by "rho" to be in log space (as it should for density, molecular 3206 concentration in mol.cm-3 etc..). Set missing value to 1.E20 3207 lslin.F90: fix various problems in the output. -
trunk/LMDZ.MARS/util/README
r2431 r2432 1 This directory contains executable files (and their source) that can be1 This directory contains source codes of utilities (programs) that can be 2 2 used to process the LMD Mars GCM output files (like "diagfi" or 3 "stats") , whatever the dimension.4 In addition most output file from one of these program can be5 processe sby another.3 "stats"). 4 In addition most output file from one of these program can then be 5 processed by another. 6 6 7 The executable files should run on any Linux platform. 7 See script "compile" for instructions and recommendations to compile 8 the utilities. Once adequately modified, that script can be used to 9 compile each utility; e.g. to build the zrecast.e utility program: 10 > compile zrecast 8 11 9 Inputs can be provided by (1) replying to questions on screen or10 (2) filling the corresponding *.def and directthe input of these *.def12 Note that inputs can be provided by (1) replying to questions on screen or 13 (2) filling the corresponding *.def and redirecting the input of these *.def 11 14 files instead. For example : 12 15 > concatnc.e < concatnc.def … … 14 17 15 18 -------------------------------------------------------------------- 16 1) concatnc.e 19 1) concatnc.e : concatenate successive GCM output files 17 20 -------------------------------------------------------------------- 18 21 … … 23 26 software like Grads may not be able to use it. To have a linear "Ls" 24 27 timescale, you can use "Ls_Linear.e" (see below). 28 You can also add a "Ls" variable corresponding solar longitude for each 29 timestep by using the "adls" option. 25 30 26 31 Output file is : concat.nc 27 32 28 MODIFICATION:29 07/2008 Utility concatnc.F90 (not used by the gcm): improvement in order30 to 1) concatenate 1D variable and 2) increase the number of input files31 up to 100032 33 34 33 -------------------------------------------------------------------- 35 2) localtime.e34 2) zrecast.e : put GCM data in physical vertical coordinate 36 35 -------------------------------------------------------------------- 37 36 38 Program to redistribute and interpolate the variable a the same 39 local times everywhere (useful to mimic satellite observations, or 40 analyse day to day variations at a given local time). 41 input : diagfi.nc / concat.nc / stats.nc kind of files 42 43 output file is : 44 name_of_input_file_LT.nc with pressure coordinate 45 46 -------------------------------------------------------------------- 47 3) zrecast.e 48 -------------------------------------------------------------------- 37 GCM outputs are in GCM hybrid coordinate which do not correspond to any 38 physical vertical coordinate ! zrecast is NECESSARY to make any publishable 39 scientific figure. 49 40 50 41 This program reads 4D (lon-lat-alt-time) fields from GCM output files … … 65 56 - surface pressure 66 57 - atmospheric temperature 67 - hybrid coordinates aps() and bps(), or sigma levels() (see section 68 1.3.2) 58 - hybrid coordinates aps() and bps(), or sigma levels() 69 59 - ground geopotential (in input file; if not found, it is sought 70 60 in a 'diagfi.nc' file. If not found there, it is then sought in … … 77 67 2.2 in source file) 78 68 69 - Vertical interpolation : note that density (kg.m-3) and species density 70 (e.g. in molecules.cm-3) must be vertically interpolated in log-space. For 71 that purpose, these variables names must start with "rho" (exemple : rho for 72 density, rho_co2, rho_o2, etc....) 73 79 74 output file is : 80 75 name_of_input_file_P.nc with pressure coordinate … … 83 78 name_of_input_file_R.nc with altitude as distance to center of planet 84 79 85 MODIFICATION : 86 01/2010 : correction to interpolate above surface if density is not available. 87 03/2011 : added possibility to have output as distance to center of planet 80 -------------------------------------------------------------------- 81 3) localtime.e : put GCM data in local time coordinate 82 -------------------------------------------------------------------- 83 84 Program to redistribute and interpolate the variable a the same 85 local times everywhere (useful to mimic satellite observations, or 86 analyse day to day variations at a given local time). 87 input : diagfi.nc / concat.nc / stats.nc kind of files 88 89 output file is : name_of_input_file_LT.nc 88 90 89 91 -------------------------------------------------------------------- 90 4) lslin.e 92 4) lslin.e : redistribute and AVERAGE gcm output in Ls coordinate. 91 93 -------------------------------------------------------------------- 92 94 93 95 This program has been designed to interpol data in Solar Longitude (Ls) 94 96 linear time coordinate (usable with grads) from Netcdf diagfi or concatnc 95 files. 96 output file is : lslin.nc 97 lslin also create a lslin.ctl file that can be read 97 files and to AVERAGE the instantaneous data in Ls period (for comparison with 98 binned dataset, for instance). 99 100 lslin also creates a lslin.ctl file that can be read 98 101 directly by grads (>xdfopen lsllin.ctl) to plot in Ls coordinate to 99 102 avoid some problem with grads when grads think that "the time interval 100 103 is too small"... 101 104 102 MODIFICATION 103 10/2007 Utility lslin.F90 (not used by the gcm) 104 changed evaluation of 'start_var' from hard-coded values to a computed value 105 04/2015 Added possibility to bin data (instead of interpolating) over 106 the time intervals 105 Output file is : name_of_input_file_LS.nc 107 106 108 107 -------------------------------------------------------------------- 109 5) hrecast.e108 5) solzenangle.e : select GCM data at a given solar zenith angle 110 109 -------------------------------------------------------------------- 111 110 112 This program can interpolate GCM output on any horizontal grid (regular lat - lon) as long as it cover all the 113 planet. The grid can be given points by points. The best way is to use the redirected input hrecast.def 111 Program to redistribute and interpolate the variable a the same 112 solar zenith angle (notably useful to mimic satellite observations and in particular 113 SOLAR OCCULTATIONS by choosing solar zenith angle = 90°) 114 The user choose between Morning and Evening side. 115 116 input : diagfi.nc / concat.nc / stats.nc kind of files 117 118 On the morning side output file (1 output per sol per grid point) is : 119 name_of_input_file_MO.nc 120 121 On the evening side output file is (1 output per sol per grid point): 122 name_of_input_file_EV.nc 123 124 -------------------------------------------------------------------- 125 6) hrecast.e : interpolate data at another horizontal grid resolution. 126 -------------------------------------------------------------------- 127 128 This program can interpolate GCM output on any horizontal grid (regular 129 lat - lon) as long as it cover all the planet. 130 The grid can be given points by points. The best way is to use the 131 redirected input hrecast.def 114 132 115 133 hrecast.e < hrecast.def … … 117 135 118 136 -------------------------------------------------------------------- 119 6) expandstartfi.e137 7) expandstartfi.e : to plot data in a startfi.nc file 120 138 -------------------------------------------------------------------- 121 139 140 In startfi.nc file, data are not plotable because the horizontal coordinate 141 in only a 1D list of all atmospheric columns on the planets. 122 142 This program takes a physics start file ("startfi.nc") and recasts it 123 143 on the corresponding lonxlat grid (so it contents may easily be displayed 124 using Grads, Ferret, etc.)144 using Python, Grads, Ferret, etc.) 125 145 126 146 Simply run expandstartfi.e as a command line with arguments: … … 132 152 133 153 -------------------------------------------------------------------- 134 6) extract.e 154 8) extract.e : get data at specific coordinates for comparison with observations 135 155 -------------------------------------------------------------------- 136 156 -
trunk/LMDZ.MARS/util/compile
r2395 r2432 3 3 # > compile concat 4 4 # > compile zrecast 5 ## BUT first you must customize this script to your personal settings: 6 # 1) set up the correct environment; e.g. environment variable 7 # NETCDF_HOME should point to your NetCDF distribution root directory 8 # (and possibly you might need to "module load ..." a few things) 9 # 2) put the appropriate compiler and compiler options 10 # in variables COMPILER and COMPILER_OPTIONS 11 # 3) Note that when you will run the executable, you might need to 12 # also add the paths to the used libraries (e.g. $NETCDF_HOME/lib) 13 # in environment variable LD_LIBRARY_PATH (most often the "module load ..." 14 # command does this, so you should run it before running the executable) 5 15 6 # pgf90 -Bstatic $1.F90 \ 7 #-I/distrib/local/netcdf/pgi_7.1-6_32/include \ 8 #-L/distrib/local/netcdf/pgi_7.1-6_32/lib -lnetcdf -o $1.e 16 # Setup: (see at the end of this script for real world examples) 17 # possibly source some modules here and adapt variables below: 18 NETCDF_HOME="/path/to/the/NetCDF/root/directory" 19 COMPILER="gfortran" 20 COMPILER_OPTIONS="-O2" 9 21 10 #ifort $1.F90 \ 11 #pgf90 $1.F90 \ 12 ifort $1.F90 \ 13 -I$NETCDF/include \ 14 -L$NETCDF/lib -lnetcdf -o $1.e 22 # Compilation: 23 # (on some very old systems the Fortran NetCDF library is included 24 # in the C library and "-lnetcdff" should be replaced with "-lnetcdf") 15 25 16 # Before running that on you computer you might want to change : 17 # 1) replace "pgf90" with the name of your favorite compiler 18 # (you may also add some non-agressive optimization options e.g. -O2) 19 # 2) replace "/distrib/local/netcdf/pgi_7.1-6_32/lib" with the 20 # address of the 21 # directory that contains the NetCDF library (file libnetcdf.a that can 22 # be obtained for free on 23 # http://www.unidata.ucar.edu/packages/netcdf/index.html 24 # (see user manual) 26 $COMPILER $COMPILER_OPTIONS $1.F90 \ 27 -I$NETCDF_HOME/include \ 28 -L$NETCDF_HOME/lib -lnetcdff \ 29 -o $1.e 30 25 31 # 26 # 3) Replace "/distrib/local/netcdf/pgi_7.1-6_32/lib" with the address of the 27 # directory that contains the NetCDF include file "netcdf.inc" 28 # that can be obtained at the web address above. 29 # 30 # 4) The "-Bstatic" option is here to ensure that the executable will 31 # work on any Linux machine (only necessary if you want to export the 32 # executable from a machine to another). 32 # Example of a setup on a simple Linux system where the netcdf library 33 # is in a personal location /home/myacount/netcdf directory: 34 # NETCDF_HOME=/home/myaccount/netcdf 35 # COMPILER="gfortran" 36 # COMPILER_OPTIONS="-O2" 37 # And of course the LD_LIBRARY_PATH environement variable should contain 38 # path "/home/myaccount/netcdf/lib" to be able to run the executable 39 # 40 # Example of a setup on LMD CentOS7 machines using gfortran and NetCDF 4.5: 41 # module purge 42 # module load gnu/7.2.0 43 # module load netcdf4/4.5.0-gfortran72 44 # NETCDF_HOME=/opt/netcdf45/gfortran72 45 # COMPILER="gfortran" 46 # COMPILER_OPTIONS="-O2" 47 # And of course modules above need be loaded before running the executable 48 # 49 # Example of a setup on the Ciclad cluster using ifort and NetCDF 4.3 50 # module purge 51 # module load intel/15.0.6.233 52 # module load netcdf4/4.3.3.1-ifort 53 # NETCDF_HOME=/opt/netcdf43/ifort 54 # COMPILER="ifort" 55 # COMPILER_OPTIONS="-O2 -ip" 56 # And of course modules above need be loaded before running the executable 33 57 34 58 35 36 -
trunk/LMDZ.MARS/util/lslin.F90
r1409 r2432 27 27 character (len=50) :: units_alt 28 28 ! var(): units of altitude which can be 'km' or 'Pa' (after zrecast) 29 character (len=50) :: altlong_name,altunits,altpositive 30 ! altlong_name(): [netcdf] altitude "long_name" attribute 31 ! altunits(): [netcdf] altitude "units" attribute 32 ! altpositive(): [netcdf] altitude "positive" attribute 33 29 34 character (len=100) :: outfile 30 35 ! outfile(): output file name … … 35 40 character (len=1) :: average 36 41 ! average: the character 'y' to average within the Ls timestep 37 integer :: nid,varid,ierr,miss 42 integer :: nid,varid,ierr,miss,validr 38 43 ! nid: [netcdf] ID # of input file 39 44 ! varid: [netcdf] ID # of a variable … … 55 60 ! tab_cntrl(length): array, stored in the input file, 56 61 ! which contains various control parameters. 57 real, dimension(:), allocatable:: lat,lon,alt,time,lsgcm,timels 62 real, dimension(:), allocatable:: lat,lon,alt,time,lsgcm,timels,ctl 58 63 ! lat(): latitude coordinates (read from input file) 59 64 ! lon(): longitude coordinates (read from input file) … … 62 67 ! lsgcm(): time coordinate (in unevenly spaced "Ls") 63 68 ! timels(): new time coordinates (evenly spaced "Ls"; written to output file) 64 integer :: latlen,lonlen,altlen,timelen,Nls,Sls 69 ! ctl(): array, stores controle array 70 integer :: latlen,lonlen,altlen,timelen,Nls,Sls,ctllen 65 71 ! latlen: # of elements of lat() array 66 72 ! lonlen: # of elements of lon() array … … 72 78 ! nbvarfile: total # of variables (in netcdf file) 73 79 ! ndim: [netcdf] # of dimensions (3 or 4) of a variable 74 integer :: latdim,londim,altdim,timedim 80 integer :: latdim,londim,altdim,timedim,ctldim 75 81 ! latdim: [netcdf] "latitude" dim ID 76 82 ! londim: [netcdf] "longitude" dim ID 77 83 ! altdim: [netcdf] "altdim" dim ID 78 84 ! timedim: [netcdf] "timedim" dim ID 79 integer :: latvar,lonvar,altvar,timevar 85 ! ctldim: [netcdf] "controle" dim ID 86 integer :: latvar,lonvar,altvar,timevar,ctlvar 80 87 ! latvar: [netcdf] ID of "latitude" variable 81 88 ! lonvar: [netcdf] ID of "longitude" variable … … 240 247 else 241 248 ierr=NF_INQ_DIMLEN(nid,altdim,altlen) 242 units_alt=" 249 units_alt="" 243 250 ierr=NF_GET_ATT_TEXT(nid,varid,"units",units_alt) 244 251 endif 245 252 write(*,*) "altlen: ",altlen 253 ! Get altitude attributes to handle files with any altitude type 254 ierr=nf_get_att_text(nid,altvar,'long_name',altlong_name) 255 ierr=nf_get_att_text(nid,altvar,'units',altunits) 256 ierr=nf_get_att_text(nid,altvar,'positive',altpositive) 257 246 258 247 259 ! Allocate lat(), lon() and alt() … … 251 263 252 264 ! Read lat(),lon() and alt() from input file 253 254 255 256 257 258 265 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 259 266 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) … … 264 271 265 272 273 ierr=NF_INQ_DIMID(nid,"index",ctldim) 274 if (ierr.NE.NF_NOERR) then 275 write(*,*) ' Dimension <index> is missing in file '//trim(infile) 276 ctllen=0 277 !stop "" 278 endif 279 ierr=NF_INQ_VARID(nid,"controle",ctlvar) 280 if (ierr.NE.NF_NOERR) then 281 write(*,*) 'Field <controle> is missing in file '//trim(infile) 282 ctllen=0 283 !stop "" 284 else 285 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen) 286 endif 287 288 allocate(ctl(ctllen),stat=ierr) 289 if (ierr.ne.0) then 290 write(*,*) "Error: failed to allocate ctl(ctllen)" 291 stop 292 endif 293 294 if (ctllen .ne. 0) then 295 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 296 if (ierr.ne.0) then 297 write(*,*) "Error: failed to load controle" 298 write(*,*) NF_STRERROR(ierr) 299 stop 300 endif 301 endif ! of if (ctllen .ne. 0) 302 303 304 266 305 !============================================================================== 267 306 ! 2.2. Create (and initialize latitude, longitude and altitude in) output file 268 307 !============================================================================== 269 308 270 call initiate(outfile,lat,lon,alt,nout,& 271 latdimout,londimout,altdimout,timedimout,timevarout,units_alt) 309 ! Initialize output file's lat,lon,alt and time dimensions 310 call initiate(outfile,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,& 311 altlong_name,altunits,altpositive,& 312 nout,latdimout,londimout,altdimout,timedimout,timevarout) 313 314 ! Initialize output file's aps,bps and phisinit variables 315 call init2(nid,lonlen,latlen,altlen,altdim,& 316 nout,londimout,latdimout,altdimout) 272 317 273 318 !============================================================================== … … 328 373 endif 329 374 330 day_ini = tab_cntrl(4)375 day_ini = nint(tab_cntrl(4)) 331 376 day_ini = modulo(day_ini,669) 332 377 write(*,*) 'day_ini', day_ini … … 392 437 393 438 ! Build timels() 394 timels(1) = 0.01*nint(100.*ls0) ! Ehouarn: what the !!!???!!!439 timels(1) = 0.01*nint(100.*ls0) 395 440 do k=2,Nls 396 441 timels(k) = timels(k-1) + deltals … … 482 527 ! 3.3 Write this variable's definition and attributes to the output file 483 528 !============================================================================== 484 units=" " 485 title=" " 486 ierr=NF_GET_ATT_TEXT(nid,varid,"title",title) 487 ierr=NF_GET_ATT_TEXT(nid,varid,"units",units) 488 489 call def_var(nout,var(j),title,units,ndim,dim,varidout,ierr) 529 if (ndim.ge.3) then 530 units="" 531 title="" 532 ierr=NF_GET_ATT_TEXT(nid,varid,"title",title) 533 ierr=NF_GET_ATT_TEXT(nid,varid,"units",units) 534 535 call def_var(nout,var(j),title,units,ndim,dim,varidout,ierr) 536 end if 490 537 491 538 !============================================================================== 492 539 ! 3.4 Read variable 493 !============================================================================== 494 495 496 497 498 ierr = NF_GET_VAR_REAL(nid,varid,var3d) 499 miss = NF_GET_ATT_REAL(nid,varid,"missing_value",missing) 500 miss = NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range) 540 !==== ========================================================================== 541 542 if (ndim.ge.3) then 543 ierr = NF_GET_VAR_REAL(nid,varid,var3d) 544 miss=NF_GET_ATT_REAL(nid,varid,"missing_value",missing) 545 validr=NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range) 546 end if 501 547 502 548 … … 582 628 583 629 584 585 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,var3dls) 586 587 588 if (ierr.ne.NF_NOERR) then 630 if (ndim.ge.3) then 631 632 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,var3dls) 633 634 635 if (ierr.ne.NF_NOERR) then 589 636 write(*,*) 'PUT_VAR ERROR: ',NF_STRERROR(ierr) 590 637 stop "" 591 endif638 endif 592 639 593 640 ! In case there is a "missing value" attribute and "valid range" 594 if (miss.eq.NF_NOERR) then 595 call missing_value(nout,varidout,valid_range,missing) 596 end if 597 598 deallocate(var3d) 599 deallocate(var3dls) 600 deallocate(var3dxy) 641 if (miss.eq.NF_NOERR) then 642 call missing_value(nout,varidout,missing) 643 end if 644 645 deallocate(var3d) 646 deallocate(var3dls) 647 deallocate(var3dxy) 648 endif ! if (ndim.ge.3) 601 649 602 650 enddo ! of do j=1,nbvar loop … … 641 689 contains 642 690 643 !************************************ 644 subroutine initiate (filename,lat,lon,alt,& 645 nout,latdimout,londimout,altdimout,timedimout,timevarout,units_alt) 691 !****************************************************************************** 692 693 subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,& 694 altlong_name,altunits,altpositive,& 695 nout,latdimout,londimout,altdimout,timedimout,timevarout) 646 696 !============================================================================== 647 697 ! Purpose: … … 661 711 character (len=*), intent(in):: filename 662 712 ! filename(): the file's name 663 real, dimension(:), intent(in):: lat 713 integer,intent(in) ::latlen,lonlen,altlen,ctllen 714 real, intent(in):: lat(latlen) 664 715 ! lat(): latitude 665 real, dimension(:), intent(in):: lon716 real, intent(in):: lon(lonlen) 666 717 ! lon(): longitude 667 real, dimension(:), intent(in):: alt718 real, intent(in):: alt(altlen) 668 719 ! alt(): altitude 720 real, intent(in):: ctl(ctllen) 721 ! ctl(): controle 722 character (len=*), intent(in) :: altlong_name 723 ! altlong_name(): [netcdf] altitude "long_name" attribute 724 character (len=*), intent(in) :: altunits 725 ! altunits(): [netcdf] altitude "units" attribute 726 character (len=*), intent(in) :: altpositive 727 ! altpositive(): [netcdf] altitude "positive" attribute 669 728 integer, intent(out):: nout 670 729 ! nout: [netcdf] file ID … … 679 738 integer, intent(out):: timevarout 680 739 ! timevarout: [netcdf] "Time" (considered as a variable) ID 681 character (len=50) :: units_alt682 ! var(): units of altitude which can be m or Pa (after zrecast)683 684 740 685 741 !============================================================================== … … 688 744 !integer :: latdim,londim,altdim,timedim 689 745 integer :: nvarid,ierr 746 integer :: ctldimout 690 747 ! nvarid: [netcdf] ID of a variable 691 748 ! ierr: [netcdf] return error code (from called subroutines) … … 698 755 ! NB: setting NF_CLOBBER mode means that it's OK to overwrite an existing file 699 756 if (ierr.NE.NF_NOERR) then 700 WRITE(*,*)'ERROR: Impossible to create the file.' 757 WRITE(*,*)'ERROR: Impossible to create the file ',trim(filename) 758 write(*,*) NF_STRERROR(ierr) 701 759 stop "" 702 760 endif … … 706 764 !============================================================================== 707 765 708 ierr = NF_DEF_DIM(nout, "latitude", size(lat), latdimout) 709 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout) 710 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout) 766 ierr = NF_DEF_DIM(nout, "latitude", latlen, latdimout) 767 if (ierr.NE.NF_NOERR) then 768 WRITE(*,*)'initiate: error failed to define dimension <latitude>' 769 write(*,*) NF_STRERROR(ierr) 770 stop "" 771 endif 772 ierr = NF_DEF_DIM(nout, "longitude", lonlen, londimout) 773 if (ierr.NE.NF_NOERR) then 774 WRITE(*,*)'initiate: error failed to define dimension <longitude>' 775 write(*,*) NF_STRERROR(ierr) 776 stop "" 777 endif 778 ierr = NF_DEF_DIM(nout, "altitude", altlen, altdimout) 779 if (ierr.NE.NF_NOERR) then 780 WRITE(*,*)'initiate: error failed to define dimension <altitude>' 781 write(*,*) NF_STRERROR(ierr) 782 stop "" 783 endif 784 if (size(ctl).ne.0) then 785 ierr = NF_DEF_DIM(nout, "index", ctllen, ctldimout) 786 if (ierr.NE.NF_NOERR) then 787 WRITE(*,*)'initiate: error failed to define dimension <index>' 788 write(*,*) NF_STRERROR(ierr) 789 stop "" 790 endif 791 endif 711 792 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout) 793 if (ierr.NE.NF_NOERR) then 794 WRITE(*,*)'initiate: error failed to define dimension <Time>' 795 write(*,*) NF_STRERROR(ierr) 796 stop "" 797 endif 712 798 713 799 ! End netcdf define mode 714 800 ierr = NF_ENDDEF(nout) 801 if (ierr.NE.NF_NOERR) then 802 WRITE(*,*)'initiate: error failed to switch out of define mode' 803 write(*,*) NF_STRERROR(ierr) 804 stop "" 805 endif 715 806 716 807 !============================================================================== … … 718 809 !============================================================================== 719 810 720 call def_var(nout,"Time"," Time","years since 0000-00-0 00:00:00",1,&811 call def_var(nout,"Time","Ls (Solar Longitude)","degrees",1,& 721 812 (/timedimout/),timevarout,ierr) 813 ! Switch to netcdf define mode 814 ierr = NF_REDEF (nout) 815 ierr = NF_ENDDEF(nout) 722 816 723 817 !============================================================================== … … 729 823 730 824 ierr = NF_PUT_VAR_REAL (nout,nvarid,lat) 825 if (ierr.NE.NF_NOERR) then 826 WRITE(*,*)'initiate: error failed writing variable <latitude>' 827 write(*,*) NF_STRERROR(ierr) 828 stop "" 829 endif 731 830 732 831 !============================================================================== … … 738 837 739 838 ierr = NF_PUT_VAR_REAL (nout,nvarid,lon) 740 741 !============================================================================== 742 ! 4. Write "altitude" (data and attributes) 839 if (ierr.NE.NF_NOERR) then 840 WRITE(*,*)'initiate: error failed writing variable <longitude>' 841 write(*,*) NF_STRERROR(ierr) 842 stop "" 843 endif 844 845 !============================================================================== 846 ! 5. Write "altitude" (data and attributes) 743 847 !============================================================================== 744 848 … … 748 852 ierr = NF_DEF_VAR (nout,"altitude",NF_FLOAT,1,altdimout,nvarid) 749 853 750 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",8,"altitude") 751 !********************* temlporaire **************** 752 !ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,units_alt) 753 !if((units_alt(1:2).eq.'Pa').or.(units_alt(1:2).eq.'pa')) then 754 ! ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"down") 755 !else 756 ! ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"up") 757 !end if 758 !********************* temlporaire **************** 759 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,'Pa') 760 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',4,'down') 761 !********************* temlporaire **************** 854 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'long_name',len_trim(adjustl(altlong_name)),adjustl(altlong_name)) 855 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',len_trim(adjustl(altunits)),adjustl(altunits)) 856 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',len_trim(adjustl(altpositive)),adjustl(altpositive)) 762 857 763 858 ! End netcdf define mode … … 765 860 766 861 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 862 if (ierr.NE.NF_NOERR) then 863 WRITE(*,*)'initiate: error failed writing variable <altitude>' 864 write(*,*) NF_STRERROR(ierr) 865 stop "" 866 endif 867 868 !============================================================================== 869 ! 6. Write "controle" (data and attributes) 870 !============================================================================== 871 872 if (size(ctl).ne.0) then 873 ! Switch to netcdf define mode 874 ierr = NF_REDEF (nout) 875 876 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 877 878 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 879 880 ! End netcdf define mode 881 ierr = NF_ENDDEF(nout) 882 883 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 884 if (ierr.NE.NF_NOERR) then 885 WRITE(*,*)'initiate: error failed writing variable <controle>' 886 write(*,*) NF_STRERROR(ierr) 887 stop "" 888 endif 889 endif 767 890 768 891 end Subroutine initiate 769 !************************************ 892 893 !****************************************************************************** 894 subroutine init2(infid,lonlen,latlen,altlen,altdimid, & 895 outfid,londimout,latdimout,altdimout) 896 !============================================================================== 897 ! Purpose: 898 ! Copy aps(), bps() and phisinit() from input file to output file 899 !============================================================================== 900 ! Remarks: 901 ! The NetCDF files must be open 902 !============================================================================== 903 904 implicit none 905 906 include "netcdf.inc" ! NetCDF definitions 907 908 !============================================================================== 909 ! Arguments: 910 !============================================================================== 911 integer, intent(in) :: infid ! NetCDF output file ID 912 integer, intent(in) :: lonlen ! # of grid points along longitude 913 integer, intent(in) :: latlen ! # of grid points along latitude 914 integer, intent(in) :: altlen ! # of grid points along altitude 915 integer, intent(in) :: altdimid ! ID of altitude dimension 916 integer, intent(in) :: outfid ! NetCDF output file ID 917 integer, intent(in) :: londimout ! longitude dimension ID 918 integer, intent(in) :: latdimout ! latitude dimension ID 919 integer, intent(in) :: altdimout ! altitude dimension ID 920 !============================================================================== 921 ! Local variables: 922 !============================================================================== 923 real,dimension(:),allocatable :: aps,bps ! hybrid vertical coordinates 924 real,dimension(:,:),allocatable :: phisinit ! Ground geopotential 925 integer :: apsid,bpsid,phisinitid 926 integer :: ierr 927 integer :: tmpdimid ! temporary dimension ID 928 integer :: tmpvarid ! temporary variable ID 929 integer :: tmplen ! temporary variable length 930 logical :: phis, aps_ok, bps_ok ! are "phisinit" "aps" "bps" available ? 931 932 933 !============================================================================== 934 ! 1. Read data from input file 935 !============================================================================== 936 937 ! hybrid coordinate aps 938 allocate(aps(altlen),stat=ierr) 939 if (ierr.ne.0) then 940 write(*,*) "init2: failed to allocate aps(altlen)" 941 stop 942 endif 943 944 ierr=NF_INQ_VARID(infid,"aps",tmpvarid) 945 if (ierr.ne.NF_NOERR) then 946 write(*,*) "oops Failed to get aps ID. OK" 947 aps_ok=.false. 948 else 949 ! Check that aps() is the right size (it most likely won't be if 950 ! zrecast has be used to generate the input file) 951 ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid) 952 ierr=NF_INQ_DIMLEN(infid,tmpdimid,tmplen) 953 if (tmplen.ne.altlen) then 954 write(*,*) "tmplen,altlen", tmpdimid, altdimid 955 write(*,*) "init2: wrong dimension size for aps(), skipping it ..." 956 aps_ok=.false. 957 else 958 ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps) 959 if (ierr.ne.NF_NOERR) then 960 stop "init2 error: Failed reading aps" 961 aps_ok=.false. 962 endif 963 aps_ok=.true. 964 endif 965 endif 966 967 ! hybrid coordinate bps 968 allocate(bps(altlen),stat=ierr) 969 if (ierr.ne.0) then 970 write(*,*) "init2: failed to allocate bps(altlen)" 971 stop 972 endif 973 974 ierr=NF_INQ_VARID(infid,"bps",tmpvarid) 975 if (ierr.ne.NF_NOERR) then 976 write(*,*) "oops: Failed to get bps ID. OK" 977 bps_ok=.false. 978 else 979 ! Check that bps() is the right size 980 ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid) 981 ierr=NF_INQ_DIMLEN(infid,tmpdimid,tmplen) 982 if (tmplen.ne.altlen) then 983 write(*,*) "init2: wrong dimension size for bps(), skipping it ..." 984 bps_ok=.false. 985 else 986 ierr=NF_GET_VAR_REAL(infid,tmpvarid,bps) 987 if (ierr.ne.NF_NOERR) then 988 stop "init2 Error: Failed reading bps" 989 bps_ok=.false. 990 endif 991 bps_ok=.true. 992 endif 993 endif 994 995 ! ground geopotential phisinit 996 allocate(phisinit(lonlen,latlen),stat=ierr) 997 if (ierr.ne.0) then 998 write(*,*) "init2: failed to allocate phisinit(lonlen,latlen)" 999 stop 1000 endif 1001 ierr=NF_INQ_VARID(infid,"phisinit",tmpvarid) 1002 if (ierr.ne.NF_NOERR) then 1003 write(*,*) "Failed to get phisinit ID. OK" 1004 phisinit = 0. 1005 phis = .false. 1006 else 1007 ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit) 1008 if (ierr.ne.NF_NOERR) then 1009 stop "init2 Error: Failed reading phisinit" 1010 endif 1011 phis = .true. 1012 endif 1013 1014 1015 !============================================================================== 1016 ! 2. Write 1017 !============================================================================== 1018 1019 !============================================================================== 1020 ! 2.2. Hybrid coordinates aps() and bps() 1021 !============================================================================== 1022 1023 IF (aps_ok) then 1024 ! define aps 1025 call def_var(outfid,"aps","hybrid pressure at midlayers"," ",1,& 1026 (/altdimout/),apsid,ierr) 1027 if (ierr.ne.NF_NOERR) then 1028 stop "Error: Failed to def_var aps" 1029 endif 1030 1031 ! write aps 1032 ierr=NF_PUT_VAR_REAL(outfid,apsid,aps) 1033 if (ierr.ne.NF_NOERR) then 1034 stop "Error: Failed to write aps" 1035 endif 1036 ENDIF ! of IF (aps_ok) 1037 1038 IF (bps_ok) then 1039 ! define bps 1040 call def_var(outfid,"bps","hybrid sigma at midlayers"," ",1,& 1041 (/altdimout/),bpsid,ierr) 1042 if (ierr.ne.NF_NOERR) then 1043 stop "Error: Failed to def_var bps" 1044 endif 1045 1046 ! write bps 1047 ierr=NF_PUT_VAR_REAL(outfid,bpsid,bps) 1048 if (ierr.ne.NF_NOERR) then 1049 stop "Error: Failed to write bps" 1050 endif 1051 ENDIF ! of IF (bps_ok) 1052 1053 !============================================================================== 1054 ! 2.2. phisinit() 1055 !============================================================================== 1056 1057 IF (phis) THEN 1058 1059 !define phisinit 1060 call def_var(outfid,"phisinit","Ground level geopotential"," ",2,& 1061 (/londimout,latdimout/),phisinitid,ierr) 1062 if (ierr.ne.NF_NOERR) then 1063 stop "Error: Failed to def_var phisinit" 1064 endif 1065 1066 ! write phisinit 1067 ierr=NF_PUT_VAR_REAL(outfid,phisinitid,phisinit) 1068 if (ierr.ne.NF_NOERR) then 1069 stop "Error: Failed to write phisinit" 1070 endif 1071 1072 ENDIF ! of IF (phis) 1073 1074 1075 ! Cleanup 1076 deallocate(aps) 1077 deallocate(bps) 1078 deallocate(phisinit) 1079 1080 end subroutine init2 1081 1082 !****************************************************************************** 770 1083 subroutine def_var(nid,name,title,units,nbdim,dim,nvarid,ierr) 771 1084 !============================================================================== … … 816 1129 817 1130 end subroutine def_var 818 !************************************ 1131 1132 !****************************************************************************** 1133 subroutine missing_value(nout,nvarid,missing) 1134 !============================================================================== 1135 ! Purpose: 1136 ! Write "valid_range" and "missing_value" attributes (of a given 1137 ! variable) to a netcdf file 1138 !============================================================================== 1139 ! Remarks: 1140 ! NetCDF file must be open 1141 ! Variable (nvarid) ID must be set 1142 !============================================================================== 1143 1144 implicit none 1145 1146 include "netcdf.inc" ! NetCDF definitions 1147 1148 !============================================================================== 1149 ! Arguments: 1150 !============================================================================== 1151 integer, intent(in) :: nout 1152 ! nout: [netcdf] file ID # 1153 integer, intent(in) :: nvarid 1154 ! varid: [netcdf] variable ID # 1155 !real, dimension(2), intent(in) :: valid_range 1156 ! valid_range(2): [netcdf] "valid_range" attribute (min and max) 1157 real, intent(in) :: missing 1158 ! missing: [netcdf] "missing_value" attribute 1159 1160 !============================================================================== 1161 ! Local variables: 1162 !============================================================================== 1163 integer :: ierr 1164 ! ierr: [netcdf] subroutine returned error code 1165 ! INTEGER nout,nvarid,ierr 1166 ! REAL missing 1167 ! REAL valid_range(2) 1168 1169 ! Switch to netcdf dataset define mode 1170 ierr = NF_REDEF (nout) 1171 if (ierr.ne.NF_NOERR) then 1172 print*,'missing_value: ' 1173 print*, NF_STRERROR(ierr) 1174 endif 1175 1176 1177 !********* valid range not used in Lslin **************** 1178 ! Write valid_range() attribute 1179 !ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range) 1180 ! 1181 !if (ierr.ne.NF_NOERR) then 1182 ! print*,'missing_value: valid_range attribution failed' 1183 ! print*, NF_STRERROR(ierr) 1184 ! !write(*,*) 'NF_NOERR', NF_NOERR 1185 ! !CALL abort 1186 ! stop "" 1187 !endif 1188 !********************************************************* 1189 1190 ! Write "missing_value" attribute 1191 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing) 1192 if (ierr.NE.NF_NOERR) then 1193 print*, 'missing_value: missing value attribution failed' 1194 print*, NF_STRERROR(ierr) 1195 ! WRITE(*,*) 'NF_NOERR', NF_NOERR 1196 ! CALL abort 1197 stop "" 1198 endif 1199 1200 ! End netcdf dataset define mode 1201 ierr = NF_ENDDEF(nout) 1202 1203 end subroutine missing_value 1204 1205 !****************************************************************************** 819 1206 subroutine sol2ls(sol,Ls) 820 1207 !============================================================================== … … 921 1308 integer nd 922 1309 ! internal 923 integer i ,j1310 integer i 924 1311 real y_undefined 925 1312 … … 955 1342 end subroutine interpolf 956 1343 957 end 958 959 960 961 !****************************************************************************** 962 !****************************************************************************** 963 subroutine missing_value(nout,nvarid,valid_range,missing) 964 !============================================================================== 965 ! Purpose: 966 ! Write "valid_range" and "missing_value" attributes (of a given 967 ! variable) to a netcdf file 968 !============================================================================== 969 ! Remarks: 970 ! NetCDF file must be open 971 ! Variable (nvarid) ID must be set 972 !============================================================================== 973 974 implicit none 975 976 include "netcdf.inc" ! NetCDF definitions 977 978 !============================================================================== 979 ! Arguments: 980 !============================================================================== 981 integer, intent(in) :: nout 982 ! nout: [netcdf] file ID # 983 integer, intent(in) :: nvarid 984 ! varid: [netcdf] variable ID # 985 real, dimension(2), intent(in) :: valid_range 986 ! valid_range(2): [netcdf] "valid_range" attribute (min and max) 987 real, intent(in) :: missing 988 ! missing: [netcdf] "missing_value" attribute 989 990 !============================================================================== 991 ! Local variables: 992 !============================================================================== 993 integer :: ierr 994 ! ierr: [netcdf] subroutine returned error code 995 ! INTEGER nout,nvarid,ierr 996 ! REAL missing 997 ! REAL valid_range(2) 998 999 ! Switch to netcdf dataset define mode 1000 ierr = NF_REDEF (nout) 1001 if (ierr.ne.NF_NOERR) then 1002 print*,'missing_value: ' 1003 print*, NF_STRERROR(ierr) 1004 endif 1005 1006 ! Write valid_range() attribute 1007 #ifdef NC_DOUBLE 1008 ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range) 1009 #else 1010 ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range) 1011 #endif 1012 1013 if (ierr.ne.NF_NOERR) then 1014 print*,'missing_value: valid_range attribution failed' 1015 print*, NF_STRERROR(ierr) 1016 !write(*,*) 'NF_NOERR', NF_NOERR 1017 !CALL abort 1018 stop "" 1019 endif 1020 1021 ! Write "missing_value" attribute 1022 #ifdef NC_DOUBLE 1023 ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing) 1024 #else 1025 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing) 1026 #endif 1027 1028 if (ierr.NE.NF_NOERR) then 1029 print*, 'missing_value: missing value attribution failed' 1030 print*, NF_STRERROR(ierr) 1031 ! WRITE(*,*) 'NF_NOERR', NF_NOERR 1032 ! CALL abort 1033 stop "" 1034 endif 1035 1036 ! End netcdf dataset define mode 1037 ierr = NF_ENDDEF(nout) 1038 1039 end subroutine missing_value 1040 !****************************************************************************** 1344 end program lslin -
trunk/LMDZ.MARS/util/zrecast.F90
r2401 r2432 61 61 ! TN 01/2013 : Adapted for large output files with at least 2 variables > 2 GiB 62 62 ! TN 10/2013 : Read and write controle field, if available 63 ! FF 10/2020 : Force interpolation in log space for variable starting by "rho" 63 64 ! 64 65 implicit none … … 94 95 integer,dimension(3) :: surfdatashape ! shape of 3D (surface+time) datasets 95 96 96 real :: miss_val= -9.99e+33! special "missing value" to specify missing data97 real,parameter :: miss_val_def= -9.99e+33! default value for "missing value"97 real :: miss_val= 1.E+20 ! special "missing value" to specify missing data 98 real,parameter :: miss_val_def= 1.E+20 ! default value for "missing value" 98 99 character (len=64), dimension(:), allocatable :: var 99 100 ! var(): names of variables that will be processed … … 1809 1810 ! interpolate dataset onto new grid 1810 1811 ! check if variable is "rho" (to set flag for interpolation below) 1811 if (var(i) .eq.'rho') then1812 if (var(i)(1:3).eq.'rho') then 1812 1813 j=1 1814 write(*,*) trim(var(i)), ' is interpolated in log scale' 1813 1815 else 1814 1816 j=0 … … 1864 1866 ! interpolate dataset onto new grid 1865 1867 ! check if variable is "rho" (to set flag for interpolation below) 1866 if (var(i) .eq.'rho') then1868 if (var(i)(1:3).eq.'rho') then 1867 1869 j=1 1870 write(*,*) trim(var(i)), ' is interpolated in log scale' 1868 1871 else 1869 1872 j=0 … … 1919 1922 ! interpolate dataset onto new grid 1920 1923 ! check if variable is "rho" (to set flag for interpolation below) 1921 if (var(i) .eq.'rho') then1924 if (var(i)(1:3).eq.'rho') then 1922 1925 j=1 1926 write(*,*) trim(var(i)), ' is interpolated in log scale' 1923 1927 else 1924 1928 j=0
Note: See TracChangeset
for help on using the changeset viewer.