Video Conversion Script for ffmpeg

Once and a while I have to convert a video made with Cheese, a .webm, or one made by my camera, .mov to an MP4 which takes up the least amount of space (as of 2017) and seems to be supported across a lot of devices.

The script is both a script to run and a reminder as to the syntax that ffmpeg expects as I seem to occasionally forget and wanted a snippet on line as a quick go to for reference.

In this one scaling is applied via the -s option and the bandwidth via the -b option is limited as well. Plus it allows you to choose the filename for the output file.

If ffmpeg -i %1 %1.mp4 is used for example it would take the input file and convert to mp4, tacking on the mp4 extension with no scaling and bandwidth limiting.

#! /bin/bash
#ffmpeg -i input.wmv -s 480x320 -b 1000k output.mp4
ffmpeg -i %1 -s 480x320 -b 1000k %2

Better Yet Do It Batchwise

For example, with a for loop, this code will simply go through the directory and convert all .webm’s to .mp4’s and it is set up to do scaling too if needed using -s hd480. It also keeps the same filename by changes the extension to the appropriate one for the output file.

#!/bin/bash

for a in ./*.webm; do
#  ffmpeg -i "$a" -qscale:a 0 "${a[@]/%webm/mp4}"
  ffmpeg -i "$a" -s hd480 -qscale:a 0 "${a[@]/%webm/mp4}"
done

 

Temperature, Humidity and Barometric Pressure Monitoring with Raspberry Pi

Brief notes on hooking up sensors for temperature, humidity and barometric sensors. These notes are kind of an outline of what I used and went through to get the sensors up an running. There are plenty of other detailed notes out there on the web, this might help fill in some blanks. Plus I figured, I took all these notes down and they might as well be published to do some more good.

Raspberry Pi Pinout

Model B IO Pins

DHT22 / AM2302

https://www.adafruit.com/products/385?&main_page=product_info&products_id=385

https://www.adafruit.com/products/393?&main_page=product_info&products_id=393

I followed this example to get the DHT22 sensor up and running all the way to executing the example code

https://learn.adafruit.com/downloads/pdf/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging.pdf

Raspberry Pi Weather Dashboard

I put all if this together to make a dashboard page for the sensors.

http://erick.mynetgear.com

 

 

morse-1 code

Cron Driven Morse Code Time Sounder

My goal was to make a new hourly chime,something with a bit of intelligence to it than just the same tone every hour. It was actually one of those random things that runs through your head when laying in bed trying to get in a mood to sleep.

A bit of history

Typically I have been using a preexisting system sound on a Linux PC to annunciate that it is the top of the hour. This helps to keep track of how long I am on the computer, time to take a break maybe. It also makes me away of the time, in case I am in the zone with coding or whatnot and need to be aware of how time flies. Once you have this, you kind of look for it, even when you are in the room doing something other than computer work.

Up to now this is what I typically had in my crontab…

00 09-23 * * * aplay /usr/share/sounds/fLight__2.0/stereo/Message.wav

I restrict the hours down, just so the thing doesn’t wake me at night if I forget to turn off the PC.

Festival

Years ago I used Festival, the text to speech program and made it annunciate the time. This works OK as long as you are at the PC. If you are away from it a bit, you don’t always pick up what the machine generated voice is saying. Morse Code has an advantage over voice, in that the tones are easy to pick up, even when faint. I have a ham license and have experienced this first hand. So that was my line of thinking with using Morse to give me the time at the top of the hour. It would be easy to not only know that it is the top of the hour but, I can tell what hour it is easily with Morse code. Plus it seemed like a fun twist. I have even thought of putting something like this on my Pi which runs 24/7 in my office. In our living room we have a bird clock, that has different bird sounds for each hour and that has been pretty useful at times, so that got me going on this whole hourly chime adventure years ago.

I was initially inclined to make my own tones but, a brief search found Stephen C. Phillips site and his Morse Code Translator. Using it I was able to create a more code “hour” sound file from 0-23, that plays the correct sounding for every hour.

It is possible to take any sound files and label them 0-23.wav and get other types of sounds to chime at the top of the hour. Birds songs, train whistles, nature sounds, the possibilities are endless.

How it works

Using the Morse Code Translator, I was able to create a series of Morse Code translations from 0-23, in WAV file format. The WAV files get put in a directory, morse-code-audio under my home folder and the following script gets called in place of the line shown above in my crontab….

#!/bin/bash

sounddir=/home/erick/morse-code-audio

# Grab the Hours off of the date.

hour=$(date +"%H")

#Call the correct file based off of the hour
 aplay $sounddir/$hour.wav

WAV Files for the Morse Code Time Sounder

I put the 0-23.wav files online, as a tar.gz.

morse-code-audio.tar

Compression, Signal Processing, Information Theory and Cryptography

Uncompressed the 24 WAV files in the tar file are a total of 348K , it is interesting just how compressible single frequency tones are. All of them compress down to a 2.8K tar.gz. I had to check twice, I thought I was missing a bunch of files. But it stands to reason when one thinks of a single frequency turned on and off slowly, has very little bandwidth. Provided the keying is shaped in a way so that it is not a pure sine wave modulated by a square wave, the pulses have to be shaped the corners rounded off to get the bandwidth below 100Hz. Thinking of Fourier transform, a tone left on from infinity has a bandwidth of zero. A digital signal, pulse shaped, on and off keying at 20WPM code is going to have a real narrow bandwidth, therefore highly compressible. The opposite extreme, white noise, would not be compressed down at all by gzip or any of the fancier types of compression. White noise is random, equally distributed across the spectrum, hence incompressible. But it makes for a hell of an encryption key for that very reason. The worlds of signal processing and cryptography do come together in interesting ways!

Resources

Stephen C Phillips has an excellent website and blog that covers a lot of technical topics among with the Morse Code Translator is an example. He also covers Python code and the Raspberry Pi for example.

http://blog.scphillips.com/

The featured image is from this site and it is an interesting read…

https://www.raspberrypi.org/learning/morse-code-virtual-radio/worksheet/

24 Hour Digital Clock Gets a Better Timebase

The last post on this clock built out of 7400 series TTL chips gave a bit of back story on it and the initial troubleshooting of it’s timebase drift and noise issues that caused extraneous counts to occur. Now that the noise is figured out and solved, it is time to do something better than a plain crystal with a trimmer 7400 ( NAND Gate ) oscillator for a timebase.

Driving the clock with an OCXO

The goal was to allow the clock to be driven by an oven controlled crystal oscillator (OCXO), which would surpass the performance of the oscillator on the board. The on board oscillator can be easily pulled off it’s frequency and slaved to an external source. By using a 7414 Schmitt Trigger Hex Inverter, it is possible to take the low level sine wave output from the OCXO and convert it into a digital signal capable of entraining the on-board oscillator. By using an external master, I can pull the master OCXO off if I need it to calibrate anything else, meanwhile the clock keeps running off of it’s board oscillator. Most of the time the OCXO is not being used and can just remain with the clock.

7414-Schmitt-Trigger-on-breadboard
7414 Schmitt Trigger Hex Inverter on Breadboard

The hookup is pretty simple, I breadboarded it and found out the biasing one of the inputs of the 7414 mid range using a pair of 33K Ohm resistors in series from +5V power to ground with the input to an inverter stage on the 7414 in the middle at 2.5V, feeding in the OCXO signal, capacitively coupled  and then feeding the output of that stage into another inverter on the 7414 for a buffer, I was able to get a clean square wave at 10MHz. This I coupled to the board oscillator using a 370 Ohm resistor. The resistor is more or less a protection in case I touched it to something that I shouldn’t and I don’t want too much current to be able to flow in either direction. I also temporarily drove an LED via a 370 Ohm resistor off of the same output as a check that I was actually getting output, the LED is lit at half the brightness when it is excited by a square wave.

Initial testing with the breadboard shows that the clock now tracks time very well as compared to another clock I have that is synced to the WWV 60KHz signal.

OCXO to 7414 to TTL Clock
OCXO to 7414 to TTL Clock: Signal path is via yellow clip leads.

 

Previous post in this series

Miscanthus giganteus

I recently saw a stand of Miscanthus giganteus at Cutler Gardens in Binghamton,NY. It is an impressive grass standing at 10-11 feet tall. I am thinking of ordering some rhizomes to grow some. It would make a nice natural privacy fence. It sure looks cool too, even when it dies off it still stands nice and tall. I imagine the snow will eventually knock it over in the winter. When I saw it, I looked it up on the little pamphlets available at the gardens and of course on Wikipedia. https://en.wikipedia.org/wiki/Miscanthus_giganteus
Who would have know that it can be actually used as a biofuel! What an interesting plant and it is a so called C4 plant as well just like corn, it can more efficiency convert water and CO2, via photosynthesis into plant material, giving it an edge in creating biomass.

I found a place to order the rhizomes too…

http://www.mapleriverfarms.com/index.php

24HRTTLCLK

24 Hour Digital Clock Using TTL Chips

About 10 years ago I built a clock built out of TTL 7400 series chips. It worked in my shop for a number of years, then it got packed away when I moved in 2013. Meanwhile, In 2016  built a well made 24 hour clock from a kit from MTM Scientific, Inc that has a TCXO and drifts only a few seconds between the times of the year that it needs adjustment for daylight savings time. It has a nice bright readout and works well in my bedroom. But, it also got me thinking about the TTL clock again and I thought that one might be worth revisiting.

One issue with the 24 hour clock that I built from TTL chips is that it occasionally required adjustment of a trimmer capacitor to keep the oscillator running in time. I also noticed that occasionally it would flake out completely and get extra counts, causing it to run fast by about 1.5%. Sometimes just restarting it would fix the issue, it was a mysterious. It first occurred when I moved it to a different spot on the work bench after initially getting it put together and pinned to a wood board. My first thoughts were that I had a flaky chip. At one point I had accidentally connected the clock to a 12V power supply and blew out one chip and I speculated that there might be others  that were working but damaged. Or it could have been a bad solder joint, with all the points of connection that was certainly plausible.

The Real Issue

One thing that I didn’t have access to in 2007 that I have in hand now is a frequency counter. When I built the clock my frequency counter was missing. I had it packed away somewhere in 2003 and only found it years later (2013) as it was packed in a box that made no sense at all. But, it would have been handy at the time to track down where I was getting these extra counts. In early 2017 with the frequency counter in hand, I was able to quickly determine that it was not only extra counts, but noisy extra counts as the lower digits on the counter were fluctuating. Something was ringing or going into an oscillation, that was my initial thoughts. I relatively quickly suspected a buffer chip, 7400 inverter, that I had added to provide some reference outputs at 1MHz,100KHz, 10KHz and 1KHz. The chip was the only one on the oscillator and divider board that I had tacked on after the clock was working, so it seemed likely that it might be part of the issue. Plus, it was the only one that I had neglected to put a bypass capacitor across from power to ground. Removing power from the chip solved the problem, good counts, a perfect multiple of the 10MHz clock were now coming out of the board to drive the dividers on the second board with the digits. The chip might not be worth using, if I need lower frequency references I can always take another oscillator I have and use that.

Clock running close to target frequency.

Calibrating the 10MHz crystal oscillator by tweaking the trimmer, against a 10MHz OCXO ( Oven Controlled Crystal Oscillator ) and then watching it keep time for a few days, it now holds reasonable time.

The Next Plan

Frequency Counter and 10MHz OCXO
Frequency Counter and 10MHz OCXO

The next plan for this clock is to drive it with the 10MHz OCXO to overcome the limits of the simple 7400 Inverter TTL chip 10MHz crystal oscillator with a trimmer capacitor. This simple oscillator is limited, temperature will make it swing along with any proximity of metal or whatnot that changes the frequency. If you touch the crystal or any part of the circuit around it, I imagine the frequency is pulled off target.

By feeding it with the closed box OCXO, powered through a decent regulator, frequency variations due to temperature changes, voltage changes and capacitive changes due to proximity of conductors will be minimized. It will be interesting to see how stable the clock can be.

Also, it would be nice for this thing to finally wind up in a decent box and be powered by something other than a 12V to 5V regulator tacked to a spare breadboard.

24HRTTLCLKmounted
24HR TTL Clock. Mounted to temporary wood board.

I plan on writing more on this as the project unfolds, along with the schematics, when I find them, all hand written and might be lost when I moved, but I might just have to recreate them!

Next Post in this Series

Original Writeup on the Clock

It starts with a 10 MHz 7400 inverter oscillator and divides down using 7490 decade dividers set up to divide by 6 or 10 as needed. Some AND/OR logic appears in the design as well to provide a pseudo WWV time code, 1kHz second ticks, minute and hour marker. This output is provided as an amplified audio output. This is done using a small 1 stage transistor amplifier driving the 2 inch speaker, with series resistor to limit volume. A 1/8in jack is provided as well for driving a larger speaker. The marker is also able to modulate a 1MHz output for a test signal. Three modes of output are provided, 1MHz carrier, 1MHz modulated with steady 1kHz signal and 1MHz modulated with pseudo WWV time signal. This signal and 100kHz,10kHz,1kHz are provided as buffered outputs for off the board use.

The display itself is an array of dual 7 segment common anode 0.75 inch elements, with appropriate 7-segment drivers. Setting is via 3 pushbuttons. Two provide speedups of seconds 1000X and 10X to roll the clock ahead faster than real time, a third button is a halt button for syncing with another clock source. A 10Hz ‘heartbeat’ LED is provided for debugging purposes. This is connected at the junction between both boards.

One board is the oscillator and divider to 1000Hz and the test outputs (1MHz,100kHz, 10kHz and 1kHz. Pseudo WWV 1MHz and audio) and the other board divides down further and has the display and the drivers for the 7-segment LEDS.(3/2007)

From my old website projects page at…

http://www.frontiernet.net/~erickclasen/projects.html

Samba and Linux Mint

In my original post on Samba I covered a lot of basics. Recently I learned a bit more using Linux Mint. In Mint Samba is already loaded in the process of installing the OS. I remembered that I had to add all the computers to the same workgroup to get Linux and Windows to play together. But I couldn’t get two Mint machines to work via Samba. Name resolution was the issue.

I kept getting a “Failed to Retrieve Share List from Server” error. I was able to move files from a Mint machine to the Windows machine and then to the other Mint machine. The only thing I had to do is open up permissions on the folder to let Samba write to it. I used the Public folder under the /home/user directory. I would think that adding Samba to my user group would also work, I have checked into this and this is the answer I find…

http://unix.stackexchange.com/questions/206309/how-to-create-a-samba-share-that-is-writable-from-windows-without-777-permission

 

I did install Winbind thinking that it might help out. Windows machine can see Public folder, go into it and read and write with 777 permissions on it.

winbind is a component of the Samba suite of programs that solves the unified logon problem. Winbind uses a UNIX implementation of Microsoft RPC calls, Pluggable Authentication Modules (PAMs), and the name service switch (NSS) to allow Windows NT domain users to appear and operate as UNIX users on a UNIX machine.

https://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/winbind.html

 

I started with this post which got me sort of there…

Samba Basic – Lesson 1: Samba Simply

https://community.linuxmint.com/tutorial/view/672

 

Name Resolution with Samba

http://www.oreilly.com/openbook/samba/book/ch07_03.html

How to Fix ‘Failed to Retrieve Share List from Server’ in Ubuntu 12.04 / 11.10 when File Sharing with Windows

How to Fix ‘Failed to Retrieve Share List from Server’ in Ubuntu 12.04 / 11.10 when File Sharing with Windows

 

Banner Kashmiri Pumpkin

Kashmiri Pumpkin Curry

  • Why Pumpkin?

    A pumpkin patch grew out of out compost pile and it was a ready to display for Halloween. But then what to do. It hung out until December and it was time to bring it in and do something before it rotted. I saw a show about Kashmir recently ( Raja, Rasoi Aur Anya Kahaniyaan ) and thaPumpkint is where pumpkins come from originally and ridged squash too, in the vernacular that they used on the show, that must mean squash with ridges, like acorn squash. I figured there must be some good Kashmiri recipe out there for pumpkin. What else is going to be done with it, it is large and would make more than a pie, so it might as well get used in a new an different way.

     

    Ingredients

  • 2 onions, quartered
  • 2 garlic cloves
  • 4 cm (1½ inch) piece of fresh root ginger, peeled and sliced
  • 1 large red chilli, halved and deseeded
  • 1 teaspoon cumin seeds, roughly crushed
  • 1 teaspoon coriander seeds, roughly crushed
  • 5 cardamom pods, crushed
  • 1.4 kg (2¾ lb) pumpkin, deseeded and peeled
  • 2 tablespoons sunflower oil
  • 15 g (½ oz) butter
  • 1 teaspoon ground turmeric
  • 1 teaspoon paprika
  • 1 cinnamon stick, halved
  • 450 ml (¾ pint) vegetable stock
  • 150 ml (¼ pint) double cream
  • 50 g (2 oz) pistachio nuts, roughly chopped
  • small bunch of coriander, torn
  • salt and pepper
Onions and spices in pan for Kashmiri Pumpkin
Onions, garlic, ginger,chili and spices in pan for Kashmiri Pumpkin

Directions

Finely chop the onion, garlic, ginger and chill in a blender or food processor, or finely chop by hand, and mix with the crushed cumin, coriander and cardamom.

Slice the pumpkin into 2.5 cm (1 inch) wedges, then cut the wedges in half. Heat the oil and butter in a large frying pan, add the pumpkin pieces and fry for 5 minutes until lightly browned. Push the pumpkin to one side of the pan then add the onion mixture and fry until beginning to color.

Add the turmeric, paprika and cinnamon, cook briefly then stir in the stock. Season and bring to the boil. Cover and simmer for 10 minutes until the pumpkin is almost cooked. Allow to cool, cover and chill until required.

When ready to serve, add half the cream, half the pistachios and half the coriander leaves. Reheat until piping hot. Drizzle with the remaining cream, and sprinkle with the remaining pistachios and coriander. Serve with naan breads and a tomato and onion salad.

 

Resource

http://www.aol.co.uk/living/food/kashmiri-pumpkin-curry/903/

Benchmark Generation 2 i5 -vs- Generation 3 i5

Once and a while I will benchmark a PC that I happen to get my hands on. I tested a laptop with a Gen 3 i5 and compared it to my desktop with has 2 Gen 2 i5….

erick@OptiPlex-790 ~/factor $ tail i5-3340M@3200Mhz-bmark.txt

Calculations Completed!
 Time: 9 seconds

Factor: Finished in about 10.000000 seconds.
 Pi: Finished in about 9.000000 seconds.

Factor to Pi Ratio 1.111111
 erick@OptiPlex-790 ~/factor $ tail i5-2500@3700.txt

Calculations Completed!
 Time: 9 seconds

Factor: Finished in about 10.000000 seconds.
 Pi: Finished in about 9.000000 seconds.

Factor to Pi Ratio 1.111111

It looks like a Generation 2 i5 running at 3700MHz can run calculations at the same rate as a Generation 3 i5 at 3200MHz. The benchmark is both a pi calculation and a factoring calculation. The ratios will vary from processor to processor sometimes. Especially across old -vs- new ones. But these seem to line up.

Comparison

It looks like the raw speed difference for a given clock speed, 3700/3200 = 1.15625x faster. In other words, the Gen 2 has to be running 1.15625x faster on the clock to get the same speeds.

Note: The MHz values are running one core at turbo speed.

Code

The code is something that I patched together. I wrote the factoring part years ago to run under MS-DOS and ported it to compile under GCC. I made it at a time that I was toying around with extracting factors of numbers and was an exercise in making speed efficient code. I always had some spare moments while waiting for other compiles to happen. At the time I was working on embedded code in industry, these compiles could take a few minutes with each change and up to 20 minutes when doing a scratch build. This is on machines of the Pentium 2 -4 era. When writing embedded code and compiling there were plenty of slices of time to experiment with other code.

The Pi part I snagged off the web a long time ago, not sure where, or I would reference it here. It is interesting to see how the speeds will vary between the Pi and Factor parts, therefore I compute a ratio of them. I fiddled with the constants so that the time that both parts run is about 10 seconds and around a 1:1 ratio on my current desktop i5@3300Mhz. Essentially the desktop is the reference normal against which I am comparing other machines.

 

 

#include <stdio.h> 
#include <float.h> 
#include <time.h> 
#include <stdlib.h> 
#include <sys/time.h> 
#include <unistd.h> 
 
 
    unsigned int x; 
unsigned int f = 0, stopn = 100000, maxFactor = 0; //4294967295 
   time_t curtime; 
 
     
    FILE *fp; 
 
 
long secstart, usecstart; 
long kf, ks; 
long *mf, *ms; 
long cnt, n, temp, nd; 
long i; 
long col, col1; 
long loc, stor[40]; 
 
int main(void) 
{ 
 
  float factor_time; 
  float pi_time; 
  float ratio; 
  factor_time = factor(); 
  pi_time = pi(); 
 
  ratio = factor_time / pi_time; 
   printf("\n\nFactor: Finished in about %f seconds. \n", factor_time); 
   printf("Pi: Finished in about %f seconds. \n", pi_time); 
 
   printf("\n\nFactor to Pi Ratio %f \n",ratio ); 
 
} 
 
 
int factor(void) 
{ 
    unsigned int i = 1; 
    unsigned int n; 
 
    time_t start, stop; 
    clock_t ticks; long count; 
 
     
    //scanf("%s",fname); 
    //scanf("%i",stopn); 
    //fopen("temp.txt","w"); 
    //stopn = argv[i]; 
 
 
    // Mark off the start time for the program.  
   time(&start); 
 
    for(n = 1;n < stopn;n++) 
    { 
        
    #if 1 
      // Inner loop, Walk through all values of numbers up to 1 more than the middle number. 
        for(x = 2;x < (n/2)+1;x++) 
        { 
          // Found a factor incriment f 
      //      if((n/x) - (int)(n/x) == 0) 
      if(n%x == 0) 
            { 
                f++; 
            } 
        } 
    #endif 
 
        //fprintf(fp,"%i    %i \n",n,f); 
    // If the value of the factor f is larger than the largest factor found, mark the occurance. 
    if(f > maxFactor) 
    { 
      printf("%i\t %i\t",n,f); 
 
      maxFactor = f; 
 
      // Get Current Time, print it out. 
      time(&curtime); 
      printf("%s", ctime(&curtime)); 
 
    } 
        // Reset the factor count for the next outer loop. 
        f = 0; 
        
    } 
 
    // Mark the stop time of the program. 
 
   time(&stop); 
    
   // How long did the program run and how much CPU time did it use. 
   //   printf("Used %0.2f seconds of CPU time. \n", (double)ticks/CLOCKS_PER_SEC); 
   printf("Finished in about %.0f seconds. \n", difftime(stop, start)); 
 
    return(difftime(stop, start)); 
} 
 
 
 
 
 
 
 
 
 
 
void shift(long *l1, long *l2, long lp, long lmod) 
{ 
    long k; 
 
    k = ((*l2) > 0 ? (*l2) / lmod: -(-(*l2) / lmod) - 1); 
    *l2 -= k * lmod; 
    *l1 += k * lp; 
} 
 
void yprint(long m) 
{ 
    if (cnt<n) 
    { 
        if (++col == 11) 
        { 
            col = 1; 
            if (++col1 == 6) 
                { 
                    col1 = 0; 
                    printf("\n"); 
                    printf("%4ld",m%10); 
                } 
            else printf("%3ld",m%10); 
        } 
        else printf("%ld",m); 
        cnt++; 
    } 
} 
 
void xprint(long m) 
{ 
    long ii, wk, wk1; 
 
    if (m < 8) 
    { 
        for (ii = 1; ii <= loc; ) 
        yprint(stor[(int)(ii++)]); 
        loc = 0; 
    } 
    else 
    { 
        if (m > 9) 
        { 
            wk = m / 10; 
            m %= 10; 
            for (wk1 = loc; wk1 >= 1; wk1--) 
            { 
                wk += stor[(int)wk1]; 
                stor[(int)wk1] = wk % 10; 
                wk /= 10; 
            } 
        } 
    } 
    stor[(int)(++loc)] = m; 
} 
 
void memerr(int errno) 
{ 
    printf("\a\nOut of memory error #%d\n", errno); 
    if (2 == errno) 
    free(mf); 
    _exit(2); 
} 
 
int pi(void) 
{ 
    int i=0; 
    char *endp; 
 
 
    stor[i++] = 0; 
 
    n = 22000; 
 
    mf = malloc((size_t)(n + 3L)*(size_t)sizeof(long)); 
    if (!mf) 
    memerr(1); 
    ms = malloc((size_t)(n + 3L)*(size_t)sizeof(long)); 
    if (!ms) 
    memerr(2); 
    printf("\nApproximation of PI to %ld digits\n", (long)n); 
 
    struct timeval tv; 
    struct timezone tz; 
        gettimeofday(&tv, &tz); 
        secstart=tv.tv_sec; 
        usecstart=tv.tv_usec; 
    cnt = 0; 
    kf = 25; 
    ks = 57121L; 
    mf[1] = 1L; 
    for (i = 2; i <= (int)n; i += 2) 
    { 
        mf[i] = -16L; 
        mf[i+1] = 16L; 
    } 
    for (i = 1; i <= (int)n; i += 2) 
    { 
        ms[i] = -4L; 
        ms[i+1] = 4L; 
    } 
    printf("\n 3."); 
    while (cnt < n) 
    { 
        for (i = 0; ++i <= (int)n - (int)cnt; ) 
        { 
            mf[i] *= 10L; 
            ms[i] *= 10L; 
        } 
        for (i =(int)(n - cnt + 1); --i >= 2; ) 
        { 
            temp = 2 * i - 1; 
            shift(&mf[i - 1], &mf[i], temp - 2, temp * kf); 
            shift(&ms[i - 1], &ms[i], temp - 2, temp * ks); 
        } 
        nd = 0; 
        shift((long *)&nd, &mf[1], 1L, 5L); 
        shift((long *)&nd, &ms[1], 1L, 239L); 
        xprint(nd); 
    } 
    printf("\n\nCalculations Completed!\n"); 
    gettimeofday(&tv, &tz); 
    printf("Time: %ld seconds\n",tv.tv_sec-secstart); 
    free(ms); 
    free(mf); 
    return(tv.tv_sec-secstart); 
}