awk Script for DWAF national chemical water quality monitoring project

Handles conversion from wms2wmrq.pl output to comma-delimited ASCII for input by INFO into Arc/Info for use by WaterMarque and associated software.
BEGIN { FS="|"; OFS="," }
# awk script to convert flat ASCII file created by wms2wmrq.pl to file importable by INFO
# and usable by WaterMarque Arc/Info water quality mapping system.
# Michael Silberbauer IWQS DWAF 2001-03
{
  n=0;
  #for( L=2;L<=length($2);L++ )
  #{
    #if( substr($2,L,1) != " " ) n=L;
  #}
  L=0
  while( str!=" " )
    {
      L++
      str=substr($2,L,1)
    }

  stn=substr( $2,2,9 );
  if( substr( stn,1,1 ) == "Z" && substr( stn,9,1 ) != " " ) #check for embedded Z-code station code in description
  {
    station=stn
  }
  else
    { 
      for( k=1;k<=9;k++ ) {chk[k]=0}                        #check for embedded hydro station code in description
      k=1;var=substr( stn,k,1 ); if( var >= "A" && var <= "Z" ) {chk[k]=1}  #A
      k=2;var=substr( stn,k,1 ); if( var >=  0  && var <=  9  ) {chk[k]=1}  #2
      k=3;var=substr( stn,k,1 ); if( var >= "A" && var <= "Z" ) {chk[k]=1}  #H
      k=4;var=substr( stn,k,1 ); if( var >=  0  && var <=  9  ) {chk[k]=1}  #0
      k=5;var=substr( stn,k,1 ); if( var >=  0  && var <=  9  ) {chk[k]=1}  #2
      k=6;var=substr( stn,k,1 ); if( var >=  0  && var <=  9  ) {chk[k]=1}  #7
      k=7;var=substr( stn,k,1 ); if( var >= "A" && var <= "Z" ) {chk[k]=1}  #Q
      k=8;var=substr( stn,k,1 ); if( var >=  0  && var <=  9  ) {chk[k]=1}  #0
      k=9;var=substr( stn,k,1 ); if( var >=  0  && var <=  9  ) {chk[k]=1}  #1
      if( chk[1] && chk[2] && chk[3] && chk[4] && chk[5] && chk [6] && chk[7] && chk[8] &&chk[9] )
      {
        station=stn
      }
      else
        {
          station = $1*1
        }
    }
  cat = substr($3,2,1)
  if( cat == " " ) cat = "?"
  rec = station","cat","substr($4,2,10)","substr($5,2,2)substr($5,5,2)
  output_it = 0
  for( j=6;j<=25;j++ )
  {
    if( $j == " -9999" || $j == " -99999" ) x = -9
      else
      {
        x = 1 * $j
        output_it = 1
      }
    rec = rec"," x
  }
  depth = -9999
  if( $26 != " -9999" ) depth = 1 * $26
  preserve = 9
  if( $27 == " NONE" ) preserve = 0
  if( $27 == " NOT APPLICABLE" ) preserve = 0
  if( $27 == " UNKNOWN" ) preserve = 0
  if( $27 == " HGCL2" ) preserve = 1
  if( $27 == " H2SO4" ) preserve = 2
  if( $27 == " FILTER & HNO3" ) preserve = 3
  if( $27 == " HNO3" ) preserve = 3
  if( $27 == " COLD  <4°C" ) preserve = 4
  if( $27 == " COOL" ) preserve = 4
  if( $27 == " COOL/DARK/COOLB" ) preserve = 4
  if( $27 == " LUGOL/DARK" ) preserve = 5
  if( $27 == " FILTERED/PAPER" ) preserve = 6
  if( $27 == " FORMALIN" ) preserve = 7
  if( $27 == " ETHANOL/DARK" ) preserve = 8

  rec = rec","depth","preserve
  if( output_it ) print rec
}



[IWQS Home]