- Timestamp:
- Nov 17, 2020, 1:36:34 PM (4 years ago)
- Location:
- trunk/LMDZ.MARS
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/README
r2432 r2434 3206 3206 concentration in mol.cm-3 etc..). Set missing value to 1.E20 3207 3207 lslin.F90: fix various problems in the output. 3208 3209 == 17/11/2020 == FF + AB 3210 Update utilities : 3211 concat.F90 3212 - rewrite and simplify the handling of time and offset so that any file 3213 can be concatenated, including files from different years or stats file 3214 - use modulo to shift starting sols in concat.nc to values between 0 and 669 3215 - add a "adls" option in addition to "sol" or "ls" to add a Ls 1D variable 3216 while keeping "sol" as the Time axis 3217 - add conservation of altitude attributes (long_name,units,positive) 3218 - enable absence of both hybrid (aps,bps) and sigma levels 3219 3220 solzenangle.F90 3221 - improve calculation for 1 sol file (stats) to use all local time data 3222 - read the starting sol in the file instead of asking it to the user 3223 (except for stats file) ; keep the possibility for user to change it 3224 - ask mean Ls value for stats file instead of sol number 3225 - fix crash when using "all variable" option (ticket #66) 3226 - fix bug on aps,bps by using GCM_layers dimension instead of altitude 3227 3228 localtime.F90 3229 - fix crash when using "all variable" option (ticket #66) 3230 - fix bug on aps,bps by using GCM_layers dimension instead of altitude 3231 3232 For all 3 utilities : 3233 - handle all ndim cases for the variables (ticket #52) 3234 - change "title" attribute into "long_name" by default (ticket #48) 3235 - extend size of long_name character string (ticket #57) 3236 - remove the use of #ifdef NC_DOUBLE (ticket #67) -
trunk/LMDZ.MARS/util/concatnc.F90
r2395 r2434 34 34 character (len=50), dimension(:), allocatable :: var 35 35 ! var(): name(s) of variable(s) that will be concatenated 36 character (len= 50) :: tmpvar,tmpfile,title,units36 character (len=100) :: tmpvar,tmpfile,long_name,units 37 37 ! tmpvar(): used to temporarily store a variable name 38 38 ! tmpfile(): used to temporarily store a file name 39 ! title(): [netcdf] title attribute39 ! long_name(): [netcdf] long_name attribute 40 40 ! units(): [netcdf] units attribute 41 41 character (len=100) :: filename,vartmp 42 42 ! filename(): output file name 43 43 ! vartmp(): temporary variable name (read from netcdf input file) 44 !character (len=1) :: ccopy 45 ! ccpy: 'y' or 'n' answer 44 character (len=50) :: altlong_name,altunits,altpositive 45 ! altlong_name(): [netcdf] altitude "long_name" attribute 46 ! altunits(): [netcdf] altitude "units" attribute 47 ! altpositive(): [netcdf] altitude "positive" attribute 46 48 character (len=4) :: axis 47 ! axis: "ls" or "sol"49 ! axis: "sol" or "ls" or "adls" 48 50 integer :: nid,ierr,miss 49 51 ! nid: [netcdf] file ID # … … 115 117 real :: ctlsol 116 118 ! ctlsol: starting sol value of the file, stored in the variable ctl() 117 real :: memotime 118 ! memotime: (cumulative) time value, in martian days (sols) 119 real :: previous_last_output_time, output_time 120 ! previous_last_output_time: last time stored in concat.nc after treating a file 121 logical :: firstsol 122 ! firstsol: true if the first file's starting day must be used in the output 123 real :: startsol 124 ! startsol: sol of the firstday as requested by the users (used if firstsol="y") 119 125 real :: starttimeoffset 120 ! starttimeoffset: offset given by the user for the output time axis 121 character (len=1) :: firstsol 122 ! firstsol: =[y/n], to know whether the user offset or the first file's starting day must be used in the output 126 ! starttimeoffset: offset given by the user for the output time axis (0 if ! firstsol="n") 123 127 real :: missing 124 128 !PARAMETER(missing=1E+20) … … 126 130 real, dimension(2) :: valid_range 127 131 ! valid_range(2): [netcdf] interval in which a value is considered valid 132 real :: year_day = 669. 128 133 129 134 !============================================================================== … … 154 159 !============================================================================== 155 160 156 write(*,*) 157 write(*,*) "Starting day to be stored in the output file time axis?"158 write(*,*) "(e.g.: 100 if you want the output file to start at time=100 sols)"159 write(*,*) "Your answer will bypass any starting day value stored in the 1st" 160 write(*,*) "input file. Conversely, just type return if you want this 1st file's" 161 write(*,*) "value to be kept for the output file starting day." 162 read(*,*,iostat=ierr) starttimeoffset 163 if ( ierr.ne.0) then161 write(*,*) "Starting time in the concat file ?" 162 write(*,*) " If you really wish to change it, write it now (not recommanded!)" 163 write(*,*) " If you do not want to change it, just write 'n' (recommanded)" 164 165 read(*,*,iostat=ierr) startsol 166 167 firstsol= (ierr.eq.0) 168 if (firstsol) then 164 169 ! if nothing or a character that is not a float is read 165 170 write(*,*) "1st input file's starting day will serve as starting day for the outfile." 166 firstsol='n'167 171 else ! if the user gave a number 168 172 write(*,*) "Your input day will serve as starting day for the outfile." 169 firstsol='y'170 173 endif 171 174 … … 190 193 191 194 write(*,*) 192 write(*,*) "W arning: to read the result with grads, choose sol"193 write(*,*) " Warning: use ferret to read the non linear scale ls"194 write(*,*) " Which time axis should be given in the output? (sol/ls)"195 write(*,*) "Which time axis should be given in the output? (sol/ls/adls)" 196 write(*,*) " (Warning: to read the result with grads, choose sol)" 197 write(*,*) " To keep sol as the time axis, and just add Ls as a variable, type adls " 195 198 read(*,*) axis 196 199 ! loop as long as axis is neither "sol" nor "ls" 197 do while ((axis/="sol").AND.(axis/="ls") )200 do while ((axis/="sol").AND.(axis/="ls").AND.(axis/="adls")) 198 201 read(*,*) axis 199 202 enddo … … 255 258 if (tmpvar=="all") then 256 259 if (axis=="ls") then 257 ! write(*,*) "Do you want to keep the original file? (y/n)"258 ! read(*,*) ccopy259 ! if ((ccopy=="n").or.(ccopy=="N")) then260 ! do i=1,nbfile261 ! ierr=NF_CLOSE(nid)262 ! ierr = NF_OPEN(file(1),NF_WRITE,nid)263 ! call change_time_axis(nid,ierr)264 ! ierr=NF_CLOSE(nid)265 ! STOP ""266 ! enddo267 ! else268 260 nbvar=nbvarfile-Nnotconcat 269 261 do j=Nnotconcat+1,nbvarfile 270 262 ierr=nf_inq_varname(nid,j,var(j-Nnotconcat)) 271 263 enddo 272 ! endif ! of if ((ccopy=="n").or.(ccopy=="N"))273 264 endif ! of if (axis=="ls") 274 265 ! Variables names from the file are catched … … 394 385 endif 395 386 endif 396 ! write(*,*) "controle: ",controle397 387 398 388 if (ctllen .ne. 0) then ! variable controle 399 389 allocate(ctl(ctllen)) 400 #ifdef NC_DOUBLE401 ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)402 #else403 390 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 404 #endif405 391 ctlsol = ctl(4) 406 392 endif … … 425 411 allocate(time(timelen)) 426 412 427 #ifdef NC_DOUBLE428 ierr = NF_GET_VAR_DOUBLE(nid,timevar,time)429 #else430 413 ierr = NF_GET_VAR_REAL(nid,timevar,time) 431 #endif432 433 414 434 415 !============================================================================== … … 437 418 !============================================================================== 438 419 439 if (i==1) then ! First call; initialize/allocate420 if (i==1) then ! First File ; initialize/allocate 440 421 memolatlen=latlen 441 422 memolonlen=lonlen … … 445 426 allocate(lon(lonlen)) 446 427 allocate(alt(altlen)) 447 #ifdef NC_DOUBLE448 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)449 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)450 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)451 #else452 428 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 453 429 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 454 430 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 455 #endif 431 ! Get altitude attributes to handle files with any altitude type 432 ierr=nf_get_att_text(nid,altvar,'long_name',altlong_name) 433 if (ierr.ne.nf_noerr) then 434 ! if no attribute "long_name", try "title" 435 ierr=nf_get_att_text(nid,altvar,"title",altlong_name) 436 endif 437 ierr=nf_get_att_text(nid,altvar,'units',altunits) 438 ierr=nf_get_att_text(nid,altvar,'positive',altpositive) 456 439 write(*,*) 440 457 441 if (ctllen .ne. 0) then 458 if (int(starttimeoffset) .ne. (int(ctlsol)+int(time(1))) ) then 459 write(*,*) "WARNING: Starting day of the first file is not ",& 460 int(starttimeoffset)," but ",int(ctlsol)+int(time(1)),"!" 442 443 if (firstsol) then 444 starttimeoffset = float(int(ctlsol)+int(time(1) + ctl(27))) - startsol 445 else ! if firstsol.eq..false. 446 ! if there is no user chosen first sol, nevertheless use 447 ! starttimeoffset to lower the sol number (same exact season) 448 startsol = modulo(int(int(ctlsol)+int(time(1) + ctl(27))),int(year_day)) 449 starttimeoffset = float(int(ctlsol)+int(time(1) + ctl(27))) - startsol 461 450 endif 462 463 if (firstsol.eq.'y') then 464 starttimeoffset = float(int(ctlsol)+int(time(1))) + ctl(27) - starttimeoffset 465 else ! if firstsol.eq.'n' 466 starttimeoffset = 0 467 endif 468 469 memotime=float(int(ctlsol)+int(time(1))) + ctl(27) 451 452 ! artificially estimating "previous_last_output_time" for first file read: 453 previous_last_output_time= startsol 454 470 455 ctl(4) = 0. ! values written in the output 471 456 ctl(27) = 0. ! file controle variable (resp. day_ini and hour_ini) 472 457 473 458 else ! if no variable "controle" 474 if (int(starttimeoffset) .ne. (int(time(1))) ) then 475 write(*,*) "WARNING: Starting day of the first file is not ",& 476 int(starttimeoffset)," but ",int(time(1)),"!" 477 endif 478 479 if (firstsol.eq.'y') then 480 starttimeoffset = int(time(1)) - starttimeoffset 481 else ! if firstsol.eq.'n' 459 if (firstsol) then 460 starttimeoffset = int(time(1)) - startsol 461 else ! if firstsol.eq.false 482 462 starttimeoffset = 0 483 463 endif 484 464 485 memotime=float(int(time(1))) 465 ! artificially estimating "previous_last_output_time" for first file read: 466 previous_last_output_time=time(1) -(time(2) - time(1)) - starttimeoffset 486 467 endif 468 write(*,*) "Original starting day of 1st input file", previous_last_output_time + starttimeoffset 469 write(*,*) "Starting day of the concat file : ", previous_last_output_time 470 487 471 488 472 ! Initialize output file's lat,lon,alt and time dimensions 489 473 write(*,*) 490 call initiate(filename,lat,lon,alt,ctl,GCM_layers,nout,& 491 latdimout,londimout,altdimout,timedimout,& 474 call initiate(filename,lat,lon,alt,ctl,GCM_layers,& 475 altlong_name,altunits,altpositive,& 476 nout,latdimout,londimout,altdimout,timedimout,& 492 477 layerdimout,interlayerdimout,timevarout,axis) 493 478 ! Initialize output file's aps,bps,ap,bp and phisinit variables 494 call init2(nid,lonlen,latlen,altlen,GCM_layers,&479 call init2(nid,lonlen,latlen,altlen,GCM_layers,& 495 480 nout,londimout,latdimout,altdimout,& 496 481 layerdimout,interlayerdimout) 497 482 498 else ! Not a first call,483 else ! Not first file to concatenate 499 484 ! Check that latitude,longitude and altitude of current input file 500 485 ! are identical to those of the output file … … 521 506 522 507 rep=0 523 write(*,*) 524 write(*,'(a3,1x,f6.1)') "Sol",memotime-starttimeoffset 525 ! if (ctllen.ne.0) write(*,'(a30,1x,f6.1)') "In the current file's ctl: Sol",ctlsol 526 527 ! Add (memotime)/(ctlsol) offset and write "concatenated" time values to output file 528 if (ctllen.ne.0) then 529 do k=reptime+1,reptime+timelen 508 509 do k=reptime+1,reptime+timelen 530 510 rep=rep+1 531 if ((time(rep)+ctlsol).le.memotime) then 532 write(*,*) "ERROR : the time intervals of the files are not dissociated" 533 stop "" 534 endif 535 #ifdef NC_DOUBLE 536 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,ctlsol+time(rep)-starttimeoffset) 537 #else 538 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,ctlsol+time(rep)-starttimeoffset) 539 #endif 540 ! 541 enddo 542 543 ! Compute new time offset (for further concatenations) 544 memotime=ctlsol+time(timelen) ! the actual last day of the current file 545 ! becomes the reference time for next file 546 ! leaving potential "time holes" in the output time axis 547 ! at the junction of two files' time axes 548 549 else ! if no variable "controle" 550 551 do k=reptime+1,reptime+timelen 552 rep=rep+1 553 #ifdef NC_DOUBLE 554 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,memotime+time(rep)-int(time(1))-starttimeoffset) 555 #else 556 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,memotime+time(rep)-int(time(1))-starttimeoffset) 557 #endif 558 enddo 559 560 ! Compute new time offset (for further concatenations) 561 memotime=memotime+time(timelen)-time(1) ! files are concatenated one after another 562 ! even if their time axes normally don't 563 ! directly follow each other 564 endif ! if ctllen.ne.0 511 if (ctllen.ne.0) then 512 output_time=time(rep)+ctlsol-starttimeoffset 513 ! correction if the file to concatenate seems "before" previous file 514 ! (for instance to concatenate diagfi from the previous year at the enf of a year) 515 do while (output_time.lt.previous_last_output_time) 516 output_time = output_time + year_day 517 end do 518 else ! if no control, just add timestep after timestep 519 output_time= previous_last_output_time + (time(2)-time(1)) & 520 + (time(rep)-time(1)) 521 end if 522 if (rep.eq.1) write(*,*) "Sol", int(output_time) 523 524 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,output_time) 525 end do 526 ! use the last output_time value to update memotime 527 previous_last_output_time = output_time 528 565 529 566 530 !============================================================================== … … 577 541 ierr=nf_inq_varid(nid,var(j),varid) 578 542 if (ierr.NE.NF_NOERR) then 579 write(*,*) 'ERROR: Field <',var(j),'> not found in file '//file(i)543 write(*,*) 'ERROR: Field <',var(j),'> not found in file '//file(i) 580 544 stop "" 581 545 endif 582 546 ierr=nf_inq_varndims(nid,varid,ndim) 583 547 548 ! Check that it is a 1D, 3D or 4D variable 549 if ((ndim.ne.1).and.(ndim.ne.3).and.(ndim.ne.4)) then 550 write(*,*) "Error:",trim(var(j))," is not a time-dependent variable," 551 write(*,*) "so it can't be concatenated." 552 write(*,*) "We'll skip that variable..." 553 CYCLE ! go directly to the next variable 554 endif 555 584 556 !============================================================================== 585 557 ! 2.5.2 Prepare things in order to read/write the variable … … 644 616 if (i==1) then ! First call: write some definitions to output file 645 617 units=" " 646 title=" " 647 ierr=nf_get_att_text(nid,varid,"title",title) 618 long_name=" " 619 ierr=nf_get_att_text(nid,varid,"long_name",long_name) 620 if (ierr.ne.nf_noerr) then 621 ! if no attribute "long_name", try "title" 622 ierr=nf_get_att_text(nid,varid,"title",long_name) 623 endif 648 624 ierr=nf_get_att_text(nid,varid,"units",units) 649 call def_var(nout,var(j), title,units,ndim,dim,varidout,ierr)625 call def_var(nout,var(j),long_name,units,ndim,dim,varidout,ierr) 650 626 else 651 627 ierr=NF_INQ_VARID(nout,var(j),varidout) … … 656 632 !============================================================================== 657 633 658 #ifdef NC_DOUBLE659 ierr = NF_GET_VAR_DOUBLE(nid,varid,var3d)660 ierr= NF_PUT_VARA_DOUBLE(nout,varidout,corner,edges,var3d)661 miss=NF_GET_ATT_DOUBLE(nid,varid,"missing_value",missing)662 miss=NF_GET_ATT_DOUBLE(nid,varid,"valid_range",valid_range)663 #else664 634 ierr = NF_GET_VAR_REAL(nid,varid,var3d) 665 635 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,var3d) 666 636 miss=NF_GET_ATT_REAL(nid,varid,"missing_value",missing) 667 637 miss=NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range) 668 #endif669 638 670 639 if (ierr.ne.NF_NOERR) then … … 700 669 !============================================================================== 701 670 702 if (axis=="ls") then 703 write(*,*);write(*,*) "Converting the time axis from sol to Ls..." 704 call change_time_axis(nout,ierr) 671 if ((axis=="ls").or.(axis=="adls")) then 672 call change_time_axis(nout,ierr,axis) 705 673 endif 706 674 … … 712 680 713 681 !****************************************************************************** 714 subroutine initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,& 715 latdimout,londimout,altdimout,timedimout,& 716 layerdimout,interlayerdimout,timevarout,axis) 682 subroutine initiate (filename,lat,lon,alt,ctl,GCM_layers,& 683 altlong_name,altunits,altpositive,& 684 nout,latdimout,londimout,altdimout,timedimout,& 685 layerdimout,interlayerdimout,timevarout,axis) 717 686 !============================================================================== 718 687 ! Purpose: … … 741 710 ! ctl(): controle 742 711 integer,intent(in) :: GCM_layers ! number of GCM layers 712 character (len=*), intent(in) :: altlong_name 713 ! altlong_name(): [netcdf] altitude "long_name" attribute 714 character (len=*), intent(in) :: altunits 715 ! altunits(): [netcdf] altitude "units" attribute 716 character (len=*), intent(in) :: altpositive 717 ! altpositive(): [netcdf] altitude "positive" attribute 743 718 integer, intent(out):: nout 744 719 ! nout: [netcdf] file ID … … 787 762 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout) 788 763 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout) 789 if ( size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout)764 if (ctllen.ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout) 790 765 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout) 791 766 ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout) … … 798 773 ! 3. Write "Time" and its attributes 799 774 !============================================================================== 800 if (axis=="sol") then 775 if (axis=="ls") then 776 call def_var(nout,"Time","Solar longitude","degree",1,& 777 (/timedimout/),timevarout,ierr) 778 else 801 779 call def_var(nout,"Time","Time","days since 0000-00-0 00:00:00",1,& 802 780 (/timedimout/),timevarout,ierr) 803 else ! Ls804 call def_var(nout,"Time","Solar longitude","days since 0000-00-0 00:00:00",1,&805 (/timedimout/),timevarout,ierr)806 781 endif 807 782 !============================================================================== … … 812 787 (/latdimout/),nvarid,ierr) 813 788 814 #ifdef NC_DOUBLE815 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,lat)816 #else817 789 ierr = NF_PUT_VAR_REAL (nout,nvarid,lat) 818 #endif819 790 820 791 !============================================================================== … … 825 796 (/londimout/),nvarid,ierr) 826 797 827 #ifdef NC_DOUBLE828 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,lon)829 #else830 798 ierr = NF_PUT_VAR_REAL (nout,nvarid,lon) 831 #endif832 799 833 800 !============================================================================== … … 838 805 ierr = NF_REDEF (nout) 839 806 840 #ifdef NC_DOUBLE841 ierr = NF_DEF_VAR (nout,"altitude",NF_DOUBLE,1,altdimout,nvarid)842 #else843 807 ierr = NF_DEF_VAR (nout,"altitude",NF_FLOAT,1,altdimout,nvarid) 844 #endif 845 846 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",8,"altitude") 847 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,"km") 848 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"up") 808 809 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'long_name',len_trim(adjustl(altlong_name)),adjustl(altlong_name)) 810 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',len_trim(adjustl(altunits)),adjustl(altunits)) 811 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',len_trim(adjustl(altpositive)),adjustl(altpositive)) 849 812 850 813 ! End netcdf define mode 851 814 ierr = NF_ENDDEF(nout) 852 815 853 #ifdef NC_DOUBLE854 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,alt)855 #else856 816 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 857 #endif858 817 859 818 !============================================================================== … … 861 820 !============================================================================== 862 821 863 if ( size(ctl).ne.0) then822 if (ctllen.ne.0) then 864 823 ! Switch to netcdf define mode 865 824 ierr = NF_REDEF (nout) 866 825 867 #ifdef NC_DOUBLE868 ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)869 #else870 826 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 871 #endif 872 873 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 827 828 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",18,"Control parameters") 874 829 875 830 ! End netcdf define mode 876 831 ierr = NF_ENDDEF(nout) 877 832 878 #ifdef NC_DOUBLE879 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)880 #else881 833 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 882 #endif883 834 endif 884 835 … … 890 841 !============================================================================== 891 842 ! Purpose: 892 ! Copy ap() 893 ! from input file to outp out file843 ! Copy ap(), bp(), aps(), bps(), aire() and phisinit() 844 ! from input file to output file 894 845 !============================================================================== 895 846 ! Remarks: … … 907 858 integer, intent(in) :: lonlen ! # of grid points along longitude 908 859 integer, intent(in) :: latlen ! # of grid points along latitude 909 integer, intent(in) :: altlen ! # of grid points along latitude860 integer, intent(in) :: altlen ! # of grid points along altitude 910 861 integer, intent(in) :: GCM_layers ! # of GCM atmospheric layers 911 862 integer, intent(in) :: outfid ! NetCDF output file ID … … 931 882 logical :: hybrid ! are "aps" and "bps" available ? 932 883 logical :: apbp ! are "ap" and "bp" available ? 884 logical :: sig ! is "sigma" available ? 933 885 934 886 !============================================================================== … … 976 928 write(*,*) "init2: failed to allocate ap!" 977 929 stop 930 endif 931 ierr=NF_INQ_VARID(infid,"ap",tmpvarid) 932 if (ierr.ne.NF_NOERR) then 933 write(*,*) "Ooops. Failed to get ap ID. OK." 934 apbp=.false. 978 935 else 979 ierr=NF_INQ_VARID(infid,"ap",tmpvarid) 980 if (ierr.ne.NF_NOERR) then 981 write(*,*) "Ooops. Failed to get ap ID. OK." 982 apbp=.false. 983 else 984 ierr=NF_GET_VAR_REAL(infid,tmpvarid,ap) 985 apbp=.true. 986 if (ierr.ne.NF_NOERR) then 987 stop "Error: Failed reading ap" 988 endif 936 ierr=NF_GET_VAR_REAL(infid,tmpvarid,ap) 937 apbp=.true. 938 if (ierr.ne.NF_NOERR) then 939 stop "Error: Failed reading ap" 989 940 endif 990 941 endif … … 995 946 write(*,*) "init2: failed to allocate bp!" 996 947 stop 948 endif 949 ierr=NF_INQ_VARID(infid,"bp",tmpvarid) 950 if (ierr.ne.NF_NOERR) then 951 write(*,*) "Ooops. Failed to get bp ID. OK." 952 apbp=.false. 997 953 else 998 ierr=NF_INQ_VARID(infid,"bp",tmpvarid) 999 if (ierr.ne.NF_NOERR) then 1000 write(*,*) "Ooops. Failed to get bp ID. OK." 1001 apbp=.false. 1002 else 1003 ierr=NF_GET_VAR_REAL(infid,tmpvarid,bp) 1004 apbp=.true. 1005 if (ierr.ne.NF_NOERR) then 1006 stop "Error: Failed reading bp" 1007 endif 954 ierr=NF_GET_VAR_REAL(infid,tmpvarid,bp) 955 apbp=.true. 956 if (ierr.ne.NF_NOERR) then 957 stop "Error: Failed reading bp" 1008 958 endif 1009 959 endif … … 1017 967 endif 1018 968 ierr=NF_INQ_VARID(infid,"sigma",tmpvarid) 1019 ierr=NF_GET_VAR_REAL(infid,tmpvarid,sigma) 1020 if (ierr.ne.NF_NOERR) then 1021 stop "init2 Error: Failed reading sigma" 969 if (ierr.ne.NF_NOERR) then 970 write(*,*) "Ooops. Failed to get sigma ID. OK." 971 sig=.false. 972 else 973 ierr=NF_GET_VAR_REAL(infid,tmpvarid,sigma) 974 sig=.true. 975 if (ierr.ne.NF_NOERR) then 976 stop "init2 Error: Failed reading sigma" 977 endif 1022 978 endif 1023 979 endif ! of if (.not.hybrid) … … 1075 1031 1076 1032 ! write aps 1077 #ifdef NC_DOUBLE1078 ierr=NF_PUT_VAR_DOUBLE(outfid,apsid,aps)1079 #else1080 1033 ierr=NF_PUT_VAR_REAL(outfid,apsid,aps) 1081 #endif1082 1034 if (ierr.ne.NF_NOERR) then 1083 1035 stop "init2 Error: Failed to write aps" … … 1092 1044 1093 1045 ! write bps 1094 #ifdef NC_DOUBLE1095 ierr=NF_PUT_VAR_DOUBLE(outfid,bpsid,bps)1096 #else1097 1046 ierr=NF_PUT_VAR_REAL(outfid,bpsid,bps) 1098 #endif1099 1047 if (ierr.ne.NF_NOERR) then 1100 1048 stop "init2 Error: Failed to write bps" … … 1110 1058 1111 1059 ! write ap 1112 #ifdef NC_DOUBLE1113 ierr=NF_PUT_VAR_DOUBLE(outfid,apid,ap)1114 #else1115 1060 ierr=NF_PUT_VAR_REAL(outfid,apid,ap) 1116 #endif1117 1061 if (ierr.ne.NF_NOERR) then 1118 1062 stop "Error: Failed to write ap" … … 1127 1071 1128 1072 ! write bp 1129 #ifdef NC_DOUBLE1130 ierr=NF_PUT_VAR_DOUBLE(outfid,bpid,bp)1131 #else1132 1073 ierr=NF_PUT_VAR_REAL(outfid,bpid,bp) 1133 #endif1134 1074 if (ierr.ne.NF_NOERR) then 1135 1075 stop "Error: Failed to write bp" … … 1137 1077 endif ! of if (apbp) 1138 1078 1139 else 1079 else if (sig) then 1140 1080 ! define sigma 1141 1081 call def_var(nout,"sigma","sigma at midlayers"," ",1,& … … 1145 1085 endif 1146 1086 ! write sigma 1147 #ifdef NC_DOUBLE1148 ierr=NF_PUT_VAR_DOUBLE(outfid,sigmaid,sigma)1149 #else1150 1087 ierr=NF_PUT_VAR_REAL(outfid,sigmaid,sigma) 1151 #endif1152 1088 if (ierr.ne.NF_NOERR) then 1153 1089 stop "init2 Error: Failed to write sigma" … … 1168 1104 1169 1105 ! write aire 1170 #ifdef NC_DOUBLE1171 ierr=NF_PUT_VAR_DOUBLE(outfid,tmpvarid,aire)1172 #else1173 1106 ierr=NF_PUT_VAR_REAL(outfid,tmpvarid,aire) 1174 #endif1175 1107 if (ierr.ne.NF_NOERR) then 1176 1108 stop "init2 Error: Failed to write aire" … … 1188 1120 1189 1121 ! write phisinit 1190 #ifdef NC_DOUBLE1191 ierr=NF_PUT_VAR_DOUBLE(outfid,phisinitid,phisinit)1192 #else1193 1122 ierr=NF_PUT_VAR_REAL(outfid,phisinitid,phisinit) 1194 #endif1195 1123 if (ierr.ne.NF_NOERR) then 1196 1124 stop "init2 Error: Failed to write phisinit" … … 1211 1139 end subroutine init2 1212 1140 !****************************************************************************** 1213 subroutine def_var(nid,name, title,units,nbdim,dim,nvarid,ierr)1141 subroutine def_var(nid,name,long_name,units,nbdim,dim,nvarid,ierr) 1214 1142 !============================================================================== 1215 1143 ! Purpose: Write a variable (i.e: add a variable to a dataset) 1216 ! called "name"; along with its attributes " title", "units"...1144 ! called "name"; along with its attributes "long_name", "units"... 1217 1145 ! to a file (following the NetCDF format) 1218 1146 !============================================================================== … … 1232 1160 character (len=*), intent(in) :: name 1233 1161 ! name(): [netcdf] variable's name 1234 character (len=*), intent(in) :: title1235 ! title(): [netcdf] variable's "title" attribute1162 character (len=*), intent(in) :: long_name 1163 ! long_name(): [netcdf] variable's "long_name" attribute 1236 1164 character (len=*), intent(in) :: units 1237 1165 ! unit(): [netcdf] variable's "units" attribute … … 1249 1177 1250 1178 ! Insert the definition of the variable 1251 #ifdef NC_DOUBLE1252 ierr=NF_DEF_VAR(nid,adjustl(name),NF_DOUBLE,nbdim,dim,nvarid)1253 #else1254 1179 ierr=NF_DEF_VAR(nid,adjustl(name),NF_FLOAT,nbdim,dim,nvarid) 1255 #endif1256 1180 1257 1181 ! Write the attributes 1258 ierr=NF_PUT_ATT_TEXT(nid,nvarid," title",len_trim(adjustl(title)),adjustl(title))1182 ierr=NF_PUT_ATT_TEXT(nid,nvarid,"long_name",len_trim(adjustl(long_name)),adjustl(long_name)) 1259 1183 ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",len_trim(adjustl(units)),adjustl(units)) 1260 1184 … … 1264 1188 end subroutine def_var 1265 1189 !****************************************************************************** 1266 subroutine change_time_axis(nid,ierr )1190 subroutine change_time_axis(nid,ierr,axis) 1267 1191 !============================================================================== 1268 1192 ! Purpose: … … 1285 1209 integer, intent(out) :: ierr 1286 1210 ! ierr: [netcdf] return error code 1211 character (len=4),intent(in) :: axis 1212 ! axis: "ls" or "sol" 1287 1213 1288 1214 !============================================================================== … … 1315 1241 ierr=NF_INQ_DIMLEN(nid,timedim,timelen) 1316 1242 allocate(time(timelen),ls(timelen)) 1317 #ifdef NC_DOUBLE1318 ierr = NF_GET_VAR_DOUBLE(nid,nvarid,time)1319 #else1320 1243 ierr = NF_GET_VAR_REAL(nid,nvarid,time) 1321 #endif1322 1244 if (ierr.ne.NF_NOERR) then 1323 1245 write(*,*) "ERROR in change_time_axis: Failed to load Time" … … 1353 1275 !============================================================================== 1354 1276 1355 #ifdef NC_DOUBLE 1356 ierr = NF_PUT_VAR_DOUBLE(nid,nvarid,ls) 1357 #else 1277 if (axis.eq."ls") then 1278 write(*,*) "Converting the time axis from sol to Ls..." 1279 else ! if (axis.eq."adls") 1280 write(*,*) "Adding Ls as a 1D time variable" 1281 call def_var(nout,"Ls","Solar Longitude","degree",1, (/timedimout/),nvarid,ierr) 1282 end if 1283 1358 1284 ierr = NF_PUT_VAR_REAL(nid,nvarid,ls) 1359 #endif1360 1285 if (ierr.ne.NF_NOERR) then 1361 write(*,*) "ERROR in change_time_axis: Failed to write Ls"1362 stop1286 write(*,*) "ERROR in change_time_axis: Failed to write Ls" 1287 stop 1363 1288 endif 1364 1289 … … 1502 1427 1503 1428 ! Write valid_range() attribute 1504 #ifdef NC_DOUBLE1505 ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range)1506 #else1507 1429 ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range) 1508 #endif1509 1430 1510 1431 if (ierr.ne.NF_NOERR) then … … 1517 1438 1518 1439 ! Write "missing_value" attribute 1519 #ifdef NC_DOUBLE1520 ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing)1521 #else1522 1440 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing) 1523 #endif1524 1441 1525 1442 if (ierr.NE.NF_NOERR) then -
trunk/LMDZ.MARS/util/concatnc.def
r2313 r2434 3 3 diagfi12.nc 4 4 5 515 ! Starting sol to use in the output file?6 sol ! output timescale ("sol" or " ls")5 n ! Starting sol of the run stored in the first input file? 6 sol ! output timescale ("sol" or "Ls" or "adls") 7 7 tsurf 8 8 ps 9 9 10 10 11 11 12 ----------------------------------------------------------------------- 12 ABOVE is the list of inputs to be fed to "concatnc.e" if you don 't want13 ABOVE is the list of inputs to be fed to "concatnc.e" if you don t want 13 14 to reply directly to the program: 14 15 15 16 1) List of N files to be read (N lines) 16 17 2) blank line at the end 17 3) Starting sol of the output file? 18 (or a blank if you want to use the first file's 19 starting sol = time(1)+controle(4) ) 20 4) Output timescale ("sol" or "ls") 21 5) List of X variables to be kept (X lines) or 'all' 22 6) blank line at the end 18 3) Starting sol of the run stored in the first input file? juste write "n" if you 19 wish to keep the date of the input files (recommended) 20 4) List of X variables to be kept (X lines) or 'all' 21 5) blank line at the end 23 22 24 23 The use is : -
trunk/LMDZ.MARS/util/localtime.F90
r2280 r2434 14 14 character (len=50) file 15 15 ! file(): input file(s) names(s) 16 character (len=30), dimension(1 5) :: notconcat17 ! not concat(): names of the (15) variables that won't be concatenated16 character (len=30), dimension(16) :: notprocessed 17 ! notprocessed(): names of the (16) variables that won't be processed 18 18 character (len=50), dimension(:), allocatable :: var 19 ! var(): name(s) of variable(s) that will be concatenated20 character (len= 50) :: tmpvar,title,units19 ! var(): name(s) of variable(s) that will be processed 20 character (len=100) :: tmpvar,long_name,units 21 21 ! tmpvar(): used to temporarily store a variable name 22 ! title(): [netcdf] title attribute22 ! long_name(): [netcdf] long_name attribute 23 23 ! units(): [netcdf] units attribute 24 24 character (len=100) :: filename,vartmp … … 58 58 ! ctldim: [netcdf] "controle" dim ID 59 59 ! timedim: [netcdf] "timedim" dim ID 60 integer :: gcmlayerdim ! NetCDF dimension ID for # of layers in GCM 60 61 integer :: latvar,lonvar,altvar,ctlvar,timevar 61 62 ! latvar: [netcdf] ID of "latitude" variable … … 68 69 ! latlen: # of elements of lat() array 69 70 ! lonlen: # of elements of lon() array 70 ! alt var: # of elements of alt() array71 ! ctl var: # of elements of ctl() array71 ! altlen: # of elements of alt() array 72 ! ctllen: # of elements of ctl() array 72 73 ! timelen: # of elemnets of time() array 73 74 ! timelen_tot:# =timelen or timelen+1 (if 1 more time to interpolate needed) 74 75 ! timelen_lt: # of elemnets of time() array in output 76 integer :: nhour,nsol 77 integer :: GCM_layers ! number of GCM atmospheric layers (may not be 78 ! same as altlen if file is an output of zrecast) 75 79 integer :: nout,latdimout,londimout,altdimout,timedimout,timevarout 76 integer :: nhour,nsol77 80 ! nout: [netcdf] output file ID 78 81 ! latdimout: [netcdf] output latitude (dimension) ID … … 81 84 ! timedimout: [netcdf] output time (dimension) ID 82 85 ! timevarout: [netcdf] ID of output "Time" variable 86 integer :: layerdimout ! NetCDF dimension ID for # of layers in GCM 83 87 integer :: varidout 84 88 ! varidout: [netcdf] variable ID # (of a variable to write to the output file) 85 integer :: Nnot concat,var_ok86 ! Nnot concat: # of (leading)variables that won't be concatenated89 integer :: Nnotprocessed,var_ok 90 ! Nnotprocessed: # of (leading)variables that won't be concatenated 87 91 ! var_ok: flag (0 or 1) 88 92 integer, dimension(4) :: corner,edges,dim … … 143 147 !============================================================================== 144 148 145 notconcat(1)='Time' 146 notconcat(2)='controle' 147 notconcat(3)='rlonu' 148 notconcat(4)='latitude' 149 notconcat(5)='longitude' 150 notconcat(6)='altitude' 151 notconcat(7)='rlatv' 152 notconcat(8)='aps' 153 notconcat(9)='bps' 154 notconcat(10)='ap' 155 notconcat(11)='bp' 156 notconcat(12)='cu' 157 notconcat(13)='cv' 158 notconcat(14)='aire' 159 notconcat(15)='phisinit' 149 notprocessed(1)='Time' 150 notprocessed(2)='controle' 151 notprocessed(3)='rlonu' 152 notprocessed(4)='latitude' 153 notprocessed(5)='longitude' 154 notprocessed(6)='altitude' 155 notprocessed(7)='rlatv' 156 notprocessed(8)='aps' 157 notprocessed(9)='bps' 158 notprocessed(10)='ap' 159 notprocessed(11)='bp' 160 notprocessed(12)='soildepth' 161 notprocessed(13)='cu' 162 notprocessed(14)='cv' 163 notprocessed(15)='aire' 164 notprocessed(16)='phisinit' 165 160 166 161 167 !============================================================================== … … 163 169 !============================================================================== 164 170 write(*,*) 165 Nnot concat=0171 Nnotprocessed=0 166 172 do i=1,nbvarfile 167 173 ierr=NF_INQ_VARNAME(nid,i,vartmp) 168 174 ! vartmp now contains the "name" of variable of ID # i 169 175 var_ok=0 170 do inter=1,1 5171 if (vartmp.eq.not concat(inter)) then176 do inter=1,16 177 if (vartmp.eq.notprocessed(inter)) then 172 178 var_ok=1 173 Nnot concat=Nnotconcat+1179 Nnotprocessed=Nnotprocessed+1 174 180 endif 175 181 enddo … … 177 183 enddo 178 184 179 ! Nnot concat: # of variables that won't be processed185 ! Nnotprocessed: # of variables that won't be processed 180 186 ! nbvarfile: total # of variables in file 181 allocate(var(nbvarfile-Nnot concat),stat=ierr)187 allocate(var(nbvarfile-Nnotprocessed),stat=ierr) 182 188 if (ierr.ne.0) then 183 write(*,*) "Error: failed allocation of var(nbvarfile-Nnot concat)"189 write(*,*) "Error: failed allocation of var(nbvarfile-Nnotprocessed)" 184 190 write(*,*) " nbvarfile=",nbvarfile 185 write(*,*) " Nnot concat=",Nnotconcat191 write(*,*) " Nnotprocessed=",Nnotprocessed 186 192 stop 187 193 endif … … 201 207 202 208 if (tmpvar=="all") then 203 nbvar=nbvarfile-Nnot concat204 do j=Nnot concat+1,nbvarfile205 ierr=nf_inq_varname(nid,j,var(j-Nnot concat))209 nbvar=nbvarfile-Nnotprocessed 210 do j=Nnotprocessed+1,nbvarfile 211 ierr=nf_inq_varname(nid,j,var(j-Nnotprocessed)) 206 212 enddo 207 213 ! Variables names from the file are stored in var() 208 nbvar=nbvarfile-Nnot concat214 nbvar=nbvarfile-Nnotprocessed 209 215 do i=1,nbvar 210 ierr=nf_inq_varname(nid,i+Nnot concat,var(i))216 ierr=nf_inq_varname(nid,i+Nnotprocessed,var(i)) 211 217 write(*,'(a9,1x,i2,1x,a1,1x,a50)') "variable ",i,":",var(i) 212 218 enddo … … 220 226 !============================================================================== 221 227 filename=file(1:len_trim(file)-3)//"_LT.nc" 222 write(*,*) trim(filename)228 write(*,*) "Output file :"//trim(filename) 223 229 224 230 !============================================================================== … … 226 232 !============================================================================== 227 233 228 229 230 231 232 233 234 235 234 write(*,*) 235 write(*,*) "opening "//trim(file)//"..." 236 ierr = NF_OPEN(file,NF_NOWRITE,nid) 237 if (ierr.NE.NF_NOERR) then 238 write(*,*) 'ERROR: Pb opening file '//trim(file) 239 write(*,*) NF_STRERROR(ierr) 240 stop "" 241 endif 236 242 237 243 !============================================================================== … … 277 283 ierr=NF_INQ_DIMLEN(nid,altdim,altlen) 278 284 ! write(*,*) "altlen: ",altlen 285 286 ! load size of aps() or sigma() (in case it is not altlen) 287 ! default is that GCM_layers=altlen 288 ! but for outputs of zrecast, it may be a different value 289 ierr=NF_INQ_DIMID(nid,"GCM_layers",gcmlayerdim) 290 if (ierr.ne.NF_NOERR) then 291 ! didn't find a GCM_layers dimension; therefore we have: 292 GCM_layers=altlen 293 else 294 ! load value of GCM_layers 295 ierr=NF_INQ_DIMLEN(nid,gcmlayerdim,GCM_layers) 296 endif 297 ! write(*,*) "GCM_layers=",GCM_layers 279 298 280 299 ierr=NF_INQ_DIMID(nid,"index",ctldim) … … 299 318 !============================================================================== 300 319 301 ! First call; initialize/allocate 302 allocate(lat(latlen),stat=ierr) 303 if (ierr.ne.0) then 304 write(*,*) "Error: failed to allocate lat(latlen)" 305 stop 306 endif 307 allocate(lon(lonlen),stat=ierr) 308 if (ierr.ne.0) then 309 write(*,*) "Error: failed to allocate lon(lonlen)" 310 stop 311 endif 312 allocate(alt(altlen),stat=ierr) 313 if (ierr.ne.0) then 314 write(*,*) "Error: failed to allocate alt(altlen)" 315 stop 316 endif 317 allocate(ctl(ctllen),stat=ierr) 318 if (ierr.ne.0) then 319 write(*,*) "Error: failed to allocate ctl(ctllen)" 320 stop 321 endif 322 323 #ifdef NC_DOUBLE 324 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat) 325 #else 326 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 327 #endif 328 if (ierr.ne.0) then 329 write(*,*) "Error: failed to load latitude" 330 write(*,*) NF_STRERROR(ierr) 331 stop 332 endif 333 334 #ifdef NC_DOUBLE 335 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon) 336 #else 337 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 338 #endif 339 if (ierr.ne.0) then 340 write(*,*) "Error: failed to load longitude" 341 write(*,*) NF_STRERROR(ierr) 342 stop 343 endif 344 345 #ifdef NC_DOUBLE 346 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt) 347 #else 348 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 349 #endif 350 if (ierr.ne.0) then 351 write(*,*) "Error: failed to load altitude" 352 write(*,*) NF_STRERROR(ierr) 353 stop 354 endif 320 allocate(lat(latlen),stat=ierr) 321 if (ierr.ne.0) then 322 write(*,*) "Error: failed to allocate lat(latlen)" 323 stop 324 endif 325 allocate(lon(lonlen),stat=ierr) 326 if (ierr.ne.0) then 327 write(*,*) "Error: failed to allocate lon(lonlen)" 328 stop 329 endif 330 allocate(alt(altlen),stat=ierr) 331 if (ierr.ne.0) then 332 write(*,*) "Error: failed to allocate alt(altlen)" 333 stop 334 endif 335 allocate(ctl(ctllen),stat=ierr) 336 if (ierr.ne.0) then 337 write(*,*) "Error: failed to allocate ctl(ctllen)" 338 stop 339 endif 340 341 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 342 if (ierr.ne.0) then 343 write(*,*) "Error: failed to load latitude" 344 write(*,*) NF_STRERROR(ierr) 345 stop 346 endif 347 348 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 349 if (ierr.ne.0) then 350 write(*,*) "Error: failed to load longitude" 351 write(*,*) NF_STRERROR(ierr) 352 stop 353 endif 354 355 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 356 if (ierr.ne.0) then 357 write(*,*) "Error: failed to load altitude" 358 write(*,*) NF_STRERROR(ierr) 359 stop 360 endif 355 361 ! Get altitude attributes to handle files with any altitude type 356 ierr=nf_get_att_text(nid,altvar,'long_name',altlong_name)357 ierr=nf_get_att_text(nid,altvar,'units',altunits) 358 ierr=nf_get_att_text(nid,altvar,'positive',altpositive) 359 360 if (ctllen .ne. 0) then361 #ifdef NC_DOUBLE 362 ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)363 #else 364 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)365 #endif 366 367 368 369 370 371 362 ierr=nf_get_att_text(nid,altvar,'long_name',altlong_name) 363 if (ierr.ne.nf_noerr) then 364 ! if no attribute "long_name", try "title" 365 ierr=nf_get_att_text(nid,timevar,"title",long_name) 366 endif 367 ierr=nf_get_att_text(nid,altvar,'units',altunits) 368 ierr=nf_get_att_text(nid,altvar,'positive',altpositive) 369 370 if (ctllen .ne. 0) then 371 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 372 if (ierr.ne.0) then 373 write(*,*) "Error: failed to load controle" 374 write(*,*) NF_STRERROR(ierr) 375 stop 376 endif 377 endif ! of if (ctllen .ne. 0) 372 378 373 379 !============================================================================== … … 391 397 ! write(*,*) "timelen: ",timelen 392 398 393 ! Sanity Check: Does "Time" has a " title" attribute399 ! Sanity Check: Does "Time" has a "long_name" attribute 394 400 ! and is it "Solar longitude" ? 395 ierr=nf_get_att_text(nid,timevar,"title",title) 396 if ((ierr.EQ.NF_NOERR).and.(title.eq."Solar longitude")) then 401 ierr=nf_get_att_text(nid,timevar,"long_name",long_name) 402 if (ierr.ne.nf_noerr) then 403 ! if no attribute "long_name", try "title" 404 ierr=nf_get_att_text(nid,timevar,"title",long_name) 405 endif 406 if ((ierr.EQ.NF_NOERR).and.(long_name.eq."Solar longitude")) then 397 407 write(*,*) "ERROR: Time axis in input file is in Solar Longitude!" 398 408 write(*,*) " localtime requires sols as time axis!" … … 408 418 endif 409 419 410 #ifdef NC_DOUBLE411 ierr = NF_GET_VAR_DOUBLE(nid,timevar,time)412 #else413 420 ierr = NF_GET_VAR_REAL(nid,timevar,time) 414 #endif415 421 if (ierr.NE.NF_NOERR) then 416 422 write(*,*) "Error , failed to load Time" … … 432 438 write(*,*) 'list of selected local time (0<t<24)' 433 439 do it=1,nhour 434 440 read(*,*) lt_hour(it) 435 441 end do 436 442 437 443 if ((timelen.eq.12).and.(time(1).eq.2).and.(time(timelen).eq.24))then 438 439 440 441 442 443 444 445 446 447 448 444 write(*,*) 'We detect a ""stats"" file' 445 stats=.true. 446 timelen_lt=nhour 447 allocate(lt_out(timelen_lt),stat=ierr) 448 if (ierr.ne.0) then 449 write(*,*) "Error: failed to allocate lt_hour(nhour)" 450 stop 451 endif 452 do it=1,nhour 453 lt_out(it)=lt_hour(it)/24. 454 end do 449 455 ! We rewrite the time from "stats" from 0 to 1 sol... 450 451 452 453 456 do it=1,timelen ! loop temps in 457 time(it) = time(it)/24. 458 end do 459 nsol =1 454 460 else ! case of a diagfi or concatnc file 455 461 stats=.false. … … 469 475 end do 470 476 end do 471 477 end if 472 478 473 479 if (nsol.gt.1) then … … 499 505 500 506 ! Initialize output file's lat,lon,alt and time dimensions 501 call initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen, &507 call initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,GCM_layers,& 502 508 altlong_name,altunits,altpositive,& 503 nout,latdimout,londimout,altdimout,timedimout,timevarout) 509 nout,latdimout,londimout,altdimout,timedimout,& 510 layerdimout,timevarout) 504 511 505 512 ! Initialize output file's aps,bps and phisinit variables 506 call init2(nid,lonlen,latlen,altlen,altdim,& 507 nout,londimout,latdimout,altdimout) 513 call init2(nid,lonlen,latlen,altlen,GCM_layers,& 514 nout,londimout,latdimout,altdimout,& 515 layerdimout) 508 516 509 517 … … 515 523 516 524 do it=1,timelen_lt 517 #ifdef NC_DOUBLE518 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,it,1,lt_hour(it))519 #else520 525 ierr= NF_PUT_VARA_REAL(nout,timevarout,it,1,lt_hour(it)) 521 #endif522 526 enddo 523 527 else 524 528 do it=1,timelen_lt 525 #ifdef NC_DOUBLE526 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,it,1,lt_out(it))527 #else528 529 ierr= NF_PUT_VARA_REAL(nout,timevarout,it,1,lt_out(it)) 529 #endif530 530 if (ierr.NE.NF_NOERR) then 531 531 write(*,*) "Error , failed to write Time" … … 553 553 ierr=nf_inq_varndims(nid,varid,ndim) 554 554 555 ! Check that it is a 3D or 4D variable 556 if (ndim.lt.3) then 557 write(*,*) "Error:",trim(var(j))," is nor a 3D neither a 4D variable" 558 write(*,*) "We'll skip that variable..." 559 CYCLE ! go directly to the next variable 560 endif 555 561 !============================================================================== 556 562 ! 2.5.2 Prepare things in order to read/write the variable … … 599 605 endif 600 606 601 units=" " 602 title=" " 603 ierr=nf_get_att_text(nid,varid,"title",title) 604 ierr=nf_get_att_text(nid,varid,"units",units) 605 call def_var(nout,var(j),title,units,ndim,dim,varidout,ierr) 607 units=" " 608 long_name=" " 609 ierr=nf_get_att_text(nid,timevar,"long_name",long_name) 610 if (ierr.ne.nf_noerr) then 611 ! if no attribute "long_name", try "title" 612 ierr=nf_get_att_text(nid,timevar,"title",long_name) 613 endif 614 ierr=nf_get_att_text(nid,varid,"units",units) 615 call def_var(nout,var(j),long_name,units,ndim,dim,varidout,ierr) 606 616 607 617 … … 611 621 !============================================================================== 612 622 613 #ifdef NC_DOUBLE614 ierr = NF_GET_VAR_DOUBLE(nid,varid,var3d)615 miss=NF_GET_ATT_DOUBLE(nid,varid,"missing_value",missing)616 validr=NF_GET_ATT_DOUBLE(nid,varid,"valid_range",valid_range)617 #else618 623 ierr = NF_GET_VAR_REAL(nid,varid,var3d) 619 624 miss=NF_GET_ATT_REAL(nid,varid,"missing_value",missing) 620 625 validr=NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range) 621 #endif622 626 623 627 !============================================================================== … … 677 681 !============================================================================== 678 682 679 #ifdef NC_DOUBLE680 ierr= NF_PUT_VARA_DOUBLE(nout,varidout,corner,edges,var3d_lt)681 #else682 683 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,var3d_lt) 683 #endif684 684 685 685 if (ierr.ne.NF_NOERR) then … … 712 712 ierr=NF_CLOSE(nout) 713 713 714 write(*,*) "Program completed !" 715 714 716 contains 715 717 716 718 !****************************************************************************** 717 Subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen, &719 Subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,GCM_layers,& 718 720 altlong_name,altunits,altpositive,& 719 nout,latdimout,londimout,altdimout,timedimout,timevarout) 721 nout,latdimout,londimout,altdimout,timedimout,& 722 layerdimout,timevarout) 720 723 !============================================================================== 721 724 ! Purpose: … … 744 747 real, intent(in):: ctl(ctllen) 745 748 ! ctl(): controle 749 integer,intent(in) :: GCM_layers ! number of GCM layers 746 750 character (len=*), intent(in) :: altlong_name 747 751 ! altlong_name(): [netcdf] altitude "long_name" attribute … … 760 764 integer, intent(out):: timedimout 761 765 ! timedimout: [netcdf] "Time" ID 766 integer,intent(out) :: layerdimout 767 ! layerdimout: [netcdf] "GCM_layers" ID 762 768 integer, intent(out):: timevarout 763 769 ! timevarout: [netcdf] "Time" (considered as a variable) ID … … 821 827 endif 822 828 829 ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout) 830 823 831 ! End netcdf define mode 824 832 ierr = NF_ENDDEF(nout) … … 843 851 (/latdimout/),nvarid,ierr) 844 852 845 #ifdef NC_DOUBLE846 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,lat)847 #else848 853 ierr = NF_PUT_VAR_REAL (nout,nvarid,lat) 849 #endif850 854 if (ierr.NE.NF_NOERR) then 851 855 WRITE(*,*)'initiate: error failed writing variable <latitude>' … … 861 865 (/londimout/),nvarid,ierr) 862 866 863 #ifdef NC_DOUBLE 864 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,lon) 865 #else 867 866 868 ierr = NF_PUT_VAR_REAL (nout,nvarid,lon) 867 #endif868 869 if (ierr.NE.NF_NOERR) then 869 870 WRITE(*,*)'initiate: error failed writing variable <longitude>' … … 879 880 ierr = NF_REDEF (nout) 880 881 881 #ifdef NC_DOUBLE882 ierr = NF_DEF_VAR (nout,"altitude",NF_DOUBLE,1,altdimout,nvarid)883 #else884 882 ierr = NF_DEF_VAR (nout,"altitude",NF_FLOAT,1,altdimout,nvarid) 885 #endif886 883 887 884 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'long_name',len_trim(adjustl(altlong_name)),adjustl(altlong_name)) … … 892 889 ierr = NF_ENDDEF(nout) 893 890 894 #ifdef NC_DOUBLE 895 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,alt) 896 #else 897 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 898 #endif 891 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 899 892 if (ierr.NE.NF_NOERR) then 900 893 WRITE(*,*)'initiate: error failed writing variable <altitude>' … … 911 904 ierr = NF_REDEF (nout) 912 905 913 #ifdef NC_DOUBLE914 ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)915 #else916 906 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 917 #endif 918 919 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 907 908 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",18,"Control parameters") 920 909 921 910 ! End netcdf define mode 922 911 ierr = NF_ENDDEF(nout) 923 912 924 #ifdef NC_DOUBLE925 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)926 #else927 913 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 928 #endif929 914 if (ierr.NE.NF_NOERR) then 930 915 WRITE(*,*)'initiate: error failed writing variable <controle>' … … 936 921 end Subroutine initiate 937 922 !****************************************************************************** 938 subroutine init2(infid,lonlen,latlen,altlen,altdimid, & 939 outfid,londimout,latdimout,altdimout) 923 subroutine init2(infid,lonlen,latlen,altlen,GCM_layers,& 924 outfid,londimout,latdimout,altdimout,& 925 layerdimout) 940 926 !============================================================================== 941 927 ! Purpose: … … 957 943 integer, intent(in) :: latlen ! # of grid points along latitude 958 944 integer, intent(in) :: altlen ! # of grid points along altitude 959 integer, intent(in) :: altdimid ! ID of altitude dimension945 integer, intent(in) :: GCM_layers ! # of GCM atmospheric layers 960 946 integer, intent(in) :: outfid ! NetCDF output file ID 961 947 integer, intent(in) :: londimout ! longitude dimension ID 962 948 integer, intent(in) :: latdimout ! latitude dimension ID 963 949 integer, intent(in) :: altdimout ! altitude dimension ID 950 integer, intent(in) :: layerdimout ! GCM_layers dimension ID 964 951 !============================================================================== 965 952 ! Local variables: … … 971 958 integer :: tmpdimid ! temporary dimension ID 972 959 integer :: tmpvarid ! temporary variable ID 973 logical :: phis, aps_ok, bps_ok ! are "phisinit" "aps""bps" available ?960 logical :: phis, hybrid ! are "phisinit" and "aps"/"bps" available ? 974 961 975 962 … … 979 966 980 967 ! hybrid coordinate aps 981 allocate(aps(altlen),stat=ierr) 968 !write(*,*) "aps: altlen=",altlen," GCM_layers=",GCM_layers 969 allocate(aps(GCM_layers),stat=ierr) 970 if (ierr.ne.0) then 971 write(*,*) "init2: failed to allocate aps!" 972 stop 973 endif 974 ierr=NF_INQ_VARID(infid,"aps",tmpvarid) 975 if (ierr.ne.NF_NOERR) then 976 write(*,*) "Ooops. Failed to get aps ID. OK." 977 hybrid=.false. 978 else 979 hybrid=.true. 980 ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps) 981 hybrid=.true. 982 if (ierr.ne.NF_NOERR) then 983 stop "init2 Error: Failed reading aps" 984 endif 985 986 ! hybrid coordinate bps 987 ! write(*,*) "bps: altlen=",altlen," GCM_layers=",GCM_layers 988 allocate(bps(GCM_layers),stat=ierr) 982 989 if (ierr.ne.0) then 983 write(*,*) "init2: failed to allocate aps(altlen)"990 write(*,*) "init2: failed to allocate bps!" 984 991 stop 985 992 endif 986 987 ierr=NF_INQ_VARID(infid,"aps",tmpvarid) 988 if (ierr.ne.NF_NOERR) then 989 write(*,*) "oops Failed to get aps ID. OK" 990 aps_ok=.false. 991 else 992 ! Check that aps() is the right size (it most likely won't be if 993 ! zrecast has be used to generate the input file) 994 ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid) 995 if (tmpdimid.ne.altdimid) then 996 write(*,*) "init2: wrong dimension size for aps(), skipping it ..." 997 aps_ok=.false. 998 else 999 ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps) 1000 if (ierr.ne.NF_NOERR) then 1001 stop "init2 error: Failed reading aps" 1002 endif 1003 aps_ok=.true. 1004 endif 1005 endif 1006 1007 ! hybrid coordinate bps 1008 allocate(bps(altlen),stat=ierr) 1009 if (ierr.ne.0) then 1010 write(*,*) "init2: failed to allocate bps(altlen)" 1011 stop 1012 endif 1013 1014 ierr=NF_INQ_VARID(infid,"bps",tmpvarid) 1015 if (ierr.ne.NF_NOERR) then 1016 write(*,*) "oops: Failed to get bps ID. OK" 1017 bps_ok=.false. 1018 else 1019 ! Check that bps() is the right size 1020 ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid) 1021 if (tmpdimid.ne.altdimid) then 1022 write(*,*) "init2: wrong dimension size for bps(), skipping it ..." 1023 bps_ok=.false. 993 ierr=NF_INQ_VARID(infid,"bps",tmpvarid) 994 if (ierr.ne.NF_NOERR) then 995 write(*,*) "Ooops. Failed to get bps ID. OK." 996 hybrid=.false. 1024 997 else 1025 998 ierr=NF_GET_VAR_REAL(infid,tmpvarid,bps) … … 1027 1000 stop "init2 Error: Failed reading bps" 1028 1001 endif 1029 bps_ok=.true.1030 1002 endif 1031 1003 endif … … 1059 1031 !============================================================================== 1060 1032 1061 IF ( aps_ok) then1033 IF (hybrid) then 1062 1034 ! define aps 1063 1035 call def_var(outfid,"aps","hybrid pressure at midlayers"," ",1,& 1064 (/ altdimout/),apsid,ierr)1036 (/layerdimout/),apsid,ierr) 1065 1037 if (ierr.ne.NF_NOERR) then 1066 1038 stop "Error: Failed to def_var aps" … … 1068 1040 1069 1041 ! write aps 1070 #ifdef NC_DOUBLE1071 ierr=NF_PUT_VAR_DOUBLE(outfid,apsid,aps)1072 #else1073 1042 ierr=NF_PUT_VAR_REAL(outfid,apsid,aps) 1074 #endif1075 1043 if (ierr.ne.NF_NOERR) then 1076 1044 stop "Error: Failed to write aps" 1077 1045 endif 1078 ENDIF ! of IF (aps_ok) 1079 1080 IF (bps_ok) then 1046 1081 1047 ! define bps 1082 1048 call def_var(outfid,"bps","hybrid sigma at midlayers"," ",1,& 1083 (/ altdimout/),bpsid,ierr)1049 (/layerdimout/),bpsid,ierr) 1084 1050 if (ierr.ne.NF_NOERR) then 1085 1051 stop "Error: Failed to def_var bps" … … 1087 1053 1088 1054 ! write bps 1089 #ifdef NC_DOUBLE1090 ierr=NF_PUT_VAR_DOUBLE(outfid,bpsid,bps)1091 #else1092 1055 ierr=NF_PUT_VAR_REAL(outfid,bpsid,bps) 1093 #endif1094 1056 if (ierr.ne.NF_NOERR) then 1095 1057 stop "Error: Failed to write bps" 1096 1058 endif 1097 ENDIF ! of IF (bps_ok) 1059 1060 deallocate(aps) 1061 deallocate(bps) 1062 ENDIF ! of IF (hybrid) 1098 1063 1099 1064 !============================================================================== … … 1111 1076 1112 1077 ! write phisinit 1113 #ifdef NC_DOUBLE1114 ierr=NF_PUT_VAR_DOUBLE(outfid,phisinitid,phisinit)1115 #else1116 1078 ierr=NF_PUT_VAR_REAL(outfid,phisinitid,phisinit) 1117 #endif1118 1079 if (ierr.ne.NF_NOERR) then 1119 1080 stop "Error: Failed to write phisinit" 1120 1081 endif 1121 1082 1083 deallocate(phisinit) 1122 1084 ENDIF ! of IF (phis) 1123 1085 1124 1086 1125 ! Cleanup1126 deallocate(aps)1127 deallocate(bps)1128 deallocate(phisinit)1129 1130 1087 end subroutine init2 1088 1131 1089 !****************************************************************************** 1132 subroutine def_var(nid,name, title,units,nbdim,dim,nvarid,ierr)1090 subroutine def_var(nid,name,long_name,units,nbdim,dim,nvarid,ierr) 1133 1091 !============================================================================== 1134 1092 ! Purpose: Write a variable (i.e: add a variable to a dataset) 1135 ! called "name"; along with its attributes " title", "units"...1093 ! called "name"; along with its attributes "long_name", "units"... 1136 1094 ! to a file (following the NetCDF format) 1137 1095 !============================================================================== … … 1151 1109 character (len=*), intent(in) :: name 1152 1110 ! name(): [netcdf] variable's name 1153 character (len=*), intent(in) :: title1154 ! title(): [netcdf] variable's "title" attribute1111 character (len=*), intent(in) :: long_name 1112 ! long_name(): [netcdf] variable's "long_name" attribute 1155 1113 character (len=*), intent(in) :: units 1156 1114 ! unit(): [netcdf] variable's "units" attribute … … 1168 1126 1169 1127 ! Insert the definition of the variable 1170 #ifdef NC_DOUBLE1171 ierr=NF_DEF_VAR(nid,adjustl(name),NF_DOUBLE,nbdim,dim,nvarid)1172 #else1173 1128 ierr=NF_DEF_VAR(nid,adjustl(name),NF_FLOAT,nbdim,dim,nvarid) 1174 #endif1175 1129 1176 1130 ! Write the attributes 1177 ierr=NF_PUT_ATT_TEXT(nid,nvarid," title",len_trim(adjustl(title)),adjustl(title))1131 ierr=NF_PUT_ATT_TEXT(nid,nvarid,"long_name",len_trim(adjustl(long_name)),adjustl(long_name)) 1178 1132 ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",len_trim(adjustl(units)),adjustl(units)) 1179 1133 … … 1232 1186 ! Write valid_range() attribute 1233 1187 if (validr.eq.NF_NOERR) then 1234 #ifdef NC_DOUBLE1235 ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range)1236 #else1237 1188 ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range) 1238 #endif1239 1189 1240 1190 if (ierr.ne.NF_NOERR) then … … 1246 1196 endif 1247 1197 endif 1248 1198 if (miss.eq.NF_NOERR) then 1249 1199 ! Write "missing_value" attribute 1250 if (miss.eq.NF_NOERR) then1251 #ifdef NC_DOUBLE1252 ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing)1253 #else1254 1200 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing) 1255 #endif1256 1201 1257 1202 if (ierr.NE.NF_NOERR) then -
trunk/LMDZ.MARS/util/solzenangle.F90
r2416 r2434 15 15 character (len=50) file 16 16 ! file(): input file(s) names(s) 17 character (len=30), dimension(1 5) :: notconcat18 ! not concat(): names of the (15) variables that won't be concatenated17 character (len=30), dimension(16) :: notprocessed 18 ! notprocessed(): names of the (16) variables that won't be processed 19 19 character (len=50), dimension(:), allocatable :: var 20 ! var(): name(s) of variable(s) that will be concatenated21 character (len= 50) :: tmpvar,title,units20 ! var(): name(s) of variable(s) that will be processed 21 character (len=100) :: tmpvar,long_name,units 22 22 ! tmpvar(): used to temporarily store a variable name 23 ! title(): [netcdf] title attribute23 ! long_name(): [netcdf] long_name attribute 24 24 ! units(): [netcdf] units attribute 25 25 character (len=100) :: filename,vartmp … … 62 62 ! ctldim: [netcdf] "controle" dim ID 63 63 ! timedim: [netcdf] "timedim" dim ID 64 integer :: gcmlayerdim ! NetCDF dimension ID for # of layers in GCM 64 65 integer :: latvar,lonvar,altvar,ctlvar,timevar 65 66 ! latvar: [netcdf] ID of "latitude" variable … … 72 73 ! latlen: # of elements of lat() array 73 74 ! lonlen: # of elements of lon() array 74 ! alt var: # of elements of alt() array75 ! ctl var: # of elements of ctl() array75 ! altlen: # of elements of alt() array 76 ! ctllen: # of elements of ctl() array 76 77 ! timelen: # of elements of time() array 77 78 ! timelen_tot:# =timelen or timelen+1 (if 1 more time to interpolate needed) 78 79 integer :: nsol 79 80 ! nsol: # of sols in the input file AND # of elements of time() array in output 81 integer :: GCM_layers ! number of GCM atmospheric layers (may not be 82 ! same as altlen if file is an output of zrecast) 80 83 integer :: nout,latdimout,londimout,altdimout,timedimout,timevarout 81 84 ! nout: [netcdf] output file ID … … 85 88 ! timedimout: [netcdf] output time (dimension) ID 86 89 ! timevarout: [netcdf] ID of output "Time" variable 90 integer :: layerdimout ! NetCDF dimension ID for # of layers in GCM 87 91 integer :: varidout 88 92 ! varidout: [netcdf] variable ID # (of a variable to write to the output file) 89 integer :: Nnot concat,var_ok90 ! Nnot concat: # of (leading)variables that won't be concatenated93 integer :: Nnotprocessed,var_ok 94 ! Nnotprocessed: # of (leading)variables that won't be concatenated 91 95 ! var_ok: flag (0 or 1) 92 96 integer, dimension(4) :: corner,edges,dim … … 107 111 real :: sza ! solar zenith angle 108 112 character (len=30) :: szastr ! to store the sza value in a string 109 real :: start timeoffset ! offset(in sols) of sol 0 in input file, wrt Ls=0113 real :: startsol ! starting date (in sols) of sol 0 in input file, wrt Ls=0 110 114 real :: tmpsol ! to temporarily store a sol value 111 115 real :: tmpLs ! to temporarily store a Ls value … … 121 125 ! valid_range(2): [netcdf] interval in which a value is considered valid 122 126 logical :: stats ! stats=T when reading a "stats" kind of ile 127 real :: year_day_gcm = 669. ! number of sols in a year in GCM 128 129 123 130 124 131 … … 160 167 !============================================================================== 161 168 162 notconcat(1)='Time' 163 notconcat(2)='controle' 164 notconcat(3)='rlonu' 165 notconcat(4)='latitude' 166 notconcat(5)='longitude' 167 notconcat(6)='altitude' 168 notconcat(7)='rlatv' 169 notconcat(8)='aps' 170 notconcat(9)='bps' 171 notconcat(10)='ap' 172 notconcat(11)='bp' 173 notconcat(12)='cu' 174 notconcat(13)='cv' 175 notconcat(14)='aire' 176 notconcat(15)='phisinit' 169 notprocessed(1)='Time' 170 notprocessed(2)='controle' 171 notprocessed(3)='rlonu' 172 notprocessed(4)='latitude' 173 notprocessed(5)='longitude' 174 notprocessed(6)='altitude' 175 notprocessed(7)='rlatv' 176 notprocessed(8)='aps' 177 notprocessed(9)='bps' 178 notprocessed(10)='ap' 179 notprocessed(11)='bp' 180 notprocessed(12)='soildepth' 181 notprocessed(13)='cu' 182 notprocessed(14)='cv' 183 notprocessed(15)='aire' 184 notprocessed(16)='phisinit' 177 185 178 186 !============================================================================== … … 180 188 !============================================================================== 181 189 write(*,*) 182 Nnot concat=0190 Nnotprocessed=0 183 191 do i=1,nbvarfile 184 192 ierr=NF_INQ_VARNAME(nid,i,vartmp) 185 193 ! vartmp now contains the "name" of variable of ID # i 186 194 var_ok=0 187 do inter=1,1 5188 if (vartmp.eq.not concat(inter)) then195 do inter=1,16 196 if (vartmp.eq.notprocessed(inter)) then 189 197 var_ok=1 190 Nnot concat=Nnotconcat+1198 Nnotprocessed=Nnotprocessed+1 191 199 endif 192 200 enddo … … 194 202 enddo 195 203 196 ! Nnot concat: # of variables that won't be processed204 ! Nnotprocessed: # of variables that won't be processed 197 205 ! nbvarfile: total # of variables in file 198 allocate(var(nbvarfile-Nnot concat),stat=ierr)206 allocate(var(nbvarfile-Nnotprocessed),stat=ierr) 199 207 if (ierr.ne.0) then 200 write(*,*) "Error: failed allocation of var(nbvarfile-Nnot concat)"208 write(*,*) "Error: failed allocation of var(nbvarfile-Nnotprocessed)" 201 209 write(*,*) " nbvarfile=",nbvarfile 202 write(*,*) " Nnot concat=",Nnotconcat210 write(*,*) " Nnotprocessed=",Nnotprocessed 203 211 stop 204 212 endif … … 218 226 219 227 if (tmpvar=="all") then 220 nbvar=nbvarfile-Nnot concat221 do j=Nnot concat+1,nbvarfile222 ierr=nf_inq_varname(nid,j,var(j-Nnot concat))228 nbvar=nbvarfile-Nnotprocessed 229 do j=Nnotprocessed+1,nbvarfile 230 ierr=nf_inq_varname(nid,j,var(j-Nnotprocessed)) 223 231 enddo 224 232 ! Variables names from the file are stored in var() 225 nbvar=nbvarfile-Nnot concat233 nbvar=nbvarfile-Nnotprocessed 226 234 do i=1,nbvar 227 ierr=nf_inq_varname(nid,i+Nnot concat,var(i))235 ierr=nf_inq_varname(nid,i+Nnotprocessed,var(i)) 228 236 write(*,'(a9,1x,i2,1x,a1,1x,a50)') "variable ",i,":",var(i) 229 237 enddo … … 290 298 ! write(*,*) "altlen: ",altlen 291 299 300 ! load size of aps() or sigma() (in case it is not altlen) 301 ! default is that GCM_layers=altlen 302 ! but for outputs of zrecast, it may be a different value 303 ierr=NF_INQ_DIMID(nid,"GCM_layers",gcmlayerdim) 304 if (ierr.ne.NF_NOERR) then 305 ! didn't find a GCM_layers dimension; therefore we have: 306 GCM_layers=altlen 307 else 308 ! load value of GCM_layers 309 ierr=NF_INQ_DIMLEN(nid,gcmlayerdim,GCM_layers) 310 endif 311 ! write(*,*) "GCM_layers=",GCM_layers 312 292 313 ierr=NF_INQ_DIMID(nid,"index",ctldim) 293 314 if (ierr.NE.NF_NOERR) then … … 304 325 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen) 305 326 endif 306 ! write(*,*) "controle: ",controle 327 307 328 308 329 !============================================================================== … … 311 332 !============================================================================== 312 333 313 ! First call; initialize/allocate314 334 allocate(lat(latlen),stat=ierr) 315 335 if (ierr.ne.0) then … … 333 353 endif 334 354 335 #ifdef NC_DOUBLE336 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)337 #else338 355 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 339 #endif340 356 if (ierr.ne.0) then 341 357 write(*,*) "Error: failed to load latitude" … … 344 360 endif 345 361 346 #ifdef NC_DOUBLE347 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)348 #else349 362 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 350 #endif351 363 if (ierr.ne.0) then 352 364 write(*,*) "Error: failed to load longitude" … … 355 367 endif 356 368 357 #ifdef NC_DOUBLE358 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)359 #else360 369 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 361 #endif362 370 if (ierr.ne.0) then 363 371 write(*,*) "Error: failed to load altitude" … … 367 375 ! Get altitude attributes to handle files with any altitude type 368 376 ierr=nf_get_att_text(nid,altvar,'long_name',altlong_name) 377 if (ierr.ne.nf_noerr) then 378 ! if no attribute "long_name", try "title" 379 ierr=nf_get_att_text(nid,altvar,"title",altlong_name) 380 endif 369 381 ierr=nf_get_att_text(nid,altvar,'units',altunits) 370 382 ierr=nf_get_att_text(nid,altvar,'positive',altpositive) 371 383 372 384 if (ctllen .ne. 0) then 373 #ifdef NC_DOUBLE374 ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)375 #else376 385 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 377 #endif378 386 if (ierr.ne.0) then 379 387 write(*,*) "Error: failed to load controle" … … 403 411 ! write(*,*) "timelen: ",timelen 404 412 405 ! Sanity Check: Does "Time" has a " title" attribute413 ! Sanity Check: Does "Time" has a "long_name" attribute 406 414 ! and is it "Solar longitude" ? 407 ierr=nf_get_att_text(nid,timevar,"title",title) 408 if ((ierr.EQ.NF_NOERR).and.(title.eq."Solar longitude")) then 415 ierr=nf_get_att_text(nid,timevar,"long_name",long_name) 416 if (ierr.ne.nf_noerr) then 417 ! if no attribute "long_name", try "title" 418 ierr=nf_get_att_text(nid,timevar,"title",long_name) 419 endif 420 if ((ierr.EQ.NF_NOERR).and.(long_name.eq."Solar longitude")) then 409 421 write(*,*) "ERROR: Time axis in input file is in Solar Longitude!" 410 422 write(*,*) " localtime requires sols as time axis!" … … 420 432 endif 421 433 422 #ifdef NC_DOUBLE423 ierr = NF_GET_VAR_DOUBLE(nid,timevar,time)424 #else425 434 ierr = NF_GET_VAR_REAL(nid,timevar,time) 426 #endif427 435 if (ierr.NE.NF_NOERR) then 428 436 write(*,*) "Error , failed to load Time" … … 434 442 ! 2.4.1 Select local times to be saved "Time" in output file 435 443 !============================================================================== 436 write(*,*) "Planet side of the Solar Zenith Angle ? "444 write(*,*) "Planet side of the Solar Zenith Angle ? (morning or evening)" 437 445 read(*,*) planetside 438 446 if ((trim(planetside).ne."morning").and.(trim(planetside).ne."evening")) then … … 448 456 stop 449 457 endif 450 write(*,*) "Beginning date of the simulation file " 451 write(*,*) "(or median date of the simulation for a stats)?" 452 write(*,*) "(i.e. number of sols since Ls=0 at the Time=0.0 in the input file)" 453 read(*,*) starttimeoffset 458 459 ! Sol and season: 460 461 if (ctllen .ne. 0) then 462 startsol = int(int(ctl(4))+int(time(1) + ctl(27))) 463 else 464 startsol = int(time(1)) 465 end if 454 466 455 467 if ((timelen.eq.12).and.(time(1).eq.2).and.(time(timelen).eq.24))then … … 466 478 nsol = int(time(timelen)) - int(time(1)) 467 479 end if 468 469 480 allocate(intsol(nsol),stat=ierr) 470 481 if (ierr.ne.0) then … … 477 488 stop 478 489 endif 490 491 if (stats) then 492 write(*,*) "What is the mean Ls of this stats file (degree) ?" 493 read(*,*,iostat=ierr) tmpLs 494 startsol=0. 495 else 496 write(*,*) "Beginning date (sol since Ls=0) of this file is :",startsol 497 write(*,*) "If you do not want to change it, just write 'n' (recommended)" 498 write(*,*) "If you really wish to change it, write it now (not recommended!)" 499 read(*,*,iostat=ierr) startsol 500 if((ierr.eq.0).and.(ctllen.ne.0)) ctl(4)=startsol 501 write(*,*) "Beginning date (sol since Ls=0) will be :",startsol 502 end if 503 479 504 do it=1,nsol 480 505 intsol(it)= int(time(1)) + it-1. 481 506 do ilon=1,lonlen 482 ! For the computation of Ls, we try to take into account the rotation time483 ! of Mars it's supposed that the morning/evening507 ! For the computation of Ls, we try to take into account the 508 ! rotation time of Mars. It is supposed that the morning/evening 484 509 ! correspond to LT=6h/18h at the given longitude, which is 485 510 ! then reported to a sol value at longitude 0 486 511 if (trim(planetside).eq."morning") then 487 tmpsol = intsol(it) + (6.-lon(ilon)/15.)/24. + start timeoffset512 tmpsol = intsol(it) + (6.-lon(ilon)/15.)/24. + startsol 488 513 else !if trim(planetside).eq."evening" 489 tmpsol = intsol(it) + (18.-lon(ilon)/15.)/24. + start timeoffset514 tmpsol = intsol(it) + (18.-lon(ilon)/15.)/24. + startsol 490 515 endif 491 call sol2ls(tmpsol,tmpLs)516 if (.not.stats) call sol2ls(tmpsol,tmpLs) 492 517 do ilat=1,latlen 493 518 ! Compute the Local Time of the solar zenith angle at a given longitude … … 541 566 542 567 ! Initialize output file's lat,lon,alt and time dimensions 543 call initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen, &568 call initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,GCM_layers,& 544 569 altlong_name,altunits,altpositive,& 545 nout,latdimout,londimout,altdimout,timedimout,timevarout) 546 570 nout,latdimout,londimout,altdimout,timedimout,& 571 layerdimout,timevarout) 572 547 573 ! Initialize output file's aps,bps and phisinit variables 548 call init2(nid,lonlen,latlen,altlen, altdim,&549 nout,londimout,latdimout,altdimout )550 574 call init2(nid,lonlen,latlen,altlen,GCM_layers,& 575 nout,londimout,latdimout,altdimout,& 576 layerdimout) 551 577 552 578 !============================================================================== … … 557 583 558 584 do it=1,nsol 559 #ifdef NC_DOUBLE 560 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,it,1,intsol(it)*24.) 561 #else 562 ierr= NF_PUT_VARA_REAL(nout,timevarout,it,1,intsol(it)*24.) 563 #endif 585 ierr= NF_PUT_VARA_REAL(nout,timevarout,it,1,intsol(it)*24.) 564 586 enddo 565 587 else 566 588 do it=1,nsol 567 #ifdef NC_DOUBLE 568 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,it,1,intsol(it)) 569 #else 570 ierr= NF_PUT_VARA_REAL(nout,timevarout,it,1,intsol(it)) 571 #endif 572 if (ierr.NE.NF_NOERR) then 573 write(*,*) "Error , failed to write Time" 574 stop 575 endif 589 ierr= NF_PUT_VARA_REAL(nout,timevarout,it,1,intsol(it)) 590 if (ierr.NE.NF_NOERR) then 591 write(*,*) "Error , failed to write Time" 592 stop 593 endif 576 594 enddo 577 595 end if … … 584 602 585 603 !============================================================================== 586 ! 2.5.1 Check that variable to be read exist ein input file604 ! 2.5.1 Check that variable to be read exists in input file 587 605 !============================================================================== 588 606 … … 595 613 ierr=nf_inq_varndims(nid,varid,ndim) 596 614 615 ! Check that it is a 3D or 4D variable 616 if (ndim.lt.3) then 617 write(*,*) "Error:",trim(var(j))," is nor a 3D neither a 4D variable" 618 write(*,*) "We'll skip that variable..." 619 CYCLE ! go directly to the next variable 620 endif 621 597 622 !============================================================================== 598 623 ! 2.5.2 Prepare things in order to read/write the variable … … 642 667 643 668 units=" " 644 title=" " 645 ierr=nf_get_att_text(nid,varid,"title",title) 669 long_name=" " 670 ierr=nf_get_att_text(nid,varid,"long_name",long_name) 671 if (ierr.ne.nf_noerr) then 672 ! if no attribute "long_name", try "title" 673 ierr=nf_get_att_text(nid,varid,"title",long_name) 674 endif 646 675 ierr=nf_get_att_text(nid,varid,"units",units) 647 call def_var(nout,var(j), title,units,ndim,dim,varidout,ierr)676 call def_var(nout,var(j),long_name,units,ndim,dim,varidout,ierr) 648 677 649 678 … … 653 682 !============================================================================== 654 683 655 #ifdef NC_DOUBLE656 ierr = NF_GET_VAR_DOUBLE(nid,varid,var3d)657 miss=NF_GET_ATT_DOUBLE(nid,varid,"missing_value",missing)658 validr=NF_GET_ATT_DOUBLE(nid,varid,"valid_range",valid_range)659 #else660 684 ierr = NF_GET_VAR_REAL(nid,varid,var3d) 661 685 miss=NF_GET_ATT_REAL(nid,varid,"missing_value",missing) 662 686 validr=NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range) 663 #endif 664 665 ! If there is no missing value attribute in the input variable, create one 687 688 ! If there is no missing value attribute in the input variable, create one 666 689 if (miss.ne.NF_NOERR) then 667 690 missing = miss_lt … … 673 696 !============================================================================== 674 697 675 do ilon=1,lonlen698 do ilon=1,lonlen 676 699 ! Recast GCM local time (sol decimal value) at each longitude : 677 700 do it=1,timelen ! loop time input file … … 688 711 lt_outc(it)=intsol(it) + lt_out(ilon,ilat,it)/24. 689 712 endif 690 ! If the computed local time exceeds the GCM input file time bounds, 691 ! put a missing value in the local time variable 692 if ((lt_outc(it).gt.lt_gcm(timelen_tot)).OR.(lt_outc(it).lt.lt_gcm(1))) then 693 lt_out(ilon,ilat,it)=miss_lt 694 lt_outc(it)=miss_lt 695 endif 713 if (nsol.eq.1) then 714 ! If 1 sol file (stats), use all data from that sol. 715 if(lt_outc(it).gt.lt_gcm(timelen_tot)) lt_outc(it)=lt_outc(it)-1 716 if(lt_outc(it).lt.lt_gcm(1)) lt_outc(it)=lt_outc(it)+1 717 else 718 ! If the computed local time exceeds the GCM input file time bounds, 719 ! put a missing value in the local time variable 720 if ((lt_outc(it).gt.lt_gcm(timelen_tot)).OR.(lt_outc(it).lt.lt_gcm(1))) then 721 lt_out(ilon,ilat,it)=miss_lt 722 lt_outc(it)=miss_lt 723 endif 724 end if 696 725 enddo ! local time 697 726 … … 710 739 enddo ! local time 711 740 712 else if 741 else if (ndim==4) then 713 742 do ialt=1,altlen 714 743 do it=1,timelen ! loop time input file … … 725 754 enddo ! local time 726 755 enddo ! alt 727 endif 756 endif ! ndim 728 757 729 758 enddo ! lat 730 end do ! lon759 end do ! lon 731 760 732 761 … … 735 764 !============================================================================== 736 765 737 #ifdef NC_DOUBLE 738 ierr= NF_PUT_VARA_DOUBLE(nout,varidout,corner,edges,var3d_lt) 739 #else 740 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,var3d_lt) 741 #endif 742 743 if (ierr.ne.NF_NOERR) then 766 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,var3d_lt) 767 768 if (ierr.ne.NF_NOERR) then 744 769 write(*,*) 'PUT_VAR ERROR: ',NF_STRERROR(ierr) 745 770 stop "" 746 endif771 endif 747 772 748 773 ! Write "missing_value" (and "valid_range" if there is one) attributes in output file 749 call missing_value(nout,varidout,validr,miss,valid_range,missing)774 call missing_value(nout,varidout,validr,miss,valid_range,missing) 750 775 751 776 ! free var3d() array 752 deallocate(var3d)753 deallocate(var3d_lt)777 deallocate(var3d) 778 deallocate(var3d_lt) 754 779 755 780 enddo ! of do j=1,nbvar … … 780 805 write(szastr,*) sza 781 806 if (trim(planetside).eq."morning") then 782 title="Morning-side LTST at sza="//trim(adjustl(szastr))//"deg"807 long_name="Morning-side LTST at sza="//trim(adjustl(szastr))//"deg" 783 808 else !if trim(planetside).eq."evening" 784 title="Evening-side LTST at sza="//trim(adjustl(szastr))//"deg" 785 endif 786 call def_var(nout,tmpvar,title,units,3,dim,varidout,ierr) 787 788 #ifdef NC_DOUBLE 789 ierr= NF_PUT_VARA_DOUBLE(nout,varidout,corner,edges,lt_out) 790 #else 809 long_name="Evening-side LTST at sza="//trim(adjustl(szastr))//"deg" 810 endif 811 call def_var(nout,tmpvar,long_name,units,3,dim,varidout,ierr) 812 791 813 ierr= NF_PUT_VARA_REAL(nout,varidout,corner,edges,lt_out) 792 #endif793 814 if (ierr.ne.NF_NOERR) then 794 815 write(*,*) 'PUT_VAR ERROR: ',NF_STRERROR(ierr) … … 798 819 validr=NF_NOERR+1 799 820 miss=NF_NOERR 800 call missing_value(nout,varidout,validr,miss,(0,0),miss_lt) 821 valid_range(:)=0. 822 call missing_value(nout,varidout,validr,miss,valid_range,miss_lt) 801 823 write(*,*)"with missing value = ",miss_lt 802 824 !============================================================================== … … 837 859 !****************************************************************************** 838 860 839 subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen, &861 subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,GCM_layers,& 840 862 altlong_name,altunits,altpositive,& 841 nout,latdimout,londimout,altdimout,timedimout,timevarout) 863 nout,latdimout,londimout,altdimout,timedimout,& 864 layerdimout,timevarout) 842 865 !============================================================================== 843 866 ! Purpose: … … 866 889 real, intent(in):: ctl(ctllen) 867 890 ! ctl(): controle 891 integer,intent(in) :: GCM_layers ! number of GCM layers 868 892 character (len=*), intent(in) :: altlong_name 869 893 ! altlong_name(): [netcdf] altitude "long_name" attribute … … 882 906 integer, intent(out):: timedimout 883 907 ! timedimout: [netcdf] "Time" ID 908 integer,intent(out) :: layerdimout 909 ! layerdimout: [netcdf] "GCM_layers" ID 884 910 integer, intent(out):: timevarout 885 911 ! timevarout: [netcdf] "Time" (considered as a variable) ID … … 943 969 endif 944 970 971 ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout) 972 if (ierr.NE.NF_NOERR) then 973 WRITE(*,*)'initiate: error failed to define dimension <GCM_layers>' 974 write(*,*) NF_STRERROR(ierr) 975 stop "" 976 endif 977 945 978 ! End netcdf define mode 946 979 ierr = NF_ENDDEF(nout) … … 950 983 stop "" 951 984 endif 952 953 985 !============================================================================== 954 986 ! 3. Write "Time" and its attributes … … 960 992 ierr = NF_REDEF (nout) 961 993 ierr = NF_PUT_ATT_TEXT(nout,timevarout,'comment',135,& 962 "The true unit of the variable Time is the integer value of sol at lon=0deg. A false unit is put to enable reading from Grads or Ferret") 994 "The true unit of the variable Time is the integer value & 995 of sol at lon=0deg. A false unit is put to enable reading from Grads or Ferret") 963 996 ! End netcdf define mode 964 997 ierr = NF_ENDDEF(nout) … … 971 1004 (/latdimout/),nvarid,ierr) 972 1005 973 #ifdef NC_DOUBLE974 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,lat)975 #else976 1006 ierr = NF_PUT_VAR_REAL (nout,nvarid,lat) 977 #endif978 1007 if (ierr.NE.NF_NOERR) then 979 1008 WRITE(*,*)'initiate: error failed writing variable <latitude>' … … 989 1018 (/londimout/),nvarid,ierr) 990 1019 991 #ifdef NC_DOUBLE992 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,lon)993 #else994 1020 ierr = NF_PUT_VAR_REAL (nout,nvarid,lon) 995 #endif996 1021 if (ierr.NE.NF_NOERR) then 997 1022 WRITE(*,*)'initiate: error failed writing variable <longitude>' … … 1007 1032 ierr = NF_REDEF (nout) 1008 1033 1009 #ifdef NC_DOUBLE1010 ierr = NF_DEF_VAR (nout,"altitude",NF_DOUBLE,1,altdimout,nvarid)1011 #else1012 1034 ierr = NF_DEF_VAR (nout,"altitude",NF_FLOAT,1,altdimout,nvarid) 1013 #endif1014 1035 1015 1036 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'long_name',len_trim(adjustl(altlong_name)),adjustl(altlong_name)) … … 1020 1041 ierr = NF_ENDDEF(nout) 1021 1042 1022 #ifdef NC_DOUBLE 1023 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,alt) 1024 #else 1025 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 1026 #endif 1043 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 1027 1044 if (ierr.NE.NF_NOERR) then 1028 1045 WRITE(*,*)'initiate: error failed writing variable <altitude>' … … 1039 1056 ierr = NF_REDEF (nout) 1040 1057 1041 #ifdef NC_DOUBLE1042 ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)1043 #else1044 1058 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 1045 #endif 1046 1047 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 1059 1060 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",18,"Control parameters") 1048 1061 1049 1062 ! End netcdf define mode 1050 1063 ierr = NF_ENDDEF(nout) 1051 1064 1052 #ifdef NC_DOUBLE1053 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)1054 #else1055 1065 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 1056 #endif1057 1066 if (ierr.NE.NF_NOERR) then 1058 1067 WRITE(*,*)'initiate: error failed writing variable <controle>' … … 1065 1074 1066 1075 !****************************************************************************** 1067 subroutine init2(infid,lonlen,latlen,altlen,altdimid, & 1068 outfid,londimout,latdimout,altdimout) 1076 subroutine init2(infid,lonlen,latlen,altlen,GCM_layers, & 1077 outfid,londimout,latdimout,altdimout, & 1078 layerdimout) 1069 1079 !============================================================================== 1070 1080 ! Purpose: … … 1086 1096 integer, intent(in) :: latlen ! # of grid points along latitude 1087 1097 integer, intent(in) :: altlen ! # of grid points along altitude 1088 integer, intent(in) :: altdimid ! ID of altitude dimension1098 integer, intent(in) :: GCM_layers ! # of GCM atmospheric layers 1089 1099 integer, intent(in) :: outfid ! NetCDF output file ID 1090 1100 integer, intent(in) :: londimout ! longitude dimension ID 1091 1101 integer, intent(in) :: latdimout ! latitude dimension ID 1092 1102 integer, intent(in) :: altdimout ! altitude dimension ID 1103 integer, intent(in) :: layerdimout ! GCM_layers dimension ID 1093 1104 !============================================================================== 1094 1105 ! Local variables: … … 1100 1111 integer :: tmpdimid ! temporary dimension ID 1101 1112 integer :: tmpvarid ! temporary variable ID 1102 logical :: phis, aps_ok, bps_ok ! are "phisinit" "aps" "bps" available ? 1113 integer :: tmplen ! temporary variable length 1114 logical :: phis,hybrid ! are "phisinit" and "aps"/"bps" available ? 1103 1115 1104 1116 … … 1108 1120 1109 1121 ! hybrid coordinate aps 1110 allocate(aps(altlen),stat=ierr) 1122 !write(*,*) "aps: altlen=",altlen," GCM_layers=",GCM_layers 1123 allocate(aps(GCM_layers),stat=ierr) 1124 if (ierr.ne.0) then 1125 write(*,*) "init2: failed to allocate aps!" 1126 stop 1127 endif 1128 ierr=NF_INQ_VARID(infid,"aps",tmpvarid) 1129 if (ierr.ne.NF_NOERR) then 1130 write(*,*) "Ooops. Failed to get aps ID. OK." 1131 hybrid=.false. 1132 else 1133 ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps) 1134 hybrid=.true. 1135 if (ierr.ne.NF_NOERR) then 1136 stop "init2 Error: Failed reading aps" 1137 endif 1138 1139 ! hybrid coordinate bps 1140 ! write(*,*) "bps: altlen=",altlen," GCM_layers=",GCM_layers 1141 allocate(bps(GCM_layers),stat=ierr) 1111 1142 if (ierr.ne.0) then 1112 write(*,*) "init2: failed to allocate aps(altlen)"1143 write(*,*) "init2: failed to allocate bps!" 1113 1144 stop 1114 1145 endif 1115 1116 ierr=NF_INQ_VARID(infid,"aps",tmpvarid) 1117 if (ierr.ne.NF_NOERR) then 1118 write(*,*) "oops Failed to get aps ID. OK" 1119 aps_ok=.false. 1120 else 1121 ! Check that aps() is the right size (it most likely won't be if 1122 ! zrecast has be used to generate the input file) 1123 ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid) 1124 if (tmpdimid.ne.altdimid) then 1125 write(*,*) "init2: wrong dimension size for aps(), skipping it ..." 1126 aps_ok=.false. 1127 else 1128 ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps) 1129 if (ierr.ne.NF_NOERR) then 1130 stop "init2 error: Failed reading aps" 1131 endif 1132 aps_ok=.true. 1133 endif 1134 endif 1135 1136 ! hybrid coordinate bps 1137 allocate(bps(altlen),stat=ierr) 1138 if (ierr.ne.0) then 1139 write(*,*) "init2: failed to allocate bps(altlen)" 1140 stop 1141 endif 1142 1143 ierr=NF_INQ_VARID(infid,"bps",tmpvarid) 1144 if (ierr.ne.NF_NOERR) then 1145 write(*,*) "oops: Failed to get bps ID. OK" 1146 bps_ok=.false. 1147 else 1148 ! Check that bps() is the right size 1149 ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid) 1150 if (tmpdimid.ne.altdimid) then 1151 write(*,*) "init2: wrong dimension size for bps(), skipping it ..." 1152 bps_ok=.false. 1146 ierr=NF_INQ_VARID(infid,"bps",tmpvarid) 1147 if (ierr.ne.NF_NOERR) then 1148 write(*,*) "Ooops. Failed to get bps ID. OK." 1149 hybrid=.false. 1153 1150 else 1154 1151 ierr=NF_GET_VAR_REAL(infid,tmpvarid,bps) … … 1156 1153 stop "init2 Error: Failed reading bps" 1157 1154 endif 1158 bps_ok=.true.1159 1155 endif 1160 1156 endif … … 1188 1184 !============================================================================== 1189 1185 1190 IF ( aps_ok) then1186 IF (hybrid) then 1191 1187 ! define aps 1192 1188 call def_var(outfid,"aps","hybrid pressure at midlayers"," ",1,& 1193 (/ altdimout/),apsid,ierr)1189 (/layerdimout/),apsid,ierr) 1194 1190 if (ierr.ne.NF_NOERR) then 1195 1191 stop "Error: Failed to def_var aps" … … 1197 1193 1198 1194 ! write aps 1199 #ifdef NC_DOUBLE1200 ierr=NF_PUT_VAR_DOUBLE(outfid,apsid,aps)1201 #else1202 1195 ierr=NF_PUT_VAR_REAL(outfid,apsid,aps) 1203 #endif1204 1196 if (ierr.ne.NF_NOERR) then 1205 1197 stop "Error: Failed to write aps" 1206 1198 endif 1207 ENDIF ! of IF (aps_ok) 1208 1209 IF (bps_ok) then 1199 1210 1200 ! define bps 1211 1201 call def_var(outfid,"bps","hybrid sigma at midlayers"," ",1,& 1212 (/ altdimout/),bpsid,ierr)1202 (/layerdimout/),bpsid,ierr) 1213 1203 if (ierr.ne.NF_NOERR) then 1214 1204 stop "Error: Failed to def_var bps" … … 1216 1206 1217 1207 ! write bps 1218 #ifdef NC_DOUBLE1219 ierr=NF_PUT_VAR_DOUBLE(outfid,bpsid,bps)1220 #else1221 1208 ierr=NF_PUT_VAR_REAL(outfid,bpsid,bps) 1222 #endif1223 1209 if (ierr.ne.NF_NOERR) then 1224 1210 stop "Error: Failed to write bps" 1225 1211 endif 1226 ENDIF ! of IF (bps_ok) 1212 1213 deallocate(aps) 1214 deallocate(bps) 1215 ENDIF ! of IF (hybrid) 1227 1216 1228 1217 !============================================================================== … … 1240 1229 1241 1230 ! write phisinit 1242 #ifdef NC_DOUBLE1243 ierr=NF_PUT_VAR_DOUBLE(outfid,phisinitid,phisinit)1244 #else1245 1231 ierr=NF_PUT_VAR_REAL(outfid,phisinitid,phisinit) 1246 #endif1247 1232 if (ierr.ne.NF_NOERR) then 1248 1233 stop "Error: Failed to write phisinit" 1249 1234 endif 1250 1235 1236 deallocate(phisinit) 1251 1237 ENDIF ! of IF (phis) 1252 1238 1253 1239 1254 ! Cleanup1255 deallocate(aps)1256 deallocate(bps)1257 deallocate(phisinit)1258 1259 1240 end subroutine init2 1260 1241 1261 1242 !****************************************************************************** 1262 subroutine def_var(nid,name, title,units,nbdim,dim,nvarid,ierr)1243 subroutine def_var(nid,name,long_name,units,nbdim,dim,nvarid,ierr) 1263 1244 !============================================================================== 1264 1245 ! Purpose: Write a variable (i.e: add a variable to a dataset) 1265 ! called "name"; along with its attributes " title", "units"...1246 ! called "name"; along with its attributes "long_name", "units"... 1266 1247 ! to a file (following the NetCDF format) 1267 1248 !============================================================================== … … 1281 1262 character (len=*), intent(in) :: name 1282 1263 ! name(): [netcdf] variable's name 1283 character (len=*), intent(in) :: title1284 ! title(): [netcdf] variable's "title" attribute1264 character (len=*), intent(in) :: long_name 1265 ! long_name(): [netcdf] variable's "long_name" attribute 1285 1266 character (len=*), intent(in) :: units 1286 1267 ! unit(): [netcdf] variable's "units" attribute … … 1298 1279 1299 1280 ! Insert the definition of the variable 1300 #ifdef NC_DOUBLE1301 ierr=NF_DEF_VAR(nid,adjustl(name),NF_DOUBLE,nbdim,dim,nvarid)1302 #else1303 1281 ierr=NF_DEF_VAR(nid,adjustl(name),NF_FLOAT,nbdim,dim,nvarid) 1304 #endif1305 1282 1306 1283 ! Write the attributes 1307 ierr=NF_PUT_ATT_TEXT(nid,nvarid," title",len_trim(adjustl(title)),adjustl(title))1284 ierr=NF_PUT_ATT_TEXT(nid,nvarid,"long_name",len_trim(adjustl(long_name)),adjustl(long_name)) 1308 1285 ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",len_trim(adjustl(units)),adjustl(units)) 1309 1286 … … 1363 1340 ! Write valid_range() attribute 1364 1341 if (validr.eq.NF_NOERR) then 1365 #ifdef NC_DOUBLE1366 ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range)1367 #else1368 1342 ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range) 1369 #endif1370 1343 1371 1344 if (ierr.ne.NF_NOERR) then … … 1380 1353 ! Write "missing_value" attribute 1381 1354 if (miss.eq.NF_NOERR) then 1382 #ifdef NC_DOUBLE1383 ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing)1384 #else1385 1355 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing) 1386 #endif1387 1356 1388 1357 if (ierr.NE.NF_NOERR) then -
trunk/LMDZ.MARS/util/solzenangle.def
r2289 r2434 18 18 5) solar zenith angle (within [0;180[ deg) 19 19 0deg = zenith ; 90deg = terminator at the surface ; >90deg = terminator in altitude 20 6) starttimeoffset : 21 - for a diagfi/concat : sol value at the beginning of the run, wrt Ls=0 22 - for a stats : sol value at the middle of the run, wrt Ls=0 23 20 6) reference time 21 - for a diagfi/concat : 22 - write "n" to keep the date stored in the file (recommended) 23 - if needed: sol value at the beginning of the run, wrt Ls=0 24 - for a stats : Ls value at the middle of the run (degree) 24 25 USE : 25 26 solzenangle.e < solzenangle.def
Note: See TracChangeset
for help on using the changeset viewer.