3 shift registers in and 2 out but with 1 line I don't understand

I have succeeded in writing a sketch to drive 3 CD4021's inputting and 2 74LS595's outputting.
The sketch works fine, I am watching the third input on the monitor.
The sketch is below, I discovered a way of lining the outputs up by adding a line
digitalWrite (clockPinin,1);
If I comment the line out the first register input reads 1 bit out, the second register shows the first bit as the last bit of the third register and the third register reads 1 bit out because of it? With it in the signals are all in line?
Can anybody tell me why this is and is this the only way of overcoming the error?

/*
	3 shift registers in, 2 out.

        Drive 2 banks of 8 LED's with 2 banks of 8 switches (with 1 extra input bank added for future expansion).
        
        The circuit:
	Connected to 3 cd 4021's with the inputs via switches to 5v and with 10k resistors to 0v.
        Connected to 2 74LS595's with their outputs connected via resistors and LED's to 0v.

	Created 09.11.13
	By matelot
	Modified ------------
	By -----------
*/
//connected to 2 cd4021's with the pin 11 on the first connected to pin 3 on the second.
const int latchPinin  =  5; //4021 pin 9
const int dataPinin   =  6;  //4021 pin 3
const int clockPinin  =  7; //4021 pin 10
//connected to 2 47LS595's with the pin 9 on the first connected to pin 12 on the second.
const int dataPinout  =  8;   //595 pin 14
const int latchPinout =  9;  //595 pin 11
const int clockPinout = 10; //595 pin 12
int myinput;
int myinput2;
int myinput3;

void setup()
{
  Serial.begin(9600);
  pinMode(dataPinout,  OUTPUT);
  pinMode(latchPinout, OUTPUT);
  pinMode(clockPinout, OUTPUT);
  pinMode(latchPinin,  OUTPUT);
  pinMode(clockPinin,  OUTPUT); 
  pinMode(dataPinin,    INPUT);
}

void loop()
{
   delayMicroseconds  (20);


   digitalWrite       (clockPinin,1);//what does this line do?


   digitalWrite       (latchPinin,1);//set it to 1 to collect parallel data
   delayMicroseconds  (20);//pause to let digitalWrite finish
   digitalWrite       (latchPinin,0); //set it to 0 to transmit data serially 
   delayMicroseconds  (20);
   myinput  = shiftIn (dataPinin, clockPinin, LSBFIRST);//read first register
   delayMicroseconds  (20);
   myinput2 = shiftIn (dataPinin, clockPinin, LSBFIRST);//read second register
   delayMicroseconds  (20);
   myinput3 = shiftIn (dataPinin, clockPinin, LSBFIRST);//read second register
   delayMicroseconds  (20);
   Serial.print  (myinput,BIN);
   Serial.print  ("   ");
   Serial.print  (myinput2,BIN);
   Serial.print  ("   ");
   Serial.println(myinput3,BIN);

   digitalWrite  (latchPinout, LOW);
   shiftOut      (dataPinout, clockPinout, LSBFIRST, myinput2);//Send data      
   shiftOut      (dataPinout, clockPinout, LSBFIRST, myinput); //Send data
   digitalWrite  (latchPinout, HIGH);
}

The digital write sets which edge the clocking of data happens on. To quote the manual:

Note: if you're interfacing with a device that's clocked by rising edges, you'll need to make sure that the clock pin is low before the call to shiftOut(), e.g. with a call to digitalWrite(clockPin, LOW).

Ergo, by setting it high, you clock out on the falling edges.

Am I getting you right? I can state which transition the clock will work on?
By putting digitalwrite clockpin ,HIGH I am telling the arduino to send a rising clock pulse as this is what the register requires?

I have replaced the line

digitalWrite (clockPinin,1); with digitalWrite (clockPinin,HIGH);

and it works, thanks for the reply.

matelot:
Am I getting you right? I can state which transition the clock will work on?
By putting digitalwrite clockpin ,HIGH I am telling the arduino to send a rising clock pulse as this is what the register requires?

I have replaced the line

digitalWrite (clockPinin,1); with digitalWrite (clockPinin,HIGH);

and it works, thanks for the reply.

No, that's not what's going on. It's a bit simpler than that.

shiftOut / shiftIn work by setting the Clock pin HIGH, then setting it LOW. If the clock pin is already HIGH at the beginning of this sequence, the first rising edge won't happen, since it'll go from HIGH to HIGH, rather than LOW to HIGH.

With the input shift register, you;ll want to start the Clock pin HIGH so that it won't clock the first bit out before it's read.

For reference, here's the shiftIn code from wiring_shift.h

uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
	uint8_t value = 0;
	uint8_t i;

	for (i = 0; i < 8; ++i) {
		digitalWrite(clockPin, HIGH);
		if (bitOrder == LSBFIRST)
			value |= digitalRead(dataPin) << i;
		else
			value |= digitalRead(dataPin) << (7 - i);
		digitalWrite(clockPin, LOW);
	}
	return value;
}

There's nothing in there about setting the clock edge.

thank you for that. That makes perfect sense now.
I am reading the first bit, moving the register along 1 bit with the positive going edge of the clock so the second bit is in place of the first and then reading that, moving the register along 1 etc.
I am, at this point only wanting to write the decimal into one variable (i.e. 255 if all on) and send it to a 74LS595.

I don't fully understand the section of sketch you added, I have seen uint8_t before but I don't know what it is?
Does uint8_t bitOrder read what the bitorder is? if (bitOrder == LSBFIRST) looks as if it does?
Does the variable value act like an array? could you remove any bit from it as required?
Always question!!!
Thanks anyway.
matelot.