Changeset 2432 for trunk/LMDZ.MARS/util/lslin.F90
- Timestamp:
- Nov 14, 2020, 3:27:44 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.