| 2516 | | open(CURRENT_IN_SITU_SQLFILE,'>>../sql/current_in_situ_prod_'.$institution_code_value.'_' |
|---|
| 2517 | | .$platform_code_value.'_'.$package_code_value.'.sql'); |
|---|
| 2518 | | print CURRENT_IN_SITU_SQLFILE "-- format_category = $format_category_value\n"; |
|---|
| 2519 | | print CURRENT_IN_SITU_SQLFILE "-- institution_code = $institution_code_value\n"; |
|---|
| 2520 | | print CURRENT_IN_SITU_SQLFILE "-- platform_code = $platform_code_value\n"; |
|---|
| 2521 | | print CURRENT_IN_SITU_SQLFILE "-- package_code = $package_code_value\n"; |
|---|
| 2522 | | print CURRENT_IN_SITU_SQLFILE "-- title = $title_value\n"; |
|---|
| 2523 | | print CURRENT_IN_SITU_SQLFILE "-- institution = $institution_value\n"; |
|---|
| 2524 | | print CURRENT_IN_SITU_SQLFILE "-- institution_url = $institution_url_value\n"; |
|---|
| 2525 | | print CURRENT_IN_SITU_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; |
|---|
| 2526 | | print CURRENT_IN_SITU_SQLFILE "-- source = $source_value\n"; |
|---|
| 2527 | | print CURRENT_IN_SITU_SQLFILE "-- references = $references_value\n"; |
|---|
| 2528 | | print CURRENT_IN_SITU_SQLFILE "-- contact = $contact_value\n"; |
|---|
| 2529 | | print CURRENT_IN_SITU_SQLFILE "-- missing_value = $missing_value_value\n"; |
|---|
| 2530 | | print CURRENT_IN_SITU_SQLFILE "-- _FillValue = $Fill_value_value\n"; |
|---|
| 2531 | | for my $i (0..$#sea_surface_eastward_current) { |
|---|
| 2532 | | my $j = 0; |
|---|
| 2533 | | while ($j <= $#sea_surface_northward_current |
|---|
| 2534 | | && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'}) { |
|---|
| 2535 | | $j++; |
|---|
| 2536 | | } |
|---|
| 2537 | | if ($j > $#sea_surface_northward_current) { |
|---|
| 2538 | | die "ABORT! Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i] {'var_name'}.\n"; |
|---|
| 2539 | | } |
|---|
| 2540 | | else { |
|---|
| 2541 | | for my $k (0..$#this_sea_surface_eastward_current_data) { |
|---|
| 2542 | | $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; |
|---|
| 2543 | | $this_time_stamp = $time_formatted_values[$k]; |
|---|
| 2544 | | $this_time_stamp_sec = timelocal(substr($this_time_stamp,17,2),substr($this_time_stamp,14,2),substr($this_time_stamp,11,2),substr($this_time_stamp,8,2),(substr($this_time_stamp,5,2)-1),substr($this_time_stamp,0,4)); |
|---|
| 2545 | | |
|---|
| 2546 | | #print "debug: $sea_surface_eastward_current[$i]{'data'}[$k]\n"; |
|---|
| 2547 | | if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value |
|---|
| 2548 | | && $sea_surface_eastward_current[$i]{'data'}[$k] != $Fill_value_value |
|---|
| 2549 | | && $sea_surface_northward_current[$j]{'data'}[$k] != $missing_value_value |
|---|
| 2550 | | && $sea_surface_northward_current[$j]{'data'}[$k] != $Fill_value_value |
|---|
| 2551 | | && $this_station_id_top_ts < $this_time_stamp_sec |
|---|
| 2552 | | && $this_time_stamp_sec > $oldest_ok_timestamp) { |
|---|
| 2553 | | print CURRENT_IN_SITU_SQLFILE "INSERT INTO current_in_situ_prod ("; |
|---|
| 2554 | | print CURRENT_IN_SITU_SQLFILE "station_id,"; |
|---|
| 2555 | | print CURRENT_IN_SITU_SQLFILE "time_stamp,"; |
|---|
| 2556 | | print CURRENT_IN_SITU_SQLFILE "z,"; |
|---|
| 2557 | | print CURRENT_IN_SITU_SQLFILE "positive,"; |
|---|
| 2558 | | print CURRENT_IN_SITU_SQLFILE "eastward_current,"; |
|---|
| 2559 | | print CURRENT_IN_SITU_SQLFILE "northward_current,"; |
|---|
| 2560 | | print CURRENT_IN_SITU_SQLFILE "surface_or_bottom,"; |
|---|
| 2561 | | print CURRENT_IN_SITU_SQLFILE "the_geom"; |
|---|
| 2562 | | print CURRENT_IN_SITU_SQLFILE ") "; |
|---|
| 2563 | | print CURRENT_IN_SITU_SQLFILE "VALUES ("; |
|---|
| 2564 | | print CURRENT_IN_SITU_SQLFILE '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; |
|---|
| 2565 | | print CURRENT_IN_SITU_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$k].'\''; |
|---|
| 2566 | | if ($sea_surface_eastward_current[$i]{'height'} == $missing_value_value |
|---|
| 2567 | | || $sea_surface_eastward_current[$i]{'height'} == $Fill_value_value) { |
|---|
| 2568 | | print CURRENT_IN_SITU_SQLFILE ','.'\'\''; |
|---|
| 2569 | | } |
|---|
| 2570 | | else { |
|---|
| 2571 | | $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'}); |
|---|
| 2572 | | print CURRENT_IN_SITU_SQLFILE ','.$this_val; |
|---|
| 2573 | | |
|---|
| 2574 | | } |
|---|
| 2575 | | print CURRENT_IN_SITU_SQLFILE ','.'\''.$height_var{'positive'}.'\''; |
|---|
| 2576 | | $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); |
|---|
| 2577 | | |
|---|
| 2578 | | print CURRENT_IN_SITU_SQLFILE ','.$this_val; |
|---|
| 2579 | | $this_val = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); |
|---|
| 2580 | | |
|---|
| 2581 | | print CURRENT_IN_SITU_SQLFILE ','.$this_val; |
|---|
| 2582 | | print CURRENT_IN_SITU_SQLFILE ','.'\'surface\''; |
|---|
| 2583 | | print CURRENT_IN_SITU_SQLFILE ",GeometryFromText('POINT("; |
|---|
| 2584 | | print CURRENT_IN_SITU_SQLFILE $longitude_value[0].' '.$latitude_value[0]; |
|---|
| 2585 | | print CURRENT_IN_SITU_SQLFILE ")',-1));\n"; |
|---|
| 2586 | | } |
|---|
| 2587 | | |
|---|
| | 2516 | if( $bWriteSQLFiles ) |
|---|
| | 2517 | { |
|---|
| | 2518 | open(CURRENT_IN_SITU_SQLFILE,'>>../sql/current_in_situ_prod_'.$institution_code_value.'_' |
|---|
| | 2519 | .$platform_code_value.'_'.$package_code_value.'.sql'); |
|---|
| | 2520 | print CURRENT_IN_SITU_SQLFILE "-- format_category = $format_category_value\n"; |
|---|
| | 2521 | print CURRENT_IN_SITU_SQLFILE "-- institution_code = $institution_code_value\n"; |
|---|
| | 2522 | print CURRENT_IN_SITU_SQLFILE "-- platform_code = $platform_code_value\n"; |
|---|
| | 2523 | print CURRENT_IN_SITU_SQLFILE "-- package_code = $package_code_value\n"; |
|---|
| | 2524 | print CURRENT_IN_SITU_SQLFILE "-- title = $title_value\n"; |
|---|
| | 2525 | print CURRENT_IN_SITU_SQLFILE "-- institution = $institution_value\n"; |
|---|
| | 2526 | print CURRENT_IN_SITU_SQLFILE "-- institution_url = $institution_url_value\n"; |
|---|
| | 2527 | print CURRENT_IN_SITU_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; |
|---|
| | 2528 | print CURRENT_IN_SITU_SQLFILE "-- source = $source_value\n"; |
|---|
| | 2529 | print CURRENT_IN_SITU_SQLFILE "-- references = $references_value\n"; |
|---|
| | 2530 | print CURRENT_IN_SITU_SQLFILE "-- contact = $contact_value\n"; |
|---|
| | 2531 | print CURRENT_IN_SITU_SQLFILE "-- missing_value = $missing_value_value\n"; |
|---|
| | 2532 | print CURRENT_IN_SITU_SQLFILE "-- _FillValue = $Fill_value_value\n"; |
|---|
| | 2533 | for my $i (0..$#sea_surface_eastward_current) { |
|---|
| | 2534 | my $j = 0; |
|---|
| | 2535 | while ($j <= $#sea_surface_northward_current |
|---|
| | 2536 | && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'}) { |
|---|
| | 2537 | $j++; |
|---|
| 2589 | | } |
|---|
| 2590 | | print CURRENT_IN_SITU_SQLFILE "\n"; |
|---|
| 2591 | | } |
|---|
| 2592 | | close(CURRENT_IN_SITU_SQLFILE); |
|---|
| 2593 | | } |
|---|
| 2594 | | #DWR 4/5/2008 |
|---|
| 2595 | | if( $bWriteobsKMLFile ) |
|---|
| 2596 | | { |
|---|
| 2597 | | for my $i (0..$#sea_surface_eastward_current) |
|---|
| 2598 | | { |
|---|
| 2599 | | my $j = 0; |
|---|
| 2600 | | while ($j <= $#sea_surface_northward_current |
|---|
| 2601 | | && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'}) |
|---|
| 2602 | | { |
|---|
| 2603 | | $j++; |
|---|
| 2604 | | } |
|---|
| 2605 | | if ($j > $#sea_surface_northward_current) |
|---|
| 2606 | | { |
|---|
| 2607 | | die "ABORT! Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i] {'var_name'}.\n"; |
|---|
| 2608 | | } |
|---|
| 2609 | | else |
|---|
| 2610 | | { |
|---|
| 2611 | | for my $k (0..$#this_sea_surface_eastward_current_data) |
|---|
| 2612 | | { |
|---|
| 2613 | | $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; |
|---|
| 2614 | | $this_time_stamp = $time_formatted_values[$k]; |
|---|
| 2615 | | $this_time_stamp_sec = timelocal(substr($this_time_stamp,17,2),substr($this_time_stamp,14,2),substr($this_time_stamp,11,2),substr($this_time_stamp,8,2),(substr($this_time_stamp,5,2)-1),substr($this_time_stamp,0,4)); |
|---|
| 2616 | | |
|---|
| 2617 | | my $ECurrentDataVal = 'NULL'; |
|---|
| 2618 | | my $NCurrentDataVal = 'NULL'; |
|---|
| 2619 | | my $Height = ''; |
|---|
| 2620 | | |
|---|
| 2621 | | if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value |
|---|
| | 2539 | if ($j > $#sea_surface_northward_current) { |
|---|
| | 2540 | die "ABORT! Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i] {'var_name'}.\n"; |
|---|
| | 2541 | } |
|---|
| | 2542 | else { |
|---|
| | 2543 | for my $k (0..$#this_sea_surface_eastward_current_data) { |
|---|
| | 2544 | $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; |
|---|
| | 2545 | $this_time_stamp = $time_formatted_values[$k]; |
|---|
| | 2546 | $this_time_stamp_sec = timelocal(substr($this_time_stamp,17,2),substr($this_time_stamp,14,2),substr($this_time_stamp,11,2),substr($this_time_stamp,8,2),(substr($this_time_stamp,5,2)-1),substr($this_time_stamp,0,4)); |
|---|
| | 2547 | |
|---|
| | 2548 | #print "debug: $sea_surface_eastward_current[$i]{'data'}[$k]\n"; |
|---|
| | 2549 | if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value |
|---|
| 2626 | | && $this_time_stamp_sec > $oldest_ok_timestamp) |
|---|
| | 2554 | && $this_time_stamp_sec > $oldest_ok_timestamp) { |
|---|
| | 2555 | print CURRENT_IN_SITU_SQLFILE "INSERT INTO current_in_situ_prod ("; |
|---|
| | 2556 | print CURRENT_IN_SITU_SQLFILE "station_id,"; |
|---|
| | 2557 | print CURRENT_IN_SITU_SQLFILE "time_stamp,"; |
|---|
| | 2558 | print CURRENT_IN_SITU_SQLFILE "z,"; |
|---|
| | 2559 | print CURRENT_IN_SITU_SQLFILE "positive,"; |
|---|
| | 2560 | print CURRENT_IN_SITU_SQLFILE "eastward_current,"; |
|---|
| | 2561 | print CURRENT_IN_SITU_SQLFILE "northward_current,"; |
|---|
| | 2562 | print CURRENT_IN_SITU_SQLFILE "surface_or_bottom,"; |
|---|
| | 2563 | print CURRENT_IN_SITU_SQLFILE "the_geom"; |
|---|
| | 2564 | print CURRENT_IN_SITU_SQLFILE ") "; |
|---|
| | 2565 | print CURRENT_IN_SITU_SQLFILE "VALUES ("; |
|---|
| | 2566 | print CURRENT_IN_SITU_SQLFILE '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; |
|---|
| | 2567 | print CURRENT_IN_SITU_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$k].'\''; |
|---|
| | 2568 | if ($sea_surface_eastward_current[$i]{'height'} == $missing_value_value |
|---|
| | 2569 | || $sea_surface_eastward_current[$i]{'height'} == $Fill_value_value) { |
|---|
| | 2570 | print CURRENT_IN_SITU_SQLFILE ','.'\'\''; |
|---|
| | 2571 | } |
|---|
| | 2572 | else { |
|---|
| | 2573 | $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'}); |
|---|
| | 2574 | print CURRENT_IN_SITU_SQLFILE ','.$this_val; |
|---|
| | 2575 | |
|---|
| | 2576 | } |
|---|
| | 2577 | print CURRENT_IN_SITU_SQLFILE ','.'\''.$height_var{'positive'}.'\''; |
|---|
| | 2578 | $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); |
|---|
| | 2579 | |
|---|
| | 2580 | print CURRENT_IN_SITU_SQLFILE ','.$this_val; |
|---|
| | 2581 | $this_val = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); |
|---|
| | 2582 | |
|---|
| | 2583 | print CURRENT_IN_SITU_SQLFILE ','.$this_val; |
|---|
| | 2584 | print CURRENT_IN_SITU_SQLFILE ','.'\'surface\''; |
|---|
| | 2585 | print CURRENT_IN_SITU_SQLFILE ",GeometryFromText('POINT("; |
|---|
| | 2586 | print CURRENT_IN_SITU_SQLFILE $longitude_value[0].' '.$latitude_value[0]; |
|---|
| | 2587 | print CURRENT_IN_SITU_SQLFILE ")',-1));\n"; |
|---|
| | 2588 | } |
|---|
| | 2589 | |
|---|
| | 2590 | } |
|---|
| | 2591 | } |
|---|
| | 2592 | print CURRENT_IN_SITU_SQLFILE "\n"; |
|---|
| | 2593 | } |
|---|
| | 2594 | close(CURRENT_IN_SITU_SQLFILE); |
|---|
| | 2595 | } |
|---|
| | 2596 | #DWR 4/5/2008 |
|---|
| | 2597 | if( $bWriteobsKMLFile ) |
|---|
| | 2598 | { |
|---|
| | 2599 | for my $i (0..$#sea_surface_eastward_current) |
|---|
| | 2600 | { |
|---|
| | 2601 | my $j = 0; |
|---|
| | 2602 | while ($j <= $#sea_surface_northward_current |
|---|
| | 2603 | && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'}) |
|---|
| | 2604 | { |
|---|
| | 2605 | $j++; |
|---|
| | 2606 | } |
|---|
| | 2607 | if ($j > $#sea_surface_northward_current) |
|---|
| | 2608 | { |
|---|
| | 2609 | die "ABORT! Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i] {'var_name'}.\n"; |
|---|
| | 2610 | } |
|---|
| | 2611 | else |
|---|
| | 2612 | { |
|---|
| | 2613 | for my $k (0..$#this_sea_surface_eastward_current_data) |
|---|
| 2628 | | if ($sea_surface_eastward_current[$i]{'height'} != $missing_value_value |
|---|
| 2629 | | && $sea_surface_eastward_current[$i]{'height'} != $Fill_value_value) |
|---|
| | 2615 | $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; |
|---|
| | 2616 | $this_time_stamp = $time_formatted_values[$k]; |
|---|
| | 2617 | $this_time_stamp_sec = timelocal(substr($this_time_stamp,17,2),substr($this_time_stamp,14,2),substr($this_time_stamp,11,2),substr($this_time_stamp,8,2),(substr($this_time_stamp,5,2)-1),substr($this_time_stamp,0,4)); |
|---|
| | 2618 | |
|---|
| | 2619 | my $ECurrentDataVal = 'NULL'; |
|---|
| | 2620 | my $NCurrentDataVal = 'NULL'; |
|---|
| | 2621 | my $Height = ''; |
|---|
| | 2622 | |
|---|
| | 2623 | if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value |
|---|
| | 2624 | && $sea_surface_eastward_current[$i]{'data'}[$k] != $Fill_value_value |
|---|
| | 2625 | && $sea_surface_northward_current[$j]{'data'}[$k] != $missing_value_value |
|---|
| | 2626 | && $sea_surface_northward_current[$j]{'data'}[$k] != $Fill_value_value |
|---|
| | 2627 | && $this_station_id_top_ts < $this_time_stamp_sec |
|---|
| | 2628 | && $this_time_stamp_sec > $oldest_ok_timestamp) |
|---|
| 2635 | | $NCurrentDataVal = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); |
|---|
| 2636 | | |
|---|
| 2637 | | } |
|---|
| 2638 | | my $strUnits; |
|---|
| 2639 | | $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_eastward_current[$i]{'units'}, $XMLControlFile ); |
|---|
| 2640 | | if( length( $strUnits ) == 0 ) |
|---|
| 2641 | | { |
|---|
| 2642 | | $strUnits = $sea_surface_eastward_current[$i]{'units'}; |
|---|
| 2643 | | } |
|---|
| 2644 | | |
|---|
| 2645 | | obsKMLSubRoutines::KMLAddObsToHash( 'eastward_current', |
|---|
| 2646 | | $time_formatted_values[$j], |
|---|
| 2647 | | $ECurrentDataVal, |
|---|
| 2648 | | 1, |
|---|
| 2649 | | $strPlatformID, |
|---|
| 2650 | | $Height, |
|---|
| 2651 | | $strUnits, |
|---|
| 2652 | | $rObsHash ); |
|---|
| 2653 | | $strUnits = ''; |
|---|
| 2654 | | $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_northward_current[$i]{'units'}, $XMLControlFile ); |
|---|
| 2655 | | if( length( $strUnits ) == 0 ) |
|---|
| 2656 | | { |
|---|
| 2657 | | $strUnits = $sea_surface_northward_current[$i]{'units'}; |
|---|
| 2658 | | } |
|---|
| 2659 | | obsKMLSubRoutines::KMLAddObsToHash( 'northward_current', |
|---|
| 2660 | | $time_formatted_values[$j], |
|---|
| 2661 | | $NCurrentDataVal, |
|---|
| 2662 | | 1, |
|---|
| 2663 | | $strPlatformID, |
|---|
| 2664 | | $Height, |
|---|
| 2665 | | $strUnits, |
|---|
| 2666 | | $rObsHash ); |
|---|
| 2667 | | } |
|---|
| 2668 | | } |
|---|
| 2669 | | } |
|---|
| | 2647 | obsKMLSubRoutines::KMLAddObsToHash( 'eastward_current', |
|---|
| | 2648 | $time_formatted_values[$j], |
|---|
| | 2649 | $ECurrentDataVal, |
|---|
| | 2650 | 1, |
|---|
| | 2651 | $strPlatformID, |
|---|
| | 2652 | $Height, |
|---|
| | 2653 | $strUnits, |
|---|
| | 2654 | $rObsHash ); |
|---|
| | 2655 | $strUnits = ''; |
|---|
| | 2656 | $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_northward_current[$i]{'units'}, $XMLControlFile ); |
|---|
| | 2657 | if( length( $strUnits ) == 0 ) |
|---|
| | 2658 | { |
|---|
| | 2659 | $strUnits = $sea_surface_northward_current[$i]{'units'}; |
|---|
| | 2660 | } |
|---|
| | 2661 | obsKMLSubRoutines::KMLAddObsToHash( 'northward_current', |
|---|
| | 2662 | $time_formatted_values[$j], |
|---|
| | 2663 | $NCurrentDataVal, |
|---|
| | 2664 | 1, |
|---|
| | 2665 | $strPlatformID, |
|---|
| | 2666 | $Height, |
|---|
| | 2667 | $strUnits, |
|---|
| | 2668 | $rObsHash ); |
|---|
| | 2669 | } |
|---|
| | 2670 | } |
|---|
| | 2671 | } |
|---|
| | 2672 | } |
|---|