#!/bin/csh -f

# Script to process HIRS CTP orbitital data.

#---------------------------------------------------------------
# Location of HIRS CTP input statistics files.
  set HIRS_CTP_DIR = /data/richardf/HIRS/run16
  set HIRS_CTP_DAILY_MEAN_DIR = /data/richardf/HIRS/run16

# Location of the executable file (also working directory).
  set EXE_DIR = /home/richardf/src/HIRS_Processing/HIRS_AVHRR_CTPs

# Set days (Dyyddd) to process.
# January
  set days = (D08001 D08002 D08003 D08004 D08005 D08006 \
              D08007 D08008 D08009 D08010 D08011 D08012 \
              D08013 D08014 D08015 D08016 D08017 D08018 \
              D08019 D08020 D08021 D08022 D08023 D08024 \
              D08025 D08026 D08027 D08028 D08029 D08030 \
              D08031)
  @ ndays = 31
# set days = (D09001 D09002 D09003 D09004 D09005 D09006 \
#             D09007 D09008 D09009 D09010 D09011 D09012 \
#             D09013 D09014 D09015 D09016 D09017 D09018 \
#             D09019 D09020 D09021 D09022 D09023 D09024 \
#             D09025 D09026 D09027 D09028 D09029 D09030 \
#             D09031)
# @ ndays = 31
# set days = (D08001)
# @ ndays = 1

# Caution - these for a leap year!
# February
# set days = (D08032 D08033 D08034 D08035 D08036 D08037 \
#             D08038 D08039 D08040 D08041 D08042 D08043 \
#             D08044 D08045 D08046 D08047 D08048 D08049 \
#             D08050 D08051 D08052 D08053 D08054 D08055 \
#             D08056 D08057 D08058 D08059 D08060)
# @ ndays = 29

# February for a regular year (2009)
# set days = (D09032 D09033 D09034 D09035 D09036 D09037 \
#             D09038 D09039 D09040 D09041 D09042 D09043 \
#             D09044 D09045 D09046 D09047 D09048 D09049 \
#             D09050 D09051 D09052 D09053 D09054 D09055 \
#             D09056 D09057 D09058 D09059)
# @ ndays = 28

# Caution - these for a leap year!
# March   
# set days = (D08061 D08062 D08063 D08064 D08065 D08066 \
#             D08067 D08068 D08069 D08070 D08071 D08072 \
#             D08073 D08074 D08075 D08076 D08077 D08078 \
#             D08079 D08080 D08081 D08082 D08083 D08084 \
#             D08085 D08086 D08087 D08088 D08089 D08090 \
#             D08091)
# @ ndays = 31

# March for a regular year (2009)
# set days = (D09060 D09061 D09062 D09063 D09064 D09065 \
#             D09066 D09067 D09068 D09069 D09070 D09071 \
#             D09072 D09073 D09074 D09075 D09076 D09077 \
#             D09078 D09079 D09080 D09081 D09082 D09083 \
#             D09084 D09085 D09086 D09087 D09088 D09089 \
#             D09090)
# @ ndays = 31

# April for leap year
# set days = (D08092 D08093 D08094 D08095 D08096 D08097 \
#             D08098 D08099 D08100 D08101 D08102 D08103 \
#             D08104 D08105 D08106 D08107 D08108 D08109 \
#             D08110 D08111 D08112 D08113 D08114 D08115 \
#             D08116 D08117 D08118 D08119 D08120 D08121) 
# @ ndays = 30

# April for regular year (2009)
# set days = (D09091 D09092 D09093 D09094 D09095 D09096 \
#             D09097 D09098 D09099 D09100 D09101 D09102 \
#             D09103 D09104 D09105 D09106 D09107 D09108 \
#             D09109 D09110 D09111 D09112 D09113 D09114 \
#             D09115 D09116 D09117 D09118 D09119 D09120) 
# @ ndays = 30

# Caution - these for a leap year!
# May
# set days = (D08122 D08123 D08124 D08125 D08126 D08127 \
#             D08128 D08129 D08130 D08131 D08132 D08133 \
#             D08134 D08135 D08136 D08137 D08138 D08139 \
#             D08140 D08141 D08142 D08143 D08144 D08145 \
#             D08146 D08147 D08148 D08149 D08150 D08151 \
#             D08152)
# @ ndays = 31

# May for a regular year (2009)
# set days = (D09121 D09122 D09123 D09124 D09125 D09126 \
#             D09127 D09128 D09129 D09130 D09131 D09132 \
#             D09133 D09134 D09135 D09136 D09137 D09138 \
#             D09139 D09140 D09141 D09142 D09143 D09144 \
#             D09145 D09146 D09147 D09148 D09149 D09150 \
#             D09151)
# @ ndays = 31

# Caution - these for a leap year!
# June
# set days = (D08153 D08154 D08155 D08156 D08157 D08158 \
#             D08159 D08160 D08161 D08162 D08163 D08164 \
#             D08165 D08166 D08167 D08168 D08169 D08170 \
#             D08171 D08172 D08173 D08174 D08175 D08176 \
#             D08177 D08178 D08179 D08180 D08181 D08182)
# @ ndays = 30

# June for a regular year (2009)
# set days = (D09152 D09153 D09154 D09155 D09156 D09157 \
#             D09158 D09159 D09160 D09161 D09162 D09163 \
#             D09164 D09165 D09166 D09167 D09168 D09169 \
#             D09170 D09171 D09172 D09173 D09174 D09175 \
#             D09176 D09177 D09178 D09179 D09180 D09181)
# @ ndays = 30

# Caution - these for a leap year!
# July
# set days = (D08183 D08184 D08185 D08186 D08187 D08188 \
#             D08189 D08190 D08191 D08192 D08193 D08194 \
#             D08195 D08196 D08197 D08198 D08199 D08200 \
#             D08201 D08202 D08203 D08204 D08205 D08206 \
#             D08207 D08208 D08209 D08210 D08211 D08212 \
#             D08213)
# @ ndays = 31

# July for regular year (2009)
# set days = (D09182 D09183 D09184 D09185 D09186 D09187 \
#             D09188 D09189 D09190 D09191 D09192 D09193 \
#             D09194 D09195 D09196 D09197 D09198 D09199 \
#             D09200 D09201 D09202 D09203 D09204 D09205 \
#             D09206 D09207 D09208 D09209 D09210 D09211 \
#             D09212)
# @ ndays = 31
# set days = (D09182)
# @ ndays = 1

# Caution - these for a leap year!
# August
# set days = (D08214 D08215 D08216 D08217 D08218 D08219 \
#             D08220 D08221 D08222 D08223 D08224 D08225 \
#             D08226 D08227 D08228 D08229 D08230 D08231 \
#             D08232 D08233 D08234 D08235 D08236 D08237 \
#             D08238 D08239 D08240 D08241 D08242 D08243 \
#             D08244)
# @ ndays = 31

# August for a regular year (2009)
# set days = (D09213 D09214 D09215 D09216 D09217 D09218 \
#             D09219 D09220 D09221 D09222 D09223 D09224 \
#             D09225 D09226 D09227 D09228 D09229 D09230 \
#             D09231 D09232 D09233 D09234 D09235 D09236 \
#             D09237 D09238 D09239 D09240 D09241 D09242 \
#             D09243)
# @ ndays = 31

# Caution - these for a leap year!
# September
# set days = (D08245 D08246 D08247 D08248 D08249 D08250 \
#             D08251 D08252 D08253 D08254 D08255 D08256 \
#             D08257 D08258 D08259 D08260 D08261 D08262 \
#             D08263 D08264 D08265 D08266 D08267 D08268 \
#             D08269 D08270 D08271 D08272 D08273 D08274)
# @ ndays = 30

# September for a regular year (2009)
# set days = (D09244 D09245 D09246 D09247 D09248 D09249 \
#             D09250 D09251 D09252 D09253 D09254 D09255 \
#             D09256 D09257 D09258 D09259 D09260 D09261 \
#             D09262 D09263 D09264 D09265 D09266 D09267 \
#             D09268 D09269 D09270 D09271 D09272 D09273)
# @ ndays = 30

# Caution - these for a leap year!
# October
# set days = (D08275 D08276 D08277 D08278 D08279 D08280 \
#             D08281 D08282 D08283 D08284 D08285 D08286 \
#             D08287 D08288 D08289 D08290 D08291 D08292 \
#             D08293 D08294 D08295 D08296 D08297 D08298 \
#             D08299 D08300 D08301 D08302 D08303 D08304 \
#             D08305)
# @ ndays = 31

# October for a regular year (2009)
# set days = (D09274 D09275 D09276 D09277 D09278 D09279 \
#             D09280 D09281 D09282 D09283 D09284 D09285 \
#             D09286 D09287 D09288 D09289 D09290 D09291 \
#             D09292 D09293 D09294 D09295 D09296 D09297 \
#             D09298 D09299 D09300 D09301 D09302 D09303 \
#             D09304)
# @ ndays = 31

# Caution - these for a leap year!
# November
# set days = (D08306 D08307 D08308 D08309 D08310 D08311 \
#             D08312 D08313 D08314 D08315 D08316 D08317 \
#             D08318 D08319 D08320 D08321 D08322 D08323 \
#             D08324 D08325 D08326 D08327 D08328 D08329 \
#             D08330 D08331 D08332 D08333 D08334 D08335)
# @ ndays = 30

# November for a regular year (2009)
# set days = (D09305 D09306 D09307 D09308 D09309 D09310 \
#             D09311 D09312 D09313 D09314 D09315 D09316 \
#             D09317 D09318 D09319 D09320 D09321 D09322 \
#             D09323 D09324 D09325 D09326 D09327 D09328 \
#             D09329 D09330 D09331 D09332 D09333 D09334)
# @ ndays = 30

# Caution - these for a leap year!
# December
# set days = (D08336 D08337 D08338 D08339 D08340 D08341 \
#             D08342 D08343 D08344 D08345 D08346 D08347 \
#             D08348 D08349 D08350 D08351 D08352 D08353 \
#             D08354 D08355 D08356 D08357 D08358 D08359 \
#             D08360 D08361 D08362 D08363 D08364 D08365 \
#             D08366)
# @ ndays = 31

# December for a regular year (2009)
# set days = (D09335 D09336 D09337 D09338 D09339 D09340 \
#             D09341 D09342 D09343 D09344 D09345 D09346 \
#             D09347 D09348 D09349 D09350 D09351 D09352 \
#             D09353 D09354 D09355 D09356 D09357 D09358 \
#             D09359 D09360 D09361 D09362 D09363 D09364 \
#             D09365)
# @ ndays = 31

  echo $days
  echo $ndays

#---------------------------------------------------------------

  cd $EXE_DIR

#---------------------------------------------------------------

# Loop through desired days.

#---------------------------------------------------------------

  @ j = 1

  while ($j <= $ndays)

#   Create list of input files for current day.

    set k = $days[$j]

#   set num_CTP_files = `ls -1 ${HIRS_CTP_DIR}/*NM.${k}* | wc -l`
#   set num_CTP_files = `ls -1 ${HIRS_CTP_DIR}/*M2.${k}* | wc -l`
#   set num_CTP_files = `ls -1 ${HIRS_CTP_DIR}/*NK.${k}* | wc -l`
    set num_CTP_files = `ls -1 ${HIRS_CTP_DIR}/*NN.${k}* | wc -l`
    echo Number of files to be processed for day ${k}: ${num_CTP_files}

#   ls -1 ${HIRS_CTP_DIR}/*NM.${k}* > CTP_file_list
#   ls -1 ${HIRS_CTP_DIR}/*M2.${k}* > CTP_file_list
#   ls -1 ${HIRS_CTP_DIR}/*NK.${k}* > CTP_file_list
    ls -1 ${HIRS_CTP_DIR}/*NN.${k}* > CTP_file_list
    echo HIRS input CTP files for day ${k}:
#   ls -1 ${HIRS_CTP_DIR}/*NM.${k}*
#   ls -1 ${HIRS_CTP_DIR}/*M2.${k}*
#   ls -1 ${HIRS_CTP_DIR}/*NK.${k}*
    ls -1 ${HIRS_CTP_DIR}/*NN.${k}*
    echo


#---------------------------------------------------------------

#   Construct CTP daily global output file names.
    set out_id = ${k}
    set ctp_file = ${HIRS_CTP_DAILY_MEAN_DIR}/HIRS_daily_NN_${out_id}_v5.3.bin

#---------------------------------------------------------------

#   HIRS processing command line.

#   ./create_daily_global_data.exe

#        HIRS CTP input list file
#        HIRS CTP daily global mean output file

#   Echo command (version 4.3 and later).
#   echo ./create_daily_glb_data.exe CTP_file_list \
#        $ctp_file

#   ./create_daily_cloud_data.exe CTP_file_list \
#         $ctp_file

#   For land vs. water UTLS stats.
    ./create_daily_cloud_data.exe CTP_file_list \
          $ctp_file


    echo

#---------------------------------------------------------------

    @ j += 1
  
  end
#---------------------------------------------------------------

  rm CTP_file_list

  cd .

  exit 0
