Changeset 2975 for trunk/LMDZ.MARS/util/expandstartfi.F90
- Timestamp:
- May 30, 2023, 5:35:09 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/expandstartfi.F90
r1469 r2975 20 20 integer :: varid ! to store the ID of a variable 21 21 integer :: datashape(4) ! to store dimension IDs of a given dataset 22 integer :: corner( 3),edges(3) ! to read data with a time axis22 integer :: corner(4),edges(4) ! to read data with a time axis 23 23 character(len=90) :: varname ! name of a variable 24 24 character(len=90) :: varatt ! name of attribute of a variable … … 28 28 integer :: subsurface_layers_dimid 29 29 integer :: nlayer_plus_1_dimid 30 integer :: nslope_dimid 30 31 integer :: number_of_advected_fields_dimid 31 32 integer :: time_dimid … … 37 38 integer :: subsurface_layers 38 39 integer :: nlayer_plus_1 40 integer :: nslope 39 41 integer :: number_of_advected_fields 40 42 integer :: timelen 41 43 real,allocatable :: surf_field(:) ! to store a 1D field of physical_points elements 42 44 real,allocatable :: subsurf_field(:,:) ! to store subsurface (2D field) 45 real,allocatable :: subslope_field(:,:) 46 real,allocatable :: nlayer_plus_1_field(:,:) 47 real,allocatable :: subsurf_subslope_field(:,:,:) 43 48 44 49 ! Output file dimensions: … … 51 56 real,allocatable :: out_surf_field(:,:) 52 57 real,allocatable :: out_subsurf_field(:,:,:) 58 real,allocatable :: out_subslope_field(:,:,:) 59 real,allocatable :: out_nlayer_plus_1_field(:,:,:) 60 real,allocatable :: out_subsurf_subslope_field(:,:,:,:) 53 61 ! Output file dimension IDs 54 62 integer :: lon_dimid 55 63 integer :: lat_dimid 56 64 integer :: depth_dimid 65 integer :: nslope_out_dimid 66 integer :: nlayer_plus_1_out_dimid 57 67 ! IDs of Output file variables 58 68 integer :: lon_varid … … 143 153 endif 144 154 145 status=nf90_inq_dimid(inid,"n umber_of_advected_fields",number_of_advected_fields_dimid)146 if (status.ne.nf90_noerr) then 147 write(*,*)"Failed to find number_of_advected_fields dimension"148 write(*,*)trim(nf90_strerror(status))149 stop150 e ndif151 status=nf90_inquire_dimension(inid,n umber_of_advected_fields_dimid,len=number_of_advected_fields)152 if (status.ne.nf90_noerr) then 153 write(*,*)"Failed to find n umber_of_advected_fieldsvalue"155 status=nf90_inq_dimid(inid,"nslope",nslope_dimid) 156 if (status.ne.nf90_noerr) then 157 write(*,*)"Failed to find slope dimension, old startfi file" 158 nslope=0 159 write(*,*)trim(nf90_strerror(status)) 160 else 161 status=nf90_inquire_dimension(inid,nslope_dimid,len=nslope) 162 if (status.ne.nf90_noerr) then 163 write(*,*)"Failed to find nslope value" 154 164 write(*,*)trim(nf90_strerror(status)) 155 165 stop 156 166 else 157 write(*,*) " number_of_advected_fields = ",number_of_advected_fields 167 write(*,*) " nslope = ",nslope 168 endif 158 169 endif 159 170 … … 177 188 allocate(surf_field(physical_points)) 178 189 allocate(subsurf_field(physical_points,subsurface_layers)) 190 allocate(subslope_field(physical_points,nslope)) 191 allocate(nlayer_plus_1_field(physical_points,nlayer_plus_1)) 192 allocate(subsurf_subslope_field(physical_points,subsurface_layers,nslope)) 179 193 180 194 ! 2.1. Create output file … … 296 310 stop 297 311 endif 312 ! nslope: 313 status=nf90_def_dim(outid,"nslope",nslope,nslope_out_dimid) 314 if (status.ne.nf90_noerr) then 315 write(*,*) "Failed creating nslope dimension" 316 write(*,*)trim(nf90_strerror(status)) 317 stop 318 endif 319 ! nslope: 320 status=nf90_def_dim(outid,"nlayer_plus_1",nlayer_plus_1,nlayer_plus_1_out_dimid) 321 if (status.ne.nf90_noerr) then 322 write(*,*) "Failed creating nslope dimension" 323 write(*,*)trim(nf90_strerror(status)) 324 stop 325 endif 298 326 299 327 !2.3. write variables to output file … … 379 407 380 408 allocate(out_surf_field(lonlen,latlen)) 381 382 shape(:) = 0 409 allocate(out_subsurf_field(lonlen,latlen,subsurface_layers)) 410 allocate(out_subslope_field(lonlen,latlen,nslope)) 411 allocate(out_nlayer_plus_1_field(lonlen,latlen,nlayer_plus_1)) 412 allocate(out_subsurf_subslope_field(lonlen,latlen,subsurface_layers,nslope)) 413 383 414 do ivar=1,nbinvars ! loop on all input variables 415 shape(:) = 0 384 416 ! find out what dimensions are linked to this variable 385 417 status=nf90_inquire_variable(inid,ivar,name=varname,ndims=nbdim,& 386 418 dimids=shape,natts=nbatt) 419 387 420 if (((nbdim==1).and.(shape(1)==physical_points_dimid))& 388 421 .or.((nbdim==2).and.(shape(1)==physical_points_dimid)& … … 473 506 endif 474 507 endif ! of if ((nbdim==1).and.(shape(1)==physical_points_dimid)) 475 enddo ! of do i=1,nbinvars 476 477 ! 2.4. 3D (subsurface) variables 478 allocate(out_subsurf_field(lonlen,latlen,subsurface_layers)) 479 480 do ivar=1,nbinvars ! loop on all input variables 481 ! find out what dimensions are linked to this variable 482 status=nf90_inquire_variable(inid,ivar,name=varname,ndims=nbdim,& 483 dimids=shape,natts=nbatt) 484 if (((nbdim==2).and.(shape(1)==physical_points_dimid)& 485 .and.(shape(2)==subsurface_layers_dimid))& 486 .or.((nbdim==3).and.(shape(1)==physical_points_dimid)& 487 .and.(shape(2)==subsurface_layers_dimid)& 488 .and.(shape(3)==time_dimid))) then 508 509 if ((nbdim==2).and.(shape(1)==physical_points_dimid)& 510 .and.(shape(2)==subsurface_layers_dimid)) then 489 511 490 512 corner(1) = 1 … … 570 592 endif 571 593 endif ! of if ((nbdim==1).and.(shape(1)==physical_points_dimid)...) 594 595 596 597 598 if ((nbdim==3).and.(shape(1)==physical_points_dimid)& 599 .and.(shape(2)==nslope_dimid)) then 600 601 corner(1) = 1 602 corner(2) = 1 603 corner(3) = timelen 604 edges(1) = physical_points 605 edges(2) = nslope 606 edges(3) = 1 607 608 write(*,*) " processing: ",trim(varname) 609 610 ! load input data: 611 status=nf90_inq_varid(inid,varname,invarid) 612 status=nf90_get_var(inid,invarid,subslope_field,corner,edges) 613 614 ! switch output file to to define mode 615 status=nf90_redef(outid) 616 if (status.ne.nf90_noerr) then 617 write(*,*) "Failed to swich to define mode" 618 write(*,*)trim(nf90_strerror(status)) 619 stop 620 endif 621 !define the variable 622 status=nf90_def_var(outid,trim(varname),NF90_REAL,& 623 (/lon_dimid,lat_dimid,nslope_out_dimid/),varid) 624 if (status.ne.nf90_noerr) then 625 write(*,*) "Failed creating variable ",trim(varname) 626 write(*,*)trim(nf90_strerror(status)) 627 stop 628 endif 629 630 ! variable attributes 631 do k=1,nbatt 632 status=nf90_inq_attname(inid,invarid,k,varatt) 633 if (status.ne.nf90_noerr) then 634 write(*,*) "Failed getting attribute number",k," for ",trim(varname) 635 write(*,*)trim(nf90_strerror(status)) 636 stop 637 endif 638 status=nf90_get_att(inid,invarid,trim(varatt),varattcontent) 639 if (status.ne.nf90_noerr) then 640 write(*,*) "Failed loading attribute ",trim(varatt) 641 write(*,*)trim(nf90_strerror(status)) 642 stop 643 endif 644 645 ! write the attribute and its value to output 646 status=nf90_put_att(outid,varid,trim(varatt),trim(varattcontent)) 647 if (status.ne.nf90_noerr) then 648 write(*,*) "Failed writing attribute ",trim(varatt) 649 write(*,*)trim(nf90_strerror(status)) 650 stop 651 endif 652 enddo ! do k=1,nbatt 653 654 ! swich out of NetCDF define mode 655 status=nf90_enddef(outid) 656 if (status.ne.nf90_noerr) then 657 write(*,*) "Failed to swich out of define mode" 658 write(*,*)trim(nf90_strerror(status)) 659 stop 660 endif 661 662 ! "convert" from subsurf_field(:,:) to out_subslope_field(:,:,:) 663 do i=1,lonlen 664 out_subslope_field(i,1,:)=subslope_field(1,:) ! North Pole 665 out_subslope_field(i,latlen,:)=subslope_field(physical_points,:) ! South Pole 666 enddo 667 do j=2,latlen-1 668 ig0=1+(j-2)*(lonlen-1) 669 do i=1,lonlen-1 670 out_subslope_field(i,j,:)=subslope_field(ig0+i,:) 671 enddo 672 out_subslope_field(lonlen,j,:)=out_subslope_field(1,j,:) ! redundant lon=180 673 enddo 674 675 ! write the variable 676 status=nf90_put_var(outid,varid,out_subslope_field) 677 if (status.ne.nf90_noerr) then 678 write(*,*) "Failed to write ",trim(varname) 679 write(*,*)trim(nf90_strerror(status)) 680 stop 681 endif 682 endif ! of if ((nbdim==1).and.(shape(1)==physical_points_dimid)...) 683 684 685 686 687 688 if ((nbdim==3).and.(shape(1)==physical_points_dimid)& 689 .and.(shape(2)==nlayer_plus_1_dimid)) then 690 691 corner(1) = 1 692 corner(2) = 1 693 corner(3) = timelen 694 edges(1) = physical_points 695 edges(2) = nlayer_plus_1 696 edges(3) = 1 697 698 write(*,*) " processing: ",trim(varname) 699 700 ! load input data: 701 status=nf90_inq_varid(inid,varname,invarid) 702 status=nf90_get_var(inid,invarid,nlayer_plus_1_field,corner,edges) 703 704 ! switch output file to to define mode 705 status=nf90_redef(outid) 706 if (status.ne.nf90_noerr) then 707 write(*,*) "Failed to swich to define mode" 708 write(*,*)trim(nf90_strerror(status)) 709 stop 710 endif 711 !define the variable 712 status=nf90_def_var(outid,trim(varname),NF90_REAL,& 713 (/lon_dimid,lat_dimid,nlayer_plus_1_out_dimid/),varid) 714 if (status.ne.nf90_noerr) then 715 write(*,*) "Failed creating variable ",trim(varname) 716 write(*,*)trim(nf90_strerror(status)) 717 stop 718 endif 719 720 ! variable attributes 721 do k=1,nbatt 722 status=nf90_inq_attname(inid,invarid,k,varatt) 723 if (status.ne.nf90_noerr) then 724 write(*,*) "Failed getting attribute number",k," for ",trim(varname) 725 write(*,*)trim(nf90_strerror(status)) 726 stop 727 endif 728 status=nf90_get_att(inid,invarid,trim(varatt),varattcontent) 729 if (status.ne.nf90_noerr) then 730 write(*,*) "Failed loading attribute ",trim(varatt) 731 write(*,*)trim(nf90_strerror(status)) 732 stop 733 endif 734 735 ! write the attribute and its value to output 736 status=nf90_put_att(outid,varid,trim(varatt),trim(varattcontent)) 737 if (status.ne.nf90_noerr) then 738 write(*,*) "Failed writing attribute ",trim(varatt) 739 write(*,*)trim(nf90_strerror(status)) 740 stop 741 endif 742 enddo ! do k=1,nbatt 743 744 ! swich out of NetCDF define mode 745 status=nf90_enddef(outid) 746 if (status.ne.nf90_noerr) then 747 write(*,*) "Failed to swich out of define mode" 748 write(*,*)trim(nf90_strerror(status)) 749 stop 750 endif 751 752 ! "convert" from subsurf_field(:,:) to out_nlayer_plus_1_field(:,:,:) 753 do i=1,lonlen 754 out_nlayer_plus_1_field(i,1,:)=nlayer_plus_1_field(1,:) ! North Pole 755 out_nlayer_plus_1_field(i,latlen,:)=nlayer_plus_1_field(physical_points,:) ! South Pole 756 enddo 757 do j=2,latlen-1 758 ig0=1+(j-2)*(lonlen-1) 759 do i=1,lonlen-1 760 out_nlayer_plus_1_field(i,j,:)=nlayer_plus_1_field(ig0+i,:) 761 enddo 762 out_nlayer_plus_1_field(lonlen,j,:)=out_nlayer_plus_1_field(1,j,:) ! redundant lon=180 763 enddo 764 765 ! write the variable 766 status=nf90_put_var(outid,varid,out_nlayer_plus_1_field) 767 if (status.ne.nf90_noerr) then 768 write(*,*) "Failed to write ",trim(varname) 769 write(*,*)trim(nf90_strerror(status)) 770 stop 771 endif 772 endif ! of if ((nbdim==1).and.(shape(1)==physical_points_dimid)...) 773 774 775 776 777 if (nbdim==4) then 778 779 corner(1) = 1 780 corner(2) = 1 781 corner(3) = 1 782 corner(4) = timelen 783 edges(1) = physical_points 784 edges(2) = subsurface_layers 785 edges(3) = nslope 786 edges(4) = 1 787 788 write(*,*) " processing: ",trim(varname) 789 790 ! load input data: 791 status=nf90_inq_varid(inid,varname,invarid) 792 status=nf90_get_var(inid,invarid,subsurf_subslope_field,corner,edges) 793 794 ! switch output file to to define mode 795 status=nf90_redef(outid) 796 if (status.ne.nf90_noerr) then 797 write(*,*) "Failed to swich to define mode" 798 write(*,*)trim(nf90_strerror(status)) 799 stop 800 endif 801 !define the variable 802 print *, "subsurface_layers_dimid", subsurface_layers_dimid 803 print *, "nslope_out_dimid", nslope_out_dimid 804 status=nf90_def_var(outid,trim(varname),NF90_REAL,& 805 (/lon_dimid,lat_dimid,depth_dimid,nslope_out_dimid/),varid) 806 if (status.ne.nf90_noerr) then 807 write(*,*) "Failed creating variable ",trim(varname) 808 write(*,*)trim(nf90_strerror(status)) 809 stop 810 endif 811 812 ! variable attributes 813 do k=1,nbatt 814 status=nf90_inq_attname(inid,invarid,k,varatt) 815 if (status.ne.nf90_noerr) then 816 write(*,*) "Failed getting attribute number",k," for ",trim(varname) 817 write(*,*)trim(nf90_strerror(status)) 818 stop 819 endif 820 status=nf90_get_att(inid,invarid,trim(varatt),varattcontent) 821 if (status.ne.nf90_noerr) then 822 write(*,*) "Failed loading attribute ",trim(varatt) 823 write(*,*)trim(nf90_strerror(status)) 824 stop 825 endif 826 827 ! write the attribute and its value to output 828 status=nf90_put_att(outid,varid,trim(varatt),trim(varattcontent)) 829 if (status.ne.nf90_noerr) then 830 write(*,*) "Failed writing attribute ",trim(varatt) 831 write(*,*)trim(nf90_strerror(status)) 832 stop 833 endif 834 enddo ! do k=1,nbatt 835 836 ! swich out of NetCDF define mode 837 status=nf90_enddef(outid) 838 if (status.ne.nf90_noerr) then 839 write(*,*) "Failed to swich out of define mode" 840 write(*,*)trim(nf90_strerror(status)) 841 stop 842 endif 843 844 ! "convert" from subsurf_field(:,:) to out_subsurf_subslope_field(:,:,:) 845 do i=1,lonlen 846 out_subsurf_subslope_field(i,1,:,:)=subsurf_subslope_field(1,:,:) ! North Pole 847 out_subsurf_subslope_field(i,latlen,:,:)=subsurf_subslope_field(physical_points,:,:) ! South Pole 848 enddo 849 do j=2,latlen-1 850 ig0=1+(j-2)*(lonlen-1) 851 do i=1,lonlen-1 852 out_subsurf_subslope_field(i,j,:,:)=subsurf_subslope_field(ig0+i,:,:) 853 enddo 854 out_subsurf_subslope_field(lonlen,j,:,:)=out_subsurf_subslope_field(1,j,:,:) ! redundant lon=180 855 enddo 856 857 ! write the variable 858 status=nf90_put_var(outid,varid,out_subsurf_subslope_field) 859 if (status.ne.nf90_noerr) then 860 write(*,*) "Failed to write ",trim(varname) 861 write(*,*)trim(nf90_strerror(status)) 862 stop 863 endif 864 endif ! of if ((nbdim==1).and.(shape(1)==physical_points_dimid)...) 865 866 867 572 868 enddo ! of do i=1,nbinvars 573 574 869 575 870 ! 3. Finish things and cleanup … … 582 877 endif 583 878 879 write(*,*)"Done writing file ",trim(outfile) 880 584 881 end program expandstartfi
Note: See TracChangeset
for help on using the changeset viewer.