From 47302a776408d180f16d90ad31f779325ef9eced Mon Sep 17 00:00:00 2001 From: Sylvain Watelet Date: Thu, 31 Mar 2016 14:50:26 +0000 Subject: [PATCH] Sylvain Watelet - 31/03/2016 : MAJOR upgrade : bottom analysis now possible. The distance is counted from the bottom ocean, derived from the interpolation of the topography topo.grd. Program added : interpbottom.f90. Programs upgraded : divadoall,ivaselectorODV4,dvvinterpodv. --- DIVA3D/src/Fortran/Util/interpbottom.f90 | 290 +++++++++++++++++++++++ JRA4/Climatology/divadoall | 10 +- JRA4/Climatology/divaselectorODV4 | 37 ++- JRA4/Climatology/dvvinterpodv | 76 +++++- 4 files changed, 395 insertions(+), 18 deletions(-) create mode 100755 DIVA3D/src/Fortran/Util/interpbottom.f90 diff --git a/DIVA3D/src/Fortran/Util/interpbottom.f90 b/DIVA3D/src/Fortran/Util/interpbottom.f90 new file mode 100755 index 0000000..78cfdef --- /dev/null +++ b/DIVA3D/src/Fortran/Util/interpbottom.f90 @@ -0,0 +1,290 @@ +Program interpbottom +implicit none + +!------------------------------------------------ +! Sylvain Watelet - 27/03/2016 +! swatelelet@ulg.ac.be +! +! Interpolation of the bottom depth from topo.grd +!------------------------------------------------ + + integer nmax,iw,i,j,n,ii,d + parameter(nmax=10000,iw=100000000) + REAL*4 U(iw) + REAL*4 X(nmax) + REAL*4 Y(nmax) + + real*8,allocatable,dimension(:)::lon,lat,botdepth + real*8::deltalat,deltalon,a,c,R=6371.,pi=3.14159265,distance + real*8,dimension(4)::dist_proche,U_proche + + integer NX, NY, KMAX, ipr, nw, IMAX, JMAX + real VALEXU + real*8 W8(1) + real xorig, yorig, dx, dy, xend, yend, valex + + character(len=256)::gherfile,infofile,bigfile,bigfile2 + character(len=256)::c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,botdepthc + +gherfile="topo.grd" +infofile="TopoInfo.dat" +bigfile="bigfile.nobotdepth" +bigfile2="bigfile.botdepth" + +open (unit=10,file=trim(gherfile),form='unformatted') +CALL UREADC(10,W8,U,VALEXU,IPR,IMAX,JMAX,KMAX,NW) + + if (KMAX.ne.1) stop "2D Field only, please." + + ipr=4 + nw=imax*jmax + if(nw.gt.iw) then + write(6,*) 'Severe error, increase iw interpbottom.f90' + stop 'Severe error, increase iw interpbottom.f90' + endif + if(imax.gt.nmax.or.jmax.gt.nmax) then + write(6,*) 'Severe error, increase iw interpbottom.f90' + stop 'Severe error, increase nmax interpbottom.f90' + endif + + +! Reads the grid data from info file +!---------------------------------------------- + open(unit=90,file=trim(infofile)) + read(90,*) xorig + read(90,*) yorig + read(90,*) dx + read(90,*) dy + read(90,*) xend + read(90,*) yend + + NX=int((xend-xorig)/dx) + NY=int((yend-yorig)/dy) + + close(90) +! write(*,*) 'valex = ,', valex + close(10) + +!------------------------------------------------ +! Creation of dimensions +!------------------------------------------------ + +do i = 1, IMAX + X(i) = xorig + (i - 1) * dx +end do +do j = 1, JMAX + Y(j) = yorig + (j - 1) * dy +end do + +!Do j=1,jmax +! Do i=1,imax +! write(0,*) X(i),Y(j),U(i+(j-1)*imax) +! Enddo +!Enddo + +!------------------------------------------------ +! Reading coordinates of VAR.bigfile.nobotdepth +!------------------------------------------------ + +open(unit=11,file=trim(bigfile)) + +n=0 +Do while (.true.) + read(11,*,end=1009) + n=n+1 +Enddo + +1009 continue + +allocate(lon(n),lat(n),botdepth(n)) + +rewind(11) + +i=0 +Do while (.true.) + i=i+1 + read(11,*,end=1010) lon(i),lat(i) +Enddo + +1010 continue + + close(11) + +!write(0,*) n,lon(n),lat(n) + +!------------------------------------------------ +! Interpolation of bot depth on each lon-lat +!------------------------------------------------ + +Do ii=1,n + dist_proche(:)=99999. + U_proche(:)=99999. + Do i=1,imax + Do j=1,jmax + d=d+1 + + deltalon=lon(ii)-X(i) + deltalat=lat(ii)-Y(j) + + If ((abs(deltalat)>dy).or.(abs(deltalon)>dx)) cycle + + deltalat = deltalat*(pi/180.) + deltalon = deltalon*(pi/180.) + + a = (sin(deltalat/2.))**2 + cos(lat(ii)*(pi/180.))*cos(Y(j)*(pi/180.))*(sin(deltalon/2.))**2 !! Haversine formula + c = 2*atan2(sqrt(a),sqrt(1-a)) + distance = R*c + + If (distance input/contour.depth +fi + echo 'divadoall:' echo 'divadoall:' 'Running diva3Ddress on '"$var" $year $month echo 'divadoall:' '########################################' diff --git a/JRA4/Climatology/divaselectorODV4 b/JRA4/Climatology/divaselectorODV4 index 9c27a07..b7374e6 100755 --- a/JRA4/Climatology/divaselectorODV4 +++ b/JRA4/Climatology/divaselectorODV4 @@ -53,6 +53,14 @@ fi fi inputfile=$1 +isextractf=$2 + +if [ "$isextractf" == "3" ] +then +echo "" +echo "Extraction will be performed from the BOTTOM." +echo "" +fi if [ -f "$inputfile" ] then @@ -199,6 +207,10 @@ datecol_timeseries=$(grep -i "time_ISO8601" ODVcolumns | head -1 | awk -F "$del cdicol=$(grep -i "LOCAL_CDI" ODVcolumns | head -1 | awk -F "$delimiter" '{print $3}') edmocol=$(grep -i "EDMO" ODVcolumns | head -1 | awk -F "$delimiter" '{print $3}') issdn=1 + +botcol=$(grep -i "bot" ODVcolumns | grep -i "depth" | head -1 | awk -F "$delimiter" '{print $3}') +echo "Bottom depth in column " $botcol + if [ "$datecol_timeseries" != "" ] then echo "!!! Warning : TIME SERIES detected ! The column time_ISO8601 is present => it will be used as the ONLY time axis !!!" @@ -206,17 +218,17 @@ datecol=$datecol_timeseries fi if [ "$cdicol" == "" ] then -echo WARNING NO CDI FOUND +echo "WARNING NO CDI FOUND" issdn=0 else echo CDI found in column $cdicol fi if [ "$edmocol" == "" ] then -echo WARNING NO EDMO-CODE FOUND +echo "WARNING NO EDMO-CODE FOUND" issdn=0 else -echo EDMO found in column $edmocol +echo "EDMO found in column" $edmocol fi # Pressure for the moment if depth, carefull about bottom depth columns @@ -277,7 +289,7 @@ then awk -F "$delimiter" '{if (substr($0,1,2) !="//") {print $0} }' $inputfile | \ awk -F "$delimiter" -v datacol=$datacol -v qccol=$qccol -v latcol=$latcol -v loncol=$loncol -v datecol=$datecol -v depthcol=$depthcol -v todepth=$todepth \ -v cruisecol=$cruisecol -v stationcol=$stationcol -v valexodv=$valexodv -v boundmin=$boundmin -v boundmax=$boundmax \ - -v issdn=$issdn -v edmocol=$edmocol -v cdicol=$cdicol \ + -v issdn=$issdn -v edmocol=$edmocol -v cdicol=$cdicol -v botcol=$botcol -v isextractf=$isextractf \ ' function myqfok(qf,n,qval) # ===== @@ -301,6 +313,7 @@ return 0 {if ($loncol +0> -180+360) {n=int(($loncol-(-180))/360); $loncol=$loncol-n*360}} ; {if ($latcol > "") {ww=$latcol} else {$latcol=ww}}; {if ($datecol > "") {www=$datecol} else {$datecol=www}}; + {if ($botcol > "") {wwww=$botcol} else {$botcol=wwww}}; year=substr($datecol,1,4); month=substr($datecol,6,2); day=substr($datecol,9,2); @@ -316,9 +329,21 @@ return 0 {if (issdn==1) {foralex=$edmocol"-"$cdicol} else {foralex="Cruise:"$cruisecol"-"$stationcol"-"$loncol"-"$latcol}}; # # if ( $qccol==1 || $qccol==2 || $qccol==8 ); - if ($datacol > "" && qfok==1 && $datacol != valexodv) print $loncol,$latcol,$datacol,$depthcol,$qccol,year,month,day,hour,$datecol,foralex}' \ + {if ($datacol > "" && qfok==1 && $datacol != valexodv && isextractf != 3) {print $loncol,$latcol,$datacol,$depthcol,$qccol,year,month,day,hour,$datecol,foralex,$botcol} else if ($datacol > "" && qfok==1 && $datacol != valexodv && isextractf == 3 && $botcol > "") {print $loncol,$latcol,$datacol,$depthcol,$qccol,year,month,day,hour,$datecol,foralex,$botcol} else if ($datacol > "" && qfok==1 && $datacol != valexodv && isextractf == 3 && $botcol == "") {print "error"}}}' \ > ${WORK}/"${var}".bigfile +# interpolation of topo.grd, replace the column with bottom depth into bigfile + if [ "$isextractf" == "3" ] + then + cp ${WORK}/"${var}".bigfile ${WORK}/bigfile.nobotdepth #no ${var} to avoid blank spaces problems in fortran + cp -v input/topo.grd ${WORK}/topo.grd + cp -v input/TopoInfo.dat ${WORK}/TopoInfo.dat + cd ${WORK} + ../../../DIVA3D/bin/interpbottom.a + cp bigfile.botdepth "${var}".bigfile + cd .. + fi + fi #Then make interpolation on standard depth. @@ -327,7 +352,7 @@ echo "Now interpolating" # make sure columns are now in correct order -awk -f "dvvinterpodv" ./input/contour.depth ${WORK}/"${var}".bigfile > ${WORK}/"${var}".bigfile.interp +awk -f "dvvinterpodv" -v isextractf=$isextractf ./input/contour.depth ${WORK}/"${var}".bigfile > ${WORK}/"${var}".bigfile.interp #Then split file in data for layers? diff --git a/JRA4/Climatology/dvvinterpodv b/JRA4/Climatology/dvvinterpodv index 1c17e69..ab0b5c5 100644 --- a/JRA4/Climatology/dvvinterpodv +++ b/JRA4/Climatology/dvvinterpodv @@ -12,7 +12,7 @@ # Algorithm: # Valex in input must be eliminated. # -function vinterp(zin,vin,nin,zout,vout,nout,valex) +function vinterp(zin,vin,nin,zout,vout,nout,valex,isextractf) # ======= { kl=1; klp=jmmin(nin,kl+1); k=0; # make sure input is sorted @@ -35,11 +35,20 @@ while (k "/dev/stderr"; + if (zout[k] < zin[kl] && abs(zin[kl]-zout[k]) < DDout && isextractf == 3) {vout[k]=vin[kl]; continue} + +# Otherwise, if measurement too far if (zout[k] < zin[kl]) {vout[k]=valex; continue} + # Too deep, but save point that is within one meter of deepest point if(kl==nin && zout[k] < zin[kl]+1) {vout[k]=vin[kl];continue} if(kl>=nin) {vout[k]=valex;continue} @@ -48,6 +57,7 @@ while (k "/dev/stderr"; if( abs(zin[kl]-zout[k])> DDDDDD && abs(zin[klp]-zout[k])> DDDDDD) {vout[k]=valex;continue}; # First point if (kl==1) {vout[k]=flin(zin[kl],vin[kl],zin[klp],vin[klp],zout[k]);continue} @@ -186,14 +196,42 @@ return n # Main program # -BEGIN {meta[1]=0;meta[2]=0;meta[3]=0;meta[4]=0;meta[5]=0;meta[6]=0;meta[7]=0;meta[8]=0;meta[9]=0;i=1;ifirst=1} +BEGIN {meta[1]=0;meta[2]=0;meta[3]=0;meta[4]=0;meta[5]=0;meta[6]=0;meta[7]=0;meta[8]=0;meta[9]=0;meta[10]=0;i=1;ifirst=1} NR==FNR {level[k+1]=$1;vout[k+1]=0;k=k+1;jjj=0;next} {if (jjj<=0) {jjj=1;i=1;jm=k; {for (j=1;j<=jm/2;j++) { zz=level[j]; level[j]=level[jm-j+1];level[jm-j+1]=zz}} }} #} + +#{print level[3] > "/dev/stderr"} + {#Main loop -if (ifirst==1 && i==1) {meta[1]=$1 ; meta[2]=$2 ; meta[3]=$5 ; meta[4]=$6 ; meta[5]=$7; meta[6]=$8 ; meta[7]=$9 ; meta[8]=$10 ; meta[9]=$11 ; ifirst=0}; +if (ifirst==1 && i==1) + { +meta[1]=$1 ; meta[2]=$2 ; meta[3]=$5 ; meta[4]=$6 ; meta[5]=$7; meta[6]=$8 ; meta[7]=$9 ; meta[8]=$10 ; meta[9]=$11 ; meta[10]=$12 ; ifirst=0 ; + } + +#bottom - level if isextractf=3 + +{if (isextractf==3) + { + for (j=1;j<=jm;j++) + { + newlevel[j]=meta[10]-level[j]; +# print meta[10],newlevel[1],newlevel[2],level[1],level[2] > "/dev/stderr"; + if (newlevel[j]<0) + { +# print "WARNING : some profiles contain incorrect bottom depth or depth, PLEASE correct your ODV file (these profiles are NOT extracted)" > "/dev/stderr"; +# print meta[10],newlevel[1],newlevel[2],level[1],level[2] > "/dev/stderr"; + err[j]=1 + } + else + { + err[j]=0 + } + } + } +} #conformity of profiles if (meta[8]!=$10 && meta[9]==$11) @@ -208,21 +246,39 @@ zin[i]=$4;vin[i]=$3;i=i+1#;print "uu",i-1,zin[i-1],vin[i-1] } else # profile now to be treated + +#{print isextractf > "/dev/stderr"} +#{print newlevel[1],newlevel[2],level[1],level[2] > "/dev/stderr"} + { -zzz=$4;vvv=$3;mm1=$1;mm2=$2;mm3=$3;mm4=$4;mm5=$5;mm6=$6;mm7=$7;mm8=$8;mm9=$9;mm10=$10;mm11=$11; +zzz=$4;vvv=$3;mm1=$1;mm2=$2;mm3=$3;mm4=$4;mm5=$5;mm6=$6;mm7=$7;mm8=$8;mm9=$9;mm10=$10;mm11=$11;mm12=$12; # print "jjj",i-1,jm,vin[1],zin[1],meta[8],meta[9],vin[i-1],zin[i-1]; - nin=i-1;nout=jm;valex=99999; jmb=vinterp(zin,vin,nin,level,vout,nout,valex); + nin=i-1;nout=jm;valex=99999; + {if (isextractf==3) + jmb=vinterp(zin,vin,nin,newlevel,vout,nout,valex,isextractf); + else + jmb=vinterp(zin,vin,nin,level,vout,nout,valex,isextractf); + } # add test to put out only when no exclusion value - for (ii=1; ii<=nout; ii++) {if (vout[ii] != valex) print meta[1],meta[2],vout[ii],level[ii],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-ii+1)}; - meta[1]=mm1 ; meta[2]=mm2 ; meta[3]=mm5 ; meta[4]=mm6 ; meta[5]=mm7; meta[6]=mm8 ; meta[7]=mm9 ; meta[8]=mm10 ; meta[9]=mm11; + for (ii=1; ii<=nout; ii++) {if (vout[ii] != valex && err[ii] != 1 && isextractf == 3) print meta[1],meta[2],vout[ii],newlevel[ii],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-ii+1)}; + for (ii=1; ii<=nout; ii++) {if (vout[ii] != valex && err[ii] != 1 && isextractf != 3) print meta[1],meta[2],vout[ii],level[ii],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-ii+1)}; + meta[1]=mm1 ; meta[2]=mm2 ; meta[3]=mm5 ; meta[4]=mm6 ; meta[5]=mm7; meta[6]=mm8 ; meta[7]=mm9 ; meta[8]=mm10 ; meta[9]=mm11 ; meta[10]=mm12; zin[1]=zzz;vin[1]=vvv;i=2; + for (ii=1; ii<=nout; ii++) {err[ii]=0}; } } END { - nin=i-1;nout=jm;valex=99999; jmb=vinterp(zin,vin,nin,level,vout,nout,valex); + nin=i-1;nout=jm;valex=99999; + {if (isextractf==3) + jmb=vinterp(zin,vin,nin,newlevel,vout,nout,valex,isextractf); + else + jmb=vinterp(zin,vin,nin,level,vout,nout,valex,isextractf); + } # add test to put out only when no exclusion value - for (i=1; i<=nout; i++) {if (vout[i] != valex) print meta[1],meta[2],vout[i],level[i],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-i+1)}; +# for (i=1; i<=nout; i++) {if (vout[i] != valex) print meta[1],meta[2],vout[i],level[i],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-i+1)}; + for (ii=1; ii<=nout; ii++) {if (vout[ii] != valex && err[ii] != 1 && isextractf == 3) print meta[1],meta[2],vout[ii],newlevel[ii],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-ii+1)}; + for (ii=1; ii<=nout; ii++) {if (vout[ii] != valex && err[ii] != 1 && isextractf != 3) print meta[1],meta[2],vout[ii],level[ii],meta[3],meta[4],meta[5],meta[6],meta[7],meta[8],meta[9],10000+(jm-ii+1)}; }