public void saveToDisk(RandomAccessFile raf, File file, boolean alreadyHasEIAHeader, boolean template) throws IOException {
//      Algorithm: 
//      1. get the number of channels;
//      2. create an EIA Header only nChannels valid. only for ESA template header
//      3. designate the saving tasks to every channel.
//      Note: index is required for saving designation.
    	int nChannels = this.getNumberOfChannels(); // 1.
        if(!template) {
            if (!alreadyHasEIAHeader)  // end of 2.
                writeNumberOfChannelsToHeader(raf, file, nChannels);
            for(int index = 0; index < nChannels; index++) { // start of 3.
                ESAChannel currentChannel = this.getSignalChannelAt(index);
                currentChannel.writeESAChannelToDisk(raf, index, nChannels);
            }//end of 3.
        } else {
            if (!alreadyHasEIAHeader)  // 2.
                writeNumberOfChannelsToHeader(raf, file, nChannels);
            
//            for (int index = 0; index < nChannels; index++) { // start of 3.
//                ESATemplateChannel currentChannel = this.getSignalTemplateChannelAt(index);
//                currentChannel.writeESATemplateChannelToDisk(raf, index, nChannels);
//            }//end of 3.
        }
    	    
        raf.close();
        this.setHostEdfFile(file);
    }