# HG changeset patch # User A.M. Thurnherr # Date 1425578098 18000 # Node ID bdd9251865629bd058c367d1a76cb3327f8205d6 # Parent 58c5aa2305501fac8a295e9dca207cb3cc432512 laptop version diff --git a/antsio.pl b/antsio.pl --- a/antsio.pl +++ b/antsio.pl @@ -2,9 +2,9 @@ #====================================================================== # A N T S I O . P L # doc: Fri Jun 19 19:22:51 1998 -# dlm: Tue Jul 22 20:39:11 2014 +# dlm: Thu Aug 7 09:20:37 2014 # (c) 1998 A.M. Thurnherr -# uE-Info: 497 0 NIL 0 0 70 2 2 4 NIL ofnI +# uE-Info: 204 55 NIL 0 0 70 2 2 4 NIL ofnI #====================================================================== # HISTORY: @@ -201,6 +201,7 @@ # Jul 20, 2014: - adapted antsFileScanParam() to :: convention # Jul 22, 2014: - BUG: antsPadIn was done after handling -S & -N # - removed antsPadIn flag (made it always be true) +# Aug 7, 2014: - allow optional % in param name in &antsFileScanParam() # NOTES: # - %P was named without an ants-prefix because associative arrays @@ -871,6 +872,8 @@ my($f,$pn) = @_; my($v1,$v2); + $pn = $' if ($pn =~ /^%/); # strip optional leading % + while ($_ = <$f>) { # get next record last unless (/^#/ || /^\s*$/); next unless (/^#ANTS#PARAMS# /); diff --git a/antsusage.pl b/antsusage.pl --- a/antsusage.pl +++ b/antsusage.pl @@ -2,9 +2,9 @@ #====================================================================== # A N T S U S A G E . P L # doc: Fri Jun 19 13:43:05 1998 -# dlm: Tue Apr 2 22:26:55 2013 +# dlm: Wed Jul 30 12:43:52 2014 # (c) 1998 A.M. Thurnherr -# uE-Info: 157 44 NIL 0 0 70 2 2 4 NIL ofnI +# uE-Info: 365 24 NIL 0 0 70 2 2 4 NIL ofnI #====================================================================== # HISTORY: @@ -155,6 +155,7 @@ # Apr 2, 2013: - BUG: pref{}suff special args did sometimes produce unexpanded as well # as expanded output (unexpanded should be produced only if the # expansion is empty) +# Jul 30, 2014: - added special args to -U)sage output # NOTES: # - ksh expands {}-arguments with commas in them!!! Use + instead @@ -168,15 +169,21 @@ print(STDERR "\n$0\n\n") } if ($opt_U) { - print(STDERR "Options & Arguments: $antsCurUsage$_[0]\n\nCommon options:\n" . - "\t[-F)ields {%P|f|[\$@]|[f]=expr}[,...]]\n" . - "\t[num for-M)at] [-C)anonical numbers] [-G)eographic lat/lon]\n" . - "\t[-A)ctivate output] [LaTeX -T)able output]\n" . - "\t[-S)elect ] [-N)ums f[,...]] [-H)ead ]\n" . - "\t[-P)ass comments] [-Q)uiet (no headers)] [-X (no new header)]\n" . - "\t[suppress -D)ependency checks & addition of new dependencies]\n" . - "\t[-L)oad ]\n" . - "\t[-I)n field-sep] [-O)ut field-sep] [-R)ecord sep]\n"); + print(STDERR "Options & Arguments: $antsCurUsage$_[0]\n\n" . + "Common Options:\n" . + "\t[-F)ields {%P|f|[\$@]|[f]=expr}[,...]]\n" . + "\t[num for-M)at] [-C)anonical numbers] [-G)eographic lat/lon]\n" . + "\t[-A)ctivate output] [LaTeX -T)able output]\n" . + "\t[-S)elect ] [-N)ums f[,...]] [-H)ead ]\n" . + "\t[-P)ass comments] [-Q)uiet (no headers)] [-X (no new header)]\n" . + "\t[suppress -D)ependency checks & addition of new dependencies]\n" . + "\t[-L)oad ]\n" . + "\t[-I)n field-sep] [-O)ut field-sep] [-R)ecord sep]\n\n" . + "Special Argument Expansion:\n" . + "\t@:\t\t\t values in \n" . + "\t#-[:]\t\tenumerated values\n" . + "\t[prefix]{}[suffix]\texisting files (ranges: [-][+...])\n" . + "\t[prefix](())[suffix]\tfiles, using with ranges\n"); } else { print(STDERR "Options & Arguments: $antsCurUsage$_[0]\n"); } @@ -321,7 +328,6 @@ push(@exp,$i); } } -# } elsif ($ARGV[$ai] =~ m{\{([^\}]+)\}}) { # pref{list of ranges}suff } elsif ($ARGV[$ai] =~ m{\{([-\+,\d]+)\}}) { # pref{list of ranges}suff my($pref) = $`; my($suff) = $'; foreach my $range (split('[,\+]',$1)) { @@ -350,6 +356,31 @@ } @exp = ($ARGV[$ai]) # make sure it *was* special arg unless (@exp); + } elsif ($ARGV[$ai] =~ m{\(\(([^\)]+)\)\)}) { # pref((file))suff + my($pref) = $`; my($suff) = $'; + &antsAddDeps($1); + open(F,$1) || croak("$1: $!\n"); + while () { + s/#.*//g; next if /^\s+$/; # handle comments and empty lines + s/\s*//g; + chomp($_); + if ($_ =~ /^(\d+)-(\d+)$/) { + my($fmt) = length($1)==length($2) ? + sprintf("$pref%%0%dd$suff",length($1)) : "$pref%d$suff"; + if ($2 > $1) { + for (my($i)=$1; $i<=$2; $i++) { + push(@exp,sprintf($fmt,$i)); + } + } else { + for (my($i)=$1; $i>=$2; $i--) { + push(@exp,sprintf($fmt,$i)); + } + } + } else { + push(@exp,"$pref$_$suff"); + } + } + close(F); } else { # regular argument next; } diff --git a/libconv.pl b/libconv.pl --- a/libconv.pl +++ b/libconv.pl @@ -1,9 +1,9 @@ #====================================================================== # L I B C O N V . P L # doc: Sat Dec 4 13:03:49 1999 -# dlm: Tue May 22 11:34:01 2012 +# dlm: Thu Aug 7 09:17:59 2014 # (c) 1999 A.M. Thurnherr -# uE-Info: 63 84 NIL 0 0 70 2 2 4 NIL ofnI +# uE-Info: 203 27 NIL 0 0 70 2 2 4 NIL ofnI #====================================================================== # HISTORY: @@ -61,6 +61,7 @@ # Apr 17, 2012: - added space as another date separator in ddmmyy2dec_time # May 22, 2012: - BUG: illegal time spec error was also produced on missing seconds # - BUG: mmddyy2dec_time() did not allow for optional epoch argument +# Aug 7, 2014: - finally cleaned up date conversions require "$ANTS/libEOS83.pl"; # &sigma() require "$ANTS/libPOSIX.pl"; # &floor() @@ -93,76 +94,11 @@ croak("$0: &monthLength(): Illegal month\n"); } -{ my(@fc); - - sub Date(@) # day number -> date - { - - my($dnf); # find std dn field & epoch - if (@_ == 0) { - for (my($i)=0; $i<@antsLayout; $i++) { - next unless ($antsLayout[$i] =~ /^dn(\d\d)$/); - $dnf = $antsLayout[$i]; push(@_,$1); - last; - } - } - - my($year,$day) = &antsFunUsage(2,"cf","epoch, dayNo",\@fc,undef,$dnf,@_); - - $year += ($year < 50) ? 2000 : 1900 # Y2K - if ($year < 100); - - $day = int($day); # prevent runover on last day of month - while ($day > 365+&leapYearP($year)) { # adjust year - $day -= 365 + &leapYearP($year); - $year++; - } - - my($month) = 1; - while ($day > &monthLength($year,$month)) { - $day -= &monthLength($year,$month); - $month++; - } - - return sprintf('%04d/%02d/%02d',$year,$month,$day); - } -} - -{ my(@fc); - - sub Time(@) # day number -> date/time - { - my($dnf); # find standard dn field - for (my($i)=0; $i<@antsLayout; $i++) { - next unless ($antsLayout[$i] =~ /^dn\d\d$/); - $dnf = $antsLayout[$i]; - last; - } - - my($fday) = &antsFunUsage(1,"f","dayNo",\@fc,$dnf,@_); - my($day) = int($fday); - $fday -= $day; - - my($hour) = int(24*$fday); - $fday -= $hour/24; - my($min) = int(24*60*$fday); - $fday -= $min/24/60; - my($sec) = round(24*3600*$fday); - $min++,$sec=0 if ($sec == 60); - $hour++,$min=0 if ($min == 60); - $day++,$hour=0 if ($hour == 24); - - return sprintf('%02d:%02d:%02d',$hour,$min,$sec); - } -} - sub dayNo(@) # day number, starting at 1 { - my($epoch,$y,$m,$d) = - &antsFunUsage(-3,"c..","[epoch,] year, month, day",@_); - unless (defined($d)) { - $d = $m; $m = $y; $y = $epoch; - } + my($y,$m,$d,$epoch) = + &antsFunUsage(-3,"c..","year, month, day[, epoch]",@_); + $epoch = $y unless defined($epoch); unless (cardinalp($m)) { $m = lc($m); @@ -235,83 +171,106 @@ return $h*3600 + $m*60 + $s; } -sub str2dec_time(@) # decimal time -{ - my($ts,$ds,$epoch) = - &antsFunUsage(-1,'.',"'hh:mm[:ss]'[,'[YY]YY/MM/DD'[,epoch]]",@_); - - my($dayNo) = 0; - if ($ds ne '') { # date - my($yy,$mm,$dd) = split('[-/\.]',$ds); - $dayNo = defined($epoch) ? - dayNo($epoch,$yy,$mm,$dd) : dayNo($yy,$mm,$dd); - } - - my($h,$m,$s) = split(':',$ts); - $s = 0 unless defined($s); - return $dayNo + &frac_day($h,$m,$s); -} - sub dec_time(@) # decimal time { my($epoch,$yy,$mm,$dd,$h,$m,$s) = &antsFunUsage(7,'ccccccf'," ",@_); - return &dayNo($epoch,$yy,$mm,$dd) + &frac_day($h,$m,$s); + return &dayNo($yy,$mm,$dd,$epoch) + &frac_day($h,$m,$s); } -sub mmddyy2dec_time(@) # decimal time +#---------------------------------------------------------------------- +# String to Decimal Time Conversion +#---------------------------------------------------------------------- + +{ my($date_fmt); + + sub str2dec_time(@) # heuristic + { + my($ds,$ts,$epoch) = + &antsFunUsage(-2,"..","date, hh:mm[:ss][, epoch]",@_); + + croak("$0 str2dec_time: date required\n") unless ($ds ne ''); + + unless (defined($date_fmt)) { + my($X,$Y,$Z) = split('[-/\.]',$ds); + if ($X > 31) { # YY/MM//DD + $date_fmt = 1; + } elsif ($X > 12) { # DD/MM/YY + $date_fmt = 2; + } elsif ($Y > 12) { # MM/DD/YY + $date_fmt = 3; + } else { + &antsInfo("str2dec_time: ambiguous date <$ds>; MM/DD/YY assumed"); + $date_fmt = 3; + } + } + + if ($date_fmt == 1) { return yymmdd2dec_time($ds,$ts,$epoch); } + elsif ($date_fmt == 2) { return ddmmyy2dec_time($ds,$ts,$epoch); } + else { return mmddyy2dec_time($ds,$ts,$epoch); } + } + +} + +sub mmddyy2dec_time(@) { my($ds,$ts,$epoch) = - &antsFunUsage(-2,"..","date-string (empty ok), time-string[, epoch]",@_); + &antsFunUsage(-2,"..","MM/DD/[YY]YY, hh:mm[:ss][, epoch]",@_); my($time) = 0; - if ($ds ne "") { # date - my($mm,$dd,$yy) = split('[-/\. ]',$ds); - if (defined($epoch)) { - $time = dayNo($epoch,$yy,$mm,$dd); - } else { - $time = dayNo($yy,$yy,$mm,$dd); + if ($ds ne '') { + my($yy,$mm,$dd); + if (length($ds) == 6) { + $mm = substr($ds,0,2); + $dd = substr($ds,2,2); + $yy = substr($ds,4,2); + } else { + ($mm,$dd,$yy) = split('[-/\.]',$ds); } + $time = dayNo($yy,$mm,$dd,$epoch); + } + if ($ts ne '') { + my($h,$m,$s) = split(':',$ts); + $s = 0 unless defined($s); + return $time + &frac_day($h,$m,$s); + } + return $time; +} + +sub ddmmyy2dec_time(@) +{ + my($ds,$ts,$epoch) = + &antsFunUsage(-2,"..","DD/MM/[YY]YY, hh:mm[:ss][, epoch]",@_); + + my($time) = 0; + if ($ds ne '') { + my($yy,$mm,$dd); + if (length($ds) == 6) { + $dd = substr($ds,0,2); + $mm = substr($ds,2,2); + $yy = substr($ds,4,2); + } else { + ($dd,$mm,$yy) = split('[-/\.]',$ds); + } + $time = dayNo($yy,$mm,$dd,$epoch); } - my($h,$m,$s) = split(':',$ts); # time - croak("$0: &mmddyy2dec_time(): illegal time spec $ts\n") - unless ((defined($h) && $h>=0 && $h<24) && - (defined($m) && $m>=0 && $m<60) && - (!defined($s) || ($s>=0 && $s<60))); - $time += $h/24 + $m/24/60 + $s/24/3600; + if ($ts ne '') { + my($h,$m,$s) = split(':',$ts); + $s = 0 unless defined($s); + return $time + &frac_day($h,$m,$s); + } return $time; } -sub ddmmyy2dec_time(@) # decimal time +sub yymmdd2dec_time(@) { - my($epoch,$ds,$ts) = - &antsFunUsage(3,"c..","epoch, date-string (empty ok), time-string",@_); + my($ds,$ts,$epoch) = + &antsFunUsage(-2,"..","[YY]YY/MM/DD, hh:mm[:ss][, epoch]",@_); my($time) = 0; - if ($ds ne "") { # date - my($dd,$mm,$yy) = split('[-/\.]',$ds); - $time = dayNo($epoch,$yy,$mm,$dd); - } - - my($h,$m,$s) = split(':',$ts); - croak("$0: &dec_time(): illegal time spec $ts\n") - unless ((defined($h) && $h>=0 && $h<24) && - (defined($m) && $m>=0 && $m<60) && - (!defined($s) || ($s>=0 && $s<60))); - $time += $h/24 + $m/24/60 + $s/24/3600; - - return $time; -} - -sub yymmdd2dec_time(@) # decimal time -{ - my($epoch,$ds,$ts) = - &antsFunUsage(3,"c..","epoch, date-string (empty ok), time-string (empty ok)",@_); - - my($time) = 0; - if ($ds ne "") { # date + if ($ds ne '') { my($yy,$mm,$dd); if (length($ds) == 6) { $yy = substr($ds,0,2); @@ -320,46 +279,114 @@ } else { ($yy,$mm,$dd) = split('[-/\.]',$ds); } - $time = dayNo($epoch,$yy,$mm,$dd); + $time = dayNo($yy,$mm,$dd,$epoch); } if ($ts ne '') { my($h,$m,$s) = split(':',$ts); - croak("$0: &dec_time(): illegal time spec $ts\n") - unless ((defined($h) && $h>=0 && $h<24) && - (defined($m) && $m>=0 && $m<60) && - (!defined($s) || ($s>=0 && $s<60))); - $time += $h/24 + $m/24/60 + $s/24/3600; + $s = 0 unless defined($s); + return $time + &frac_day($h,$m,$s); } return $time; } +#---------------------------------------------------------------------- +# Decimal Time to Strin Conversion +#---------------------------------------------------------------------- + +{ my(@fc); + + sub Date(@) # day number -> date + { + + my($dnf); # find std dn field & epoch + if (@_ == 0) { + for (my($i)=0; $i<@antsLayout; $i++) { + next unless ($antsLayout[$i] =~ /^dn(\d\d)$/); + $dnf = $antsLayout[$i]; push(@_,$1); + last; + } + } + + my($year,$day) = &antsFunUsage(2,"cf","epoch, dayNo",\@fc,undef,$dnf,@_); + + $year += ($year < 50) ? 2000 : 1900 # Y2K + if ($year < 100); + + $day = int($day); # prevent runover on last day of month + while ($day > 365+&leapYearP($year)) { # adjust year + $day -= 365 + &leapYearP($year); + $year++; + } + + my($month) = 1; + while ($day > &monthLength($year,$month)) { + $day -= &monthLength($year,$month); + $month++; + } + + return sprintf('%04d/%02d/%02d',$year,$month,$day); + } +} + +{ my(@fc); + + sub Time(@) # day number -> date/time + { + my($dnf); # find standard dn field + for (my($i)=0; $i<@antsLayout; $i++) { + next unless ($antsLayout[$i] =~ /^dn\d\d$/); + $dnf = $antsLayout[$i]; + last; + } + + my($fday) = &antsFunUsage(1,"f","dayNo",\@fc,$dnf,@_); + my($day) = int($fday); + $fday -= $day; + + my($hour) = int(24*$fday); + $fday -= $hour/24; + my($min) = int(24*60*$fday); + $fday -= $min/24/60; + my($sec) = round(24*3600*$fday); + $min++,$sec=0 if ($sec == 60); + $hour++,$min=0 if ($min == 60); + $day++,$hour=0 if ($hour == 24); + + return sprintf('%02d:%02d:%02d',$hour,$min,$sec); + } +} + +#---------------------------------------------------------------------- +# Other Misc Date Conversions +#---------------------------------------------------------------------- + sub date2str(@) { - my($MM,$DD,$YYYY) = &antsFunUsage(3,"ccc","month, day, year",@_); + my($MM,$DD,$YYYY) = &antsFunUsage(3,'ccc','month, day, year',@_); $YYYY += 2000 if ($YYYY < 50); $YYYY += 1900 if ($YYYY < 100); - return sprintf("%02d",$MM) . "/" . - sprintf("%02d",$DD) . "/" . $YYYY; + return sprintf('%02d',$MM) . '/' . + sprintf('%02d',$DD) . '/' . $YYYY; } sub card_date2str(@) { - my($DDMMYY) = &antsFunUsage(1,"c","ddmmyy",@_); - $DDMMYY = sprintf("%06d",$DDMMYY); + my($DDMMYY) = &antsFunUsage(1,'c','ddmmyy',@_); + $DDMMYY = sprintf('%06d',$DDMMYY); return &fmtdate(substr($DDMMYY,2,2),substr($DDMMYY,0,2),substr($DDMMYY,4,2)); } sub time2str(@) { - my($HH,$MM) = &antsFunUsage(2,"cc","hr, min",@_); - return sprintf("%02d",$HH) . ":" . sprintf("%02d",$MM); + my($HH,$MM) = &antsFunUsage(2,'cc','hr, min',@_); + return sprintf('%02d',$HH) . ':' . sprintf('%02d',$MM); } sub card_time2str(@) { - my($HHMM) = &antsFunUsage(1,"c","hrmin",@_); + my($HHMM) = &antsFunUsage(1,'c','hrmin',@_); return &fmttime(int($HHMM/100),$HHMM%100); } @@ -376,7 +403,7 @@ sub dmh2deg(@) # dd mm.m NSEW -> dd.d { my($deg,$min,$hemisph) = - &antsFunUsage(3,"ff1","deg, min, hemisphere",@_); + &antsFunUsage(3,'ff1','deg, min, hemisphere',@_); croak("$0 dmh2d(): may not be -ve\n") if ($deg < 0); croak("$0 dmh2d(): may not be -ve\n") if ($min < 0); $deg += $min/60; @@ -392,7 +419,7 @@ sub dmsh2deg(@) # dd mm ss NSEW -> dd.d { my($deg,$min,$sec,$hemisph) = - &antsFunUsage(4,"fff1","deg, min, sec, hemisphere",@_); + &antsFunUsage(4,'fff1','deg, min, sec, hemisphere',@_); croak("$0 dmsh2d(): may not be -ve\n") if ($deg < 0); croak("$0 dmsh2d(): may not be -ve\n") if ($min < 0); croak("$0 dmsh2d(): may not be -ve\n") if ($sec < 0); @@ -408,7 +435,7 @@ sub str2deg(@) # string containing dd [mm.m] [NSEW] -> dd.d { - my($s) = &antsFunUsage(1,".","'deg[ :][min][ ]hemisphere'",@_); + my($s) = &antsFunUsage(1,'.',"'deg[ :][min][ ]hemisphere'",@_); my($deg,$a,$b) = ($s =~ m{^([-\d]+)[\s:]([\d\.]+)\s*([NSEW])$}); # print(STDERR "--> $deg, $a, $b\n"); return ($b eq "") ? &dmh2d($deg,0,$a) : &dmh2d($deg,$a,$b);