├── 2017-04-19-your-filename.md ├── env └── csv2little_r.env.tmpl ├── configure ├── README └── src ├── csv2little_r.sh └── csv2little_r.f.tmpl /2017-04-19-your-filename.md: -------------------------------------------------------------------------------- 1 | ## A New Post 2 | 3 | Enter text in [Markdown](http://daringfireball.net/projects/markdown/). Use the toolbar above, or click the **?** button for formatting help. 4 | primo post 5 | -------------------------------------------------------------------------------- /env/csv2little_r.env.tmpl: -------------------------------------------------------------------------------- 1 | ########################################################################### 2 | # 3 | # LaMMA - Valerio Capecchi 4 | # 5 | # Author : Valerio Capecchi 6 | # Date : 2015-03-17 7 | # UpDate : 8 | # Purpose : Parameters settings for csv2little_r 9 | # 10 | ########################################################################### 11 | 12 | ## Global Variables 13 | # Local parameters 14 | ROOTDIR='ROOTTOBEDET' 15 | SRCDIR=$ROOTDIR'/src' 16 | LOGDIR=$ROOTDIR'/log' 17 | DATDIR=$ROOTDIR'/data' 18 | WRKDIR=$ROOTDIR'/wrkg' 19 | fout='LITTLE_R.output' 20 | 21 | ## Fortran options 22 | FC=gfortran 23 | 24 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | arg=$1 4 | 5 | # check input argument 6 | if test -z "$1" ; then 7 | echo "usage: ./$0 path/to/where/you/want/working/directory" 8 | exit 1; 9 | fi 10 | 11 | # check os 12 | os=`uname` 13 | if [ "$os" != "Linux" ]; then 14 | echo "opss this is not designed for not-Linux machines. Bye"; 15 | exit 1; 16 | fi 17 | 18 | # check Fortran compiler 19 | fc_comp=`cat env/csv2little_r.env.tmpl | grep FC | cut -d'=' -f2` 20 | resp=`which $fc_comp` 21 | if [ $? = 0 ]; then 22 | echo "fortran compiler is $fc_comp" 23 | else 24 | echo "opss cannot find fortran compiler $fc_comp"; exit; 25 | fi 26 | 27 | # check installing directory 28 | echo 'Installing directory is '$arg'. Okay to proceed? [y/n]' 29 | read resp 30 | if [ "$resp" != "y" ]; then 31 | echo "exit"; exit 1; 32 | elif [ ! -d "$arg" ]; then 33 | echo "$arg is missing. Do you want to create it? [y/n]" 34 | read resp 35 | if [ "$resp" = "y" ]; then 36 | mkdir -p $arg 37 | fi 38 | fi 39 | 40 | # installing stuff 41 | echo "Installing stuff in $arg/" 42 | CP=`which cp` 43 | if [ $? = 0 ]; then 44 | $CP -r src $arg/ 45 | else 46 | echo "opss cannota find cp command"; exit; 47 | fi 48 | MKDIR=`which mkdir` 49 | if [ $? = 0 ]; then 50 | ${MKDIR} -p $arg/data 51 | ${MKDIR} -p $arg/wrkg 52 | ${MKDIR} -p $arg/log 53 | ${MKDIR} -p $arg/env 54 | else 55 | echo "opss cannota find mkdir command"; exit; 56 | fi 57 | CAT=`which cat` 58 | [ $? = 0 ] || exit 1; 59 | SED=`which sed` 60 | [ $? = 0 ] || exit 1; 61 | ${CAT} env/csv2little_r.env.tmpl | ${SED} -e "s!ROOTTOBEDET!${arg}!g" > $arg/env/test.env 62 | 63 | echo "" 64 | echo "done!" 65 | echo "first of all edit $arg/env/test.env!" 66 | echo "then run sh $arg/src/csv2little_r.sh INPUTFILE VARIABLE" 67 | echo "and cross fingers" 68 | echo "enjoy!" 69 | 70 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # csv2little_r 2 | 3 | DESCRIPTION: 4 | This procedure is designed to convert csv data file format into LITTLE_R 5 | that WRFDA will ingest (http://www2.mmm.ucar.edu/wrf/users/wrfda/). 6 | From WRFDA Tutorial: 7 | 'LITTLE_R is an ASCII-based observation file format, in use since the MM5 era. 8 | Because raw observation data files have many possible formats (such as ASCII, 9 | BUFR, PREPBUFR, MADIS, and HDF) LITTLE_R is designed to be an intermediate 10 | format so that WRFDA might be able to assimilate as many observation types as 11 | possible in a universal manner. It is a report-based file format, so all 12 | manner of observation types can easily be "cat-ted" together into an 13 | easy-to-read and -edit text file.' 14 | Input file is supposed to be like this: 15 | Chieti;14.181;42.377;20111025_0630;139 16 | Teramo;13.711;42.656;20111025_0530;207 17 | L_Aquila;13.432;42.339;20111025_0530;180 18 | i.e. 19 | NAME;LON;LAT;YYYYMMDD_hhmm;VARIABLE_VALUE 20 | where variable can be one of the following: 21 | WIND SPEED (SPD) 22 | WIND DIRECTION (DIR) 23 | TEMPERATURE (TMP) 24 | PRESSURE (BAR) 25 | RELATIVE HUMIDITY (IGR) 26 | ZONAL WIND (UWND) 27 | MERIDIONAL WIND (VWND) 28 | THICKNESS (THICK) 29 | where 30 | pressure is in hPa 31 | temperature is in K 32 | wind speed is in m/s 33 | wind direction is in degrees 34 | relative humidity is in % 35 | zonal and meridional wind are in m/s (actually they were not tested) 36 | thickness is in m (actually it was not tested) 37 | 38 | SYSTEM REQUIREMENTS: 39 | * Linux system 40 | * /bin/bash 41 | * a Fortran compiler (gfortran worked for me..no other compilers were tested..) 42 | 43 | INSTALL: 44 | * tar/unzip the source code 45 | * cd csv2little_r 46 | * you have the following dir/files: 47 | - configure: - checks for system features and copies files and directories to the working directoy 48 | - env: contains configuration parameters for the procedure 49 | - src: contains a Bash procedure and the fortran 50 | * run ./configure /path/to/where/you/want/working/directory 51 | 52 | RUN: 53 | * cd env 54 | * edit the 'test.env' file according to your needs (if any). The file has minimal comments, if your are in doubts write me at valcap74@gmail.com 55 | * cd ../srs 56 | * sh csv2little_r.sh INPUTFILE_with_PATH SPD|DIR|TMP|BAR|IGR|UWND|VWND|THICK 57 | example: 58 | sh csv2little_r.sh ../data/sample.file.wind WND 59 | 60 | TODO: 61 | this is a very first attempt so a lot of stuff to improve the procedure is needed. 62 | Nevertheless the procedure works in most cases. 63 | Feel free to contribute 64 | 65 | MAINTAINER(S): 66 | valcap valcap74@gmail.com 67 | 68 | -------------------------------------------------------------------------------- /src/csv2little_r.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ############################################################# 4 | # 5 | # Author : Valerio Capecchi 6 | # Date : 2013-05-13 7 | # UpDate : 2015-03-17 8 | # Purpose : Convert csv files (comma separated value) into 9 | # lttle_r format observation data files 10 | # 11 | ############################################################# 12 | 13 | # Argument(s) 14 | if [ $# -ne 2 ] ; then 15 | echo "Usage: sh ./$0 csv_file variable SPD|DIR|TMP|BAR|IGR|UWND|VWND|THICK" 16 | echo "Example: sh ./$0 ../data/infile.csv TMP" 17 | echo "" 18 | exit 1 19 | fi 20 | 21 | # Functions 22 | function notice { 23 | echo "+++"`date +%Y-%b-%d_%H:%M:%S`"+++ "$@ 24 | } 25 | 26 | # Log file 27 | if [ ! -d "../log" ]; then 28 | logfile=`basename $0 .sh`_`date +"%Y%m%d"`.log 29 | else 30 | logfile=../log/`basename $0 .sh`_`date +"%Y%m%d"`.log 31 | fi 32 | exec 1>>../log/`basename $0 .sh`_`date +"%Y%m%d"`.log 33 | exec 2>&1 34 | 35 | # Check input file (input file exists and is not zero size) 36 | datfile=$1 37 | if [ ! -e "$datfile" ] || [ ! -s "$datfile" ]; then 38 | notice "input file is missing or is zero size..." 39 | notice "Exiting..." 40 | exit 1; 41 | fi 42 | 43 | # Check input variables 44 | var=$2 45 | if [ $var != 'SPD' ] && [ $var != 'DIR' ] && [ $var != 'TMP' ] && [ $var != 'BAR' ] && [ $var != 'IGR' ] && [ $var != 'UWND' ] && [ $var != 'VWND' ] && [ $var != 'THICK' ]; then 46 | notice "input variable must be one of SPD|DIR|TMP|BAR|IGR|UWND|VWND|THICK" 47 | notice "whereas input variable is $var" 48 | notice "Exiting..." 49 | exit 1; 50 | fi 51 | 52 | # Check env file 53 | envfile='../env/test.env' 54 | if [ -f "$envfile" ]; then 55 | source $envfile 56 | else 57 | notice "env file $envfile is missing..." 58 | notice "Exiting..." 59 | exit 1; 60 | fi 61 | 62 | # Check .f file 63 | forfile=$SRCDIR'/csv2little_r.f.tmpl' 64 | if [ ! -e $forfile ]; then 65 | notice "opss $forfile is missing"; 66 | notice "Exiting..." 67 | exit 1; 68 | fi 69 | 70 | # Change directory and clean stuff 71 | rm -f $WRKDIR/infile.csv $WRKDIR/csv2little_r.f $WRKDIR/pippo.exe 72 | rm -f $WRKDIR/${fout} 73 | cd $WRKDIR 74 | cp $datfile $WRKDIR/infile.csv 75 | 76 | ###################################################################################### 77 | # Main loop over variables: wind speed, wind direction, relative humidity and pressure 78 | ###################################################################################### 79 | for row in `cat $WRKDIR/infile.csv` 80 | do 81 | # It supposes the input file like this 82 | # NAME_OF_STATION;LONGITUDE;LATITUDE;YYYYMMDD_hhmm;VALUE 83 | namP=`echo $row | cut -d';' -f1` 84 | lonP=`echo $row | cut -d';' -f2` 85 | latP=`echo $row | cut -d';' -f3` 86 | strP=$namP' '$lonP' '$latP' ' 87 | if [ ${#strP} -gt 40 ]; then 88 | TMPL_STR=`echo $strP | cut -c1-40` 89 | else 90 | TMPL_STR=$strP 91 | while [ ${#TMPL_STR} -lt 40 ] 92 | do 93 | TMPL_STR=$TMPL_STR'x' 94 | done 95 | fi 96 | if [ ${#TMPL_STR} -ne 40 ]; then 97 | echo "boh...something went wrong"; exit 1; 98 | fi 99 | dateP=`echo $row | cut -d';' -f4` 100 | yyyyP=`echo $dateP | cut -c1-4` 101 | yyP=`echo $dateP | cut -c3-4` 102 | mmP=`echo $dateP | cut -c5-6` 103 | ddP=`echo $dateP | cut -c7-8` 104 | hhP=`echo $dateP | cut -c10-11` 105 | nnP=`echo $dateP | cut -c12-13` 106 | mdateP=$yyP$mmP$ddP$hhP 107 | case $var in 108 | BAR) 109 | VAL_P=`echo $row | cut -d';' -f5` 110 | if [[ -z "$VAL_P" || "$VAL_P" =~ "," ]]; then 111 | VAL_P='-888888.' 112 | fi 113 | VAL_DIR='-888888.' 114 | VAL_SPD='-888888.' 115 | VAL_RH='-888888.' 116 | VAL_TMP='-888888.' 117 | VAL_U='-888888.' 118 | VAL_V='-888888.' 119 | VAL_THICK='-888888.' 120 | ;; 121 | DIR) 122 | VAL_P='-888888.' 123 | VAL_DIR=`echo $row | cut -d';' -f5` 124 | if [[ -z "$VAL_DIR" || "$VAL_DIR" =~ "," ]]; then 125 | VAL_DIR='-888888.' 126 | fi 127 | VAL_SPD='-888888.' 128 | VAL_RH='-888888.' 129 | VAL_TMP='-888888.' 130 | VAL_U='-888888.' 131 | VAL_V='-888888.' 132 | VAL_THICK='-888888.' 133 | ;; 134 | SPD) 135 | VAL_P='-888888.' 136 | VAL_DIR='-888888.' 137 | VAL_SPD=`echo $row | cut -d';' -f5` 138 | if [[ -z "$VAL_SPD" || "$VAL_SPD" =~ "," ]]; then 139 | VAL_SPD='-888888.' 140 | fi 141 | VAL_RH='-888888.' 142 | VAL_TMP='-888888.' 143 | VAL_U='-888888.' 144 | VAL_V='-888888.' 145 | VAL_THICK='-888888.' 146 | ;; 147 | IGR) 148 | VAL_P='-888888.' 149 | VAL_DIR='-888888.' 150 | VAL_SPD='-888888.' 151 | VAL_RH=`echo $row | cut -d';' -f5` 152 | if [[ -z "$VAL_RH" || "$VAL_RH" =~ "," ]]; then 153 | VAL_RH='-888888.' 154 | fi 155 | VAL_TMP='-888888.' 156 | VAL_U='-888888.' 157 | VAL_V='-888888.' 158 | VAL_THICK='-888888.' 159 | ;; 160 | TMP) 161 | VAL_P='-888888.' 162 | VAL_DIR='-888888.' 163 | VAL_SPD='-888888.' 164 | VAL_RH='-888888.' 165 | VAL_TMP=`echo $row | cut -d';' -f5` 166 | if [[ -z "$VAL_TMP" || "$VAL_TMP" =~ "," ]]; then 167 | VAL_TMP='-888888.' 168 | fi 169 | VAL_U='-888888.' 170 | VAL_V='-888888.' 171 | VAL_THICK='-888888.' 172 | ;; 173 | THICK) 174 | VAL_P='-888888.' 175 | VAL_DIR='-888888.' 176 | VAL_SPD='-888888.' 177 | VAL_RH='-888888.' 178 | VAL_TMP='-888888.' 179 | VAL_THICK=`echo $row | cut -d';' -f5` 180 | if [[ -z "$VAL_THICK" || "$VAL_THICK" =~ "," ]]; then 181 | VAL_THICK='-888888.' 182 | fi 183 | VAL_U='-888888.' 184 | VAL_V='-888888.' 185 | ;; 186 | VWND) 187 | VAL_P='-888888.' 188 | VAL_DIR='-888888.' 189 | VAL_SPD='-888888.' 190 | VAL_RH='-888888.' 191 | VAL_TMP='-888888.' 192 | VAL_V=`echo $row | cut -d';' -f5` 193 | if [[ -z "$VAL_V" || "$VAL_V" =~ "," ]]; then 194 | VAL_V='-888888.' 195 | fi 196 | VAL_U='-888888.' 197 | VAL_THICK='-888888.' 198 | ;; 199 | UWND) 200 | VAL_P='-888888.' 201 | VAL_DIR='-888888.' 202 | VAL_SPD='-888888.' 203 | VAL_RH='-888888.' 204 | VAL_TMP='-888888.' 205 | VAL_U=`echo $row | cut -d';' -f5` 206 | if [[ -z "$VAL_U" || "$VAL_U" =~ "," ]]; then 207 | VAL_U='-888888.' 208 | fi 209 | VAL_V='-888888.' 210 | VAL_THICK='-888888.' 211 | ;; 212 | *) 213 | echo "boh...something went wrong with input parameters"; exit 1; 214 | esac 215 | seq_num=1 216 | 217 | # Terrain variable....stuff to fix here 218 | terP='-888888.' 219 | 220 | # 221 | ## Validate Fortran program 222 | cat $forfile \ 223 | | sed -e "s/VAL_K/1/g" \ 224 | | sed -e "s/TMPL_STR/$TMPL_STR/g" \ 225 | | sed -e "s/TMPL_NAM/$namP/g" \ 226 | | sed -e "s/TMPL_LON/$lonP/g" \ 227 | | sed -e "s/TMPL_LAT/$latP/g" \ 228 | | sed -e "s/VAL_TER/$terP/g" \ 229 | | sed -e "s/VAL_Z/$terP/g" \ 230 | | sed -e "s/VAL_MDATE_MINS/$nnP/g" \ 231 | | sed -e "s/VAL_MDATE/$mdateP/g" \ 232 | | sed -e "s/VAL_TMP/$VAL_TMP/g" \ 233 | | sed -e "s/VAL_SPD/$VAL_SPD/g" \ 234 | | sed -e "s/VAL_DIR/$VAL_DIR/g" \ 235 | | sed -e "s/VAL_P/$VAL_P/g" \ 236 | | sed -e "s/VAL_TD/$VAL_TD/g" \ 237 | | sed -e "s/VAL_U/$VAL_U/g" \ 238 | | sed -e "s/VAL_V/$VAL_V/g" \ 239 | | sed -e "s/VAL_RH/$VAL_RH/g" \ 240 | | sed -e "s/VAL_THICK/$VAL_THICK/g" \ 241 | > $WRKDIR/csv2little_r.f 242 | 243 | # 244 | ## Compile Fortran program 245 | $FC $WRKDIR/csv2little_r.f -o $WRKDIR/pippo.exe 246 | if [ ! -e $WRKDIR/pippo.exe ]; then 247 | echo "opss cannot compile $WRKDIR/csv2little_r.f"; 248 | rm -f $WRKDIR/pippo.exe; 249 | exit 1; 250 | fi 251 | 252 | # 253 | ## Run Fortran program 254 | $WRKDIR/pippo.exe 255 | if [ ! -e $WRKDIR/fort.2 ]; then 256 | echo "$WRKDIR/fort.2 is missing"; 257 | echo "fortran program failed for some reasons"; 258 | exit 1; 259 | else 260 | cat $WRKDIR/fort.2 >> $WRKDIR/$fout 261 | rm -f $WRKDIR/pippo.exe $WRKDIR/fort.2; 262 | fi 263 | done 264 | 265 | # Check output file 266 | if [ ! -e $WRKDIR/$fout ]; then 267 | echo "boh something went wrong"; exit 1; 268 | fi 269 | 270 | ## Ciao 271 | rm -f $WRKDIR/infile.csv $WRKDIR/csv2little_r.f $WRKDIR/pippo.exe $WRKDIR/fort.2 272 | exit 0; 273 | 274 | -------------------------------------------------------------------------------- /src/csv2little_r.f.tmpl: -------------------------------------------------------------------------------- 1 | program singleobs2little_r 2 | 3 | ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 4 | c 5 | c Author : Valerio Capecchi 6 | c Date : 2013-05-13 7 | c UpDate : 2015-03-17 8 | c Purpose : Convert csv files (comma separated value) into 9 | c lttle_r format observation data files 10 | c Comments: Modified from the original NCAR code upa.f available at 11 | c ftp://ftp.ucar.edu/mesouser/MM5V3/V3-7-0/LITTLE_R.TAR.gz 12 | c or 13 | c http://www2.mmm.ucar.edu/mm5/On-Line-Tutorial/little_r/extras/upa.f 14 | c 15 | ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 16 | 17 | c ... this is a little testing routine that is supposed to generate a 18 | c single sounding that the objective analysis program will ingest 19 | 20 | c ... pressure is in Pa, height in m, temperature and dew point are in 21 | c K, speed is in m/s, and direction is in degrees 22 | 23 | c ... sea level pressure is in Pa, terrain elevation is in m, latitude 24 | c is in degrees N, longitude is in degrees E 25 | 26 | c ... to put in a surface observation, make only a single level "sounding" 27 | c and make the value of the height equal the terrain elevation -- PRESTO! 28 | 29 | c ... the first 40 character string may be used for the description of 30 | c the station (i.e. name city country, etc) 31 | 32 | c ... the second character string we use for our source 33 | 34 | c ... the third string should be left alone, it uses the phrase "FM-35 TEMP" 35 | c for an upper air station, and should use "FM-12 SYNOP" for surface data 36 | 37 | c ... the fourth string is unused, feel free to experiment with labels! 38 | 39 | c ... bogus data are not subject to quality control 40 | 41 | c ... There are 3 records for each observation site: 42 | c 1. a header that contains information about station identifier, 43 | c station location, data information, station elevation 44 | c and whether the report is a bogus or not, etc; 45 | c 2. a report (whether it is a sounding containing many levels, or only a surface report) 46 | c 3. an end-of-message line. 47 | 48 | c ... For a surface observation, the geopotential height (z(k)) 49 | c must be set equal to the terrain elevation (ter) field. 50 | c This is the definition of a surface observation. 51 | 52 | parameter (kx=VAL_K) 53 | parameter (gravity=9.8066) 54 | parameter (Fmolarmass=0.028964) 55 | parameter (universalR=8.3143) 56 | parameter (standardT=288.15) 57 | dimension p(kx), z(kx), t(kx), td(kx), spd(kx), dir(kx) 58 | dimension u(kx), v(kx), rh(kx), thick(kx), es(kx) 59 | logical bogus 60 | logical is_sounding 61 | logical discard 62 | 63 | data t / VAL_TMP/ 64 | data spd/ VAL_SPD/ 65 | data dir/ VAL_DIR/ 66 | data p / VAL_P/ 67 | data u / VAL_U/ 68 | data v / VAL_V/ 69 | data rh / VAL_RH/ 70 | data thick / VAL_THICK/ 71 | 72 | c ... The following two parameters need to be the same (see the previous note above)) 73 | data ter/VAL_TER/ 74 | data z /VAL_Z/ 75 | c ... User-defined...mdate should be in the form 11102506 76 | data xlat/TMPL_LAT/ 77 | data xlon/TMPL_LON/ 78 | data mdate /VAL_MDATE/ 79 | c ... bogus data are not subject to quality control 80 | data bogus /.false./ 81 | data is_sounding /.false./ 82 | data discard /.false./ 83 | c ... iseq_num Sequence number of this observation 84 | iseq_num=0 85 | 86 | do 100 k=1,kx 87 | if ( dir(k) < 0. .OR. dir(k) > 360. ) then 88 | dir(k)=-888888. 89 | end if 90 | if ( p(k) > 600. ) then 91 | p(k)=p(k)*100. 92 | else 93 | p(k)=-888888. 94 | end if 95 | c ... The following parameter can be derived from the above ones 96 | if ( t(k) > -60. .AND. rh(k) .ge. 0.0 .AND. rh(k) .le. 100. ) 97 | & then 98 | c ... http://www.srh.noaa.gov/images/epz/wxcalc/wetBulbTdFromRh.pdf (Calcolo di T dewpoint) 99 | c ... http://www.srh.noaa.gov/images/epz/wxcalc/vaporPressure.pdf (Calcolo pressione di vapor saturo, ES) 100 | es(k)=6.11*10**((7.5*t(k))/(237.3+t(k))) 101 | td(k)=(237.3*log(es(k)*rh(k)/611))/ 102 | & (7.5*log(10.0)-log(es(k)*rh(k)/611)) 103 | c ... http://andrew.rsmas.miami.edu/bmcnoldy/Humidity.html 104 | c ... Alduchov, O. A., and R. E. Eskridge, 1996: 105 | c ... Improved Magnus' form approximation of saturation vapor pressure. 106 | c ... J. Appl. Meteor., 35, 601–609. 107 | c td(k)=243.04*(log(rh(k)/100)+((17.625*t(k))/(243.04+t(k))))/ 108 | c & (17.625-log(rh(k)/100)-((17.625*t(k))/(243.04+t(k)))) 109 | if ( td(k) > -60. ) then 110 | td(k)=td(k)+273.15 111 | else 112 | td(k)=-888888. 113 | end if 114 | else 115 | td(k)=-888888. 116 | end if 117 | if ( t(k) > -60. ) then 118 | t(k)=t(k)+273.15 119 | else 120 | t(k)=-888888. 121 | end if 122 | 100 continue 123 | 124 | c ... The following parameter can be derived from the above ones 125 | if ( p(1)> 600. ) then 126 | slp=p(1)/exp(-(gravity*Fmolarmass*ter)/(universalR*standardT)) 127 | else 128 | slp=-888888. 129 | end if 130 | 131 | c ... Echo some values 132 | c write (*,*) gravity,Fmolarmass,ter,universalR,standardT 133 | c write (*,*) 'TMPL_STR' 134 | c write (*,*) 'pressure -->',p(1) 135 | c write (*,*) 'terrain elevation-->',ter 136 | c write (*,*) 'slp -->',slp 137 | c write (*,*) 'z -->',z 138 | c write (*,*) 't -->',t 139 | c write (*,*) 'spd -->',spd(1) 140 | c write (*,*) 'dir -->',dir(1) 141 | c write (*,*) 'td -->',td(1) 142 | c write (*,*) 'rh -->',rh(1) 143 | c write (*,*) 'u -->',u(1) 144 | c write (*,*) 'v -->',v(1) 145 | c write (*,*) 'thick -->',thick(1) 146 | c write (*,*) ' -->', 147 | 148 | c ... this forces the single surface observation writing 149 | k=VAL_K 150 | 151 | if ( k .eq. 1 ) then 152 | call write_obs (p,z,t,td,spd,dir, 153 | & slp, ter, xlat, xlon, mdate, kx, 154 | & 'TMPL_STR', 155 | & 'SURFACE DATA FROM MY DATABASExxxxxxxxxxx', 156 | & 'FM-12 SYNOPxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 157 | & 'I did itxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 158 | & bogus , iseq_num , 2 ) 159 | else 160 | call write_obs (p,z,t,td,spd,dir, 161 | & slp, ter, xlat, xlon, mdate, kx, 162 | & '99001 Maybe more site info ', 163 | & 'SOUNDINGS FROM ????????? SOURCE ', 164 | & 'FM-35 TEMP ', 165 | & ' ', 166 | & bogus , iseq_num , 2 ) 167 | endif 168 | 169 | stop 99999 170 | end 171 | 172 | c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 173 | c ... Subroutines below here 174 | c cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 175 | 176 | SUBROUTINE write_obs ( p , z , t , td , spd , dir , 177 | & slp , ter , xlat , xlon , mdate , kx , 178 | & string1 , string2 , string3 , string4 , bogus , iseq_num , 179 | & iunit ) 180 | 181 | dimension p(kx), z(kx), t(kx), td(kx), spd(kx),dir(kx) 182 | 183 | character *20 date_char 184 | character *40 string1, string2 , string3 , string4 185 | CHARACTER *84 ini_format 186 | CHARACTER *22 mid_format 187 | CHARACTER *14 end_format 188 | logical bogus 189 | logical is_sounding 190 | logical discard 191 | data is_sounding /.false./ 192 | data discard /.false./ 193 | 194 | c ... Define writing formats 195 | 196 | c ini_format writes an header: 197 | ccc two integers --> 2f20.5 198 | ccc station latitude (north positive) 199 | ccc station longitude (east positive) 200 | ccc string1, string2, string3, string4 --> 2a40 & 2a40 201 | ccc string1 ID of station 202 | ccc string2 Name of station 203 | ccc string3 Description of the measurement device 204 | ccc string4 GTS, NCAR/ADP, BOGUS, etc. 205 | ccc terrain elevation (m) --> 1f20.5 206 | ccc five integers: kx*6, 0, 0, iseq_num, 0 --> 5i10 207 | ccc Number of valid fields in the report 208 | ccc Number of errors encountered during the decoding of this observation 209 | ccc Number of warnings encountered during decoding of this observation 210 | ccc Sequence number of this observation 211 | ccc Number of duplicates found for this observation 212 | ccc three logicals: is_sounding, bogus, .false. --> 3L10 213 | ccc Multiple levels or a single level 214 | ccc bogus report or normal one 215 | ccc Duplicate and discarded (or merged) report 216 | ccc two integers --> 2i10 217 | ccc Seconds since 0000 UTC 1 January 1970 218 | ccc Day of the year 219 | ccc date of observation as character --> a20 220 | ccc YYYYMMDDHHmmss 221 | ccc 13 couples of numbers --> 13(f13.5,i7) 222 | ccc 1. Sea-level pressure (Pa) and a QC flag 223 | ccc 2. Reference pressure level (for thickness) (Pa) and a QC flag 224 | ccc 3. Ground Temperature (T) and QC flag 225 | ccc 4. Sea-Surface Temperature (K) and QC 226 | ccc 5. Surface pressure (Pa) and QC 227 | ccc 6. Precipitation Accumulation and QC 228 | ccc 7. Daily maximum T (K) and QC 229 | ccc 8. Daily minimum T (K) and QC 230 | ccc 9. Overnight minimum T (K) and QC 231 | ccc 10. 3-hour pressure change (Pa) and QC 232 | ccc 11. 24-hour pressure change (Pa) and QC 233 | ccc 12. Total cloud cover (oktas) and QC 234 | ccc 13. Height (m) of cloud base and QC 235 | ini_format = ' ( 2f20.5 , 2a40 , ' 236 | & // ' 2a40 , 1f20.5 , 5i10 , 3L10 , ' 237 | & // ' 2i10 , a20 , 13( f13.5 , i7 ) ) ' 238 | 239 | c mid_format writes the actual observations: 240 | ccc ten floating numbers and integers --> 10( f13.5 , i7 ) 241 | ccc 1. Pressure (Pa) of observation, and QC 242 | ccc 2. Height (m MSL) of observation, and QC 243 | ccc 3. Temperature (K) and QC 244 | ccc 4. Dewpoint (K) and QC 245 | ccc 5. Wind speed (m s-1 ) and QC 246 | ccc 6. Wind direction (degrees) and QC 247 | ccc 7. U component of wind (m s-1 ), and QC 248 | ccc 8. V component of wind (m s-1 ), and QC 249 | ccc 9. Relative Humidity (%) and QC 250 | ccc 10. Thickness (m), and QC 251 | mid_format = ' ( 10( f13.5 , i7 ) ) ' 252 | 253 | c end_format writes the tail of the little_r file 254 | ccc three integers --> 3 ( i7 ) 255 | ccc Number of valid fields in the report 256 | ccc Number of errors encountered during the decoding of the report 257 | ccc Number of warnings encountered during the decoding the report 258 | end_format = ' ( 3 ( i7 ) ) ' 259 | c ... End of writing formats 260 | 261 | c ... Init of date_char 262 | date_char(1:6)=' ' 263 | if (mdate/1000000 .GT. 70 ) then 264 | date_char(7:8)='19' 265 | else 266 | date_char(7:8)='20' 267 | endif 268 | write (date_char(9:16),fmt='(i8.8)') mdate 269 | c **************************************** 270 | c date_char(17:20)='0000' 271 | date_char(17:18)='VAL_MDATE_MINS' 272 | date_char(19:20)='00' 273 | c write (*,*) 'date_char -->',date_char 274 | c **************************************** 275 | c ... End of date_char 276 | 277 | c ... Write ini format (known as header-format) 278 | WRITE ( UNIT = iunit , ERR = 19 , FMT = ini_format ) 279 | & xlat, xlon, 280 | & string1, string2, string3, string4, 281 | & ter, 282 | c & kx, 0, 0, iseq_num, 0, 283 | & kx*6, 0, 0, 0, 0, 284 | & is_sounding, bogus, discard, 285 | & -888888, -888888, 286 | & date_char, 287 | & slp, 0, 288 | & -888888.,0,-888888.,0,-888888.,0,p(1),0, 289 | & -888888.,0,-888888.,0,-888888.,0,-888888.,0, 290 | & -888888.,0,-888888.,0,-888888.,0,-888888.,0 291 | 292 | c ... Write mid format (known as data-records) 293 | do 100 k = 1 , kx 294 | WRITE ( UNIT = iunit , ERR = 19 , FMT = mid_format ) 295 | & p(k), 0, z(k),0, t(k),0, td(k),0, 296 | & spd(k),0, dir(k),0, 297 | & -888888.,0, -888888.,0, 298 | & -888888.,0, -888888.,0 299 | 100 continue 300 | 301 | c ... Again write mid format (known as end-data-record) 302 | WRITE ( UNIT = iunit , ERR = 19 , FMT = mid_format ) 303 | & -777777.,0, -777777.,0, float(kx),0, 304 | & -888888.,0, -888888.,0, -888888.,0, 305 | & -888888.,0, -888888.,0, -888888.,0, 306 | & -888888.,0 307 | 308 | c ... Write end format 309 | WRITE ( UNIT = iunit , ERR = 19 , FMT = end_format ) kx, 0, 0 310 | 311 | return 312 | 19 continue 313 | print *,'troubles writing little_r observation' 314 | stop 19 315 | END 316 | 317 | --------------------------------------------------------------------------------