!
      program mkcdf
!
! May, 2003 bf: 
! Read IEEE binary boundary files from mgcm model (Jim Murphy),
!   and write equivalent netcdf files for import to mtgcm15.
!
      use readmgcm,only: rdmgcm
      implicit none
      character(len=120) :: filein,fileout
      integer :: eof,irec
! ----NEW LBC DATASETS (October 2003) ---------------
!     filein = 'TGCM_lowbound_Ls90-94.TESyr1'
!     filein = 'TGCM_lowbound_Ls269-274.TESyr2'
!     filein = 'TGCM_lbnd_composite_TESyr2_720ts.Ls269-274'
!     filein = 'TGCM_lbnd_composite_TESyr1_720ts.Ls90-94'
! ----NEW LBC DATASETS (March 2004) ---------------
!     filein='TGCM_lbnd_comp_Ls90-94_TESyr1_GCM2.F24'
!     filein='TGCM_lbnd_comp_Ls90-94_TESyr1_GCM2.F2p4'
!     filein='TGCM_lbnd_comp_Ls90-94_TESyr1_GCM2.F2p4b'
!     filein='TGCM_lbnd_comp_TESyr1_LS90-94.FILT2.4hr'
!     filein='TGCM_lbnd_comp_Ls90-94_TESyr1_GCM2.FILT12.0'
!     filein='TGCM_lbnd_comp_Ls90-94_GCM2_TESyr1.FILT12_HIGHdust'
! ----NEW LBC DATASETS (April 2004 for MARGSRAM TES YEAR#1) ------
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls000'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls030'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls060'
!     filein='TGCM_lbnd_comp_Ls90-94_GCM2_TESyr1.FILT12_HIGHdust'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls120'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls150'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls180'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls210'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls240'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls270'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls300'
!     filein='TGCM_lbnd_comp_TESyr1_filt12.Ls330'
! ----NEW LBC DATASETS FOR JARED AT SPG. AGU 2004-----
!     filein='TGCM_lbnd_comp_TAU0.3_CONR0.005.Ls090'
!     filein='TGCM_lbnd_comp_TAU0.3_CONR0.03.Ls090'
!     filein='TGCM_lbnd_comp_TAU0.3_CONR0.3.Ls090'
!     filein='TGCM_lbnd_comp_TAU1.0_CONR0.005.Ls090'
!     filein='TGCM_lbnd_comp_TAU1.0_CONR0.03.Ls090'
!     filein='TGCM_lbnd_comp_TAU1.0_CONR0.3.Ls090'
!
!     filein='TGCM_lbnd_comp_TAU1.0_CONR0.005.Ls270'
!     filein='TGCM_lbnd_comp_TAU1.0_CONR0.03.Ls270'
!     filein='TGCM_lbnd_comp_TAU1.0_CONR0.3.Ls270'
! ----NEW LBC DATASETS (Fall 2004 for MARGSRAM TES YEAR#2) ------
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls180'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls210'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls240'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls270'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls300'
!     ------------------------------------------
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls000'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls030'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls060'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls090'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls120'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls150'
!     filein='TGCM_lbnd_comp_TESyr2_filt12.Ls330'
! ----NEW LBC DATASETS (Winter 2005: Inverted Topo : TES YEAR#1) ------
!     filein='TGCM_lbnd_comp_TESyr1_invtopo.Ls090'
!     filein='TGCM_lbnd_comp_invtopo.Ls270'
! ----NEW LBC DATASETS (Summer 2005: Extremes of Vertical Dust : TES YR#1) 
! --- (a) constant veritical dist. of opacity (CONRATH param. constant everywhere)
! --- (b) TES YR#1 horizontal distirbution (empirical)
! --- (c) taufac1.25 = 1.25 X TES YR#1 horionatl distribution of opacity
!     filein='TGCM_lbnd_comp_CONRNU0.001.Ls090'
!     filein='TGCM_lbnd_comp_TESyr1_CONRNU0.03.Ls090'
!     filein='TGCM_lbnd_comp_CONRNUlat_TESyr1.Ls090'
!     filein='TGCMlbnd_TESyr1_CONRNU0.03_taufac1.25.Ls090'
! ----NEW LBC DATASETS (Winter 2006: TES Year #3) ------
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.005.Ls270'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.005.Ls90'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.01_Ls270'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.01_Ls90'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.03.Ls270'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.03.Ls90'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.3.Ls270'
!     filein='TGCM_lbnd_comp_TESyr3_CONRNU0.3.Ls90'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls090'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls270'
! ----NEW LBC DATASETS (Fall 2006: FRancisco LMD-MTGCM Comparisons) ------
!     filein='TGCM_lbnd_comp_tau0.0.Ls90'
!     filein='TGCM_lbnd_comp_tau0.0_Ls0'
!     filein='TGCM_lbnd_comp_tau0.3_CONRN0.3_Ls0'
! ----NEW LBC DATASETS (Winter 2007: JGR Paper additional run)
!     filein='TGCM_lbnd_DailyAvg_TESyr3_CONR0.005.Ls270'
! ----NEW LBC DATASETS (Summer 2007: Mars 7th Conference:  TES YR3)
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls000'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls030'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls060'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls120'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls150'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls180'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls210'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls240'
!     filein='TGCM_lbnd_comp_TESyr3_CONRtau.Ls300'
! ----NEW LBC DATASETS (Summer 2007: Mars 7th Conference:  TES YR1 Deeper)
!     filein='TGCM_lbnd_comp_TESyr1_CONRtau_deeper.Ls090'
!     filein='TGCM_lbnd_comp_TESyr1_CONRtau_deeper.Ls150'
!     filein='TGCM_lbnd_comp_TESyr1_CONRtau_deeper.Ls180'
!     filein='TGCM_lbnd_comp_TESyr1_CONRtau_deeper.Ls240'
!     filein='TGCM_lbnd_comp_TESyr1_CONRtau_deeper.Ls270'
!     filein='TGCM_lbnd_comp_TESyr1_CONRtau_deeper.Ls300'
! ----NEW LBC DATASETS (Fall 2007: Deeper dust studies :TES YR1 Deeper)
!      filein='TGCM_lbnd_comp_THEMISyr1_Ls230_deepdust.102507'
!      filein='TGCM_lbnd_comp_TESyr1_CONRNU0.0001_155.Ls180'
!      filein='TGCM_lbnd_comp_TESyr1_CONRNU0.0001_144.Ls120'
!      filein='TGCM_lbnd_comp_Intrctv-dust_Ls230.102507'
!      filein='TGCM_lbnd_comp_Intrctv-dust_Ls150.010708' 
!      filein='TGCM_lbnd_comp_THEMISyr1_Ls230_depdust.011008'
!      filein='TGCM_lbnd_comp_THEMISyr1_Ls230_file252_deepdust.011008'
!      filein='TGCM_lbnd_comp_THEMISyr1_Ls230_depdust.011008'
! ----NEW LBC DATASETS (Fall 2010:  JPL/CPD MAVEN Studies)
!      filein='TGCM_lbnd_comp_Ls270_TAU0.3-GW-VAR200-KAP2.5E-6.110210'
!      filein='TGCM_lbnd_comp_Ls270_TAU0.3-noGW-noRF.110210'
!      filein='TGCM_lbnd_comp_Ls270_TAU1.0-GW-VAR200-KAP2.5E-6.103110'
! ----
!      filein='TGCM_lbnd-Ls270-GW200-2.5E-6_TESyr1-CONR0.005-noswap'
!      filein='TGCM_lbnd-Ls90-GW200-2.5E-6_TESyr1-CONR0.005-noswap'
!      filein='TGCM_lbnd-Ls180-GW200-2.5E-6_TESyr1-CONR0.005-noswap'
!      filein='TGCM_lbnd-Ls0-GW200-2.5E-6_TESyr1-CONR0.005-noswap'
!      filein='TGCMlbnd-Ls270-GW200-2.5E-6_TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls90-GW200-2.5E-6_TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls180-GW200-2.5E-6_TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls0-GW200-2.5E-6_TESyr1-CONR0.005-SWAP'
! ----
!      filein='TGCMlbnd-Ls0-GW-VAR200-2.5E-5-TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls90-GW-VAR200-2.5E-5-TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls180-GW-VAR200-2.5E-5-TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls270-GW-VAR200-2.5E-5-TESyr1-CONR0.005-SWAP'
! ----
!      filein='TGCMlbnd-Ls0-noGW-noRF-TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls90-noGW-noRF-TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls180-noGW-noRF-TESyr1-CONR0.005-SWAP'
!      filein='TGCMlbnd-Ls270-noGW-noRF-TESyr1-CONR0.005-SWAP'
! ----
!      filein='TGCMlbnd-Ls0-noGW-wRF-TESyr1-CONRNU0.005-SWAP'
!      filein='TGCMlbnd-Ls90-noGW-wRF-TESyr1-CONRNU0.005-SWAP'
!      filein='TGCMlbnd-Ls180-noGW-wRF-TESyr1-CONRNU0.005-SWAP'
!      filein='TGCMlbnd-Ls270-noGW-wRF-TESyr1-CONRNU0.005-SWAP'
! ----
!      filein='TGCMlbnd-Ls0-GW-VARMOLAsd-2.5E-6-TESyr1-CONRNU0.005-SWAP'
!      filein='TGCMlbnd-Ls90-GW-VARMOLAsd-2.5E-6-TESyr1-CONRNU0.005-SW'
!      filein='TGCMlbnd-Ls180-GW-VARMOLAsd-2.5E-6-TESyr1-CONRNU0.005-SW'
!      filein='TGCMlbnd-Ls270-GW-VARMOLAsd-2.5E-6-TESyr1-CONRNU0.005-SW'
! ----
!      filein='TGCMlbnd-Ls0-GW-VARMOLAsd-3.0E-7-TESyr1-CONRNU0.01-SW'
!      filein='TGCMlbnd-Ls90-GW-VARMOLAsd-3.0E-7-TESyr1-CONRNU0.01-SW'
!      filein='TGCMlbnd-Ls180-GW-VARMOLAsd-3.0E-7-TESyr1-CONRNU0.01-SW'
!      filein='TGCMlbnd-Ls270-GW-VARMOLAsd-3.0E-7-TESyr1-CONRNU0.01-SW'
! ----
!      filein='TGCMlbnd-Ls0-noGW-wRF-TESyr1-CONRNU0.01-SW'
!      filein='TGCMlbnd-Ls90-noGW-wRF-TESyr1-CONRNU0.01-SW'
!      filein='TGCMlbnd-Ls180-noGW-wRF-TESyr1-CONRNU0.01-SW'
!      filein='TGCMlbnd-Ls270-noGW-wRF-TESyr1-CONRNU0.01-SW'
! ----
!      filein='TGCMlbnd-Ls0-GW-2.5E-5-damp10.0km.031511'
!      filein='TGCMlbnd-Ls90-GW-2.5E-5-damp10.0km.031511'
!      filein='TGCMlbnd-Ls180-GW-2.5E-5-damp10.0km.031511'
!      filein='TGCMlbnd-Ls270-GW-2.5E-5-damp10.0km.031511'
! ----
!      filein='TGCMlbnd-Ls0-GW-2.5E-5-damp1.0km.031611'
!      filein='TGCMlbnd-Ls90-GW-2.5E-5-damp1.0km.031611'
!      filein='TGCMlbnd-Ls180-GW-2.5E-5-damp1.0km.031611'
!      filein='TGCMlbnd-Ls270-GW-2.5E-5-damp1.0km.031611'
! ----
!      filein='TGCMlbnd-Ls0-GW-2.5E-5-damp5.0km.031611'
!      filein='TGCMlbnd-Ls90-GW-2.5E-5-damp5.0km.031611'
!      filein='TGCMlbnd-Ls180-GW-2.5E-5-damp5.0km.031611'
!      filein='TGCMlbnd-Ls270-GW-2.5E-5-damp5.0km.031611'
! ----
!      filein='TGCMlbnd-Ls0-GW-2.5E-5-damp7.5km.032011'
!      filein='TGCMlbnd-Ls90-GW-2.5E-5-damp7.5km.032111'
!      filein='TGCMlbnd-Ls180-GW-2.5E-5-damp7.5km.032111'
!      filein='TGCMlbnd-Ls270-GW-2.5E-5-damp7.5km.032111'
! ----
!      filein='TGCMlbnd-Ls0-GW-2.5E-5-damp2.5km.032211'
!      filein='TGCMlbnd-Ls90-GW-2.5E-5-damp2.5km.032211'
!      filein='TGCMlbnd-Ls180-GW-2.5E-5-damp2.5km.032211'
!      filein='TGCMlbnd-Ls270-GW-2.5E-5-damp2.5km.032211'
! ------------------------------------------------------------------------
!      filein='TGCMlbnd-Ls000-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls030-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls060-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls090-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls120-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls150-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls180-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls210-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls240-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls270-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls300-TAU0.5-GW-damp7.5km.051511'
!      filein='TGCMlbnd-Ls330-TAU0.5-GW-damp7.5km.051511'
! ------------------------------------------------------------------------
!      filein='TGCMlbnd-Ls000-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls030-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls060-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls090-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls120-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls150-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls180-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls210-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls240-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls270-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls300-TESyr1-0.001-GW-damp7.5km.052411'
!      filein='TGCMlbnd-Ls330-TESyr1-0.001-GW-damp7.5km.052411'
!      fileout = trim(filein)//'.nc'
! ------------------------------------------------------------------------
!      filein='TGCMlbnd-Ls000-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls030-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls060-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls090-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls120-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls150-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls180-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls210-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls240-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls270-TESyr2-0.001-GW-damp7.5km.053111'
!      filein='TGCMlbnd-Ls300-TESyr2-0.001-GW-damp7.5km.053111'
       filein='TGCMlbnd-Ls330-TESyr2-0.001-GW-damp7.5km.053111'
! ------------------------------------------------------------------------
      fileout = trim(filein)//'.nc'
      write(6,"('mkcdf: fileout=',a)") trim(fileout)
      irec = 0
      readloop: do
        call rdmgcm(filein,eof)
        irec = irec+1
!
! Write only first 3 records for test:
!       if (irec == 3) eof = 1

        call mkncfile(fileout,eof)
        if (eof > 0) exit readloop

      enddo readloop

      end program mkcdf
