#!/bin/bash # # Acquire a set of meteorological forcing data from the North American # Regional Reanalysis (NARR) NCEP NOMADS OPeNDAP server for forcing ROMS # # John Wilkin (jwilkin@rutgers.edu) December 2007 # with help from Rich Signell (rsignell@usgs.gov) # # This script is step 1 of 2: # # In step 1: # Acquire the forcing data in individual files for each day for a user # defined spatial subset from the NCEP NOMADS OPeNDAP server and prepare # them for concatenation # # ------------------------------------------------------------------------- # # North American Regional Reanalysis data on NOMADS server # These data cover the entire continent at 3-houlry intervals # The archive goes back to 1979. # The 'a' file has everything ROMS needs for BULK_FLUXES # The 'b' file has additional derived products. # # Here we load a sequence of daily analysis fields (cycle=_0000_000). # There are monthly composite data in a higher level directory, but those # files always have 248 (31*8) records no matter how many days there are # in a month and working with them is cumbersome because we would need to # clip the missing data at the end on months with days < 31. It's easier # to scan each month archive which only has files for valid days of that month. # # For NOMADS NARR # Specify the data url: server=http://nomads.ncdc.noaa.gov:9091/dods/NCEP_NARR_DAILY file=narr-a_221_ cycle=_0000_000 # There are higher spatial resolution data available from the North American # Mesoscale (NAM) model: # NAM ANALYSIS back to early 2004 is available at 6-hour intervals. # NAM FORECAST cycles at 1-hour and 3-hour intervals are also available. # These need slightly different handling of the url and time_constraints and # precipitation, which is a dignostic field. # See scripts similar to this one: step1_get_nam... # ---------------------------------------------------------------------- # ---------------------------------------------------------------------- # ---------------------------------------------------------------------- # # Options the user needs to set ---------------------------------------- # These might be better passed in at the command line, but those # niceties can come later # # year, month, and day strings will be used to build input url # # The year string is passed in from the command line # See below where the month and day strings are specified in for loops echo Starting script $0 if [ -n "$1" ] then yyyy=$1 echo for year $yyyy else echo Error in $0 No year to process requested echo Usage is, e.g.: echo step1_narr_get_data_from_nomads 2008 exit fi # In principle, if we had built the nco tools with udunits support we # could enter the spatial subset constraints in terms of dimension units: # # lon_constraint="\"-81.25 degrees_east\",\"-66.25 degrees_east\"" # lat_constraint="\"33 degrees_north\",\"43.5 degrees_north\"" # # ... but we haven't built nco like that, so these index limits are # determined by the user by loading the lon/lat vectors and interactively # choosing the desired limits # For NARR there is no time_constraint because these are reanalysis # data and there are no overlapping time recrods in the archive. # For MABGOM/ESPreSSO domain (1-based index because we use ncks -F) lon_constraint=369,428 # 82 W to 60 W lat_constraint=83,127 # 31 N to 47 N # For NENA domain (real numbers force lon/lat values) lon_constraint=-92.0,-49.0 lat_constraint=18.0,51.0 # For Delaware (real numbers force lon/lat values) lon_constraint=-76.0,-73.5 lat_constraint=37.5,40.25 # destination directory for daily files workdir=./frc_narr_$yyyy # ---------------------------------------------------------------------- # ---------------------------------------------------------------------- # ---------------------------------------------------------------------- for mm in 01 02 03 04 05 06 07 08 09 10 11 12 ; do # I test this script with an abbreviated month list #for mm in 02 ; do for dd in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; do # I test this script with an abbreviated day list # for dd in 27 28 29 30 ; do # build url for each day of NARR data url=$server/$yyyy$mm/$yyyy$mm$dd/$file$yyyy$mm$dd$cycle echo echo ______ $yyyy $mm $dd _____________________________________ # send global metadata to stdout ncks -M $url # trap event that the url does not exist (because this day of # month does not exist or archive runs out of data) if [ $? -gt 0 ]; then echo echo __________ URL not found. Probably a non existent date - keep going echo __________ $url echo continue fi # loop through variables required for varname in ugrd10m vgrd10m tmp2m rh2m pressfc dlwrfsfc dswrfsfc ulwrfsfc uswrfsfc apcp ; do echo echo __________ $varname echo # build output file name local_file=$workdir/$varname$yyyy$mm$dd.nc # extract regional subset for each variable and keep in separate # file (to be concatenated later) ncks -F \ --dimension lon,$lon_constraint \ --dimension lat,$lat_constraint \ --variable $varname \ --overwrite $url $local_file # NOTE: the metadata for min,max values of lon,lat are not # updated in this ncks extraction step # document the original NCEP variable name and the source ncatted --history -a NCEP_variable,$varname,c,c,$varname $local_file # The next three operations convert time to an unlimited dimension so that # the files can be combined later with ncrcat # create an unlimited record dimension ncecat --history --overwrite $local_file $local_file # switch time and the record dimension ncpdq -a time,record --history --overwrite $local_file $local_file # average to remove the spurious singleton dimension record ncwa -a record --history --overwrite $local_file $local_file done # close varname loop done # close dd loop done # close mm loop