program p_argocmp use mod_common use mod_year_info use mod_levitus use netcdf use m_year_day use m_datetojulian use m_get_grid use mod_xc, only: mod_xc_idm => idm, mod_xc_jdm => jdm use mod_za , only: zaiost, zaioempty use mod_read_dailyab use mod_read_rstab use mod_read_weekab use mod_spline_calc use m_read_field_wrapper use m_read_coriolis use m_dump_coriolis use m_initconfmap use m_pivotp use m_oldtonew implicit none !integer*4, external :: iargc ! Version info of this program character(len=*), parameter :: cver = 'V0.1' ! Input file with days character(len=80) :: hyc_file integer :: maxfiles,numfiles type(year_info) :: rt,rti,rtd,rtb ! Time info type integer :: year,day,hour,find,k,ios,nrmem,ifile, & counter, refyear real :: undef logical :: ex real, allocatable, dimension(:,: ) :: dp, pres, presold, saln, temp logical, allocatable, dimension(:) :: valid_profile character(len=8), dimension(:), pointer :: floatid character(len=8) :: dateinfo,cdate character(len=11) :: tag7 character(len=3) :: rungen ! Run ID character(len=80) :: modcorfile,corfile ! Name of new netcdf file character(len=80) :: fbase,filename_ice,cprof character(len=40) :: tmpchar,vartitle,fname character(len=40) :: grid_mapping,coords_mapping character(len=160) :: tmpcharlong character(len= 4) :: char_fac character(len=3) :: cgg,cii character(len=12) :: clon, clat, cjuld integer :: fname_iday,fname_iyear,fname_dday,fname_dyear integer :: finduf,findab,findrst,finddaily,findweek integer :: i, i2, i3,ilon,jlat integer :: hycfile integer :: tmpdim(2) integer :: igroup, istat,nstat real, pointer, dimension(:,:) :: csaln, cspres, ctemp, ctpres real, pointer, dimension(:,:) :: msaln , mtemp, msaln1, mtemp1, mpres1 real, pointer, dimension(:,:) :: mpresd, msalnd, mtempd real, pointer, dimension(:,:) :: levsaln, levtemp ! Error flags - used locally by nersc logical, pointer, dimension(:,:) :: errorflag_sal,errorflag_temp ! invalid profile - per mersea definitions logical, pointer, dimension(:) :: invalid_sal,invalid_temp real, pointer, dimension(:) :: cslon,ctlon,cslat,ctlat,csjuld,ctjuld real :: lat_n,lon_n integer :: iprof, izlev integer :: nprof, nzlev integer :: ipiv,jpiv integer :: validk integer :: k2 integer :: iyear, imonth, iday logical :: l_ncdump=.false. integer :: fid_num character(len=10) :: cfid_num undef = -999 if (iargc()/=2 .and. iargc()/=3 ) then print *,'Usage:' print *,' argocmp argo-file hycom-file [ncdump]' stop else call getarg(1,corfile) call getarg(2,hyc_file) if (iargc()==3) then call getarg(3,tmpchar) if (trim(tmpchar)=='-ncdump') then l_ncdump=.true. else print *,'Usage:' print *,' argocmp argo-file hycom-file [ncdump]' stop end if end if end if !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Initialization stuff for model -- allocation galore print * ! Get bathymetry - lon/lat fields and sets up bigrid call get_grid ! Get the coriolis schtuff - for now we can deal with one input file only !corfile='20060131_prof.nc' call read_coriolis(trim(corfile),csaln,cspres,cslon,cslat,csjuld,floatid, & errorflag_sal, invalid_sal, 'PSAL',undef) call read_coriolis(trim(corfile),ctemp,ctpres,ctlon,ctlat,ctjuld,floatid, & errorflag_temp,invalid_temp,'TEMP',undef) if (any(cspres/=ctpres)) then print *,'Temperature and salinity is defined at different levels. Fix me.' stop end if nzlev = size(csaln,1) nprof = size(csaln,2) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Start working with hycom data file !hyc_file='FORDAILY_2006_108_2006_108.a' write (6,'(a)',advance='yes') 'Reading from '//trim(hyc_file) rungen=hyc_file(1:3) ! Check for type ... finduf=index(hyc_file,'.uf') findab=max(index(hyc_file,'.a'),index(hyc_file,'.b')) if (finduf>0) then ! old type print *,'uf-files no longer supported by this routine ...' stop else if (.not. findab>0) then print *,'No .ab files' stop else ! We have a .ab-file. Now figure out what type. findrst =index(hyc_file,'restart') finddaily=index(hyc_file,'DAILY') findweek =index(hyc_file,'AVE') if (findrst==4) then hycfile=1 ! 1 for restart files elseif (finddaily==4) then hycfile=2 ! 1 for daily files elseif (findweek==4) then hycfile=3 ! 1 for weekly files else print *,'Can not deduce file type from file name' stop end if end if ! Read different fields - returns undef if not defined fbase=hyc_file(1:findab-1) if (hycfile==2) then call daily_average_read_header(trim(fbase),rti,rtd,nrmem,idm,jdm,kdm) else if (hycfile==1) then call rst_read_header(trim(fbase),rti,nrmem,idm,jdm,kdm) rtd=rti nrmem=1 else if (hycfile==3) then call week_read_header(trim(fbase),rti,idm,jdm,kdm) rtd=rti nrmem=1 end if ! Init file io mod_xc_idm=idm mod_xc_jdm=jdm nx=idm ! Get rid of these ny=jdm ! Get rid of these nz=kdm ! Get rid of these call zaiost call initconfmap ! We now have the averaged estimate if (hycfile==2) then ! daily write (6,'(a,i4,a)') 'Fields based on ',nrmem,' members' end if ! Start allocating fields now.. allocate(dp (idm,jdm)) ! Holds 2D vars on original grid allocate(pres (idm,jdm)) ! Holds 2D vars on original grid allocate(presold (idm,jdm)) ! Holds 2D vars on original grid allocate(temp (idm,jdm)) ! Holds 2D vars on original grid allocate(saln (idm,jdm)) ! Holds 2D vars on original grid allocate(msaln1(kdm,nprof)) allocate(mtemp1(kdm,nprof)) allocate(mpres1(kdm,nprof)) allocate(msalnd(nzlev,nprof)) allocate(mtempd(nzlev,nprof)) allocate(mpresd(nzlev,nprof)) allocate(msaln(nzlev,nprof)) allocate(mtemp(nzlev,nprof)) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Days start from "0". Add 1 to get real ! dates rtb=rti write(rtb%cdm,'(i2.2)') rtb%idm+1 write(rtb%cdd,'(i3.3)') rtb%idd+1 write(rtd%cdm,'(i2.2)') rtd%idm+1 write(rtd%cdd,'(i3.3)') rtd%idd+1 write(rti%cdm,'(i2.2)') rti%idm+1 write(rti%cdd,'(i3.3)') rti%idd+1 ! Start working through the model layers mpres1=0. pres=0. presold=0. allocate(valid_profile(nprof)) valid_profile=.true. do k=1,kdm ! Cater to different needs if (hycfile==2) then call read_field2d(trim(fbase),'pres ',pres ,idm,jdm,k,undef) pres=pres / ( onem * nrmem) dp=pres-presold elseif (hycfile==3) then ! mod_average typo, pres is actually dp call read_weekfield2d(trim(fbase),'pres ',dp ,idm,jdm,kdm,undef) pres=presold+dp elseif (hycfile==1) then call read_rstfield2d(trim(fbase),'dp ',dp ,idm,jdm,kdm,undef) dp=dp/onem pres=presold+dp end if ! Read temp & saln call read_field_wrapper_2d(saln ,'saln ',trim(fbase),idm,jdm,k,hycfile,nrmem,undef,dp) call read_field_wrapper_2d(temp ,'temp ',trim(fbase),idm,jdm,k,hycfile,nrmem,undef,dp) ! Put into model profile array 1. Same vertical levels as model ! Go through coriolis profiles -- find corresponding points in model do iprof=1,nprof ! Get closest point in model call oldtonew(cslat(iprof),cslon(iprof),lat_n,lon_n) call pivotp(lon_n,lat_n,ipiv,jpiv) if ( ipiv>1 .and. ipiv < idm .and. jpiv > 1 .and. jpiv < jdm .and. & depths(ipiv,jpiv)>1.) then if (k==1) then print *,'model / obs point :',modlon(ipiv,jpiv),modlat(ipiv,jpiv), & cslon(iprof),cslat(iprof) end if mtemp1(k,iprof)=temp(ipiv,jpiv) msaln1(k,iprof)=saln(ipiv,jpiv) mpres1(k,iprof)=pres(ipiv,jpiv) else if (.not.(ipiv>1.and.ipiv1.and.jpivcspres(k,iprof)) then mtempd(k,iprof)=mtemp1(k2,iprof) msalnd(k,iprof)=msaln1(k2,iprof) mpresd(k,iprof)=mpres1(k2,iprof)*.5 end if else if ( mpres1(k2,iprof)>cspres(k,iprof) .and. mpres1(k2-1,iprof)